1 /*******************************************************************************
2 * Copyright (c) 2015 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 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.diagramEditor.handlers;
14 import java.util.ArrayList;
17 import org.eclipse.core.commands.AbstractHandler;
18 import org.eclipse.core.commands.ExecutionEvent;
19 import org.eclipse.core.commands.ExecutionException;
20 import org.eclipse.core.runtime.IProgressMonitor;
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.core.runtime.Status;
23 import org.eclipse.core.runtime.jobs.Job;
24 import org.eclipse.jface.viewers.ISelection;
25 import org.eclipse.ui.handlers.HandlerUtil;
26 import org.simantics.DatabaseJob;
27 import org.simantics.db.Resource;
28 import org.simantics.db.WriteGraph;
29 import org.simantics.db.common.request.WriteRequest;
30 import org.simantics.db.exception.DatabaseException;
31 import org.simantics.modeling.actions.DisconnectFlag;
32 import org.simantics.modeling.ui.Activator;
33 import org.simantics.ui.SimanticsUI;
34 import org.simantics.utils.ui.ISelectionUtils;
37 * @author Tuukka Lehtonen
39 public class DisconnectFlagHandler extends AbstractHandler {
42 public Object execute(ExecutionEvent event) throws ExecutionException {
43 ISelection sel = HandlerUtil.getCurrentSelection(event);
44 final Set<Resource> resources = ISelectionUtils.filterSetSelection(sel, Resource.class);
45 if (resources.isEmpty())
48 Job job = new DatabaseJob("Disconnect Flags") {
50 protected IStatus run(IProgressMonitor monitor) {
52 SimanticsUI.getSession().syncRequest(new WriteRequest() {
54 public void perform(WriteGraph graph) throws DatabaseException {
55 graph.markUndoPoint();
56 DisconnectFlag.disconnectFlags(graph, new ArrayList<>(resources));
59 return Status.OK_STATUS;
60 } catch (DatabaseException e) {
61 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to disconnect flags.", e);