]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Allow selection of modules to rename through checkboxes and Select All/Clear Selectio...
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 26 Sep 2016 13:07:37 +0000 (16:07 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 26 Sep 2016 13:07:37 +0000 (16:07 +0300)
refs #6708
[PRIVATE-11320]

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/RenameDiagramComponents.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/renaming/ComponentsRenamingDialog.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/renaming/ComponentsRenamingModel.java

index fd824f2bc40e0952cd7706bb4e455c3d1bf83de3..5801213e892266d54a1b1b59a592ba27bcbe3126 100644 (file)
@@ -8,7 +8,7 @@ import org.simantics.Simantics;
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.request.UniqueRead;\r
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.adapter.ActionFactory;\r
@@ -30,12 +30,11 @@ public class RenameDiagramComponents implements ActionFactory {
         return new Runnable() {\r
             @Override\r
             public void run() {\r
-                final ComponentsRenamingModel model = new ComponentsRenamingModel();\r
                 try {\r
-                    Simantics.getSession().syncRequest(new ReadRequest() {\r
+                    ComponentsRenamingModel model = Simantics.getSession().syncRequest(new UniqueRead<ComponentsRenamingModel>() {\r
                         @Override\r
-                        public void run(ReadGraph graph) throws DatabaseException {\r
-                            model.read(graph, composite);\r
+                        public ComponentsRenamingModel perform(ReadGraph graph) throws DatabaseException {\r
+                            return new ComponentsRenamingModel().read(graph, composite);\r
                         }\r
                     });\r
                     ComponentsRenamingDialog dialog = new ComponentsRenamingDialog(\r
index 8a73bed10bec36ea7acadaa0e1340cb71624cfba..2af483185079ad8be63143c1a39aab49b5f0abf1 100644 (file)
@@ -1,11 +1,18 @@
 package org.simantics.modeling.ui.diagram.renaming;\r
 \r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
 import org.eclipse.jface.dialogs.Dialog;\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.jface.viewers.ArrayContentProvider;\r
+import org.eclipse.jface.viewers.CheckStateChangedEvent;\r
+import org.eclipse.jface.viewers.CheckboxTableViewer;\r
 import org.eclipse.jface.viewers.ColumnLabelProvider;\r
-import org.eclipse.jface.viewers.TableViewer;\r
+import org.eclipse.jface.viewers.ICheckStateListener;\r
+import org.eclipse.jface.viewers.ICheckStateProvider;\r
+import org.eclipse.jface.viewers.StructuredSelection;\r
 import org.eclipse.jface.viewers.TableViewerColumn;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.events.ModifyEvent;\r
@@ -14,6 +21,7 @@ import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;\r
 import org.eclipse.swt.layout.GridData;\r
 import org.eclipse.swt.layout.GridLayout;\r
+import org.eclipse.swt.layout.RowLayout;\r
 import org.eclipse.swt.widgets.Button;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Control;\r
@@ -21,6 +29,7 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Label;\r
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.swt.widgets.Text;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
 \r
 public class ComponentsRenamingDialog extends Dialog {\r
 \r
@@ -33,7 +42,7 @@ public class ComponentsRenamingDialog extends Dialog {
     Text newNamePrefix;\r
     Label errorLabel;\r
     Text error;\r
-    TableViewer tableViewer;\r
+    CheckboxTableViewer tableViewer;\r
 \r
     public ComponentsRenamingDialog(Shell parentShell, ComponentsRenamingModel model) {\r
         super(parentShell);\r
@@ -126,11 +135,23 @@ public class ComponentsRenamingDialog extends Dialog {
         \r
         // Name table\r
         \r
-        tableViewer = new TableViewer(composite);\r
+        tableViewer = CheckboxTableViewer.newCheckList(composite,\r
+                SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);\r
+\r
         tableViewer.getTable().setHeaderVisible(true);\r
         GridDataFactory.fillDefaults().grab(true, true).applyTo(tableViewer.getTable());\r
         \r
         tableViewer.setContentProvider(ArrayContentProvider.getInstance());\r
+        tableViewer.setCheckStateProvider(new ICheckStateProvider() {\r
+            @Override\r
+            public boolean isGrayed(Object element) {\r
+                return false;\r
+            }\r
+            @Override\r
+            public boolean isChecked(Object element) {\r
+                return model.selectedEntries.contains(element);\r
+            }\r
+        });\r
         \r
         TableViewerColumn oldNameColumn = new TableViewerColumn(tableViewer, SWT.NONE);\r
         oldNameColumn.getColumn().setText("Old name");\r
@@ -153,9 +174,59 @@ public class ComponentsRenamingDialog extends Dialog {
                 return entry.newName;\r
             }\r
         });\r
+        tableViewer.addCheckStateListener(new ICheckStateListener() {\r
+            void addOrRemoveSelection(NameEntry entry, boolean add) {\r
+                if (add)\r
+                    model.selectedEntries.add(entry);\r
+                else\r
+                    model.selectedEntries.remove(entry);\r
+            }\r
+            @Override\r
+            public void checkStateChanged(CheckStateChangedEvent event) {\r
+                final boolean checked = event.getChecked();\r
+                NameEntry checkedNode = (NameEntry) event.getElement();\r
+\r
+                Set<NameEntry> entries = new HashSet<NameEntry>();\r
+                Set<NameEntry> selection = ISelectionUtils.filterSetSelection(tableViewer.getSelection(), NameEntry.class);\r
+                if (selection.contains(checkedNode))\r
+                    entries.addAll(selection);\r
+                else\r
+                    tableViewer.setSelection(StructuredSelection.EMPTY);\r
+                entries.add(checkedNode);\r
+\r
+                for (NameEntry entry : entries) {\r
+                    addOrRemoveSelection(entry, checked);\r
+                }\r
+\r
+                tableViewer.refresh();\r
+            }\r
+        });\r
         tableViewer.setInput(model.entries.toArray());\r
         newNamePrefix.setFocus();\r
-        \r
+\r
+        // Select All/None button bar\r
+        Composite bar = new Composite(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(bar);\r
+        bar.setLayout(new RowLayout());\r
+        Button selectAll = new Button(bar, SWT.PUSH);\r
+        selectAll.setText("Select &All");\r
+        selectAll.addSelectionListener(new SelectionAdapter() {\r
+            @Override\r
+            public void widgetSelected(SelectionEvent e) {\r
+                model.selectedEntries.addAll(model.entries);\r
+                tableViewer.setAllChecked(true);\r
+            }\r
+        });\r
+        Button clearSelection = new Button(bar, SWT.PUSH);\r
+        clearSelection.setText("&Clear Selection");\r
+        clearSelection.addSelectionListener(new SelectionAdapter() {\r
+            @Override\r
+            public void widgetSelected(SelectionEvent e) {\r
+                model.selectedEntries.clear();\r
+                tableViewer.setAllChecked(false);\r
+            }\r
+        });\r
+\r
         return composite;\r
     }\r
     \r
index 23d2ffa83d723de2f76642d06d1fdbdb3d3ffb30..4df5d4ec0a54be0a1558491b19bb36c4827626eb 100644 (file)
@@ -2,7 +2,9 @@ package org.simantics.modeling.ui.diagram.renaming;
 \r
 import java.util.ArrayList;\r
 import java.util.Collections;\r
+import java.util.HashSet;\r
 import java.util.List;\r
+import java.util.Set;\r
 \r
 import org.eclipse.core.runtime.IStatus;\r
 import org.eclipse.core.runtime.Status;\r
@@ -31,6 +33,7 @@ import org.simantics.structural.stubs.StructuralResource2;
  */\r
 public class ComponentsRenamingModel {\r
     public ArrayList<NameEntry> entries = new ArrayList<NameEntry>();\r
+    public Set<NameEntry> selectedEntries = new HashSet<>();\r
     public String oldNamePrefix;\r
     public String newNamePrefix;\r
     public boolean reset;\r
@@ -41,7 +44,7 @@ public class ComponentsRenamingModel {
     private Resource configuration;\r
     private ComponentNamingStrategy namingStrategy;\r
 \r
-    public void read(ReadGraph g, Resource composite) throws DatabaseException {\r
+    public ComponentsRenamingModel read(ReadGraph g, Resource composite) throws DatabaseException {\r
         this.session = g.getSession();\r
         this.compositeVariable = Variables.getVariable(g, composite);\r
         this.configuration = g.syncRequest(new Configuration(composite));\r
@@ -68,6 +71,11 @@ public class ComponentsRenamingModel {
             prefixValidator = displayValue.getPossiblePropertyValue(g, Variables.INPUT_VALIDATOR);\r
 \r
         this.namingStrategy = ComponentNamingUtil.findNamingStrategy(g, null, composite);\r
+\r
+        // By default, select all entries.\r
+        this.selectedEntries.addAll(entries);\r
+\r
+        return this;\r
     }\r
 \r
     public void computeNewNames() {\r
@@ -125,7 +133,7 @@ public class ComponentsRenamingModel {
         Layer0 L0 = Layer0.getInstance(g);\r
         Layer0X L0X = Layer0X.getInstance(g);\r
         for(NameEntry entry : entries)\r
-            if(!entry.oldName.equals(entry.newName))\r
+            if(!entry.oldName.equals(entry.newName) && selectedEntries.contains(entry))\r
                 g.claimLiteral(entry.resource, L0.HasName, entry.newName, Bindings.STRING);\r
         if(!oldNamePrefix.equals(newNamePrefix))\r
             compositeVariable.setPropertyValue(g, L0X.HasGeneratedNamePrefix, newNamePrefix, Bindings.STRING);\r