1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.modelBrowser.handlers;
14 import java.util.HashSet;
15 import java.util.List;
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;
33 * See <a href="https://www.simantics.org/wiki/index.php/Modeling_ontology#Creating_connection_points}">Creating connection points</a>
35 * @author Hannu Niemistö
37 public class CreateConnectionPoint extends AbstractHandler {
39 private static List<Resource> getFlagResource(ISelection sel) {
40 return ISelectionUtils.getPossibleKeys(sel, SelectionHints.KEY_MAIN, Resource.class);
44 public Object execute(ExecutionEvent event) throws ExecutionException {
45 ISelection sel = HandlerUtil.getCurrentSelection(event);
46 List<Resource> flags = getFlagResource(sel);
49 final Set<Resource> flagSet = new HashSet<Resource>(flags);
51 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
53 public void perform(WriteGraph g) throws DatabaseException {
54 for (Resource flag : flagSet)
55 LiftFlag.liftFlag(g, flag);