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$ } }
@Override public void showSizeOnDropFeedback(CreateRequest request, IFigure feedback, Insets insets) { Point p = new Point(request.getLocation().getCopy()); feedback.translateToRelative(p); Dimension size = request.getSize().getCopy(); feedback.translateToRelative(size); feedback.setBounds(new Rectangle(p, size).expand(insets)); }
protected Command getCreateCommand(CreateRequest request) { NodeCreateCommand createCommand = new NodeCreateCommand(); createCommand.setNode((Node) request.getNewObject()); createCommand.setParent((ProcessDefinition) getHost().getModel()); createCommand.setLocation(request.getLocation()); createCommand.setLabel("create a node"); return createCommand; }
@Override protected Command getCreateCommand(CreateRequest request) { Rectangle bounds = getConstraintFor(request); if (request.getNewObjectType() instanceof EClass) { EClass eClass = (EClass) request.getNewObjectType(); // Archimate type object if (IArchimatePackage.eINSTANCE.getArchimateElement().isSuperTypeOf(eClass)) { return new CreateDiagramArchimateObjectCommand(getHost(), request, bounds); } } return super.getCreateCommand(request); }
/** @see ContainerEditPolicy#getCreateCommand(org.eclipse.gef.requests.CreateRequest) */ protected Command getCreateCommand(CreateRequest request) { CreateAndAssignSourceCommand cmd = new CreateAndAssignSourceCommand(); cmd.setParent((StructuredActivity) getHost().getParent().getModel()); cmd.setChild((Activity) request.getNewObject()); cmd.setSource((Activity) getHost().getModel()); return cmd; }
@Override protected Command getCreateCommand(CreateRequest request) { if (request.getType() == REQ_CREATE && getHost() instanceof UMLContainerFigurePart) { UMLCreateCommand cmd = new UMLCreateCommand(); cmd.setUMLContainer(getHost().getModel()); cmd.setUML(request.getNewObject()); Rectangle constraint = (Rectangle) getConstraintFor(request); constraint.x = (constraint.x < 0) ? 0 : constraint.x; constraint.y = (constraint.y < 0) ? 0 : constraint.y; constraint.width = (constraint.width <= 0) ? UMLClassFigure.SERVICE_FIGURE_DEFWIDTH : constraint.width; constraint.height = (constraint.height <= 0) ? UMLClassFigure.SERVICE_FIGURE_DEFHEIGHT : constraint.height; cmd.setLayout(constraint); return cmd; } return null; }
/** @see LayoutEditPolicy#getCreateCommand(org.eclipse.gef.requests.CreateRequest) */ @Override protected Command getCreateCommand(CreateRequest request) { StructuredActivity parent = (StructuredActivity) getHost().getModel(); EditPartViewer viewer = getHost().getViewer(); CreateCommand command = new CreateCommand(parent.getDiagram().getTextEditor(), viewer); command.setParent(parent); command.setChild((Activity) request.getNewObject()); return command; }
/* * Over-ride this to get any extra constraints for an object */ @Override protected Rectangle getConstraintFor(CreateRequest request) { Rectangle bounds = (Rectangle) super.getConstraintFor(request); Dimension d = getMaximumSizeFor(request.getNewObjectType()); bounds.width = Math.min(d.width, bounds.width); bounds.height = Math.min(d.height, bounds.height); return bounds; }
@Override protected Command getCreateCommand(CreateRequest request) { IEntity child = (IEntity) request.getNewObject(); IContainer container = (IContainer) getHost().getModel(); S2InterceptorsChildAddCommand command = new S2InterceptorsChildAddCommand(child, container); EditPart after = getInsertionReference(request); int index = getHost().getChildren().indexOf(after); command.setIndex(index); return command; }
/* * (non-Javadoc) * * @see * org.eclipse.gef.editpolicies.LayoutEditPolicy#createSizeOnDropFeedback * (org.eclipse.gef.requests.CreateRequest) */ protected IFigure createSizeOnDropFeedback(CreateRequest createRequest) { IFigure figure; if (createRequest.getNewObject() instanceof Circuit) figure = new CircuitFeedbackFigure(); else if (createRequest.getNewObject() instanceof LogicFlowContainer) figure = new LogicFlowFeedbackFigure(); else if (createRequest.getNewObject() instanceof LogicLabel) figure = new LabelFeedbackFigure(); else { figure = new RectangleFigure(); ((RectangleFigure) figure).setXOR(true); ((RectangleFigure) figure).setFill(true); figure.setBackgroundColor(LogicColorConstants.ghostFillColor); figure.setForegroundColor(ColorConstants.white); } addFeedback(figure); return figure; }
/* (non-Javadoc) * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#getCreateCommand(org.eclipse.gef.requests.CreateRequest) */ protected Command getCreateCommand(CreateRequest request) { Object newObjectType = request.getNewObjectType(); Command createCommand = null; if (newObjectType == ProvidesDef.class || newObjectType == UsesDef.class || newObjectType == PublishesDef.class || newObjectType == ConsumesDef.class) { CreateNodeCommand create = new CreateNodeCommand(); Dimension dim = request.getSize(); if (dim == null) dim = new Dimension(100, 20); create.setConstraint(new Rectangle(request.getLocation(), dim)); create.setParent((View) getHost().getModel()); create.setModelParent(((View) getHost().getModel()).getModuleDef()); create.setModelObject((Contained) request.getNewObject()); create.setLabel("create a node"); createCommand = create; } return createCommand; }
/* * (non-Javadoc) * * @see * org.eclipse.gef.editpolicies.LayoutEditPolicy#getCreateCommand(org.eclipse * .gef.requests.CreateRequest) */ @Override protected Command getCreateCommand(CreateRequest request) { Command command = null; if (request.getNewObject() instanceof Attribute) { Node node = (Node) getHost().getModel(); if (node.getType() != null) if ((node.getType().getEAllAttributes().size() - node.getAttributes().size() > 0)) command = new CreateAttributesCommand(node); } return command; }
@Override protected Command getCreateCommand(CreateRequest request) { if (request.getType() == REQ_CREATE && getHost() instanceof AppAbstractEditPart) { if (((BControl) ((AppAbstractEditPart) getHost()).getModel()).canHaveChildren()) { BControl newObj = (BControl) request.getNewObject(); CreateCommand createCmd = new CreateCommand(newObj, (BControl) getHost().getModel()); Rectangle constraint = (Rectangle) getConstraintFor(request); constraint.x = (constraint.x < 0) ? 0 : constraint.x; constraint.y = (constraint.y < 0) ? 0 : constraint.y; BAttributeWidth atrWidth = (BAttributeWidth) newObj.getAttributes().get(AttributeConstants.ATTRIBUTE_WIDTH); BAttributeHeight atrHeight = (BAttributeHeight) newObj.getAttributes().get(AttributeConstants.ATTRIBUTE_HEIGHT); if (atrWidth != null) { constraint.width = Integer.valueOf(atrWidth.getValue().toString()); } else { constraint.width = (constraint.width <= 0) ? 100 : constraint.width; } if (atrHeight != null) { constraint.height = Integer.valueOf(atrHeight.getValue().toString()); } else { constraint.height = (constraint.height <= 0) ? 100 : constraint.height; } createCmd.setLayout(constraint); Command cmd = chainGuideAttachmentCommand(request, newObj, createCmd, true); return chainGuideAttachmentCommand(request, newObj, cmd, false); } } return null; }
protected Command getCreateCommand(CreateRequest request) { CreateCommand create = new CreateCommand(); create.setParent((LogicDiagram) getHost().getModel()); LogicSubpart newPart = (LogicSubpart) request.getNewObject(); create.setChild(newPart); Rectangle constraint = (Rectangle) getConstraintFor(request); create.setLocation(constraint); create.setLabel(LogicMessages.LogicXYLayoutEditPolicy_CreateCommandLabelText); Command cmd = chainGuideAttachmentCommand(request, newPart, create, true); return chainGuideAttachmentCommand(request, newPart, cmd, false); }
@Override protected Command getCreateCommand(CreateRequest request) { CreateModelCommand command = new CreateModelCommand(); // 产生创建图形的尺寸和位置 Rectangle constraint = (Rectangle) getConstraintFor(request); // 获得新创建的模型 AbstractModel model = (AbstractModel) request.getNewObject(); // 为该图形设置前面获得的位置和尺寸 model.setConstraint(constraint); command.setWorkFlowModel((WorkFlowModel) getHost().getModel()); command.setModel(model); return command; }
@Override protected Command getCreateCommand(CreateRequest request) { final Rectangle constraint = (Rectangle) getConstraintFor(request); // get the child object to create final Object newObject = request.getNewObject(); final EditPart editPart = getHost(); final MyRentalAgency parentAgency = (MyRentalAgency) editPart.getModel(); Command command = UnexecutableCommand.INSTANCE; if (parentAgency != null) { if (newObject instanceof Customer) { command = new CreateCustomerCommand((Customer) newObject, parentAgency, constraint); } else if (newObject instanceof RentalObject) { command = new CreateRentalObjectCommand((RentalObject) newObject, parentAgency, constraint); } } return command; }
@Override protected Command getCreateCommand(CreateRequest request) { if (request instanceof CreateViewAndElementRequest) { CreateViewAndElementRequest req = (CreateViewAndElementRequest) request; if (req.getViewAndElementDescriptor() .getSemanticHint() .equals(((IHintedType) UMLElementTypes.Pseudostate_16000).getSemanticHint()) || req.getViewAndElementDescriptor() .getSemanticHint() .equals(((IHintedType) UMLElementTypes.Pseudostate_17000).getSemanticHint()) || req.getViewAndElementDescriptor() .getSemanticHint() .equals( ((IHintedType) UMLElementTypes.ConnectionPointReference_18000) .getSemanticHint())) { TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain(); CompositeTransactionalCommand cc = new CompositeTransactionalCommand(editingDomain, DiagramUIMessages.AddCommand_Label); Iterator<?> iter = req.getViewDescriptors().iterator(); // Retrieve parent location Point parentLoc = getHostFigure().getBounds().getLocation().getCopy(); // Compute relative creation location Point requestedLocation = request.getLocation().getCopy(); getHostFigure().translateToRelative(requestedLocation); // Create proposed creation bounds and use the locator to find the expected position CustomEntryExitPointPositionLocator locator = new CustomEntryExitPointPositionLocator(getHostFigure(), PositionConstants.NONE); Rectangle proposedBounds = new Rectangle(requestedLocation, new Dimension(20, 20)); Rectangle preferredBounds = locator.getPreferredLocation(proposedBounds); // Convert the calculated preferred bounds as relative to parent location Rectangle creationBounds = preferredBounds.getTranslated(parentLoc.getNegated()); while (iter.hasNext()) { CreateViewRequest.ViewDescriptor viewDescriptor = (CreateViewRequest.ViewDescriptor) iter.next(); cc.compose( new SetBoundsCommand( editingDomain, DiagramUIMessages.SetLocationCommand_Label_Resize, viewDescriptor, creationBounds)); } if (cc.reduce() == null) { return null; } return new ICommandProxy(cc.reduce()); } } return null; }
/* * (non-Javadoc) * * @see * org.eclipse.gef.editpolicies.LayoutEditPolicy#getCreationFeedbackOffset * (org.eclipse.gef.requests.CreateRequest) */ protected Insets getCreationFeedbackOffset(CreateRequest request) { if (request.getNewObject() instanceof LED || request.getNewObject() instanceof Circuit) return new Insets(2, 0, 2, 0); return new Insets(); }
@Override protected Request createTargetRequest() { CreateRequest request = new CreateRequest(); request.setFactory(transferFactory); return request; }