From ad8152c8f0d0efe8889fd75f722b7d80466406d1 Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Fri, 10 Mar 2017 10:57:46 +0200 Subject: [PATCH] Prefer WorkbenchSelectionUtils when obtaining Resource from selection refs #7077 Change-Id: I45cfa3940df8e1f4abe016b215843dc083227b2b --- .../modeling/ui/actions/ModeledActions.java | 21 ++++++++++--------- .../OpenWithMenuContribution.java | 5 +++-- .../OperationsMenuContribution.java | 5 +++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/ModeledActions.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/ModeledActions.java index 41062fef8..478d8b761 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/ModeledActions.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/ModeledActions.java @@ -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); } } diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/contribution/OpenWithMenuContribution.java b/bundles/org.simantics.ui/src/org/simantics/ui/contribution/OpenWithMenuContribution.java index 55128b89e..4112d9051 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/contribution/OpenWithMenuContribution.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/contribution/OpenWithMenuContribution.java @@ -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; } diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/contribution/OperationsMenuContribution.java b/bundles/org.simantics.ui/src/org/simantics/ui/contribution/OperationsMenuContribution.java index b194694b5..a49073a4d 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/contribution/OperationsMenuContribution.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/contribution/OperationsMenuContribution.java @@ -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 { -- 2.47.1