Java Code Examples for javax.swing.table.TableColumn#getCellEditor()

The following examples show how to use javax.swing.table.TableColumn#getCellEditor() . 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: DesktopAbstractTable.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void removeGeneratedColumn(String columnId) {
    checkArgument(columnId != null, "columnId is null");
    Column col = getColumn(columnId);
    if (col != null) {
        boolean oldContentRepaintEnabled = isContentRepaintEnabled();
        setContentRepaintEnabled(false);

        TableColumn targetTableColumn = getColumn(col);
        TableCellEditor cellEditor = targetTableColumn.getCellEditor();
        if (cellEditor instanceof DesktopTableCellEditor) {
            Column associatedRuntimeColumn = ((DesktopTableCellEditor) cellEditor).getAssociatedRuntimeColumn();

            removeColumn(associatedRuntimeColumn);
        }

        tableModel.removeGeneratedColumn(col);
        generatedColumnsCount--;

        packRows();
        repaintImplIfNeeded();
        setContentRepaintEnabled(oldContentRepaintEnabled);
    }
}
 
Example 2
Source File: DesktopAbstractTable.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Printable getPrintable(String columnId) {
    checkArgument(columnId != null, "columnId is null");

    Printable printable = printables.get(columnId);
    if (printable != null) {
        return printable;
    } else {
        Column column = getColumn(columnId);
        if (column != null) {
            TableColumn tableColumn = getColumn(column);
            TableCellEditor cellEditor = tableColumn.getCellEditor();
            if (cellEditor instanceof DesktopTableCellEditor) {
                ColumnGenerator columnGenerator = ((DesktopTableCellEditor) cellEditor).getColumnGenerator();
                if (columnGenerator instanceof Printable) {
                    return (Printable) columnGenerator;
                }
            }
        }
        return null;
    }
}
 
Example 3
Source File: DesktopAbstractTable.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected boolean allColumnsAreInline() {
    if (generatedColumnsCount <= 0) {
        return true;
    }

    for (Column column : columnsOrder) {
        if (!tableModel.isGeneratedColumn(column)) {
            continue;
        }

        TableColumn tableColumn = getColumn(column);
        if (tableColumn != null) {
            DesktopTableCellEditor cellEditor = (DesktopTableCellEditor) tableColumn.getCellEditor();
            if (cellEditor != null) {
                boolean inline = cellEditor.isInline();
                if (!inline) {
                    return false;
                }
            }
        }
    }
    return true;
}
 
Example 4
Source File: DesktopAbstractTable.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void onDataChange() {
    for (TableColumn tableColumn : getAllColumns()) {
        TableCellEditor cellEditor = tableColumn.getCellEditor();
        if (cellEditor instanceof DesktopTableCellEditor) {
            ((DesktopTableCellEditor) cellEditor).clearCache();
        }
    }
    repaintImplIfNeeded();
}
 
Example 5
Source File: DesktopAbstractTable.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void clearGeneratedColumnsCache() {
    for (Column column : columnsOrder) {
        if (tableModel.isGeneratedColumn(column)) {
            TableColumn tableColumn = getColumn(column);
            if (tableColumn != null) {
                TableCellEditor tableCellEditor = tableColumn.getCellEditor();
                if (tableCellEditor instanceof DesktopTableCellEditor) {
                    ((DesktopTableCellEditor) tableCellEditor).clearCache();
                }
            }
        }
    }
}
 
Example 6
Source File: DesktopAbstractTable.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void repaint() {
    TableCellEditor cellEditor = impl.getCellEditor();
    if (cellEditor instanceof DesktopTableCellEditor) {
        ((DesktopTableCellEditor) cellEditor).clearCache();
    }

    List<TableColumn> implColumns = impl.getColumns();
    for (Column column : getColumns()) {
        TableColumn tableColumn = null;
        for (TableColumn implColumn : implColumns) {
            if (column.equals((implColumn.getIdentifier()))) {
                tableColumn = implColumn;
                break;
            }
        }
        // column may be hidden
        if (tableColumn != null) {
            TableCellEditor columnCellEditor = tableColumn.getCellEditor();
            if (columnCellEditor instanceof DesktopTableCellEditor) {
                ((DesktopTableCellEditor) columnCellEditor).clearCache();
            }
        }
    }
    packRows();
    repaintImplIfNeeded();
}
 
Example 7
Source File: EditableTableHeaderColumn.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
public void copyValues(TableColumn base) {
	modelIndex = base.getModelIndex();
	identifier = base.getIdentifier();
	width = base.getWidth();
	minWidth = base.getMinWidth();
	setPreferredWidth(base.getPreferredWidth());
	maxWidth = base.getMaxWidth();
	headerRenderer = base.getHeaderRenderer();
	headerValue = base.getHeaderValue();
	cellRenderer = base.getCellRenderer();
	cellEditor = base.getCellEditor();
	isResizable = base.getResizable();
}
 
Example 8
Source File: MyTreeTable.java    From gameserver with Apache License 2.0 5 votes vote down vote up
@Override
public TableCellEditor getCellEditor(int row, int column) {
   TableColumn tableColumn = getColumnModel().getColumn(column);
   TableCellEditor editor = tableColumn.getCellEditor();
   if (editor == null) {
   	Object value = this.getValueAt(row, column);
   	if ( value != null ) {
   		editor = getDefaultEditor(value.getClass());
   	} else {
   		editor = getDefaultEditor(getColumnClass(column));
   	}
   }
   return editor;
}
 
Example 9
Source File: ProductEntryTableModel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isCellEditable(final int rowIndex, final int columnIndex) {
    if (columnIndex >= columnList.size()) {
        return false;
    }
    final TableColumn column = columnList.get(columnIndex);
    return column.getCellEditor() != null;
}
 
Example 10
Source File: AOITableModel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isCellEditable(final int rowIndex, final int columnIndex) {
    if (columnIndex >= columnList.size()) {
        return false;
    }
    final TableColumn column = columnList.get(columnIndex);
    return column.getCellEditor() != null;
}
 
Example 11
Source File: ElementMetaDataTable.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public TableCellEditor getCellEditor( final int row, final int viewColumn ) {
  final int column = convertColumnIndexToModel( viewColumn );
  final Object value = getModel().getValueAt( row, column );
  if ( value instanceof GroupingHeader ) {
    return getDefaultEditor( GroupingHeader.class );
  }

  final ElementMetaDataTableModel model = (ElementMetaDataTableModel) getModel();
  final PropertyEditor propertyEditor = model.getEditorForCell( row, column );
  final Class columnClass = model.getClassForCell( row, column );

  if ( propertyEditor != null ) {
    final String[] tags = propertyEditor.getTags();
    if ( columnClass.isArray() ) {
      arrayCellEditor.setPropertyEditorType( propertyEditor.getClass() );
    } else if ( tags == null || tags.length == 0 ) {
      propertyEditorCellEditor.setPropertyEditor( propertyEditor );
      return propertyEditorCellEditor;
    } else {
      taggedPropertyEditorCellEditor.setPropertyEditor( propertyEditor );
      return taggedPropertyEditorCellEditor;
    }
  }

  final TableColumn tableColumn = getColumnModel().getColumn( column );
  final TableCellEditor renderer = tableColumn.getCellEditor();
  if ( renderer != null ) {
    return renderer;
  }

  if ( columnClass.isArray() ) {
    return arrayCellEditor;
  }

  final TableCellEditor editor = getDefaultEditor( columnClass );
  if ( editor != null && logger.isTraceEnabled() ) {
    logger.trace( "Using preconfigured default editor for column class " + columnClass + ": " + editor ); // NON-NLS
  }
  return editor;
}
 
Example 12
Source File: EditableHeaderTableColumn.java    From chipster with MIT License 5 votes vote down vote up
public void copyValues(TableColumn base) {    
	modelIndex     = base.getModelIndex();
	identifier     = base.getIdentifier();
	width          = base.getWidth();
	minWidth       = base.getMinWidth();
	setPreferredWidth(base.getPreferredWidth());
	maxWidth       = base.getMaxWidth();
	headerRenderer = base.getHeaderRenderer();
	headerValue    = base.getHeaderValue();
	cellRenderer   = base.getCellRenderer();
	cellEditor     = base.getCellEditor();
	isResizable    = base.getResizable();
}
 
Example 13
Source File: Outline.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean editCellAt (int row, int column, EventObject e) {
    //If it was on column 0, it may be a request to expand a tree
    //node - check for that first.
    boolean isTreeColumn = isTreeColumnIndex(column);
    if (isTreeColumn && e instanceof MouseEvent) {
        MouseEvent me = (MouseEvent) e;
        TreePath path = getLayoutCache().getPathForRow(convertRowIndexToModel(row));
        if (path != null && !getOutlineModel().isLeaf(path.getLastPathComponent())) {
            int handleWidth = DefaultOutlineCellRenderer.getExpansionHandleWidth();
            Insets ins = getInsets();
            int nd = path.getPathCount() - (isRootVisible() ? 1 : 2);
            if (nd < 0) {
                nd = 0;
            }
            int handleStart = ins.left + (nd * DefaultOutlineCellRenderer.getNestingWidth());
            int handleEnd = ins.left + handleStart + handleWidth;
            // Translate 'x' to position of column if non-0:
            int columnStart = getCellRect(row, column, false).x;
            handleStart += columnStart;
            handleEnd += columnStart;

            TableColumn tableColumn = getColumnModel().getColumn(column);
            TableCellEditor columnCellEditor = tableColumn.getCellEditor();
            if ((me.getX() > ins.left && me.getX() >= handleStart && me.getX() <= handleEnd) ||
                (me.getClickCount() > 1 && columnCellEditor == null)) {

                boolean expanded = getLayoutCache().isExpanded(path);
                //me.consume();  - has no effect!
                //System.err.println("  event consumed.");
                if (!expanded) {
                    getTreePathSupport().expandPath(path);
                    
                    Object ourObject = path.getLastPathComponent();
                    int cCount = getOutlineModel().getChildCount(ourObject);
                    if (cCount > 0) {
                        int lastRow = row;
                        for (int i = 0; i < cCount; i++) {
                            Object child = getOutlineModel().getChild(ourObject, i);
                            TreePath childPath = path.pathByAddingChild(child);
                            int childRow = getLayoutCache().getRowForPath(childPath);
                            childRow = convertRowIndexToView(childRow);
                            if (childRow > lastRow) {
                                lastRow = childRow;
                            }
                        }
                        int firstRow = row;
                        Rectangle rectLast = getCellRect(lastRow, 0, true);
                        Rectangle rectFirst = getCellRect(firstRow, 0, true);
                        Rectangle rectFull = new Rectangle(
                                rectFirst.x,
                                rectFirst.y,
                                rectLast.x + rectLast.width - rectFirst.x,
                                rectLast.y + rectLast.height - rectFirst.y);
                        scrollRectToVisible(rectFull);
                    }
                    
                } else {
                    getTreePathSupport().collapsePath(path);
                }
                selectionDisabled = true;
                return false;
            }
        }
        // It may be a request to check/uncheck a check-box
        if (checkAt(row, column, me)) {
            return false;
        }
    } else if (isTreeColumn && e instanceof ActionEvent) {
        if (((ActionEvent) e).getModifiers() == 0 &&
            lastProcessedKeyStroke != null) {
            
            if (lastProcessedKeyStroke.getKeyCode() == KeyEvent.VK_SPACE) {
                if (checkAt(row, column, null)) {
                    return false;
                }
            }
        }
    }
        
    boolean res = false;
    if (!isTreeColumn || e instanceof MouseEvent && row >= 0 && isEditEvent(row, column, (MouseEvent) e)) {
        res = super.editCellAt(row, column, e);
    }
    if( res && isTreeColumn && row >= 0 && null != getEditorComponent() ) {
        configureTreeCellEditor(getEditorComponent(), row, column);
    }
    if (e == null && !res && isTreeColumn) {
        // Handle SPACE
        checkAt(row, column, null);
    }
    return res;
}
 
Example 14
Source File: ObjectPropertyViewerPanel.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
public TableCellEditor getCellEditor(int row, int column) {
   TableColumn tableColumn = getColumnModel().getColumn(column);
   TableCellEditor editor = tableColumn.getCellEditor();
   if (editor == null) editor = getDefaultEditor(model.getCellClass(adapter.nodeForRow(row), convertColumnIndexToModel(column)));
   return editor;
}
 
Example 15
Source File: PropertyTable.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public TableCellEditor getCellEditor( final int row, final int viewColumn ) {
  final TableModel tableModel = getModel();
  if ( tableModel instanceof PropertyTableModel ) {
    final PropertyTableModel model = (PropertyTableModel) getModel();
    final int column = convertColumnIndexToModel( viewColumn );

    final PropertyEditor propertyEditor = model.getEditorForCell( row, column );
    final Class columnClass = model.getClassForCell( row, column );

    if ( propertyEditor != null ) {
      final String[] tags = propertyEditor.getTags();

      if ( columnClass.isArray() ) {
        arrayCellEditor.setPropertyEditorType( propertyEditor.getClass() );
      } else if ( tags == null || tags.length == 0 ) {
        propertyEditorCellEditor.setPropertyEditor( propertyEditor );
        return propertyEditorCellEditor;
      } else {
        taggedPropertyEditorCellEditor.setPropertyEditor( propertyEditor );
        return taggedPropertyEditorCellEditor;
      }
    }

    final TableColumn tableColumn = getColumnModel().getColumn( column );
    final TableCellEditor renderer = tableColumn.getCellEditor();
    if ( renderer != null ) {
      return renderer;
    }

    if ( columnClass.isArray() ) {
      return arrayCellEditor;
    }

    final TableCellEditor editor = getDefaultEditor( columnClass );
    if ( editor != null && logger.isTraceEnabled() ) {
      logger.trace( "Using preconfigured default editor for column class " + columnClass + ": " + editor ); // NON-NLS
    }
    return editor;
  }
  return super.getCellEditor( row, viewColumn );
}