From acf5a3bf93ecfc3561d515c88fc652f5b904e959 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Tue, 20 Oct 2020 16:30:50 +0300 Subject: [PATCH] Modified OpenWith for further customization. gitlab #624 Change-Id: I186c49de0590f4832e7f6337505001db81c057bf --- .../internal/GraphDebuggerEditorAdapter.java | 5 +++ .../GraphicalDebuggerEditorAdapter.java | 5 +++ .../OpenWithMenuContribution.java | 37 ++++++++++++------- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/GraphDebuggerEditorAdapter.java b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/GraphDebuggerEditorAdapter.java index 6039f8287..727b91b3c 100644 --- a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/GraphDebuggerEditorAdapter.java +++ b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/GraphDebuggerEditorAdapter.java @@ -38,4 +38,9 @@ public class GraphDebuggerEditorAdapter extends AbstractResourceEditorAdapter { openEditorWithId(GraphDebuggerEditor.EDITOR_ID, new ResourceEditorInput(GraphDebuggerEditor.EDITOR_ID,r)); } + @Override + public String getEditorId() { + return GraphDebuggerEditor.EDITOR_ID; + } + } diff --git a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/GraphicalDebuggerEditorAdapter.java b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/GraphicalDebuggerEditorAdapter.java index d98edc4c4..63a7aa802 100644 --- a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/GraphicalDebuggerEditorAdapter.java +++ b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/GraphicalDebuggerEditorAdapter.java @@ -36,4 +36,9 @@ public class GraphicalDebuggerEditorAdapter extends AbstractResourceEditorAdapte openEditorWithId(GraphicalDebuggerEditor.EDITOR_ID, new ResourceEditorInput(GraphicalDebuggerEditor.EDITOR_ID,r)); } + @Override + public String getEditorId() { + return GraphicalDebuggerEditor.EDITOR_ID; + } + } 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 f09dd23ce..c8a88f27d 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 @@ -49,7 +49,7 @@ public class OpenWithMenuContribution extends DynamicMenuContribution implements private static final boolean DEBUG_ADAPTERS = false; - private ResourceManager resourceManager; + protected ResourceManager resourceManager; private String editorId = null; public OpenWithMenuContribution() { @@ -73,6 +73,10 @@ public class OpenWithMenuContribution extends DynamicMenuContribution implements } } + public String getEditorId() { + return editorId; + } + public void setEditorId(String editorId) { this.editorId = editorId; } @@ -123,18 +127,7 @@ public class OpenWithMenuContribution extends DynamicMenuContribution implements if (editorAdapters.length > 0) { // Sort the open with actions in descending priority order. - Adapter[] adapters = new Adapter[editorAdapters.length]; - for (int i = 0; i < editorAdapters.length; i++) - adapters[i] = new Adapter(editorAdapters[i], r, true); - Arrays.sort(adapters, new Comparator() { - @Override - public int compare(Adapter o1, Adapter o2) { - int delta = o2.getPriority() - o1.getPriority(); - if (delta != 0) - return delta; - return AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(o1.getText(), o2.getText()); - } - }); + Adapter[] adapters = toAdapters(editorAdapters, r); for (Adapter a : adapters) addMenuItem(subMenu, a, r); @@ -144,6 +137,22 @@ public class OpenWithMenuContribution extends DynamicMenuContribution implements }; } + protected Adapter[] toAdapters(EditorAdapter[] editorAdapters, Object r) { + Adapter[] adapters = new Adapter[editorAdapters.length]; + for (int i = 0; i < editorAdapters.length; i++) + adapters[i] = new Adapter(editorAdapters[i], r, true); + Arrays.sort(adapters, new Comparator() { + @Override + public int compare(Adapter o1, Adapter o2) { + int delta = o2.getPriority() - o1.getPriority(); + if (delta != 0) + return delta; + return AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(o1.getText(), o2.getText()); + } + }); + return adapters; + } + protected EditorAdapter[] filter(EditorAdapter[] adapters, String id) { if (id == null) return adapters; @@ -170,7 +179,7 @@ public class OpenWithMenuContribution extends DynamicMenuContribution implements item.addSelectionListener(adapter); } - static class Adapter extends ResourceEditorAdapterAction implements SelectionListener { + protected static class Adapter extends ResourceEditorAdapterAction implements SelectionListener { boolean remember; public Adapter(EditorAdapter adapter, Object r, boolean remember) { -- 2.47.1