From: Marko Luukkainen Date: Mon, 3 Apr 2017 09:41:47 +0000 (+0300) Subject: Allow overriding of CopyPasteHandler and Paster methods X-Git-Tag: v1.29.0~123 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=26b517dc84713ad02191ba4dbad7d3b0efc151bb;p=simantics%2Fplatform.git Allow overriding of CopyPasteHandler and Paster methods Changed some method signatures from private to protected for inheritance purposes. refs #7125 Change-Id: Ib66104a271d18824ad1f397e4a48e89086f694cd --- 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..52217c3cf 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 @@ -150,19 +150,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 +205,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { */ protected boolean hasFocus = false; - private AbstractCanvasParticipant highlightMode = null; + protected AbstractCanvasParticipant highlightMode = null; private IProject observedProject = null; /** @@ -375,7 +375,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 +383,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 +399,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 +473,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 +576,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { message(null); return false; } - + TimeLogger.resetTimeAndLog(getClass(), "paste"); ElementObjectAssortment ea = ds.getAssortment(); @@ -685,7 +685,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 +823,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 +872,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 +881,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 +891,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 +1090,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 +1111,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 +1133,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 +1145,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 +1156,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { }); } - void swtExec(Runnable r) { + protected void swtExec(Runnable r) { ThreadUtils.asyncExec(SWTThread.getThreadAccess(Display.getDefault()), r); } @@ -1289,7 +1289,7 @@ public class CopyPasteHandler extends AbstractDiagramParticipant { graph.claim(resource, L0X.ObtainsProperty1, null, template); } } - + } }); } diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/Paster.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/Paster.java index 03edda6bd..c8995f4c1 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/Paster.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/Paster.java @@ -274,7 +274,7 @@ public class Paster { return noParentElementReturnValue; } - private void cut() throws Exception { + protected void cut() throws Exception { final GraphLayerManager glm = targetContext.get(GraphSynchronizationHints.GRAPH_LAYER_MANAGER); final THashSet cutElements = new THashSet(); @@ -748,7 +748,7 @@ public class Paster { } }; - private void copy() throws Exception { + protected void copy() throws Exception { nodeMap = new NodeMap(); CommonDBUtils.selectClusterSet(graph, targetDiagram); @@ -1360,5 +1360,8 @@ public class Paster { public NodeMap getNodeMap() { return nodeMap; } - + + protected PasteOperation getOperation() { + return op; + } }