merge-update from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.application / src / main / java / eu / etaxonomy / taxeditor / ApplicationWorkbenchWindowAdvisor.java
index 72ee9adf8745b16ba8e6c9cd280c9f85daed2aa1..a4d2e6816dc5452ab1f36ae1b54eeadeb5d4852f 100644 (file)
@@ -1,21 +1,17 @@
 package eu.etaxonomy.taxeditor;
 
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.equinox.internal.p2.core.Activator;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.core.IProvisioningAgentProvider;
-import org.eclipse.equinox.p2.core.ProvisionException;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.application.ActionBarAdvisor;
 import org.eclipse.ui.application.IActionBarConfigurer;
 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
 import org.eclipse.ui.application.WorkbenchWindowAdvisor;
-import org.osgi.framework.ServiceReference;
 
+import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.ui.dialogs.LoginDialog;
+import eu.etaxonomy.taxeditor.ui.dialog.LoginDialog;
+import eu.etaxonomy.taxeditor.update.P2Util;
 
 /**
  * <p>ApplicationWorkbenchWindowAdvisor class.</p>
@@ -35,7 +31,8 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
        }
 
        /** {@inheritDoc} */
-       public ActionBarAdvisor createActionBarAdvisor(
+       @Override
+    public ActionBarAdvisor createActionBarAdvisor(
                        IActionBarConfigurer configurer) {
                return new ApplicationActionBarAdvisor(configurer);
        }
@@ -43,60 +40,49 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
        /**
         * <p>preWindowOpen</p>
         */
-       public void preWindowOpen() {
+       @Override
+    public void preWindowOpen() {
                IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
                configurer.setInitialSize(new Point(963, 637));
                configurer.setShowCoolBar(true);
                configurer.setShowStatusLine(true);
                configurer.setShowPerspectiveBar(true);
-               configurer.setTitle("EDIT Taxonomic Editor");
+               configurer.setTitle("EDIT Taxonomic Editor " + ApplicationUtil.getVersion());
                configurer.setShowProgressIndicator(true);
+
+               CdmDataSourceRepository.createDefaultH2DataSource();
        }
 
        /**
         * <p>postWindowOpen</p>
         */
-       public void postWindowOpen() { 
+       @Override
+    public void postWindowOpen() {
                PreferencesUtil.checkNomenclaturalCode();
 
-               if(PreferencesUtil.shouldConnectAtStartUp())
-                       CdmStore.connect();
 
-//             automaticUpdate();
+
+               if(PreferencesUtil.shouldConnectAtStartUp()) {
+            CdmStore.connect();
+        }
+
+               P2Util.setP2UpdateRepositories();
 
        }
 
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowClose()
+        */
+       @Override
+    public void postWindowClose() {
+        P2Util.saveP2RepositoryPreferences();
+    }
+
        private int authenticate(){
-               Shell shell = TaxonomicEditorPlugin.getDefault().getWorkbench()
-               .getActiveWorkbenchWindow().getShell();
+               Shell shell = TaxonomicEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
 
                LoginDialog loginDialog = new LoginDialog(shell);
                return loginDialog.open();
        }
-
-       private void automaticUpdate(){
-
-               ServiceReference sr = Activator.context.getServiceReference(IProvisioningAgentProvider.SERVICE_NAME);
-               IProvisioningAgentProvider agentProvider = null;
-               if (sr == null)
-                       return;
-               agentProvider = (IProvisioningAgentProvider) Activator.context.getService(sr);
-               IProvisioningAgent agent = null;
-               try {
-                       agent = agentProvider.createAgent(null);//new URI("file:/Applications/eclipse36/p2"));
-                       if (agent == null) {
-                               ApplicationUtil.error(this.getClass(), "No provisioning agent found. This application is not set up for updates.", null);
-                               return;
-                       }
-
-                       IStatus status = P2Util.checkForUpdates(agent, null);
-
-                       ApplicationUtil.info(status);
-               } catch (ProvisionException e) {
-                       ApplicationUtil.error(getClass(), e);
-               } finally {
-                       if(agent != null) agent.stop();
-               }
-       }
 }