]> gerrit.simantics Code Review - simantics/platform.git/blob
ab386699cd2c1982e4468a5611df21d618ced49b
[simantics/platform.git] /
1 package org.simantics.workbench.internal.contributions.search;
2
3
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;
14
15 public class SearchServiceFactory extends AbstractServiceFactory {
16
17
18         @SuppressWarnings("rawtypes")
19         @Override
20         public Object create(Class serviceInterface, IServiceLocator parentLocator,
21                         IServiceLocator locator) {
22                 if (!ISearchService.class.equals(serviceInterface))
23                         return null;
24                 IWorkbenchLocationService wls = (IWorkbenchLocationService) locator
25                                 .getService(IWorkbenchLocationService.class);
26                 final IWorkbench wb = wls.getWorkbench();
27                 if (wb == null) {
28                         return null;
29                 }
30                 
31                 Object parent = parentLocator.getService(serviceInterface);
32                 if (parent == null) {
33                         return new SearchServiceImpl();
34                 }
35                 final IWorkbenchWindow window = wls.getWorkbenchWindow();
36                 final IWorkbenchPartSite site = wls.getPartSite();
37                 if (site == null) {
38                         Expression exp = new WorkbenchWindowExpression(window);
39                         return new SlaveSearchService((ISearchService)parent, exp);
40                 }
41                 if (parent instanceof SlaveSearchService) {
42                         Expression parentExp = ((SlaveSearchService) parent).getDefaultExpression();
43                         return new NestableSearchService((ISearchService)parent, parentExp);
44                 }
45                 
46                 Expression exp = new ActivePartExpression(site.getPart());
47                 return new SlaveSearchService((ISearchService)parent, exp);
48         }
49
50 }