1 package org.simantics.modeling.ui.actions;
3 import java.util.Collections;
6 import org.eclipse.core.runtime.IProgressMonitor;
7 import org.eclipse.ui.PlatformUI;
8 import org.simantics.db.Resource;
9 import org.simantics.db.WriteGraph;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.diagram.synchronization.runtime.DiagramSelectionUpdater;
12 import org.simantics.g2d.canvas.ICanvasContext;
13 import org.simantics.modeling.flags.MergeFlags;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
18 * @author Hannu Niemistö
19 * @author Tuukka Lehtonen
21 public class MergeFlagsHandler extends FlagOperationHandler {
23 private static final Logger LOGGER = LoggerFactory.getLogger(MergeFlagsHandler.class);
24 protected void perform(IProgressMonitor monitor, WriteGraph graph, List<Resource> flags, ICanvasContext canvasContext) throws DatabaseException {
25 monitor.beginTask(Messages.MergeFlagsHandler_MonitorMergeSelectedFlags, IProgressMonitor.UNKNOWN);
26 performMerge(graph, flags, canvasContext);
29 public static void performMerge(WriteGraph graph, List<Resource> flags, ICanvasContext canvasContext) throws DatabaseException {
30 final String text = MergeFlags.validateForMerge(graph, flags);
33 PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
36 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
37 .getActiveEditor().getEditorSite().getActionBars().getStatusLineManager()
38 .setErrorMessage(text);
43 String result = MergeFlags.merge(graph, flags);
44 if(result != null && !result.isEmpty()) {
45 LOGGER.error(result); // Should not happen because of prevalidation
47 if (canvasContext != null) {
48 // Make sure the diagram selection is set to the
49 // merged flag after the merge.
50 new DiagramSelectionUpdater( canvasContext )
51 .setNewSelection(0, Collections.singleton( flags.get(0) ))