use of org.eclipse.swt.events.FocusAdapter in project cubrid-manager by CUBRID.
the class PstmtSQLDialog method registerContextMenu.
private void registerContextMenu() {
parameterTable.getTable().addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent event) {
ActionManager.getInstance().changeFocusProvider(parameterTable.getTable());
}
});
MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
Menu contextMenu = menuManager.createContextMenu(parameterTable.getTable());
parameterTable.getTable().setMenu(contextMenu);
Menu menu = new Menu(getShell(), SWT.POP_UP);
final MenuItem itemShowMuchValue = new MenuItem(menu, SWT.PUSH);
itemShowMuchValue.setText(Messages.pstmtSQLMuchItem);
itemShowMuchValue.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
//seems like MenuEvent can't get the mouse click Point
//so use the point which table MouseDown event marked
Point pt = clickPoint;
int selectIndex = parameterTable.getTable().getSelectionIndex();
final TableItem item = parameterTable.getTable().getItem(selectIndex);
if (item == null) {
return;
}
for (int i = 1; i < parameterTable.getTable().getColumnCount(); i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
String type = parameterTypeTable.getItem(0).getText(i);
SetPstmtValueDialog dialog = new SetPstmtValueDialog(getShell(), item, database, i, type);
if (IDialogConstants.OK_ID == dialog.open()) {
charSet = (String) item.getData(SetPstmtValueDialog.FILE_CHARSET);
valueList.get(selectIndex).getValue().set(i, item.getText(i));
packTable();
addTableItemToLast(selectIndex, item);
}
validate();
}
}
}
});
menu.addMenuListener(new MenuAdapter() {
public void menuShown(MenuEvent event) {
//seems like MenuEvent can't get the mouse click Point
//so use the point which table MouseDown event marked
Point pt = clickPoint;
int selectIndex = parameterTable.getTable().getSelectionIndex();
if (selectIndex < 0) {
itemShowMuchValue.setEnabled(false);
return;
}
final TableItem item = parameterTable.getTable().getItem(selectIndex);
if (item == null) {
itemShowMuchValue.setEnabled(false);
return;
}
for (int i = 1; i < parameterTable.getTable().getColumnCount(); i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
String type = parameterTypeTable.getItem(0).getText(i);
//if type is nut much value type ,set the menu disable
if (DBAttrTypeFormatter.isMuchValueType(type)) {
itemShowMuchValue.setEnabled(true);
} else {
itemShowMuchValue.setEnabled(false);
}
}
}
}
});
parameterTable.getTable().setMenu(menu);
}
use of org.eclipse.swt.events.FocusAdapter in project cubrid-manager by CUBRID.
the class PstmtSQLDialog method handleType.
/**
* Handle type
*
* @param item TableItem
*/
protected void handleType(final TableItem item, final int editColumn) {
String[][] typeMapping = DataType.getTypeMapping(database.getDatabaseInfo(), true, true);
LinkedList<String> typeList = new LinkedList<String>();
for (int i = 0; i < typeMapping.length; i++) {
String type = typeMapping[i][0];
if (!type.startsWith(DataType.DATATYPE_OBJECT)) {
typeList.add(type);
}
}
// add default precision
typeList.addFirst("NUMERIC(38,12)");
sortTypeList(typeList);
addColumnToList(typeList);
String[] items = typeList.toArray(new String[] {});
final Combo typeCombo = new Combo(parameterTypeTable, SWT.BORDER | SWT.FULL_SELECTION);
typeCombo.setItems(items);
typeCombo.setVisibleItemCount(20);
final String paraName = item.getText(0);
typeCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
validateType(paraName, typeCombo.getText(), editColumn);
}
});
typeCombo.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent event) {
if (isChanging) {
return;
}
isChanging = true;
// if (validateType(paraName, typeCombo.getText(), editColumn)) {
item.setText(editColumn, typeCombo.getText());
// }
typeCombo.dispose();
isChanging = false;
validate();
}
});
//add listener for key pressed
typeCombo.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent event) {
if (event.detail == SWT.TRAVERSE_RETURN) {
if (isChanging) {
return;
}
isChanging = true;
// if (validateType(paraName, typeCombo.getText(), editColumn)) {
item.setText(editColumn, typeCombo.getText());
// }
typeCombo.dispose();
isChanging = false;
validate();
event.doit = true;
} else if (event.detail == SWT.TRAVERSE_ESCAPE) {
if (isChanging) {
return;
}
isChanging = true;
typeCombo.dispose();
event.doit = false;
isChanging = false;
}
}
});
tableEditor.setEditor(typeCombo, item, editColumn);
typeCombo.setText(item.getText(editColumn));
typeCombo.setFocus();
}
use of org.eclipse.swt.events.FocusAdapter in project cubrid-manager by CUBRID.
the class PstmtDataDialog method handleType.
protected void handleType(final TableItem item) {
String[][] typeMapping = DataType.getTypeMapping(database.getDatabaseInfo(), true, true);
List<String> typeList = new ArrayList<String>();
for (int i = 0; i < typeMapping.length; i++) {
String type = typeMapping[i][0];
if (!type.startsWith(DataType.DATATYPE_OBJECT)) {
typeList.add(type);
}
}
String[] items = typeList.toArray(new String[] {});
final int editColumn = 1;
final Combo typeCombo = new Combo(parameterTable, SWT.BORDER | SWT.FULL_SELECTION);
typeCombo.setItems(items);
typeCombo.setVisibleItemCount(20);
final String paraName = item.getText(0);
typeCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
validateType(paraName, typeCombo.getText());
}
});
typeCombo.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent event) {
if (isChanging) {
return;
}
isChanging = true;
if (validateType(paraName, typeCombo.getText())) {
item.setText(editColumn, typeCombo.getText());
}
typeCombo.dispose();
isChanging = false;
validate();
}
});
//add listener for key pressed
typeCombo.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent event) {
if (event.detail == SWT.TRAVERSE_RETURN) {
if (isChanging) {
return;
}
isChanging = true;
if (validateType(paraName, typeCombo.getText())) {
item.setText(editColumn, typeCombo.getText());
}
typeCombo.dispose();
isChanging = false;
validate();
event.doit = true;
handleValue(item);
} else if (event.detail == SWT.TRAVERSE_ESCAPE) {
if (isChanging) {
return;
}
isChanging = true;
typeCombo.dispose();
event.doit = false;
isChanging = false;
}
}
});
tableEditor.setEditor(typeCombo, item, editColumn);
typeCombo.setText(item.getText(editColumn));
typeCombo.setFocus();
}
use of org.eclipse.swt.events.FocusAdapter in project cubrid-manager by CUBRID.
the class InsertTableDataDialog method handleValue.
private void handleValue(final TableItem item) {
// Clean up any previous editor control
Control oldEditor = tableEditor.getEditor();
if (oldEditor != null) {
oldEditor.dispose();
}
final Text newEditor = new Text(attrTable, SWT.MULTI | SWT.WRAP);
newEditor.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
validate(newEditor.getText(), item);
}
});
newEditor.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent event) {
if (isChanging) {
return;
}
isChanging = true;
if (validate(newEditor.getText(), item)) {
item.setText(EDIT_COLUMN, newEditor.getText());
}
newEditor.dispose();
validate();
isChanging = false;
}
});
//add listener for key pressed
newEditor.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent event) {
if (event.detail == SWT.TRAVERSE_RETURN) {
if (isChanging) {
return;
}
isChanging = true;
if (validate(newEditor.getText(), item)) {
item.setText(EDIT_COLUMN, newEditor.getText());
}
newEditor.dispose();
validate();
isChanging = false;
event.doit = true;
int selItem = (attrTable.getSelectionIndex() + 1) % attrTable.getItemCount();
if (selItem == 0) {
getButton(BTN_INSERT_ID).setFocus();
} else {
attrTable.setSelection(selItem);
handleValue(attrTable.getItem(selItem));
}
} else if (event.detail == SWT.TRAVERSE_ESCAPE) {
if (isChanging) {
return;
}
isChanging = true;
newEditor.dispose();
event.doit = false;
isChanging = false;
}
}
});
tableEditor.setEditor(newEditor, item, EDIT_COLUMN);
newEditor.setText(item.getText(EDIT_COLUMN));
newEditor.selectAll();
newEditor.setFocus();
}
use of org.eclipse.swt.events.FocusAdapter 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;
}
Aggregations