1 package org.simantics.workbench.internal.contributions.search;
4 import org.eclipse.core.expressions.Expression;
5 import org.eclipse.ui.IWorkbench;
6 import org.eclipse.ui.IWorkbenchPartSite;
7 import org.eclipse.ui.IWorkbenchWindow;
8 import org.eclipse.ui.internal.expressions.ActivePartExpression;
9 import org.eclipse.ui.internal.expressions.WorkbenchWindowExpression;
10 import org.eclipse.ui.internal.services.IWorkbenchLocationService;
11 import org.eclipse.ui.services.AbstractServiceFactory;
12 import org.eclipse.ui.services.IServiceLocator;
13 import org.simantics.workbench.search.ISearchService;
15 public class SearchServiceFactory extends AbstractServiceFactory {
18 @SuppressWarnings("rawtypes")
20 public Object create(Class serviceInterface, IServiceLocator parentLocator,
21 IServiceLocator locator) {
22 if (!ISearchService.class.equals(serviceInterface))
24 IWorkbenchLocationService wls = (IWorkbenchLocationService) locator
25 .getService(IWorkbenchLocationService.class);
26 final IWorkbench wb = wls.getWorkbench();
31 Object parent = parentLocator.getService(serviceInterface);
33 return new SearchServiceImpl();
35 final IWorkbenchWindow window = wls.getWorkbenchWindow();
36 final IWorkbenchPartSite site = wls.getPartSite();
38 Expression exp = new WorkbenchWindowExpression(window);
39 return new SlaveSearchService((ISearchService)parent, exp);
41 if (parent instanceof SlaveSearchService) {
42 Expression parentExp = ((SlaveSearchService) parent).getDefaultExpression();
43 return new NestableSearchService((ISearchService)parent, parentExp);
46 Expression exp = new ActivePartExpression(site.getPart());
47 return new SlaveSearchService((ISearchService)parent, exp);