]> gerrit.simantics Code Review - simantics/platform.git/blob
76ea9607b72857f52493b8a9c1c84b5aab6fcb53
[simantics/platform.git] /
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.Collections;
15
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 {
31
32     private static Resource getResource(ISelection sel) {
33         Resource r = AdaptionUtils.adaptToSingle(sel, Resource.class);
34         return r;
35     }
36
37     @Override
38     public Object execute(ExecutionEvent event) throws ExecutionException {
39         
40         ISelection sel = HandlerUtil.getCurrentSelection(event);
41         final Resource element = getResource(sel);
42         if (element == null)
43             return null;
44
45         SimanticsUI.getSession().asyncRequest(new WriteRequest() {
46             @Override
47             public void perform(WriteGraph graph) throws DatabaseException {
48                 
49                 IssueResource ISSUE = IssueResource.getInstance(graph);
50                                 
51                 Resource resource = graph.getPossibleObject(element, ModelingResources.getInstance(graph).ElementToComponent);
52                 if(resource == null) return;
53                 
54                                 IssueUtils.newUserIssueForModel(graph, resource, "New User Issue", ISSUE.Severity_Note, Collections.singletonList(resource));
55                 
56             }
57         });
58
59         return null;
60     }
61
62 }
63