]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/CreateConnectionPoint.java
43f854fd4b669f91ea83b23816dba6df2e0afc35
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / handlers / CreateConnectionPoint.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.ui.modelBrowser.handlers;
13
14 import java.util.HashSet;
15 import java.util.List;
16 import java.util.Set;
17
18 import org.eclipse.core.commands.AbstractHandler;
19 import org.eclipse.core.commands.ExecutionEvent;
20 import org.eclipse.core.commands.ExecutionException;
21 import org.eclipse.jface.viewers.ISelection;
22 import org.eclipse.ui.handlers.HandlerUtil;
23 import org.simantics.db.Resource;
24 import org.simantics.db.WriteGraph;
25 import org.simantics.db.common.request.WriteRequest;
26 import org.simantics.db.exception.DatabaseException;
27 import org.simantics.db.layer0.SelectionHints;
28 import org.simantics.modeling.flags.LiftFlag;
29 import org.simantics.ui.SimanticsUI;
30 import org.simantics.utils.ui.ISelectionUtils;
31
32 /**
33  * See <a href="https://www.simantics.org/wiki/index.php/Modeling_ontology#Creating_connection_points}">Creating connection points</a>
34  * 
35  * @author Hannu Niemistö
36  */
37 public class CreateConnectionPoint extends AbstractHandler {
38
39     private static List<Resource> getFlagResource(ISelection sel) {
40         return ISelectionUtils.getPossibleKeys(sel, SelectionHints.KEY_MAIN, Resource.class);
41     }
42
43     @Override
44     public Object execute(ExecutionEvent event) throws ExecutionException {
45         ISelection sel = HandlerUtil.getCurrentSelection(event);
46         List<Resource> flags = getFlagResource(sel);
47         if (flags.isEmpty())
48             return null;
49         final Set<Resource> flagSet = new HashSet<Resource>(flags);
50
51         SimanticsUI.getSession().asyncRequest(new WriteRequest() {
52             @Override
53             public void perform(WriteGraph g) throws DatabaseException {
54                 for (Resource flag : flagSet)
55                     LiftFlag.liftFlag(g, flag);
56             }
57         });
58
59         return null;
60     }
61     
62 }
63