1 package org.simantics.modeling.tests.commands;
3 import java.util.Collection;
6 import org.simantics.Simantics;
7 import org.simantics.db.Resource;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.layer0.request.ModelInstances;
10 import org.simantics.db.testing.common.CommandSequenceEnvironment;
11 import org.simantics.db.testing.common.WriteCommand;
12 import org.simantics.diagram.elements.DiagramNodeUtil;
13 import org.simantics.diagram.stubs.DiagramResource;
14 import org.simantics.g2d.canvas.ICanvasContext;
16 public class ActivateProfile extends WriteCommand<CommandSequenceEnvironment> {
18 private LoadDiagram diagram;
19 private String profileName;
20 private Collection<Resource> entries;
22 public ActivateProfile(LoadDiagram diagram, String profileName, Collection<Resource> entries) {
23 this.diagram = diagram;
24 this.profileName = profileName;
25 this.entries = entries;
29 public void run(CommandSequenceEnvironment environment) throws DatabaseException {
31 ICanvasContext ctx = diagram.getContext();
33 Resource runtime = DiagramNodeUtil.getRuntime(ctx);
35 DiagramResource DIA = DiagramResource.getInstance(Simantics.getSession());
37 Map<String, Resource> profiles = Simantics.getSession().sync(new ModelInstances(diagram.getResource(), DIA.Profile));
38 Resource profile = profiles.get(profileName);
40 DiagramNodeUtil.activateProfileWithEntries(runtime, profile, entries);