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;
&& ((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()));
+ }
+
}
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
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;
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;
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;
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 {
}
});
-
ReportDialog md = new ReportDialog(getShell(), report[0], 800, 500);
md.open();
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;