use of org.eclipse.swt.widgets.Item in project cubrid-manager by CUBRID.
the class EditUserDialog method createAuthComposite.
/**
* Create auth composite
*
* @return the composite
*/
private Composite createAuthComposite() {
final Composite composite = new Composite(tabFolder, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout();
composite.setLayout(layout);
Label classTableDescLabel = new Label(composite, SWT.NONE);
classTableDescLabel.setText(Messages.lblUnAuthorizedTable);
final String[] columnNameArr = new String[] { Messages.tblColClassName, Messages.tblColClassSchematype, Messages.tblColClassOwner, Messages.tblColClassType };
classTableViewer = CommonUITool.createCommonTableViewer(composite, new TableViewerSorter(), columnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
classTableViewer.setInput(classListData);
classTable = classTableViewer.getTable();
classTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
setAuthBtnEnableDisable();
}
});
final Composite cmpControl = new Composite(composite, SWT.NONE);
final GridData gdCmpControl = new GridData(SWT.CENTER, SWT.FILL, false, false);
cmpControl.setLayoutData(gdCmpControl);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
cmpControl.setLayout(gridLayout);
grantButton = new Button(cmpControl, SWT.LEFT);
grantButton.setEnabled(false);
grantButton.setText(Messages.addClassButtonName);
grantButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
int[] idx = classTable.getSelectionIndices();
if (idx.length < 0) {
return;
}
for (int i : idx) {
String className = classTable.getItem(i).getText(0);
for (Map<String, String> map : classListData) {
if (map.get("0").equals(className)) {
classListData.remove(map);
break;
}
}
ClassAuthorizations classAuthorizations = classGrantMap.get(className);
if (classAuthorizations == null) {
classAuthorizations = new ClassAuthorizations();
classAuthorizations.setClassName(className);
classAuthorizations.setSelectPriv(true);
}
authListData.add(getItemAuthMap(classAuthorizations));
}
classTableViewer.refresh();
authTableViewer.refresh();
if (authTableViewer.getTable().getColumn(0) != null) {
authTableViewer.getTable().getColumn(0).pack();
}
setAuthBtnEnableDisable();
}
});
revokeButton = new Button(cmpControl, SWT.NONE);
revokeButton.setEnabled(false);
revokeButton.setText(Messages.deleteClassButtonName);
revokeButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
int[] idx = authTable.getSelectionIndices();
if (idx.length < 0) {
return;
}
for (int id : idx) {
String tableName = authTable.getItem(id).getText(0);
for (ClassInfo bean : allClassInfoList) {
if (tableName.equals(bean.getClassName())) {
if (bean.isSystemClass()) {
CommonUITool.openErrorBox(parentComp.getShell(), Messages.errRemoveSysClass);
return;
} else {
Map<String, String> map = new HashMap<String, String>();
map.put("0", bean.getClassName());
map.put("1", bean.isSystemClass() ? Messages.msgSystemSchema : Messages.msgUserSchema);
map.put("2", bean.getOwnerName());
map.put("3", bean.getClassType() == ClassType.VIEW ? Messages.msgVirtualClass : Messages.msgClass);
classListData.add(map);
}
}
}
for (Map<String, Object> map : authListData) {
String className = (String) map.get("0");
if (tableName.equals(className)) {
authListData.remove(map);
break;
}
}
}
authTableViewer.refresh();
classTableViewer.refresh();
setAuthBtnEnableDisable();
}
});
Label authTableDescLabel = new Label(composite, SWT.NONE);
authTableDescLabel.setText(Messages.lblAuthorizedTable);
final String[] authColumnNameArr = new String[] { Messages.tblColAuthTable, Messages.tblColAuthSelect, Messages.tblColAuthInsert, Messages.tblColAuthUpdate, Messages.tblColAuthDelete, Messages.tblColAuthAlter, Messages.tblColAuthIndex, Messages.tblColAuthExecute, Messages.tblColAuthGrantselect, Messages.tblColAuthGrantinsert, Messages.tblColAuthGrantupdate, Messages.tblColAuthGrantdelete, Messages.tblColAuthGrantalter, Messages.tblColAuthGrantindex, Messages.tblColAuthGrantexecute };
authTableViewer = createCommonTableViewer(composite, authColumnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
authTableViewer.setLabelProvider(new AuthTableLabelProvider());
authTableViewer.setInput(authListData);
authTable = authTableViewer.getTable();
CellEditor[] editors = new CellEditor[15];
editors[0] = null;
for (int i = 1; i < 15; i++) {
editors[i] = new CheckboxCellEditor(authTable, SWT.READ_ONLY);
}
authTableViewer.setColumnProperties(authColumnNameArr);
authTableViewer.setCellEditors(editors);
authTableViewer.setCellModifier(new ICellModifier() {
@SuppressWarnings("unchecked")
public boolean canModify(Object element, String property) {
Map<String, Object> map = (Map<String, Object>) element;
boolean isDbaAuthority = database.getDatabaseInfo().getAuthLoginedDbUserInfo().isDbaAuthority();
if (isDbaAuthority) {
return true;
}
/*Can't grant/revoke for current login user*/
if (StringUtil.isEqual(userName, currentUserInfo.getName())) {
return false;
}
String name = (String) map.get("0");
for (ClassInfo bean : allClassInfoList) {
if (name.equals(bean.getClassName())) {
if (bean.isSystemClass()) {
return false;
} else if (currentUserInfo.getName().equalsIgnoreCase(bean.getOwnerName())) {
return true;
}
}
}
ClassAuthorizations authorizations = currentUserAuthorizations.get(name);
if (authorizations == null || authorizations.isAllPriv() || authorizations.isPriv(property)) {
return true;
} else {
return false;
}
}
@SuppressWarnings("unchecked")
public Object getValue(Object element, String property) {
Map<String, Object> map = (Map<String, Object>) element;
for (int i = 1; i < 15; i++) {
if (property.equals(authColumnNameArr[i])) {
return Boolean.valueOf((Boolean) map.get("" + i));
}
}
return null;
}
@SuppressWarnings("unchecked")
public void modify(Object element, String property, Object value) {
Object elementData;
elementData = element;
if (element instanceof Item) {
elementData = ((Item) element).getData();
}
String key = "";
Map<String, Object> map = (Map<String, Object>) elementData;
for (int i = 1; i < 15; i++) {
if (property.equals(authColumnNameArr[i])) {
key = "" + i;
break;
}
}
if (value instanceof Boolean) {
map.put(key, ((Boolean) value).booleanValue());
}
authTableViewer.refresh();
}
});
authTable.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent event) {
}
public void widgetSelected(SelectionEvent event) {
setAuthBtnEnableDisable();
}
});
authTable.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent event) {
setAuthBtnEnableDisable();
}
});
return composite;
}
use of org.eclipse.swt.widgets.Item in project cubrid-manager by CUBRID.
the class BrokerParameterPropertyPage 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) {
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 paramName = map.get("0");
String type = map.get("1");
boolean isValid = true;
if (type.indexOf("int") >= 0) {
boolean isInt = ValidateUtil.isInteger(value.toString());
if (!isInt) {
isValid = false;
}
} else if (type.startsWith("string")) {
String valueStr = value.toString().trim();
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;
}
}
if (!isExist) {
isValid = false;
}
}
}
if (!isValid) {
CommonUITool.openErrorBox(Messages.bind(Messages.errParameterValue, new Object[] { paramName }));
}
if (type.indexOf("int") >= 0 && isValid) {
int intValue = Integer.parseInt(value.toString());
if (paramName.equalsIgnoreCase(ConfConstants.MAX_STRING_LENGTH)) {
if (intValue == 0 || intValue < -1) {
isValid = false;
CommonUITool.openErrorBox(Messages.bind(Messages.errMaxStringLengthValue, new Object[] { paramName }));
}
} else {
if (intValue <= 0) {
isValid = false;
CommonUITool.openErrorBox(Messages.bind(Messages.errPositiveValue, new Object[] { paramName }));
}
List<Map<String, String>> parameterList = (List<Map<String, String>>) paraTableViewer.getInput();
if (paramName.equalsIgnoreCase(ConfConstants.MIN_NUM_APPL_SERVER)) {
Map<String, String> dataMap = parameterList.get(3);
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 (paramName.equalsIgnoreCase(ConfConstants.MAX_NUM_APPL_SERVER)) {
Map<String, String> dataMap = parameterList.get(2);
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 (paramName.equalsIgnoreCase(ConfConstants.BROKER_PORT) && isValid) {
int port = Integer.parseInt(value.toString());
if (port < 1024 || port > 65535) {
isValid = false;
CommonUITool.openErrorBox(Messages.bind(Messages.errBrokerPortAndShmId, paramName));
}
if (isValid) {
String paramValue = value.toString().trim();
for (Map.Entry<String, Map<String, String>> entry : oldConfParaMap.entrySet()) {
if (entry.getKey().equals(node.getLabel())) {
isValid = true;
continue;
} else {
String otherPort = entry.getValue().get(ConfConstants.BROKER_PORT);
if (paramValue.equalsIgnoreCase(otherPort)) {
isValid = false;
CommonUITool.openErrorBox(Messages.errReduplicatePort);
break;
} else {
isValid = true;
}
}
}
Map<String, String> brokerSectionMap = oldConfParaMap.get(ConfConstants.BROKER_SECTION_NAME);
String masterShmId = brokerSectionMap.get(ConfConstants.MASTER_SHM_ID);
if (paramValue.equals(masterShmId)) {
isValid = false;
CommonUITool.openErrorBox(Messages.bind(Messages.errUseMasterShmId, paramValue));
}
}
if (isValid) {
String paramValue = value.toString().trim();
int intServerPortValue = Integer.parseInt(paramValue) + 1;
List<Map<String, String>> parameterList = (List<Map<String, String>>) paraTableViewer.getInput();
for (Map<String, String> dataMap : parameterList) {
if (dataMap.get("0").equalsIgnoreCase(ConfConstants.APPL_SERVER_PORT)) {
String serverPortValue = Integer.toString(intServerPortValue);
dataMap.put("2", serverPortValue);
}
}
}
}
if (paramName.equalsIgnoreCase(ConfConstants.APPL_SERVER_SHM_ID) && isValid) {
int port = Integer.parseInt(value.toString());
if (port < 1024 || port > 65535) {
isValid = false;
CommonUITool.openErrorBox(Messages.bind(Messages.errBrokerPortAndShmId, paramName));
}
if (isValid) {
String paramValue = value.toString().trim();
for (Map.Entry<String, Map<String, String>> entry : oldConfParaMap.entrySet()) {
if (entry.getKey().equals(node.getLabel())) {
isValid = true;
continue;
} else {
String otherPort = entry.getValue().get(ConfConstants.APPL_SERVER_SHM_ID);
if (paramValue.equalsIgnoreCase(otherPort)) {
isValid = false;
CommonUITool.openErrorBox(Messages.errReduplicateShmId);
break;
} else {
isValid = true;
}
}
}
Map<String, String> brokerSectionMap = oldConfParaMap.get(ConfConstants.BROKER_SECTION_NAME);
String masterShmId = brokerSectionMap.get(ConfConstants.MASTER_SHM_ID);
if (paramValue.equals(masterShmId)) {
isValid = false;
CommonUITool.openErrorBox(Messages.bind(Messages.errUseMasterShmId, paramValue));
}
}
}
if (isValid) {
map.put("2", value.toString());
}
paraTableViewer.refresh();
}
});
}
use of org.eclipse.swt.widgets.Item in project cubrid-manager by CUBRID.
the class DatabaseConfigPropertyPage method linkEditorForTable.
/**
* Link editor for table
*/
private void linkEditorForTable() {
advancedOptionTableViewer.setColumnProperties(columnNameArrs);
CellEditor[] editors = new CellEditor[4];
editors[0] = null;
editors[1] = null;
editors[2] = null;
editors[3] = new TextCellEditor(advancedOptionTable);
advancedOptionTableViewer.setCellEditors(editors);
advancedOptionTableViewer.setCellModifier(new ICellModifier() {
@SuppressWarnings("unchecked")
public boolean canModify(Object element, String property) {
Object obj = null;
if (element instanceof Item) {
obj = ((Item) element).getData();
} else if (element instanceof Map) {
obj = element;
}
if (obj == null) {
return false;
}
Map<String, String> map = (Map<String, String>) obj;
String parameter = map.get("0");
if (parameter.equals(ConfConstants.HA_MODE) && !isCanSetOnForHaMode) {
return false;
}
if (property.equals(columnNameArrs[3])) {
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[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;
modifyTable(map, property, value);
}
});
}
use of org.eclipse.swt.widgets.Item in project cubrid-manager by CUBRID.
the class QueryExecuter method changeInsertedItemStyle.
/**
* change new-inserted item's style
* @param item a new-inserted item
*/
private void changeInsertedItemStyle(TableItem item) {
if (item == null)
return;
item.setImage(0, CommonUIPlugin.getImage("icons/action/table_record_adding.png"));
// Get Max index
int maxIndex = -1;
Item[] allItems = tblResult.getItems();
for (Item it : allItems) {
if (it.getText() != null) {
int index = StringUtil.intValue(it.getText(), -1);
if (index > maxIndex) {
maxIndex = index;
}
}
}
maxIndex++;
item.setText(0, String.valueOf(maxIndex));
item.setBackground(0, Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
//item.setBackground(1, Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
//item.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
tblResult.showItem(item);
}
use of org.eclipse.swt.widgets.Item in project cubrid-manager by CUBRID.
the class ShardConnectionPanel method linkEditorForTable.
/**
* Links the editable column of table
*/
private void linkEditorForTable() {
connectionTableViewer.setColumnProperties(columnNameArrs);
CellEditor[] editors = new CellEditor[3];
editors[0] = new TextCellEditor(connectionTable);
editors[1] = new TextCellEditor(connectionTable);
editors[2] = new TextCellEditor(connectionTable);
connectionTableViewer.setCellEditors(editors);
connectionTableViewer.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(columnNameArrs[0])) {
return map.get("0");
} else if (property.equals(columnNameArrs[1])) {
return map.get("1");
} else if (property.equals(columnNameArrs[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 (property.equals(columnNameArrs[0])) {
isValid = ValidateUtil.isInteger(value.toString());
if (isValid) {
for (Map<String, String> paras : parameterList) {
if (paras == obj) {
continue;
}
if (paras.get("0").equals(value)) {
isValid = false;
CommonUITool.openErrorBox(Messages.bind(Messages.errShardIdExist, new Object[] { value.toString() }));
break;
}
}
} else {
CommonUITool.openErrorBox(Messages.errShardIdNotNumeric);
}
if (isValid) {
map.put("0", value.toString());
}
} else if (property.equals(columnNameArrs[1])) {
map.put("1", value.toString());
} else if (property.equals(columnNameArrs[2])) {
map.put("2", value.toString());
}
connectionTableViewer.refresh();
// Notice the upper layer
modifyListener.modifyText(null);
}
});
}
Aggregations