1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.event.view.handler;
\r
14 import java.util.HashSet;
\r
15 import java.util.List;
\r
16 import java.util.Set;
\r
18 import org.eclipse.core.commands.AbstractHandler;
\r
19 import org.eclipse.core.commands.ExecutionEvent;
\r
20 import org.eclipse.core.commands.ExecutionException;
\r
21 import org.eclipse.jface.viewers.ISelection;
\r
22 import org.eclipse.ui.handlers.HandlerUtil;
\r
23 import org.simantics.Simantics;
\r
24 import org.simantics.db.Resource;
\r
25 import org.simantics.db.Session;
\r
26 import org.simantics.db.VirtualGraph;
\r
27 import org.simantics.db.WriteGraph;
\r
28 import org.simantics.db.common.request.WriteRequest;
\r
29 import org.simantics.db.common.utils.Logger;
\r
30 import org.simantics.db.exception.DatabaseException;
\r
31 import org.simantics.db.layer0.SelectionHints;
\r
32 import org.simantics.db.service.VirtualGraphSupport;
\r
33 import org.simantics.event.ontology.EventResource;
\r
34 import org.simantics.layer0.Layer0;
\r
35 import org.simantics.utils.datastructures.Callback;
\r
36 import org.simantics.utils.ui.ISelectionUtils;
\r
40 * @author Tuukka Lehtonen
\r
42 public class Delete extends AbstractHandler {
\r
44 protected final String virtualGraphId;
\r
47 virtualGraphId = "experiments";
\r
51 public Object execute(ExecutionEvent event) throws ExecutionException {
\r
52 Session session = Simantics.peekSession();
\r
53 if (session == null)
\r
55 ISelection selection = HandlerUtil.getCurrentSelection(event);
\r
56 final List<Resource> resources = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
\r
57 final VirtualGraph vg = virtualGraphId == null ? null :
\r
58 session.getService(VirtualGraphSupport.class).getWorkspacePersistent(virtualGraphId);
\r
60 session.asyncRequest(new WriteRequest(vg) {
\r
62 public void perform(WriteGraph graph) throws DatabaseException {
\r
63 Layer0 L0 = Layer0.getInstance(graph);
\r
64 EventResource EVENT = EventResource.getInstance(graph);
\r
65 Set<Resource> eventLogs = new HashSet<Resource>();
\r
66 for (Resource event : resources) {
\r
67 if (graph.isInstanceOf(event, EVENT.Event)) {
\r
68 Resource slice = graph.getPossibleObject(event, L0.PartOf);
\r
70 Resource eventlog = graph.getPossibleObject(slice, L0.PartOf);
\r
71 if (eventlog != null) eventLogs.add(eventlog);
\r
74 graph.deny( event );
\r
76 for (Resource eventlog : eventLogs) {
\r
77 if (graph.isInstanceOf(eventlog, EVENT.EventLog))
\r
78 graph.syncRequest( new CorrectMilestoneLabelsAction(eventlog, vg) );
\r
81 }, new Callback<DatabaseException>() {
\r
83 public void run(DatabaseException e) {
\r
84 if (e != null) Logger.defaultLogError(e);
\r