/* * (non-Javadoc) * * @see org.eclipse.birt.report.designer.core.util.mediator.request.IRequestConvert#convertSelectionToModelLisr(java.util.List) */ public List convertSelectionToModelLisr(List list) { List retValue = new ArrayList(); int size = list.size(); boolean isDummy = false; for (int i = 0; i < size; i++) { Object object = list.get(i); if (!(object instanceof EditPart)) { continue; } EditPart part = (EditPart) object; if (part instanceof DummyEditpart) { retValue.add(part.getModel()); isDummy = true; } else if (isDummy) { break; } else if (part.getModel() instanceof ListBandProxy) { retValue.add(((ListBandProxy) part.getModel()).getSlotHandle()); } else { Object model = part.getModel(); if (model instanceof IAdaptable) { Object temp = ((IAdaptable) model).getAdapter(DesignElementHandle.class); model = temp == null ? model : temp; } if (model instanceof ReportItemHandle) { ReportItemHandle handle = (ReportItemHandle) model; if (handle.getCurrentView() != null) { model = handle.getCurrentView(); } } retValue.add(model); } } return retValue; }
/** * Compares semantically the two given edit parts * * @param one The first edit part to be compared * @param other The second edit part to be compared * @return True if the two edit parts refer to the same model element, false otherwise */ private boolean semanticCompareEditParts(EditPart one, EditPart other) { if (one.getModel() instanceof View && other.getModel() instanceof View) { View view1 = (View) one.getModel(); View view2 = (View) other.getModel(); return view1 != null && view2 != null && view1.getElement() == view2.getElement(); } return false; }
/* * (non-Javadoc) * * @see org.eclipse.papyrus.layout.LayouttoolInterface#getSource(org.eclipse.gef.EditPart) */ public EditPart getSource(EditPart element) { if (element.getModel() instanceof Edge) { Edge edge = (Edge) element.getModel(); removeBendPoints(edge); AbstractConnectionEditPart acep = (AbstractConnectionEditPart) element; return acep.getSource(); } return null; }
/* * (non-Javadoc) * * @see org.eclipse.papyrus.layout.LayouttoolInterface#getBounds(org.eclipse.gef.EditPart) */ public Rectangle getBounds(EditPart element) { if (element.getModel() instanceof Node) { Node node = (Node) element.getModel(); if (node.getLayoutConstraint() instanceof Bounds) { Bounds bounds = (Bounds) node.getLayoutConstraint(); return new Rectangle(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); } } return null; }
@Override protected Command createChangeConstraintCommand( ChangeBoundsRequest request, EditPart child, Object constraint) { BControlChangeLayoutCommand cmd = new BControlChangeLayoutCommand(); BControl part = (BControl) child.getModel(); cmd.setModel(child.getModel()); cmd.setConstraint((Rectangle) constraint); Command result = cmd; if ((request.getResizeDirection() & PositionConstants.NORTH_SOUTH) != 0) { Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_GUIDE); if (guidePos != null) { result = chainGuideAttachmentCommand(request, part, result, true); } else if (part.getHorizontalGuide() != null) { // SnapToGuides didn't provide a horizontal guide, but this part // is attached // to a horizontal guide. Now we check to see if the part is // attached to // the guide along the edge being resized. If that is the case, // we need to // detach the part from the guide; otherwise, we leave it alone. int alignment = part.getHorizontalGuide().getAlignment(part); int edgeBeingResized = 0; if ((request.getResizeDirection() & PositionConstants.NORTH) != 0) edgeBeingResized = -1; else edgeBeingResized = 1; if (alignment == edgeBeingResized) result = result.chain(new ChangeGuideCommand(part, true)); } } if ((request.getResizeDirection() & PositionConstants.EAST_WEST) != 0) { Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_GUIDE); if (guidePos != null) { result = chainGuideAttachmentCommand(request, part, result, false); } else if (part.getVerticalGuide() != null) { int alignment = part.getVerticalGuide().getAlignment(part); int edgeBeingResized = 0; if ((request.getResizeDirection() & PositionConstants.WEST) != 0) edgeBeingResized = -1; else edgeBeingResized = 1; if (alignment == edgeBeingResized) result = result.chain(new ChangeGuideCommand(part, false)); } } if (request.getType().equals(REQ_MOVE_CHILDREN) || request.getType().equals(REQ_ALIGN_CHILDREN)) { result = chainGuideAttachmentCommand(request, part, result, true); result = chainGuideAttachmentCommand(request, part, result, false); result = chainGuideDetachmentCommand(request, part, result, true); result = chainGuideDetachmentCommand(request, part, result, false); } return result; }
/** @generated */ protected Command getOpenCommand(Request request) { EditPart targetEditPart = getTargetEditPart(request); if (false == targetEditPart.getModel() instanceof View) { return null; } View view = (View) targetEditPart.getModel(); Style link = view.getStyle(NotationPackage.eINSTANCE.getHintedDiagramLinkStyle()); if (false == link instanceof HintedDiagramLinkStyle) { return null; } return new ICommandProxy(new OpenDiagramCommand((HintedDiagramLinkStyle) link)); }
/** * (non-Javadoc) * * @see com.odcgroup.workbench.editors.properties.ISelectionAdapter#adaptModel(java.lang.Object) */ @Override public EObject adaptModel(Object object) { EObject model = null; if (object != null && object instanceof EditPart) { EditPart ep = (EditPart) object; if (ep.getModel() instanceof View) { View view = (View) ep.getModel(); model = view.getElement(); } } return model; }
/** @generated */ protected EObject getSemanticElement(Object object) { View view = null; if (object instanceof View) { view = (View) object; } else if (object instanceof EditPart) { EditPart editPart = (EditPart) object; if (editPart.getModel() instanceof View) { view = (View) editPart.getModel(); } } if (view != null && DiagramEditPart.MODEL_ID.equals(MolicVisualIDRegistry.getModelID(view))) { return view.getElement(); } return null; }
/** * @return Returns view for corresponding model element. * @param containerEditPart Edit part containing the given shape. * @param shapeOfNode Model shape of the view to be searched and returned. */ private static NodeImpl getViewFromModel( final EditPart containerEditPart, final Shape shapeOfNode) { final List<EditPart> editParts = EditPartService.getAllShapesInSideCompartment(containerEditPart); for (final EditPart i : editParts) { if (i.getModel() instanceof NodeImpl) { final NodeImpl shapeImpl = (NodeImpl) i.getModel(); final Shape element = (Shape) shapeImpl.getElement(); if (element.equals(shapeOfNode)) { return shapeImpl; } } } return null; }
@Override protected EditPolicy createChildEditPolicy(EditPart child) { BControl control = (BControl) child.getModel(); ResizableEditPolicy policy = new ResizableEditPolicy(); BAttributeWidth atrWidth = (BAttributeWidth) control.getAttributes().get(AttributeConstants.ATTRIBUTE_WIDTH); BAttributeHeight atrHeight = (BAttributeHeight) control.getAttributes().get(AttributeConstants.ATTRIBUTE_HEIGHT); if (atrWidth.isEditable() && atrHeight.isEditable()) return policy; if (atrWidth.isEditable()) { policy.setResizeDirections(PositionConstants.EAST_WEST); return policy; } if (atrHeight.isEditable()) { policy.setResizeDirections(PositionConstants.NORTH_SOUTH); return policy; } policy.setResizeDirections(0); return policy; }
private GraphElement getTargetElement() { if (selectedPart instanceof EventTreeEditPart) { return (GraphElement) selectedPart.getParent().getModel(); } else { return (GraphElement) selectedPart.getModel(); } }
private Command createCopyCommand(List<Object> selectedObjects) { if (selectedObjects == null || selectedObjects.isEmpty()) return null; CopyCommand cmd = new CopyCommand(); Iterator<Object> it = selectedObjects.iterator(); while (it.hasNext()) { Object nextElement = it.next(); if (nextElement instanceof EditPart) { EditPart ep = (EditPart) nextElement; if (ep.getModel() instanceof BControl) { BControl node = (BControl) ep.getModel(); if (cmd.isCopyableControl(node)) cmd.addElement(node); } } } return cmd; }
/** * This is to avoid RJS0007E Semantic refresh failed issue appears in compartments, which has only * one node. This should be replaced with the better approach */ public static void relocateStartNodes() { for (Iterator<EditPart> it = startNodes.iterator(); it.hasNext(); ) { try { EditPart next = it.next(); GraphicalEditPart gEditpart = (GraphicalEditPart) next; Rectangle rect = gEditpart.getFigure().getBounds().getCopy(); rect.x++; SetBoundsCommand sbc = new SetBoundsCommand( gEditpart.getEditingDomain(), "change location", new EObjectAdapter((View) next.getModel()), rect); gEditpart.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(sbc)); Thread.sleep(50); } catch (Exception e) { break; } } startNodes = new ArrayList<EditPart>(); }
protected Command createAddCommand(EditPart child) { Activity activity = (Activity) child.getModel(); EditPartViewer viewer = getHost().getViewer(); AddCommand add = new AddCommand(activity.getDiagram().getTextEditor(), viewer); add.setParent((StructuredActivity) getHost().getModel()); add.setChild(activity); return add; }
private void checkStyleBeforeCustom(SWTBotGefEditPart botGefEditPart) { EditPart editPart = botGefEditPart.part(); Node model = (Node) editPart.getModel(); ShapeStyle shapeStyle = (ShapeStyle) model.getStyles().get(0); assertEquals("Wrong expected fill color.", EXPECTED_FILL_COLOR, shapeStyle.getFillColor()); assertEquals("Wrong expected font height", EXPECTED_FONT_HEIGHT, shapeStyle.getFontHeight()); assertEquals("Wrong expected font color", EXPECTED_FONT_COLOR, shapeStyle.getFontColor()); assertEquals("Wrong expected line color", EXPECTED_LINE_COLOR, shapeStyle.getLineColor()); }
@Override protected Command createChangeConstraintCommand(EditPart child, Object constraint) { ChangeConstraintCommand command = new ChangeConstraintCommand(); command.setModel((AbstractModel) child.getModel()); command.setConstraint((Rectangle) constraint); return command; }
/** * @param reversedMode * @param editpart */ private static void relocateNode(final Rectangle location, EditPart editpart) { GraphicalEditPart gEditpart = (GraphicalEditPart) editpart; if (editpart instanceof org.wso2.developerstudio.eclipse.gmf.esb.diagram.custom.AbstractMediator) { Rectangle rect = new Rectangle(new Point(), gEditpart.getFigure().getPreferredSize()).getCopy(); Rectangle rectCopy = rect.getCopy(); if (editpart instanceof complexFiguredAbstractMediator) { @SuppressWarnings("rawtypes") List children = gEditpart.getChildren(); int pointY = 50; for (Object child : children) { if (child instanceof AbstractOutputConnectorEditPart) { EsbConnector connector = (EsbConnector) ((Node) ((EditPart) child).getModel()).getElement(); Rectangle point = currentLocation.get(connector); if (point != null) { rectCopy.width = Math.max(rectCopy.width, point.x + 50); pointY += (point.y + point.height) + 20; rectCopy.height = Math.max(rectCopy.height, pointY); } if (((complexFiguredAbstractMediator) editpart).reversed) { rect.width += 50; // no effect on width } } } } rect.x = location.x; rect.y = location.y; SetBoundsCommand sbc = new SetBoundsCommand( gEditpart.getEditingDomain(), "change location", new EObjectAdapter((View) editpart.getModel()), rect); nodeBounds.put((EsbNode) ((View) editpart.getModel()).getElement(), rect.getCopy()); gEditpart.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(sbc)); location.x = location.x + rectCopy.width + 40; location.height = Math.max(location.height, rectCopy.height); } }
/* * (non-Javadoc) * * @see org.eclipse.papyrus.layout.LayouttoolInterface#isNode(org.eclipse.gef.EditPart) */ public boolean isNode(EditPart element) { if (element.getModel() instanceof Node) { if (GMFLayoutAreaCreator.getArea() != null && element.equals(GMFLayoutAreaCreator.getArea())) { return false; } return true; } return false; }
void retrieveParameters(Request request) { EditPart editPart = getTargetEditPart(request); contract = (Contract) ((View) editPart.getModel()).getElement(); mEditingDomain = ((IGraphicalEditPart) editPart).getEditingDomain(); IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); diagramFile = ((IFileEditorInput) activeEditor.getEditorInput()).getFile(); project = ((IResource) diagramFile).getProject(); }
/** * ChangeCombinedFragmentConstraintCommand * * @param editPart * @param constraint */ public ChangeCombinedFragmentConstraintCommand(EditPart editPart, Rectangle constraint) { this.notationNode = (NotationNode) editPart.getModel(); this.oldConstraint = new Rectangle( notationNode.getX(), notationNode.getY(), notationNode.getWidth(), notationNode.getHeight()); this.newConstraint = constraint; }
/* * (non-Javadoc) * * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled() */ @Override protected boolean calculateEnabled() { node = null; List<?> selectedObjects = getSelectedObjects(); if (selectedObjects.size() != 1) { return false; } Object selectedObject = selectedObjects.get(0); if ((selectedObject instanceof EditPart)) { EditPart editpart = (EditPart) selectedObject; Object selectedModel = editpart.getModel(); if ((selectedModel instanceof Unit && !(selectedModel instanceof ConditionalUnitPart))) { transUnit = (Unit) editpart.getModel(); return true; } if (selectedModel instanceof EContainerDescriptor && editpart.getAdapter(Parameter.class) != null) { transUnit = (Unit) ((EContainerDescriptor) selectedModel).getContainer(); return true; } if (editpart.getModel() instanceof Node && ((editpart.getParent() instanceof LhsRhsTreeEditPart) || (editpart instanceof RuleNodeEditPart && (editpart.getParent() instanceof LhsRhsEditPart)))) { node = (Node) editpart.getModel(); transUnit = (Unit) node.getGraph().eContainer(); return ParameterUtil.getParameter(node) == null; } } return false; }
/** * ShiftLifeLineNodeCommand * * @param editPart * @param constraint * @param lifeLineNodeList * @param diagram */ public ShiftLifeLineNodeCommand( EditPart editPart, Rectangle constraint, List<LifeLineNode> lifeLineNodeList, Diagram diagram) { this.node = (AbstractNode) editPart.getModel(); this.lifeLineNodeList = lifeLineNodeList; this.oldX = node.getX(); this.newX = constraint.x; this.diagram = diagram; }
/** * Called when the request for a type is not in the cache. It will resolve the request by * iterating the elements in the last selection, searching for the requested type. The result will * be cached and returned * * @param type the selected type * @return a not null list of the elements of the desired type or of one of its subclasses */ private ModelPartPair createCacheForModelType(Class<?> type) { ModelPartPair result = new ModelPartPair(); for (EditPart part : lastModelSelection.parts) { if (type.isInstance(part.getModel())) { result.add(part); } else if (!allowDishomogeneousSelection) { return new ModelPartPair(); } } return result; }
@Override protected Command createChangeConstraintCommand(EditPart child, Object constraint) { AbstractLayoutCommand command = null; if (child instanceof UMLClassFigurePart) command = new ClassChangeLayoutCommand(); else if (child instanceof CircleFigureEditPart) command = new CircleChangeLayoutCommand(); else if (child instanceof RectangleFigureEditPart) command = new RectangleChangeLayoutCommand(); else if (child instanceof LineFigureEditPart) command = new LineChangeLayoutCommand(); command.setModel(child.getModel()); command.setConstraint((Rectangle) constraint); return command; }
/** @generated */ protected void refreshVisibility() { Object model = null; EditPart ep = this; while (!(model instanceof View) && ep != null) { model = ep.getModel(); ep = ep.getParent(); } boolean realIsVisible = ((View) model).isVisible(); realIsVisible &= isVisibleByPreferences(); if (model instanceof View) setVisibility(realIsVisible); }
/** @generated */ public static View findView( DiagramEditPart diagramEditPart, EObject targetElement, LazyElement2ViewMap lazyElement2ViewMap) { boolean hasStructuralURI = false; if (targetElement.eResource() instanceof XMLResource) { hasStructuralURI = ((XMLResource) targetElement.eResource()).getID(targetElement) == null; } View view = null; LinkedList<EditPart> editPartHolder = new LinkedList<EditPart>(); if (hasStructuralURI && !lazyElement2ViewMap.getElement2ViewMap().isEmpty()) { view = lazyElement2ViewMap.getElement2ViewMap().get(targetElement); } else if (findElementsInDiagramByID(diagramEditPart, targetElement, editPartHolder) > 0) { EditPart editPart = editPartHolder.get(0); view = editPart.getModel() instanceof View ? (View) editPart.getModel() : null; } return (view == null) ? diagramEditPart.getDiagramView() : view; }
@Override protected Command createAddCommand(EditPart child, EditPart after) { int index = getHost().getChildren().indexOf(after); TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain(); AddCommand command = new AddCommand( editingDomain, new EObjectAdapter((View) getHost().getModel()), new EObjectAdapter((View) child.getModel()), index); return new ICommandProxy(command); }
@Override protected EditPolicy createChildEditPolicy(final EditPart child) { final View childView = (View) child.getModel(); if (UMLVisualIDRegistry.getVisualID(childView) == this.labelVisualId) { return new ExternalLabelPrimaryDragRoleEditPolicy(); } EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); } return result; }
/** @return the selected pictogram element. */ protected PictogramElement getSelectedPictogramElement() { if (getSelection() instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) getSelection(); Object firstElement = structuredSelection.getFirstElement(); if (firstElement instanceof PictogramElement) { return (PictogramElement) firstElement; } EditPart editPart = null; if (firstElement instanceof EditPart) { editPart = (EditPart) firstElement; } else if (firstElement instanceof IAdaptable) { editPart = (EditPart) ((IAdaptable) firstElement).getAdapter(EditPart.class); } if (editPart != null && editPart.getModel() instanceof PictogramElement) { return (PictogramElement) editPart.getModel(); } } return null; }
/** * return commands to transform a binary association to n-ary association or allow adding * branches. * * @param createConnectionViewAndElementRequest the create connection view and element request * @param command that will contains subcommands * @return the command */ public Command getCommand( CreateConnectionViewAndElementRequest createConnectionViewAndElementRequest, Command command) { // 0. get source and target type command = new CompoundCommand(); EditPart sourceEditPart = createConnectionViewAndElementRequest.getSourceEditPart(); EditPart targetEditPart = createConnectionViewAndElementRequest.getTargetEditPart(); // if the the source or the target is a node association the goal is // to create only one branch if ((((View) sourceEditPart.getModel()).getType() == "" + AssociationNodeEditPart.VISUAL_ID)) { return getBranchAssociationCommand(createConnectionViewAndElementRequest, command); } if ((((View) targetEditPart.getModel()).getType() == "" + AssociationNodeEditPart.VISUAL_ID)) { return UnexecutableCommand.INSTANCE; } // the source or the target has to be different of a dependency branch if (sourceEditPart instanceof AssociationBranchEditPart) { GraphicalEditPart associationNodeEditPart = lookForAssociationNodeEditPart((AssociationBranchEditPart) sourceEditPart); if (associationNodeEditPart != null) { createConnectionViewAndElementRequest.setSourceEditPart(associationNodeEditPart); return getBranchAssociationCommand(createConnectionViewAndElementRequest, command); } else { return UnexecutableCommand.INSTANCE; } } // the source or the target has to be different of a dependency branch if (targetEditPart instanceof AssociationBranchEditPart) { return UnexecutableCommand.INSTANCE; } // if not this a transformation of simple dependency to multiDependency return getAssociationToMultiAssociationCommand(createConnectionViewAndElementRequest, command); }