javax.swing.table.TableCellEditor Java Examples

The following examples show how to use javax.swing.table.TableCellEditor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetaDataDeclarationEditor.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public TableCellEditor getCellEditor(int row, int column) {
	if (column == 0) { // RowNo.
		if (row == IS_SELECTED_ROW) {
			return globalCheckBoxCellEditor;
		}
		return super.getCellEditor();
	}
	column--;
	if (row == VALUE_TYPE_ROW) {
		return valueTypeCellEditor;
	}
	if (row == IS_SELECTED_ROW) {
		return checkBoxCellEditor;
	}
	if (row == ROLE_ROW) {
		return roleCellEditor;
	}
	// ATTRIBUTE_NAME_ROW
	return super.getCellEditor(row, column);
}
 
Example #2
Source File: MyTable.java    From gameserver with Apache License 2.0 6 votes vote down vote up
@Override
public TableCellEditor getCellEditor(int row, int column) {
	if ( editorFactory != null ) {
		TableModel tableModel = this.getModel();
		if ( tableModel != null ) {
			String columnName = getColumnName(column, tableModel);
			//Use original row / column index
			TableCellEditor editor = this.editorFactory.getCellEditor(
					row, column, columnName, tableModel, this);
			if ( editor != null ) {
				return editor;
			}
		}
	}
	return super.getCellEditor(row, column);
}
 
Example #3
Source File: BaseDialog.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
private void commitComponent(final Component container) {
    if (container == null)
        return;
    if (container instanceof JTable) {
        TableCellEditor cellEditor = ((JTable) container).getCellEditor();
        if (cellEditor != null) {
            try {
                cellEditor.stopCellEditing();
            } catch (Exception e) {
                try {
                    cellEditor.cancelCellEditing();
                } catch (Exception ex) {

                }
            }
        }
    }
}
 
Example #4
Source File: CalendarEditorPanel.java    From ganttproject with GNU General Public License v3.0 6 votes vote down vote up
private static Pair<JLabel, ? extends TableCellEditor> createDateValidatorComponents(final String hint, DateFormat... dateFormats) {
  Supplier<List<DateFormat>> formatSupplier = Suppliers.<List<DateFormat>>ofInstance(Lists.newArrayList(dateFormats));
  final JLabel hintLabel = new JLabel(" "); // non-empty label to occupy some vertical space
  final ValueValidator<Date> realValidator = UIUtil.createStringDateValidator(null, formatSupplier);
  ValueValidator<Date> decorator = new ValueValidator<Date>() {
    @Override
    public Date parse(String text) throws ValidationException {
      try {
        Date result = realValidator.parse(text);
        hintLabel.setText("");
        return result;
      } catch (ValidationException e) {
        e.printStackTrace();
        hintLabel.setText(hint);
        throw e;
      }
    }
  };
  GPDateCellEditor dateEditor = new GPDateCellEditor(null, true, decorator, formatSupplier);
  return Pair.create(hintLabel, dateEditor);
}
 
Example #5
Source File: EditableTableHeader.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean editCellAt(int index, EventObject e) {
	if (cellEditor != null && !cellEditor.stopCellEditing()) {
		return false;
	}
	if (!isCellEditable(index)) {
		return false;
	}
	TableCellEditor editor = getCellEditor(index);

	if (editor != null && editor.isCellEditable(e)) {
		editorComp = prepareEditor(editor, index);
		editorComp.setBounds(getHeaderRect(index));
		add(editorComp);
		editorComp.validate();
		setCellEditor(editor);
		setEditingColumn(index);
		editor.addCellEditorListener(this);

		return true;
	}
	return false;
}
 
Example #6
Source File: GPTreeTableBase.java    From ganttproject with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Component prepareEditor(TableCellEditor editor, int row, int column) {
  Component result = super.prepareEditor(editor, row, column);
  if (result instanceof JTextComponent) {
    Object textFieldFont = UIManager.get("TextField.font");
    if (textFieldFont instanceof Font) {
      result.setFont((Font) textFieldFont);
    }

    if (Boolean.TRUE == getClientProperty("GPTreeTableBase.clearText")) {
      ((JTextComponent) result).setText("");
    }
    if (Boolean.TRUE == getClientProperty("GPTreeTableBase.selectAll")) {
      SwingUtilities.invokeLater(TreeTableCellEditorImpl.createSelectAllCommand((JTextComponent) result));
    }
    if (Boolean.TRUE == getClientProperty("GPTreeTableBase.unselectAll")) {
      SwingUtilities.invokeLater(TreeTableCellEditorImpl.createUnselectAllCommand((JTextComponent) result));
      putClientProperty("GPTreeTableBase.unselectAll", false);
    }
  }
  return result;
}
 
Example #7
Source File: XMBeanAttributes.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final boolean editCellAt(final int row, final int column, EventObject e) {
    if (LOGGER.isLoggable(Level.TRACE)) {
        LOGGER.log(Level.TRACE, "editCellAt(row="+row+", col="+column+
                ", e="+e+")");
    }
    if (JConsole.isDebug()) {
        System.err.println("edit: "+getValueName(row)+"="+getValue(row));
    }
    boolean retVal = super.editCellAt(row, column, e);
    if (retVal) {
        final TableCellEditor tableCellEditor =
                getColumnModel().getColumn(column).getCellEditor();
        if (tableCellEditor == valueCellEditor) {
            ((JComponent) tableCellEditor).requestFocus();
        }
    }
    return retVal;
}
 
Example #8
Source File: OldJTable.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public TableColumn addColumn(Object columnIdentifier, int width,
                             TableCellRenderer renderer,
                             TableCellEditor editor, List columnData) {
    checkDefaultTableModel();

    // Set up the model side first
    DefaultTableModel m = (DefaultTableModel)getModel();
    m.addColumn(columnIdentifier, columnData.toArray());

    // The column will have been added to the end, so the index of the
    // column in the model is the last element.
    TableColumn newColumn = new TableColumn(
            m.getColumnCount()-1, width, renderer, editor);
    super.addColumn(newColumn);
    return newColumn;
}
 
Example #9
Source File: OldJTable.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public TableColumn addColumn(Object columnIdentifier, int width,
                             TableCellRenderer renderer,
                             TableCellEditor editor, List columnData) {
    checkDefaultTableModel();

    // Set up the model side first
    DefaultTableModel m = (DefaultTableModel)getModel();
    m.addColumn(columnIdentifier, columnData.toArray());

    // The column will have been added to the end, so the index of the
    // column in the model is the last element.
    TableColumn newColumn = new TableColumn(
            m.getColumnCount()-1, width, renderer, editor);
    super.addColumn(newColumn);
    return newColumn;
}
 
Example #10
Source File: MemoryMapProvider1Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testEditName() throws Exception {

	table.addRowSelectionInterval(0, 0);
	Rectangle rect = table.getCellRect(0, MemoryMapModel.NAME, true);
	clickMouse(table, 1, rect.x, rect.y, 2, 0);
	waitForPostedSwingRunnables();

	SwingUtilities.invokeAndWait(() -> {
		int row = 0;
		TableCellEditor editor = table.getCellEditor(row, MemoryMapModel.NAME);
		Component c = editor.getTableCellEditorComponent(table,
			model.getValueAt(row, MemoryMapModel.NAME), true, row, MemoryMapModel.NAME);
		JTextField tf = (JTextField) c;

		tf.setText(".test");
		editor.stopCellEditing();
	});
	waitForPostedSwingRunnables();
	assertEquals(".test", model.getValueAt(0, MemoryMapModel.NAME));
}
 
Example #11
Source File: XMBeanAttributes.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final boolean editCellAt(final int row, final int column, EventObject e) {
    if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.finer("editCellAt(row="+row+", col="+column+
                ", e="+e+")");
    }
    if (JConsole.isDebug()) {
        System.err.println("edit: "+getValueName(row)+"="+getValue(row));
    }
    boolean retVal = super.editCellAt(row, column, e);
    if (retVal) {
        final TableCellEditor tableCellEditor =
                getColumnModel().getColumn(column).getCellEditor();
        if (tableCellEditor == valueCellEditor) {
            ((JComponent) tableCellEditor).requestFocus();
        }
    }
    return retVal;
}
 
Example #12
Source File: PDeclensionGridPanel.java    From PolyGlot with MIT License 6 votes vote down vote up
/**
 * Gets map of all declined word forms. Key = combined ID, value = word form
 * @return 
 */
@Override
public Map<String, String> getAllDecValues() {
    Map<String, String> ret = new HashMap<>();
    
    TableCellEditor editor = table.getCellEditor();
    if (editor != null) {
        editor.stopCellEditing();
    }
    
    decIdsToGridLocation.entrySet().forEach((entry) -> {
        Object val = table.getModel().getValueAt(entry.getValue().height, entry.getValue().width);
        ret.put(entry.getKey(), val == null ? "" : (String)val);
    });
    
    return ret;
}
 
Example #13
Source File: DesktopAbstractTable.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected TableCellEditor getCellEditor(int row, int column) {

        TableColumn tableColumn = impl.getColumnModel().getColumn(column);
        if (tableColumn.getIdentifier() instanceof Column) {
            Column columnConf = (Column) tableColumn.getIdentifier();

            if (editableColumns != null
                    && columnConf.getId() instanceof MetaPropertyPath
                    && editableColumns.contains(columnConf.getId())) {

                return tableFieldFactory.createEditComponent(row, columnConf);
            }
        }

        return null;
    }
 
Example #14
Source File: PropertyTable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void valueCommitted(PropertyEditor source, boolean continueEditing, boolean closeEditorOnError) {
  if (isEditing()) {
    Object value;
    TableCellEditor tableCellEditor = cellEditor;

    try {
      value = tableCellEditor.getCellEditorValue();
    }
    catch (Exception e) {
      showInvalidInput(e);
      return;
    }

    if (setValueAtRow(editingRow, value)) {
      if (!continueEditing) {
        tableCellEditor.stopCellEditing();
      }
    }
    else if (closeEditorOnError) {
      tableCellEditor.cancelCellEditing();
    }
  }
}
 
Example #15
Source File: TableTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        KeyboardFocusManager.getCurrentKeyboardFocusManager();
        System.setSecurityManager(new AppletSecurity());

        JTable table = new JTable();
        TableCellEditor de = table.getDefaultEditor(Double.class);
        if (de == null) {
            throw new RuntimeException("Table default editor is null");
        }
    }
 
Example #16
Source File: ListPropertyTable2.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * This is needed in order to allow auto completion: Otherwise the editor will be immediately
 * removed after setting the first selected value and loosing its focus. This way it is ensured
 * that the editor won't be removed.
 */
@Override
public void editingStopped(ChangeEvent e) {

	TableCellEditor editor = getCellEditor();
	if (editor != null) {
		Object value = editor.getCellEditorValue();
		setValueAt(value, editingRow, editingColumn);
	}
}
 
Example #17
Source File: TableTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        KeyboardFocusManager.getCurrentKeyboardFocusManager();
        System.setSecurityManager(new AppletSecurity());

        JTable table = new JTable();
        TableCellEditor de = table.getDefaultEditor(Double.class);
        if (de == null) {
            throw new RuntimeException("Table default editor is null");
        }
    }
 
Example #18
Source File: ContentFolderPropertiesDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public TableCellEditor getEditor(final Item o) {
  return new ComboBoxCellEditor() {
    @Override
    protected List<String> getComboBoxItems() {
      Object[] values = o.myProvider.getValues();
      List<String> items = new ArrayList<String>();
      for (Object value : values) {
        items.add(String.valueOf(value));
      }
      return items;
    }
  };
}
 
Example #19
Source File: CalendarEditorPanel.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
public JPanel createNonRecurringComponent() {
  AbstractTableAndActionsComponent<CalendarEvent> tableAndActions = createTableComponent(myOneOffModel, GanttLanguage.getInstance().getShortDateFormat(), myUiFacade);
  JPanel result = AbstractTableAndActionsComponent.createDefaultTableAndActions(tableAndActions.getTable(), tableAndActions.getActionsComponent());

  Date today = CalendarFactory.newCalendar().getTime();
  final String hint = GanttLanguage.getInstance().formatText("calendar.editor.dateHint",
      GanttLanguage.getInstance().getMediumDateFormat().format(today), GanttLanguage.getInstance().getShortDateFormat().format(today));

  Pair<JLabel,? extends TableCellEditor> validator = createDateValidatorComponents(hint, GanttLanguage.getInstance().getMediumDateFormat(), GanttLanguage.getInstance().getShortDateFormat());
  TableColumn dateColumn = tableAndActions.getTable().getColumnModel().getColumn(TableModelImpl.Column.DATES.ordinal());
  dateColumn.setCellEditor(validator.second());
  result.add(validator.first(), BorderLayout.SOUTH);
  result.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  return result;
}
 
Example #20
Source File: EditableHeader.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public TableCellEditor getCellEditor( final int index ) {
  final int columnIndex = columnModel.getColumn( index ).getModelIndex();
  if ( columnIndex == 0 ) {
    return null;
  }
  final EditableHeaderTableColumn col = (EditableHeaderTableColumn) columnModel.getColumn( columnIndex );
  return col.getHeaderEditor();
}
 
Example #21
Source File: SchemaPropertiesController.java    From bigtable-sql with Apache License 2.0 5 votes vote down vote up
public void applyChanges()
{

   TableCellEditor cellEditor = _pnl.tblSchemas.getCellEditor();
   if(null != cellEditor)
   {
      cellEditor.stopCellEditing();
   }


   if(_pnl.radLoadAllAndCacheNone.isSelected())
   {
      _alias.getSchemaProperties().setGlobalState(SQLAliasSchemaProperties.GLOBAL_STATE_LOAD_ALL_CACHE_NONE);
   }
   else if(_pnl.radLoadAndCacheAll.isSelected())
   {
      _alias.getSchemaProperties().setGlobalState(SQLAliasSchemaProperties.GLOBAL_STATE_LOAD_AND_CACHE_ALL);
   }
   else if(_pnl.radSpecifySchemas.isSelected())
   {
      _alias.getSchemaProperties().setGlobalState(SQLAliasSchemaProperties.GLOBAL_STATE_SPECIFY_SCHEMAS);
   }

   _alias.getSchemaProperties().setSchemaDetails(_schemaTableModel.getData());

   _alias.getSchemaProperties().setCacheSchemaIndependentMetaData(_pnl.chkCacheSchemaIndepndentMetaData.isSelected());

}
 
Example #22
Source File: JTableOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTable.prepareEditor(TableCellEditor, int, int)} through queue
 */
public Component prepareEditor(final TableCellEditor tableCellEditor, final int i, final int i1) {
    return (runMapping(new MapAction<Component>("prepareEditor") {
        @Override
        public Component map() {
            return ((JTable) getSource()).prepareEditor(tableCellEditor, i, i1);
        }
    }));
}
 
Example #23
Source File: JAutoColumnTable.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Component prepareEditor(TableCellEditor editor, int row, int column) {
	Component component = super.prepareEditor(editor, row, column);
	if (component instanceof JTextComponent) {
		JTextComponent jTextComponent = (JTextComponent) component;
		TextManager.installTextComponent(jTextComponent);
		jTextComponent.selectAll();
	} else if (component instanceof Container) {
		TextManager.installAll((Container) component);
	}
	return component;
}
 
Example #24
Source File: TableTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        KeyboardFocusManager.getCurrentKeyboardFocusManager();
        System.setSecurityManager(new AppletSecurity());

        JTable table = new JTable();
        TableCellEditor de = table.getDefaultEditor(Double.class);
        if (de == null) {
            throw new RuntimeException("Table default editor is null");
        }
    }
 
Example #25
Source File: AttrTable.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void attrStructureChanged(AttrTableModelEvent e) {
	if (e.getSource() != attrModel) {
		attrModel.removeAttrTableModelListener(this);
		return;
	}
	TableCellEditor ed = table.getCellEditor();
	if (ed != null) {
		ed.cancelCellEditing();
	}
	fireTableChanged();
}
 
Example #26
Source File: TableCellEditorFactory.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
public TableCellEditor getCellEditor(int type) {
    if (type == FONT) {
        if (fontEditor == null)
            fontEditor = createFontEditor();
        return fontEditor;
    }
    if (type == MODEL)
        return createModelEditor();
    if (type == BASE_QUALIFIER)
        return createBaseQualifierEditor();
    TableCellEditor editor = editors.get(type);
    if (editor == null)
        return defaultEditor;
    return editor;
}
 
Example #27
Source File: EditableTableHeader.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
public void setCellEditor(TableCellEditor newEditor) {
	TableCellEditor oldEditor = cellEditor;
	cellEditor = newEditor;

	// firePropertyChange

	if (oldEditor != null) {
		oldEditor.removeCellEditorListener(this);
	}
	if (newEditor != null) {
		newEditor.addCellEditorListener(this);
	}
}
 
Example #28
Source File: UIUtil.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
public static TableCellEditor newDateCellEditor(IGanttProject project, boolean showDatePicker) {
  Supplier<List<DateFormat>> supplier = new Supplier<List<DateFormat>>() {
    @Override
    public List<DateFormat> get() {
      return Collections.<DateFormat>singletonList(GanttLanguage.getInstance().getShortDateFormat());
    }
  };
  return new GPDateCellEditor(project, showDatePicker, null, supplier);
}
 
Example #29
Source File: SheetTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Overridden to set the colors apropriately - we always want the editor
* to appear selected */
@Override
public Component prepareEditor(TableCellEditor editor, int row, int col) {
    if (editor == null) {
        return null;
    }

    Component result = super.prepareEditor(editor, row, col);

    if (result == null) {
        return null;
    }

    if( 1 == col ) {
    //Usually result == ine, but custom impls may not be
    InplaceEditor ine = getEditor().getInplaceEditor();

    if (ine.supportsTextEntry()) {
        result.setBackground(PropUtils.getTextFieldBackground());
        result.setForeground(PropUtils.getTextFieldForeground());
    }
    }

    if (result instanceof JComponent) {
        //unlikely that it won't be
        ((JComponent) result).setBorder(BorderFactory.createEmptyBorder(0, PropUtils.getTextMargin(), 0, 0));
    }

    return result;
}
 
Example #30
Source File: FmtImports.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void removeStarImportPackageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeStarImportPackageButtonActionPerformed
    int row = starImportPackagesTable.getSelectedRow();
    if (row >= 0) {
        TableCellEditor cellEditor = starImportPackagesTable.getCellEditor();
        if (cellEditor != null)
            cellEditor.cancelCellEditing();
        ((DefaultTableModel)starImportPackagesTable.getModel()).removeRow(row);
    }
}