List of usage examples for org.eclipse.jface.viewers ComboBoxCellEditor getItems
public String[] getItems()
From source file:com.microsoft.tfs.client.common.ui.wit.qe.QueryEditorCellModifier.java
License:Open Source License
/** * Called to translated from a value supplied by a ComboBoxCellEditor into a * value suitable for setting into the model. This method makes use of the * modify listener that we hook onto the CCombo to retrieve typed text. *///from w w w . j a v a 2 s .co m private String getStringFromModifyComboBoxCellEditor(final Object value, final String property, final boolean mustBeItemInList) { final ComboBoxCellEditor comboBoxCellEditor = (ComboBoxCellEditor) getCellEditorForProperty(property); final String[] items = comboBoxCellEditor.getItems(); final int index = ((Integer) value).intValue(); /* * When you tab-away from a field, modify gets called with the index of * the currently selected item. If the user has entered text into the * cell then we should use the user-entered value instead of the value * at the specified index. Otherwise, pressing 'tab' would clear what * the user just typed */ if (index == -1 || propertyNameToComboText.containsKey(property)) { if (propertyNameToComboText.containsKey(property)) { final String text = propertyNameToComboText.get(property); if (!mustBeItemInList) { return text; } for (int i = 0; i < items.length; i++) { if (items[i].equalsIgnoreCase(text)) { return items[i]; } } } } else { return items[index]; } return null; }
From source file:com.microsoft.tfs.client.common.ui.wit.qe.QueryEditorCellModifier.java
License:Open Source License
/** * Computes an Integer value to give to a ComboBoxCellEditor. The value * corresponds to an index into the cell editor's array of items. The item * at that index is equal to the current value held in the model. *///from w w w . j ava2 s . c o m private Integer getValueForComboBoxCellEditor(final String objectModelValue, final String property) { propertyNameToComboText.remove(property); if (objectModelValue == null) { return new Integer(-1); } final ComboBoxCellEditor comboBoxCellEditor = (ComboBoxCellEditor) getCellEditorForProperty(property); final String[] items = comboBoxCellEditor.getItems(); for (int i = 0; i < items.length; i++) { if (objectModelValue.equalsIgnoreCase(items[i])) { return new Integer(i); } } return new Integer(-1); }
From source file:com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject.java
License:Open Source License
public void setPropertyValue(Object id, Object value) { DatabaseObject databaseObject = getObject(); Object oldValue = getPropertyValue(id); String propertyName = (String) id; ComboBoxCellEditor editor = DynamicComboBoxPropertyDescriptor.getLast(); if (editor != null && !Integer.valueOf(editor.getItems().length - 1).equals(value)) { editor = null;/*from w ww .ja v a2 s. c o m*/ } if (isValueInProcess || (oldValue != null && oldValue.equals(value) && editor == null)) { return; } try { isValueInProcess = true; java.beans.PropertyDescriptor databaseObjectPropertyDescriptor = getPropertyDescriptor(propertyName); TreeViewer viewer = (TreeViewer) getAdapter(TreeViewer.class); if (databaseObjectPropertyDescriptor == null) return; Class<?> propertyClass = databaseObjectPropertyDescriptor.getPropertyType(); Class<?> pec = databaseObjectPropertyDescriptor.getPropertyEditorClass(); if (editor != null) { Control control = editor.getControl(); Display display = control.getDisplay(); final Shell shell = new Shell(control.getShell(), SWT.ON_TOP | SWT.TOOL | SWT.NO_FOCUS | SWT.APPLICATION_MODAL); shell.setLocation(control.toDisplay(0, 0)); shell.setSize(control.getSize()); shell.setLayout(new FillLayout()); final Text text = new Text(shell, SWT.NONE); final String[] newValue = new String[] { null }; String[] items = editor.getItems(); text.setText(items[items.length - 1]); text.addTraverseListener(new TraverseListener() { @Override public void keyTraversed(TraverseEvent e) { if (e.detail == SWT.TRAVERSE_RETURN) { newValue[0] = text.getText(); shell.close(); } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } if (newValue[0] != null) { value = newValue[0]; } } Object oriValue = value; boolean changed; do { changed = false; boolean wasSymbolError = databaseObject.isSymbolError(); value = databaseObject.compileProperty(propertyClass, propertyName, oriValue); try { oldValue = Engine.theApp.databaseObjectsManager.getCompiledValue(oldValue); } catch (UndefinedSymbolsException e) { oldValue = e.incompletValue(); } Set<String> symbolsErrors = databaseObject.getSymbolsErrors(propertyName); if (symbolsErrors != null) { boolean[] res = ConvertigoPlugin.warningGlobalSymbols(databaseObject.getProject().getName(), databaseObject.getName(), databaseObject.getDatabaseType(), propertyName, "" + databaseObject.getCompilablePropertySourceValue(propertyName), symbolsErrors, false); changed = res[0]; if (changed) { Engine.theApp.databaseObjectsManager.symbolsCreateUndefined(symbolsErrors); } else { databaseObject.getProject().undefinedGlobalSymbols = true; viewer.update(getProjectTreeObject(), null); } } else if (wasSymbolError) { Engine.theApp.databaseObjectsManager .symbolsProjectCheckUndefined(databaseObject.getProject().getName()); viewer.update(getProjectTreeObject(), null); } } while (changed); if (editor != null && value instanceof String) { String[] items = editor.getItems(); int len = items.length - 1; String strValue = (String) value; value = 0; for (int i = 0; i < len; i++) { if (items[i].equals(strValue)) { value = i; break; } ; } } if (pec != null && propertyClass != int.class && propertyClass != Integer.class && value instanceof Integer) { Object[] values = null; try { if (PropertyWithTagsEditorAdvance.class.isAssignableFrom(pec)) { Method getTags = pec.getMethod("getTags", new Class[] { DatabaseObjectTreeObject.class, String.class }); values = (String[]) getTags.invoke(null, new Object[] { this, propertyName }); value = values[(Integer) value]; } else if (Enum.class.isAssignableFrom(pec)) { values = (Enum[]) pec.getMethod("values").invoke(null); value = values[(Integer) value]; } } catch (ArrayIndexOutOfBoundsException e) { value = values.length > 0 ? values[0] : ""; String message = "Incorrect property \"" + propertyName + "\" value for the object \"" + databaseObject.getName() + "\"."; ConvertigoPlugin.logWarning(message); } } if ((EmulatorTechnologyEditor.class.equals(pec))) { Method getEmulatorClassNames = pec.getDeclaredMethod("getEmulatorClassNames", new Class[] { DatabaseObjectTreeObject.class }); String[] emulatorClassNames = (String[]) getEmulatorClassNames.invoke(null, new Object[] { this }); value = emulatorClassNames[((Integer) value).intValue()]; } // Must rename bean when normalizedScreenClassName changed if (databaseObject instanceof ScHandlerStatement) { ScHandlerStatement scHandlerStatement = (ScHandlerStatement) databaseObject; if (propertyName.equals("normalizedScreenClassName")) { if (!this.rename("on" + (String) value + scHandlerStatement.getHandlerType(), Boolean.FALSE)) return; } } // Must rename bean when handlerType changed else if ((databaseObject instanceof HandlerStatement) && !(databaseObject instanceof ScDefaultHandlerStatement)) { //HandlerStatement handlerStatement = (HandlerStatement)databaseObject; if (propertyName.equals("handlerType")) { if (!this.rename("on" + (String) value, Boolean.FALSE)) return; } } // Set property's nillable value if (Boolean.TRUE.equals(databaseObjectPropertyDescriptor.getValue("nillable"))) { try { PropertyDescriptor pd = findPropertyDescriptor(propertyName); if ((pd != null) && (pd instanceof DataOrNullPropertyDescriptor)) { Boolean isNull = ((DataOrNullPropertyDescriptor) pd).isNullProperty(); ((INillableProperty) databaseObject).setNullProperty(propertyName, isNull); if (isNull) { // Overrides fake editor value to real bean's one if (value instanceof String) value = ""; if (value instanceof XMLVector) value = new XMLVector<Object>(); } } } catch (Exception e) { String message = "Error while trying to set 'isNull' attribute of property \"" + propertyName + "\" for the object \"" + databaseObject.getName() + "\"."; ConvertigoPlugin.logException(e, message); } } // Check XML name property value if needed if (Boolean.TRUE.equals(databaseObjectPropertyDescriptor.getValue(DatabaseObject.PROPERTY_XMLNAME))) { if (value instanceof String) { String sValue = value.toString(); if (!XMLUtils.checkName(sValue)) { String message = "The property \"" + propertyName + "\" value for the object \"" + databaseObject.getName() + "\" is not a valid XML name: " + sValue; ConvertigoPlugin.logWarning(message); return; } } } Method setter = databaseObjectPropertyDescriptor.getWriteMethod(); Object args[] = { value }; setter.invoke(databaseObject, args); hasBeenModified(true); // Set treeObject isEnabled attribute value (Fix #1129) if (propertyName.equals("isEnabled") || propertyName.equals("isEnable")) { setEnabled(value.equals(true)); } viewer.update(this, null); // Fix #2528 #2533 : commented next line because of stack overflow on multiselection //viewer.setSelection(viewer.getSelection(),true); //update property view and display the new value for zone editor if (pec != null) { PropertySheet propertySheet = ConvertigoPlugin.getDefault().getPropertiesView(); if (propertySheet != null && pec.getName().contains("ZoneEditor")) { Tree tree = (Tree) propertySheet.getCurrentPage().getControl(); TreeItem[] treeItems = tree.getSelection(); for (int i = 0; i < treeItems.length; i++) { TreeItem treeItem = treeItems[i]; if (treeItem.getText().equals(databaseObjectPropertyDescriptor.getDisplayName())) { PropertySheetEntry propEntry = (PropertySheetEntry) treeItem.getData(); propEntry.getEditor(tree).setValue(value); propEntry.setValues(args); } } tree.update(); } } TreeObjectEvent treeObjectEvent = new TreeObjectEvent(this, propertyName, oldValue, value); ConvertigoPlugin.projectManager.getProjectExplorerView().fireTreeObjectPropertyChanged(treeObjectEvent); } catch (Exception e) { String message = "Error while trying to set property \"" + propertyName + "\" value for the object \"" + databaseObject.getName() + "\"."; ConvertigoPlugin.logException(e, message); } finally { isValueInProcess = false; } }
From source file:org.eclipse.graphiti.ui.internal.parts.directedit.GFCellEditorValidator.java
License:Open Source License
@Override public String isValid(Object value) { if (!directEditHolder.isSimpleMode()) { return isValidProposal(value); }/*w w w.j a v a 2s. co m*/ String ret = null; if (value instanceof String) { ret = directEditHolder.getDirectEditingFeature().checkValueValid((String) value, directEditHolder.getDirectEditingContext()); } else if (value instanceof Integer && getCellEditor() instanceof ComboBoxCellEditor) { ComboBoxCellEditor cb = (ComboBoxCellEditor) getCellEditor(); String sValue = null; int index = (Integer) value; if (index < 0) { // -1 if user inserted a new value Control control = cb.getControl(); if (control instanceof CCombo) { CCombo cc = (CCombo) control; sValue = cc.getText(); } } else { String[] items = cb.getItems(); if (items != null && index < items.length) { sValue = items[index]; } } if (sValue != null) { ret = directEditHolder.getDirectEditingFeature().checkValueValid(sValue, directEditHolder.getDirectEditingContext()); } } return ret; }
From source file:org.locationtech.udig.catalog.service.database.ExtraParams.java
License:Open Source License
/** * Create a combo based Extra param//w w w. ja v a2 s. co m * * @param name name to display * @param param the actual param * @param defaultValue the default value to set if null then the first option is set * @param options the list of options to put in the combo */ public static ExtraParams combo(String name, Param param, final String defaultValue, final String... options) { int current = 0; if (defaultValue != null) { for (String option : options) { if (option.equals(defaultValue)) { break; } current++; } if (current >= options.length) { CatalogUIPlugin.log("ERROR: " + defaultValue + " is not one of the legal options", new Exception()); current = 0; } } final int choice = current; return new ExtraParams(name, param) { @Override public CellEditor createCellEditor(Composite parent) { ComboBoxCellEditor comboBoxCellEditor = new ComboBoxCellEditor(parent, options); comboBoxCellEditor.setValue(choice); return comboBoxCellEditor; } @Override public Serializable convertValue(Object cellEditorValue) { ComboBoxCellEditor editor = (ComboBoxCellEditor) getCellEditor(); String value = editor.getItems()[(Integer) cellEditorValue]; return super.convertValue(value); } @Override public void setValue(String value) { int index = 0; for (String option : options) { if (option.equals(value)) { getCellEditor().setValue(index); return; } index++; } throw new IllegalArgumentException( value + " is not one of the options in the combo:" + (Arrays.toString(options))); } @Override public String getValue() { ComboBoxCellEditor editor = (ComboBoxCellEditor) getCellEditor(); int cellEditorValue = (Integer) editor.getValue(); String value = editor.getItems()[cellEditorValue]; return value; } }; }
From source file:org.talend.designer.pigmap.policy.PigDirectEditPolicy.java
License:Open Source License
@Override protected Command getDirectEditCommand(DirectEditRequest request) { Command command = null;//from w ww.j a v a 2 s. c o m 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 JOIN_MODEL: case JOIN_OPTIMIZATION: case OUTPUT_REJECT: case LOOK_UP_INNER_JOIN_REJECT: if (editor instanceof ComboBoxCellEditor) { ComboBoxCellEditor combo = (ComboBoxCellEditor) editor; int selectIndex = (Integer) combo.getValue(); command = new TableSettingDirectEditCommand(model, type, combo.getItems()[selectIndex]); } break; case CUSTOM_PARTITIONER: case INCREASE_PARALLELISM: case EXPRESSION_FILTER: if (editor instanceof TextCellEditor) { command = new TableSettingDirectEditCommand(model, type, request.getCellEditor().getValue()); } default: break; } } else { switch (type) { case JOIN_MODEL: case JOIN_OPTIMIZATION: 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 TableSettingDirectEditCommand(getHost().getModel(), type, combo.getItems()[selectIndex]); } break; case CUSTOM_PARTITIONER: case INCREASE_PARALLELISM: case EXPRESSION_FILTER: command = new TableSettingDirectEditCommand(getHost().getModel(), type, request.getCellEditor().getValue()); } } } return command; }