Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormgolubev2012-05-02 07:16:30 +0000
committermgolubev2012-05-02 07:16:30 +0000
commit02e441ef6339b4f7caf557c81e16c77f8bb7a5b2 (patch)
tree02eb37ec1c718f936ddf946825dcaf600a44c273
parent6450b639fdfeb31d2b4d3a605a9025214561a612 (diff)
downloadorg.eclipse.gmf-tooling-02e441ef6339b4f7caf557c81e16c77f8bb7a5b2.tar.gz
org.eclipse.gmf-tooling-02e441ef6339b4f7caf557c81e16c77f8bb7a5b2.tar.xz
org.eclipse.gmf-tooling-02e441ef6339b4f7caf557c81e16c77f8bb7a5b2.zip
Custom policy to avoid showing Assign to Layers on the diagram canvas
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerItemProvider.java (renamed from examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayersItemProvider.java)7
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerItemProviderPolicy.java35
-rw-r--r--examples/org.eclipse.gmf.examples.taipan.gmf.editor/plugin.xml11
3 files changed, 38 insertions, 15 deletions
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayersItemProvider.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerItemProvider.java
index 180d62000..66f3e138f 100644
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayersItemProvider.java
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerItemProvider.java
@@ -15,15 +15,10 @@ import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.ui.IWorkbenchPage;
-public class AssignToLayersItemProvider extends AbstractContributionItemProvider implements IProvider {
+public class AssignToLayerItemProvider extends AbstractContributionItemProvider implements IProvider {
public static final String MENU_ASSIGN_TO_LAYER = "menu_assign_to_layer"; //$NON-NLS-1$
- public AssignToLayersItemProvider() {
- super();
- System.out.println("AssignToLayersItemProvider.AssignToLayersItemProvider()");
- }
-
@Override
protected IMenuManager createMenuManager(String menuId, IWorkbenchPartDescriptor partDescriptor) {
if (!MENU_ASSIGN_TO_LAYER.equals(menuId)) {
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerItemProviderPolicy.java b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerItemProviderPolicy.java
new file mode 100644
index 000000000..4875b9b6d
--- /dev/null
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/custom-src/org/eclipse/gmf/examples/subdiagrams/popup/AssignToLayerItemProviderPolicy.java
@@ -0,0 +1,35 @@
+package org.eclipse.gmf.examples.subdiagrams.popup;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.IPopupMenuContributionPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+
+public class AssignToLayerItemProviderPolicy implements IPopupMenuContributionPolicy {
+
+ @Override
+ public boolean appliesTo(ISelection selection, IConfigurationElement configuration) {
+ if (false == selection instanceof IStructuredSelection) {
+ return false;
+ }
+ List<?> allSelected = ((IStructuredSelection) selection).toList();
+ if (allSelected.isEmpty()) {
+ return false;
+ }
+ for (Object next : allSelected) {
+ if (!checkSelectedElement(next)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private boolean checkSelectedElement(Object selected) {
+ return selected instanceof IGraphicalEditPart && !(selected instanceof DiagramEditPart);
+ }
+
+}
diff --git a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/plugin.xml b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/plugin.xml
index 5530ead6d..fbddacc5b 100644
--- a/examples/org.eclipse.gmf.examples.taipan.gmf.editor/plugin.xml
+++ b/examples/org.eclipse.gmf.examples.taipan.gmf.editor/plugin.xml
@@ -636,7 +636,7 @@ Contributors:
<?gmfgen generated="false"?>
<contributionItemProvider
checkPluginLoaded="true"
- class="org.eclipse.gmf.examples.subdiagrams.popup.AssignToLayersItemProvider">
+ class="org.eclipse.gmf.examples.subdiagrams.popup.AssignToLayerItemProvider">
<Priority name="Medium"/>
<popupContribution
class="org.eclipse.gmf.examples.taipan.gmf.editor.part.DiagramEditorContextMenuProvider">
@@ -648,15 +648,8 @@ Contributors:
path="/AssignToLayerGroup"
id="menu_assign_to_layer">
</popupMenu>
- <!--
<popupStructuredContributionCriteria
- objectClass="org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart"
- objectCount="1">
- </popupStructuredContributionCriteria>
- -->
- <popupStructuredContributionCriteria
- objectClass="org.eclipse.gmf.examples.taipan.gmf.editor.edit.parts.PortEditPart"
- objectCount="1">
+ policyClass="org.eclipse.gmf.examples.subdiagrams.popup.AssignToLayerItemProviderPolicy">
</popupStructuredContributionCriteria>
</popupContribution>
</contributionItemProvider>

Back to the top