use of org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter in project tdi-studio-se by Talend.
the class DataMapTableView method createExpressionCellEditor.
protected TextCellEditor createExpressionCellEditor(final TableViewerCreator tableViewerCreator, TableViewerCreatorColumn column, final Zone[] zones, boolean isConstraintExpressionCellEditor) {
final TextCellEditorWithProposal cellEditor = new TextCellEditorWithProposal(tableViewerCreator.getTable(), SWT.MULTI | SWT.BORDER, column);
final Text expressionTextEditor = (Text) cellEditor.getControl();
if (isConstraintExpressionCellEditor) {
// moved to it's caller to execute
// constraintExpressionTextEditor = expressionTextEditor;
} else {
columnExpressionTextEditor = expressionTextEditor;
}
cellEditor.addListener(new ICellEditorListener() {
Text text = (Text) cellEditor.getControl();
@Override
public void applyEditorValue() {
ModifiedObjectInfo modifiedObjectInfo = tableViewerCreator.getModifiedObjectInfo();
mapperManager.getUiManager().parseNewExpression(text.getText(), (ITableEntry) modifiedObjectInfo.getCurrentModifiedBean(), true);
}
@Override
public void cancelEditor() {
ModifiedObjectInfo modifiedObjectInfo = tableViewerCreator.getModifiedObjectInfo();
text.setText((String) modifiedObjectInfo.getOriginalPropertyBeanValue());
ITableEntry tableEntry = (ITableEntry) (modifiedObjectInfo.getCurrentModifiedBean() != null ? modifiedObjectInfo.getCurrentModifiedBean() : modifiedObjectInfo.getPreviousModifiedBean());
String originalExpression = (String) modifiedObjectInfo.getOriginalPropertyBeanValue();
mapperManager.getUiManager().parseNewExpression(originalExpression, tableEntry, true);
}
@Override
public void editorValueChanged(boolean oldValidState, boolean newValidState) {
if (expressionTextEditor.isFocusControl() || lastExpressionEditorTextWhichLostFocus == expressionTextEditor) {
ModifiedObjectInfo modifiedObjectInfo = tableViewerCreator.getModifiedObjectInfo();
ITableEntry tableEntry = (ITableEntry) (modifiedObjectInfo.getCurrentModifiedBean() != null ? modifiedObjectInfo.getCurrentModifiedBean() : modifiedObjectInfo.getPreviousModifiedBean());
mapperManager.getUiManager().parseNewExpression(text.getText(), tableEntry, false);
resizeTextEditor(text, tableViewerCreator);
}
}
});
expressionTextEditor.addControlListener(new ControlListener() {
ExecutionLimiter executionLimiter = null;
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
if (executionLimiter == null) {
executionLimiter = new ExecutionLimiter(50, true) {
@Override
public void execute(boolean isFinalExecution, Object data) {
if (isFinalExecution && !expressionTextEditor.isDisposed()) {
expressionTextEditor.getDisplay().syncExec(new Runnable() {
@Override
public void run() {
if (expressionTextEditor.isDisposed()) {
return;
}
resizeTextEditor(expressionTextEditor, tableViewerCreator);
}
});
}
}
};
}
executionLimiter.startIfExecutable();
}
});
expressionTextEditor.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
ITableEntry currentModifiedEntry = (ITableEntry) tableViewerCreator.getModifiedObjectInfo().getCurrentModifiedBean();
initExpressionProposals(cellEditor, zones, tableViewerCreator, currentModifiedEntry);
resizeTextEditor(expressionTextEditor, tableViewerCreator);
StyledTextHandler styledTextHandler = mapperManager.getUiManager().getTabFolderEditors().getStyledTextHandler();
styledTextHandler.setCurrentEntry(currentModifiedEntry);
//$NON-NLS-1$
styledTextHandler.setTextWithoutNotifyListeners(currentModifiedEntry.getExpression() == null ? "" : currentModifiedEntry.getExpression());
}
@Override
public void focusLost(FocusEvent e) {
expressionEditorTextSelectionBeforeFocusLost = expressionTextEditor.getSelection();
lastExpressionEditorTextWhichLostFocus = expressionTextEditor;
}
});
column.setCellEditor(cellEditor, new CellEditorValueAdapter() {
@Override
public Object getCellEditorTypedValue(CellEditor cellEditor, Object originalTypedValue) {
return super.getCellEditorTypedValue(cellEditor, originalTypedValue);
}
@Override
public String getColumnText(CellEditor cellEditor, Object bean, Object cellEditorTypedValue) {
//$NON-NLS-1$ //$NON-NLS-2$
return super.getColumnText(cellEditor, bean, cellEditorTypedValue).replaceAll("[\r\n\t]+", " ... ");
}
@Override
public Object getOriginalTypedValue(CellEditor cellEditor, Object cellEditorTypedValue) {
return super.getOriginalTypedValue(cellEditor, cellEditorTypedValue);
}
});
return cellEditor;
}
use of org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter in project tdi-studio-se by Talend.
the class MetadataTableEditorViewExt method configureFunctionColumns.
/**
* qzhang Comment method "configureFunctionColumns".
*
* @param tableViewerCreator
*/
private void configureFunctionColumns(TableViewerCreator<IMetadataColumn> tableViewerCreator) {
//$NON-NLS-1$
CellEditorValueAdapter comboValueAdapter = CellEditorValueAdapterFactory.getComboAdapterForComboCellEditor("String");
final TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
final ComboBoxCellEditor functComboBox = new ComboBoxCellEditor();
functComboBox.create(tableViewerCreator.getTable());
CCombo functCombo = (CCombo) functComboBox.getControl();
functCombo.setEditable(false);
column.setCellEditor(functComboBox, comboValueAdapter);
// if (functComboBox.getControl() instanceof CCombo) {
// final CCombo combo = (CCombo) functComboBox.getControl();
// combo.addSelectionListener(new SelectionAdapter() {
//
// /*
// * (non-Javadoc)
// *
// * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
// */
// @Override
// public void widgetSelected(SelectionEvent e) {
// if (getTable() != null) {
// generatorUI.updateFunParameter(getTable());
// }
// }
// });
// }
column.setId(ID_COLUMN_FUNCTION);
//$NON-NLS-1$
column.setTitle(Messages.getString("RowGenTableEditor2.Fuctions.TitleText"));
column.setBeanPropertyAccessors(getFunctionAccessor(functComboBox));
column.setModifiable(true);
column.setWeight(10);
column.setWidth(45);
}
use of org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter 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.runtime.swt.tableviewer.behavior.CellEditorValueAdapter in project tdi-studio-se by Talend.
the class AutoConversionTypesEditorView method configureTypeColumn.
private void configureTypeColumn(TableViewerCreator<AutoConversionType> tableViewerCreator, TableViewerCreatorColumn column) {
IBeanPropertyAccessors<AutoConversionType, Boolean> nullableAccessors = new IBeanPropertyAccessors<AutoConversionType, Boolean>() {
@Override
public Boolean get(AutoConversionType bean) {
return Boolean.TRUE;
}
@Override
public void set(AutoConversionType bean, Boolean value) {
return;
}
};
CellEditorValueAdapter comboValueAdapter = new JavaTypeComboValueAdapter(JavaTypesManager.getDefaultJavaType(), nullableAccessors);
String[] arrayTalendTypes = new String[0];
try {
arrayTalendTypes = MetadataTalendType.getTalendTypesLabels();
} catch (NoClassDefFoundError e) {
// shouln't be happend
// e.printStackTrace();
ExceptionHandler.process(e);
} catch (ExceptionInInitializerError e) {
// shouln't be happend
// e.printStackTrace();
ExceptionHandler.process(e);
}
ComboBoxCellEditor typeComboEditor = new ComboBoxCellEditor(tableViewerCreator.getTable(), arrayTalendTypes, SWT.READ_ONLY);
CCombo typeCombo = (CCombo) typeComboEditor.getControl();
typeCombo.setEditable(false);
column.setCellEditor(typeComboEditor, comboValueAdapter);
}
use of org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter in project tdi-studio-se by Talend.
the class SetLoopFunctionDialog method createDialogArea.
public Control createDialogArea(Composite parent) {
Composite composite = new Composite(parent, SWT.BORDER);
GridLayout layout = new GridLayout();
composite.setLayout(layout);
GridData data = new GridData(GridData.FILL_BOTH);
composite.setLayoutData(data);
tableViwer = new AbstractDataTableEditorView<TreeSchemaTableEntry>(composite, SWT.NONE, tableModel, false, true, false) {
@Override
protected void createColumns(TableViewerCreator<TreeSchemaTableEntry> tableViewerCreator, Table table) {
TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle("Sequence");
column.setWeight(40);
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeSchemaTableEntry, Object>() {
public Object get(TreeSchemaTableEntry bean) {
int index = getExtendedTableModel().getBeansList().indexOf(bean);
return getExtendedTableModel().getBeansList().indexOf(bean);
}
public void set(TreeSchemaTableEntry bean, Object value) {
// do nothing
}
});
column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle("Xpath");
column.setWeight(60);
String[] items = new String[inputLoops.size()];
for (int i = 0; i < inputLoops.size(); i++) {
items[i] = inputLoops.get(i).getXpath();
}
CellEditorValueAdapter comboValueAdapter = CellEditorValueAdapterFactory.getComboAdapterForComboCellEditor("String");
ComboBoxCellEditor cellEditor = new ComboBoxCellEditor(tableViewerCreator.getTable(), items, SWT.READ_ONLY);
column.setModifiable(true);
column.setCellEditor(cellEditor, comboValueAdapter);
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeSchemaTableEntry, Object>() {
public Object get(TreeSchemaTableEntry bean) {
return bean.getXPath();
}
public void set(TreeSchemaTableEntry bean, Object value) {
for (TreeNode loopNode : inputLoops) {
if (loopNode.getXpath().equals(value)) {
bean.setTreeNode(loopNode);
}
}
}
});
}
@Override
protected ExtendedToolbarView initToolBar() {
ExtendedToolbarView toolbarView = new ExtendedToolbarView(getMainComposite(), SWT.NONE, this.getExtendedTableViewer()) {
@Override
protected CopyPushButton createCopyPushButton() {
return null;
}
@Override
protected AddPushButton createAddPushButton() {
return new AddPushButtonForExtendedTable(this.toolbar, getExtendedTableViewer()) {
@Override
public boolean getEnabledState() {
return super.getEnabledState();
}
@Override
protected Object getObjectToAdd() {
TreeNode loopNodetoAdd = null;
for (TreeNode loopNode : inputLoops) {
boolean found = false;
for (TreeSchemaTableEntry extendedModel : getExtendedTableModel().getBeansList()) {
if (loopNode.getXpath().equals(extendedModel.getXPath())) {
found = true;
break;
}
}
if (!found) {
loopNodetoAdd = loopNode;
break;
}
}
if (loopNodetoAdd == null && !inputLoops.isEmpty()) {
loopNodetoAdd = inputLoops.get(0);
}
if (loopNodetoAdd != null) {
TreeSchemaTableEntry entry = new TreeSchemaTableEntry(loopNodetoAdd);
return entry;
}
return null;
}
};
}
};
return super.initToolBar();
}
};
tableViwer.setGridDataSize(400, 120);
statusLabel = new Label(composite, SWT.NONE);
statusLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
tableModel.addAfterOperationListListener(new IListenableListListener<TreeSchemaTableEntry>() {
public void handleEvent(ListenableListEvent<TreeSchemaTableEntry> event) {
updateStatus(true);
}
});
tableModel.setModifiedBeanListenable(tableViwer.getTableViewerCreator());
tableModel.addModifiedBeanListener(new IModifiedBeanListener<TreeSchemaTableEntry>() {
public void handleEvent(ModifiedBeanEvent<TreeSchemaTableEntry> event) {
updateStatus(false);
}
});
return composite;
}
Aggregations