View Javadoc
1   package org.argeo.connect.e4;
2   
3   import java.util.Collections;
4   import java.util.Map;
5   import java.util.SortedMap;
6   import java.util.TreeMap;
7   
8   import org.argeo.connect.ServiceRanking;
9   import org.argeo.connect.ui.AppWorkbenchService;
10  import org.argeo.connect.ui.SystemWorkbenchService;
11  import org.eclipse.e4.core.contexts.ContextFunction;
12  import org.eclipse.e4.core.contexts.IEclipseContext;
13  
14  public class SystemE4ServiceFunction extends ContextFunction {
15  	// Injected known AppWorkbenchServices: order is important, first found
16  	// result will be returned by the various methods.
17  	private SortedMap<ServiceRanking, AppWorkbenchService> knownAppWbServices = Collections
18  			.synchronizedSortedMap(new TreeMap<>());
19  
20  	@Override
21  	public Object compute(IEclipseContext context, String contextKey) {
22  //		MApplication app = context.get(MApplication.class);
23  //		IEclipseContext appContext = app.getContext();
24  //		EPartService partService = appContext.get(EPartService.class);
25  //		ECommandService commandService = appContext.get(ECommandService.class);
26  //		EHandlerService handlerService = appContext.get(EHandlerService.class);
27  
28  		SystemE4Service systemE4Service = new SystemE4Service(knownAppWbServices, context);
29  
30  		// if (app == null) {// during login
31  		// context.set(SystemWorkbenchService.class, systemE4Service);
32  		// } else {// regular use case
33  		// IEclipseContext appCtx = app.getContext();
34  		// if (appCtx != null)
35  		// appCtx.set(SystemWorkbenchService.class, systemE4Service);
36  		// else
37  		// context.set(SystemWorkbenchService.class, systemE4Service);
38  		// }
39  		context.set(SystemWorkbenchService.class, systemE4Service);
40  		return systemE4Service;
41  	}
42  
43  	public void addAppService(AppWorkbenchService appService, Map<String, Object> properties) {
44  		// String serviceRankingStr = properties.get(Constants.SERVICE_RANKING);
45  		// int serviceRanking = serviceRankingStr == null ? 0 :
46  		// Integer.parseInt(serviceRankingStr);
47  		// Integer serviceRanking = (Integer) properties.get(Constants.SERVICE_RANKING);
48  		// System.out.println(serviceRanking + " | " + properties);
49  		knownAppWbServices.put(new ServiceRanking(properties), appService);
50  	}
51  
52  	public void removeAppService(AppWorkbenchService appService, Map<String, Object> properties) {
53  		knownAppWbServices.remove(new ServiceRanking(properties));
54  	}
55  
56  }