1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 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.event.view.handler;
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.Simantics;
24 import org.simantics.db.Resource;
25 import org.simantics.db.Session;
26 import org.simantics.db.VirtualGraph;
27 import org.simantics.db.WriteGraph;
28 import org.simantics.db.common.request.WriteRequest;
29 import org.simantics.db.common.utils.Logger;
30 import org.simantics.db.exception.DatabaseException;
31 import org.simantics.db.layer0.SelectionHints;
32 import org.simantics.db.service.VirtualGraphSupport;
33 import org.simantics.event.ontology.EventResource;
34 import org.simantics.layer0.Layer0;
35 import org.simantics.utils.ui.ISelectionUtils;
39 * @author Tuukka Lehtonen
41 public class Delete extends AbstractHandler {
43 protected final String virtualGraphId;
46 virtualGraphId = "experiments";
50 public Object execute(ExecutionEvent event) throws ExecutionException {
51 Session session = Simantics.peekSession();
54 ISelection selection = HandlerUtil.getCurrentSelection(event);
55 final List<Resource> resources = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
56 final VirtualGraph vg = virtualGraphId == null ? null :
57 session.getService(VirtualGraphSupport.class).getWorkspacePersistent(virtualGraphId);
59 session.asyncRequest(new WriteRequest(vg) {
61 public void perform(WriteGraph graph) throws DatabaseException {
62 Layer0 L0 = Layer0.getInstance(graph);
63 EventResource EVENT = EventResource.getInstance(graph);
64 Set<Resource> eventLogs = new HashSet<Resource>();
65 for (Resource event : resources) {
66 if (graph.isInstanceOf(event, EVENT.Event)) {
67 Resource slice = graph.getPossibleObject(event, L0.PartOf);
69 Resource eventlog = graph.getPossibleObject(slice, L0.PartOf);
70 if (eventlog != null) eventLogs.add(eventlog);
75 for (Resource eventlog : eventLogs) {
76 if (graph.isInstanceOf(eventlog, EVENT.EventLog))
77 graph.syncRequest( new CorrectMilestoneLabelsAction(eventlog, vg) );
81 if (e != null) Logger.defaultLogError(e);