]> gerrit.simantics Code Review - simantics/3d.git/blob
37cd717d0310ff8a793481e4d868f99ba6ddc730
[simantics/3d.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.processeditor.actions;\r
12 \r
13 import java.util.List;\r
14 \r
15 import org.simantics.db.Graph;\r
16 import org.simantics.db.GraphRequestStatus;\r
17 import org.simantics.db.Resource;\r
18 import org.simantics.layer0.utils.EntityFactory;\r
19 import org.simantics.layer0.utils.IEntity;\r
20 import org.simantics.processeditor.ProcessResource;\r
21 import org.simantics.processeditor.common.PipingTools2;\r
22 import org.simantics.processeditor.stubs.PipelineComponent;\r
23 import org.simantics.proconf.g3d.actions.WriteAction;\r
24 import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;\r
25 \r
26 \r
27 \r
28 public class ReversePipelineAction extends WriteAction {\r
29         \r
30         public ReversePipelineAction(ThreeDimensionalEditorBase parent) {\r
31                 super(parent,false);\r
32         }\r
33 \r
34         @Override\r
35         public boolean usable(Graph graph, List<Resource> resources) {\r
36                 if (resources.size() != 1)\r
37                         return false;\r
38                 IEntity t = EntityFactory.create(graph, resources.get(0));\r
39                 return (t.isInstanceOf(ProcessResource.plant3Dresource.PipelineComponent));\r
40         }\r
41         \r
42         @Override\r
43         public GraphRequestStatus doChanges(Graph graph) throws Exception {\r
44                 Resource r = parent.getSelectionAdapter().getSelectedResources().get(0);\r
45                 PipelineComponent comp = new PipelineComponent(graph, r);\r
46                 PipingTools2.reversePipeRun(PipingTools2.getPipeRun(comp));\r
47 \r
48                 return GraphRequestStatus.transactionComplete();\r
49         }\r
50 \r
51         \r
52         @Override\r
53         public void init() {\r
54                 this.setText("Reverse pipeline");\r
55         }\r
56 \r
57 }\r