Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Schnekenburger2015-10-27 13:47:25 +0000
committerRemi Schnekenburger2015-10-27 13:47:25 +0000
commitb06cef0b9417f03a4d5a389c314f432f2d9b9e34 (patch)
tree44b2c70f86e3115d83ca6fe80ff66369cfa8a889 /plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands
parent308666baced83ced2447c2cdf7cce54b6b7192e3 (diff)
downloadorg.eclipse.papyrus-b06cef0b9417f03a4d5a389c314f432f2d9b9e34.tar.gz
org.eclipse.papyrus-b06cef0b9417f03a4d5a389c314f432f2d9b9e34.tar.xz
org.eclipse.papyrus-b06cef0b9417f03a4d5a389c314f432f2d9b9e34.zip
Diffstat (limited to 'plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateViewCommand.java134
1 files changed, 59 insertions, 75 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateViewCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateViewCommand.java
index 12b463c5622..cdd7a64ee2f 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateViewCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateViewCommand.java
@@ -1,75 +1,59 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
-import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
-import org.eclipse.gmf.runtime.emf.type.core.IElementType;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-
-/**
- * A replacement for CreateCommand that avoids that takes into account the incorrect
- * generation of ViewProvider by GMFTooling and modifies SemanticAdapter in call to {@link ViewService#provides(Class, org.eclipse.core.runtime.IAdaptable, View, String, int, boolean, org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint)} .
- */
-public class CreateViewCommand extends CreateCommand {
-
- /** Constructor */
- public CreateViewCommand(TransactionalEditingDomain editingDomain, ViewDescriptor viewDescriptor, View containerView) {
- super(editingDomain, viewDescriptor, containerView);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean canExecute() {
-
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=450921
- // it should be possible to create not only elements with semantic
- // like oval or note
- int hint;
- try {
- hint = Integer.parseInt(viewDescriptor.getSemanticHint());
- } catch(Exception e) {
- hint = -1;
- }
-
- if (hint == -1) {
- return super.canExecute();
- }
-
- // Warning the element adapter can possibly be null (see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=353129)
- if (viewDescriptor.getElementAdapter() == null) {
- return false;
- }
-
- // Try to adapt the descriptor ElementAdapter in EObject
- EObject element = EMFHelper.getEObject(viewDescriptor.getElementAdapter());
- IElementType elementType = (IElementType) viewDescriptor.getElementAdapter().getAdapter(IElementType.class);
-
- SemanticElementAdapter semanticAdapter = new SemanticElementAdapter(element, elementType);
-
- // Use the semanticAdapter instead of view descriptor element adapter to avoid the use of provides(ViewForKind) method
- // from ViewProvider which is incorrectly implemented in GMF Tooling generated editors (other editors may have undesired side-effect on each-other).
-
- return ViewService.getInstance().provides(viewDescriptor.getViewKind(), semanticAdapter, containerView, viewDescriptor.getSemanticHint(), viewDescriptor.getIndex(), viewDescriptor.isPersisted(), viewDescriptor.getPreferencesHint());
- }
-
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
+import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * A replacement for CreateCommand that avoids that takes into account the incorrect
+ * generation of ViewProvider by GMFTooling and modifies SemanticAdapter in call to {@link ViewService#provides(Class, org.eclipse.core.runtime.IAdaptable, View, String, int, boolean, org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint)} .
+ */
+public class CreateViewCommand extends CreateCommand {
+
+ /** Constructor */
+ public CreateViewCommand(TransactionalEditingDomain editingDomain, ViewDescriptor viewDescriptor, View containerView) {
+ super(editingDomain, viewDescriptor, containerView);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean canExecute() {
+ // Warning the element adapter can possibly be null (see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=353129)
+ if (viewDescriptor.getElementAdapter() == null) {
+ return false;
+ }
+
+ // Try to adapt the descriptor ElementAdapter in EObject
+ EObject element = EMFHelper.getEObject(viewDescriptor.getElementAdapter());
+ IElementType elementType = (IElementType) viewDescriptor.getElementAdapter().getAdapter(IElementType.class);
+
+ SemanticElementAdapter semanticAdapter = new SemanticElementAdapter(element, elementType);
+
+ // Use the semanticAdapter instead of view descriptor element adapter to avoid the use of provides(ViewForKind) method
+ // from ViewProvider which is incorrectly implemented in GMF Tooling generated editors (other editors may have undesired side-effect on each-other).
+
+ return ViewService.getInstance().provides(viewDescriptor.getViewKind(), semanticAdapter, containerView, viewDescriptor.getSemanticHint(), viewDescriptor.getIndex(), viewDescriptor.isPersisted(), viewDescriptor.getPreferencesHint());
+ }
+
+
+
+}

Back to the top