]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.workbench/src/org/simantics/workbench/internal/SimanticsWorkbenchAdvisor.java
Merge "Easier baselines"
[simantics/platform.git] / bundles / org.simantics.workbench / src / org / simantics / workbench / internal / SimanticsWorkbenchAdvisor.java
index bce220c9c3ae24fb64f8248766f0dce4956c1f8f..8a8b493753e3be04b14156483ba9f4df63dba9a8 100644 (file)
@@ -82,22 +82,24 @@ import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog;
 import org.eclipse.ui.keys.IBindingService;
 import org.eclipse.ui.progress.IProgressService;
 import org.eclipse.ui.statushandlers.AbstractStatusHandler;
+import org.eclipse.ui.statushandlers.StatusAdapter;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.Version;
 import org.simantics.CancelStartupException;
+import org.simantics.DatabaseBaselines;
 import org.simantics.PlatformException;
 import org.simantics.Simantics;
 import org.simantics.SimanticsPlatform;
 import org.simantics.SimanticsPlatform.OntologyRecoveryPolicy;
 import org.simantics.SimanticsPlatform.RecoveryPolicy;
+import org.simantics.TimingProgressMonitor;
+import org.simantics.UnhandledExceptionService;
 import org.simantics.application.arguments.IArguments;
 import org.simantics.application.arguments.SimanticsArguments;
 import org.simantics.db.common.Indexing;
 import org.simantics.db.indexing.DatabaseIndexing;
-import org.simantics.db.procore.server.environment.RebootRequiredException;
-import org.simantics.db.procore.server.environment.windows.Product;
-import org.simantics.internal.TimedSessionCache;
 import org.simantics.project.IProject;
 import org.simantics.project.ProjectKeys;
 import org.simantics.ui.SimanticsUI;
@@ -105,7 +107,6 @@ import org.simantics.ui.jobs.SessionGarbageCollectorJob;
 import org.simantics.ui.workbench.PerspectiveBarsActivator;
 import org.simantics.ui.workbench.PerspectiveContextActivator;
 import org.simantics.utils.logging.TimeLogger;
-import org.simantics.utils.threads.ThreadUtils;
 import org.simantics.utils.ui.dialogs.ShowError;
 import org.simantics.utils.ui.dialogs.ShowMessage;
 import org.slf4j.Logger;
@@ -341,12 +342,6 @@ public class SimanticsWorkbenchAdvisor extends WorkbenchAdvisor {
                 // Start the database garbage collector after a short while.
                 SessionGarbageCollectorJob.getInstance().scheduleAfterQuietTime();
 
-                // Discard database session undo history at this point to prevent
-                // the user from undoing any initialization operations performed
-                // by the platform startup.
-                SimanticsPlatform.INSTANCE.discardSessionUndoHistory();
-                TimeLogger.log("Discarded session undo history");
-
                 // #6353: Workaround for  
                 fixBindings();
 
@@ -415,6 +410,7 @@ public class SimanticsWorkbenchAdvisor extends WorkbenchAdvisor {
 
             if (args.contains(SimanticsArguments.DO_NOT_SYNCHRONIZE_ONTOLOGIES)) {
                 requireSynchronize = false;
+                ontologyPolicy = OntologyRecoveryPolicy.Bypass;
             }
             
             if (args.contains(SimanticsArguments.DISABLE_INDEX)) {
@@ -436,6 +432,11 @@ public class SimanticsWorkbenchAdvisor extends WorkbenchAdvisor {
             if (PROFILE_PLATFORM_STARTUP)
                 mon = new TimingProgressMonitor();
             SimanticsPlatform.INSTANCE.startUp(databaseDriverId, mon, workspacePolicy, ontologyPolicy, requireSynchronize, new JFaceUserAgent());
+            if(DatabaseBaselines.shouldCreateAutomaticBaseline(SimanticsPlatform.INSTANCE.databaseExists() != null)) {
+                SimanticsPlatform.INSTANCE.shutdown(null);
+                DatabaseBaselines.createAutomaticBaseline(SimanticsPlatform.INSTANCE.dbLocation());
+                SimanticsPlatform.INSTANCE.reconnect(Simantics.getDefaultDatabaseDriver());
+            }
 
             // Make sure that the default perspective comes from the project if
             // the project has set ProjectKeys#DEFAULT_PERSPECTIVE.
@@ -471,19 +472,7 @@ public class SimanticsWorkbenchAdvisor extends WorkbenchAdvisor {
             return false;
         } catch (Exception e) {
             log.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
-
-            Throwable cause = e.getCause();
-            if (cause instanceof RebootRequiredException) {
-                RebootRequiredException rre = (RebootRequiredException) cause;
-                StringBuilder msg = new StringBuilder();
-                msg.append("The application must be restarted after installing the following products:\n");
-                for (Product product : rre.products)
-                    msg.append("\t" + product + "\n");
-                msg.append("\nThe application will now close.");
-                MessageDialog.openInformation(null, "Restart Required", msg.toString());
-            } else {
-                new ShowError("Platform Startup Failed", "Simantics Platform startup failed:\n\n" + e.getMessage(), e, true);
-            }
+            new ShowError("Platform Startup Failed", "Simantics Platform startup failed:\n\n" + e.getMessage(), e, true);
             return false;
         }
 
@@ -741,29 +730,13 @@ public class SimanticsWorkbenchAdvisor extends WorkbenchAdvisor {
             try {
                 try {
                     progress.subTask("Platform");
-                    SimanticsPlatform.INSTANCE.shutdown(progress.newChild(50));
+                    SimanticsPlatform.INSTANCE.shutdown(progress.newChild(100));
                 } catch (PlatformException e) {
                     Activator.logError("Problems encountered while shutting down Simantics platform, see exception for details.", e);
                 }
 
                 progress.subTask("Remaining database connections");
                 SimanticsUI.closeSessions();
-                progress.worked(20);
-                TimedSessionCache.close();
-                progress.worked(20);
-
-                progress.subTask("Thread pools");
-                ThreadUtils.shutdown();
-                progress.worked(5);
-
-                progress.subTask("Clear index status");
-                try {
-                    // Everything ok, clear index dirty state.
-                    DatabaseIndexing.clearAllDirty();
-                } catch (IOException e) {
-                    Activator.logError("Problems encountered while refreshing database index states, see exception for details.", e);
-                }
-                progress.worked(5);
 
                 progress.setWorkRemaining(0);
             } finally {
@@ -870,7 +843,7 @@ public class SimanticsWorkbenchAdvisor extends WorkbenchAdvisor {
         }
 
         if (perspectiveId == null) {
-            IProject project = SimanticsUI.peekProject();
+            IProject project = Simantics.peekProject();
             if (project != null)
                 perspectiveId = project.getHint(ProjectKeys.DEFAULT_PERSPECTIVE);
         }
@@ -1169,17 +1142,17 @@ public class SimanticsWorkbenchAdvisor extends WorkbenchAdvisor {
      *         location is not being shown
      */
     public String getWorkspaceLocation() {
-               // read command line, which has priority
-               IEclipseContext context = getWorkbenchConfigurer().getWorkbench().getService(IEclipseContext.class);
-               String location = context != null ? (String) context.get(E4Workbench.FORCED_SHOW_LOCATION) : null;
-               if (location != null) {
-                       return location;
-               }
-               // read the preference
-               if (IDEWorkbenchPlugin.getDefault().getPreferenceStore().getBoolean(IDEInternalPreferences.SHOW_LOCATION)) {
-                       return Platform.getLocation().toOSString();
-               }
-               return null;
+        // read command line, which has priority
+        IEclipseContext context = getWorkbenchConfigurer().getWorkbench().getService(IEclipseContext.class);
+        String location = context != null ? (String) context.get(E4Workbench.FORCED_SHOW_LOCATION) : null;
+        if (location != null) {
+            return location;
+        }
+        // read the preference
+        if (IDEWorkbenchPlugin.getDefault().getPreferenceStore().getBoolean(IDEInternalPreferences.SHOW_LOCATION)) {
+            return Platform.getLocation().toOSString();
+        }
+        return null;
     }
 
     /**
@@ -1211,13 +1184,30 @@ public class SimanticsWorkbenchAdvisor extends WorkbenchAdvisor {
      *
      * @see org.eclipse.ui.application.WorkbenchAdvisor#getWorkbenchErrorHandler()
      */
+
+    private AbstractStatusHandler workbenchErrorHandler = new AbstractStatusHandler() {
+
+        @Override
+        public void handle(StatusAdapter statusAdapter, int style) {
+            if (ideWorkbenchErrorHandler == null) {
+                ideWorkbenchErrorHandler = new IDEWorkbenchErrorHandler(
+                        getWorkbenchConfigurer());
+            }
+            ideWorkbenchErrorHandler.handle(statusAdapter, style);
+
+            BundleContext context = Activator.getDefault().getBundle().getBundleContext();
+            ServiceReference<?> ref = context.getServiceReference(UnhandledExceptionService.class.getName());
+            UnhandledExceptionService unhandled = (UnhandledExceptionService)context.getService(ref);
+            Throwable t = statusAdapter.getStatus().getException();
+            if(t != null)
+                unhandled.handle(t);
+
+        }
+    };
+
     @Override
     public AbstractStatusHandler getWorkbenchErrorHandler() {
-        if (ideWorkbenchErrorHandler == null) {
-            ideWorkbenchErrorHandler = new IDEWorkbenchErrorHandler(
-                    getWorkbenchConfigurer());
-        }
-        return ideWorkbenchErrorHandler;
+        return workbenchErrorHandler;
     }
 
     /* (non-Javadoc)