X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Fwizard%2FMigrateWizard.java;h=533a4303483689340b26e1878fb885377c1d8743;hp=f0eee752920fad488de5d51018a11b96f2e089e4;hb=a2a42428426818a7498d5a1705603fb8d3a8a95a;hpb=53059ca1a958697cc6235d27628614fbaa944d59 diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/wizard/MigrateWizard.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/wizard/MigrateWizard.java index f0eee7529..533a43034 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/wizard/MigrateWizard.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/wizard/MigrateWizard.java @@ -11,10 +11,7 @@ *******************************************************************************/ package org.simantics.modeling.ui.wizard; -import gnu.trove.map.hash.THashMap; -import gnu.trove.set.hash.THashSet; -import gnu.trove.set.hash.TIntHashSet; - +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -22,6 +19,10 @@ import java.util.Comparator; import java.util.Map; import java.util.Set; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubMonitor; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.dialogs.IDialogSettings; @@ -44,7 +45,6 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.List; @@ -64,6 +64,7 @@ import org.simantics.db.common.request.UniqueRead; import org.simantics.db.common.request.WriteResultRequest; import org.simantics.db.common.utils.Logger; import org.simantics.db.common.utils.Versions; +import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.layer0.Layer0; @@ -78,6 +79,10 @@ import org.simantics.utils.datastructures.Pair; import org.simantics.utils.datastructures.Triple; import org.simantics.utils.strings.AlphanumComparator; +import gnu.trove.map.hash.THashMap; +import gnu.trove.set.hash.THashSet; +import gnu.trove.set.hash.TIntHashSet; + /** * @author Antti Villberg */ @@ -129,7 +134,7 @@ public class MigrateWizard extends Wizard { Collection ops = migratePage.model.sortedShownInstances; int index = 0; - final ArrayList result = new ArrayList(); + final ArrayList result = new ArrayList<>(); for(MigrationOperation op : ops) { if(sels.contains(index)) result.add(op); index++; @@ -138,58 +143,80 @@ public class MigrateWizard extends Wizard { if(result.isEmpty()) return true; try { - - final String report = Simantics.getSession().syncRequest(new WriteResultRequest() { - @Override - public String perform(WriteGraph graph) throws DatabaseException { - graph.markUndoPoint(); - String report = UserComponentMigration.doMigration(graph, result); - UserComponentMigration.doPostMigration(graph, result); - return report; + String[] report = { null }; + getContainer().run(true, true, monitor -> { + SubMonitor mon = SubMonitor.convert(monitor, 1000); + try { + report[0] = Simantics.getSession().syncRequest(new WriteResultRequest() { + @Override + public String perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + String report = UserComponentMigration.doMigration(mon.newChild(500, SubMonitor.SUPPRESS_NONE), graph, result); + UserComponentMigration.doPostMigration(mon.newChild(500, SubMonitor.SUPPRESS_NONE), graph, result); + mon.setTaskName("Committing Changes"); + mon.subTask(""); + return report; + } + }); + } catch (DatabaseException e) { + throw new InvocationTargetException(e); + } finally { + monitor.done(); } }); - class InfoMessageDialog extends MessageDialog { - - public InfoMessageDialog(Shell shell) { - super(shell, - "Migration report", null, - "", - MessageDialog.INFORMATION, new String[] { "Continue" }, 0); - } - - @Override - protected boolean isResizable() { - return true; - } - - @Override - protected Point getInitialSize() { - return new Point(800, 500); - } - - @Override - protected Control createCustomArea(Composite composite) { - - GridLayoutFactory.fillDefaults().applyTo(composite); - Text text = new Text(composite, SWT.MULTI | SWT.V_SCROLL | SWT.READ_ONLY | SWT.BORDER); - text.setText(report); - GridDataFactory.fillDefaults().grab(true, true).applyTo(text); - return composite; - - } - - } - - InfoMessageDialog md = new InfoMessageDialog(Display.getCurrent().getActiveShell()); - md.open(); - - - } catch (DatabaseException e) { - Logger.defaultLogError(e); - } - - return true; + + ReportDialog md = new ReportDialog(getShell(), report[0], 800, 500); + md.open(); + + return true; + } catch (InvocationTargetException e) { + // Don't show user cancellations as errors. + Throwable cause = e.getCause(); + if (!(cause instanceof CancelTransactionException || cause instanceof OperationCanceledException)) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, + "Migration failed, see Error Log for details.", e.getCause())); + } + } catch (InterruptedException e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, + "Migration interrupted, see Error Log for details.", e)); + } + return false; + } + + static class ReportDialog extends MessageDialog { + private final String report; + private final int initialWidth; + private final int initialHeight; + + public ReportDialog(Shell shell, String report, int width, int height) { + super(shell, + "Migration report", null, + "", + MessageDialog.INFORMATION, new String[] { "Continue" }, 0); + this.report = report; + this.initialWidth = width; + this.initialHeight = height; + } + + @Override + protected boolean isResizable() { + return true; + } + + @Override + protected Point getInitialSize() { + return new Point(initialWidth, initialHeight); + } + + @Override + protected Control createCustomArea(Composite composite) { + GridLayoutFactory.fillDefaults().applyTo(composite); + Text text = new Text(composite, SWT.MULTI | SWT.V_SCROLL | SWT.READ_ONLY | SWT.BORDER); + text.setText(report); + GridDataFactory.fillDefaults().grab(true, true).applyTo(text); + return composite; + } } abstract static class SelectionAdapter implements SelectionListener { @@ -414,7 +441,7 @@ public class MigrateWizard extends Wizard { result.add(new NamedResource(name, symbol)); } - return new ArrayList(result); + return new ArrayList<>(result); } @@ -556,7 +583,7 @@ public class MigrateWizard extends Wizard { int locationIndex = locations.getSelectionIndex(); if(locationIndex == -1) return; - model.sortedShownInstances = new ArrayList(); + model.sortedShownInstances = new ArrayList<>(); for(MigrationOperation o : model.instances.get(locationIndex).third) model.sortedShownInstances.add(o); Collections.sort(model.sortedShownInstances, MIGRATION_OP_COMPARATOR);