+/*******************************************************************************
+ * 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;
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);
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));
}
});
}