/**
  * Set data displayed in JTable
  *
  * @param name the variable name
  * @param type the variable type
  * @param data : data to be displayed in JTable
  */
 public void updateData(String name, String type, Object[][] data) {
   if (map.containsKey(name)) {
     editorTab.updateData(map.get(name), name, type, data);
   } else {
     editorTab.setData(name, type, data);
     map.put(name, tabPane.getSelectedComponent());
   }
 }
 /**
  * Constructor
  *
  * @param type the variable type
  * @param data the JTable data.
  * @param variableName the name in Scilab of the variable being edited.
  */
 private ScilabVariableEditor(String type, Object[][] data, String variableName) {
   super();
   editorTab = new SwingScilabVariableEditor(variableName, type, data);
   tabPane = editorTab.getTabPane();
   TextBox infobar = ScilabTextBox.createTextBox();
   editorTab.addInfoBar(infobar);
   addTab(editorTab);
   map.put(variableName, tabPane.getSelectedComponent());
 }
 /** Close Variable Editor */
 public void close() {
   SwingScilabWindow editvarWindow =
       SwingScilabWindow.allScilabWindows.get(editorTab.getParentWindowId());
   ChangeListener[] cl = tabPane.getChangeListeners();
   for (int i = 0; i < cl.length; i++) {
     tabPane.removeChangeListener(cl[i]);
   }
   instance = null;
   map.clear();
   super.close();
 }
  /**
   * Get the variable editor singleton with specified data.
   *
   * @param type the variable type
   * @param data : the data to fill the editor with
   * @param variableName : the scilab name of the variable being edited.
   * @return the Variable Editor
   */
  public static ScilabVariableEditor getVariableEditor(
      final String type, final Object[][] data, final String variableName) {
    if (instance == null) {
      try {
        SwingUtilities.invokeAndWait(
            new Runnable() {
              public void run() {
                instance = new ScilabVariableEditor(type, data, variableName);
                instance.setVisible(true);
              }
            });
      } catch (Exception e) {
        System.err.println(e);
      }
    } else {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              SwingScilabWindow window =
                  (SwingScilabWindow)
                      SwingUtilities.getAncestorOfClass(SwingScilabWindow.class, editorTab);
              window.setVisible(true);
              window.toFront();
              final JTable table = editorTab.getCurrentTable();
              int r = -1;
              int c = -1;

              if (table != null) {
                r = table.getSelectedRow();
                c = table.getSelectedColumn();
              }
              boolean b = map.containsKey(variableName);
              instance.updateData(variableName, type, data);
              if (b && r != -1 && c != -1) {
                table.setRowSelectionInterval(r, r);
                table.setColumnSelectionInterval(c, c);
              }
            }
          });
    }

    editorTab.setName(
        Messages.gettext("Variable Editor") + " - " + variableName + "  (" + type + ")");
    return instance;
  }
 /** {@inheritDoc} */
 public void setVisible(boolean status) {
   super.setVisible(status);
   editorTab.setVisible(status);
 }
 /**
  * Set data displayed in JTable
  *
  * @param name the variable name
  * @param type the variable type
  * @param data : data to be displayed in JTable
  */
 public void updateData(
     String name, String type, Object[][] data, double[] rowsIndex, double[] colsIndex) {
   if (map.containsKey(name)) {
     editorTab.updateData(map.get(name), name, type, data, rowsIndex, colsIndex);
   }
 }