]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Prefer WorkbenchSelectionUtils when obtaining Resource from selection 55/355/3
authorAntti Villberg <antti.villberg@semantum.fi>
Fri, 10 Mar 2017 08:57:46 +0000 (10:57 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sun, 12 Mar 2017 16:23:59 +0000 (18:23 +0200)
refs #7077

Change-Id: I45cfa3940df8e1f4abe016b215843dc083227b2b

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/ModeledActions.java
bundles/org.simantics.ui/src/org/simantics/ui/contribution/OpenWithMenuContribution.java
bundles/org.simantics.ui/src/org/simantics/ui/contribution/OperationsMenuContribution.java

index 41062fef81798496ee4569d218240e1811867df8..478d8b761046177484db3ecbc02643ada1801feb 100644 (file)
@@ -115,17 +115,18 @@ public class ModeledActions extends DynamicMenuContribution implements IExecutab
         for (Object o : selection) {
             if ((o instanceof IAdaptable)) {
                    NodeContext nodeContext = ((IAdaptable) o).getAdapter(NodeContext.class);
-                   if (nodeContext != null)
+                   if (nodeContext != null) {
                        result.add(nodeContext);
-            } else if (o instanceof WorkbenchSelectionElement) {
-               try {
-                                       Resource res = WorkbenchSelectionUtils.getPossibleResource((WorkbenchSelectionElement)o);
-                                       if(res != null) {
-                                               result.add(NodeContextBuilder.buildWithInput(res));
-                                       }
-                               } catch (DatabaseException e) {
-                                   LOGGER.error("Failed to get node contexts for selection.", e);
-                               }
+                       continue;
+                   }
+            }
+            try {
+               Resource res = WorkbenchSelectionUtils.getPossibleResource(o);
+               if(res != null) {
+                       result.add(NodeContextBuilder.buildWithInput(res));
+               }
+            } catch (DatabaseException e) {
+               LOGGER.error("Failed to get node contexts for selection.", e);
             }
         }
 
index 55128b89e29fba7fd3461c401c7376d89115b8b7..4112d905134e5b9319a86e8db55a1f14a7112f6c 100644 (file)
@@ -28,7 +28,7 @@ import org.eclipse.swt.widgets.MenuItem;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.ui.utils.ResourceAdaptionUtils;
+import org.simantics.ui.selection.WorkbenchSelectionUtils;
 import org.simantics.ui.workbench.action.ResourceEditorAdapterAction;
 import org.simantics.ui.workbench.editor.EditorAdapter;
 import org.simantics.ui.workbench.editor.EditorRegistry;
@@ -58,7 +58,8 @@ public class OpenWithMenuContribution extends DynamicMenuContribution {
     }
 
     protected Object extractResource(ReadGraph graph, Object object) throws DatabaseException {
-       Resource resource = ResourceAdaptionUtils.adaptToResource(graph, object);
+       Resource resource = WorkbenchSelectionUtils.getPossibleResource(object);
+       //Resource resource = ResourceAdaptionUtils.adaptToResource(graph, object);
        if(resource != null) return resource;
        else return object; 
     }
index b194694b58e01a3868861dd0e82bd6847a6e533b..a49073a4d7a7ddbe0ffd07e7340f8f34edd88bb7 100644 (file)
@@ -28,6 +28,7 @@ import org.simantics.layer0.utils.operations.IOperation;
 import org.simantics.project.IProject;
 import org.simantics.ui.SimanticsUI;
 import org.simantics.ui.icons.ImageUtil;
+import org.simantics.ui.selection.WorkbenchSelectionUtils;
 import org.simantics.ui.utils.ResourceAdaptionUtils;
 import org.simantics.utils.datastructures.persistent.ContextMap;
 
@@ -48,9 +49,9 @@ public abstract class OperationsMenuContribution extends DynamicMenuContribution
     }
 
     @Override
-    protected IAction[] getActions(ReadGraph g, Object[] selection) {
+    protected IAction[] getActions(ReadGraph g, Object[] selection) throws DatabaseException {
         if(selection.length == 1) {
-            final Resource r = ResourceAdaptionUtils.adaptToResource(selection[0]);
+            final Resource r = WorkbenchSelectionUtils.getPossibleResource(selection[0]);
             if(r == null)
                return NO_ACTIONS;
             try {