Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/org.eclipse.gmf.ecore.editor/src/org/eclipse/gmf/ecore/edit/policies/EcoreBaseItemSemanticEditPolicy.java13
-rw-r--r--examples/org.eclipse.gmf.ecore.editor/src/org/eclipse/gmf/ecore/sheet/EcoreSheetLabelProvider.java61
2 files changed, 41 insertions, 33 deletions
diff --git a/examples/org.eclipse.gmf.ecore.editor/src/org/eclipse/gmf/ecore/edit/policies/EcoreBaseItemSemanticEditPolicy.java b/examples/org.eclipse.gmf.ecore.editor/src/org/eclipse/gmf/ecore/edit/policies/EcoreBaseItemSemanticEditPolicy.java
index 8fccbef55..62e398fdb 100644
--- a/examples/org.eclipse.gmf.ecore.editor/src/org/eclipse/gmf/ecore/edit/policies/EcoreBaseItemSemanticEditPolicy.java
+++ b/examples/org.eclipse.gmf.ecore.editor/src/org/eclipse/gmf/ecore/edit/policies/EcoreBaseItemSemanticEditPolicy.java
@@ -143,10 +143,7 @@ public class EcoreBaseItemSemanticEditPolicy extends SemanticEditPolicy {
ICommand command = editPolicyCommand instanceof ICommandProxy ? ((ICommandProxy) editPolicyCommand).getICommand() : new CommandProxy(editPolicyCommand);
request.setParameter(EcoreBaseEditHelper.EDIT_POLICY_COMMAND, command);
}
- IElementType requestContextElementType = EcoreElementTypes.getElementType(getVisualID(request));
- if (requestContextElementType == null) {
- requestContextElementType = myElementType;
- }
+ IElementType requestContextElementType = getContextElementType(request);
request.setParameter(EcoreBaseEditHelper.CONTEXT_ELEMENT_TYPE, requestContextElementType);
ICommand command = requestContextElementType.getEditCommand(request);
request.setParameter(EcoreBaseEditHelper.EDIT_POLICY_COMMAND, null);
@@ -164,6 +161,14 @@ public class EcoreBaseItemSemanticEditPolicy extends SemanticEditPolicy {
/**
* @generated
*/
+ private IElementType getContextElementType(IEditCommandRequest request) {
+ IElementType requestContextElementType = EcoreElementTypes.getElementType(getVisualID(request));
+ return requestContextElementType != null ? requestContextElementType : myElementType;
+ }
+
+ /**
+ * @generated
+ */
protected Command getSemanticCommandSwitch(IEditCommandRequest req) {
if (req instanceof CreateRelationshipRequest) {
return getCreateRelationshipCommand((CreateRelationshipRequest) req);
diff --git a/examples/org.eclipse.gmf.ecore.editor/src/org/eclipse/gmf/ecore/sheet/EcoreSheetLabelProvider.java b/examples/org.eclipse.gmf.ecore.editor/src/org/eclipse/gmf/ecore/sheet/EcoreSheetLabelProvider.java
index bbd1e562e..b7cdc2cb6 100644
--- a/examples/org.eclipse.gmf.ecore.editor/src/org/eclipse/gmf/ecore/sheet/EcoreSheetLabelProvider.java
+++ b/examples/org.eclipse.gmf.ecore.editor/src/org/eclipse/gmf/ecore/sheet/EcoreSheetLabelProvider.java
@@ -16,39 +16,39 @@ import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.ecore.navigator.EcoreNavigatorGroup;
import org.eclipse.gmf.ecore.part.EcoreDiagramEditorPlugin;
+import org.eclipse.gmf.ecore.part.EcoreVisualIDRegistry;
+import org.eclipse.gmf.ecore.providers.EcoreElementTypes;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.viewers.BaseLabelProvider;
import org.eclipse.jface.viewers.DecoratingLabelProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.graphics.Image;
/**
* @generated
*/
-public class EcoreSheetLabelProvider extends DecoratingLabelProvider {
-
- /**
- * @generated
- */
- public EcoreSheetLabelProvider() {
- super(new AdapterFactoryLabelProvider(EcoreDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory()), null);
- }
+public class EcoreSheetLabelProvider extends BaseLabelProvider implements ILabelProvider {
/**
* @generated
*/
public String getText(Object element) {
- Object selected = unwrap(element);
- if (selected instanceof EcoreNavigatorGroup) {
- return ((EcoreNavigatorGroup) selected).getGroupName();
+ element = unwrap(element);
+ if (element instanceof EcoreNavigatorGroup) {
+ return ((EcoreNavigatorGroup) element).getGroupName();
}
- return super.getText(selected);
+ IElementType etype = getElementType(getView(element));
+ return etype == null ? "" : etype.getDisplayName();
}
/**
* @generated
*/
public Image getImage(Object element) {
- return super.getImage(unwrap(element));
+ IElementType etype = getElementType(getView(unwrap(element)));
+ return etype == null ? null : EcoreElementTypes.getImage(etype);
}
/**
@@ -56,16 +56,7 @@ public class EcoreSheetLabelProvider extends DecoratingLabelProvider {
*/
private Object unwrap(Object element) {
if (element instanceof IStructuredSelection) {
- return unwrap(((IStructuredSelection) element).getFirstElement());
- }
- if (element instanceof EditPart) {
- return unwrapEditPart((EditPart) element);
- }
- if (element instanceof IAdaptable) {
- View view = (View) ((IAdaptable) element).getAdapter(View.class);
- if (view != null) {
- return unwrapView(view);
- }
+ return ((IStructuredSelection) element).getFirstElement();
}
return element;
}
@@ -73,18 +64,30 @@ public class EcoreSheetLabelProvider extends DecoratingLabelProvider {
/**
* @generated
*/
- private Object unwrapEditPart(EditPart p) {
- if (p.getModel() instanceof View) {
- return unwrapView((View) p.getModel());
+ private View getView(Object element) {
+ if (element instanceof View) {
+ return (View) element;
+ }
+ if (element instanceof IAdaptable) {
+ return (View) ((IAdaptable) element).getAdapter(View.class);
}
- return p.getModel();
+ return null;
}
/**
* @generated
*/
- private Object unwrapView(View view) {
- return view.getElement() == null ? view : view.getElement();
+ private IElementType getElementType(View view) {
+ // For intermediate views climb up the containment hierarchy to find the one associated with an element type.
+ while (view != null) {
+ int vid = EcoreVisualIDRegistry.getVisualID(view);
+ IElementType etype = EcoreElementTypes.getElementType(vid);
+ if (etype != null) {
+ return etype;
+ }
+ view = view.eContainer() instanceof View ? (View) view.eContainer() : null;
+ }
+ return null;
}
}

Back to the top