use of org.eclipse.swt.events.MenuEvent 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;
}
use of org.eclipse.swt.events.MenuEvent in project hale by halestudio.
the class ShowLayoutMenuHandler method execute.
/**
* @see IHandler#execute(ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IViewPart viewPart = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().findView(StyledMapView.ID);
if (viewPart instanceof MapView) {
// view visible - show layout menu
final MenuManager manager = new MenuManager();
manager.setRemoveAllWhenShown(true);
final IconPainterLayoutContribution contribution = new IconPainterLayoutContribution();
manager.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
// populate context menu
manager.add(contribution);
}
});
Shell shell = HandlerUtil.getActiveShell(event);
final Menu menu = manager.createContextMenu(shell);
// determine location
Point cursorLocation = Display.getCurrent().getCursorLocation();
// default to cursor location
Point location = cursorLocation;
// try to determine from control
Control cursorControl = Display.getCurrent().getCursorControl();
if (cursorControl != null) {
if (cursorControl instanceof ToolBar) {
ToolBar bar = (ToolBar) cursorControl;
ToolItem item = bar.getItem(bar.toControl(cursorLocation));
if (item != null) {
Rectangle bounds = item.getBounds();
location = bar.toDisplay(bounds.x, bounds.y + bounds.height);
}
} else {
// show below control
location = cursorControl.toDisplay(0, cursorControl.getSize().y);
}
}
menu.setLocation(location);
menu.addMenuListener(new MenuListener() {
@Override
public void menuShown(MenuEvent e) {
// do nothing
}
@Override
public void menuHidden(MenuEvent e) {
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
/*
* Dispose everything as it is used only once. Done
* asynchronously as otherwise we interfere with the
* menu click handling.
*/
manager.dispose();
contribution.dispose();
menu.dispose();
}
});
}
});
// show menu
menu.setVisible(true);
} else {
// view not visible - just show map perspective
try {
PlatformUI.getWorkbench().showPerspective(StyledMapPerspective.ID, HandlerUtil.getActiveWorkbenchWindow(event));
} catch (WorkbenchException e) {
log.error("Could not open map perspective", e);
}
}
return null;
}
use of org.eclipse.swt.events.MenuEvent in project dbeaver by dbeaver.
the class NavigatorUtils method createContextMenu.
public static MenuManager createContextMenu(final IWorkbenchSite workbenchSite, final Viewer viewer, final IMenuListener menuListener) {
final Control control = viewer.getControl();
final MenuManager menuMgr = new MenuManager();
Menu menu = menuMgr.createContextMenu(control);
menu.addMenuListener(new MenuListener() {
@Override
public void menuHidden(MenuEvent e) {
}
@Override
public void menuShown(MenuEvent e) {
Menu m = (Menu) e.widget;
DBNNode node = getSelectedNode(viewer.getSelection());
if (node != null && !node.isLocked() && node.allowsOpen()) {
String commandID = NavigatorUtils.getNodeActionCommand(DBXTreeNodeHandler.Action.open, node, CoreCommands.CMD_OBJECT_OPEN);
// Get contribution item from menu item and check it's ID
for (MenuItem item : m.getItems()) {
Object itemData = item.getData();
if (itemData instanceof IContributionItem) {
String contribId = ((IContributionItem) itemData).getId();
if (contribId != null && contribId.equals(commandID)) {
m.setDefaultItem(item);
}
}
}
}
}
});
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(final IMenuManager manager) {
ViewerColumnController columnController = ViewerColumnController.getFromControl(control);
if (columnController != null && columnController.isClickOnHeader()) {
columnController.fillConfigMenu(manager);
manager.add(new Separator());
return;
}
manager.add(new GroupMarker(CoreCommands.GROUP_NAVIGATOR_ADDITIONS));
final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
final DBNNode selectedNode = getSelectedNode(viewer);
if (selectedNode != null && !selectedNode.isLocked() && workbenchSite != null) {
// Add "Set active object" menu
if (selectedNode.isPersisted() && selectedNode instanceof DBNDatabaseNode && !(selectedNode instanceof DBNDatabaseFolder) && ((DBNDatabaseNode) selectedNode).getObject() != null) {
final DBSObjectSelector activeContainer = DBUtils.getParentAdapter(DBSObjectSelector.class, ((DBNDatabaseNode) selectedNode).getObject());
if (activeContainer != null && activeContainer.supportsDefaultChange()) {
DBSObject activeChild;
activeChild = activeContainer.getDefaultObject();
if (activeChild != ((DBNDatabaseNode) selectedNode).getObject()) {
DBNDatabaseNode databaseNode = (DBNDatabaseNode) selectedNode;
if (databaseNode.getObject() != null && (activeChild == null || activeChild.getClass() == databaseNode.getObject().getClass())) {
manager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_SET_ACTIVE));
}
}
}
}
manager.add(new Separator());
manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
manager.add(new GroupMarker(IActionConstants.MB_ADDITIONS_END));
// Add properties button
if (PreferencesUtil.hasPropertiesContributors(selection.getFirstElement())) {
manager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_PROPERTIES));
}
if (selectedNode.isPersisted()) {
// Add refresh button
manager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_REFRESH));
}
}
manager.add(new GroupMarker(CoreCommands.GROUP_TOOLS));
manager.add(new GroupMarker(CoreCommands.GROUP_TOOLS_END));
if (menuListener != null) {
menuListener.menuAboutToShow(manager);
}
}
});
menuMgr.setRemoveAllWhenShown(true);
control.setMenu(menu);
control.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
menuMgr.dispose();
}
});
return menuMgr;
}
use of org.eclipse.swt.events.MenuEvent in project eclipse.platform.text by eclipse.
the class OpenSearchDialogPageAction method fillMenu.
private void fillMenu(final Menu localMenu) {
List<SearchPageDescriptor> pageDescriptors = SearchPlugin.getDefault().getSearchPageDescriptors();
int accelerator = 1;
for (SearchPageDescriptor desc : pageDescriptors) {
if (!WorkbenchActivityHelper.filterItem(desc) && desc.isEnabled()) {
SearchPageAction action = new SearchPageAction(fWorkbenchWindow, desc);
addToMenu(localMenu, action, accelerator++);
}
}
localMenu.addMenuListener(new MenuAdapter() {
@Override
public void menuHidden(MenuEvent e) {
e.display.asyncExec(() -> localMenu.dispose());
}
});
}
use of org.eclipse.swt.events.MenuEvent in project cubrid-manager by CUBRID.
the class BrokerConfigEditComposite method registerContextMenu.
/**
* Register context menu
*/
private void registerContextMenu() {
final Table confTable = confTableViewer.getTable();
confTable.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent event) {
ActionManager.getInstance().changeFocusProvider(confTable);
}
});
final MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
final Menu contextMenu = menuManager.createContextMenu(confTable);
confTable.setMenu(contextMenu);
final Menu menu = new Menu(editorPart.getSite().getShell(), SWT.POP_UP);
final MenuItem itemEditAnnotation = new MenuItem(menu, SWT.PUSH);
itemEditAnnotation.setText(Messages.cubridBrokerConfEditorTableMenuEditAnnotation);
itemEditAnnotation.addSelectionListener(new SelectionAdapter() {
@SuppressWarnings("all")
public void widgetSelected(SelectionEvent event) {
// It seems like MenuEvent can't get the mouse click Point
// so use the point which table MouseDown event marked
final Point pt = clickPoint;
int selectIndex = confTable.getSelectionIndex();
if (selectIndex < 0) {
return;
}
final TableItem item = confTable.getItem(selectIndex);
if (item == null) {
return;
}
for (int i = 0, len = confTable.getColumnCount(); i < len; i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
if (i == 0) {
openErrorBox(editorPart.getSite().getShell(), Messages.cubridBrokerConfEditAnnotationDialogOpenErrorMsg);
return;
}
IStructuredSelection selection = (IStructuredSelection) confTableViewer.getSelection();
HashMap<String, String> valueMap = (HashMap<String, String>) selection.getFirstElement();
String brokerName = confListData.get(0).get(String.valueOf(i));
String parentPropertyKey = valueMap.get("0");
String parentKey = " ";
if (selectIndex == 0) {
parentKey += brokerName;
} else {
parentKey += brokerName + "->" + parentPropertyKey;
}
String annotationKey = i + ANNOTATION;
CubridBrokerConfEditAnnotationDialog dialog = new CubridBrokerConfEditAnnotationDialog(editorPart.getSite().getShell(), parentKey, annotationKey, valueMap);
if (dialog.open() == OK_ID) {
editorPart.setDirty(true);
}
}
}
}
});
final MenuItem itemAddBrokerConf = new MenuItem(menu, SWT.PUSH);
itemAddBrokerConf.setText(Messages.cubridBrokerConfEditorAddBrokerConfItemLabel);
itemAddBrokerConf.setImage(CommonUIPlugin.getImage("icons/action/column_insert.png"));
itemAddBrokerConf.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
addBrokerConfColumn();
editorPart.setDirty(true);
}
});
final MenuItem itemDeleteBrokerConf = new MenuItem(menu, SWT.PUSH);
itemDeleteBrokerConf.setText(Messages.cubridBrokerConfEditorDeleteBrokerConfItemLabel);
itemDeleteBrokerConf.setImage(CommonUIPlugin.getImage("icons/action/column_delete.png"));
itemDeleteBrokerConf.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
// It seems like MenuEvent can't get the mouse click Point
// so use the point which table MouseDown event marked
final Point pt = clickPoint;
final TableItem item = findSelectItem(confTable);
if (item == null) {
return;
}
int columnCount = confTable.getColumnCount();
for (int i = 0; i < columnCount; i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
Map<String, String> valueMap = confListData.get(0);
String confName = valueMap.get(String.valueOf(i));
String msg = Messages.bind(Messages.cubridBrokerConfEditorDeleteBrokerConfConfirm, confName);
if (!CommonUITool.openConfirmBox(msg)) {
return;
}
confTable.getColumn(i).dispose();
for (int j = 1; j < columnCount; j++) {
confTable.getColumn(j).setText(Messages.cubridBrokerConfEditorBrokerTitle + (j - 1));
}
// delete data from cubridBrokerConfig, so regenerate cubridBrokerConfListData from cubridBrokerConfig
editorPart.getBrokerConfPersistUtil().deleteBrokerPropertyByBrokerName(brokerConfig, confName);
confListData.clear();
confListData.addAll(editorPart.parseBrokerConfigToCommonTableValue(brokerConfig));
confTableViewer.refresh();
editorPart.setDirty(true);
return;
}
}
}
});
menu.addMenuListener(new MenuAdapter() {
public void menuShown(MenuEvent event) {
// It seems like MenuEvent can't get the mouse click Point
// so use the point which table MouseDown event marked
final Point pt = clickPoint;
// It will allow that the click timing is more than 300 msec.
if (System.currentTimeMillis() - clickPointTiming > 300) {
itemEditAnnotation.setEnabled(false);
itemDeleteBrokerConf.setEnabled(false);
itemAddBrokerConf.setEnabled(false);
return;
}
int selectIndex = confTable.getSelectionIndex();
if (selectIndex < 0) {
itemEditAnnotation.setEnabled(false);
itemDeleteBrokerConf.setEnabled(false);
itemAddBrokerConf.setEnabled(true);
return;
}
final TableItem item = confTable.getItem(selectIndex);
if (item == null) {
return;
}
for (int i = 0, len = confTable.getColumnCount(); i < len; i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
boolean enableToAccess = i > 0;
itemEditAnnotation.setEnabled(enableToAccess);
itemDeleteBrokerConf.setEnabled(enableToAccess);
}
}
itemAddBrokerConf.setEnabled(true);
}
});
confTable.setMenu(menu);
}
Aggregations