1 package org.simantics.modeling.ui.diagram;
5 import org.eclipse.core.runtime.CoreException;
6 import org.eclipse.core.runtime.IConfigurationElement;
7 import org.eclipse.core.runtime.IExecutableExtension;
8 import org.eclipse.jface.action.Action;
9 import org.eclipse.jface.action.ActionContributionItem;
10 import org.eclipse.jface.action.IContributionItem;
11 import org.eclipse.jface.resource.ImageDescriptor;
12 import org.simantics.Simantics;
13 import org.simantics.db.ReadGraph;
14 import org.simantics.db.Resource;
15 import org.simantics.db.Statement;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.common.request.IndexRoot;
18 import org.simantics.db.common.request.WriteRequest;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.diagram.stubs.DiagramResource;
21 import org.simantics.modeling.ui.Activator;
22 import org.simantics.scl.commands.Command;
23 import org.simantics.scl.commands.Commands;
24 import org.simantics.ui.contribution.DynamicMenuContribution;
25 import org.simantics.ui.utils.ResourceAdaptionUtils;
28 * @author Tuukka Lehtonen
30 public class ResetProfileMonitorTransformContribution extends DynamicMenuContribution implements IExecutableExtension {
33 ImageDescriptor image = null;
36 public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
37 throws CoreException {
38 if (data instanceof Map<?,?>) {
39 @SuppressWarnings("unchecked")
40 Map<String, String> args = (Map<String, String>) data;
41 name = args.get("name");
42 String imageId = args.get("image");
43 image = Activator.getDefault().getImageRegistry().getDescriptor(imageId);
48 protected Object[] getSelectedObjects() {
49 return ResourceAdaptionUtils.toResources(getSelection());
53 protected IContributionItem[] getContributionItems(ReadGraph graph, final Object[] elements) throws DatabaseException {
54 if (elements.length == 0)
58 DiagramResource DIA = DiagramResource.getInstance(graph);
59 for (Object object : elements) {
60 Resource element = (Resource)object;
61 Statement stm = graph.getPossibleStatement(element, DIA.Element_profileMonitorOffset);
62 if (stm != null && !stm.isAsserted(element)) {
71 return new IContributionItem[] {
72 new ActionContributionItem(new Action(name, image) {
75 Simantics.async(new WriteRequest() {
77 public void perform(WriteGraph graph) throws DatabaseException {
78 Command cmd = Commands.get(graph, "Simantics/Profile/resetProfileMonitorPosition");
79 Resource model = graph.syncRequest(new IndexRoot((Resource)elements[0]));
80 for(Object element : elements)
81 cmd.execute(graph, model, element);