use of org.eclipse.swt.events.MenuListener in project cubrid-manager by CUBRID.
the class ServiceDashboardEditor method initMenu.
private void initMenu(Tree tree) {
ActionManager manager = ActionManager.getInstance();
Menu menu = new Menu(this.getSite().getShell(), SWT.POP_UP);
tree.setMenu(menu);
refreshMenuItem = new MenuItem(menu, SWT.PUSH);
refreshMenuItem.setText(Messages.btnRefresh);
refreshMenuItem.setImage(CubridManagerUIPlugin.getImage("icons/action/refresh.png"));
refreshMenuItem.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
widgetDefaultSelected(e);
}
public void widgetDefaultSelected(SelectionEvent e) {
loadAllData();
}
});
new MenuItem(menu, SWT.SEPARATOR);
final ConnectHostAction connectHostAction = (ConnectHostAction) manager.getAction(ConnectHostAction.ID);
connectMenuItem = new MenuItem(menu, SWT.PUSH);
connectMenuItem.setText(connectHostAction.getText());
connectMenuItem.setImage(connectHostAction.getImageDescriptor().createImage());
connectMenuItem.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
widgetDefaultSelected(e);
}
public void widgetDefaultSelected(SelectionEvent e) {
connectHostAction.doRun(getSelectedServer());
loadAllData();
}
});
final DisConnectHostAction disConnectHostAction = (DisConnectHostAction) manager.getAction(DisConnectHostAction.ID);
disConnectMenuItem = new MenuItem(menu, SWT.PUSH);
disConnectMenuItem.setText(disConnectHostAction.getText());
disConnectMenuItem.setImage(disConnectHostAction.getImageDescriptor().createImage());
disConnectMenuItem.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
widgetDefaultSelected(e);
}
public void widgetDefaultSelected(SelectionEvent e) {
disConnectHostAction.doRun(getSelectedServer());
loadAllData();
}
});
new MenuItem(menu, SWT.SEPARATOR);
final AddHostAction addHostAction = (AddHostAction) manager.getAction(AddHostAction.ID);
addHostMenuItem = new MenuItem(menu, SWT.PUSH);
addHostMenuItem.setText(addHostAction.getText());
addHostMenuItem.setImage(addHostAction.getImageDescriptor().createImage());
addHostMenuItem.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
widgetDefaultSelected(e);
}
public void widgetDefaultSelected(SelectionEvent e) {
addHostAction.doRun(getSelectedServer());
loadAllData();
}
});
final EditHostAction editHostAction = (EditHostAction) manager.getAction(EditHostAction.ID);
editHostMenuItem = new MenuItem(menu, SWT.PUSH);
editHostMenuItem.setText(editHostAction.getText());
editHostMenuItem.setImage(editHostAction.getImageDescriptor().createImage());
editHostMenuItem.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
widgetDefaultSelected(e);
}
public void widgetDefaultSelected(SelectionEvent e) {
editHostAction.doRun(getSelectedServer(), false);
loadAllData();
}
});
final DeleteHostAction deleteHostAction = (DeleteHostAction) manager.getAction(DeleteHostAction.ID);
deleteHostMenuItem = new MenuItem(menu, SWT.PUSH);
deleteHostMenuItem.setText(deleteHostAction.getText());
deleteHostMenuItem.setImage(deleteHostAction.getImageDescriptor().createImage());
deleteHostMenuItem.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
widgetDefaultSelected(e);
}
public void widgetDefaultSelected(SelectionEvent e) {
deleteHostAction.doRun(getSelectedServer());
loadAllData();
}
});
new MenuItem(menu, SWT.SEPARATOR);
final StartServiceAction startServiceAction = (StartServiceAction) manager.getAction(StartServiceAction.ID);
startServiceMenuItem = new MenuItem(menu, SWT.PUSH);
startServiceMenuItem.setText(startServiceAction.getText());
startServiceMenuItem.setImage(startServiceAction.getImageDescriptor().createImage());
startServiceMenuItem.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
widgetDefaultSelected(e);
}
public void widgetDefaultSelected(SelectionEvent e) {
startServiceAction.doRun(getSelectedServer());
loadAllData();
}
});
final StopServiceAction stopServiceAction = (StopServiceAction) manager.getAction(StopServiceAction.ID);
stopServiceMenuItem = new MenuItem(menu, SWT.PUSH);
stopServiceMenuItem.setText(stopServiceAction.getText());
stopServiceMenuItem.setImage(stopServiceAction.getImageDescriptor().createImage());
stopServiceMenuItem.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
widgetDefaultSelected(e);
}
public void widgetDefaultSelected(SelectionEvent e) {
stopServiceAction.doRun(getSelectedServer());
loadAllData();
}
});
menu.addMenuListener(new MenuListener() {
public void menuShown(MenuEvent e) {
updateMenuItems();
}
public void menuHidden(MenuEvent e) {
}
});
}
use of org.eclipse.swt.events.MenuListener in project dbeaver by serge-rider.
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(MB_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())) {
// + databaseNode.getNodeType();
String text = "Set Active ";
// Fill context menu
IAction action = ActionUtils.makeAction(new NavigatorActionSetActiveObject(), workbenchSite, selection, text, null, null);
manager.add(action);
}
}
}
}
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));
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.MenuListener in project cubrid-manager by CUBRID.
the class TableConfigCellEditor method registerContextMenu.
/**
* register context menu
*/
private void registerContextMenu() {
sqlFileTableViewer.getTable().addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent event) {
ActionManager.getInstance().changeFocusProvider(sqlFileTableViewer.getTable());
}
});
Menu menu = new Menu(getShell(), SWT.POP_UP);
final MenuItem addSchemaItem = new MenuItem(menu, SWT.PUSH);
addSchemaItem.setText(Messages.btnAddSchemaFile);
addSchemaItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
addFile(TableConfig.TYPE_SCHEMA);
}
});
final MenuItem addDataItem = new MenuItem(menu, SWT.PUSH);
addDataItem.setText(Messages.btnAddDataFile);
addDataItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
addFile(TableConfig.TYPE_DATA);
}
});
final MenuItem addIndexItem = new MenuItem(menu, SWT.PUSH);
addIndexItem.setText(Messages.btnAddIndexFile);
addIndexItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
addFile(TableConfig.TYPE_INDEX);
}
});
new MenuItem(menu, SWT.SEPARATOR);
final MenuItem delItem = new MenuItem(menu, SWT.PUSH);
delItem.setText(Messages.btnDelFiles);
delItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
deleteSelectedFile();
}
});
menu.addMenuListener(new MenuListener() {
public void menuHidden(org.eclipse.swt.events.MenuEvent e) {
}
public void menuShown(org.eclipse.swt.events.MenuEvent e) {
delItem.setEnabled(delCanEnable());
}
});
sqlFileTableViewer.getTable().setMenu(menu);
}
Aggregations