From: jsimomaa Date: Wed, 20 Jun 2018 06:28:07 +0000 (+0300) Subject: Reinitialize visible diagrams after shared library migration X-Git-Tag: v1.43.0~136^2~458 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F64%2F1864%2F5;p=simantics%2Fplatform.git Reinitialize visible diagrams after shared library migration gitlab #28 Change-Id: Ie3f8f5c90ed98490e2f03f1c955995d30b9a3923 --- diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramEditor.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramEditor.java index 7734ce714..60dc7f599 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramEditor.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramEditor.java @@ -13,6 +13,7 @@ package org.simantics.modeling.ui.diagramEditor; import java.lang.reflect.Constructor; +import java.util.Set; import java.util.function.Predicate; import org.eclipse.core.runtime.IConfigurationElement; @@ -433,4 +434,19 @@ public class DiagramEditor extends EditorPart implements IResourceEditorPart2, I && ((IResourceEditorInput) input).getResource().equals(diagram)); } + /** + * Reinitializes all DiagramEditor instances in all workbench windows that have + * the specified diagrams as their input. + * + *

Must be invoked from the SWT thread.

+ * + * @param diagrams + * collection of diagram resources for which to reinitialize all DiagramEditors + * for + */ + public static void reinitializeDiagram(Set diagrams) { + reinitializeDiagram(input -> input instanceof IResourceEditorInput + && diagrams.contains(((IResourceEditorInput) input).getResource())); + } + } 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 59c478e0d..14386190c 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 @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -59,6 +60,7 @@ import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.NamedResource; import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.request.UnaryRead; import org.simantics.db.common.request.UniqueRead; import org.simantics.db.common.request.WriteResultRequest; @@ -66,6 +68,7 @@ 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.db.request.Read; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.layer0.Layer0; import org.simantics.modeling.MigrateModel; @@ -73,11 +76,13 @@ import org.simantics.modeling.MigrateModel.MigrationOperation; import org.simantics.modeling.ModelingResources; import org.simantics.modeling.UserComponentMigration; import org.simantics.modeling.ui.Activator; +import org.simantics.modeling.ui.diagramEditor.DiagramEditor; import org.simantics.structural.stubs.StructuralResource2; import org.simantics.ui.workbench.dialogs.ResourceSelectionDialog3; import org.simantics.utils.datastructures.Pair; import org.simantics.utils.datastructures.Triple; import org.simantics.utils.strings.AlphanumComparator; +import org.simantics.utils.ui.SWTUtils; import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; @@ -158,6 +163,14 @@ public class MigrateWizard extends Wizard { return report; } }); + + // Schedule diagram reinitialization to see actual migration changes + // This needs to be done because the diagram editor can't currently + // refresh itself after type (InstanceOf) changes in diagram elements. + Set diagramsToReopen = Simantics.getSession().syncRequest( + (Read>) graph -> componentsToDiagrams(graph, ops)); + SWTUtils.asyncExec(MigrateWizard.this.getContainer().getShell().getDisplay(), + () -> DiagramEditor.reinitializeDiagram(diagramsToReopen)); } catch (DatabaseException e) { throw new InvocationTargetException(e); } finally { @@ -165,7 +178,6 @@ public class MigrateWizard extends Wizard { } }); - ReportDialog md = new ReportDialog(getShell(), report[0], 800, 500); md.open(); @@ -184,6 +196,21 @@ public class MigrateWizard extends Wizard { return false; } + private static final Set componentsToDiagrams(ReadGraph graph, Collection ops) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + ModelingResources MOD = ModelingResources.getInstance(graph); + Set diagrams = new HashSet<>(); + for (MigrationOperation op : ops) { + Resource composite = graph.getPossibleObject(op.instanceToMigrate.getResource(), L0.PartOf); + if (composite != null) { + Resource diagram = graph.getPossibleObject(composite, MOD.CompositeToDiagram); + if (diagram != null) + diagrams.add(diagram); + } + } + return diagrams; + } + static class ReportDialog extends MessageDialog { private final String report; private final int initialWidth;