]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.team.ui/src/org/simantics/team/ui/handlers/SynchroniseAllHandler.java
Removed contact application support prints
[simantics/platform.git] / bundles / org.simantics.team.ui / src / org / simantics / team / ui / handlers / SynchroniseAllHandler.java
index 7a1a586ceb26bdd93cc036c4ef510b425423d3f8..6463ccbb2f58808c217643c342f6e7e3ecc2ffe8 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.team.ui.handlers;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.nio.charset.Charset;\r
-\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.core.runtime.NullProgressMonitor;\r
-import org.eclipse.core.runtime.Platform;\r
-import org.eclipse.jface.dialogs.MessageDialog;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.ServerReference;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.service.LifecycleSupport;\r
-import org.simantics.db.service.TeamSupport;\r
-import org.simantics.team.Activator;\r
-import org.simantics.team.Utils;\r
-import org.simantics.team.internal.StagingLauncher;\r
-import org.simantics.team.internal.StagingLauncher.Config;\r
-import org.simantics.team.internal.StagingLauncher.StagingResult;\r
-import org.simantics.team.ui.StageInitWizard;\r
-import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.workbench.handler.AbstractPreferenceHandler;\r
-import org.simantics.utils.FileUtils;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-import org.simantics.utils.ui.dialogs.ShowError;\r
-\r
-public class SynchroniseAllHandler extends AbstractPreferenceHandler {\r
-\r
-    public SynchroniseAllHandler() {\r
-        super(Activator.getDefault());\r
-    }\r
-    @Override\r
-    public Object execute(ExecutionEvent event) throws ExecutionException {\r
-        System.out.println("DEBUG: SynchronizeAllHandler");\r
-//        ISelection sel = HandlerUtil.getCurrentSelection(event);\r
-//        IStructuredSelection ss = StructuredSelection.EMPTY;\r
-//        if (sel instanceof IStructuredSelection)\r
-//            ss = (IStructuredSelection) sel;\r
-        try {\r
-            Session session = SimanticsUI.getSession();\r
-            File wsFolder = new File(Platform.getInstanceLocation().getURL().getFile());\r
-            File stFolder = new File(wsFolder, "staging");\r
-            File teamFolder = pullAll(session, Utils.getTeamFolder(), stFolder);\r
-            if (null == teamFolder)\r
-                return null; // User cancelled operation.\r
-            show(session, teamFolder, stFolder);\r
-        } catch (DatabaseException e) {\r
-            ShowError.showError("Staging In.", "Staging failed", e);\r
-        }\r
-        return null;\r
-    }\r
-    static File pullAll(Session session, File teamFolder, File stFolder)\r
-    throws DatabaseException {\r
-        File dbFolder = new File(stFolder, "db");\r
-        try {\r
-            FileUtils.deleteAll(dbFolder);\r
-            File tempFolder = new File(stFolder, "temp");\r
-            FileUtils.deleteAll(tempFolder);\r
-            File indexingFolder = new File(stFolder, ".metadata/.plugins/org.simantics.db.indexing");\r
-            FileUtils.deleteAll(indexingFolder);\r
-            File procoreFolder = new File(stFolder, "metadata/.plugins/org.simantics.db.procore");\r
-            FileUtils.deleteAll(procoreFolder);\r
-        } catch (IOException e) {\r
-            throw new DatabaseException("Pull failed.", e);\r
-        }\r
-        if (null == teamFolder || !teamFolder.isDirectory()) {\r
-            final StageInitWizard.Data data = new StageInitWizard.Data(stFolder, null);\r
-            data.requireExisting = true;\r
-            if (!StageInitWizard.openInitWizard(data)) {\r
-                Utils.setTeamFolder(null);\r
-                return null; // User cancelled the operation.\r
-            }\r
-            teamFolder = data.teamFolder;\r
-            assert(null != teamFolder);\r
-        }\r
-        TeamSupport ts = session.getService(TeamSupport.class);\r
-        ts.pull(teamFolder, dbFolder);\r
-        return teamFolder;\r
-    }\r
-    static void show(Session session, File teamFolder, File wsFolder) {\r
-        final IProgressMonitor monitor = new NullProgressMonitor();\r
-        try {\r
-            monitor.beginTask("begin", 1300);\r
-            LifecycleSupport lfs = session.getService(LifecycleSupport.class);\r
-            ServerReference sref = lfs.getSessionReference().getServerReference();\r
-//            SerialisationSupport ss = session.getService(SerialisationSupport.class);\r
-            String randomAccessId = "target"; // String.valueOf(ss.getRandomAccessId(target));\r
-            Resource targetLibrary = null;\r
-            final Config config = new Config(session, targetLibrary, wsFolder, teamFolder);\r
-            config.titlePrefix = wsFolder.getName();\r
-            StagingResult result = StagingLauncher.launch(config, sref.toString(), randomAccessId);\r
-            if (result.getExitValue() != 0) {\r
-                String msg = "";\r
-                if (result.getLogFile().exists()) {\r
-                    byte[] data = FileUtils.readFile(result.getLogFile());\r
-                    msg = new String(data, Charset.defaultCharset());\r
-                }\r
-                if (msg.isEmpty() || msg.matches(" *"))\r
-                    msg = "Staging crashed and burned. Contact application support.";\r
-                ShowError.showError("Staging failed, errorcode="+result.getExitValue(), msg, new Exception());\r
-            }\r
-            if (result.getMessageLog() != null) {\r
-                MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(),\r
-                        "Staging failed",\r
-                        result.getMessageLog());\r
-            }\r
-            } catch (Exception e) {\r
-                ErrorLogger.defaultLogError(e);\r
-            } finally {\r
-                monitor.done();\r
-            }\r
-    }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.team.ui.handlers;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.ui.PlatformUI;
+import org.simantics.db.Resource;
+import org.simantics.db.ServerReference;
+import org.simantics.db.Session;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.service.LifecycleSupport;
+import org.simantics.db.service.TeamSupport;
+import org.simantics.team.Activator;
+import org.simantics.team.Utils;
+import org.simantics.team.internal.StagingLauncher;
+import org.simantics.team.internal.StagingLauncher.Config;
+import org.simantics.team.internal.StagingLauncher.StagingResult;
+import org.simantics.team.ui.StageInitWizard;
+import org.simantics.ui.SimanticsUI;
+import org.simantics.ui.workbench.handler.AbstractPreferenceHandler;
+import org.simantics.utils.FileUtils;
+import org.simantics.utils.ui.ErrorLogger;
+import org.simantics.utils.ui.dialogs.ShowError;
+
+public class SynchroniseAllHandler extends AbstractPreferenceHandler {
+
+    public SynchroniseAllHandler() {
+        super(Activator.getDefault());
+    }
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        System.out.println("DEBUG: SynchronizeAllHandler");
+//        ISelection sel = HandlerUtil.getCurrentSelection(event);
+//        IStructuredSelection ss = StructuredSelection.EMPTY;
+//        if (sel instanceof IStructuredSelection)
+//            ss = (IStructuredSelection) sel;
+        try {
+            Session session = SimanticsUI.getSession();
+            File wsFolder = new File(Platform.getInstanceLocation().getURL().getFile());
+            File stFolder = new File(wsFolder, "staging");
+            File teamFolder = pullAll(session, Utils.getTeamFolder(), stFolder);
+            if (null == teamFolder)
+                return null; // User cancelled operation.
+            show(session, teamFolder, stFolder);
+        } catch (DatabaseException e) {
+            ShowError.showError("Staging In.", "Staging failed", e);
+        }
+        return null;
+    }
+    static File pullAll(Session session, File teamFolder, File stFolder)
+    throws DatabaseException {
+        File dbFolder = new File(stFolder, "db");
+        try {
+            FileUtils.deleteAll(dbFolder);
+            File tempFolder = new File(stFolder, "temp");
+            FileUtils.deleteAll(tempFolder);
+            File indexingFolder = new File(stFolder, ".metadata/.plugins/org.simantics.db.indexing");
+            FileUtils.deleteAll(indexingFolder);
+            File procoreFolder = new File(stFolder, "metadata/.plugins/org.simantics.db.procore");
+            FileUtils.deleteAll(procoreFolder);
+        } catch (IOException e) {
+            throw new DatabaseException("Pull failed.", e);
+        }
+        if (null == teamFolder || !teamFolder.isDirectory()) {
+            final StageInitWizard.Data data = new StageInitWizard.Data(stFolder, null);
+            data.requireExisting = true;
+            if (!StageInitWizard.openInitWizard(data)) {
+                Utils.setTeamFolder(null);
+                return null; // User cancelled the operation.
+            }
+            teamFolder = data.teamFolder;
+            assert(null != teamFolder);
+        }
+        TeamSupport ts = session.getService(TeamSupport.class);
+        ts.pull(teamFolder, dbFolder);
+        return teamFolder;
+    }
+    static void show(Session session, File teamFolder, File wsFolder) {
+        final IProgressMonitor monitor = new NullProgressMonitor();
+        try {
+            monitor.beginTask("begin", 1300);
+            LifecycleSupport lfs = session.getService(LifecycleSupport.class);
+            ServerReference sref = lfs.getSessionReference().getServerReference();
+//            SerialisationSupport ss = session.getService(SerialisationSupport.class);
+            String randomAccessId = "target"; // String.valueOf(ss.getRandomAccessId(target));
+            Resource targetLibrary = null;
+            final Config config = new Config(session, targetLibrary, wsFolder, teamFolder);
+            config.titlePrefix = wsFolder.getName();
+            StagingResult result = StagingLauncher.launch(config, sref.toString(), randomAccessId);
+            if (result.getExitValue() != 0) {
+                String msg = "";
+                if (result.getLogFile().exists()) {
+                    byte[] data = FileUtils.readFile(result.getLogFile());
+                    msg = new String(data, Charset.defaultCharset());
+                }
+                if (msg.isEmpty() || msg.matches(" *"))
+                    msg = "Staging crashed and burned.";
+                ShowError.showError("Staging failed, errorcode="+result.getExitValue(), msg, new Exception());
+            }
+            if (result.getMessageLog() != null) {
+                MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
+                        "Staging failed",
+                        result.getMessageLog());
+            }
+            } catch (Exception e) {
+                ErrorLogger.defaultLogError(e);
+            } finally {
+                monitor.done();
+            }
+    }
+}