]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Modified OpenWith for further customization. 48/4548/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 20 Oct 2020 13:30:50 +0000 (16:30 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 20 Oct 2020 13:30:50 +0000 (16:30 +0300)
gitlab #624

Change-Id: I186c49de0590f4832e7f6337505001db81c057bf

bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/GraphDebuggerEditorAdapter.java
bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/GraphicalDebuggerEditorAdapter.java
bundles/org.simantics.ui/src/org/simantics/ui/contribution/OpenWithMenuContribution.java

index 6039f82875b75f2daa837c08b203e86f143c1cb4..727b91b3c6bc421ce97f7b4f7dd184cc347afa7c 100644 (file)
@@ -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;
+    }
+    
 }
index d98edc4c4bcf32a0fb27cdeb97bc5dba08b90a78..63a7aa802b84c81ed878b2b25f8a19c9be896a92 100644 (file)
@@ -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;
+    }
+    
 }
index f09dd23ce286ec0a4ae1eb6d97f8aefb9b843099..c8a88f27dff64315f7d67ae52a6f34daba3fbf91 100644 (file)
@@ -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<Adapter>() {
-                                @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<Adapter>() {
+             @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) {