use of org.eclipse.ui.ISourceProvider in project eclipse.platform.ui by eclipse-platform.
the class LegacyHandlerService method createContextSnapshot.
@Override
public IEvaluationContext createContextSnapshot(boolean includeSelection) {
IEvaluationContext tmpContext = getCurrentState();
IEvaluationContext context = new EvaluationContext(null, IEvaluationContext.UNDEFINED_VARIABLE);
if (includeSelection) {
for (String variable : SELECTION_VARIABLES) {
copyVariable(context, tmpContext, variable);
}
}
ISourceProviderService sp = eclipseContext.get(ISourceProviderService.class);
for (ISourceProvider provider : sp.getSourceProviders()) {
String[] names = provider.getProvidedSourceNames();
for (String name : names) {
if (!isSelectionVariable(name)) {
copyVariable(context, tmpContext, name);
}
}
}
return context;
}
use of org.eclipse.ui.ISourceProvider in project eclipse.platform.ui by eclipse-platform.
the class ExpressionAuthority method dispose.
/**
* Removes all of the source provider listeners. Subclasses may extend, but must
* not override.
*/
public void dispose() {
final Iterator<ISourceProvider> providerItr = providers.iterator();
while (providerItr.hasNext()) {
final ISourceProvider provider = providerItr.next();
provider.removeSourceProviderListener(this);
}
providers.clear();
}
use of org.eclipse.ui.ISourceProvider in project eclipse.platform.ui by eclipse-platform.
the class ShowInHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPage p = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
WorkbenchPartReference r = (WorkbenchPartReference) p.getActivePartReference();
if (p != null && r != null && r.getModel() != null) {
((WorkbenchPage) p).updateShowInSources(r.getModel());
}
String targetId = event.getParameter(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_PARM_TARGET);
if (targetId == null) {
// $NON-NLS-1$
throw new ExecutionException("No targetId specified");
}
final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindowChecked(event);
ISourceProviderService sps = activeWorkbenchWindow.getService(ISourceProviderService.class);
if (sps != null) {
ISourceProvider sp = sps.getSourceProvider(ISources.SHOW_IN_SELECTION);
if (sp instanceof WorkbenchSourceProvider) {
((WorkbenchSourceProvider) sp).checkActivePart(true);
}
}
ShowInContext context = getContext(HandlerUtil.getShowInSelection(event), HandlerUtil.getShowInInput(event));
if (context == null) {
return null;
}
IWorkbenchPage page = activeWorkbenchWindow.getActivePage();
try {
IViewPart view = page.showView(targetId);
IShowInTarget target = getShowInTarget(view);
if (!(target != null && target.show(context))) {
page.getWorkbenchWindow().getShell().getDisplay().beep();
}
// TODO: move
((WorkbenchPage) page).performedShowIn(targetId);
// back up
} catch (PartInitException e) {
// $NON-NLS-1$
throw new ExecutionException("Failed to show in", e);
}
return null;
}
use of org.eclipse.ui.ISourceProvider in project eclipse.platform.ui by eclipse-platform.
the class ShowInMenu method fillMenu.
/**
* Fills the menu with Show In actions.
*/
private void fillMenu(IMenuManager innerMgr) {
IWorkbenchPage page = locator.getService(IWorkbenchPage.class);
if (page == null) {
return;
}
WorkbenchPartReference r = (WorkbenchPartReference) page.getActivePartReference();
if (r != null && r.getModel() != null) {
((WorkbenchPage) page).updateShowInSources(r.getModel());
}
// Remove all.
innerMgr.removeAll();
IWorkbenchPart sourcePart = getSourcePart();
ShowInContext context = getContext(sourcePart);
if (context == null) {
return;
}
if (context.getInput() == null && (context.getSelection() == null || context.getSelection().isEmpty())) {
return;
}
IViewDescriptor[] viewDescs = getViewDescriptors(sourcePart);
for (IViewDescriptor viewDesc : viewDescs) {
IContributionItem cci = getContributionItem(viewDesc);
if (cci != null) {
innerMgr.add(cci);
}
}
if (sourcePart != null && innerMgr instanceof MenuManager) {
ISourceProviderService sps = locator.getService(ISourceProviderService.class);
ISourceProvider sp = sps.getSourceProvider(ISources.SHOW_IN_SELECTION);
if (sp instanceof WorkbenchSourceProvider) {
((WorkbenchSourceProvider) sp).checkActivePart(true);
}
// add contributions targeting popup:org.eclipse.ui.menus.showInMenu
String location = MenuUtil.SHOW_IN_MENU_ID;
location = location.substring(location.indexOf(':') + 1);
WorkbenchWindow workbenchWindow = (WorkbenchWindow) getWindow();
MApplication application = workbenchWindow.getModel().getContext().get(MApplication.class);
MMenu menuModel = MenuFactoryImpl.eINSTANCE.createMenu();
final ArrayList<MMenuContribution> toContribute = new ArrayList<>();
final ArrayList<MMenuElement> menuContributionsToRemove = new ArrayList<>();
ExpressionContext eContext = new ExpressionContext(workbenchWindow.getModel().getContext());
ContributionsAnalyzer.gatherMenuContributions(menuModel, application.getMenuContributions(), location, toContribute, eContext, true);
ContributionsAnalyzer.addMenuContributions(menuModel, toContribute, menuContributionsToRemove);
ICommandImageService imgService = workbenchWindow.getService(ICommandImageService.class);
for (MMenuElement menuElement : menuModel.getChildren()) {
if (menuElement instanceof MHandledMenuItem) {
MCommand command = ((MHandledMenuItem) menuElement).getCommand();
String commandId = command.getElementId();
CommandContributionItemParameter ccip = new CommandContributionItemParameter(workbenchWindow, commandId, commandId, CommandContributionItem.STYLE_PUSH);
String label = menuElement.getLabel();
if (label != null && label.length() > 0) {
ccip.label = label;
String mnemonics = menuElement.getMnemonics();
if (mnemonics != null && mnemonics.length() == 1) {
ccip.mnemonic = mnemonics;
} else {
ccip.mnemonic = label.substring(0, 1);
}
}
String iconURI = menuElement.getIconURI();
try {
if (iconURI != null && !iconURI.isEmpty()) {
ccip.icon = ImageDescriptor.createFromURL(new URL(iconURI));
} else {
ccip.icon = imgService.getImageDescriptor(commandId);
}
} catch (MalformedURLException e) {
ccip.icon = imgService.getImageDescriptor(commandId);
}
List<MParameter> menuParameters = ((MHandledMenuItem) menuElement).getParameters();
if (menuParameters != null && !menuParameters.isEmpty()) {
ccip.parameters = new HashMap<>(menuParameters.size());
for (MParameter menuParam : menuParameters) {
ccip.parameters.put(menuParam.getName(), menuParam.getValue());
}
}
innerMgr.add(new CommandContributionItem(ccip));
}
}
}
}
use of org.eclipse.ui.ISourceProvider in project eclipse.platform.ui by eclipse-platform.
the class Workbench method initializeDefaultServices.
/**
* Initializes all of the default services for the workbench. For initializing
* the command-based services, this also parses the registry and hooks up all
* the required listeners.
*/
private void initializeDefaultServices() {
final IContributionService contributionService = new ContributionService(getAdvisor());
serviceLocator.registerService(IContributionService.class, contributionService);
// TODO Correctly order service initialization
// there needs to be some serious consideration given to
// the services, and hooking them up in the correct order
final IEvaluationService evaluationService = serviceLocator.getService(IEvaluationService.class);
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
serviceLocator.registerService(ISaveablesLifecycleListener.class, new SaveablesList());
}
});
/*
* Phase 1 of the initialization of commands. When this phase completes, all the
* services and managers will exist, and be accessible via the
* getService(Object) method.
*/
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
Command.DEBUG_COMMAND_EXECUTION = Policy.DEBUG_COMMANDS;
commandManager = e4Context.get(CommandManager.class);
}
});
final CommandService[] commandService = new CommandService[1];
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
commandService[0] = initializeCommandService(e4Context);
}
});
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
ContextManager.DEBUG = Policy.DEBUG_CONTEXTS;
contextManager = e4Context.get(ContextManager.class);
}
});
IContextService cxs = ContextInjectionFactory.make(ContextService.class, e4Context);
final IContextService contextService = cxs;
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
contextManager.addContextManagerListener(contextManagerEvent -> {
if (contextManagerEvent.isContextChanged()) {
String id = contextManagerEvent.getContextId();
if (id != null) {
defineBindingTable(id);
}
}
});
EContextService ecs = e4Context.get(EContextService.class);
ecs.activateContext(IContextService.CONTEXT_ID_DIALOG_AND_WINDOW);
}
});
serviceLocator.registerService(IContextService.class, contextService);
final IBindingService[] bindingService = new BindingService[1];
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
BindingManager.DEBUG = Policy.DEBUG_KEY_BINDINGS;
bindingManager = e4Context.get(BindingManager.class);
bindingService[0] = ContextInjectionFactory.make(BindingService.class, e4Context);
}
});
// bindingService[0].readRegistryAndPreferences(commandService[0]);
serviceLocator.registerService(IBindingService.class, bindingService[0]);
final CommandImageManager commandImageManager = new CommandImageManager();
final CommandImageService commandImageService = new CommandImageService(commandImageManager, commandService[0]);
commandImageService.readRegistry();
serviceLocator.registerService(ICommandImageService.class, commandImageService);
final WorkbenchMenuService menuService = new WorkbenchMenuService(serviceLocator, e4Context);
serviceLocator.registerService(IMenuService.class, menuService);
// the service must be registered before it is initialized - its
// initialization uses the service locator to address a dependency on
// the menu service
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
menuService.readRegistry();
}
});
/*
* Phase 2 of the initialization of commands. The source providers that the
* workbench provides are creating and registered with the above services. These
* source providers notify the services when particular pieces of workbench
* state change.
*/
final SourceProviderService sourceProviderService = new SourceProviderService(serviceLocator);
serviceLocator.registerService(ISourceProviderService.class, sourceProviderService);
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
// this currently instantiates all players ... sigh
sourceProviderService.readRegistry();
ISourceProvider[] sourceproviders = sourceProviderService.getSourceProviders();
for (ISourceProvider sp : sourceproviders) {
evaluationService.addSourceProvider(sp);
if (!(sp instanceof ActiveContextSourceProvider)) {
contextService.addSourceProvider(sp);
}
}
}
});
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
// these guys are need to provide the variables they say
// they source
FocusControlSourceProvider focusControl = (FocusControlSourceProvider) sourceProviderService.getSourceProvider(ISources.ACTIVE_FOCUS_CONTROL_ID_NAME);
serviceLocator.registerService(IFocusService.class, focusControl);
menuSourceProvider = (MenuSourceProvider) sourceProviderService.getSourceProvider(ISources.ACTIVE_MENU_NAME);
}
});
/*
* Phase 3 of the initialization of commands. This handles the creation of
* wrappers for legacy APIs. By the time this phase completes, any code trying
* to access commands through legacy APIs should work.
*/
final IHandlerService[] handlerService = new IHandlerService[1];
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
handlerService[0] = new LegacyHandlerService(e4Context);
e4Context.set(IHandlerService.class, handlerService[0]);
handlerService[0].readRegistry();
}
});
workbenchContextSupport = new WorkbenchContextSupport(this, contextManager);
workbenchCommandSupport = new WorkbenchCommandSupport(bindingManager, commandManager, contextManager, handlerService[0]);
initializeCommandResolver();
bindingManager.addBindingManagerListener(bindingManagerListener);
serviceLocator.registerService(ISelectionConversionService.class, new SelectionConversionService());
backForwardListener = createBackForwardListener();
StartupThreading.runWithoutExceptions(new StartupRunnable() {
@Override
public void runWithException() {
getDisplay().addFilter(SWT.MouseDown, backForwardListener);
}
});
}
Aggregations