Project

General

Profile

Download (3.39 KB) Statistics
| Branch: | Tag: | Revision:
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.swt.widgets.Shell;
10
import org.eclipse.ui.IWorkbenchWindow;
11
import org.eclipse.ui.PlatformUI;
12
import org.eclipse.ui.application.ActionBarAdvisor;
13
import org.eclipse.ui.application.IActionBarConfigurer;
14
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
15
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
16
import org.eclipse.ui.internal.WorkbenchWindow;
17

    
18
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
19
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
21
import eu.etaxonomy.taxeditor.ui.dialog.LoginDialog;
22
import eu.etaxonomy.taxeditor.update.P2Util;
23
import eu.etaxonomy.taxeditor.util.ApplicationUtil;
24

    
25
/**
26
 * <p>ApplicationWorkbenchWindowAdvisor class.</p>
27
 *
28
 * @author n.hoffmann
29
 * @version $Id: $
30
 */
31
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
32

    
33
	/**
34
	 * <p>Constructor for ApplicationWorkbenchWindowAdvisor.</p>
35
	 *
36
	 * @param configurer a {@link org.eclipse.ui.application.IWorkbenchWindowConfigurer} object.
37
	 */
38
	public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
39
		super(configurer);
40
	}
41

    
42
	/** {@inheritDoc} */
43
	@Override
44
    public ActionBarAdvisor createActionBarAdvisor(
45
			IActionBarConfigurer configurer) {
46
		return new ApplicationActionBarAdvisor(configurer);
47
	}
48

    
49
	/**
50
	 * <p>preWindowOpen</p>
51
	 */
52
	@Override
53
    public void preWindowOpen() {
54
		IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
55
		configurer.setInitialSize(new Point(963, 637));
56
		configurer.setShowCoolBar(true);
57
		configurer.setShowStatusLine(true);
58
		configurer.setShowPerspectiveBar(true);
59
		configurer.setTitle(ApplicationUtil.getTitle());
60
		configurer.setShowProgressIndicator(true);
61

    
62
		CdmDataSourceRepository.createDefaultH2DataSource();
63
	}
64

    
65
	/**
66
	 * <p>postWindowOpen</p>
67
	 */
68
	@Override
69
    public void postWindowOpen() {
70
	    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
71

    
72
	    List<MTrimElement> elements =  ((WorkbenchWindow) workbenchWindow).getTopTrim().getChildren();
73
	    for (MTrimElement item : elements) {
74
	        if (item instanceof ToolBarImpl){
75
	            ToolBarImpl toolBar = (ToolBarImpl)item;
76
	            List<MToolBarElement> children = toolBar.getChildren();
77
	            for (MToolBarElement element: children){
78
	                if (element.getElementId().equals("eu.etaxonomy.taxeditor.workbench.menu.toolbar.new")) {
79
	                    element.setVisible(false);
80
	                }
81
	            }
82
	        }
83

    
84
        }
85
		PreferencesUtil.checkNomenclaturalCode();
86

    
87
		if(PreferencesUtil.shouldConnectAtStartUp()) {
88
            CdmStore.connect();
89
        }
90

    
91
		P2Util.setP2UpdateRepositories();
92

    
93
	}
94

    
95
	/* (non-Javadoc)
96
	 * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowClose()
97
	 */
98
	@Override
99
    public void postWindowClose() {
100
        P2Util.saveP2RepositoryPreferences();
101
    }
102

    
103
	private int authenticate(){
104
		Shell shell = TaxonomicEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
105

    
106
		LoginDialog loginDialog = new LoginDialog(shell);
107
		return loginDialog.open();
108
	}
109
}
110

    
(4-4/8)