/*
* Copyright (c) 2008 Borland Software Corporation
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Tatiana Fesenko (Borland) - initial API and implementation
*/
package org.eclipse.uml2.diagram.common.sheet;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.viewers.IFilter;
public abstract class UML2ToolsPropertyFilter implements IFilter {
public boolean select(Object toTest) {
Object transformed = transformSelection(toTest);
return isValid(transformed);
}
protected abstract boolean isValid(Object transformedObject);
protected Object transformSelection(Object selected) {
if (selected instanceof EditPart) {
Object model = ((EditPart) selected).getModel();
return model instanceof View ? ((View) model).getElement() : null;
}
if (selected instanceof View) {
return ((View) selected).getElement();
}
if (selected instanceof IAdaptable) {
View view = (View) ((IAdaptable) selected).getAdapter(View.class);
if (view != null) {
return view.getElement();
}
}
return selected;
}
}