]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Change mode to operation in Spreadsheet when changing sheets 78/1978/1
authorMiro Richard Eklund <miro.eklund@semantum.fi>
Tue, 31 Jul 2018 10:43:02 +0000 (13:43 +0300)
committerMiro Richard Eklund <miro.eklund@semantum.fi>
Tue, 31 Jul 2018 10:43:02 +0000 (13:43 +0300)
gitlab #70

Change-Id: I0735e72d817b3d1c7287ecfe0c6e2473bac32a01

bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SpreadsheetModel.java

index 5339796bddbf62aaa945f1f64dba4f6c7a91ce16..5940cfbe0224a7e73ce495e3c18b196361db65af 100644 (file)
@@ -25,6 +25,7 @@ import java.awt.event.KeyEvent;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -86,6 +87,9 @@ import org.simantics.utils.ui.jface.ActiveSelectionProvider;
 @SuppressWarnings({ "rawtypes", "unchecked" })
 public class SpreadsheetModel {
 
+    final private static String OPERATIONMODE = "Operation Mode";
+    final private static String EDITMODE = "Edit Mode";
+       
        final private Adaptable serverInterface;
        final private ClientModel clientModel;
        final private ActiveSelectionProvider selectionProvider;
@@ -601,9 +605,12 @@ public class SpreadsheetModel {
 
                     CellEditor editor = serverInterface.getAdapter(CellEditor.class);
                     if (editor != null) {
-                        if (arg0.getStateChange() == ItemEvent.SELECTED)
-                            editor.edit(null, ClientModel.SHEETS, ClientModel.SHEETS_CURRENT, arg0.getItem(), null,
-                                    null);
+                        if (arg0.getStateChange() == ItemEvent.SELECTED) {
+                            editor.edit(null, ClientModel.SHEETS, ClientModel.SHEETS_CURRENT, arg0.getItem(), null, null);
+                            HashSet<String> targets = new HashSet<>();
+                            targets.add(ClientModel.MODE);
+                            resetSelections(editor, targets);
+                        }
                     }
                 }
             };
@@ -615,8 +622,9 @@ public class SpreadsheetModel {
                                        
                                        CellEditor editor = serverInterface.getAdapter(CellEditor.class);
                                        if(editor != null) {
-                                               if(arg0.getStateChange() == ItemEvent.SELECTED)
+                                               if(arg0.getStateChange() == ItemEvent.SELECTED) {
                                                        editor.edit(null, ClientModel.SOURCES, ClientModel.SOURCES_CURRENT, arg0.getItem(), null, null);
+                                               }
                                        }
 
                                }
@@ -720,9 +728,9 @@ public class SpreadsheetModel {
                        OperationMode currentMode = clientModel.getPropertyAt(ClientModel.MODE, ClientModel.MODE_CURRENT);
                        String text;
                        if (currentMode.equals(OperationMode.OPERATION))
-                           text = "Operation Mode";
+                           text = OPERATIONMODE;
                        else
-                           text = "Edit Mode";
+                           text = EDITMODE;
                        operationMode = new JToggleButton(text);
                        operationMode.addActionListener(new ActionListener() {
                            
@@ -992,6 +1000,13 @@ public class SpreadsheetModel {
 
        }
 
+       private void resetSelections(CellEditor editor, HashSet<String> targets) {
+               if(targets.contains(ClientModel.MODE)) {
+                       editor.edit(null, ClientModel.MODE, ClientModel.MODE_CURRENT, OperationMode.OPERATION, null, null);
+                       operationMode.setText(OPERATIONMODE);
+               }
+       }
+       
        private boolean isRectangularSelection(SpreadsheetTable table) {
                int[] selectedColumns = table.getSelectedColumns();
                int[] selectedRows = table.getSelectedRows();