performed javacscript:fix and worked on documentation
[taxeditor.git] / 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.helpers.ServiceHelper;
5 import org.eclipse.equinox.p2.core.IProvisioningAgent;
6 import org.eclipse.equinox.p2.operations.ProvisioningJob;
7 import org.eclipse.equinox.p2.operations.ProvisioningSession;
8 import org.eclipse.equinox.p2.operations.UpdateOperation;
9 import org.eclipse.jface.dialogs.MessageDialog;
10 import org.eclipse.swt.graphics.Point;
11 import org.eclipse.swt.widgets.Shell;
12 import org.eclipse.ui.PlatformUI;
13 import org.eclipse.ui.application.ActionBarAdvisor;
14 import org.eclipse.ui.application.IActionBarConfigurer;
15 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
16 import org.eclipse.ui.application.WorkbenchWindowAdvisor;
17
18 import eu.etaxonomy.taxeditor.dialogs.LoginDialog;
19 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20 import eu.etaxonomy.taxeditor.store.CdmStore;
21
22 /**
23 * <p>ApplicationWorkbenchWindowAdvisor class.</p>
24 *
25 * @author n.hoffmann
26 * @version $Id: $
27 */
28 public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
29
30 /**
31 * <p>Constructor for ApplicationWorkbenchWindowAdvisor.</p>
32 *
33 * @param configurer a {@link org.eclipse.ui.application.IWorkbenchWindowConfigurer} object.
34 */
35 public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
36 super(configurer);
37 }
38
39 /** {@inheritDoc} */
40 public ActionBarAdvisor createActionBarAdvisor(
41 IActionBarConfigurer configurer) {
42 return new ApplicationActionBarAdvisor(configurer);
43 }
44
45 /**
46 * <p>preWindowOpen</p>
47 */
48 public void preWindowOpen() {
49 IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
50 configurer.setInitialSize(new Point(963, 637));
51 configurer.setShowCoolBar(true);
52 configurer.setShowStatusLine(true);
53 configurer.setShowPerspectiveBar(true);
54 configurer.setTitle("EDIT Taxonomic Editor");
55 configurer.setShowProgressIndicator(true);
56 }
57
58 /**
59 * <p>postWindowOpen</p>
60 */
61 public void postWindowOpen() {
62 PreferencesUtil.checkNomenclaturalCode();
63
64 if(PreferencesUtil.shouldConnectAtStartUp())
65 CdmStore.connect();
66
67 automaticUpdate();
68
69 }
70
71 private int authenticate(){
72 Shell shell = TaxonomicEditorPlugin.getDefault().getWorkbench()
73 .getActiveWorkbenchWindow().getShell();
74
75 LoginDialog loginDialog = new LoginDialog(shell);
76 return loginDialog.open();
77 }
78
79 private void automaticUpdate(){
80 final IProvisioningAgent agent = (IProvisioningAgent) ServiceHelper.getService(TaxonomicEditorPlugin.bundleContext,
81 IProvisioningAgent.SERVICE_NAME);
82 if (agent == null) {
83 ApplicationUtil.error(this.getClass(), "No provisioning agent found. This application is not set up for updates.", null);
84 return;
85 }
86
87 //StoreUtil.warningDialog("Updates", "Searching for updates");
88 // check for updates before starting up.
89 // If an update is performed, restart. Otherwise log
90 // the status.
91
92
93
94
95 // IRunnableWithProgress runnable = new IRunnableWithProgress() {
96 // public void run(IProgressMonitor monitor)
97 // throws InvocationTargetException, InterruptedException {
98 //
99 UpdateOperation operation = null;
100 try{
101 ProvisioningSession session = new ProvisioningSession(agent);
102
103
104 // the default update operation looks for updates to the currently
105 // running profile, using the default profile root marker. To change
106 // which installable units are being updated, use the more detailed
107 // constructors.
108 operation = new UpdateOperation(session);
109 // SubMonitor sub = SubMonitor.convert(monitor,
110 // "Checking for application updates...", 200);
111 IStatus status = operation.resolveModal(null);//sub.newChild(100));
112
113 if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
114 PlatformUI.getWorkbench().getDisplay()
115 .asyncExec(new Runnable() {
116 public void run() {
117 MessageDialog.openInformation(null,
118 "Updates", "No updates were found");
119 }
120 });
121 }
122 if (status.getSeverity() == IStatus.CANCEL){
123 ApplicationUtil.info(status);
124 // throw new OperationCanceledException();
125 }
126
127 if (status.getSeverity() != IStatus.ERROR) {
128 // More complex status handling might include showing the user what updates
129 // are available if there are multiples, differentiating patches vs. updates, etc.
130 // In this example, we simply update as suggested by the operation.
131 ProvisioningJob job = operation.getProvisioningJob(null);
132
133 if(job == null){
134 ApplicationUtil.info(status);
135 // StoreUtil.warningDialog("Updates", status.toString());
136 return;
137 // throw new OperationCanceledException();
138 }
139
140 status = job.runModal(null);//sub.newChild(100));
141 if (status.getSeverity() == IStatus.CANCEL){
142 ApplicationUtil.info(status);
143 // throw new OperationCanceledException();
144 }
145 }
146
147 // StoreUtil.warningDialog("Performing update", "");
148
149 // StoreUtil.warningDialog("Updates", status.toString());
150
151 }catch(Exception e){
152 ApplicationUtil.error(this.getClass(), e);
153 }
154 }
155
156 // };
157 // try {
158 // new ProgressMonitorDialog(null).run(true, true, runnable);
159 // } catch (InvocationTargetException e) {
160 // e.printStackTrace();
161 // } catch (InterruptedException e) {
162 // }
163
164 }
165
166