use of org.eclipse.swt.events.MenuAdapter 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.MenuAdapter in project cubrid-manager by CUBRID.
the class QueryExecuter method createContextMenuItems.
private void createContextMenuItems() {
Menu menu = new Menu(queryEditor.getEditorSite().getShell(), SWT.POP_UP);
final MenuItem itemInsert = new MenuItem(menu, SWT.PUSH);
itemInsert.setText(Messages.insertRecord);
itemInsert.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (!getEditable()) {
CommonUITool.openErrorBox(Display.getDefault().getActiveShell(), Messages.errNotEditable);
return;
}
insertSaveItem.setEnabled(getEditable());
rollbackModifiedItem.setEnabled(getEditable());
addNewItem();
}
});
final MenuItem itemCopy = new MenuItem(menu, SWT.PUSH);
itemCopy.setText(Messages.copyClipBoard);
final MenuItem itemDelete = new MenuItem(menu, SWT.PUSH);
itemDelete.setText(Messages.delete);
new MenuItem(menu, SWT.SEPARATOR);
final MenuItem itemDetail = new MenuItem(menu, SWT.PUSH);
itemDetail.setText(Messages.detailView);
itemDetail.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
List<Point> selectedList = selectableSupport.getSelectedLocations();
Point location = selectedList.get(0);
if (location == null) {
CommonUITool.openErrorBox(Messages.errShowDetailFailed);
return;
}
//Bug fixed by Kevin.Qian. FYI. allDataList is a global query result to the current query.
int pageBeginIndex = (queryInfo.getCurrentPage() - 1) * queryInfo.getPageSize();
Map<String, CellValue> map = allDataList.get(pageBeginIndex + location.y);
TableItem item = tblResult.getItem(location.y);
ColumnInfo colInfo = allColumnList.get(location.x - 1);
RowDetailDialog dialog = new RowDetailDialog(tblResult.getShell(), allColumnList, map, item, colInfo.getName(), executer);
dialog.open();
}
});
tblResult.setMenu(menu);
tblResult.addListener(SWT.MouseUp, new Listener() {
public void handleEvent(Event event) {
// Point pt = new Point(event.x, event.y);
// itemOid.setEnabled(false);
int index = tblResult.getSelectionIndex();
int count = tblResult.getItemCount();
if (index < 0 || index >= count) {
return;
}
// final TableItem item = tblResult.getItem(index);
// for (int i = 0; i < tblResult.getColumnCount(); i++) {
// Rectangle rect = item.getBounds(i);
// if (rect.contains(pt)) {
// selColumnName = tblResult.getColumn(i).getText();
//// Object value = item.getData(i + "");
//// String text = item.getText(i);
//// if (!DataType.VALUE_NULL.equals(value) && containsOIDs(tblResult.getColumn(i).getText())
//// && !DataType.VALUE_NONE.equals(text)) {
//// itemOid.setEnabled(true);
//// } else {
//// itemOid.setEnabled(false);
//// }
//
// }
// }
}
});
final MenuItem itemExportAll = new MenuItem(menu, SWT.PUSH);
itemExportAll.setText(Messages.allExport);
final MenuItem itemExportSelection = new MenuItem(menu, SWT.PUSH);
itemExportSelection.setText(Messages.selectExport);
new MenuItem(menu, SWT.SEPARATOR);
final MenuItem itemMakeInsertQuery = new MenuItem(menu, SWT.PUSH);
itemMakeInsertQuery.setText(Messages.makeInsertFromSelectedRecord);
itemMakeInsertQuery.setImage(CommonUIPlugin.getImage("icons/queryeditor/record_to_insert.png"));
final MenuItem itemMakeUpdateQuery = new MenuItem(menu, SWT.PUSH);
itemMakeUpdateQuery.setText(Messages.makeUpdateFromSelectedRecord);
itemMakeUpdateQuery.setImage(CommonUIPlugin.getImage("icons/queryeditor/record_to_update.png"));
if (isEmpty()) {
itemExportAll.setEnabled(false);
itemExportSelection.setEnabled(false);
itemDetail.setEnabled(false);
}
menu.addMenuListener(new MenuAdapter() {
public void menuShown(MenuEvent event) {
List<Point> selectedList = selectableSupport.getSelectedLocations();
TableItem[] tblItems = selectableSupport.getSelectedTableItems();
boolean selectedCol = selectableSupport.hasSelected();
boolean enableItemDetail = (selectedList != null && selectedList.size() == 1);
itemExportSelection.setEnabled(selectedCol);
itemCopy.setEnabled(selectedCol);
if (allDataList.size() > 0) {
itemExportAll.setEnabled(true);
} else {
itemExportAll.setEnabled(false);
}
if (executer.getQueryEditor() != null && executer.getQueryEditor().getDatabaseInfo() != null && executer.getQueryEditor().getDatabaseInfo().equals(executer.getDatabaseInfo())) {
itemInsert.setEnabled(isEditMode());
itemDetail.setEnabled(enableItemDetail);
itemDelete.setEnabled(getEditable() && isEditMode());
} else {
itemInsert.setEnabled(false);
itemDetail.setEnabled(false);
itemDelete.setEnabled(false);
}
for (int i = 0; i < tblItems.length; i++) {
if (isEditMode() && getEditable() && tblItems[i].getText(1).equals(DataType.VALUE_NONE)) {
itemDelete.setEnabled(false);
}
}
}
});
itemCopy.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
copySelectedItems();
}
});
itemCopy.setAccelerator(SWT.CTRL + 'c');
itemDelete.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (isEditMode()) {
deleteRecord(tblResult, null);
}
}
});
itemExportAll.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
ExportResultDialog dialog = new ExportResultDialog(tblResult.getShell(), database, Messages.msgExportAllResults);
if (IDialogConstants.OK_ID == dialog.open()) {
ExportQueryResultTaskExecutor task = new ExportQueryResultTaskExecutor(dialog.getFile(), dialog.getFileCharset(), allColumnList, allDataList, false);
new ExecTaskWithProgress(task).exec();
}
}
});
// itemOid.addSelectionListener(new SelectionAdapter() {
// /**
// * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
// * @param event an event containing information about the
// * selection
// */
// public void widgetSelected(SelectionEvent event) {
// openOidNavigator(button2Position);
// }
//
// });
itemExportSelection.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
ExportResultDialog dialog = new ExportResultDialog(tblResult.getShell(), database, Messages.msgExportSelectedResults);
if (IDialogConstants.OK_ID == dialog.open()) {
ExportQueryResultTaskExecutor task = new ExportQueryResultTaskExecutor(dialog.getFile(), dialog.getFileCharset(), tblResult, selectableSupport.getSelectedTableItems(), false);
new ExecTaskWithProgress(task).exec();
}
}
});
itemMakeInsertQuery.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
String text = makeInsertQueryWithSelectedRecords();
CommonUITool.copyContentToClipboard(text);
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
itemMakeUpdateQuery.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
String text = makeUpdateQueryWithSelectedRecords();
CommonUITool.copyContentToClipboard(text);
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
use of org.eclipse.swt.events.MenuAdapter in project cubrid-manager by CUBRID.
the class UnifyHostConfigEditor method registerCubridCMConfTableContextMenu.
/**
* register CubridCMConfTable context menu
*/
private void registerCubridCMConfTableContextMenu() {
cubridCMConfTabTableViewer.getTable().addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent event) {
ActionManager.getInstance().changeFocusProvider(cubridCMConfTabTableViewer.getTable());
}
});
MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
Menu contextMenu = menuManager.createContextMenu(cubridCMConfTabTableViewer.getTable());
cubridCMConfTabTableViewer.getTable().setMenu(contextMenu);
Menu menu = new Menu(this.getSite().getShell(), SWT.POP_UP);
final MenuItem itemEditAnnotation = new MenuItem(menu, SWT.PUSH);
itemEditAnnotation.setText(Messages.confEditorTableMenuEditAnnotation);
itemEditAnnotation.addSelectionListener(new SelectionAdapter() {
@SuppressWarnings("all")
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 = cubridCMConfTableClickPoint;
int selectIndex = cubridCMConfTabTableViewer.getTable().getSelectionIndex();
final TableItem item = cubridCMConfTabTableViewer.getTable().getItem(selectIndex);
if (item == null) {
return;
}
for (int i = 0; i < cubridCMConfTabTableViewer.getTable().getColumnCount(); i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
if (i == 0) {
CommonUITool.openErrorBox(getSite().getShell(), Messages.annotationDialogOpenErrorMsg);
return;
}
IStructuredSelection selection = (IStructuredSelection) cubridCMConfTabTableViewer.getSelection();
HashMap<String, String> valueMap = (HashMap<String, String>) selection.getFirstElement();
String serverName = cubridConfCMConfigListData.get(0).get(i + "");
String parentPropertyKey = valueMap.get("0");
String parentKey = " ";
Map<String, String> cubridMap = cubridConfCMConfigListData.get(1);
String cubridName = "";
if (cubridMap != null) {
cubridName = cubridMap.get(i + "");
}
if (selectIndex == 0) {
parentKey += serverName;
} else {
if (selectIndex == 1) {
parentKey += serverName + "->" + cubridName;
} else {
parentKey += serverName + "->" + cubridName + "->" + parentPropertyKey;
}
}
String annotationKey = Integer.toString(i) + BrokerConfPersistUtil.ANNOTATION;
CubridBrokerConfEditAnnotationDialog dialog = new CubridBrokerConfEditAnnotationDialog(getSite().getShell(), parentKey, annotationKey, valueMap);
if (IDialogConstants.OK_ID == dialog.open()) {
setDirty(true);
}
}
}
}
});
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 = cubridCMConfTableClickPoint;
// click timing
if (System.currentTimeMillis() - cubridCMConfTableClickPointTiming > 300) {
itemEditAnnotation.setEnabled(false);
return;
}
int selectIndex = cubridCMConfTabTableViewer.getTable().getSelectionIndex();
if (selectIndex == -1) {
itemEditAnnotation.setEnabled(false);
return;
}
if (selectIndex == 0) {
itemEditAnnotation.setEnabled(false);
return;
}
final TableItem item = cubridCMConfTabTableViewer.getTable().getItem(selectIndex);
if (item == null) {
return;
}
for (int i = 0; i < cubridCMConfTabTableViewer.getTable().getColumnCount(); i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
if (i == 0) {
itemEditAnnotation.setEnabled(false);
} else {
itemEditAnnotation.setEnabled(true);
}
}
}
}
});
cubridCMConfTabTableViewer.getTable().setMenu(menu);
}
use of org.eclipse.swt.events.MenuAdapter in project cubrid-manager by CUBRID.
the class NewMultiHostConnectionDialog method createDialogArea.
protected Control createDialogArea(Composite parent) {
getShell().setText(Messages.multiConnectServerDialogTitle);
Composite parentComp = (Composite) super.createDialogArea(parent);
setTitle(Messages.multiConnectServerDialogTitle);
setMessage(Messages.multiConnectServerDialogMessages);
serverTable = new TableViewer(parentComp, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
serverTable.getTable().setLayoutData(gridData);
serverTable.getTable().setHeaderVisible(true);
serverTable.getTable().setLinesVisible(true);
final TableViewerColumn columnHost = new TableViewerColumn(serverTable, SWT.CENTER);
columnHost.getColumn().setWidth(120);
columnHost.getColumn().setText(Messages.multiConnectServerDialogColumnHostAddress);
final TableViewerColumn columnUser = new TableViewerColumn(serverTable, SWT.CENTER);
columnUser.getColumn().setWidth(200);
columnUser.getColumn().setText(Messages.multiConnectServerDialogColumnUser);
final TableViewerColumn columnErrMsg = new TableViewerColumn(serverTable, SWT.CENTER);
columnErrMsg.getColumn().setWidth(200);
columnErrMsg.getColumn().setText(Messages.multiConnectServerDialogColumnErrMsg);
final TableViewerColumn columnStatus = new TableViewerColumn(serverTable, SWT.CENTER);
columnStatus.getColumn().setWidth(100);
columnStatus.getColumn().setText(Messages.multiConnectServerDialogColumnStatus);
serverTable.setContentProvider(new ServerListContentProvider());
serverTable.setLabelProvider(new ServerListLabelProvider());
serverTable.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
FailedHostServerInfo multiHostConnectionFailedServerInfo = (FailedHostServerInfo) selection.getFirstElement();
editHost(multiHostConnectionFailedServerInfo);
}
});
serverTable.setInput(failedServerList);
MenuManager menuManager = new MenuManager();
Menu contextMenu = menuManager.createContextMenu(serverTable.getTable());
serverTable.getTable().setMenu(contextMenu);
Menu menu = new Menu(getShell(), SWT.POP_UP);
final MenuItem itemEdit = new MenuItem(menu, SWT.PUSH);
itemEdit.setText(Messages.msgConnectHostDialog);
itemEdit.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
IStructuredSelection selection = (StructuredSelection) serverTable.getSelection();
FailedHostServerInfo multiHostConnectionFailedServerInfo = (FailedHostServerInfo) selection.getFirstElement();
editHost(multiHostConnectionFailedServerInfo);
}
});
menu.addMenuListener(new MenuAdapter() {
public void menuShown(MenuEvent event) {
IStructuredSelection selection = (IStructuredSelection) serverTable.getSelection();
FailedHostServerInfo multiHostConnectionFailedServerInfo = (FailedHostServerInfo) selection.getFirstElement();
if (multiHostConnectionFailedServerInfo.getCubridServer().isConnected()) {
itemEdit.setEnabled(false);
} else {
itemEdit.setEnabled(true);
}
}
});
serverTable.getTable().setMenu(menu);
return parentComp;
}
use of org.eclipse.swt.events.MenuAdapter in project cubrid-manager by CUBRID.
the class MultiDatabaseLoginFailedDialog method createDialogArea.
protected Control createDialogArea(Composite parent) {
getShell().setText(Messages.multiDatabaseLoginDialogTitle);
Composite parentComp = (Composite) super.createDialogArea(parent);
setTitle(Messages.multiDatabaseLoginDialogTitle);
setMessage(Messages.multiDatabaseLoginDialogMessages);
databaseTable = new TableViewer(parentComp, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
databaseTable.getTable().setLayoutData(gridData);
databaseTable.getTable().setHeaderVisible(true);
databaseTable.getTable().setLinesVisible(true);
final TableViewerColumn columnHost = new TableViewerColumn(databaseTable, SWT.CENTER);
columnHost.getColumn().setWidth(120);
columnHost.getColumn().setText(Messages.multiDatabaseLoginDialogColumnHostAddress);
final TableViewerColumn columnDatabase = new TableViewerColumn(databaseTable, SWT.CENTER);
columnDatabase.getColumn().setWidth(150);
columnDatabase.getColumn().setText(Messages.multiDatabaseLoginDialogColumnDbName);
final TableViewerColumn columnUser = new TableViewerColumn(databaseTable, SWT.CENTER);
columnUser.getColumn().setWidth(100);
columnUser.getColumn().setText(Messages.multiDatabaseLoginDialogColumnUser);
final TableViewerColumn columnErrMsg = new TableViewerColumn(databaseTable, SWT.CENTER);
columnErrMsg.getColumn().setWidth(200);
columnErrMsg.getColumn().setText(Messages.multiDatabaseLoginDialogColumnErrMsg);
final TableViewerColumn columnStatus = new TableViewerColumn(databaseTable, SWT.CENTER);
columnStatus.getColumn().setWidth(100);
columnStatus.getColumn().setText(Messages.multiDatabaseLoginDialogColumnStatus);
databaseTable.setContentProvider(new ServerListContentProvider());
databaseTable.setLabelProvider(new ServerListLabelProvider());
databaseTable.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
MultiDatabaseloginFailedInfo multiDatabaseloginFailedInfo = (MultiDatabaseloginFailedInfo) selection.getFirstElement();
editHost(multiDatabaseloginFailedInfo);
//if all database login , close this dialog
if (checkAllDatabaseLogin()) {
close();
}
}
});
databaseTable.setInput(failedDatabaseList);
MenuManager menuManager = new MenuManager();
Menu contextMenu = menuManager.createContextMenu(databaseTable.getTable());
databaseTable.getTable().setMenu(contextMenu);
Menu menu = new Menu(getShell(), SWT.POP_UP);
final MenuItem itemEdit = new MenuItem(menu, SWT.PUSH);
itemEdit.setText(Messages.multiDatabaseLoginDialogEditLabel);
itemEdit.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
IStructuredSelection selection = (StructuredSelection) databaseTable.getSelection();
MultiDatabaseloginFailedInfo multiDatabaseloginFailedInfo = (MultiDatabaseloginFailedInfo) selection.getFirstElement();
editHost(multiDatabaseloginFailedInfo);
}
});
menu.addMenuListener(new MenuAdapter() {
public void menuShown(MenuEvent event) {
IStructuredSelection selection = (IStructuredSelection) databaseTable.getSelection();
MultiDatabaseloginFailedInfo multiDatabaseloginFailedInfo = (MultiDatabaseloginFailedInfo) selection.getFirstElement();
if (multiDatabaseloginFailedInfo.getCubridDatabase().isLogined()) {
itemEdit.setEnabled(false);
} else {
itemEdit.setEnabled(true);
}
}
});
databaseTable.getTable().setMenu(menu);
databaseTable.getTable().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (databaseTable.getTable().getSelectionIndices().length > 0) {
getButton(EDIT_ID).setEnabled(true);
} else {
getButton(EDIT_ID).setEnabled(false);
}
}
});
return parentComp;
}
Aggregations