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.Collections;
16 import org.eclipse.core.commands.AbstractHandler;
17 import org.eclipse.core.commands.ExecutionEvent;
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.ui.handlers.HandlerUtil;
21 import org.simantics.db.Resource;
22 import org.simantics.db.WriteGraph;
23 import org.simantics.db.common.request.WriteRequest;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.issues.common.IssueUtils;
26 import org.simantics.issues.ontology.IssueResource;
27 import org.simantics.modeling.ModelingResources;
28 import org.simantics.ui.SimanticsUI;
29 import org.simantics.utils.ui.AdaptionUtils;
30 public class CreateIssue extends AbstractHandler {
32 private static Resource getResource(ISelection sel) {
33 Resource r = AdaptionUtils.adaptToSingle(sel, Resource.class);
38 public Object execute(ExecutionEvent event) throws ExecutionException {
40 ISelection sel = HandlerUtil.getCurrentSelection(event);
41 final Resource element = getResource(sel);
45 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
47 public void perform(WriteGraph graph) throws DatabaseException {
49 IssueResource ISSUE = IssueResource.getInstance(graph);
51 Resource resource = graph.getPossibleObject(element, ModelingResources.getInstance(graph).ElementToComponent);
52 if(resource == null) return;
54 IssueUtils.newUserIssueForModel(graph, resource, "New User Issue", ISSUE.Severity_Note, Collections.singletonList(resource));