X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Factions%2FFlagOperationHandler.java;fp=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Factions%2FFlagOperationHandler.java;h=0208929a52e625b97555f930952822d2cd2c419e;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=c3b7d50000619775aaedd00b7f296caf7bf6ddd7;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/FlagOperationHandler.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/FlagOperationHandler.java index c3b7d5000..0208929a5 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/FlagOperationHandler.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/FlagOperationHandler.java @@ -1,82 +1,82 @@ -package org.simantics.modeling.ui.actions; - -import java.lang.reflect.InvocationTargetException; -import java.util.List; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.handlers.HandlerUtil; -import org.simantics.Simantics; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.CancelTransactionException; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.SelectionHints; -import org.simantics.g2d.canvas.ICanvasContext; -import org.simantics.utils.ui.ExceptionUtils; -import org.simantics.utils.ui.ISelectionUtils; - -/** - * @author Tuukka Lehtonen - */ -public abstract class FlagOperationHandler extends AbstractHandler { - - protected abstract void perform(IProgressMonitor monitor, WriteGraph graph, List flags, - ICanvasContext canvasContext) throws DatabaseException; - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - //System.out.println("mergeFlags"); - ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService() - .getSelection(); - - IWorkbenchPart part = HandlerUtil.getActivePartChecked(event); - final ICanvasContext canvasContext = (ICanvasContext) part.getAdapter(ICanvasContext.class); - - if (selection instanceof IStructuredSelection) { - final List flags = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class); - try { - Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - new ProgressMonitorDialog(shell).run(true, false, new IRunnableWithProgress() { - @Override - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - runWithProgress(monitor, flags, canvasContext); - } - }); - } catch (InvocationTargetException e) { - ExceptionUtils.logAndShowError(e.getTargetException()); - } catch (InterruptedException e) { - } - } - return null; - } - - protected void runWithProgress(final IProgressMonitor monitor, final List flags, final ICanvasContext canvasContext) throws InvocationTargetException { - try { - Simantics.getSession().sync(new WriteRequest() { - @Override - public void perform(WriteGraph graph) throws DatabaseException { - graph.markUndoPoint(); - FlagOperationHandler.this.perform(monitor, graph, flags, canvasContext); - } - }); - } catch (CancelTransactionException e) { - // OK. - } catch (DatabaseException e) { - throw new InvocationTargetException(e); - } finally { - monitor.done(); - } - } - +package org.simantics.modeling.ui.actions; + +import java.lang.reflect.InvocationTargetException; +import java.util.List; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.Simantics; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.CancelTransactionException; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.SelectionHints; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.utils.ui.ExceptionUtils; +import org.simantics.utils.ui.ISelectionUtils; + +/** + * @author Tuukka Lehtonen + */ +public abstract class FlagOperationHandler extends AbstractHandler { + + protected abstract void perform(IProgressMonitor monitor, WriteGraph graph, List flags, + ICanvasContext canvasContext) throws DatabaseException; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + //System.out.println("mergeFlags"); + ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService() + .getSelection(); + + IWorkbenchPart part = HandlerUtil.getActivePartChecked(event); + final ICanvasContext canvasContext = (ICanvasContext) part.getAdapter(ICanvasContext.class); + + if (selection instanceof IStructuredSelection) { + final List flags = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class); + try { + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + new ProgressMonitorDialog(shell).run(true, false, new IRunnableWithProgress() { + @Override + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + runWithProgress(monitor, flags, canvasContext); + } + }); + } catch (InvocationTargetException e) { + ExceptionUtils.logAndShowError(e.getTargetException()); + } catch (InterruptedException e) { + } + } + return null; + } + + protected void runWithProgress(final IProgressMonitor monitor, final List flags, final ICanvasContext canvasContext) throws InvocationTargetException { + try { + Simantics.getSession().sync(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + FlagOperationHandler.this.perform(monitor, graph, flags, canvasContext); + } + }); + } catch (CancelTransactionException e) { + // OK. + } catch (DatabaseException e) { + throw new InvocationTargetException(e); + } finally { + monitor.done(); + } + } + } \ No newline at end of file