/* * (non-Javadoc) * * @see * org.eclipse.gef.EditPartFactory#createEditPart(org.eclipse.gef.EditPart, * java.lang.Object) */ public EditPart createEditPart(EditPart context, Object model) { EditPart ret = null; if (model instanceof Diagram) { ret = new DiagramTreeEditPart(id, (Diagram) model); } else if (context instanceof AbstractGraphicsTreeEditPart) { EditPart root = context; while (root.getParent() != null) root = root.getParent(); DiagramTreeEditPart dep = (DiagramTreeEditPart) root.getChildren().get(0); if (model instanceof RootElement) { ret = new RootElementTreeEditPart(dep, (RootElement) model); } else if (model instanceof FlowElement) { ret = new FlowElementTreeEditPart(dep, (FlowElement) model); } else if (model instanceof BaseElement) { ret = new BaseElementTreeEditPart(dep, (BaseElement) model); } else if (model instanceof BPMNDiagram) { ret = new Bpmn2DiagramTreeEditPart(dep, (BPMNDiagram) model); } else if (model instanceof BPMNShape) { ret = new Bpmn2ShapeTreeEditPart(dep, (BPMNShape) model); } else if (model instanceof BPMNEdge) { ret = new Bpmn2EdgeTreeEditPart(dep, (BPMNEdge) model); } } return ret; }
/** * Steps up the parent EditPart hierarchy until the parent is type of an {@link IPrimaryEditPart}. * If the given EditPart is already a {@link IPrimaryEditPart} it is directly returned. * * @param editPart - EditPart to start from * @return The EditPart directly or one of the parent EditParts or {@code NULL} if none of the * parents match IPrimaryEditPart */ protected IPrimaryEditPart getPrimaryEditPart(EditPart editPart) { IPrimaryEditPart ret = null; if (editPart instanceof IPrimaryEditPart) { return (IPrimaryEditPart) editPart; } else if (editPart.getParent() != null) { ret = getPrimaryEditPart(editPart.getParent()); } return ret; }
/** * This method returns the target RegionEditPart if any, or returns null. * * @return the target RegionEditPart */ public RegionEditPart getTargetRegionEditPart() { EditPart ep = getTargetEditPart(); if ((ep != null) && (ep instanceof RegionCompartmentEditPart) && ep.getParent().getParent().equals(regionEP.getParent())) { return (RegionEditPart) ep.getParent(); } return null; }
/** * Returns the primary edit policy * * @return THe primary edit policy */ private MarkerEventListenerEditPolicy getPrimaryEditPolicy() { EditPart current = getHost(); EditPart parent = current.getParent(); while (parent != null && semanticCompareEditParts(parent, getHost())) { current = parent; parent = parent.getParent(); } return (MarkerEventListenerEditPolicy) current.getEditPolicy(ROLE); }
private GraphElement getTargetElement() { if (selectedPart instanceof EventTreeEditPart) { return (GraphElement) selectedPart.getParent().getModel(); } else { return (GraphElement) selectedPart.getModel(); } }
/** * Test if the selected item is a node. * * @return true / false */ private boolean canPerformAction() { if (getSelectedObjects().isEmpty()) { return false; } List parts = getSelectedObjects(); if (parts.size() == 1) { Object o = parts.get(0); if (!(o instanceof NodePart)) { return false; } NodePart part = (NodePart) o; if (!(part.getModel() instanceof INode)) { return false; } node = (Node) part.getModel(); EditPart parentPart = part.getParent(); while (!(parentPart instanceof ProcessPart)) { parentPart = parentPart.getParent(); } if (!(parentPart instanceof ProcessPart)) { return false; } process = (IProcess) ((ProcessPart) parentPart).getModel(); setText(Messages.getString("PropertiesContextAction.Properties")); // $NON-NLS-1$ } return true; }
@Override public void mousePressed(MouseEvent me) { EditPart root = editPart; while (root.getParent() instanceof BlockExtendedEditPart) { root = root.getParent(); } // getting compartment holder figure BlockExtendedEditPart blockExtendedEditPart = (BlockExtendedEditPart) root; BlockFigure primaryShape = blockExtendedEditPart.getPrimaryShape(); RectangleFigure rectangleFigure = (RectangleFigure) primaryShape.getChildren().get(1); // based on visibility status, hide or show the compartment if (rectangleFigure.isVisible()) { hide(rectangleFigure, blockExtendedEditPart); } else { show(rectangleFigure, blockExtendedEditPart); } }
/* * (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; }
/** @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); }
/** @return the diagram bordered node edit part. */ private IDiagramBorderNodeEditPart getBorderedNodeEditPart() { EditPart current = this; IDiagramBorderNodeEditPart borderNodeEditPart = null; while (current != null && borderNodeEditPart == null) { if (current instanceof IDiagramBorderNodeEditPart) { borderNodeEditPart = (IDiagramBorderNodeEditPart) current; } current = current.getParent(); } return borderNodeEditPart; }
private boolean isMediationFlowInFaultSequence(IGraphicalEditPart part) { EditPart temp = part; while ((temp != null) && ((!(temp instanceof ProxyServiceFaultContainerEditPart)))) { temp = temp.getParent(); } if (temp instanceof ProxyServiceFaultContainerEditPart) { return true; } else { return false; } }
/* * (non-Javadoc) * * @see org.eclipse.papyrus.layout.LayouttoolInterface#getLayoutArea(org.eclipse.gef.EditPart[]) */ public Rectangle getLayoutArea(EditPart[] element) { Rectangle bounds; if (GMFLayoutAreaCreator.getBounds() != null) { bounds = GMFLayoutAreaCreator.getBounds(); GMFLayoutAreaCreator.deleteLayoutArea(); return bounds; } for (EditPart e : element) { if (e.getModel() instanceof Node) { if (e.getParent() instanceof GraphicalEditPart) { GraphicalEditPart gep = (GraphicalEditPart) e.getParent(); bounds = gep.getFigure().getBounds(); bounds.x = 0; bounds.y = 0; return bounds; } } } return new Rectangle(0, 0, 1000, 1000); }
private static Iterator<EsbNode> getNodeIterator(LinkedList<EsbNode> nodeList) { Iterator<EsbNode> iterator = nodeList.iterator(); if (nodeList.size() > 0) { EditPart editpart = getEditpart(nodeList.getFirst()); if (editpart != null) { if (editpart.getParent() instanceof AbstractMediatorCompartmentEditPart) { if (editpart.getParent().getParent() instanceof ShapeNodeEditPart) { EditPart container = editpart.getParent().getParent().getParent(); if (container instanceof complexFiguredAbstractMediator) { if (((complexFiguredAbstractMediator) container).reversed) { iterator = nodeList.descendingIterator(); } } } } } } return iterator; }
/** @generated */ private static int findElementsInDiagramByID( DiagramEditPart diagramPart, EObject element, List<EditPart> editPartCollector) { IDiagramGraphicalViewer viewer = (IDiagramGraphicalViewer) diagramPart.getViewer(); final int intialNumOfEditParts = editPartCollector.size(); if (element instanceof View) { // support notation element lookup EditPart editPart = (EditPart) viewer.getEditPartRegistry().get(element); if (editPart != null) { editPartCollector.add(editPart); return 1; } } String elementID = EMFCoreUtil.getProxyID(element); @SuppressWarnings("unchecked") List<EditPart> associatedParts = viewer.findEditPartsForElement(elementID, IGraphicalEditPart.class); // perform the possible hierarchy disjoint -> take the top-most parts only for (EditPart nextPart : associatedParts) { EditPart parentPart = nextPart.getParent(); while (parentPart != null && !associatedParts.contains(parentPart)) { parentPart = parentPart.getParent(); } if (parentPart == null) { editPartCollector.add(nextPart); } } if (intialNumOfEditParts == editPartCollector.size()) { if (!associatedParts.isEmpty()) { editPartCollector.add(associatedParts.get(0)); } else { if (element.eContainer() != null) { return findElementsInDiagramByID(diagramPart, element.eContainer(), editPartCollector); } } } return editPartCollector.size() - intialNumOfEditParts; }
@Override public void setSelected(int value) { final EditPart parent = this.getParent(); final NormalColumnFigure figure = (NormalColumnFigure) this.getFigure(); Color backgroundColor = null; Color foregroundColor = null; boolean isSelected = false; if (value != 0 && parent != null && parent.getParent() != null) { List selectedEditParts = this.getViewer().getSelectedEditParts(); if (selectedEditParts == null || selectedEditParts.size() != 1) { return; } backgroundColor = ColorConstants.titleBackground; foregroundColor = ColorConstants.titleForeground; isSelected = true; } final NormalColumn normalColumn = (NormalColumn) this.getModel(); final ColumnHolder columnHolder = normalColumn.getColumnHolder(); if (columnHolder instanceof ColumnGroup) { if (parent != null) { for (Object child : parent.getChildren()) { final GraphicalEditPart childEditPart = (GraphicalEditPart) child; if (childEditPart.getModel() instanceof NormalColumn) { final NormalColumn column = (NormalColumn) childEditPart.getModel(); if (column.getColumnHolder() == columnHolder) { setGroupColumnFigureColor( (TableViewEditPart) parent, (ColumnGroup) columnHolder, isSelected); } } } } } else { figure.setBackgroundColor(backgroundColor); figure.setForegroundColor(foregroundColor); selected = isSelected; } super.setSelected(value); }
@Override protected Command createMoveChildCommand(EditPart child, EditPart after) { int newIndex; int displacement; // TODO: needs to be improved. int childIndex = getHost().getChildren().indexOf(child); int afterIndex = getHost().getChildren().indexOf(after); if (afterIndex == -1) { newIndex = getHost().getChildren().size() - 1; displacement = newIndex - childIndex; } else { newIndex = afterIndex; displacement = afterIndex - childIndex; if (childIndex <= afterIndex) { newIndex--; displacement--; } } TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain(); RepositionEObjectCommand command = new CompartmentRepositionEObjectCommand( child, editingDomain, "", (EList) ((View) child.getParent().getModel()).getElement().eGet(feature), ((View) child.getModel()).getElement(), displacement, newIndex) { public CommandResult doExecuteWithResult( IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException { // remove target feedback after dropping eraseLayoutTargetFeedback(null); return super.doExecuteWithResult(progressMonitor, info); } }; return new ICommandProxy(command); }
/* * (non-Javadoc) * * @see org.eclipse.jst.pagedesigner.actions.link.ILinkCreator#makeLinkElement(org.eclipse.gef.EditPart, * org.eclipse.jst.pagedesigner.viewer.DesignRange) */ public Element makeLinkElement(EditPart part, DesignRange range) { if (part instanceof TextEditPart) { Text middleNode = LinkUtil.splitDomText(part, range); EditPart parent = part.getParent(); Node parentNode = (Node) parent.getModel(); Document doc = (parentNode instanceof Document) ? (Document) parentNode : (parentNode.getOwnerDocument()); Element htmlLink = doc.createElement(IHTMLConstants.TAG_A); htmlLink.setAttribute(ICSSPropertyID.ATTR_HREF, ""); // $NON-NLS-1$ Text text = doc.createTextNode(middleNode.getNodeValue()); htmlLink.appendChild(text); parentNode.replaceChild(htmlLink, middleNode); return htmlLink; } return null; }
protected void addChildVisual(EditPart childEditPart, int index) { refreshOutputConnector( ((EntitlementMediatorEditPart) childEditPart.getParent().getParent().getParent().getParent())); super.addChildVisual(childEditPart, -1); }
/** @not-generated */ @Override public void refresh() { removeDecoration(); View view = (View) getDecoratorTarget().getAdapter(View.class); Resource viewResource = null; if (view != null) { viewResource = view.eResource(); } if (viewResource == null) { return; } EditPart editPart = (EditPart) getDecoratorTarget().getAdapter(EditPart.class); if (editPart == null || editPart.getParent() == null || editPart.getViewer() == null) { return; } // query for all the validation markers of the current resource String elementId = SiriusGMFHelper.getViewId(view); if (elementId == null) { return; } // Directly retrieve the main Session resource // (session.getSessionResource()) as we know we put the marker on // it. Session currentSession = null; ResourceSet currentRs = viewResource.getResourceSet(); for (Session session : SessionManager.INSTANCE.getSessions()) { if (currentRs == session.getTransactionalEditingDomain().getResourceSet()) { currentSession = session; break; } } Resource markedResource = currentSession == null ? null : currentSession.getSessionResource(); IResource resource = WorkspaceSynchronizer.getFile(markedResource); if (resource == null || !resource.exists()) { return; } IMarker[] markers = null; try { markers = resource.findMarkers(MARKER_TYPE, true, IResource.DEPTH_INFINITE); } catch (CoreException e) { DiagramPlugin.getDefault() .logError(Messages.StatusDecorator_validationMarkersFailureMsg, e); } if (markers == null || markers.length == 0) { return; } int severity = IMarker.SEVERITY_INFO; IMarker foundMarker = null; Label toolTip = null; for (int i = 0; i < markers.length; i++) { IMarker marker = markers[i]; String attribute = marker.getAttribute( org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, ""); // $NON-NLS-1$ if (attribute.equals(elementId)) { int nextSeverity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO); Image nextImage = getImage(nextSeverity); if (foundMarker == null) { foundMarker = marker; toolTip = new Label( marker.getAttribute(IMarker.MESSAGE, ""), // $NON-NLS-1$ nextImage); } else { if (toolTip.getChildren().isEmpty()) { Label comositeLabel = new Label(); FlowLayout fl = new FlowLayout(false); fl.setMinorSpacing(0); comositeLabel.setLayoutManager(fl); comositeLabel.add(toolTip); toolTip = comositeLabel; } toolTip.add( new Label( marker.getAttribute(IMarker.MESSAGE, ""), // $NON-NLS-1$ nextImage)); } severity = (nextSeverity > severity) ? nextSeverity : severity; } } if (foundMarker == null) { return; } // add decoration if (editPart instanceof org.eclipse.gef.GraphicalEditPart) { IDecoration decoration = null; if (view instanceof Diagram) { // There is not yet defined decorator for a diagram } else if (view instanceof Edge) { decoration = getDecoratorTarget().addConnectionDecoration(getImage(severity), 50, true); } else { int margin = -1; margin = MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart) editPart).getFigure()) .DPtoLP(margin); decoration = getDecoratorTarget() .addShapeDecoration( getImage(severity), IDecoratorTarget.Direction.NORTH_EAST, margin, true); } if (decoration != null) { setDecoration(decoration); // getDecaration() returns a {@link Decoration} instead of a // {@link IDecoration} getDecoration().setToolTip(toolTip); } } }
protected EditPart getEditPart(EditPart parent, Object object) { EditPart result = null; for (Iterator i = parent.getChildren().iterator(); i.hasNext(); ) { EditPart editPart = (EditPart) i.next(); if (editPart.getModel() == object && !(editPart instanceof IHolderEditPart) && !(editPart instanceof RootContentEditPart)) { result = editPart; break; } } if (result == null) { for (Iterator i = parent.getChildren().iterator(); i.hasNext(); ) { EditPart editPart = getEditPart((EditPart) i.next(), object); if (editPart != null) { // First check to see if there is a selection ISelection currentSelection = getSelection(); // If there is a selection then we will try to select // the target edit part that is one of its children // This is handy when you add an element to a structured edit part // then you want to select the element immediately and put it in // direct edit mode if (currentSelection != null) { if (currentSelection instanceof StructuredSelection) { EditPart targetStructureEditPart = (EditPart) ((StructuredSelection) currentSelection).getFirstElement(); if (targetStructureEditPart != null) { while (targetStructureEditPart != null) { if (targetStructureEditPart instanceof StructureEditPart) { break; } targetStructureEditPart = targetStructureEditPart.getParent(); } } EditPart potentialEditPartToSelect = editPart; while (potentialEditPartToSelect != null) { if (potentialEditPartToSelect instanceof StructureEditPart) { break; } potentialEditPartToSelect = potentialEditPartToSelect.getParent(); } // If we found a potential edit part to select then return it // OR, if there is no target found, then we should just return // the edit part we found if (potentialEditPartToSelect == targetStructureEditPart || potentialEditPartToSelect == null || targetStructureEditPart == null) { result = editPart; break; } } } else // Otherwise just find the first one and return { result = editPart; break; } } } } return result; }
/** * DOC talend Comment method "getTemplate". * * @param event * @return the validate drag able node list */ @Override protected Object getTemplate(DragSourceEvent event) { final RootEditPart rootEditPart = getViewer().getRootEditPart(); if (rootEditPart instanceof AbstractGraphicalEditPart) { AbstractGraphicalEditPart graphicPart = (AbstractGraphicalEditPart) rootEditPart; final IFigure figure = graphicPart.getFigure(); final IFigure findFigureAt = figure.findFigureAt(new Point(event.x, event.y)); if (findFigureAt instanceof ISash) { return findFigureAt; } } List<EditPart> filtedSelection = new ArrayList<EditPart>(); for (Object part : getViewer().getSelectedEditParts()) { if (part instanceof TreeNodeEditPart || part instanceof VarNodeEditPart) { filtedSelection.add((EditPart) part); } } if (filtedSelection == null || filtedSelection.isEmpty()) { return null; } List toTransfer = new ArrayList(); TransferdType type = null; List<TableEntityPart> partList = new ArrayList<TableEntityPart>(); EditPart lastSelection = filtedSelection.get(filtedSelection.size() - 1); if (lastSelection instanceof TreeNodeEditPart && !(lastSelection instanceof OutputTreeNodeEditPart)) { type = TransferdType.INPUT; } else if (lastSelection instanceof VarNodeEditPart) { type = TransferdType.VAR; } if (type != null) { if (filtedSelection.size() > 1) { partList.addAll(lastSelection.getParent().getChildren()); Map<EditPart, Integer> partAndIndex = new HashMap<EditPart, Integer>(); if (type == TransferdType.INPUT) { for (EditPart treePart : filtedSelection) { if (!XmlMapUtil.isDragable((TreeNode) treePart.getModel())) { return null; } } MapperTablePart abstractInOutTreePart = MapperUtils.getMapperTablePart((TableEntityPart) lastSelection); if (abstractInOutTreePart != null) { partList = MapperUtils.getFlatChildrenPartList(abstractInOutTreePart); } } else { partList.addAll(lastSelection.getParent().getChildren()); } for (EditPart selected : filtedSelection) { int indexOf = partList.indexOf(selected); if (indexOf != -1) { partAndIndex.put(selected, indexOf); int index = 0; for (int i = 0; i < toTransfer.size(); i++) { if (indexOf > partAndIndex.get(toTransfer.get(i))) { index = i + 1; } } toTransfer.add(index, selected); } } } else { if (lastSelection.getModel() instanceof TreeNode && !XmlMapUtil.isDragable((TreeNode) lastSelection.getModel())) { return null; } toTransfer.add(lastSelection); } return new TransferedObject(toTransfer, type); } return null; }
@Override public void execute() { // configure the request EditPart source = request.getSourceEditPart(); EditPart target = request.getTargetEditPart(); PointList list = feedback.getPoints(); DiagramEditPart diagramEditPart = null; if (source.getParent() instanceof DiagramEditPart) { diagramEditPart = (DiagramEditPart) source.getParent(); } else if (source instanceof DiagramEditPart) { diagramEditPart = (DiagramEditPart) source; } else { if (source.getParent().getParent() instanceof DiagramEditPart) { diagramEditPart = (DiagramEditPart) source.getParent().getParent(); } } if (diagramEditPart == null) { return; } if (!(source instanceof DiagramEditPart || target instanceof DiagramEditPart)) { // one must be whitespace, we make it the target request.setTargetEditPart(diagramEditPart); // additionally we must cut the drawn connection // in half to share room with the element that will // be auto-created PointList newList = new PointList(); newList.addPoint(list.getFirstPoint()); if (list.size() == 4) { // rectilinear routing will have a three points newList.addPoint(list.getPoint(1)); } newList.addPoint(list.getMidpoint()); feedback.setPoints(newList); } // create the active tool's element first CreateConnectionCommand command = new CreateConnectionCommand(request, feedback); command.execute(); Connector_c newConnector = command.result; if (newConnector == null) { return; } // we need to now refresh the diagram to get the new edit part source.refresh(); source.getParent().refresh(); GraphicalEditPart newPart = (GraphicalEditPart) source.getViewer().getEditPartRegistry().get(newConnector); // transfer the feedback connection points to the newly created // edit part ((Connection) newPart.getFigure()).setPoints(feedback.getPoints().getCopy()); // now adjust the request for the new element to be created for each // terminal specification that requires auto-creation createElementForTerminalSpec( autoStartSpec, ((NonRootModelElement) diagramEditPart.getModel()).getModelRoot(), list, newPart, target, diagramEditPart); createElementForTerminalSpec( autoEndSpec, ((NonRootModelElement) diagramEditPart.getModel()).getModelRoot(), list, newPart, target, diagramEditPart); }
/** * Sorts the editparts in the tree In this tree, we have the selected editparts. Moreover, we add * the intermediate packages, even if they aren't selected. These intermediate packages are used * to determine the final position of their parents, if the reference is inside on of these * packages * * @param editparts the editparts to sort */ public void buildTree(List<EditPart> editparts) { List<EditPart> parentsList; if (editparts.size() >= 2) { // we build the tree for (EditPart currentEP : editparts) { parentsList = new ArrayList<EditPart>(); EditPart parent = currentEP; EditPartTree grandFatherTree = this; int i = 0; while (parent != null) { if (this.contains(parent)) { grandFatherTree = this.getTree(parent); break; // on sort du while } else { // we add all the parent in this list! /* * we don't add the parent if it's a comparment , except * if the parent is the selected element (property, * enumeration literal...), of course, a property or a * enumeration literal can't move in there compartment * (in class diagram) but this choice allows avoid some * NullPointerException. (see bug 317691) */ if (!(parent instanceof CompartmentEditPart) || (parent instanceof CompartmentEditPart && parent == currentEP)) { if (!(parent instanceof RootEditPart)) { if (!(parent.getParent() instanceof RootEditPart)) { parentsList.add(i, parent); i++; } } } } parent = parent.getParent(); } // We add all the node in the rootTree EditPartTree childTree = createChildrenTree(editparts, parentsList); // we add the node to the tree if (childTree != null) { grandFatherTree.add(childTree); } } // we precise which element is the reference (the last selected // element) this.getTree(editparts.get(editparts.size() - 1)).setIsReference(true); /* * we precise for each branch the first selected element it's this * element (and its brothers) which are really align on the * reference */ Enumeration childrenEnum = this.children(); while (childrenEnum.hasMoreElements()) { EditPartTree currentTree = (EditPartTree) childrenEnum.nextElement(); for (int i = 0; i < editparts.size(); i++) { if (currentTree.contains(editparts.get(i))) { currentTree.getTree(editparts.get(i)).setFirstSelectedElement(true); break; } } } postBuildOperations(editparts); } }