use of org.eclipse.jface.viewers.CellEditor in project cubrid-manager by CUBRID.
the class SetReplicationParamComp method linkEditorForTable.
/**
* check & update table content of being edited
*
*/
private void linkEditorForTable() {
replicationParamTableViewer.setColumnProperties(columnNameArrs);
CellEditor[] editors = new CellEditor[3];
editors[0] = null;
editors[1] = null;
editors[2] = new TextCellEditor(replicationParamTable);
replicationParamTableViewer.setCellEditors(editors);
replicationParamTableViewer.setCellModifier(new ICellModifier() {
public boolean canModify(Object element, String property) {
if (property.equals(columnNameArrs[2])) {
return true;
}
return false;
}
@SuppressWarnings("unchecked")
public Object getValue(Object element, String property) {
Map<String, String> map = (Map<String, String>) element;
if (property.equals(columnNameArrs[2])) {
return map.get("2");
}
return null;
}
@SuppressWarnings("unchecked")
public void modify(Object element, String property, Object value) {
Object obj = null;
if (element instanceof Item) {
obj = ((Item) element).getData();
}
if (obj == null) {
return;
}
Map<String, String> map = (Map<String, String>) obj;
String parameter = map.get("0");
String type = map.get("1");
String paraValue = map.get("2");
boolean isValid = true;
String errorMsg = null;
if (type.startsWith("bool")) {
if (!value.toString().equalsIgnoreCase("Y") && !value.toString().equalsIgnoreCase("N")) {
isValid = false;
errorMsg = Messages.bind(Messages.repparm0errYesNoParameter, new String[] { parameter });
}
} else if (type.startsWith("int")) {
String paraVal = value.toString();
if (paraVal.length() > 8 || !paraVal.matches("\\d+")) {
isValid = false;
}
if (isValid) {
int intValue = Integer.parseInt(paraVal);
if (parameter.equals(ReplicationParamConstants.PERF_POLL_INTERVAL)) {
if (intValue < 10 || intValue > 60) {
isValid = false;
errorMsg = Messages.bind(Messages.repparm0errPerfPollInterval, new String[] { parameter });
}
} else if (parameter.equals(ReplicationParamConstants.SIZE_OF_LOG_BUFFER)) {
if (intValue < 100 || intValue > 1000) {
isValid = false;
errorMsg = Messages.bind(Messages.repparm0errSizeOfLogBuffer, new String[] { parameter });
}
} else if (parameter.equals(ReplicationParamConstants.SIZE_OF_CACHE_BUFFER)) {
if (intValue < 100 || intValue > 500) {
isValid = false;
errorMsg = Messages.bind(Messages.repparm0errSizeOfCacheBuffer, new String[] { parameter });
}
} else if (parameter.equals(ReplicationParamConstants.SIZE_OF_COPYLOG)) {
if (intValue < 1000 || intValue > 10000) {
isValid = false;
errorMsg = Messages.bind(Messages.repparm0errSizeOfCopylog, new String[] { parameter });
}
} else if (parameter.equals(ReplicationParamConstants.LOG_APPLY_INTERVAL)) {
if (intValue < 0 || intValue > 600) {
isValid = false;
errorMsg = Messages.bind(Messages.repparm0errLogApplyInterval, new String[] { parameter });
}
} else if (parameter.equals(ReplicationParamConstants.RESTART_INTERVAL) && (intValue < 1 || intValue > 60)) {
isValid = false;
errorMsg = Messages.bind(Messages.repparm0errRestartInterval, new String[] { parameter });
}
} else {
errorMsg = Messages.bind(Messages.repparm0errOnlyInteger, new String[] { parameter });
isValid = false;
}
}
if (!isValid && errorMsg != null) {
setErrorMsg(errorMsg);
updatableComp.updateUI();
}
setErrorMsg(null);
if (isValid && property.equals(columnNameArrs[2]) && !paraValue.equals(value)) {
map.put("2", value.toString());
updatableComp.updateUI();
}
replicationParamTableViewer.refresh();
for (int i = 0; i < replicationParamTable.getColumnCount(); i++) {
replicationParamTable.getColumn(i).pack();
}
}
});
}
use of org.eclipse.jface.viewers.CellEditor 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.eclipse.jface.viewers.CellEditor in project tdi-studio-se by Talend.
the class HL7OutputUI method addXMLViewer.
/**
* create xml viewer.
*
* @param mainComposite
* @param form
* @param width
* @param height
*/
private void addXMLViewer(final Composite mainComposite, final int width, final int height) {
// Group Schema Viewer
Group group = Form.createGroup(mainComposite, 1, "Linker Target", height);
// group.setBackgroundMode(SWT.INHERIT_FORCE);
xmlViewer = new TreeViewer(group, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
GridData gridData = new GridData(GridData.FILL_BOTH);
xmlViewer.getControl().setLayoutData(gridData);
xmlViewer.setUseHashlookup(true);
Tree tree = xmlViewer.getTree();
if (canModify || isRespo) {
tree.setEnabled(false);
}
tree.setLinesVisible(true);
tree.setBackground(tree.getDisplay().getSystemColor(SWT.COLOR_WHITE));
TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
column1.setText("HL7 Structure");
column1.setWidth(170);
// Related Column
TreeColumn column2 = new TreeColumn(tree, SWT.CENTER);
column2.setText("Related Column");
column2.setWidth(100);
TreeColumn column3 = new TreeColumn(tree, SWT.CENTER);
column3.setText("Node Status");
column3.setWidth(90);
TreeColumn column4 = new TreeColumn(tree, SWT.CENTER);
column4.setText("Default Value");
column4.setWidth(90);
tree.setHeaderVisible(true);
// tree.setBackgroundMode(SWT.INHERIT_NONE);
HL7TargetTreeViewerProvider provider = new HL7TargetTreeViewerProvider();
xmlViewer.setLabelProvider(provider);
xmlViewer.setCellModifier(new ICellModifier() {
@Override
public boolean canModify(Object element, String property) {
HL7TreeNode node = (HL7TreeNode) element;
if (property.equals("C1")) {
if (node.getLabel() != null && node.getLabel().length() > 0) {
return true;
}
}
if (property.equals("C4")) {
if (node.getDefaultValue() != null && node.getDefaultValue().length() > 0) {
return true;
}
}
return false;
}
@Override
public Object getValue(Object element, String property) {
HL7TreeNode node = (HL7TreeNode) element;
if (property.equals("C1")) {
return node.getLabel();
}
if (property.equals("C4")) {
return node.getDefaultValue();
}
return null;
}
@Override
public void modify(Object element, String property, Object value) {
TreeItem treeItem = (TreeItem) element;
HL7TreeNode node = (HL7TreeNode) treeItem.getData();
if (property.equals("C1")) {
if (value != null && value.toString().length() == 0) {
value = node.getLabel();
}
node.setLabel((String) value);
}
if (property.equals("C4")) {
node.setDefaultValue((String) value);
}
xmlViewer.refresh(node);
}
});
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
xmlViewer.setColumnProperties(new String[] { "C1", "C2", "C3", "C4" });
CellEditor editor = new TextCellEditor(xmlViewer.getTree());
editor.addListener(new DialogErrorXMLLabelCellEditor(editor, "C1"));
// add by wzhang for bug 8572. set Default value column to be edit.
CellEditor editorDefault = new TextCellEditor(xmlViewer.getTree());
editorDefault.addListener(new DialogErrorXMLLabelCellEditor(editorDefault, "C4"));
xmlViewer.setCellEditors(new CellEditor[] { editor, null, null, editorDefault });
xmlViewer.setContentProvider(provider);
xmlViewer.setInput(this.hl7Manager.getTreeData());
xmlViewer.expandAll();
createAction();
MenuManager menuMgr = new MenuManager("#PopupMenu");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
HL7OutputUI.this.fillContextMenu(manager);
}
});
Menu menu = menuMgr.createContextMenu(xmlViewer.getControl());
xmlViewer.getControl().setMenu(menu);
xmlViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
// TODO Auto-generated method stub
}
});
refreshXMLViewer(null);
}
use of org.eclipse.jface.viewers.CellEditor in project tdi-studio-se by Talend.
the class AddListDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
// Composite baseCom = (Composite) super.createDialogArea(parent);
Composite createDialogArea = (Composite) super.createDialogArea(parent);
createDialogArea.setLayout(new FillLayout());
SashForm baseCom = new SashForm(createDialogArea, SWT.VERTICAL | SWT.BORDER);
treeViewer = new TreeViewer(baseCom, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
tree = treeViewer.getTree();
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
tree.setLayoutData(new GridData(GridData.FILL_BOTH));
// Paramater Name Column
TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
column1.setText("Parameter Name");
column1.setWidth(200);
// Array Index Column
TreeColumn column2 = new TreeColumn(tree, SWT.CENTER);
column2.setText("Array Index");
column2.setWidth(100);
treeViewer.setColumnProperties(new String[] { NAME, INDEX });
CellEditor editor = new TextCellEditor(treeViewer.getTree());
// CellEditor nameEditor = new ComboBoxCellEditor(treeViewer.getTree());
treeViewer.setCellEditors(new CellEditor[] { null, editor });
treeViewer.setCellModifier(new ICellModifier() {
public boolean canModify(Object element, String property) {
if (element instanceof ParameterInfo) {
ParameterInfo para = (ParameterInfo) element;
if (INDEX.equals(property) && para.getArraySize() != 0) {
// if item is array it can edit.
return true;
}
}
return false;
}
public Object getValue(Object element, String property) {
if (element instanceof ParameterInfo) {
ParameterInfo para = (ParameterInfo) element;
if (INDEX.equals(property)) {
return para.getIndex() == null ? "" : para.getIndex();
} else if (NAME.equals(property)) {
return para.getName();
}
}
return null;
}
public void modify(Object element, String property, Object value) {
if (element instanceof TreeItem) {
ParameterInfo para = (ParameterInfo) ((TreeItem) element).getData();
if (INDEX.equals(property)) {
para.setIndex(value.toString());
}
}
treeViewer.refresh();
}
});
// DrillDownAdapter adapter = new DrillDownAdapter(treeView);
treeViewer.setContentProvider(new WebServiceTreeContentProvider());
treeViewer.setLabelProvider(new WebServiceTreeLabelProvider());
treeViewer.setInput(para);
treeViewer.addSelectionChangedListener(selectAction);
// tree.addSelectionListener(new SelectionAdapter() {
//
// @Override
// public void widgetSelected(SelectionEvent e) {
// TreeItem[] selects = tree.getSelection();
// ISelection select = (ISelection) treeViewer.getSelection();
// Object obj = ((IStructuredSelection) select).getFirstElement();
// if (obj instanceof ParameterInfo) {
// // if (((ParameterInfo) obj).getParameterInfos().size() > 0) {
// // // ErrorDialog dialog = new ErrorDialog(parentShell, "", "", null, 0);
// // // dialog.open();
// // selectedParaInfo = null;
// // } else {
// selectedParaInfo = (ParameterInfo) obj;
// // }
// }
// }
//
// });
treeViewer.getTree().addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
createAllTypeDialog();
}
});
return baseCom;
}
use of org.eclipse.jface.viewers.CellEditor in project tdi-studio-se by Talend.
the class XmlMapNodeDirectEditManager method createCellEditorOn.
@Override
protected CellEditor createCellEditorOn(Composite composite) {
Composite parent = (Composite) source.getViewer().getControl();
CellEditor cellEditor = null;
Figure figure = null;
if (this.locator instanceof XmlMapNodeCellEditorLocator) {
XmlMapNodeCellEditorLocator lo = (XmlMapNodeCellEditorLocator) locator;
figure = lo.getFigure();
}
if (figure instanceof IComboCell) {
try {
// tree setting can be edit or not
if (source instanceof InputXmlTreeEditPart) {
InputXmlTree inputTree = (InputXmlTree) ((InputXmlTreeEditPart) source).getModel();
if (DirectEditType.JOIN_MODEL.equals(((IComboCell) figure).getDirectEditType())) {
if (!XmlMapUtil.hasAtLeastOneHashKey(inputTree)) {
return null;
}
}
if (DirectEditType.PERSISTENT_MODEL.equals(((IComboCell) figure).getDirectEditType())) {
if (LOOKUP_MODE.CACHE_OR_RELOAD.toString().equals(inputTree.getLookupMode())) {
return null;
}
}
}
if (source instanceof OutputXmlTreeEditPart) {
OutputXmlTree outputTree = (OutputXmlTree) ((OutputXmlTreeEditPart) source).getModel();
if (DirectEditType.ALL_IN_ONE.equals(((IComboCell) figure).getDirectEditType())) {
if (!XmlMapUtil.hasDocument(outputTree)) {
return null;
}
boolean hasAggregate = false;
for (int i = 0; i < outputTree.getNodes().size(); i++) {
OutputTreeNode outputTreeNode = outputTree.getNodes().get(i);
hasAggregate = hasAggreage(outputTreeNode);
if (hasAggregate) {
break;
}
}
if (hasAggregate) {
return null;
}
} else if (DirectEditType.ENABLE_EMPTY_ELEMENT.equals(((IComboCell) figure).getDirectEditType())) {
if (!XmlMapUtil.hasDocument(outputTree)) {
return null;
}
}
}
cellEditor = new XmlComboCellEditor();
cellEditor.create(composite);
((XmlComboCellEditor) cellEditor).setItems(getComboItemsByType(((IComboCell) figure).getDirectEditType()));
cellAndType.put(cellEditor, ((IComboCell) figure).getDirectEditType());
} catch (Exception e) {
return null;
}
} else if (figure instanceof ITextCell) {
// this one is created for direct doc child name , no use anymore...
cellEditor = new TextCellEditor(composite);
cellAndType.put(cellEditor, ((ITextCell) figure).getDirectEditType());
// for the search
XmlMapNodeCellEditorLocator lo = (XmlMapNodeCellEditorLocator) locator;
if (lo.getFigure() != null && lo.getFigure() instanceof VarNodeTextLabel) {
figure = (VarNodeTextLabel) lo.getFigure();
if (figure.getParent() != null && figure.getParent() instanceof XmlMapSearchZoneToolBar) {
XmlMapSearchZoneToolBar searchZone = (XmlMapSearchZoneToolBar) figure.getParent();
if (searchZone.getSearchMaps().size() > 0) {
searchZone.getSearchZoneMapper().hightlightAll(searchZone.getSearchMaps(), false);
searchZone.getSearchZoneMapper().setHightlightAll(false);
searchZone.getSearchMaps().clear();
searchZone.hightLightAll.setSelected(false);
}
}
}
} else if (figure instanceof IExpressionBuilderCell && model instanceof AbstractNode) {
IService expressionBuilderDialogService = GlobalServiceRegister.getDefault().getService(IExpressionBuilderDialogService.class);
CellEditorDialogBehavior behavior = new CellEditorDialogBehavior();
cellEditor = new ExpressionCellEditor(composite, behavior, source, DirectEditType.EXPRESSION);
((ExpressionCellEditor) cellEditor).setOwnerId(((AbstractNode) model).getExpression());
IExpressionBuilderDialogController dialog = ((IExpressionBuilderDialogService) expressionBuilderDialogService).getExpressionBuilderInstance(parent, (ExpressionCellEditor) cellEditor, null);
cellAndType.put(cellEditor, DirectEditType.EXPRESSION);
behavior.setCellEditorDialog(dialog);
} else if (figure instanceof ITextAreaCell) {
TextAreaBehavior behavior = new TextAreaBehavior();
cellEditor = new ExpressionCellEditor(composite, behavior, source, DirectEditType.EXPRESSION_FILTER);
cellAndType.put(cellEditor, DirectEditType.EXPRESSION_FILTER);
} else if (figure instanceof IExpressionBuilderCell && model instanceof InputXmlTree) {
IService expressionBuilderDialogService = GlobalServiceRegister.getDefault().getService(IExpressionBuilderDialogService.class);
CellEditorDialogBehavior behavior = new CellEditorDialogBehavior();
cellEditor = new ExpressionCellEditor(composite, behavior, source, DirectEditType.EXPRESSION);
((ExpressionCellEditor) cellEditor).setOwnerId(((InputXmlTree) model).getLookupMode());
IExpressionBuilderDialogController dialog = ((IExpressionBuilderDialogService) expressionBuilderDialogService).getExpressionBuilderInstance(parent, (ExpressionCellEditor) cellEditor, null);
cellAndType.put(cellEditor, DirectEditType.EXPRESSION);
behavior.setCellEditorDialog(dialog);
}
// }
return cellEditor;
}
Aggregations