X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FSCLClipboard.java;h=94db9c596e301975d7e34e28442d0f158d99307b;hb=d924aa9e2691606e0bc8044cce01aff4abcc7bc9;hp=572df2f7a0150776f2bd1fa224abd71884dff03a;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/SCLClipboard.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/SCLClipboard.java index 572df2f7a..94db9c596 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/SCLClipboard.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/SCLClipboard.java @@ -1,148 +1,149 @@ -package org.simantics.modeling.ui; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.jface.viewers.ISelection; -import org.simantics.db.Resource; -import org.simantics.modeling.ui.modelBrowser.handlers.StandardCopyHandler; -import org.simantics.modeling.ui.modelBrowser.handlers.StandardPasteHandler; -import org.simantics.scenegraph.g2d.events.command.Commands; -import org.simantics.utils.threads.ThreadUtils; -import org.simantics.utils.ui.ISelectionUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.PasteHandler; -import org.simantics.g2d.canvas.ICanvasContext; -import org.simantics.g2d.diagram.DiagramHints; -import org.simantics.g2d.diagram.IDiagram; -import org.simantics.g2d.diagram.handler.DataElementMap; -import org.simantics.g2d.diagram.participant.Selection; -import org.simantics.g2d.element.IElement; -import org.simantics.g2d.utils.CanvasUtils; - -public class SCLClipboard { - - public static void copyNode (Resource node) { - - ISelection selection = ISelectionUtils.createSelection(node); - Resource[] rs = new Resource[] {node}; - StandardCopyHandler.copyResourcesToClipboard(rs, selection); - } - - public static void pasteNode (Resource target) { - - PasteHandler handler = StandardPasteHandler.getPasteHandlerFromResource(target, PasteHandler.class); - StandardPasteHandler.pasteResourceFromClipboardWithoutMonitor(handler); - } - - public static void copyPasteNode(Resource node, Resource target) { - - copyNode(node); - pasteNode(target); - } - - public static boolean copyPasteDiagramContents (final ICanvasContext source_ctx, final ICanvasContext target_ctx, List modules) throws DatabaseException { - - IDiagram idiagram = source_ctx.getDefaultHintContext().getHint(DiagramHints.KEY_DIAGRAM); - - DataElementMap dem = idiagram.getDiagramClass().getAtMostOneItemOfClass(DataElementMap.class); - if (dem != null) { - final Collection newSelection = new ArrayList(); - for (Resource module : modules) { - IElement element = dem.getElement(idiagram, module); - if (element != null) { - newSelection.add(element); - } else { - throw new DatabaseException("Could not find IElement for " + element); - } - } - - ThreadUtils.syncExec(source_ctx.getThreadAccess(), new Runnable() { - @Override - public void run() { - if (source_ctx.isDisposed()) - return; - Selection selection = source_ctx.getAtMostOneItemOfClass(Selection.class); - if (selection != null) { - // This prevents workbench selection from being left over. - // Also prevents scene graph crap from being left on the screen. - selection.setSelection(0, newSelection); - } - CanvasUtils.sendCommand(source_ctx, Commands.COPY); - CanvasUtils.sendCommand(target_ctx, Commands.PASTE); - } - }); - - //} - - while(source_ctx.getEventQueue().size() > 0) { - try { - Thread.sleep(10); - } catch (InterruptedException e) { - throw new DatabaseException(e); - } - } - - ThreadUtils.syncExec(source_ctx.getThreadAccess(), new Runnable() { - @Override - public void run() { - } - }); - - } - return true; - } - - public static boolean delete (final ICanvasContext source_ctx, List modules) throws DatabaseException { - - IDiagram idiagram = source_ctx.getDefaultHintContext().getHint(DiagramHints.KEY_DIAGRAM); - - DataElementMap dem = idiagram.getDiagramClass().getAtMostOneItemOfClass(DataElementMap.class); - if (dem != null) { - final Collection newSelection = new ArrayList(); - for (Resource module : modules) { - IElement element = dem.getElement(idiagram, module); - if (element != null) { - newSelection.add(element); - } else { - throw new DatabaseException("Could not find IElement for " + element); - } - } - - ThreadUtils.syncExec(source_ctx.getThreadAccess(), new Runnable() { - @Override - public void run() { - if (source_ctx.isDisposed()) - return; - Selection selection = source_ctx.getAtMostOneItemOfClass(Selection.class); - if (selection != null) { - // This prevents workbench selection from being left over. - // Also prevents scene graph crap from being left on the screen. - selection.setSelection(0, newSelection); - } - CanvasUtils.sendCommand(source_ctx, Commands.DELETE); - } - }); - - //} - - while(source_ctx.getEventQueue().size() > 0) { - try { - Thread.sleep(10); - } catch (InterruptedException e) { - throw new DatabaseException(e); - } - } - - ThreadUtils.syncExec(source_ctx.getThreadAccess(), new Runnable() { - @Override - public void run() { - } - }); - - } - return true; - } - +package org.simantics.modeling.ui; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.viewers.ISelection; +import org.simantics.db.Resource; +import org.simantics.modeling.ui.modelBrowser.handlers.StandardCopyHandler; +import org.simantics.modeling.ui.modelBrowser.handlers.StandardPasteHandler; +import org.simantics.scenegraph.g2d.events.command.Commands; +import org.simantics.utils.threads.ThreadUtils; +import org.simantics.utils.ui.ISelectionUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.PasteHandler; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.DiagramHints; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.diagram.handler.DataElementMap; +import org.simantics.g2d.diagram.participant.Selection; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.utils.CanvasUtils; + +public class SCLClipboard { + + public static void copyNode (Resource node) { + + ISelection selection = ISelectionUtils.createSelection(node); + Resource[] rs = new Resource[] {node}; + StandardCopyHandler.copyResourcesToClipboard(rs, selection, new NullProgressMonitor()); + } + + public static void pasteNode (Resource target) { + + PasteHandler handler = StandardPasteHandler.getPasteHandlerFromResource(target, PasteHandler.class); + StandardPasteHandler.pasteResourceFromClipboardWithoutMonitor(handler); + } + + public static void copyPasteNode(Resource node, Resource target) { + + copyNode(node); + pasteNode(target); + } + + public static boolean copyPasteDiagramContents (final ICanvasContext source_ctx, final ICanvasContext target_ctx, List modules) throws DatabaseException { + + IDiagram idiagram = source_ctx.getDefaultHintContext().getHint(DiagramHints.KEY_DIAGRAM); + + DataElementMap dem = idiagram.getDiagramClass().getAtMostOneItemOfClass(DataElementMap.class); + if (dem != null) { + final Collection newSelection = new ArrayList(); + for (Resource module : modules) { + IElement element = dem.getElement(idiagram, module); + if (element != null) { + newSelection.add(element); + } else { + throw new DatabaseException("Could not find IElement for " + element); + } + } + + ThreadUtils.syncExec(source_ctx.getThreadAccess(), new Runnable() { + @Override + public void run() { + if (source_ctx.isDisposed()) + return; + Selection selection = source_ctx.getAtMostOneItemOfClass(Selection.class); + if (selection != null) { + // This prevents workbench selection from being left over. + // Also prevents scene graph crap from being left on the screen. + selection.setSelection(0, newSelection); + } + CanvasUtils.sendCommand(source_ctx, Commands.COPY); + CanvasUtils.sendCommand(target_ctx, Commands.PASTE); + } + }); + + //} + + while(source_ctx.getEventQueue().size() > 0) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + throw new DatabaseException(e); + } + } + + ThreadUtils.syncExec(source_ctx.getThreadAccess(), new Runnable() { + @Override + public void run() { + } + }); + + } + return true; + } + + public static boolean delete (final ICanvasContext source_ctx, List modules) throws DatabaseException { + + IDiagram idiagram = source_ctx.getDefaultHintContext().getHint(DiagramHints.KEY_DIAGRAM); + + DataElementMap dem = idiagram.getDiagramClass().getAtMostOneItemOfClass(DataElementMap.class); + if (dem != null) { + final Collection newSelection = new ArrayList(); + for (Resource module : modules) { + IElement element = dem.getElement(idiagram, module); + if (element != null) { + newSelection.add(element); + } else { + throw new DatabaseException("Could not find IElement for " + element); + } + } + + ThreadUtils.syncExec(source_ctx.getThreadAccess(), new Runnable() { + @Override + public void run() { + if (source_ctx.isDisposed()) + return; + Selection selection = source_ctx.getAtMostOneItemOfClass(Selection.class); + if (selection != null) { + // This prevents workbench selection from being left over. + // Also prevents scene graph crap from being left on the screen. + selection.setSelection(0, newSelection); + } + CanvasUtils.sendCommand(source_ctx, Commands.DELETE); + } + }); + + //} + + while(source_ctx.getEventQueue().size() > 0) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + throw new DatabaseException(e); + } + } + + ThreadUtils.syncExec(source_ctx.getThreadAccess(), new Runnable() { + @Override + public void run() { + } + }); + + } + return true; + } + } \ No newline at end of file