use of org.eclipse.jface.viewers.CellEditor in project cubrid-manager by CUBRID.
the class ShardBrokerPropertiesPanel method linkEditorForTable.
/**
* Links the editable column of table
*/
private void linkEditorForTable() {
paraTableViewer.setColumnProperties(columnNameArrs);
CellEditor[] editors = new CellEditor[3];
editors[0] = null;
editors[1] = null;
editors[2] = new TextCellEditor(paraTable);
paraTableViewer.setCellEditors(editors);
paraTableViewer.setCellModifier(new ICellModifier() {
public boolean canModify(Object element, String property) {
@SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>) element;
String para = map.get("0");
if (property.equals(columnNameArrs[2]) && (!CubridShardConfParaConstants.SHARD_CONNECTION_FILE.equals(para) && !CubridShardConfParaConstants.SHARD_KEY_FILE.equals(para) && !CubridShardConfParaConstants.APPL_SERVER_SHM_ID.equals(para))) {
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 paramName = map.get("0");
String type = map.get("1");
boolean isValid = true;
String valueStr = value.toString().trim();
if (!StringUtil.isEmpty(valueStr)) {
if (type.indexOf("int") >= 0) {
if (!ValidateUtil.isInteger(value.toString())) {
isValid = false;
} else {
int intValue = Integer.parseInt(value.toString());
int start = type.indexOf("(");
int end = type.indexOf(")");
if (start > 0) {
String valueRange = type.substring(start + 1, end);
String[] values = valueRange.split("~");
int min = Integer.parseInt(values[0]);
int max = Integer.parseInt(values[1]);
if (intValue < min || intValue > max || intValue < 1) {
isValid = false;
}
}
}
} else if (type.startsWith("string")) {
int start = type.indexOf("(");
int end = type.indexOf(")");
if (start > 0) {
String valueStrs = type.substring(start + 1, end);
String[] values = valueStrs.split("\\|");
boolean isExist = false;
for (String val : values) {
if (valueStr.equals(val)) {
isExist = true;
break;
}
}
if (!isExist) {
isValid = false;
}
}
}
if (!isValid) {
CommonUITool.openErrorBox(Messages.bind(Messages.errParameterValue, new Object[] { paramName }));
}
if (isValid && paramName.equalsIgnoreCase(CubridShardConfParaConstants.MIN_NUM_APPL_SERVER)) {
int intValue = Integer.parseInt(value.toString());
Map<String, String> dataMap = parameterList.get(9);
String maxNumApplServer = dataMap.get("2");
if (maxNumApplServer.trim().length() > 0 && intValue > Integer.parseInt(maxNumApplServer.trim())) {
isValid = false;
CommonUITool.openErrorBox(Messages.bind(Messages.errMinNumApplServerValue, new Object[] { paramName }));
}
}
if (isValid && paramName.equalsIgnoreCase(CubridShardConfParaConstants.MAX_NUM_APPL_SERVER)) {
int intValue = Integer.parseInt(value.toString());
Map<String, String> dataMap = parameterList.get(10);
String minNumApplServer = dataMap.get("2");
if (minNumApplServer.trim().length() > 0 && intValue < Integer.parseInt(minNumApplServer.trim())) {
isValid = false;
CommonUITool.openErrorBox(Messages.bind(Messages.errMaxNumApplServeValue, new Object[] { paramName }));
}
}
if (isValid && paramName.equalsIgnoreCase(CubridShardConfParaConstants.BROKER_PORT)) {
Map<String, String> dataMap = parameterList.get(8);
String metadataShmId = dataMap.get("2");
if (valueStr.equals(metadataShmId)) {
isValid = false;
CommonUITool.openErrorBox(Messages.bind(Messages.errShmIdExist, new Object[] { paramName }));
}
dataMap = parameterList.get(7);
dataMap.put("2", value.toString());
}
if (isValid && paramName.equalsIgnoreCase(CubridShardConfParaConstants.METADATA_SHM_ID)) {
Map<String, String> dataMap = parameterList.get(7);
String metadataShmId = dataMap.get("2");
if (valueStr.equals(metadataShmId)) {
isValid = false;
CommonUITool.openErrorBox(Messages.bind(Messages.errShmIdExist, new Object[] { paramName }));
}
}
}
if (isValid) {
map.put("2", value.toString());
}
paraTableViewer.refresh();
// Notice the upper layer
modifyListener.modifyText(null);
}
});
}
use of org.eclipse.jface.viewers.CellEditor in project cubrid-manager by CUBRID.
the class ShardKeysPanel method linkEditorForKeyListTable.
/**
* Links the editable column of table
*/
private void linkEditorForKeyListTable() {
keyListTableViewer.setColumnProperties(keyListColumnNameArrs);
CellEditor[] editors = new CellEditor[3];
editors[0] = new TextCellEditor(keyListTable);
keyListTableViewer.setCellEditors(editors);
keyListTableViewer.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;
return map.get("0");
}
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())) {
for (Map<String, String> paras : keyList) {
if (paras == obj) {
continue;
}
if (paras.get("0").equals(value)) {
isValid = false;
CommonUITool.openErrorBox(Messages.bind(Messages.errShardKeyNameExist, new Object[] { value.toString() }));
break;
}
}
}
if (isValid) {
map.put("0", value.toString());
currentShardKey.setName(value.toString());
keyInfoGroup.setText("Key Info: " + value);
}
keyListTableViewer.refresh();
// Notice the upper layer
modifyListener.modifyText(null);
}
});
}
use of org.eclipse.jface.viewers.CellEditor 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.CellEditor in project cubrid-manager by CUBRID.
the class BrokerParameterDialog method linkEditorForTable.
/**
* Makes a certain column of table can be edited
*/
private void linkEditorForTable() {
paraTableViewer.setColumnProperties(columnNameArrs);
CellEditor[] editors = new CellEditor[3];
editors[0] = null;
editors[1] = null;
editors[2] = new TextCellEditor(paraTable);
paraTableViewer.setCellEditors(editors);
paraTableViewer.setCellModifier(new ParameterCellModifier());
}
use of org.eclipse.jface.viewers.CellEditor in project cubrid-manager by CUBRID.
the class UserAuthDbInfoPage method setCellEditors.
/**
*
* Set cell editors
*/
private void setCellEditors() {
authTableViewer.setCellEditors(null);
Table authTable = authTableViewer.getTable();
CellEditor[] editors = new CellEditor[5];
editors[0] = null;
editors[1] = new ComboBoxCellEditor(authTable, allowConnected, SWT.READ_ONLY);
editors[2] = new TextCellEditor(authTable);
editors[3] = new TextCellEditor(authTable);
if (allBrokerPorts != null && allBrokerPorts.length > 0) {
editors[4] = new ComboBoxCellEditor(authTable, allBrokerPorts, SWT.READ_ONLY);
} else {
editors[4] = new TextCellEditor(authTable);
}
authTableViewer.setCellEditors(editors);
}
Aggregations