]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #5184
authorjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 22 Aug 2014 08:04:52 +0000 (08:04 +0000)
committerjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 22 Aug 2014 08:04:52 +0000 (08:04 +0000)
- Modified EnumerationTab add  button to activate the newly created index for renaming
- Rename for EnumerationIndex can be executed via context menu "Rename" or F2

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30115 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/EnumerationIndexRenameNodeHandler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationIndexNode.java

index 7b06dd5bb14c4e834bb7da0f042c1a8d94648638..4334595d38453a058f94ca652c379b14c8538c5a 100644 (file)
                tooltip="Exports the trend to SVG file">\r
          </command>\r
       </menuContribution>\r
+      \r
+      <menuContribution\r
+            locationURI="popup:#EnumerationTabPopup?after=wbStart">\r
+            \r
+            <command\r
+               commandId="org.simantics.sysdyn.ui.renameNode1"\r
+               icon="platform:/plugin/com.famfamfam.silk/icons/textfield_rename.png"\r
+               id="org.simantics.sysdyn.ui.browser.rename"\r
+               label="Rename"\r
+               style="push">\r
+            <visibleWhen checkEnabled="true">\r
+            </visibleWhen>\r
+         </command>\r
+            \r
+      </menuContribution>\r
       <menuContribution\r
             locationURI="popup:#SysdynBrowserPopup?after=wbStart">\r
          <menu id="org.simantics.new"\r
             id="org.simantics.sysdyn.ui.renameNode"\r
             name="Rename Node">\r
       </command>\r
+      <command\r
+            id="org.simantics.sysdyn.ui.enumerationIndexRenameNode"\r
+            name="Rename Node">\r
+      </command>\r
       <command\r
             defaultHandler="org.simantics.sysdyn.ui.handlers.ToggleSimulation"\r
             id="org.simantics.sysdyn.ui.toggleSimulation"\r
    </extension>\r
    <extension\r
          point="org.eclipse.ui.handlers">\r
+         \r
+      <handler\r
+            class="org.simantics.sysdyn.ui.handlers.EnumerationIndexRenameNodeHandler"\r
+            commandId="org.simantics.sysdyn.ui.enumerationIndexRenameNode">\r
+      </handler>\r
+         \r
+         \r
       <handler\r
             class="org.simantics.sysdyn.ui.trend.PinTrend"\r
             commandId="org.simantics.sysdyn.ui.trend.view.pin">\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/EnumerationIndexRenameNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/EnumerationIndexRenameNodeHandler.java
new file mode 100644 (file)
index 0000000..11b5cc3
--- /dev/null
@@ -0,0 +1,73 @@
+/*******************************************************************************\r
+ * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.ui.IEditorPart;\r
+import org.eclipse.ui.IWorkbenchPart;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.eclipse.ui.part.IPage;\r
+import org.eclipse.ui.part.IPageSite;\r
+import org.simantics.browsing.ui.GraphExplorer;\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.common.ColumnKeys;\r
+import org.simantics.browsing.ui.platform.PropertyPageView;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
+import org.simantics.sysdyn.ui.properties.SysdynPropertyPage;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+public class EnumerationIndexRenameNodeHandler extends AbstractHandler {\r
+\r
+    @Override\r
+    public Object execute(ExecutionEvent event) throws ExecutionException {\r
+        ISelection sel2 = HandlerUtil.getActiveMenuSelection(event);\r
+        NodeContext ctx = ISelectionUtils.filterSingleSelection(sel2, NodeContext.class);\r
+        if (ctx == null)\r
+            return null;\r
+\r
+        IWorkbenchPart part = HandlerUtil.getActivePart(event);\r
+        if (part == null)\r
+            return null;\r
+\r
+        PropertyPageView ppv = (PropertyPageView) part;\r
+        IPage p = ppv.getCurrentPage();\r
+        Control control = p.getControl();\r
+        \r
+        Control geComposite = findGEComposite(control);\r
+        GraphExplorerComposite ge = (GraphExplorerComposite) geComposite;\r
+        ge.getExplorer().startEditing(ctx, ColumnKeys.SINGLE);\r
+        \r
+        return null;\r
+    }\r
+    \r
+    private Control findGEComposite(Control control) {\r
+        Control[] comp = ((Composite) control).getChildren();\r
+        Control ge = null;\r
+        for (Control cont : comp) {\r
+            if (cont instanceof GraphExplorerComposite)\r
+                return cont;\r
+            else if (cont instanceof Composite) {\r
+                ge = findGEComposite(cont);\r
+                return ge;\r
+            }\r
+            else\r
+                continue;\r
+        }\r
+        return ge;\r
+    }\r
+}\r
index 7514f47c6184dc6e4b8d9366667db965c77b169d..4252b6cd07c44c10b76b59216921d475a38cc957 100644 (file)
@@ -15,6 +15,10 @@ import java.util.ArrayList;
 import java.util.HashSet;\r
 import java.util.List;\r
 \r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.core.runtime.jobs.Job;\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.jface.viewers.ISelectionProvider;\r
@@ -29,7 +33,9 @@ import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Tree;\r
 import org.eclipse.swt.widgets.TreeItem;\r
 import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.Simantics;\r
 import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.common.ColumnKeys;\r
 import org.simantics.browsing.ui.swt.SingleSelectionInputSource;\r
 import org.simantics.browsing.ui.swt.widgets.Button;\r
 import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
@@ -47,6 +53,7 @@ import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.utils.ListUtils;\r
 import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.Layer0Utils;\r
 import org.simantics.db.layer0.variable.Variable;\r
 import org.simantics.db.layer0.variable.Variables;\r
 import org.simantics.db.management.ISessionContext;\r
@@ -62,8 +69,8 @@ import org.simantics.sysdyn.ui.properties.widgets.arrays.EnumerationIndexNode;
 import org.simantics.sysdyn.ui.properties.widgets.arrays.ReplaceableIndexesWidget;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameInputValidator;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier;\r
-import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.datastructures.ArrayMap;\r
+import org.simantics.utils.threads.SWTThread;\r
 import org.simantics.utils.ui.AdaptionUtils;\r
 \r
 public class EnumerationTab extends LabelPropertyTabContributor implements Widget {\r
@@ -78,6 +85,10 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
        Variable variable;\r
        \r
        Table table;\r
+\r
+    private Button add;\r
+    private Button remove;\r
+    \r
        @Override\r
        public void createControls(Composite body, IWorkbenchSite site,\r
                        final ISessionContext context, WidgetSupport support) {\r
@@ -97,6 +108,8 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
         indexExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
                                "displaySelectors", "displayFilter").values(false, false), site, container, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI | SWT.CHECK);\r
                \r
+        indexExplorer.setContextMenuId("#EnumerationTabPopup");\r
+        \r
         indexExplorer\r
                .setBrowseContexts(SysdynResource.URIs.EnumerationIndexes);\r
         indexExplorer.setInputSource(new SingleSelectionInputSource(\r
@@ -112,7 +125,7 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
                     final EnumerationIndexNode node = (EnumerationIndexNode) context.getAdapter(EnumerationIndexNode.class);\r
                     node.setShowInChartsSelected(checked);\r
                     \r
-                    SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+                    Simantics.getSession().asyncRequest(new ReadRequest() {\r
                                                @Override\r
                                                public void run(ReadGraph graph) throws DatabaseException {\r
                                                        updateModelResults(graph);\r
@@ -122,7 +135,7 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
             }\r
         });\r
         \r
-\r
+        \r
         indexExplorer.finish();\r
 \r
                GridDataFactory.fillDefaults().grab(true, true).span(4, 1).applyTo(\r
@@ -133,13 +146,13 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
                        ((Tree) c).setLinesVisible(true);\r
 \r
 \r
-               final Button add = new Button(container, support, SWT.None);\r
+               add = new Button(container, support, SWT.None);\r
                add.setText("Add");\r
-               add.addSelectionListener(new addEnumerationIndexListener(support));\r
+               add.addSelectionListener(new AddEnumerationIndexListener(support));\r
 \r
-               final Button remove = new Button(container, support, SWT.None);\r
+               remove = new Button(container, support, SWT.None);\r
                remove.setText("Remove");\r
-               remove.addSelectionListener(new removeEnumerationIndexListener(support));\r
+               remove.addSelectionListener(new RemoveEnumerationIndexListener(support));\r
                \r
                ReplaceableIndexesWidget externalIndexes = new ReplaceableIndexesWidget(container, support, SWT.NULL);\r
                GridDataFactory.fillDefaults().applyTo(externalIndexes.getWidget());\r
@@ -150,11 +163,11 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
                \r
        }\r
 \r
-       private class addEnumerationIndexListener implements SelectionListener, Widget {\r
+       private class AddEnumerationIndexListener implements SelectionListener, Widget {\r
 \r
                Resource enumerationIndexes;\r
 \r
-               public addEnumerationIndexListener(WidgetSupport support) {\r
+               public AddEnumerationIndexListener(WidgetSupport support) {\r
                        support.register(this);\r
                }\r
 \r
@@ -177,10 +190,15 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
                @Override\r
                public void widgetSelected(SelectionEvent e) {\r
                        try {\r
-                               SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+                           \r
+                           currentItemCount = getCurrentItemCount();\r
+                           lastItemCount = currentItemCount;\r
+                           \r
+                               Simantics.getSession().syncRequest(new WriteRequest() {\r
 \r
                                        @Override\r
                                        public void perform(WriteGraph graph) throws DatabaseException {\r
+                                           graph.markUndoPoint();\r
                                                SysdynResource sr = SysdynResource.getInstance(graph);\r
                                                Layer0 l0 = Layer0.getInstance(graph);\r
                                                \r
@@ -195,8 +213,17 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
                                                ArrayList<Resource> index = new ArrayList<Resource>();\r
                                                index.add(ei);\r
                                                ListUtils.insertBack(graph, enumerationIndexes, index);\r
+                                               \r
+                        List<Resource> list = ListUtils.toList(graph, enumerationIndexes);\r
+                        if (!list.isEmpty())\r
+                            updateRemoveButton(true);\r
+                                               \r
+                                               Layer0Utils.addCommentMetadata(graph, "Added new Enumeration Index " + NameUtils.getSafeName(graph, ei) + " to " + enumerationIndexes);\r
                                        }\r
                                });\r
+                               \r
+                               enableItemForRename();\r
+                               \r
                        } catch (DatabaseException e1) {\r
                                e1.printStackTrace();\r
                        }\r
@@ -205,16 +232,16 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
 \r
                @Override\r
                public void widgetDefaultSelected(SelectionEvent e) {\r
-\r
+                   System.out.println("asd");\r
                }\r
 \r
        }\r
 \r
-       private class removeEnumerationIndexListener implements SelectionListener, Widget {\r
+       private class RemoveEnumerationIndexListener implements SelectionListener, Widget {\r
 \r
                Resource enumerationIndexes;\r
 \r
-               public removeEnumerationIndexListener(WidgetSupport support) {\r
+               public RemoveEnumerationIndexListener(WidgetSupport support) {\r
                        support.register(this);\r
                }\r
 \r
@@ -227,6 +254,9 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
                                        @Override\r
                                        public void run(ReadGraph graph) throws DatabaseException {\r
                                                enumerationIndexes = graph.getSingleObject(enumeration, SysdynResource.getInstance(graph).Enumeration_enumerationIndexList);\r
+                                               List<Resource> list = ListUtils.toList(graph, enumerationIndexes);\r
+                                               if (list.isEmpty())\r
+                                                   updateRemoveButton(false);\r
                                        }\r
                                });\r
                        } catch (DatabaseException e) {\r
@@ -240,16 +270,21 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
                        final IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection();\r
 \r
                        try {\r
-                               SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+                               Simantics.getSession().syncRequest(new WriteRequest() {\r
 \r
                                        @Override\r
                                        public void perform(WriteGraph graph) throws DatabaseException {\r
+                                           graph.markUndoPoint();\r
                                                for(Object o : selection.toList()) {\r
                                                        Resource r = AdaptionUtils.adaptToSingle(o, Resource.class);\r
                                                        if(r == null)\r
                                                                continue;\r
                                                        ListUtils.removeElement(graph, enumerationIndexes, r);\r
                                                }\r
+                                               List<Resource> list = ListUtils.toList(graph, enumerationIndexes);\r
+                                               if (list.isEmpty())\r
+                                                   updateRemoveButton(false);\r
+                                               Layer0Utils.addCommentMetadata(graph, "Removed Enumeration Index " );\r
                                        }\r
                                });\r
                        } catch (DatabaseException e1) {\r
@@ -331,10 +366,11 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
                        public void widgetSelected(SelectionEvent e) {\r
                                final boolean selected = showAll.getWidget().getSelection();\r
                                try {\r
-                                       SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+                                       Simantics.getSession().syncRequest(new WriteRequest() {\r
 \r
                                                @Override\r
                                                public void perform(WriteGraph graph) throws DatabaseException {\r
+                                                   graph.markUndoPoint();\r
                                                        SysdynResource sr = SysdynResource.getInstance(graph);\r
                                                        List<Resource> indexes = ListUtils.toList(graph, enumerationIndexes);\r
                                                        for(Resource index : indexes) {\r
@@ -345,7 +381,7 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
                                                                        graph.claimLiteral(index, sr.EnumerationIndex_showEnumerationIndexInCharts, false, Bindings.BOOLEAN);\r
                                                                }\r
                                                        }\r
-                                                       \r
+                                                       Layer0Utils.addCommentMetadata(graph, "Modified Show all in charts");\r
                                                        updateModelResults(graph);\r
                                                }\r
                                        });\r
@@ -385,4 +421,87 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
        public void setInput(ISessionContext context, Object input) {\r
                variable = AdaptionUtils.adaptToSingle(input, Variable.class);\r
        }\r
+       \r
+       private void updateRemoveButton(final boolean enable) {\r
+           SWTThread.getThreadAccess().asyncExec(new Runnable() {\r
+            \r
+            @Override\r
+            public void run() {\r
+                remove.getWidget().setEnabled(enable);\r
+                if (!enable)\r
+                    add.getWidget().setFocus();\r
+            }\r
+        });\r
+       }\r
+       \r
+       private int currentItemCount = 0;\r
+       private int lastItemCount = 0;\r
+       \r
+       private void enableItemForRename() {\r
+           \r
+           \r
+           \r
+           Job j = new Job("") {\r
+\r
+            @Override\r
+            protected IStatus run(IProgressMonitor monitor) {\r
+                \r
+                while (lastItemCount == currentItemCount) {\r
+                    SWTThread.getThreadAccess().syncExec(new Runnable() {\r
+\r
+                        @Override\r
+                        public void run() {\r
+                            lastItemCount = getCurrentItemCount();\r
+                        }\r
+                    });\r
+                    try {\r
+                        Thread.sleep(50);\r
+                    } catch (InterruptedException e) {\r
+                        e.printStackTrace();\r
+                    }\r
+                }\r
+                \r
+                SWTThread.getThreadAccess().syncExec(new Runnable() {\r
+                    \r
+                    @Override\r
+                    public void run() {\r
+                        Control c = indexExplorer.getExplorer().getControl();\r
+                        if (c instanceof Tree) {\r
+                            Tree tree = (Tree) c;    \r
+                            TreeItem[] items = tree.getItems();\r
+                            TreeItem lastItem = items[items.length - 1];\r
+                            tree.setSelection(lastItem);\r
+                        }\r
+                    }\r
+                });\r
+                \r
+                SWTThread.getThreadAccess().syncExec(new Runnable() {\r
+                    \r
+                    @Override\r
+                    public void run() {\r
+                        Control c = indexExplorer.getExplorer().getControl();\r
+                        if (c instanceof Tree) {\r
+                            Tree tree = (Tree) c;    \r
+                            TreeItem[] items = tree.getItems();\r
+                            TreeItem lastItem = items[items.length - 1];\r
+                            NodeContext context = (NodeContext)lastItem.getData();\r
+                            tree.setSelection(lastItem);\r
+                            indexExplorer.getExplorer().startEditing(context, ColumnKeys.SINGLE); \r
+                            tree.setSelection(lastItem);\r
+                        }\r
+                    }\r
+                });\r
+                \r
+                return Status.OK_STATUS;\r
+            }\r
+           };\r
+           j.schedule();\r
+       }\r
+       \r
+       public int getCurrentItemCount() {\r
+        Control c = indexExplorer.getExplorer().getControl();\r
+        Tree tree = (Tree) c;    \r
+        return tree.getItemCount();\r
+       }\r
 }\r
+\r
index ff7b7021f570ccb8a2434eacc86d2b305e5ac013..b2ca447bdb556b7d77cbbe1fe31725851eadd2d9 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
 \r
+import org.simantics.Simantics;\r
 import org.simantics.browsing.ui.common.node.AbstractNode;\r
 import org.simantics.browsing.ui.common.node.IDoubleClickableNode;\r
 import org.simantics.browsing.ui.common.node.IModifiableNode;\r
@@ -8,12 +9,13 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.Layer0Utils;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.utils.VariableNameValidator;\r
-import org.simantics.ui.SimanticsUI;\r
 \r
 public class EnumerationIndexNode  extends AbstractNode<Resource> implements IModifiableNode, IDoubleClickableNode {\r
 \r
@@ -38,7 +40,7 @@ public class EnumerationIndexNode  extends AbstractNode<Resource> implements IMo
 \r
                 };\r
                 try {\r
-                    return SimanticsUI.getSession().syncRequest(request);\r
+                    return Simantics.getSession().syncRequest(request);\r
                 } catch (DatabaseException e) {\r
                     e.printStackTrace();\r
                     return "";\r
@@ -54,7 +56,7 @@ public class EnumerationIndexNode  extends AbstractNode<Resource> implements IMo
 \r
             @Override\r
             public void modify(final String label) {\r
-               SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+               Simantics.getSession().asyncRequest(new WriteRequest() {\r
                     @Override\r
                     public void perform(WriteGraph graph) throws DatabaseException {\r
                         graph.claimLiteral(data, Layer0.getInstance(graph).HasName, label);\r
@@ -78,11 +80,13 @@ public class EnumerationIndexNode  extends AbstractNode<Resource> implements IMo
        \r
        public void setShowInChartsSelected(final boolean selected) {\r
        try {\r
-                       SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+                       Simantics.getSession().syncRequest(new WriteRequest() {\r
                            @Override\r
                            public void perform(WriteGraph graph) throws DatabaseException {\r
+                               graph.markUndoPoint();\r
                                SysdynResource sr = SysdynResource.getInstance(graph);\r
                                graph.claimLiteral(data, sr.EnumerationIndex_showEnumerationIndexInCharts, selected);\r
+                               Layer0Utils.addCommentMetadata(graph, "Modified show in chart of " + NameUtils.getSafeName(graph, data) +  " to " + selected);\r
                            }\r
                        });\r
                } catch (DatabaseException e) {\r