protected void setUp() throws Exception { super.setUp(); List children = getTestFixture().getDiagramEditPart().getChildren(); if (children.isEmpty()) assertFalse(true); EditPart firstEP = (EditPart) children.get(0); if (firstEP instanceof CircuitEditPart) { CircuitEditPart circuitEditPart = (CircuitEditPart) firstEP; IElementType typeLED = ElementTypeRegistry.getInstance().getType("logic.led"); // $NON-NLS-1$ Point pos = circuitEditPart.getFigure().getBounds().getBottomRight(); circuitEditPart.getFigure().translateToAbsolute(pos); pos.translate(100, 100); LEDEditPart ledEP2 = (LEDEditPart) getLogicTestFixture().createShapeUsingTool(typeLED, pos, getDiagramEditPart()); Terminal term1 = (Terminal) ((Circuit) circuitEditPart.getNotationView().getElement()) .getOutputTerminals() .get(0); TerminalEditPart tep1 = null; ListIterator li = circuitEditPart.getChildren().listIterator(); while (li.hasNext()) { IGraphicalEditPart gep = (IGraphicalEditPart) li.next(); if (gep.getNotationView().getElement().equals(term1)) tep1 = (TerminalEditPart) gep; } Terminal term2 = (Terminal) ((LED) ledEP2.getNotationView().getElement()).getInputTerminals().get(0); TerminalEditPart tep2 = null; li = ledEP2.getChildren().listIterator(); while (li.hasNext()) { IGraphicalEditPart gep = (IGraphicalEditPart) li.next(); if (gep.getNotationView().getElement().equals(term2)) tep2 = (TerminalEditPart) gep; } IElementType typeWire = ElementTypeRegistry.getInstance().getType("logic.wire"); // $NON-NLS-1$ getLogicTestFixture().createConnectorUsingTool(tep1, tep2, typeWire); IGraphicalEditPart logicCompartment = circuitEditPart.getChildBySemanticHint(LogicConstants.LOGIC_SHAPE_COMPARTMENT); Rectangle rect = new Rectangle(logicCompartment.getFigure().getBounds()); logicCompartment.getFigure().translateToAbsolute(rect); CreateRequest request = getLogicTestFixture().getCreationRequest(typeLED); request.setLocation(rect.getCenter()); Command cmd = logicCompartment.getCommand(request); getCommandStack().execute(cmd); assertEquals( "Unexpected LED count.", 1, logicCompartment.getChildren().size()); // $NON-NLS-1$ } }
/** Moved to public so that it may be called programmatically by an other tool. */ public boolean handleButtonDown(int button) { Object underMouse = getCurrentViewer().findObjectAt(getCurrentInput().getMouseLocation()); if (!(underMouse instanceof IGraphicalEditPart)) { return true; } stateTransition(STATE_INITIAL, STATE_DRAG_IN_PROGRESS); _initialPosition = getCurrentPosition(); _initPosNoZoom = getCurrentPositionZoomed(); // calculate the initial selection // of shapes that should move _container = (IGraphicalEditPart) findPool(underMouse); // the children that will be moved around List<IGraphicalEditPart> bottomChildren = new ArrayList<IGraphicalEditPart>(); List<IGraphicalEditPart> subProcesses = new ArrayList<IGraphicalEditPart>(); if (_container != null && _container.resolveSemanticElement() instanceof Container) { List children = null; if (_container.resolveSemanticElement() instanceof Container) { children = _container.getChildren(); } else if (_container instanceof ShapeCompartmentEditPart) { children = ((ShapeCompartmentEditPart) _container).getChildren(); } if (children == null) { throw new IllegalArgumentException( "The part " + _container + " did not contain elements"); // $NON-NLS-1$ //$NON-NLS-2$ } // now iterate over the compartment children // and take those that are on the right. for (Object child : children) { if (child instanceof ShapeNodeEditPart) { setBoundsForOverlapComputation((IGraphicalEditPart) child, SINGLETON); ((DiagramEditPart) getCurrentViewer().getContents()) .getFigure() .translateToRelative(SINGLETON); if (SINGLETON.y > _initPosNoZoom) { bottomChildren.add((IGraphicalEditPart) child); } } } } _movingShapes = bottomChildren; _subProcesses = subProcesses; updateSourceRequest(); showSourceFeedback(); return true; }
private static void pairMediatorFlows() { for (Map.Entry<EsbConnector, EsbConnector> pair : pairMediatorFlowMap.entrySet()) { EditPart firstPart = (EditPart) getEditpart(pair.getKey()); EditPart secondPart = (EditPart) getEditpart(pair.getValue()); AbstractConnectorEditPart sourceConnector = null; AbstractConnectorEditPart targetConnector = null; if (firstPart instanceof SequencesOutputConnectorEditPart && secondPart instanceof SequencesInputConnectorEditPart) { AbstractSequencesEditPart sequence = EditorUtils.getSequence((SequencesOutputConnectorEditPart) firstPart); IGraphicalEditPart mediatorFlow = (IGraphicalEditPart) sequence.getChildren().get(0); // assuming mediatorflow is the first child IGraphicalEditPart mediatorFlowCompartment = (IGraphicalEditPart) mediatorFlow.getChildren().get(0); int numOfChildren = mediatorFlowCompartment.getChildren().size(); if (numOfChildren >= 1) { // get last child and connect its output connector to secuenceinputconnector (right hand // side) // Assuming getChildren().get(numOfChildren - 1) gives the last element in the flow ShapeNodeEditPart lastChild = (ShapeNodeEditPart) mediatorFlowCompartment.getChildren().get(numOfChildren - 1); AbstractOutputConnectorEditPart lastOutputConnector = EditorUtils.getMediatorOutputConnector(lastChild); sourceConnector = lastOutputConnector; targetConnector = (AbstractConnectorEditPart) secondPart; } } else if ((firstPart instanceof InboundEndpointSequenceOutputConnectorEditPart && secondPart instanceof InboundEndpointSequenceInputConnectorEditPart) || (firstPart instanceof InboundEndpointOnErrorSequenceOutputConnectorEditPart && secondPart instanceof InboundEndpointOnErrorSequenceInputConnectorEditPart)) { LinkedList<EsbNode> seq = connectionFlowMap.get(pair.getKey()); if (seq != null && seq.size() > 0 && seq.getLast() instanceof Sequence) { sourceConnector = (AbstractConnectorEditPart) getEditpart(((Sequence) seq.getLast()).getOutputConnector().get(0)); targetConnector = (AbstractConnectorEditPart) secondPart; } } else { if (firstPart instanceof ProxyOutputConnectorEditPart && secondPart instanceof ProxyInputConnectorEditPart) { LinkedList<EsbNode> seq = connectionFlowMap.get(pair.getKey()); if (seq != null && seq.size() > 0 && seq.getLast() instanceof SendMediator) { sourceConnector = (AbstractConnectorEditPart) getEditpart(((SendMediator) seq.getLast()).getOutputConnector()); EList<ProxyInSequenceInputConnector> inputConnectors = ((ProxyService) ((Node) EditorUtils.getProxy(secondPart).getModel()).getElement()) .getInSequenceInputConnectors(); for (ProxyInSequenceInputConnector con : inputConnectors) { if (con.getIncomingLinks().size() == 0) { targetConnector = (AbstractConnectorEditPart) getEditpart(con); break; } } } LinkedList<EsbNode> outSeq = connectionFlowMap.get(pair.getValue()); if (outSeq == null || outSeq.size() == 0) { continue; } sourceConnector = EditorUtils.getProxyOutSequenceOutputConnector( (ShapeNodeEditPart) EditorUtils.getAbstractBaseFigureEditPart( (EditPart) getEditpart(outSeq.getLast()))); if (outSeq.size() > 0 && outSeq.getLast() != null) { targetConnector = EditorUtils.getInputConnector((ShapeNodeEditPart) getEditpart(outSeq.getLast())); } else { if (pair.getValue() instanceof AbstractConnectorEditPart) { targetConnector = (AbstractConnectorEditPart) pair.getValue(); } else continue; } } else if (firstPart instanceof APIResourceOutputConnectorEditPart && secondPart instanceof APIResourceInputConnectorEditPart) { LinkedList<EsbNode> seq = connectionFlowMap.get(pair.getKey()); if (seq != null && seq.size() > 0 && seq.getLast() instanceof SendMediator) { sourceConnector = (AbstractConnectorEditPart) getEditpart(((SendMediator) seq.getLast()).getOutputConnector()); EList<APIResourceInSequenceInputConnector> inputConnectors = ((APIResource) ((Node) EditorUtils.getAPIResource((AbstractConnectorEditPart) secondPart) .getModel()) .getElement()) .getInSequenceInputConnectors(); for (APIResourceInSequenceInputConnector con : inputConnectors) { if (con.getIncomingLinks().size() == 0) { targetConnector = (AbstractConnectorEditPart) getEditpart(con); break; } } } LinkedList<EsbNode> outSeq = connectionFlowMap.get(pair.getValue()); if (outSeq == null || outSeq.size() == 0) { continue; } sourceConnector = EditorUtils.getProxyOutSequenceOutputConnector( (ShapeNodeEditPart) EditorUtils.getAbstractBaseFigureEditPart( (EditPart) getEditpart(outSeq.getLast()))); if (outSeq.size() > 0 && outSeq.getLast() != null) { targetConnector = EditorUtils.getInputConnector((ShapeNodeEditPart) getEditpart(outSeq.getLast())); } else { if (pair.getValue() instanceof AbstractConnectorEditPart) { targetConnector = (AbstractConnectorEditPart) pair.getValue(); } else continue; } } else { LinkedList<EsbNode> outSeq = connectionFlowMap.get(pair.getValue()); if (outSeq == null || outSeq.size() == 0) { continue; } sourceConnector = EditorUtils.getProxyOutSequenceOutputConnector( (ShapeNodeEditPart) EditorUtils.getAbstractBaseFigureEditPart( (EditPart) getEditpart(outSeq.getLast()))); if (outSeq.size() > 0 && outSeq.getLast() != null) { targetConnector = EditorUtils.getInputConnector((ShapeNodeEditPart) getEditpart(outSeq.getLast())); } else { if (pair.getValue() instanceof AbstractConnectorEditPart) { targetConnector = (AbstractConnectorEditPart) pair.getValue(); } else continue; } } } if (sourceConnector != null && targetConnector != null) { ConnectionUtils.createConnection(targetConnector, sourceConnector); } } /* for (Map.Entry<EsbConnector, EsbConnector> pair : pairMediatorFlowMap.entrySet()) { LinkedList<EsbNode> inSeq = connectionFlowMap.get(pair.getKey()); LinkedList<EsbNode> outSeq = connectionFlowMap.get(pair.getValue()); if (inSeq == null || outSeq == null) { continue; } if (inSeq.size() > 0 && inSeq.getLast() instanceof EndPoint) { EsbNode last = inSeq.getLast(); AbstractConnectorEditPart sourceConnector = EditorUtils .getOutputConnector((ShapeNodeEditPart) getEditpart(last)); AbstractConnectorEditPart targetConnector = null; if(outSeq.size() > 0 && outSeq.getLast() != null){ targetConnector = EditorUtils .getInputConnector((ShapeNodeEditPart) getEditpart(outSeq.getLast())); } else{ if(pair.getValue() instanceof AbstractConnectorEditPart){ targetConnector = (AbstractConnectorEditPart) pair.getValue(); } else continue; } if (sourceConnector != null && targetConnector != null) { ConnectionUtils.createConnection(targetConnector,sourceConnector); } } } //looking for other possible connections : around 1 //Connecting endpoints to last node of out-sequence Iterator<EsbConnector> iterator = getRootInputConnectors().iterator(); while (iterator.hasNext()) { EsbConnector rootConnector = iterator.next(); for (LinkedList<EsbNode> nodes : connectionFlowMap.values()) { if (!pairMediatorFlowMap.values().contains(nodes)) { if (nodes.size() > 0 && (nodes.getLast() instanceof EndPoint || rootConnector.eContainer() instanceof Sequences)) { LinkedList<EsbNode> outSeq = connectionFlowMap.get(rootConnector); AbstractConnectorEditPart targetConnector = null; EsbNode last = nodes.getLast(); AbstractConnectorEditPart sourceConnector = EditorUtils .getOutputConnector((ShapeNodeEditPart) getEditpart(last)); if (outSeq!=null &&( outSeq.size() > 0 && outSeq.getLast() != null)) { targetConnector = EditorUtils .getInputConnector((ShapeNodeEditPart) getEditpart(outSeq .getLast())); } else { targetConnector = (AbstractConnectorEditPart) getEditpart(rootConnector); } if (sourceConnector != null && targetConnector != null) { if(targetConnector instanceof SequencesInputConnectorEditPart){ if(sourceConnector.getParent().getParent().getParent().getParent().equals(targetConnector.getParent())){ ConnectionUtils.createConnection(targetConnector, sourceConnector); } }else{ ConnectionUtils.createConnection(targetConnector, sourceConnector); } } } } } } //looking for other possible connections : around 2 //Connecting send mediators to an inline endpoint or a dummy endpoint EsbNode targetNode = null; List<EsbNode> sourceNodes = new LinkedList<EsbNode>(); for (LinkedList<EsbNode> nodes : connectionFlowMap.values()) { if (targetNode==null) { if (nodes.size() > 0 && nodes.getLast() instanceof AbstractEndPoint) { AbstractEndPoint endPoint = (AbstractEndPoint) nodes.getLast(); if (endPoint instanceof AddressingEndpoint || endPoint.isInLine()) { targetNode = endPoint; } } } if (nodes.size() > 0 && nodes.getLast() instanceof SendMediator) { sourceNodes.add(nodes.getLast()); } } if(targetNode!=null && sourceNodes.size()>0){ AbstractConnectorEditPart targetConnector = EditorUtils .getInputConnector((ShapeNodeEditPart) getEditpart(targetNode)); for (EsbNode sourceNode : sourceNodes) { AbstractConnectorEditPart sourceConnector = EditorUtils .getOutputConnector((ShapeNodeEditPart) getEditpart(sourceNode)); if (sourceConnector != null && targetConnector != null) { ConnectionUtils.createConnection(targetConnector, sourceConnector); } } }*/ }