]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Reinitialize visible diagrams after shared library migration 64/1864/5
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 20 Jun 2018 06:28:07 +0000 (09:28 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 20 Jun 2018 08:02:42 +0000 (08:02 +0000)
gitlab #28

Change-Id: Ie3f8f5c90ed98490e2f03f1c955995d30b9a3923

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramEditor.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/wizard/MigrateWizard.java

index 7734ce7145f60dc20ba7b27c21a769a7b36ab17a..60dc7f5991854a62706aadde0157b4d71cc50e76 100644 (file)
@@ -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 <code>diagrams</code> as their input.
+     * 
+     * <p>Must be invoked from the SWT thread.</p>
+     * 
+     * @param diagrams
+     *            collection of diagram resources for which to reinitialize all DiagramEditors
+     *            for
+     */
+    public static void reinitializeDiagram(Set<Resource> diagrams) {
+        reinitializeDiagram(input -> input instanceof IResourceEditorInput
+                && diagrams.contains(((IResourceEditorInput) input).getResource()));
+    }
+
 }
index 59c478e0d55f70408237bc23227ae1ee677c1dbc..14386190c53b0a89e873582c16445acef8cf9ce0 100644 (file)
@@ -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<Resource> diagramsToReopen = Simantics.getSession().syncRequest(
+                            (Read<Set<Resource>>) 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<Resource> componentsToDiagrams(ReadGraph graph, Collection<MigrationOperation> ops) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        ModelingResources MOD = ModelingResources.getInstance(graph);
+        Set<Resource> 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;