use of org.eclipse.ui.handlers.IHandlerService in project egit by eclipse.
the class GitActionContributor method createItem.
private CommandContributionItem createItem(String itemAction) {
IWorkbench workbench = PlatformUI.getWorkbench();
CommandContributionItemParameter itemParam = new CommandContributionItemParameter(workbench, null, itemAction, STYLE_PUSH);
IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
IHandlerService hsr = CommonUtils.getService(activeWorkbenchWindow, IHandlerService.class);
IEvaluationContext ctx = hsr.getCurrentState();
ctx.addVariable(ACTIVE_MENU_SELECTION_NAME, getContext().getSelection());
return new CommandContributionItem(itemParam);
}
use of org.eclipse.ui.handlers.IHandlerService in project egit by eclipse.
the class RepositoriesView method createEmptyArea.
/**
* Create area shown when no repositories are present
*
* @param parent
*/
protected void createEmptyArea(Composite parent) {
emptyArea = new Composite(parent, SWT.NONE);
emptyArea.setBackgroundMode(SWT.INHERIT_FORCE);
MenuManager manager = new MenuManager();
manager.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager m) {
getNavigatorActionService().fillContextMenu(m);
}
});
getSite().registerContextMenu(manager, getCommonViewer());
Menu menu = manager.createContextMenu(emptyArea);
emptyArea.setMenu(menu);
GridLayoutFactory.fillDefaults().applyTo(emptyArea);
Composite infoArea = new Composite(emptyArea, SWT.NONE);
infoArea.setMenu(menu);
GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, true).applyTo(infoArea);
GridLayoutFactory.swtDefaults().applyTo(infoArea);
Label messageLabel = new Label(infoArea, SWT.WRAP);
messageLabel.setText(UIText.RepositoriesView_messsageEmpty);
messageLabel.setMenu(menu);
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(messageLabel);
Composite optionsArea = new Composite(infoArea, SWT.NONE);
optionsArea.setMenu(menu);
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(optionsArea);
GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, true).applyTo(optionsArea);
final FormToolkit toolkit = new FormToolkit(emptyArea.getDisplay());
emptyArea.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
toolkit.dispose();
}
});
final Color linkColor = JFaceColors.getHyperlinkText(emptyArea.getDisplay());
Label addLabel = new Label(optionsArea, SWT.NONE);
Image addImage = UIIcons.NEW_REPOSITORY.createImage();
UIUtils.hookDisposal(addLabel, addImage);
addLabel.setImage(addImage);
Hyperlink addLink = toolkit.createHyperlink(optionsArea, UIText.RepositoriesView_linkAdd, SWT.WRAP);
addLink.setForeground(linkColor);
addLink.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
IHandlerService service = CommonUtils.getService(getViewSite(), IHandlerService.class);
UIUtils.executeCommand(service, // $NON-NLS-1$
"org.eclipse.egit.ui.RepositoriesViewAddRepository");
}
});
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(addLink);
Label cloneLabel = new Label(optionsArea, SWT.NONE);
Image cloneImage = UIIcons.CLONEGIT.createImage();
UIUtils.hookDisposal(cloneLabel, cloneImage);
cloneLabel.setImage(cloneImage);
Hyperlink cloneLink = toolkit.createHyperlink(optionsArea, UIText.RepositoriesView_linkClone, SWT.WRAP);
cloneLink.setForeground(linkColor);
cloneLink.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
IHandlerService service = CommonUtils.getService(getViewSite(), IHandlerService.class);
UIUtils.executeCommand(service, // $NON-NLS-1$
"org.eclipse.egit.ui.RepositoriesViewClone");
}
});
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(cloneLink);
Label createLabel = new Label(optionsArea, SWT.NONE);
Image createImage = UIIcons.CREATE_REPOSITORY.createImage();
UIUtils.hookDisposal(createLabel, createImage);
createLabel.setImage(createImage);
Hyperlink createLink = toolkit.createHyperlink(optionsArea, UIText.RepositoriesView_linkCreate, SWT.WRAP);
createLink.setForeground(linkColor);
createLink.setText(UIText.RepositoriesView_linkCreate);
createLink.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
IHandlerService service = CommonUtils.getService(getViewSite(), IHandlerService.class);
UIUtils.executeCommand(service, // $NON-NLS-1$
"org.eclipse.egit.ui.RepositoriesViewCreateRepository");
}
});
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(createLink);
}
use of org.eclipse.ui.handlers.IHandlerService in project mylyn.docs by eclipse.
the class MarkupEditor method setAction.
@Override
public void setAction(String actionID, IAction action) {
if (action != null && action.getActionDefinitionId() != null && !isCommandAction(action)) {
// bug 336679: don't activate handlers for CommandAction.
// We do this by class name so that we don't rely on internals
IHandlerService handlerService = getSite().getService(IHandlerService.class);
handlerService.activateHandler(action.getActionDefinitionId(), new ActionHandler(action));
}
super.setAction(actionID, action);
}
use of org.eclipse.ui.handlers.IHandlerService in project ecf by eclipse.
the class DiscoveryView method createPartControl.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets
* .Composite)
*/
public void createPartControl(Composite parent) {
ComposedAdapterFactory adapterFactory = DiscoveryEditingDomainProvider.eINSTANCE.getAdapterFactory();
// create the viewer
setSelectionViewer(new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL));
getSelectionViewer().setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
getSelectionViewer().setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
getSelectionViewer().setComparator(new ViewerComparator());
getSelectionViewer().setFilters(getViewerFilters());
getSelectionViewer().setUseHashlookup(true);
getSite().setSelectionProvider(getSelectionViewer());
// populate the viewer with the model if available
EList resources = DiscoveryEditingDomainProvider.eINSTANCE.getEditingDomain().getResourceSet().getResources();
if (resources != null) {
getSelectionViewer().setInput(resources.get(0));
getSelectionViewer().setSelection(new StructuredSelection(resources.get(0)), true);
}
new AdapterFactoryTreeEditor(getSelectionViewer().getTree(), adapterFactory);
getSelectionViewer().addPostSelectionChangedListener(new AdapterFactoryStatuslineProvider(adapterFactory, getViewSite().getActionBars().getStatusLineManager()));
drillDownAdapter = new DrillDownAdapter(getSelectionViewer());
createContextMenuFor(getSelectionViewer());
hookContextMenu();
contributeToActionBars();
// add collapse handler
IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
collapseHandler = new CollapseAllHandler(getSelectionViewer());
handlerService.activateHandler(CollapseAllHandler.COMMAND_ID, collapseHandler);
// add DND support
Transfer[] supportedTransfers = { LocalSelectionTransfer.getTransfer() };
getSelectionViewer().addDragSupport(DND.DROP_DEFAULT | DND.DROP_COPY | DND.DROP_MOVE, supportedTransfers, new DragSourceAdapter() {
public void dragSetData(DragSourceEvent event) {
LocalSelectionTransfer.getTransfer().setSelection(getSelectionViewer().getSelection());
}
});
// $NON-NLS-1$
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, "org.eclipse.ecf.discovery.ui.ServiceView");
getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
}
use of org.eclipse.ui.handlers.IHandlerService in project dbeaver by serge-rider.
the class CheckForUpdateAction method deactivateStandardHandler.
public static void deactivateStandardHandler(IWorkbenchWindow window) {
if (p2UpdateHandlerActivation != null) {
return;
}
IHandlerService srv = window.getService(IHandlerService.class);
p2UpdateHandlerActivation = srv.activateHandler(CheckForUpdateAction.P2_UPDATE_COMMAND, new AbstractHandler() {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
new CheckForUpdateAction().run();
return null;
}
});
}
Aggregations