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.preference.PreferencesUtil;
|
17
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
18
|
import eu.etaxonomy.taxeditor.ui.dialogs.LoginDialog;
|
19
|
|
20
|
/**
|
21
|
* <p>ApplicationWorkbenchWindowAdvisor class.</p>
|
22
|
*
|
23
|
* @author n.hoffmann
|
24
|
* @version $Id: $
|
25
|
*/
|
26
|
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
|
27
|
|
28
|
/**
|
29
|
* <p>Constructor for ApplicationWorkbenchWindowAdvisor.</p>
|
30
|
*
|
31
|
* @param configurer a {@link org.eclipse.ui.application.IWorkbenchWindowConfigurer} object.
|
32
|
*/
|
33
|
public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
|
34
|
super(configurer);
|
35
|
}
|
36
|
|
37
|
/** {@inheritDoc} */
|
38
|
public ActionBarAdvisor createActionBarAdvisor(
|
39
|
IActionBarConfigurer configurer) {
|
40
|
return new ApplicationActionBarAdvisor(configurer);
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* <p>preWindowOpen</p>
|
45
|
*/
|
46
|
public void preWindowOpen() {
|
47
|
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
|
48
|
configurer.setInitialSize(new Point(963, 637));
|
49
|
configurer.setShowCoolBar(true);
|
50
|
configurer.setShowStatusLine(true);
|
51
|
configurer.setShowPerspectiveBar(true);
|
52
|
configurer.setTitle("EDIT Taxonomic Editor");
|
53
|
configurer.setShowProgressIndicator(true);
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* <p>postWindowOpen</p>
|
58
|
*/
|
59
|
public void postWindowOpen() {
|
60
|
PreferencesUtil.checkNomenclaturalCode();
|
61
|
|
62
|
if(PreferencesUtil.shouldConnectAtStartUp())
|
63
|
CdmStore.connect();
|
64
|
|
65
|
// automaticUpdate();
|
66
|
|
67
|
}
|
68
|
|
69
|
private int authenticate(){
|
70
|
Shell shell = TaxonomicEditorPlugin.getDefault().getWorkbench()
|
71
|
.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
|
ApplicationUtil.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
|
ApplicationUtil.info(status);
|
95
|
} catch (ProvisionException e) {
|
96
|
ApplicationUtil.error(getClass(), e);
|
97
|
} finally {
|
98
|
if(agent != null) agent.stop();
|
99
|
}
|
100
|
}
|
101
|
}
|
102
|
|