use of org.eclipse.swt.widgets.Item in project cubrid-manager by CUBRID.
the class CopyDatabaseDialog method createCopyTable.
/**
* Create Copy Button and CopyList
*
* @param composite the parent composite
*/
private void createCopyTable(Composite composite) {
copyVolButton = new Button(composite, SWT.CHECK);
copyVolButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
copyVolButton.setEnabled(false);
copyVolButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent event) {
if (copyVolButton.getSelection()) {
copyDBVolList.setEnabled(true);
destinationDBDirPathText.setEnabled(false);
volumePathText.setEnabled(false);
if (isLocalServer) {
dbDirPathButton.setEnabled(false);
dbExtPathButton.setEnabled(false);
}
} else {
copyDBVolList.setEnabled(false);
copyDBVolList.setSelection(-1);
destinationDBDirPathText.setEnabled(true);
volumePathText.setEnabled(true);
if (isLocalServer) {
dbDirPathButton.setEnabled(true);
dbExtPathButton.setEnabled(true);
}
}
if (validateText()) {
setErrorMessage(null);
getButton(IDialogConstants.OK_ID).setEnabled(true);
} else {
getButton(IDialogConstants.OK_ID).setEnabled(false);
}
}
});
copyVolButton.setText(Messages.btnCopyVolume);
final String[] columnNameArr = new String[] { Messages.tblColumnCurrentVolName, Messages.tblColumnCopyNewVolName, Messages.tblColumnCopyNewDirPath };
volumeTableViewer = CommonUITool.createCommonTableViewer(composite, null, columnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
copyDBVolList = volumeTableViewer.getTable();
copyDBVolList.setEnabled(false);
volumeTableViewer.setColumnProperties(columnNameArr);
CommonUITool.hackForYosemite(volumeTableViewer.getTable());
CellEditor[] editors = new CellEditor[3];
editors[0] = null;
editors[1] = new TextCellEditor(copyDBVolList);
editors[2] = new TextCellEditor(copyDBVolList);
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 (name.equals(database.getName()) && (property.equals(columnNameArr[0]) || property.equals(columnNameArr[1]))) {
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[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;
if (property.equals(columnNameArr[1])) {
if (ValidateUtil.isValidDBName(value.toString())) {
map.put("1", value.toString());
} else {
CommonUITool.openErrorBox(getShell(), Messages.errCopyDbName);
}
} else if (property.equals(columnNameArr[2])) {
if (ValidateUtil.isValidPathName(value.toString())) {
map.put("2", value.toString());
} else {
CommonUITool.openErrorBox(getShell(), Messages.errCopyName);
}
}
isIndividChanged = true;
volumeTableViewer.refresh();
}
});
overwriteButton = new Button(composite, SWT.CHECK);
overwriteButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
overwriteButton.setText(Messages.btnReplaceDb);
moveButton = new Button(composite, SWT.CHECK);
moveButton.setText(Messages.btnDeleteSrcDb);
}
use of org.eclipse.swt.widgets.Item 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.swt.widgets.Item in project cubrid-manager by CUBRID.
the class ShardConnectionPanel method addNewItem.
/**
* add a new item into table result
*
* @return a new added TableItem
*/
private void addNewItem() {
/* Get Max index */
int maxIndex = -1;
Item[] allItems = connectionTable.getItems();
for (Item it : allItems) {
if (it.getText() != null) {
int index = StringUtil.intValue(it.getText(), -1);
if (index > maxIndex) {
maxIndex = index;
}
}
}
maxIndex++;
Map<String, String> dataMap = new HashMap<String, String>();
dataMap.put("0", String.valueOf(maxIndex));
dataMap.put("1", "");
dataMap.put("2", "");
parameterList.add(dataMap);
connectionTableViewer.refresh();
setTableColor();
}
use of org.eclipse.swt.widgets.Item 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.swt.widgets.Item 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);
}
});
}
Aggregations