00a48ec537aca90ef3a80f95112033c888ed91ee
[taxeditor.git] / eu.etaxonomy.taxeditor.application / src / main / java / eu / etaxonomy / taxeditor / ApplicationWorkbenchWindowAdvisor.java
1 package eu.etaxonomy.taxeditor;
2
3 import org.eclipse.core.runtime.IStatus;
4 import org.eclipse.equinox.internal.p2.core.Activator;
5 import org.eclipse.equinox.p2.core.IProvisioningAgent;
6 import org.eclipse.equinox.p2.core.IProvisioningAgentProvider;
7 import org.eclipse.equinox.p2.core.ProvisionException;
8 import org.eclipse.swt.graphics.Point;
9 import org.eclipse.swt.widgets.Shell;
10 import org.eclipse.ui.application.ActionBarAdvisor;
11 import org.eclipse.ui.application.IActionBarConfigurer;
12 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
13 import org.eclipse.ui.application.WorkbenchWindowAdvisor;
14 import org.osgi.framework.ServiceReference;
15
16 import eu.etaxonomy.taxeditor.model.MessagingUtils;
17 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
18 import eu.etaxonomy.taxeditor.store.CdmStore;
19 import eu.etaxonomy.taxeditor.ui.dialog.LoginDialog;
20
21 /**
22 * <p>ApplicationWorkbenchWindowAdvisor class.</p>
23 *
24 * @author n.hoffmann
25 * @version $Id: $
26 */
27 public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
28
29 /**
30 * <p>Constructor for ApplicationWorkbenchWindowAdvisor.</p>
31 *
32 * @param configurer a {@link org.eclipse.ui.application.IWorkbenchWindowConfigurer} object.
33 */
34 public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
35 super(configurer);
36 }
37
38 /** {@inheritDoc} */
39 public ActionBarAdvisor createActionBarAdvisor(
40 IActionBarConfigurer configurer) {
41 return new ApplicationActionBarAdvisor(configurer);
42 }
43
44 /**
45 * <p>preWindowOpen</p>
46 */
47 public void preWindowOpen() {
48 IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
49 configurer.setInitialSize(new Point(963, 637));
50 configurer.setShowCoolBar(true);
51 configurer.setShowStatusLine(true);
52 configurer.setShowPerspectiveBar(true);
53 configurer.setTitle("EDIT Taxonomic Editor");
54 configurer.setShowProgressIndicator(true);
55 }
56
57 /**
58 * <p>postWindowOpen</p>
59 */
60 public void postWindowOpen() {
61 PreferencesUtil.checkNomenclaturalCode();
62
63 if(PreferencesUtil.shouldConnectAtStartUp())
64 CdmStore.connect();
65
66 // automaticUpdate();
67
68 }
69
70 private int authenticate(){
71 Shell shell = TaxonomicEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
72
73 LoginDialog loginDialog = new LoginDialog(shell);
74 return loginDialog.open();
75 }
76
77 private void automaticUpdate(){
78
79 ServiceReference sr = Activator.context.getServiceReference(IProvisioningAgentProvider.SERVICE_NAME);
80 IProvisioningAgentProvider agentProvider = null;
81 if (sr == null)
82 return;
83 agentProvider = (IProvisioningAgentProvider) Activator.context.getService(sr);
84 IProvisioningAgent agent = null;
85 try {
86 agent = agentProvider.createAgent(null);//new URI("file:/Applications/eclipse36/p2"));
87 if (agent == null) {
88 MessagingUtils.error(this.getClass(), "No provisioning agent found. This application is not set up for updates.", null);
89 return;
90 }
91
92 IStatus status = P2Util.checkForUpdates(agent, null);
93
94 MessagingUtils.info(status);
95 } catch (ProvisionException e) {
96 MessagingUtils.error(getClass(), e);
97 } finally {
98 if(agent != null) agent.stop();
99 }
100 }
101 }
102