use of org.talend.commons.ui.runtime.swt.tableviewer.behavior.ColumnCellModifier in project tbd-studio-se by Talend.
the class HDFSMetadataTableEditorView method configureNameColumn.
/*
* (non-Javadoc)
*
* @see
* org.talend.core.ui.metadata.editor.AbstractMetadataTableEditorView#configureNameColumn(org.talend.commons.ui.
* swt.tableviewer.TableViewerCreator)
*/
@Override
protected void configureNameColumn(TableViewerCreator<MetadataColumn> tableViewerCreator) {
TableViewerCreatorColumn column;
column = new TableViewerCreatorColumn(tableViewerCreator);
column.setId(ID_COLUMN_NAME);
column.setTitle("Column");
column.setToolTipHeader("Column");
column.setBeanPropertyAccessors(getLabelAccessor());
final Image imageKey = ImageProvider.getImage(EImage.KEY_ICON);
final Image imageEmpty = ImageProvider.getImage(EImage.EMPTY);
column.setImageProvider(new IColumnImageProvider() {
@Override
public Image getImage(Object element) {
if (getKeyAccesor().get((MetadataColumn) element)) {
return imageKey;
} else {
return imageEmpty;
}
}
});
column.setWeight(25);
column.setModifiable(!isReadOnly());
column.setMinimumWidth(45);
final ColumnCellModifier columnCellModifier = new ColumnCellModifier(column) {
@Override
public boolean canModify(Object bean) {
MetadataColumn columnBean = (MetadataColumn) bean;
TaggedValue seqKeyTV = TaggedValueHelper.getTaggedValue(HDFSConstants.IS_SEQUENCE_KEY, columnBean.getTaggedValue());
TaggedValue seqValTV = TaggedValueHelper.getTaggedValue(HDFSConstants.IS_SEQUENCE_VALUE, columnBean.getTaggedValue());
if (seqKeyTV != null || seqValTV != null) {
return false;
}
return true;
}
};
column.setColorProvider(new IColumnColorProvider() {
@Override
public Color getBackgroundColor(Object bean) {
if (!columnCellModifier.canModify(bean)) {
return READONLY_CELL_BG_COLOR;
}
return null;
}
@Override
public Color getForegroundColor(Object bean) {
return null;
}
});
column.setColumnCellModifier(columnCellModifier);
final TextCellEditor cellEditor = new TextCellEditorExtendTab(tableViewerCreator.getTable());
cellEditor.addListener(new DialogErrorForCellEditorListener(cellEditor, column) {
@Override
public void newValidValueTyped(int itemIndex, Object previousValue, Object newValue, CELL_EDITOR_STATE state) {
}
@Override
public String validateValue(String newValue, int beanPosition) {
return validateColumnName(newValue, beanPosition);
}
});
column.setCellEditor(cellEditor);
}
Aggregations