use of org.eclipse.jface.viewers.ICellModifier in project cubrid-manager by CUBRID.
the class ShardKeysPanel method linkEditorForKeyInfoTable.
/**
* Links the editable column of table
*/
private void linkEditorForKeyInfoTable() {
keyInfoTableViewer.setColumnProperties(keyInfoColumnNameArrs);
CellEditor[] editors = new CellEditor[3];
editors[0] = new TextCellEditor(keyInfoTable);
editors[1] = new TextCellEditor(keyInfoTable);
String[] shardIds = new String[shardIdList.size()];
shardIds = shardIdList.toArray(shardIds);
shardIdCellEditor = new ComboBoxCellEditor(keyInfoTable, shardIds, SWT.READ_ONLY) {
{
if (!shardIdList.isEmpty()) {
this.doSetValue(shardIdList.get(0));
}
}
protected void doSetValue(Object value) {
for (int i = 0; i < shardIdList.size(); i++) {
if (shardIdList.get(i).equals((String) value)) {
super.doSetValue(i);
}
}
}
protected Object doGetValue() {
int selection = ((Integer) super.doGetValue()).intValue();
if (selection == -1) {
return "";
}
return shardIdList.get(selection);
}
};
editors[2] = shardIdCellEditor;
keyInfoTableViewer.setCellEditors(editors);
keyInfoTableViewer.setCellModifier(new ICellModifier() {
public boolean canModify(Object element, String property) {
return true;
}
@SuppressWarnings("unchecked")
public Object getValue(Object element, String property) {
Map<String, String> map = (Map<String, String>) element;
if (property.equals(keyInfoColumnNameArrs[0])) {
return map.get("0");
} else if (property.equals(keyInfoColumnNameArrs[1])) {
return map.get("1");
} else if (property.equals(keyInfoColumnNameArrs[2])) {
return map.get("2");
}
return null;
}
public void modify(Object element, String property, Object value) {
Object obj = null;
if (element instanceof Item) {
obj = ((Item) element).getData();
}
if (obj == null) {
return;
}
@SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>) obj;
boolean isValid = true;
if (!StringUtil.isEmpty(value.toString())) {
if (isValid && !ValidateUtil.isInteger(value.toString())) {
isValid = false;
CommonUITool.openErrorBox(Messages.errShardKeyParameterNotNumeric);
}
if (isValid) {
if (property.equals(keyInfoColumnNameArrs[0])) {
map.put("0", value.toString());
} else if (property.equals(keyInfoColumnNameArrs[1])) {
map.put("1", value.toString());
} else if (property.equals(keyInfoColumnNameArrs[2])) {
map.put("2", value.toString());
}
}
}
keyInfoTableViewer.refresh();
saveShardKey();
// Notice the upper layer
modifyListener.modifyText(null);
}
});
}
use of org.eclipse.jface.viewers.ICellModifier in project cubrid-manager by CUBRID.
the class RenameDatabaseDialog method createNewDatabaseInfoComp.
/**
*
* Create database name group
*
* @param parent the parent composite
*/
private void createNewDatabaseInfoComp(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
GridData gridData = new GridData(GridData.FILL_BOTH);
comp.setLayoutData(gridData);
GridLayout layout = new GridLayout();
layout.numColumns = 3;
comp.setLayout(layout);
Label databaseNameLabel = new Label(comp, SWT.LEFT | SWT.WRAP);
databaseNameLabel.setText(Messages.lblNewDbName);
gridData = new GridData();
gridData.widthHint = 150;
databaseNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
databaseNameText = new Text(comp, SWT.BORDER);
databaseNameText.setTextLimit(ValidateUtil.MAX_DB_NAME_LENGTH);
databaseNameText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 2, 1, -1, -1));
exVolumePathButton = new Button(comp, SWT.LEFT | SWT.RADIO);
exVolumePathButton.setText(Messages.btnExtendedVolumePath);
exVolumePathButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
exVolumePathButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (exVolumePathButton.getSelection()) {
exVolumePathText.setEditable(true);
renameVolumeButton.setSelection(false);
volumeTable.setEnabled(false);
if (selectVolumeDirectoryButton != null) {
ServerInfo serverInfo = database.getServer().getServerInfo();
selectVolumeDirectoryButton.setEnabled(serverInfo != null && serverInfo.isLocalServer());
}
} else {
exVolumePathText.setEditable(false);
volumeTable.setEnabled(true);
if (selectVolumeDirectoryButton != null) {
selectVolumeDirectoryButton.setEnabled(false);
}
}
}
});
exVolumePathButton.setSelection(true);
boolean isLocalServer = database.getServer().getServerInfo().isLocalServer();
exVolumePathText = new Text(comp, SWT.BORDER);
exVolumePathText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, isLocalServer ? 1 : 2, 1, -1, -1));
if (isLocalServer) {
selectVolumeDirectoryButton = new Button(comp, SWT.NONE);
selectVolumeDirectoryButton.setText(Messages.btnBrowse);
selectVolumeDirectoryButton.setLayoutData(CommonUITool.createGridData(1, 1, 80, -1));
selectVolumeDirectoryButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
String text = exVolumePathText.getText();
if (text == null || text.trim().length() == 0) {
text = CubridManagerUIPlugin.getPluginDialogSettings().get(KEY_EXTENDED_VOLUME_PATH + database.getId());
}
if (text == null || text.trim().length() == 0) {
text = extVolumePath;
}
DirectoryDialog dlg = new DirectoryDialog(getShell());
if (text != null) {
dlg.setFilterPath(text);
}
dlg.setText(Messages.msgSelectDir);
dlg.setMessage(Messages.msgSelectDir);
String dir = dlg.open();
if (dir != null) {
exVolumePathText.setText(dir);
CubridManagerUIPlugin.getPluginDialogSettings().put(KEY_EXTENDED_VOLUME_PATH + database.getId(), dir);
}
}
});
selectVolumeDirectoryButton.setEnabled(true);
}
renameVolumeButton = new Button(comp, SWT.LEFT | SWT.RADIO);
renameVolumeButton.setText(Messages.btnRenameIndiVolume);
renameVolumeButton.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 3, 1, -1, -1));
renameVolumeButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (renameVolumeButton.getSelection()) {
volumeTable.setEnabled(true);
} else {
volumeTable.setEnabled(false);
}
}
});
final String[] columnNameArr = new String[] { Messages.tblColumnCurrVolName, Messages.tblColumnNewVolName, Messages.tblColumnCurrDirPath, Messages.tblColumnNewDirPath };
volumeTableViewer = CommonUITool.createCommonTableViewer(comp, new TableViewerSorter(), columnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
volumeTable = volumeTableViewer.getTable();
volumeTable.setEnabled(false);
volumeTableViewer.setColumnProperties(columnNameArr);
CellEditor[] editors = new CellEditor[4];
editors[0] = null;
editors[1] = new TextCellEditor(volumeTable);
editors[2] = null;
editors[3] = new TextCellEditor(volumeTable);
volumeTableViewer.setCellEditors(editors);
volumeTableViewer.setCellModifier(new ICellModifier() {
@SuppressWarnings("unchecked")
public boolean canModify(Object element, String property) {
Map<String, String> map = (Map<String, String>) element;
String name = map.get("0");
if (property.equals(columnNameArr[0]) || property.equals(columnNameArr[2])) {
return false;
} else if (property.equals(columnNameArr[1]) && name.equals(database.getName())) {
return false;
}
return true;
}
@SuppressWarnings("unchecked")
public Object getValue(Object element, String property) {
Map<String, String> map = (Map<String, String>) element;
if (property.equals(columnNameArr[1])) {
return map.get("1");
} else if (property.equals(columnNameArr[3])) {
return map.get("3");
}
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;
if (property.equals(columnNameArr[1])) {
map.put("1", value.toString());
} else if (property.equals(columnNameArr[3])) {
map.put("3", value.toString());
}
volumeTableViewer.refresh();
}
});
forceDelBackupVolumeButton = new Button(comp, SWT.LEFT | SWT.CHECK);
forceDelBackupVolumeButton.setText(Messages.btnForceDelBackupVolume);
forceDelBackupVolumeButton.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 3, 1, -1, -1));
}
use of org.eclipse.jface.viewers.ICellModifier 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.ICellModifier 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.ICellModifier 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;
}
Aggregations