]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SpreadsheetModel.java
Adopt spreadsheet changes made in Balas development
[simantics/platform.git] / bundles / org.simantics.spreadsheet.ui / src / org / simantics / spreadsheet / ui / SpreadsheetModel.java
index 93f455702591f7ac1d981cf5b91f944377cfc565..137cde7a44832cc160e6825f5cbb4659df0fd667 100644 (file)
@@ -2,6 +2,7 @@ package org.simantics.spreadsheet.ui;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.FlowLayout;
 import java.awt.Font;
 import java.awt.Frame;
@@ -24,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;
@@ -66,25 +68,28 @@ import org.simantics.scenegraph.INode;
 import org.simantics.scenegraph.swing.JScrollPaneSG;
 import org.simantics.spreadsheet.Adaptable;
 import org.simantics.spreadsheet.CellEditor;
-import org.simantics.spreadsheet.CellEditor.Transaction;
 import org.simantics.spreadsheet.ClientModel;
-import org.simantics.spreadsheet.ClientModel.OperationMode;
+import org.simantics.spreadsheet.OperationMode;
 import org.simantics.spreadsheet.SheetCommands;
+import org.simantics.spreadsheet.Spreadsheets;
+import org.simantics.spreadsheet.Transaction;
 import org.simantics.spreadsheet.common.cell.Parsers;
 import org.simantics.spreadsheet.common.cell.StringCellParser;
 import org.simantics.spreadsheet.event.model.RemoveCellHandler;
-import org.simantics.spreadsheet.util.SpreadsheetUtils;
 import org.simantics.ui.colors.Colors;
 import org.simantics.ui.dnd.LocalObjectTransfer;
 import org.simantics.ui.dnd.LocalObjectTransferable;
 import org.simantics.ui.fonts.Fonts;
-import org.simantics.utils.ui.dialogs.ShowMessage;
 import org.simantics.utils.ui.awt.WrapLayout;
+import org.simantics.utils.ui.dialogs.ShowMessage;
 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;
@@ -404,16 +409,16 @@ public class SpreadsheetModel {
                                        for(int col : selectedColumns) {
                                                for(int row : selectedRows) {
                                                        
-                                                       String location = SpreadsheetUtils.cellName(row, col);
+                                                       String location = Spreadsheets.cellName(row, col);
                                                        
                                                        // No
                                                        if(index == 0) {
                                                                if(col > 0) {
-                                                                       String left = SpreadsheetUtils.cellName(row, col-1);
+                                                                       String left = Spreadsheets.cellName(row, col-1);
                                                                        setCurrent(left, getCurrent(left, row, col-1) & 2);
                                                                }
                                                                if(row > 0) {
-                                                                       String up = SpreadsheetUtils.cellName(row-1, col);
+                                                                       String up = Spreadsheets.cellName(row-1, col);
                                                                        setCurrent(up, getCurrent(up, row-1, col) & 1);
                                                                }
                                                                setCurrent(location, 0);
@@ -425,14 +430,14 @@ public class SpreadsheetModel {
                                                        // Top
                                                        else if(index == 2) {
                                                                if(row > 0) {
-                                                                       String up = SpreadsheetUtils.cellName(row-1, col);
+                                                                       String up = Spreadsheets.cellName(row-1, col);
                                                                        setCurrent(up, getCurrent(up, row-1, col) | 2);
                                                                }
                                                        }
                                                        // Left
                                                        else if(index == 3) {
                                                                if(col > 0) {
-                                                                       String left = SpreadsheetUtils.cellName(row, col-1);
+                                                                       String left = Spreadsheets.cellName(row, col-1);
                                                                        setCurrent(left, getCurrent(left, row, col-1) | 1);
                                                                }
                                                        }
@@ -525,7 +530,7 @@ public class SpreadsheetModel {
                                                                if (selection.intersects(span)) {
                                                                        selection = selection.union(span);
                                                                        found = true;
-                                                                       String location = SpreadsheetUtils.cellName(span.y, span.x);
+                                                                       String location = Spreadsheets.cellName(span.y, span.x);
                                                                        editor.edit(transaction, location, ClientModel.ROW_SPAN, 1, Bindings.INTEGER, null);
                                                                        editor.edit(transaction, location, ClientModel.COLUMN_SPAN, 1, Bindings.INTEGER, null);
                                                                        iter.remove();
@@ -533,7 +538,7 @@ public class SpreadsheetModel {
                                                        }
                                                }
                                                
-                                               String location = SpreadsheetUtils.cellName(selection.y, selection.x);
+                                               String location = Spreadsheets.cellName(selection.y, selection.x);
                                                if (selection.height > 1) {
                                                        editor.edit(transaction, location, ClientModel.ROW_SPAN, selection.height, Bindings.INTEGER, null);
                                                }
@@ -600,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);
+                        }
                     }
                 }
             };
@@ -614,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);
+                                               }
                                        }
 
                                }
@@ -691,6 +700,9 @@ public class SpreadsheetModel {
                        etl = new ExpressionTextListener(expression, serverInterface.getAdapter(CellEditor.class));
                        expression.addFocusListener(etl);
                        expression.addKeyListener(etl);
+
+                       //Large default size so that the expression field is clearly visible
+                       expression.setPreferredSize(new Dimension(600, 32));
                        
                     sheets.addItemListener(sheetsListener);
 
@@ -716,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() {
                            
@@ -988,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();
@@ -1023,7 +1042,7 @@ public class SpreadsheetModel {
        private void editSelection(CellEditor editor, Transaction transaction, String property, Object value, Binding binding) { 
                for(int col : table.getSelectedColumns()) {
                        for(int row : table.getSelectedRows()) {
-                               String location = SpreadsheetUtils.cellName(row, col);
+                               String location = Spreadsheets.cellName(row, col);
                                editor.edit(transaction, location, property, value, binding, null);
                        }
                }
@@ -1040,7 +1059,7 @@ public class SpreadsheetModel {
 //             Transaction transaction = editor.startTransaction(); 
                for(int col : selectedColumns) {
                        for(int row : selectedRows) {
-                               String location = SpreadsheetUtils.cellName(row, col);
+                               String location = Spreadsheets.cellName(row, col);
                                
                                CellValue value = (CellValue)table.getValueAt(row, col);
                                int align = value != null ? value.align : 0;