use of org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn in project tdi-studio-se by Talend.
the class PropertiesTableByRowEditorView method createColumns.
/*
* (non-Javadoc)
*
* @see
* org.talend.commons.ui.swt.advanced.dataeditor.AbstractDataTableEditorView#createColumns(org.talend.commons.ui
* .swt.tableviewer.TableViewerCreator, org.eclipse.swt.widgets.Table)
*/
@Override
protected void createColumns(TableViewerCreator<B> tableViewerCreator, Table table) {
// there's two lists of values, one that will be in the table
// and the other will be stored as the current value in the property
// there is two lists because of the undo / redo capabilities
PropertiesTableEditorModel model = getModel();
TalendProposalProvider processProposalProvider = new TalendProposalProvider(model.getProcess());
String[] titles = null;
// final Element elem = model.getElement();
final IElementParameter param = model.getElemParameter();
final IElement element = model.getElement();
if (element instanceof Node) {
List<IConnection> listConnection = (List<IConnection>) ((Node) element).getInputs();
List<String> names = new ArrayList<String>();
for (IConnection con : listConnection) {
names.add(con.getName());
}
titles = new String[names.size()];
for (int i = 0; i < names.size(); i++) {
titles[i] = names.get(i);
}
}
if (titles != null && titles.length > 0) {
for (int i = 0; i < titles.length; i++) {
final int curCol = i;
boolean toDisplay = true;
if (toDisplay) {
final TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle(titles[i]);
column.setModifiable(true);
column.setMinimumWidth(100);
column.setWeight(20);
String[] stringToDisplay = null;
if (element instanceof Node) {
List<IConnection> listConnection = (List<IConnection>) ((Node) element).getInputs();
for (IConnection con : listConnection) {
if (con.getName().equals(titles[i])) {
List<IMetadataColumn> columns = con.getMetadataTable().getListColumns();
stringToDisplay = new String[columns.size()];
for (int j = 0; j < columns.size(); j++) {
stringToDisplay[j] = columns.get(j).getLabel();
}
}
}
}
final EditableComboBoxCellEditor cellEditor = new EditableComboBoxCellEditor(table, stringToDisplay);
// column.setLabelProvider(new IColumnLabelProvider() {
//
// @Override
// public String getLabel(Object bean) {
// if (bean instanceof Map) {
// Map valueMap = (Map) bean;
// String columnName = column.getTitle();
// if (valueMap.containsKey(columnName)) {
// String value = (String) valueMap.get(columnName);
// return value;
// }
// }
// return ""; //$NON-NLS-1$
// }
// });
// column.setCellEditor(cellEditor);
column.setCellEditor(cellEditor, new CellEditorValueAdapter() {
@Override
public String getColumnText(CellEditor cellEditor, Object bean, Object cellEditorValue) {
Map valueMap = (Map) bean;
String columnName = column.getTitle();
if (valueMap.containsKey(columnName)) {
String value = (String) valueMap.get(columnName);
return value;
}
return "";
}
@Override
public Object getOriginalTypedValue(CellEditor cellEditor, Object cellEditorTypedValue) {
Object returnedValue = null;
CCombo combo = (CCombo) cellEditor.getControl();
int rowNumber = ((Table) combo.getParent()).getSelectionIndex();
String[] listToDisplay = getItem(element, column.getTitle());
if (!Arrays.equals(listToDisplay, ((ComboBoxCellEditor) cellEditor).getItems())) {
((ComboBoxCellEditor) cellEditor).setItems(listToDisplay);
}
if (cellEditorTypedValue != null && cellEditorTypedValue instanceof String) {
return cellEditorTypedValue;
}
return "";
}
;
@Override
public Object getCellEditorTypedValue(CellEditor cellEditor, Object originalTypedValue) {
CCombo combo = (CCombo) cellEditor.getControl();
int rowNumber = ((Table) combo.getParent()).getSelectionIndex();
String[] listToDisplay = getItem(element, column.getTitle());
if (!Arrays.equals(listToDisplay, ((ComboBoxCellEditor) cellEditor).getItems())) {
((ComboBoxCellEditor) cellEditor).setItems(listToDisplay);
}
Object returnedValue = 0;
if (originalTypedValue != null) {
String[] namesSet = listToDisplay;
for (int j = 0; j < namesSet.length; j++) {
if (namesSet[j].equals(originalTypedValue)) {
returnedValue = j;
break;
}
}
}
return returnedValue;
}
;
private String[] getItem(IElement element, String columnName) {
List<String> stringToDisplay = new ArrayList<String>();
if (element instanceof Node) {
List<IConnection> listConnection = (List<IConnection>) ((Node) element).getInputs();
for (IConnection con : listConnection) {
if (con.getName().equals(columnName)) {
List<IMetadataColumn> columns = con.getMetadataTable().getListColumns();
for (IMetadataColumn column : columns) {
stringToDisplay.add(column.getLabel());
}
}
}
}
String[] listToDisplay = stringToDisplay.toArray(new String[0]);
return listToDisplay;
}
});
column.setColumnCellModifier(new ColumnCellModifier(column) {
@Override
public boolean canModify(Object bean) {
boolean canModify = super.canModify(bean);
return canModify;
}
@Override
public Object getValue(Object bean) {
Map valueMap = (Map) bean;
String columnName = column.getTitle();
if (valueMap.containsKey(columnName)) {
String value = (String) valueMap.get(columnName);
return value;
}
return "";
}
});
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<B, Object>() {
@Override
public Object get(B bean) {
Map valueMap = (Map) bean;
String columnName = column.getTitle();
if (valueMap.containsKey(columnName)) {
return valueMap.get(columnName);
}
return "";
}
@Override
public void set(B bean, Object value) {
if (value == null) {
return;
}
Map valueMap = (Map) bean;
String columnName = column.getTitle();
if (valueMap.containsKey(columnName)) {
valueMap.remove(columnName);
valueMap.put(columnName, value);
} else {
valueMap.put(columnName, value);
}
}
});
}
}
}
}
use of org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn in project tdi-studio-se by Talend.
the class AbstractHL7MetadataTableEditorView method configureDefaultColumn.
/**
* DOC amaumont Comment method "configureDefaultColumn".
*
* @param tableViewerCreator
*/
protected void configureDefaultColumn(TableViewerCreator<B> tableViewerCreator) {
TableViewerCreatorColumn column;
column = new TableViewerCreatorColumn(tableViewerCreator);
//$NON-NLS-1$
column.setTitle(Messages.getString("MetadataTableEditorView.DefaultTitle"));
//$NON-NLS-1$
column.setToolTipHeader(Messages.getString("MetadataTableEditorView.DefaultTitle"));
column.setId(ID_COLUMN_DEFAULT);
column.setBeanPropertyAccessors(getDefaultValueAccessor());
column.setWeight(8);
column.setModifiable(!isReadOnly());
column.setMinimumWidth(30);
//$NON-NLS-1$
column.setDefaultInternalValue("");
column.setCellEditor(new TextCellEditor(tableViewerCreator.getTable()));
}
use of org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn in project tdi-studio-se by Talend.
the class AbstractHL7MetadataTableEditorView method configureDbColumnName.
/**
* DOC amaumont Comment method "configureNameColumn".
*
* @param tableViewerCreator
*/
protected void configureDbColumnName(TableViewerCreator<B> tableViewerCreator) {
TableViewerCreatorColumn column;
column = new TableViewerCreatorColumn(tableViewerCreator);
column.setId(ID_COLUMN_DBCOLUMNNAME);
//$NON-NLS-1$
column.setTitle("Mapping Column");
//$NON-NLS-1$
column.setToolTipHeader(Messages.getString("MetadataTableEditorView.ColumnTitle"));
column.setBeanPropertyAccessors(getDbColumnNameAccessor());
column.setWeight(25);
column.setModifiable(!isReadOnly());
column.setMinimumWidth(45);
final TextCellEditor cellEditor = new TextCellEditor(tableViewerCreator.getTable());
column.setCellEditor(cellEditor);
column.setColumnCellModifier(new ColumnCellModifier(column) {
@Override
public boolean canModify(Object bean) {
return super.canModify(bean) && canModifyDBColumn(bean);
}
});
column.setCellEditorAppliedListener(new ITableCellValueModifiedListener() {
public void cellValueModified(TableCellValueModifiedEvent e) {
linker.getMainui().redrawLinkers();
linker.getBackgroundRefresher().refreshBackground();
}
});
if (!dbColumnNameWritable) {
column.setColorProvider(new IColumnColorProvider() {
public Color getBackgroundColor(Object bean) {
return READONLY_CELL_BG_COLOR;
}
public Color getForegroundColor(Object bean) {
return null;
}
});
}
}
use of org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn in project tdi-studio-se by Talend.
the class AbstractHL7MetadataTableEditorView method configureNameColumn.
/**
* DOC amaumont Comment method "configureNameColumn".
*
* @param tableViewerCreator
*/
protected void configureNameColumn(TableViewerCreator<B> tableViewerCreator) {
TableViewerCreatorColumn column;
column = new TableViewerCreatorColumn(tableViewerCreator);
column.setId(ID_COLUMN_NAME);
//$NON-NLS-1$
column.setTitle("User Column(Click to edit)");
//$NON-NLS-1$
column.setToolTipHeader(Messages.getString("MetadataTableEditorView.ColumnTitle"));
column.setBeanPropertyAccessors(getLabelAccessor());
final Image imageKey = ImageProvider.getImage(EImage.KEY_ICON);
final Image imageEmpty = org.talend.commons.ui.runtime.image.ImageProvider.getImage(EImage.EMPTY);
final TextCellEditor cellEditor = new TextCellEditor(tableViewerCreator.getTable());
column.setCellEditor(cellEditor);
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.setImageProvider(new IColumnImageProvider() {
public Image getImage(Object element) {
if (getKeyAccesor().get((B) element)) {
return imageKey;
} else {
return imageEmpty;
}
}
});
column.setWeight(25);
column.setModifiable(!isReadOnly());
column.setMinimumWidth(45);
// final TextCellEditor cellEditor = new TextCellEditor(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);
nameColumn = column;
}
use of org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn in project tdi-studio-se by Talend.
the class AbstractHL7MetadataTableEditorView method configurePrecisionColumn.
/**
* DOC amaumont Comment method "configurePrecisionColumn".
*
* @param tableViewerCreator
*/
protected void configurePrecisionColumn(TableViewerCreator<B> tableViewerCreator) {
TableViewerCreatorColumn column;
column = new TableViewerCreatorColumn(tableViewerCreator);
//$NON-NLS-1$
column.setTitle(Messages.getString("MetadataTableEditorView.PrecisionTitle"));
//$NON-NLS-1$
column.setToolTipHeader(Messages.getString("MetadataTableEditorView.PrecisionTitle"));
column.setId(ID_COLUMN_PRECISION);
column.setBeanPropertyAccessors(getPrecisionAccessor());
column.setModifiable(!isReadOnly());
column.setWeight(10);
column.setMinimumWidth(10);
column.setCellEditor(new TextCellEditor(tableViewerCreator.getTable()), CellEditorValueAdapterFactory.getPositiveIntAdapter());
}
Aggregations