use of org.eclipse.jface.viewers.ICellEditorValidator in project tdi-studio-se by Talend.
the class GearBusinessItemNameEditPart method getEditTextValidator.
/**
* @generated
*/
public ICellEditorValidator getEditTextValidator() {
return new ICellEditorValidator() {
public String isValid(final Object value) {
if (value instanceof String) {
final EObject element = getParserElement();
final IParser parser = getParser();
try {
IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
public void run() {
setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
}
});
return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
} catch (InterruptedException ie) {
// ie.printStackTrace();
ExceptionHandler.process(ie);
}
}
// shouldn't get here
return null;
}
};
}
use of org.eclipse.jface.viewers.ICellEditorValidator in project tdi-studio-se by Talend.
the class DirectionalBusinessItemRelationshipNameEditPart method getEditTextValidator.
/**
* @generated
*/
public ICellEditorValidator getEditTextValidator() {
return new ICellEditorValidator() {
public String isValid(final Object value) {
if (value instanceof String) {
final EObject element = getParserElement();
final IParser parser = getParser();
try {
IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
public void run() {
setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
}
});
return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
} catch (InterruptedException e) {
// ie.printStackTrace();
ExceptionHandler.process(e);
}
}
// shouldn't get here
return null;
}
};
}
use of org.eclipse.jface.viewers.ICellEditorValidator in project tdi-studio-se by Talend.
the class InputBusinessItemNameEditPart method getEditTextValidator.
/**
* @generated
*/
public ICellEditorValidator getEditTextValidator() {
return new ICellEditorValidator() {
public String isValid(final Object value) {
if (value instanceof String) {
final EObject element = getParserElement();
final IParser parser = getParser();
try {
IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
public void run() {
setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
}
});
return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
} catch (InterruptedException ie) {
// ie.printStackTrace();
ExceptionHandler.process(ie);
}
}
// shouldn't get here
return null;
}
};
}
use of org.eclipse.jface.viewers.ICellEditorValidator in project mdw-designer by CenturyLinkCloud.
the class VariableValueDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
composite.getShell().setText("Variable Value");
Label nameLabel = new Label(composite, SWT.NONE);
nameLabel.setFont(new Font(nameLabel.getDisplay(), new FontData("Tahoma", 8, SWT.BOLD)));
nameLabel.setText(variableValue.getName());
final String type = variableValue.getType() == null ? "Unknown" : variableValue.getType().getVariableType();
new Label(composite, SWT.NONE).setText("(" + type + ")");
if (type.equals("java.lang.Boolean")) {
valueEditor = new PropertyEditor(null, PropertyEditor.TYPE_CHECKBOX);
} else if (type.equals("java.util.Date")) {
valueEditor = new PropertyEditor(null, PropertyEditor.TYPE_DATE_PICKER);
valueEditor.setWidth(100);
} else if (type.equals("java.lang.Integer") || type.equals("java.lang.Long")) {
valueEditor = new PropertyEditor(null, PropertyEditor.TYPE_TEXT);
valueEditor.setWidth(250);
valueEditor.addValueChangeListener(new ValueChangeListener() {
public void propertyValueChanged(Object newValue) {
String stringValue = (String) newValue;
try {
long val = type.equals("java.lang.Long") ? Long.parseLong(stringValue) : Integer.parseInt(stringValue);
variableValue.setValue(String.valueOf(val));
} catch (NumberFormatException ex) {
String oldValue = variableValue.getValue();
valueEditor.setValue(oldValue);
}
}
});
} else if (type.equals("java.net.URI")) {
valueEditor = new PropertyEditor(null, PropertyEditor.TYPE_TEXT);
valueEditor.setWidth(450);
valueEditor.addValueChangeListener(new ValueChangeListener() {
public void propertyValueChanged(Object newValue) {
try {
new URI((String) newValue);
valueEditor.setLabel("");
} catch (URISyntaxException ex) {
valueEditor.setLabel(ex.getMessage());
}
}
});
} else if (type.equals("java.lang.Integer[]") || type.equals("java.lang.Long[]") || type.equals("java.lang.String[]")) {
valueEditor = new TableEditor(null, TableEditor.TYPE_TABLE);
TableEditor tableEditor = (TableEditor) valueEditor;
List<ColumnSpec> columnSpecs = new ArrayList<ColumnSpec>();
ColumnSpec valueColSpec = new ColumnSpec(PropertyEditor.TYPE_TEXT, type.substring(type.lastIndexOf('.') + 1, type.length() - 2) + " Values", type);
columnSpecs.add(valueColSpec);
tableEditor.setColumnSpecs(columnSpecs);
tableEditor.setFillWidth(true);
tableEditor.setRowDelimiter(ROW_DELIMITER);
tableEditor.setModelUpdater(new CollectionModelUpdater(tableEditor));
} else if (type.equals("java.util.Map")) {
valueEditor = new MappingEditor(null);
MappingEditor mappingEditor = (MappingEditor) valueEditor;
List<ColumnSpec> columnSpecs = new ArrayList<ColumnSpec>();
ColumnSpec keyColSpec = new ColumnSpec(PropertyEditor.TYPE_TEXT, "Key", "key");
keyColSpec.width = 150;
columnSpecs.add(keyColSpec);
ColumnSpec valColSpec = new ColumnSpec(PropertyEditor.TYPE_TEXT, "Value", "value");
valColSpec.width = 150;
columnSpecs.add(valColSpec);
mappingEditor.setColumnSpecs(columnSpecs);
mappingEditor.setHeight(150);
mappingEditor.setFillWidth(true);
mappingEditor.setRowDelimiter(ROW_DELIMITER);
mappingEditor.setColumnDelimiter(COLUMN_DELIMITER);
mappingEditor.setContentProvider(mappingEditor.new DefaultContentProvider());
mappingEditor.setLabelProvider(((TableEditor) mappingEditor).new DefaultLabelProvider());
mappingEditor.setCellModifier(((TableEditor) mappingEditor).new DefaultCellModifier());
mappingEditor.setModelUpdater(new CollectionModelUpdater(mappingEditor));
} else {
valueEditor = new PropertyEditor(null, PropertyEditor.TYPE_TEXT);
valueEditor.setMultiLine(true);
valueEditor.setWidth(500);
valueEditor.setHeight(500);
}
valueEditor.setReadOnly(variableValue.isReadOnly());
valueEditor.render(composite);
valueEditor.setValue(variableValue.getValue());
if (!variableValue.isReadOnly()) {
valueEditor.addValueChangeListener(new ValueChangeListener() {
public void propertyValueChanged(Object newValue) {
Button okButton = getButton(Dialog.OK);
if (// else not editable
okButton != null)
okButton.setEnabled(true);
}
});
}
if (isCollectionType(type))
tentativeValueForCollection = variableValue.getValue();
if (type.equals("java.lang.Boolean"))
((Button) valueEditor.getWidget()).setText("(checked = true)");
else if (type.equals("java.lang.Object"))
valueEditor.setValue(variableValue.getValue() == null ? null : variableValue.getValue().toString());
else if (type.equals("java.lang.Integer[]") || type.equals("java.lang.Long[]")) {
if (!variableValue.isReadOnly()) {
TableEditor tableEditor = (TableEditor) valueEditor;
final CellEditor cellEditor = tableEditor.getTableViewer().getCellEditors()[0];
cellEditor.setValidator(new ICellEditorValidator() {
private String oldValue = "";
public String isValid(Object value) {
String message = validateValue((String) value, variableValue.getType().getVariableType());
if (message != null)
cellEditor.setValue(oldValue);
else
oldValue = (String) value;
return null;
}
});
}
} else if (type.equals("java.util.Map")) {
if (!variableValue.isReadOnly()) {
MappingEditor mappingEditor = (MappingEditor) valueEditor;
final CellEditor valueCellEditor = mappingEditor.getTableViewer().getCellEditors()[1];
valueCellEditor.setValidator(new ICellEditorValidator() {
public String isValid(Object value) {
String message = validateValue((String) value, variableValue.getType().getVariableType());
if (message != null)
getButton(Dialog.OK).setEnabled(false);
return null;
}
});
}
}
return composite;
}
use of org.eclipse.jface.viewers.ICellEditorValidator in project egit by eclipse.
the class ConfigurationEditorComponent method createContents.
/**
* @return the control being created
*/
public Control createContents() {
final Composite main = new Composite(parent, SWT.NONE);
main.setLayout(new GridLayout(2, false));
GridDataFactory.fillDefaults().grab(true, true).applyTo(main);
if (editableConfig instanceof FileBasedConfig) {
Composite locationPanel = new Composite(main, SWT.NONE);
GridLayout locationLayout = new GridLayout(3, false);
locationLayout.marginWidth = 0;
locationPanel.setLayout(locationLayout);
GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(locationPanel);
Label locationLabel = new Label(locationPanel, SWT.NONE);
locationLabel.setText(UIText.ConfigurationEditorComponent_ConfigLocationLabel);
// GridDataFactory.fillDefaults().applyTo(locationLabel);
int locationStyle = SWT.BORDER | SWT.READ_ONLY;
location = new Text(locationPanel, locationStyle);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(location);
Button openEditor = new Button(locationPanel, SWT.PUSH);
openEditor.setText(UIText.ConfigurationEditorComponent_OpenEditorButton);
openEditor.setToolTipText(UIText.ConfigurationEditorComponent_OpenEditorTooltip);
openEditor.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IFileStore store = EFS.getLocalFileSystem().getStore(new Path(((FileBasedConfig) editableConfig).getFile().getAbsolutePath()));
try {
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), new FileStoreEditorInput(store), EditorsUI.DEFAULT_TEXT_EDITOR_ID);
} catch (PartInitException ex) {
Activator.handleError(ex.getMessage(), ex, true);
}
}
});
openEditor.setEnabled(((FileBasedConfig) editableConfig).getFile() != null);
}
tv = new TreeViewer(main, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
Tree tree = tv.getTree();
GridDataFactory.fillDefaults().hint(100, 60).grab(true, true).applyTo(tree);
TreeColumn key = new TreeColumn(tree, SWT.NONE);
key.setText(UIText.ConfigurationEditorComponent_KeyColumnHeader);
key.setWidth(150);
final TextCellEditor editor = new TextCellEditor(tree);
editor.setValidator(new ICellEditorValidator() {
@Override
public String isValid(Object value) {
String editedValue = value.toString();
return editedValue.length() > 0 ? null : UIText.ConfigurationEditorComponent_EmptyStringNotAllowed;
}
});
editor.addListener(new ICellEditorListener() {
@Override
public void editorValueChanged(boolean oldValidState, boolean newValidState) {
setErrorMessage(editor.getErrorMessage());
}
@Override
public void cancelEditor() {
setErrorMessage(null);
}
@Override
public void applyEditorValue() {
setErrorMessage(null);
}
});
TreeColumn value = new TreeColumn(tree, SWT.NONE);
value.setText(UIText.ConfigurationEditorComponent_ValueColumnHeader);
value.setWidth(250);
new TreeViewerColumn(tv, value).setEditingSupport(new EditingSupport(tv) {
@Override
protected void setValue(Object element, Object newValue) {
Entry entry = (Entry) element;
if (!entry.value.equals(newValue)) {
entry.changeValue(newValue.toString());
markDirty();
}
}
@Override
protected Object getValue(Object element) {
return ((Entry) element).value;
}
@Override
protected CellEditor getCellEditor(Object element) {
return editor;
}
@Override
protected boolean canEdit(Object element) {
return editable && element instanceof Entry;
}
});
tv.setContentProvider(new WorkbenchContentProvider());
Font defaultFont;
if (useDialogFont)
defaultFont = JFaceResources.getDialogFont();
else
defaultFont = JFaceResources.getDefaultFont();
tv.setLabelProvider(new ConfigEditorLabelProvider(defaultFont));
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
Composite buttonPanel = new Composite(main, SWT.NONE);
GridLayoutFactory.fillDefaults().applyTo(buttonPanel);
GridDataFactory.fillDefaults().grab(false, false).applyTo(buttonPanel);
newValue = new Button(buttonPanel, SWT.PUSH);
GridDataFactory.fillDefaults().applyTo(newValue);
newValue.setText(UIText.ConfigurationEditorComponent_AddButton);
newValue.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String suggestedKey;
IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
Object first = sel.getFirstElement();
if (first instanceof Section)
suggestedKey = ((Section) first).name + DOT;
else if (first instanceof SubSection) {
SubSection sub = (SubSection) first;
suggestedKey = sub.parent.name + DOT + sub.name + DOT;
} else if (first instanceof Entry) {
Entry entry = (Entry) first;
if (entry.sectionparent != null)
suggestedKey = entry.sectionparent.name + DOT;
else
suggestedKey = entry.subsectionparent.parent.name + DOT + entry.subsectionparent.name + DOT;
} else
suggestedKey = null;
AddConfigEntryDialog dlg = new AddConfigEntryDialog(getShell(), suggestedKey);
if (dlg.open() == Window.OK) {
String result = dlg.getKey();
if (result == null) {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=472110
return;
}
StringTokenizer st = new StringTokenizer(result, DOT);
if (st.countTokens() == 2) {
String sectionName = st.nextToken();
String entryName = st.nextToken();
Entry entry = ((GitConfig) tv.getInput()).getEntry(sectionName, null, entryName);
if (entry == null)
editableConfig.setString(sectionName, null, entryName, dlg.getValue());
else
entry.addValue(dlg.getValue());
markDirty();
} else if (st.countTokens() > 2) {
int n = st.countTokens();
String sectionName = st.nextToken();
StringBuilder b = new StringBuilder(st.nextToken());
for (int i = 0; i < n - 3; i++) {
b.append(DOT);
b.append(st.nextToken());
}
String subSectionName = b.toString();
String entryName = st.nextToken();
Entry entry = ((GitConfig) tv.getInput()).getEntry(sectionName, subSectionName, entryName);
if (entry == null)
editableConfig.setString(sectionName, subSectionName, entryName, dlg.getValue());
else
entry.addValue(dlg.getValue());
markDirty();
} else
Activator.handleError(UIText.ConfigurationEditorComponent_WrongNumberOfTokensMessage, null, true);
}
}
});
remove = new Button(buttonPanel, SWT.PUSH);
GridDataFactory.fillDefaults().applyTo(remove);
remove.setText(UIText.ConfigurationEditorComponent_RemoveButton);
remove.setToolTipText(UIText.ConfigurationEditorComponent_RemoveTooltip);
remove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection sel = (IStructuredSelection) tv.getSelection();
Object first = sel.getFirstElement();
if (first instanceof Section) {
Section section = (Section) first;
if (MessageDialog.openConfirm(getShell(), UIText.ConfigurationEditorComponent_RemoveSectionTitle, NLS.bind(UIText.ConfigurationEditorComponent_RemoveSectionMessage, section.name))) {
editableConfig.unsetSection(section.name, null);
markDirty();
}
} else if (first instanceof SubSection) {
SubSection section = (SubSection) first;
if (MessageDialog.openConfirm(getShell(), UIText.ConfigurationEditorComponent_RemoveSubsectionTitle, NLS.bind(UIText.ConfigurationEditorComponent_RemoveSubsectionMessage, section.parent.name + DOT + section.name))) {
editableConfig.unsetSection(section.parent.name, section.name);
markDirty();
}
} else if (first instanceof Entry) {
((Entry) first).removeValue();
markDirty();
}
super.widgetSelected(e);
}
});
tv.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateEnablement();
}
});
initControlsFromConfig();
contents = main;
return contents;
}
Aggregations