use of org.eclipse.jface.viewers.ComboBoxCellEditor in project tdi-studio-se by Talend.
the class XmlDirectEditPolicy method getDirectEditCommand.
@Override
protected Command getDirectEditCommand(DirectEditRequest request) {
Command command = null;
CellEditor editor = request.getCellEditor();
Object directEditFeature = request.getDirectEditFeature();
if (directEditFeature instanceof DirectEditType) {
DirectEditType type = (DirectEditType) directEditFeature;
if (getHost().getModel() instanceof AbstractNode) {
AbstractNode model = (AbstractNode) getHost().getModel();
switch(type) {
case EXPRESSION:
case NODE_NAME:
command = new DirectEditCommand(getHost(), model, type, request.getCellEditor().getValue());
break;
case VAR_NODE_TYPE:
if (editor instanceof ComboBoxCellEditor) {
ComboBoxCellEditor combo = (ComboBoxCellEditor) editor;
int selectIndex = (Integer) combo.getValue();
command = new DirectEditCommand(getHost(), model, type, combo.getItems()[selectIndex]);
}
break;
case LOOKUP_MODEL:
case MATCH_MODEL:
case JOIN_MODEL:
case PERSISTENT_MODEL:
case OUTPUT_REJECT:
case LOOK_UP_INNER_JOIN_REJECT:
if (editor instanceof ComboBoxCellEditor) {
ComboBoxCellEditor combo = (ComboBoxCellEditor) editor;
int selectIndex = (Integer) combo.getValue();
command = new TreeSettingDirectEditCommand(model, type, combo.getItems()[selectIndex]);
}
break;
case EXPRESSION_FILTER:
if (editor instanceof TextCellEditor) {
command = new TreeSettingDirectEditCommand(model, type, request.getCellEditor().getValue());
}
default:
break;
}
} else {
switch(type) {
case LOOKUP_MODEL:
case MATCH_MODEL:
case JOIN_MODEL:
case PERSISTENT_MODEL:
case OUTPUT_REJECT:
case LOOK_UP_INNER_JOIN_REJECT:
case ALL_IN_ONE:
case ENABLE_EMPTY_ELEMENT:
if ((editor instanceof ComboBoxCellEditor)) {
ComboBoxCellEditor combo = (ComboBoxCellEditor) editor;
int selectIndex = (Integer) combo.getValue();
command = new TreeSettingDirectEditCommand(getHost().getModel(), type, combo.getItems()[selectIndex]);
}
break;
case EXPRESSION_FILTER:
command = new TreeSettingDirectEditCommand(getHost().getModel(), type, request.getCellEditor().getValue());
}
}
}
return command;
}
use of org.eclipse.jface.viewers.ComboBoxCellEditor in project tdi-studio-se by Talend.
the class TableController method updateColumnList.
private void updateColumnList(IElementParameter param) {
if (elem instanceof Node) {
ColumnListController.updateColumnList((Node) elem, null);
} else if (elem instanceof Connection) {
ColumnListController.updateColumnList(((Connection) elem).getSource(), null);
}
TableViewerCreator tableViewerCreator = (TableViewerCreator) hashCurControls.get(param.getName());
Object[] itemsValue = param.getListItemsValue();
if (tableViewerCreator != null) {
List colList = tableViewerCreator.getColumns();
for (int j = 0; j < itemsValue.length; j++) {
if (itemsValue[j] instanceof IElementParameter) {
IElementParameter tmpParam = (IElementParameter) itemsValue[j];
if (tmpParam.getFieldType() == EParameterFieldType.COLUMN_LIST || tmpParam.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST || tmpParam.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
if ((j + 1) >= colList.size()) {
break;
}
TableViewerCreatorColumnNotModifiable column = (TableViewerCreatorColumnNotModifiable) colList.get(j + 1);
CellEditor cellEditor = column.getCellEditor();
String[] oldItems = null;
if (cellEditor instanceof ComboBoxCellEditor) {
CCombo combo = (CCombo) cellEditor.getControl();
oldItems = combo.getItems();
combo.setItems(tmpParam.getListItemsDisplayName());
}
List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
String[] items = param.getListItemsDisplayCodeName();
for (int currentIndex = 0; currentIndex < paramValues.size(); currentIndex++) {
Map<String, Object> currentLine = paramValues.get(currentIndex);
Object o = currentLine.get(items[j]);
if (o instanceof Integer) {
Integer nb = (Integer) o;
if ((nb >= oldItems.length) || (nb == -1)) {
nb = new Integer(tmpParam.getIndexOfItemFromList((String) tmpParam.getDefaultClosedListValue()));
currentLine.put(items[j], nb);
} else {
nb = new Integer(tmpParam.getIndexOfItemFromList(oldItems[nb]));
currentLine.put(items[j], nb);
}
}
}
}
}
}
}
}
use of org.eclipse.jface.viewers.ComboBoxCellEditor in project tdi-studio-se by Talend.
the class VarsDataMapTableView method initColumnsOfTableColumns.
@Override
public void initColumnsOfTableColumns(final TableViewerCreator tableViewerCreatorForColumns) {
ECodeLanguage codeLanguage = LanguageProvider.getCurrentLanguage().getCodeLanguage();
TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
//$NON-NLS-1$
column.setTitle(Messages.getString("VarsDataMapTableView.columnTitle.expression"));
column.setId(DataMapTableView.ID_EXPRESSION_COLUMN);
expressionCellEditor = createExpressionCellEditor(tableViewerCreatorForColumns, column, new Zone[] { Zone.INPUTS, Zone.VARS }, false);
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<VarTableEntry, String>() {
public String get(VarTableEntry bean) {
return bean.getExpression();
}
public void set(VarTableEntry bean, String value) {
bean.setExpression(value);
mapperManager.getProblemsManager().checkProblemsForTableEntry(bean, true);
}
});
column.setModifiable(!mapperManager.componentIsReadOnly());
//$NON-NLS-1$
column.setDefaultInternalValue("");
if (codeLanguage == ECodeLanguage.JAVA) {
column.setWeight(40);
} else {
column.setWeight(COLUMN_EXPRESSION_SIZE_WEIGHT);
}
if (codeLanguage == ECodeLanguage.JAVA) {
String[] arrayTalendTypes = new String[0];
try {
arrayTalendTypes = MetadataTalendType.getTalendTypesLabels();
arrayTalendTypes = this.talendTypeFilter.filter(arrayTalendTypes);
} catch (NoClassDefFoundError e) {
// shouln't be happend
// e.printStackTrace();
ExceptionHandler.process(e);
} catch (ExceptionInInitializerError e) {
// shouln't be happend
// e.printStackTrace();
ExceptionHandler.process(e);
}
IBeanPropertyAccessors<VarTableEntry, Boolean> nullableAccessors = new IBeanPropertyAccessors<VarTableEntry, Boolean>() {
public Boolean get(VarTableEntry bean) {
return bean.isNullable() ? Boolean.TRUE : Boolean.FALSE;
}
public void set(VarTableEntry bean, Boolean value) {
bean.setNullable(value.booleanValue());
}
};
CellEditorValueAdapter comboValueAdapter = new JavaTypeComboValueAdapter(JavaTypesManager.getDefaultJavaType(), nullableAccessors, this.talendTypeFilter);
column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
//$NON-NLS-1$
column.setTitle(Messages.getString("VarsDataMapTableView.columnTitle.type"));
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<VarTableEntry, String>() {
public String get(VarTableEntry bean) {
return bean.getType();
}
public void set(VarTableEntry bean, String value) {
bean.setType(value);
mapperManager.getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
}
});
column.setModifiable(!mapperManager.componentIsReadOnly());
column.setWeight(18);
column.setCellEditor(new ComboBoxCellEditor(tableViewerCreatorForColumns.getTable(), arrayTalendTypes), comboValueAdapter);
column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
//$NON-NLS-1$
column.setTitle("Nullable");
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<VarTableEntry, Boolean>() {
public Boolean get(VarTableEntry bean) {
return bean.isNullable();
}
public void set(VarTableEntry bean, Boolean value) {
bean.setNullable(value);
mapperManager.getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
}
});
column.setModifiable(!mapperManager.componentIsReadOnly());
column.setWidth(WindowSystem.isWIN32() ? 12 : 20);
//$NON-NLS-1$
column.setDisplayedValue("");
column.setResizable(false);
CheckboxTableEditorContent checkboxTableEditorContent = new CheckboxTableEditorContent();
//$NON-NLS-1$
String nullable = Messages.getString("VarsDataMapTableView.nullable");
checkboxTableEditorContent.setToolTipText(nullable);
column.setTableEditorContent(checkboxTableEditorContent);
column.setToolTipHeader(nullable);
}
column = new TableViewerCreatorColumn(tableViewerCreatorForColumns);
//$NON-NLS-1$
column.setTitle(Messages.getString("VarsDataMapTableView.columnTitle.variable"));
column.setId(DataMapTableView.ID_NAME_COLUMN);
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<VarTableEntry, String>() {
public String get(VarTableEntry bean) {
return bean.getName();
}
public void set(VarTableEntry bean, String value) {
bean.setName(value);
}
});
column.setModifiable(!mapperManager.componentIsReadOnly());
if (codeLanguage == ECodeLanguage.JAVA) {
column.setWeight(25);
} else {
column.setWeight(COLUMN_NAME_SIZE_WEIGHT);
}
final TextCellEditor cellEditor = new TextCellEditor(tableViewerCreatorForColumns.getTable());
cellEditor.addListener(new DialogErrorForCellEditorListener(cellEditor, column) {
@Override
public void newValidValueTyped(int itemIndex, Object previousValue, Object newValue, CELL_EDITOR_STATE state) {
if (state == CELL_EDITOR_STATE.APPLYING) {
ModifiedObjectInfo modifiedObjectInfo = tableViewerCreatorForColumns.getModifiedObjectInfo();
String originalValue = (String) modifiedObjectInfo.getOriginalPropertyBeanValue();
Object currentModifiedBean = modifiedObjectInfo.getCurrentModifiedBean();
mapperManager.getUiManager().processColumnNameChanged(originalValue.toString(), newValue.toString(), VarsDataMapTableView.this, (ITableEntry) currentModifiedBean);
}
}
@Override
public String validateValue(String newValue, int beanPosition) {
return ((VarsTable) getDataMapTable()).validateColumnName(newValue, beanPosition);
}
});
column.setCellEditor(cellEditor);
}
use of org.eclipse.jface.viewers.ComboBoxCellEditor in project tdi-studio-se by Talend.
the class InputDataMapTableView method getMapSettingValueAccess.
@Override
protected IBeanPropertyAccessors<GlobalMapEntry, Object> getMapSettingValueAccess(final CellEditor cellEditor) {
return new IBeanPropertyAccessors<GlobalMapEntry, Object>() {
public Object get(GlobalMapEntry bean) {
IDataMapTable parent = bean.getParent();
InputTable inputTable = (InputTable) parent;
if (cellEditor instanceof ComboBoxCellEditor) {
ComboBoxCellEditor functComboBox = (ComboBoxCellEditor) cellEditor;
if (LOOKUP_MODEL_SETTING.equals(bean.getName())) {
IUILookupMode[] availableJoins = { TMAP_LOOKUP_MODE.LOAD_ONCE, TMAP_LOOKUP_MODE.RELOAD, TMAP_LOOKUP_MODE.CACHE_OR_RELOAD };
List<String> names = new ArrayList<String>();
for (IUILookupMode availableJoin : availableJoins) {
names.add(availableJoin.getLabel());
}
functComboBox.setItems(names.toArray(new String[names.size()]));
final IUILookupMode lookupMode = ((InputTable) parent).getLookupMode();
if (lookupMode != null) {
return lookupMode.getLabel();
}
} else if (MATCH_MODEL_SETTING.equals(bean.getName())) {
IUIMatchingMode[] matchModel = getMatchModel();
List<String> names = new ArrayList<String>();
for (IUIMatchingMode element : matchModel) {
names.add(element.getLabel());
}
functComboBox.setItems(names.toArray(new String[names.size()]));
IUIMatchingMode matchingMode = ((InputTable) parent).getMatchingMode();
if (names.contains(matchingMode.getLabel())) {
return matchingMode.getLabel();
}
} else if (JOIN_MODEL_SETTING.equals(bean.getName())) {
String[] items = new String[] { INNER_JOIN, LEFT_OUTER_JOIN };
functComboBox.setItems(items);
boolean innerJoin = ((InputTable) parent).isInnerJoin();
if (innerJoin) {
return items[0];
}
return items[1];
} else if (PERSISTENCE_MODEL_SETTING.equals(bean.getName())) {
functComboBox.setItems(new String[] { "true", "false" });
boolean persistent = ((InputTable) parent).isPersistent();
return String.valueOf(persistent);
}
} else if (cellEditor instanceof CustomDialogCellEditor) {
CustomDialogCellEditor customDialogCellEditor = (CustomDialogCellEditor) cellEditor;
if (LOOKUP_MODEL_SETTING.equals(bean.getName())) {
customDialogCellEditor.setType(CellValueType.LOOKUP_MODEL);
final IUILookupMode lookupMode = inputTable.getLookupMode();
if (lookupMode != null) {
return lookupMode.getLabel();
}
} else if (MATCH_MODEL_SETTING.equals(bean.getName())) {
customDialogCellEditor.setType(CellValueType.MATCH_MODEL);
IUIMatchingMode matchingMode = inputTable.getMatchingMode();
if (matchingMode != null) {
return matchingMode.getLabel();
}
} else if (JOIN_MODEL_SETTING.equals(bean.getName())) {
customDialogCellEditor.setType(CellValueType.JOIN_MODEL);
boolean innerJoin = inputTable.isInnerJoin();
return innerJoin ? INNER_JOIN : LEFT_OUTER_JOIN;
} else if (PERSISTENCE_MODEL_SETTING.equals(bean.getName())) {
customDialogCellEditor.setType(CellValueType.BOOL);
boolean persistent = inputTable.isPersistent();
return String.valueOf(persistent);
} else if (SCHEMA_TYPE.equals(bean.getName())) {
customDialogCellEditor.setType(CellValueType.SCHEMA_TYPE);
enableDiaplayViewer(inputTable.isRepository());
return inputTable.isRepository() ? REPOSITORY : BUILT_IN;
} else if (SCHEMA_ID.equals(bean.getName())) {
customDialogCellEditor.setType(CellValueType.SCHEMA_ID);
return getSchemaDisplayName(inputTable.getId());
}
}
return "";
}
public void set(GlobalMapEntry bean, Object value) {
IDataMapTable parent = bean.getParent();
InputTable inputTable = (InputTable) parent;
if (LOOKUP_MODEL_SETTING.equals(bean.getName())) {
IUILookupMode[] availableJoins = { TMAP_LOOKUP_MODE.LOAD_ONCE, TMAP_LOOKUP_MODE.RELOAD, TMAP_LOOKUP_MODE.CACHE_OR_RELOAD };
for (final IUILookupMode lookupMode : availableJoins) {
if (value != null && value.equals(lookupMode.getLabel())) {
inputTable.setLookupMode(lookupMode);
if (TMAP_LOOKUP_MODE.CACHE_OR_RELOAD == lookupMode) {
persistentCheckEditable = false;
} else {
persistentCheckEditable = true;
}
if (lookupMode == TMAP_LOOKUP_MODE.RELOAD || lookupMode == TMAP_LOOKUP_MODE.CACHE_OR_RELOAD) {
showTableGlobalMap(true);
} else {
showTableGlobalMap(false);
}
enableDisablePersistentMode((TMAP_LOOKUP_MODE) lookupMode);
mapperManager.getProblemsManager().checkProblemsForTableEntry(bean, true);
checkChangementsAfterEntryModifiedOrAdded(true);
}
}
} else if (MATCH_MODEL_SETTING.equals(bean.getName())) {
for (IUIMatchingMode model : TMAP_MATCHING_MODE.values()) {
if (value != null && value.equals(model.getLabel())) {
inputTable.setMatchingMode(model);
previousMatchingModeSelected = model;
}
}
} else if (JOIN_MODEL_SETTING.equals(bean.getName())) {
if (LEFT_OUTER_JOIN.equals(value)) {
((InputTable) parent).setInnerJoin(false);
previousInnerJoinSelection = false;
} else {
((InputTable) parent).setInnerJoin(true);
previousInnerJoinSelection = true;
}
} else if (PERSISTENCE_MODEL_SETTING.equals(bean.getName())) {
if ("true".equals(value) || "false".equals(value)) {
((InputTable) parent).setPersistent(Boolean.valueOf(value.toString()));
previousValidPersistentMode = Boolean.valueOf(value.toString());
}
} else if (SCHEMA_TYPE.equals(bean.getName())) {
inputTable.setRepository(REPOSITORY.equals(value));
showSchemaIDSetting(REPOSITORY.equals(value));
enableDiaplayViewer(REPOSITORY.equals(value));
} else if (SCHEMA_ID.equals(bean.getName())) {
inputTable.setId(String.valueOf(value));
}
refreshCondensedImage((InputTable) bean.getParent(), bean.getName());
}
};
}
use of org.eclipse.jface.viewers.ComboBoxCellEditor in project sling by apache.
the class JcrEditingSupport method doGetCellEditor.
protected CellEditor doGetCellEditor(Object element) {
if (!canEdit(element)) {
return null;
}
switch(columnId) {
case NAME:
{
// no validator needed - any string is OK
return new TextCellEditor(tableViewer.getTable());
}
case TYPE:
{
// using a dropdown editor
final ComboBoxCellEditor editor = new ComboBoxCellEditor(tableViewer.getTable(), PropertyTypeSupport.PROPERTY_TYPES, SWT.NONE);
editor.setActivationStyle(ComboBoxCellEditor.DROP_DOWN_ON_KEY_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_TRAVERSE_ACTIVATION);
return editor;
}
case VALUE:
{
final Field field = asField(element);
if (getNode().getProperty(field.getPropertyName()).isMultiple()) {
// then launch the MVPEditor instead of returning an editor here
return new MVNCellEditor(tableViewer.getTable(), getNode(), field.getPropertyName());
}
if (field.getPropertyType() == PropertyType.DATE) {
return new DateTimeCellEditor(tableViewer.getTable(), getNode(), field.getPropertyName());
}
if (field.getPropertyType() == PropertyType.BOOLEAN) {
return new ComboBoxCellEditor(tableViewer.getTable(), new String[] { "false", "true" }, SWT.READ_ONLY);
}
CellEditor editor;
if (field.getPropertyName().equals("jcr:primaryType")) {
editor = new TextCellEditor(tableViewer.getTable()) {
@Override
protected Control createControl(Composite parent) {
Text text = (Text) super.createControl(parent);
Repository repository = ServerUtil.getDefaultRepository(getNode().getProject());
NodeTypeRegistry ntManager = (repository == null) ? null : repository.getNodeTypeRegistry();
if (ntManager == null) {
return text;
}
try {
Collection<String> types = ntManager.getAllowedPrimaryChildNodeTypes(getNode().getParent().getPrimaryType());
SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(types.toArray(new String[0]));
proposalProvider.setFiltering(true);
ContentProposalAdapter adapter = new ContentProposalAdapter(text, new TextContentAdapter(), proposalProvider, null, null);
adapter.setPropagateKeys(true);
adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
return text;
} catch (RepositoryException e) {
return text;
}
}
};
} else {
editor = new TextCellEditor(tableViewer.getTable());
}
// value might require a validator depending on the property type
int propertyType = getNode().getPropertyType(field.getPropertyName());
switch(propertyType) {
case PropertyType.STRING:
case PropertyType.NAME:
{
//TODO: check jcr rules for name
break;
}
case PropertyType.DECIMAL:
{
editor.setValidator(new DecimalValidator(editor));
break;
}
default:
{
//TODO
break;
}
}
return editor;
}
case MULTIPLE:
{
if (element instanceof NewRow) {
return null;
}
return new ComboBoxCellEditor(tableViewer.getTable(), new String[] { "false", "true" }, SWT.READ_ONLY);
}
default:
{
throw new IllegalStateException("Unknown columnId: " + columnId);
}
}
}
Aggregations