From: Miro Richard Eklund Date: Tue, 31 Jul 2018 10:43:02 +0000 (+0300) Subject: Change mode to operation in Spreadsheet when changing sheets X-Git-Tag: v1.43.0~136^2~426 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=8f8e745777ba9158b16c7927646200c7cf2c8d7c;p=simantics%2Fplatform.git Change mode to operation in Spreadsheet when changing sheets gitlab #70 Change-Id: I0735e72d817b3d1c7287ecfe0c6e2473bac32a01 --- diff --git a/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SpreadsheetModel.java b/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SpreadsheetModel.java index 5339796bd..5940cfbe0 100644 --- a/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SpreadsheetModel.java +++ b/bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SpreadsheetModel.java @@ -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 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 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();