1 package org.simantics.modeling.ui.actions;
\r
3 import java.util.Collections;
\r
4 import java.util.List;
\r
6 import org.eclipse.core.runtime.IProgressMonitor;
\r
7 import org.eclipse.ui.PlatformUI;
\r
8 import org.simantics.db.Resource;
\r
9 import org.simantics.db.WriteGraph;
\r
10 import org.simantics.db.exception.DatabaseException;
\r
11 import org.simantics.diagram.synchronization.runtime.DiagramSelectionUpdater;
\r
12 import org.simantics.g2d.canvas.ICanvasContext;
\r
13 import org.simantics.modeling.flags.MergeFlags;
\r
16 * @author Hannu Niemistö
\r
17 * @author Tuukka Lehtonen
\r
19 public class MergeFlagsHandler extends FlagOperationHandler {
\r
21 protected void perform(IProgressMonitor monitor, WriteGraph graph, List<Resource> flags, ICanvasContext canvasContext) throws DatabaseException {
\r
22 monitor.beginTask("Merge Selected Flags", IProgressMonitor.UNKNOWN);
\r
23 performMerge(graph, flags, canvasContext);
\r
26 public static void performMerge(WriteGraph graph, List<Resource> flags, ICanvasContext canvasContext) throws DatabaseException {
\r
27 final String text = MergeFlags.validateForMerge(graph, flags);
\r
29 System.err.println(text);
\r
30 PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
\r
33 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
\r
34 .getActiveEditor().getEditorSite().getActionBars().getStatusLineManager()
\r
35 .setErrorMessage(text);
\r
40 String result = MergeFlags.merge(graph, flags);
\r
41 if(result != null && !result.isEmpty()) {
\r
42 System.err.println(result); // Should not happen because of prevalidation
\r
44 if (canvasContext != null) {
\r
45 // Make sure the diagram selection is set to the
\r
46 // merged flag after the merge.
\r
47 new DiagramSelectionUpdater( canvasContext )
\r
48 .setNewSelection(0, Collections.singleton( flags.get(0) ))
\r