X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fhandler%2FCopyPasteHandler.java;h=de10603d3bc078257ddc27fd7c0b390915f9baa4;hp=5b0dfa066478b5362fca8ec6e02492e6ad674fba;hb=b4374193caf61635d382af556ec913bf278d53a8;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/CopyPasteHandler.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/CopyPasteHandler.java index 5b0dfa066..de10603d3 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/CopyPasteHandler.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/CopyPasteHandler.java @@ -44,7 +44,6 @@ import org.simantics.db.layer0.util.SimanticsKeys; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; import org.simantics.db.request.Read; -import org.simantics.diagram.Logger; import org.simantics.diagram.content.Change; import org.simantics.diagram.content.ConnectionUtil; import org.simantics.diagram.content.DiagramContentChanges; @@ -114,6 +113,8 @@ import org.simantics.utils.threads.SWTThread; import org.simantics.utils.threads.ThreadUtils; import org.simantics.utils.ui.ErrorLogger; import org.simantics.utils.ui.SWTUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * CopyPasteHandler is a canvas handler for Commands.CUT, Commands.COPY and @@ -141,6 +142,8 @@ import org.simantics.utils.ui.SWTUtils; */ public class CopyPasteHandler extends AbstractDiagramParticipant { + private static final Logger LOGGER = LoggerFactory.getLogger(CopyPasteHandler.class); + public static final Key KEY_CUT_SELECTION_FRAME_COLOR = new KeyOf(Color.class, "CUT_SELECTION_FRAME_COLOR"); public static final Key KEY_CUT_SELECTION_CONTENT_COLOR = new KeyOf(Color.class, "CUT_SELECTION_CONTENT_COLOR"); public static final Key KEY_COPIED_SELECTION_FRAME_COLOR = new KeyOf(Color.class, "COPY_SELECTION_FRAME_COLOR"); @@ -150,19 +153,19 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { * A key for storing the current selection within the currently active * project for copy/paste implementation. */ - private static final Key KEY_DIAGRAM_SELECTION = DiagramSelectionRepresentation.KEY_DIAGRAM_SELECTION; + private static final Key KEY_DIAGRAM_SELECTION = DiagramSelectionRepresentation.KEY_DIAGRAM_SELECTION; private static final boolean DEBUG = false; private static final boolean DEBUG_SELECTION_UPDATE = false; public static final int COPY_GHOSTING_PAINT_PRIORITY = 600; - private static final int HIGHLIGHT_PAINT_PRIORITY = 500; + protected static final int HIGHLIGHT_PAINT_PRIORITY = 500; @Dependency - private Selection sel; + protected Selection sel; @Dependency - private MouseUtil mouseUtil; + protected MouseUtil mouseUtil; protected final IStatusLineManager statusLine; protected final CopyPasteStrategy strategy; @@ -205,7 +208,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { */ protected boolean hasFocus = false; - private AbstractCanvasParticipant highlightMode = null; + protected AbstractCanvasParticipant highlightMode = null; private IProject observedProject = null; /** @@ -375,7 +378,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { return DiagramSelection.EMPTY; } - private DiagramSelection getProjectSelection() { + protected DiagramSelection getProjectSelection() { IProject p = peekProject(); if (p == null) return DiagramSelection.EMPTY; @@ -383,12 +386,12 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { return ds != null ? ds : DiagramSelection.EMPTY; } - void setDiagramSelection(DiagramSelection selection) { + protected void setDiagramSelection(DiagramSelection selection) { setProjectSelection(selection); strategy.copyToClipboard(selection); } - void setProjectSelection(DiagramSelection selection) { + protected void setProjectSelection(DiagramSelection selection) { assert selection != null; IProject p = getProject(); if (p == null) @@ -399,7 +402,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { p.setHint(KEY_DIAGRAM_SELECTION, selection); } - private void removeProjectSelection() { + protected void removeProjectSelection() { setProjectSelection(DiagramSelection.EMPTY); removeHighlight(); clearSG(); @@ -473,7 +476,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { return false; } - boolean initiateCopy(boolean cut) { + protected boolean initiateCopy(boolean cut) { //System.out.println("INITIATING COPY"); int selectionId = 0; @@ -576,7 +579,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { message(null); return false; } - + TimeLogger.resetTimeAndLog(getClass(), "paste"); ElementObjectAssortment ea = ds.getAssortment(); @@ -685,7 +688,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { } } - private String fixAssortment(ElementAssortment ea, boolean cut) { + protected String fixAssortment(ElementAssortment ea, boolean cut) { Topology diagramTopology = diagram.getDiagramClass().getAtMostOneItemOfClass(Topology.class); List conns = new ArrayList(); @@ -823,7 +826,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { * @param ea * @return */ - private void pruneAssortment(ElementAssortment ea, boolean cut) { + protected void pruneAssortment(ElementAssortment ea, boolean cut) { // Edges and branch points are never copied as such. // They are always included as parts of copied connections. // Edges can never be transformed or modified in any way as such, @@ -872,7 +875,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { * @param e * @return */ - private static boolean isConnectionOrEdge(IElement e) { + protected static boolean isConnectionOrEdge(IElement e) { ElementClass ec = e.getElementClass(); return ec.containsClass(ConnectionHandler.class)|| ec.containsClass(BendsHandler.class); } @@ -881,7 +884,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { * @param e * @return */ - private static boolean isMoveable(IElement e) { + protected static boolean isMoveable(IElement e) { ElementClass ec = e.getElementClass(); return ec.containsClass(Move.class) && ec.containsClass(Transform.class); } @@ -891,7 +894,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { * @return null if a point of reference cannot be determined * for the specified selection. */ - private Point2D getCopyStartPos(Set ss) { + protected Point2D getCopyStartPos(Set ss) { // MouseInfo mi = mouseUtil.getMouseInfo(0); // if (mi != null) { // return (Point2D) mi.canvasPosition.clone(); @@ -1090,11 +1093,11 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { return ghostNode.addNode(id, clazz); } - private boolean hasHighlight() { + protected boolean hasHighlight() { return highlightMode != null; } - private void removeHighlight() { + protected void removeHighlight() { if (isRemoved()) return; assert getContext().getThreadAccess().currentThreadAccess(); @@ -1111,7 +1114,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { return (e.stateMask & MouseEvent.CTRL_MASK) != 0; } - void selectedMessage(DiagramSelection ds) { + protected void selectedMessage(DiagramSelection ds) { int size = ds.getOriginalElements().size(); StringBuilder sb = new StringBuilder(); if (size == 0) { @@ -1133,7 +1136,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { message(sb.toString()); } - void message(final String message) { + protected void message(final String message) { if (statusLine == null) return; swtExec(new Runnable() { @@ -1145,7 +1148,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { }); } - void error(final String message) { + protected void error(final String message) { if (statusLine == null) return; swtExec(new Runnable() { @@ -1156,7 +1159,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { }); } - void swtExec(Runnable r) { + protected void swtExec(Runnable r) { ThreadUtils.asyncExec(SWTThread.getThreadAccess(Display.getDefault()), r); } @@ -1289,12 +1292,12 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { graph.claim(resource, L0X.ObtainsProperty1, null, template); } } - + } }); } } catch (DatabaseException e1) { - Logger.defaultLogError(e1); + LOGGER.error("Monitor paste failed", e1); } } return true;