From 8f8e745777ba9158b16c7927646200c7cf2c8d7c Mon Sep 17 00:00:00 2001 From: Miro Richard Eklund Date: Tue, 31 Jul 2018 13:43:02 +0300 Subject: [PATCH] Change mode to operation in Spreadsheet when changing sheets gitlab #70 Change-Id: I0735e72d817b3d1c7287ecfe0c6e2473bac32a01 --- .../spreadsheet/ui/SpreadsheetModel.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) 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(); -- 2.47.1