Merge branch 'release/5.18.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.application / src / main / java / eu / etaxonomy / taxeditor / ApplicationWorkbenchWindowAdvisor.java
1 package eu.etaxonomy.taxeditor;
2
3 import java.util.List;
4
5 import org.eclipse.e4.ui.model.application.ui.basic.MTrimElement;
6 import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement;
7 import org.eclipse.e4.ui.model.application.ui.menu.impl.ToolBarImpl;
8 import org.eclipse.swt.graphics.Point;
9 import org.eclipse.ui.IWorkbenchWindow;
10 import org.eclipse.ui.PlatformUI;
11 import org.eclipse.ui.application.ActionBarAdvisor;
12 import org.eclipse.ui.application.IActionBarConfigurer;
13 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
14 import org.eclipse.ui.application.WorkbenchWindowAdvisor;
15 import org.eclipse.ui.internal.WorkbenchWindow;
16
17 import eu.etaxonomy.taxeditor.handler.update.P2Util;
18 import eu.etaxonomy.taxeditor.util.ApplicationUtil;
19
20 /**
21 * @author n.hoffmann
22 */
23 public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
24
25 public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
26 super(configurer);
27 }
28
29 @Override
30 public ActionBarAdvisor createActionBarAdvisor(
31 IActionBarConfigurer configurer) {
32 return new ApplicationActionBarAdvisor(configurer);
33 }
34
35 @Override
36 public void preWindowOpen() {
37 IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
38 configurer.setInitialSize(new Point(1280, 720));
39 configurer.setShowCoolBar(true);
40 configurer.setShowStatusLine(true);
41 configurer.setShowPerspectiveBar(true);
42 configurer.setTitle(ApplicationUtil.getTitle());
43 configurer.setShowProgressIndicator(true);
44
45 // CdmDataSourceRepository.createDefaultH2DataSource();
46 }
47
48 @Override
49 public void postWindowOpen() {
50 IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
51
52 List<MTrimElement> elements = ((WorkbenchWindow) workbenchWindow).getTopTrim().getChildren();
53 for (MTrimElement item : elements) {
54 if (item instanceof ToolBarImpl){
55 ToolBarImpl toolBar = (ToolBarImpl)item;
56 List<MToolBarElement> children = toolBar.getChildren();
57 for (MToolBarElement element: children){
58 if (element.getElementId().equals("eu.etaxonomy.taxeditor.workbench.menu.toolbar.new")) {
59 element.setVisible(false);
60 }
61 }
62 }
63 }
64
65 P2Util.setP2UpdateRepositories();
66 // TODO: think about how to implement this with
67 // if(PreferencesUtil.shouldConnectAtStartUp()) {
68 // CdmStore.connect();
69 // }
70 }
71
72 @Override
73 public void postWindowClose() {
74 P2Util.saveP2RepositoryPreferences();
75 }
76 }