/**
  * tests if there should be an empty row appended
  *
  * @param inserting is set: the selected cell will be filled but is not yet
  */
 public void addRow(boolean inserting) {
   int row = replaceTable.getSelectedRow();
   int col = replaceTable.getSelectedColumn();
   if (row + 1 == replaceTable.getRowCount() && col >= 0) {
     boolean[] colSet = new boolean[2];
     colSet[0] = !data.lastElement().firstElement().equals("");
     colSet[1] = !data.lastElement().lastElement().equals("");
     colSet[col] = colSet[col] || inserting;
     if (colSet[0] && colSet[1]) {
       TableCellEditor editor = replaceTable.getCellEditor();
       if (editor != null) {
         row = replaceTable.getEditingRow();
         col = replaceTable.getEditingColumn();
         data.get(row).set(col, editor.getCellEditorValue().toString());
       }
       data.add(new Vector<String>(Arrays.asList(new String[] {"", ""})));
       replaceTable.revalidate();
       CASSubDialog.this.pack();
       Rectangle r = replaceTable.getCellRect(replaceTable.getRowCount() - 1, col, false);
       scrollPane.getViewport().scrollRectToVisible(r);
       if (editor != null) {
         replaceTable.editCellAt(row, col);
       }
     }
   }
 }
    public void keyPressed(KeyEvent keyEvent) {
      AppLogger.finest(
          "keyModifiers=" + keyEvent.getModifiers() + " keyCode=" + keyEvent.getKeyCode());

      int keyCode = keyEvent.getKeyCode();
      if (keyCode == KeyEvent.VK_SHIFT
          || keyCode == KeyEvent.VK_CONTROL
          || keyCode == KeyEvent.VK_ALT
          || keyCode == KeyEvent.VK_META) return;

      KeyStroke pressedKeyStroke = KeyStroke.getKeyStrokeForEvent(keyEvent);

      if (pressedKeyStroke.equals(lastKeyStroke)) {
        TableCellEditor activeCellEditor = getCellEditor();
        if (activeCellEditor != null) activeCellEditor.stopCellEditing();
      } else {
        String actionId;
        if ((actionId = data.contains(pressedKeyStroke)) != null) {
          String errorMessage =
              "The shortcut ["
                  + KeyStrokeUtils.getKeyStrokeDisplayableRepresentation(pressedKeyStroke)
                  + "] is already assigned to '"
                  + ActionProperties.getActionDescription(actionId)
                  + "'";
          tooltipBar.showErrorMessage(errorMessage);
          createCancelEditingStateThread(getCellEditor());
        } else {
          lastKeyStroke = pressedKeyStroke;
          setText(KeyStrokeUtils.getKeyStrokeDisplayableRepresentation(lastKeyStroke));
        }
      }

      keyEvent.consume();
    }
 // region Private Methods
 private static void stopCellEditing(JTable table) {
   if (table.getRowCount() > 0) {
     TableCellEditor editor = table.getCellEditor();
     if (editor != null) {
       editor.stopCellEditing();
     }
   }
 }
 /** Invoked when an action occurs. */
 public void actionPerformed(final ActionEvent e) {
   final TableCellEditor tableCellEditor = parameterMappingTable.getCellEditor();
   if (tableCellEditor != null) {
     tableCellEditor.stopCellEditing();
   }
   final ParameterMappingTableModel tableModel =
       (ParameterMappingTableModel) parameterMappingTable.getModel();
   tableModel.addRow();
 }
Beispiel #5
0
 @Override
 protected void succeeded(Profesor result) {
   modelo.addDato(result);
   int row = tabla.getRowCount() - 1;
   tabla.scrollRowToVisible(row);
   tabla.editCellAt(row, 0);
   tabla.requestFocus();
   TableCellEditor tce = tabla.getCellEditor(row, 0);
   tce.shouldSelectCell(new ListSelectionEvent(tabla, row, row, false));
 }
Beispiel #6
0
 @Override
 protected void succeeded(Usuario result) {
   modelo.addDato(result);
   int row = tabla.convertRowIndexToView(modelo.indexOf(result));
   tabla.scrollRowToVisible(row);
   tabla.editCellAt(row, 0);
   tabla.requestFocus();
   TableCellEditor tce = tabla.getCellEditor(row, 0);
   tce.shouldSelectCell(new ListSelectionEvent(tabla, row, row, false));
 }
 @Override
 public void removeEditor() {
   TableCellEditor editor = getCellEditor();
   // must be called here to remove the editor and to avoid an infinite
   // loop, because the table is an editor listener and the
   // editingCanceled method calls this removeEditor method
   super.removeEditor();
   if (editor != null) {
     editor.cancelCellEditing();
   }
 }
    /** Invoked when an action occurs. */
    public void actionPerformed(final ActionEvent e) {
      final TableCellEditor tableCellEditor = parameterMappingTable.getCellEditor();
      if (tableCellEditor != null) {
        tableCellEditor.stopCellEditing();
      }
      final int i = parameterMappingTable.getSelectedRow();
      if (i == -1) {
        return;
      }

      final ParameterMappingTableModel tableModel =
          (ParameterMappingTableModel) parameterMappingTable.getModel();
      tableModel.removeRow(i);
    }
  private static void changeTableFont(JTable table, Font f) {
    UIDefaults nimbusOverrides = new UIDefaults();
    nimbusOverrides.put("Table.font", new FontUIResource(f));
    table.putClientProperty("Nimbus.Overrides", nimbusOverrides);

    TableCellEditor editor = table.getCellEditor();
    if (editor != null) {
      editor.cancelCellEditing();
    }
    FontMetrics fm = table.getFontMetrics(f);
    int h = fm.getHeight() + 8;
    table.setRowHeight(h);
    SwingUtilities.updateComponentTreeUI(table);
  }
  public boolean editCellAt(final int row, final int column, final EventObject e) {
    if (cellEditor != null && !cellEditor.stopCellEditing()) {
      return false;
    }

    if (row < 0 || row >= getRowCount() || column < 0 || column >= getColumnCount()) {
      return false;
    }

    if (!isCellEditable(row, column)) {
      return false;
    }

    if (myEditorRemover == null) {
      final KeyboardFocusManager keyboardFocusManager =
          KeyboardFocusManager.getCurrentKeyboardFocusManager();
      myEditorRemover = new MyCellEditorRemover();
      //noinspection HardCodedStringLiteral
      keyboardFocusManager.addPropertyChangeListener("focusOwner", myEditorRemover);
      //noinspection HardCodedStringLiteral
      keyboardFocusManager.addPropertyChangeListener("permanentFocusOwner", myEditorRemover);
    }

    final TableCellEditor editor = getCellEditor(row, column);
    if (editor != null && editor.isCellEditable(e)) {
      editorComp = prepareEditor(editor, row, column);
      // ((JComponent)editorComp).setBorder(null);
      if (editorComp == null) {
        removeEditor();
        return false;
      }
      editorComp.setBounds(getCellRect(row, column, false));
      add(editorComp);
      editorComp.validate();

      IdeFocusManager.findInstanceByComponent(this).requestFocus(editorComp, false);

      setCellEditor(editor);
      setEditingRow(row);
      setEditingColumn(column);
      editor.addCellEditorListener(this);
      if (isTypeAhead) {
        JTableCellEditorHelper.typeAhead(this, e, row, column);
      }
      return true;
    }
    return false;
  }
 /**
  * Sets the new figure retrieved from the passed collection.
  *
  * @param l The collection to handle.
  */
 void setSelectedFigures(List<ROIShape> l) {
   FigureTableModel tableModel = (FigureTableModel) fieldTable.getModel();
   Iterator<ROIShape> i = l.iterator();
   // Register error and notify user.
   ROIShape shape;
   try {
     TableCellEditor editor = fieldTable.getCellEditor();
     if (editor != null) editor.stopCellEditing();
     while (i.hasNext()) {
       shape = i.next();
       tableModel.setData(shape.getFigure());
       fieldTable.repaint();
     }
   } catch (Exception e) {
     MeasurementAgent.getRegistry().getLogger().info(this, "Figures selection" + e);
   }
 }
Beispiel #12
0
  public Component getTableCellEditorComponent(
      JTable table, Object value, boolean isSelected, int row, int column) {

    // editor = (TableCellEditor)editors.get(new Integer(row));
    // if (editor == null) {
    //  editor = defaultEditor;
    // }
    return editor.getTableCellEditorComponent(table, value, isSelected, row, column);
  }
    @Override
    public void run() {
      try {
        Thread.sleep(CELL_EDITING_STATE_PERIOD);
      } catch (InterruptedException e) {
      }

      if (!stopped && cellEditor != null) cellEditor.stopCellEditing();
    }
  public void openEditWindow() {
    if (!table.isEditing()) return;

    int col = table.getEditingColumn();
    int row = table.getEditingRow();
    String data = null;
    TableCellEditor editor = table.getCellEditor();

    if (editor instanceof WbTextCellEditor) {
      WbTextCellEditor wbeditor = (WbTextCellEditor) editor;
      if (table.isEditing() && wbeditor.isModified()) {
        data = wbeditor.getText();
      } else {
        data = table.getValueAsString(row, col);
      }
    } else {
      data = (String) editor.getCellEditorValue();
    }

    Window owner = SwingUtilities.getWindowAncestor(table);
    Frame ownerFrame = null;
    if (owner instanceof Frame) {
      ownerFrame = (Frame) owner;
    }

    String title = ResourceMgr.getString("TxtEditWindowTitle");
    EditWindow w = new EditWindow(ownerFrame, title, data);
    try {
      w.setVisible(true);
      if (editor != null) {
        // we need to "cancel" the editor so that the data
        // in the editor component will not be written into the
        // table model!
        editor.cancelCellEditing();
      }
      if (!w.isCancelled()) {
        table.setValueAt(w.getText(), row, col);
      }
    } finally {
      w.dispose();
    }
  }
Beispiel #15
0
 @Override
 public void editingStopped(ChangeEvent e) {
   TableCellEditor cellEditor = getCellEditor();
   String signalName = signals.get(editingRow);
   if ((cellEditor != null) && (signalName != null)) {
     SignalData signalData = signalDataMap.get(signalName);
     Object value = cellEditor.getCellEditorValue();
     if ((signalData != null) && (value != null)) {
       switch (editingColumn) {
         case COLUMN_VISIBILE:
           signalData.visible = (Boolean) value;
           break;
         case COLUMN_COLOR:
           signalData.color = (Color) value;
           break;
       }
       setValueAt(value, editingRow, editingColumn);
       removeEditor();
     }
   }
 }
    public void tableChanged(TableModelEvent e) {
      // in case the table changes for the following reasons:
      // * the editing row has changed
      // * the editing row was removed
      // * all rows were changed
      // * rows were added
      //
      // it is better to cancel the editing of the row as our editor
      // may no longer be the right one. It happens when you play with
      // the sorting while having the focus in one editor.
      if (e.getType() == TableModelEvent.UPDATE) {
        int first = e.getFirstRow();
        int last = e.getLastRow();
        int editingRow = PropertySheetTable.this.getEditingRow();

        TableCellEditor editor = PropertySheetTable.this.getCellEditor();
        if (editor != null && first <= editingRow && editingRow <= last) {
          editor.cancelCellEditing();
        }
      }
    }
  public EditResult performEdit(
      final ParameterMapping[] parameterMappings,
      final String[] reportFields,
      final String[] declaredParameter) {
    innerTableCellEditor.setTags(reportFields);
    outerTableCellEditor.setTags(declaredParameter);

    final ParameterMappingTableModel parameterMappingTableModel =
        (ParameterMappingTableModel) parameterMappingTable.getModel();
    parameterMappingTableModel.setMappings(parameterMappings);

    if (super.performEdit() == false) {
      return null;
    }

    final TableCellEditor cellEditor = parameterMappingTable.getCellEditor();
    if (cellEditor != null) {
      cellEditor.stopCellEditing();
    }

    return new EditResult(parameterMappingTableModel.getMappings());
  }
  public void _commit(boolean finishChosen) throws CommitStepException {
    // Stop editing if any
    final TableCellEditor cellEditor = myTable.getCellEditor();
    if (cellEditor != null) {
      cellEditor.stopCellEditing();
    }

    // Check that all included fields are bound to valid bean properties
    final PsiNameHelper nameHelper = JavaPsiFacade.getInstance(myData.myProject).getNameHelper();
    for (int i = 0; i < myData.myBindings.length; i++) {
      final FormProperty2BeanProperty binding = myData.myBindings[i];
      if (binding.myBeanProperty == null) {
        continue;
      }

      if (!nameHelper.isIdentifier(binding.myBeanProperty.myName)) {
        throw new CommitStepException(
            UIDesignerBundle.message(
                "error.X.is.not.a.valid.property.name", binding.myBeanProperty.myName));
      }
    }

    myData.myGenerateIsModified = myChkIsModified.isSelected();
  }
 public void stopEditing() {
   TableCellEditor editor = myTable.getCellEditor();
   if (editor != null) {
     editor.stopCellEditing();
   }
 }
Beispiel #20
0
 public boolean stopCellEditing() {
   final TableCellEditor cellEditor = getCellEditor();
   return cellEditor != null && cellEditor.stopCellEditing();
 }
 /** Cancels all editing of fields in the tree and table. */
 void cancelEditing() {
   if (TABLE.isEditing()) {
     TableCellEditor editor = TABLE.getCellEditor();
     editor.cancelCellEditing();
   }
 }
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

    return editor.getTableCellEditorComponent(table, value, isSelected, row, column);
  }
Beispiel #23
0
  private void optionsComboBoxActionPerformed(ActionEvent e) {
    try {
      final int rowNumber = relationNodesetTable.getSelectedRow();
      TableCellEditor cell = relationNodesetTable.getCellEditor(rowNumber, 2);

      if (cell.getCellEditorValue().equals("Base Node")) {
        String nodeName =
            (String)
                JOptionPane.showInputDialog(
                    getRootPane(),
                    "Enter the name of the node:",
                    "Create a Node",
                    JOptionPane.PLAIN_MESSAGE);
        if (nodeName != null) {
          String currentNodesetValue =
              relationNodesetTableModel.getValueAt(rowNumber, 1).toString();

          if (currentNodesetValue.isEmpty()) {
            relationNodesetTableModel.setValueAt(nodeName, rowNumber, 1);
          } else {
            relationNodesetTableModel.setValueAt(
                currentNodesetValue + ", " + nodeName, rowNumber, 1);
          }
        }

      } else if (cell.getCellEditorValue().equals("Variable Node")) {
        Node varNode = network.buildVariableNode();

        String currentNodesetValue = relationNodesetTableModel.getValueAt(rowNumber, 1).toString();

        if (currentNodesetValue.isEmpty()) {
          relationNodesetTableModel.setValueAt(varNode.getIdentifier(), rowNumber, 1);
        } else {
          relationNodesetTableModel.setValueAt(
              currentNodesetValue + ", " + varNode.getIdentifier(), rowNumber, 1);
        }
      } else if (cell.getCellEditorValue().equals("build")) {

        JFrame popupFrame = new JFrame("build");
        popupFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        final cmdBuild buildPanel = new cmdBuild(network, frame, popupFrame);
        popupFrame.getContentPane().add(buildPanel);
        popupFrame.pack();
        popupFrame.setVisible(true);
        Point point = frame.getsNePSULPanel1().getMenuDrivenCommands().cascadePosition();
        popupFrame.setLocation(point);
        doneButton.setEnabled(false);
        popupFrame.addWindowListener(
            new WindowAdapter() {

              @Override
              public void windowClosed(WindowEvent e) {
                LinkedList<Node> nodes = buildPanel.getNodes();
                if (nodes.size() != 0) {
                  for (Node item : nodes) {

                    String currentNodesetValue =
                        relationNodesetTableModel.getValueAt(rowNumber, 1).toString();

                    if (currentNodesetValue.isEmpty()) {
                      relationNodesetTableModel.setValueAt(item.getIdentifier(), rowNumber, 1);
                    } else {
                      relationNodesetTableModel.setValueAt(
                          currentNodesetValue + ", " + item.getIdentifier(), rowNumber, 1);
                    }
                  }
                }

                frame.getsNePSULPanel1().getMenuDrivenCommands().cascadeBack();
                doneButton.setEnabled(true);
              }
            });

      } else if (cell.getCellEditorValue().equals("assert")) {
        JFrame popupFrame = new JFrame("assert");
        popupFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        final cmdAssert assertPanel = new cmdAssert(network, frame, popupFrame);
        popupFrame.getContentPane().add(assertPanel);
        popupFrame.pack();
        popupFrame.setVisible(true);
        Point point = frame.getsNePSULPanel1().getMenuDrivenCommands().cascadePosition();
        popupFrame.setLocation(point);
        doneButton.setEnabled(false);
        popupFrame.addWindowListener(
            new WindowAdapter() {

              @Override
              public void windowClosed(WindowEvent e) {
                LinkedList<Node> nodes = assertPanel.getNodes();
                if (nodes.size() != 0) {
                  for (Node item : nodes) {

                    String currentNodesetValue =
                        relationNodesetTableModel.getValueAt(rowNumber, 1).toString();

                    if (currentNodesetValue.isEmpty()) {
                      relationNodesetTableModel.setValueAt(item.getIdentifier(), rowNumber, 1);
                    } else {
                      relationNodesetTableModel.setValueAt(
                          currentNodesetValue + ", " + item.getIdentifier(), rowNumber, 1);
                    }
                  }
                }

                frame.getsNePSULPanel1().getMenuDrivenCommands().cascadeBack();
                doneButton.setEnabled(true);
              }
            });

      } else if (cell.getCellEditorValue().equals("find")) {
        JFrame popupFrame = new JFrame("find");
        popupFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        final cmdFind findPanel = new cmdFind(network, frame, popupFrame);
        popupFrame.getContentPane().add(findPanel);
        popupFrame.pack();
        popupFrame.setVisible(true);
        Point point = frame.getsNePSULPanel1().getMenuDrivenCommands().cascadePosition();
        popupFrame.setLocation(point);
        doneButton.setEnabled(false);
        popupFrame.addWindowListener(
            new WindowAdapter() {

              @Override
              public void windowClosed(WindowEvent e) {
                LinkedList<Node> nodes = findPanel.getNodes();
                if (nodes.size() != 0) {
                  for (Node item : nodes) {

                    String currentNodesetValue =
                        relationNodesetTableModel.getValueAt(rowNumber, 1).toString();

                    if (currentNodesetValue.isEmpty()) {
                      relationNodesetTableModel.setValueAt(item.getIdentifier(), rowNumber, 1);
                    } else {
                      relationNodesetTableModel.setValueAt(
                          currentNodesetValue + ", " + item.getIdentifier(), rowNumber, 1);
                    }
                  }
                }

                frame.getsNePSULPanel1().getMenuDrivenCommands().cascadeBack();
                doneButton.setEnabled(true);
              }
            });
      } else if (cell.getCellEditorValue().equals("Existing Node")) {
        Node node = frame.getsNePSULPanel1().getMenuDrivenCommands().existingNodes();
        if (node != null) {
          String currentNodesetValue =
              relationNodesetTableModel.getValueAt(rowNumber, 1).toString();

          if (currentNodesetValue.isEmpty()) {
            relationNodesetTableModel.setValueAt(node.getIdentifier(), rowNumber, 1);
          } else {
            relationNodesetTableModel.setValueAt(
                currentNodesetValue + ", " + node.getIdentifier(), rowNumber, 1);
          }
        }
      } else if (cell.getCellEditorValue().equals("Act Node")) {
        frame
            .getsNePSULPanel1()
            .getMenuDrivenCommands()
            .actNodes(this, relationNodesetTable, doneButton, relationNodesetTableModel);
      }
      relationNodesetTable.setValueAt(options.getItemAt(0), rowNumber, 2);
      validate();
    } catch (Exception e1) {
    }
  }
Beispiel #24
0
 public void removeCellEditorListener(CellEditorListener l) {
   editor.removeCellEditorListener(l);
 }
 private static void doCancelEditing(TableCellEditor cellEditor) {
   if (cellEditor == null) return;
   cellEditor.cancelCellEditing();
 }
Beispiel #26
0
 public boolean shouldSelectCell(EventObject anEvent) {
   selectEditor((MouseEvent) anEvent);
   return editor.shouldSelectCell(anEvent);
 }
 /** Commits on-going cell editing */
 public void commitEditing() {
   TableCellEditor editor = getCellEditor();
   if (editor != null) {
     editor.stopCellEditing();
   }
 }
 public void stopCellEditing() {
   TableCellEditor editor;
   if ((editor = getCellEditor()) != null) editor.stopCellEditing();
 }
  /**
   * Override the default removal so we can actually stop sharing and delete the file. Deletes the
   * selected rows in the table. CAUTION: THIS WILL DELETE THE FILE FROM THE DISK.
   */
  public void removeSelection() {
    int[] rows = TABLE.getSelectedRows();
    if (rows.length == 0) return;

    if (TABLE.isEditing()) {
      TableCellEditor editor = TABLE.getCellEditor();
      editor.cancelCellEditing();
    }

    List<File> files = new ArrayList<File>(rows.length);

    // sort row indices and go backwards so list indices don't change when
    // removing the files from the model list
    Arrays.sort(rows);
    for (int i = rows.length - 1; i >= 0; i--) {
      File file = DATA_MODEL.getFile(rows[i]);
      files.add(file);
    }

    CheckBoxListPanel<File> listPanel =
        new CheckBoxListPanel<File>(files, new FileTextProvider(), true);
    listPanel.getList().setVisibleRowCount(4);

    // display list of files that should be deleted
    Object[] message =
        new Object[] {
          new MultiLineLabel(
              I18n.tr(
                  "Are you sure you want to delete the selected file(s), thus removing it from your computer?"),
              400),
          Box.createVerticalStrut(ButtonRow.BUTTON_SEP),
          listPanel,
          Box.createVerticalStrut(ButtonRow.BUTTON_SEP)
        };

    // get platform dependent options which are displayed as buttons in the dialog
    Object[] removeOptions = createRemoveOptions();

    int option =
        JOptionPane.showOptionDialog(
            MessageService.getParentComponent(),
            message,
            I18n.tr("Message"),
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            removeOptions,
            removeOptions[0] /* default option */);

    if (option == removeOptions.length - 1 /* "cancel" option index */
        || option == JOptionPane.CLOSED_OPTION) {
      return;
    }

    // remove still selected files
    List<File> selected = listPanel.getSelectedElements();
    List<String> undeletedFileNames = new ArrayList<String>();

    boolean somethingWasRemoved = false;

    for (File file : selected) {
      // stop seeding if seeding
      BittorrentDownload dm = null;
      if ((dm = TorrentUtil.getDownloadManager(file)) != null) {
        dm.setDeleteDataWhenRemove(false);
        dm.setDeleteTorrentWhenRemove(false);
        BTDownloadMediator.instance().remove(dm);
      }

      // close media player if still playing
      if (MediaPlayer.instance().isThisBeingPlayed(file)) {
        MediaPlayer.instance().stop();
        MPlayerMediator.instance().showPlayerWindow(false);
      }

      // removeOptions > 2 => OS offers trash options
      boolean removed =
          FileUtils.delete(
              file, removeOptions.length > 2 && option == 0 /* "move to trash" option index */);
      if (removed) {
        somethingWasRemoved = true;
        DATA_MODEL.remove(DATA_MODEL.getRow(file));
      } else {
        undeletedFileNames.add(getCompleteFileName(file));
      }
    }

    clearSelection();

    if (somethingWasRemoved) {
      LibraryMediator.instance().getLibraryExplorer().refreshSelection(true);
    }

    if (undeletedFileNames.isEmpty()) {
      return;
    }

    // display list of files that could not be deleted
    message =
        new Object[] {
          new MultiLineLabel(
              I18n.tr(
                  "The following files could not be deleted. They may be in use by another application or are currently being downloaded to."),
              400),
          Box.createVerticalStrut(ButtonRow.BUTTON_SEP),
          new JScrollPane(createFileList(undeletedFileNames))
        };

    JOptionPane.showMessageDialog(
        MessageService.getParentComponent(), message, I18n.tr("Error"), JOptionPane.ERROR_MESSAGE);

    super.removeSelection();
  }
 /** Cancels on-going cell editing */
 public void cancelEditing() {
   TableCellEditor editor = getCellEditor();
   if (editor != null) {
     editor.cancelCellEditing();
   }
 }