Also allow the edition of a variable from a right click 45/11445/5
Sylvestre Ledru [Fri, 3 May 2013 14:08:38 +0000 (16:08 +0200)]
Change-Id: I7e4a58316dc5fb884f8073fbe81c228b0801b052

scilab/modules/gui/Makefile.am
scilab/modules/gui/Makefile.in
scilab/modules/gui/images/icons/16x16/apps/rrze_table.png [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/utils/UiDataMessages.java
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/variablebrowser/SwingScilabVariableBrowser.java
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/variablebrowser/actions/ModifyAction.java [new file with mode: 0644]

index 1f95a7c..bc0b04e 100644 (file)
@@ -315,6 +315,7 @@ images/icons/16x16/animations/process-working.png \
 images/icons/16x16/apps/accessories-text-editor.png \
 images/icons/16x16/apps/datatips.png \
 images/icons/16x16/apps/help-browser.png \
+images/icons/16x16/apps/rrze_table.png \
 images/icons/16x16/apps/scilab.png \
 images/icons/16x16/apps/utilities-system-monitor.png \
 images/icons/16x16/categories/applications-system.png \
index 32190b1..00ae601 100644 (file)
@@ -840,6 +840,7 @@ images/icons/16x16/animations/process-working.png \
 images/icons/16x16/apps/accessories-text-editor.png \
 images/icons/16x16/apps/datatips.png \
 images/icons/16x16/apps/help-browser.png \
+images/icons/16x16/apps/rrze_table.png \
 images/icons/16x16/apps/scilab.png \
 images/icons/16x16/apps/utilities-system-monitor.png \
 images/icons/16x16/categories/applications-system.png \
diff --git a/scilab/modules/gui/images/icons/16x16/apps/rrze_table.png b/scilab/modules/gui/images/icons/16x16/apps/rrze_table.png
new file mode 100644 (file)
index 0000000..b409853
Binary files /dev/null and b/scilab/modules/gui/images/icons/16x16/apps/rrze_table.png differ
index a3dd201..539e794 100644 (file)
@@ -32,6 +32,7 @@ public final class UiDataMessages {
     public static final String FILE = Messages.gettext("File");
     public static final String CLOSE = Messages.gettext("Close");
     public static final String DELETE = Messages.gettext("Delete");
+    public static final String MODIFY = Messages.gettext("Modify");
     public static final String FILTER = Messages.gettext("Filter");
 
     public static final String SCILABVAR = Messages.gettext("Hide Scilab variables");
index 256d982..65aab05 100644 (file)
@@ -88,6 +88,7 @@ import org.scilab.modules.ui_data.variableeditor.actions.ExportToCsvAction;
 import org.scilab.modules.ui_data.variableeditor.actions.PlotAction;
 import org.scilab.modules.ui_data.variablebrowser.actions.CloseAction;
 import org.scilab.modules.ui_data.variablebrowser.actions.DeleteAction;
+import org.scilab.modules.ui_data.variablebrowser.actions.ModifyAction;
 import org.scilab.modules.ui_data.variablebrowser.actions.RefreshAction;
 import org.scilab.modules.ui_data.variablebrowser.rowfilter.VariableBrowserRowDataFilter;
 import org.scilab.modules.ui_data.variablebrowser.rowfilter.VariableBrowserRowTypeFilter;
@@ -149,6 +150,7 @@ public final class SwingScilabVariableBrowser extends SwingScilabTab implements
         ToolBar toolBar = ScilabToolBar.createToolBar();
         toolBar.add(RefreshAction.createButton(UiDataMessages.REFRESH));
         toolBar.addSeparator();
+        toolBar.add(ModifyAction.createButton(this, UiDataMessages.MODIFY));
         toolBar.add(DeleteAction.createButton(this, UiDataMessages.DELETE));
         toolBar.addSeparator();
         toolBar.add(HelpAction.createButton(UiDataMessages.HELP));
@@ -341,6 +343,10 @@ public final class SwingScilabVariableBrowser extends SwingScilabTab implements
                 int clickedRow = ((JTable) e.getSource()).rowAtPoint(e.getPoint());
                 // Does nothing if no variable selected
                 if (clickedRow != -1) {
+                    // Right click ? We force the selection of the current row
+                    table.setRowSelectionInterval(clickedRow, clickedRow);
+                    table.setEditingRow(clickedRow);
+
                     displayContextMenu();
                 }
             }
@@ -352,37 +358,7 @@ public final class SwingScilabVariableBrowser extends SwingScilabTab implements
 
                     String variableVisibility = ((JTable) e.getSource())
                                                 .getValueAt(((JTable) e.getSource()).getSelectedRow(), BrowseVar.VISIBILITY_COLUMN_INDEX).toString();
-
-                    // Global variables are not editable yet
-                    if (variableVisibility.equals("global")) {
-                        ScilabModalDialog.show(getBrowserTab(),
-                                               UiDataMessages.GLOBAL_NOT_EDITABLE,
-                                               UiDataMessages.VARIABLE_EDITOR,
-                                               IconType.ERROR_ICON);
-                        return;
-                    }
-
-                    try {
-                        asynchronousScilabExec(null,
-                                               "if exists(\"" + variableName + "\") == 1 then "
-                                               + "  try "
-                                               + "    editvar(\"" + variableName + "\"); "
-                                               + "  catch "
-                                               + "    messagebox(\"Variables of type \"\"\" + typeof ("
-                                               + variableName + ") + \"\"\" can not be edited.\""
-                                               + ",\"" + UiDataMessages.VARIABLE_EDITOR + "\", \"error\", \"modal\");"
-                                               + "    clear ans;"   // clear return value of messagebox
-                                               + "  end "
-                                               + "else "
-                                               + "  messagebox(\"Variable \"\""
-                                               + variableName + "\"\" no more exists.\""
-                                               + ",\"" + UiDataMessages.VARIABLE_EDITOR + "\", \"error\", \"modal\");"
-                                               + "  clear ans;"  // clear return value of messagebox
-                                               + "  browsevar();" // Reload browsevar to remove cleared variables
-                                               + "end");
-                    } catch (InterpreterException e1) {
-                        System.err.println("An error in the interpreter has been catched: " + e1.getLocalizedMessage());
-                    }
+                    SwingScilabVariableBrowser.this.startEditVar(variableVisibility, variableName);
                 }
             }
         }
@@ -425,6 +401,8 @@ public final class SwingScilabVariableBrowser extends SwingScilabTab implements
          */
         private void displayContextMenu() {
             ContextMenu menu = ScilabContextMenu.createContextMenu();
+            ModifyAction modify = new ModifyAction(SwingScilabVariableBrowser.this);
+            menu.add(modify.createMenuItem());
 
             DeleteAction delete = new DeleteAction(SwingScilabVariableBrowser.this);
             menu.add(delete.createMenuItem());
@@ -666,4 +644,44 @@ public final class SwingScilabVariableBrowser extends SwingScilabTab implements
     public JTable getTable() {
         return table;
     }
+
+    /**
+     * Start the variable editor
+     *
+     * @param variableVisibility the visibility of the variable
+     * @param variableName The variable name
+     */
+    public void startEditVar(String variableVisibility, String variableName) {
+        // Global variables are not editable yet
+        if (variableVisibility.equals("global")) {
+            ScilabModalDialog.show(getBrowserTab(),
+                                   UiDataMessages.GLOBAL_NOT_EDITABLE,
+                                   UiDataMessages.VARIABLE_EDITOR,
+                                   IconType.ERROR_ICON);
+            return;
+        }
+
+        try {
+            asynchronousScilabExec(null,
+                                   "if exists(\"" + variableName + "\") == 1 then "
+                                   + "  try "
+                                   + "    editvar(\"" + variableName + "\"); "
+                                   + "  catch "
+                                   + "    messagebox(\"Variables of type \"\"\" + typeof ("
+                                   + variableName + ") + \"\"\" can not be edited.\""
+                                   + ",\"" + UiDataMessages.VARIABLE_EDITOR + "\", \"error\", \"modal\");"
+                                   + "    clear ans;"   // clear return value of messagebox
+                                   + "  end "
+                                   + "else "
+                                   + "  messagebox(\"Variable \"\""
+                                   + variableName + "\"\" no more exists.\""
+                                   + ",\"" + UiDataMessages.VARIABLE_EDITOR + "\", \"error\", \"modal\");"
+                                   + "  clear ans;"  // clear return value of messagebox
+                                   + "  browsevar();" // Reload browsevar to remove cleared variables
+                                   + "end");
+        } catch (InterpreterException e1) {
+            System.err.println("An error in the interpreter has been catched: " + e1.getLocalizedMessage());
+        }
+    }
+
 }
diff --git a/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/variablebrowser/actions/ModifyAction.java b/scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/variablebrowser/actions/ModifyAction.java
new file mode 100644 (file)
index 0000000..01faffc
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - DIGITEO - Vincent COUVERT
+ * Copyright (C) 2013 - S/E - Sylvestre Ledru
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.ui_data.variablebrowser.actions;
+
+import org.scilab.modules.ui_data.variablebrowser.SwingScilabVariableBrowser;
+import java.lang.reflect.InvocationTargetException;
+import java.awt.event.ActionEvent;
+import javax.swing.ImageIcon;
+import javax.swing.KeyStroke;
+import java.awt.event.ActionEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.ActionListener;
+import javax.swing.JTable;
+
+import org.scilab.modules.ui_data.utils.UiDataMessages;
+import org.scilab.modules.ui_data.BrowseVar;
+
+import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.asynchronousScilabExec;
+
+import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.InterpreterException;
+
+import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
+import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
+import org.scilab.modules.gui.events.callback.CommonCallBack;
+import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.gui.menuitem.ScilabMenuItem;
+import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.pushbutton.ScilabPushButton;
+import org.scilab.modules.gui.utils.ScilabSwingUtilities;
+
+/**
+ * Manage Modify Actions
+ * @author Vincent COUVERT
+ */
+public final class ModifyAction extends CommonCallBack {
+
+    private static final long serialVersionUID = 1L;
+
+    private static ImageIcon icon = new ImageIcon(ScilabSwingUtilities.findIcon("rrze_table"));
+
+    private static final char MNEMONIC = 'M';
+
+    private static final String KEY = "MODIFY";
+    //    private static final String SUPPR = "Suppr";
+
+    private final SwingScilabVariableBrowser variableBrowser;
+
+    /**
+     * Constructor
+     */
+    public ModifyAction(SwingScilabVariableBrowser variableBrowser) {
+        super("");
+        this.variableBrowser = variableBrowser;
+    }
+
+    /**
+     * Create a button for a tool bar
+     * @param title tooltip for the button
+     * @return the button
+     */
+    public static PushButton createButton(SwingScilabVariableBrowser variableBrowser, String title) {
+        PushButton button = ScilabPushButton.createPushButton();
+        ((SwingScilabPushButton) button.getAsSimplePushButton()).addActionListener(new ModifyAction(variableBrowser));
+        button.setToolTipText(title);
+        ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(icon);
+
+        return button;
+    }
+
+    /**
+     * Create the associated menu
+     * @return the menu
+     */
+    public MenuItem createMenuItem() {
+        MenuItem menuItem = ScilabMenuItem.createMenuItem();
+        menuItem.setText(UiDataMessages.MODIFY + " '" + getSelectedVariable() + "'");
+        menuItem.setMnemonic(MNEMONIC);
+        menuItem.setCallback(this);
+        ((SwingScilabMenuItem) menuItem.getAsSimpleMenuItem()).setIcon(icon);
+        return menuItem;
+    }
+
+
+    /**
+     * Action!
+     * @see org.scilab.modules.gui.events.callback.CallBack#callBack()
+     */
+    @Override
+    public void callBack() {
+        variableBrowser.startEditVar(getSelectedVariableVisibility(), getSelectedVariable());
+
+    }
+
+    private String getSelectedVariable() {
+
+        int clickedRow = variableBrowser.getTable().getSelectedRow();
+        // Does nothing if no variable selected
+        if (clickedRow != -1) {
+            return variableBrowser.getTable().getValueAt(clickedRow, BrowseVar.NAME_COLUMN_INDEX).toString();
+        }
+        return "";
+    }
+
+    private String getSelectedVariableVisibility() {
+
+        int clickedRow = variableBrowser.getTable().getSelectedRow();
+        // Does nothing if no variable selected
+        if (clickedRow != -1) {
+            return variableBrowser.getTable().getValueAt(clickedRow, BrowseVar.VISIBILITY_COLUMN_INDEX).toString();
+        }
+        return "";
+    }
+}