X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Factions%2FSwitchComponentTypeContribution.java;h=d8115f53e432396d166973d5f3bc25432bd7f3ba;hb=47269fe0acb894f346810417d950a1ab59cdc0ea;hp=61e81194e33d8fa2c0b880bc1c00f59f22b798ab;hpb=f43fbe51d130e91cc05e5cd6632f33456b6b94c7;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/SwitchComponentTypeContribution.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/SwitchComponentTypeContribution.java index 61e81194e..d8115f53e 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/SwitchComponentTypeContribution.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/SwitchComponentTypeContribution.java @@ -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); @@ -70,7 +86,7 @@ public class SwitchComponentTypeContribution extends ContributionItem { try { groups = Simantics.getSession().syncRequest(new ComponentSwitchGroupQuery(resource)); } catch (DatabaseException e) { - LOGGER.error("Retrieval of switch groups failed.", e); + LOGGER.error("Retrieval of switch groups failed.", e); //$NON-NLS-1$ return; } @@ -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)); } }); } @@ -133,7 +160,7 @@ public class SwitchComponentTypeContribution extends ContributionItem { if(label == null) { label = graph.getPossibleRelatedValue(group, L0.HasName); if(label == null) - label = "Alternative types"; + label = Messages.SwitchComponentTypeContribution_AlternativeTypes; } groupObj = new SwitchGroup(label); }