]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/SwitchComponentTypeContribution.java
(refs #7568) Reinitialize diagram editor when element is switched
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / actions / SwitchComponentTypeContribution.java
index 61e81194e33d8fa2c0b880bc1c00f59f22b798ab..193334e0b67789699358ebfee44d61b940cf0749 100644 (file)
@@ -1,6 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 2017 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:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
 package org.simantics.modeling.ui.actions;
 
-
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -21,11 +31,17 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.layer0.Layer0;
 import org.simantics.modeling.MigrateModel;
 import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.ui.diagramEditor.DiagramEditor;
 import org.simantics.structural.stubs.StructuralResource2;
 import org.simantics.ui.utils.ResourceAdaptionUtils;
+import org.simantics.utils.ui.SWTUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * @author Hannu Niemistö
+ * @since 1.31.0
+ */
 public class SwitchComponentTypeContribution extends ContributionItem {
     private static final Logger LOGGER = LoggerFactory.getLogger(SwitchComponentTypeContribution.class);
     
@@ -82,7 +98,18 @@ public class SwitchComponentTypeContribution extends ContributionItem {
                     Simantics.getSession().asyncRequest(new WriteRequest() {
                         @Override
                         public void perform(WriteGraph graph) throws DatabaseException {
-                            MigrateModel.changeComponentType(graph, elementToComponent(graph, resource), newComponentType);
+                            Resource component = elementToComponent(graph, resource);
+                            MigrateModel.changeComponentType(graph, component, newComponentType);
+
+                            Layer0 L0 = Layer0.getInstance(graph);
+                            Resource composite = graph.getPossibleObject(component, L0.PartOf);
+                            if (composite == null)
+                                return;
+                            ModelingResources MOD = ModelingResources.getInstance(graph);
+                            Resource diagram = graph.getPossibleObject(composite, MOD.CompositeToDiagram);
+                            if (diagram == null)
+                                return;
+                            SWTUtils.asyncExec(menu, () -> DiagramEditor.reinitializeDiagram(diagram));
                         }
                     });
                 }