/** * @param model * @param node * @return root node of object */ public static Object getRoot(GraphModel model, Object node) { Object result = node; Object parent = null; while ((parent = model.getParent(result)) != null) { result = parent; } return result; }
/** * @param model * @param parent * @param node * @return true if parent is a parent of node */ public static boolean isParentOf(GraphModel model, Object parent, Object node) { Object temp = node; while ((temp = model.getParent(temp)) != null) { if (parent == temp) { return true; } } return false; }
/** * Returns true if the specified child has an ancestor in parents. */ public static boolean hasAncestorIn(GraphModel model, Set parents, Object child) { Object parent = model.getParent(child); while (parent != null) { if (parents.contains(parent)) return true; parent = model.getParent(parent); } return false; }
protected Collection getParentPorts(Object cell) { // does nothing if a parent is already visible Object parent = graphModel.getParent(cell); while (parent != null) { if (isVisible(parent)) return null; parent = graphModel.getParent(parent); } // Else returns the parent and all ports parent = graphModel.getParent(cell); Collection collection = getPorts(parent); collection.add(parent); return collection; }
/** * Returns the roots in <code>cells</code> by checking if their parent is * <code>null</code>. This implementation only uses the GraphModel * interface. This method never returns null. */ public static Object[] getRoots(GraphModel model, Object[] cells) { List roots = new ArrayList(); if (cells != null) { for (int i = 0; i < cells.length; i++) { if (model.getParent(cells[i]) == null) { roots.add(cells[i]); } } } return roots.toArray(); }
protected CellView getVisibleParent(GraphModel model, CellMapper mapper, Object port) { CellView view = null; do { view = mapper.getMapping(port, false); port = model.getParent(port); } while (view == null && port != null); return view; }
/** * Returns the source vertex of the edge by calling getParent on getSource * on the specified model. */ public static Object getSourceVertex(GraphModel model, Object edge) { if (model != null) return model.getParent(model.getSource(edge)); return null; }
public static DefaultGraphCell getOtherExtremeFromAryEdge(GraphModel m,DefaultEdge de){ DefaultPort sourcePort = (DefaultPort) ( (Edge) de).getSource(); Object source = m.getParent(sourcePort); Port targetPort = (Port) ( (Edge) de).getTarget(); Object target = m.getParent(targetPort); if (!(source instanceof NAryEdge)) { return (DefaultGraphCell) source; } if (!(target instanceof NAryEdge)) { return (DefaultGraphCell) target; } return null; }
/** * Returns the target vertex of the edge by calling getParent on getTarget * on the specified model. */ public static Object getTargetVertex(GraphModel model, Object edge) { if (model != null) return model.getParent(model.getTarget(edge)); return null; }
public static ingenias.editor.cell.NAryEdge getNAryEdge(GraphModel m,DefaultEdge de){ DefaultPort sourcePort = (DefaultPort) ( (Edge) de).getSource(); Object source = m.getParent(sourcePort); Port targetPort = (Port) ( (Edge) de).getTarget(); Object target = m.getParent(targetPort); if (source instanceof NAryEdge) { return (NAryEdge) source; } if (target instanceof NAryEdge) { return (NAryEdge) target; } return null; }
public Object[] getRelacionesPosibles(Port source, Port target) { // The general getRelacionesPosibles method only admits a GraphCell[] parameter. GraphCell sourceGraphCell = (GraphCell) this.getModel().getParent(source); GraphCell targetGraphCell = (GraphCell) this.getModel().getParent(target); // The general getRelacionesPosibles method is invoked. return this.getPossibleRelationships(new GraphCell[]{sourceGraphCell, targetGraphCell}); }
/** * Checks if the port or one of its parents is visible. */ protected boolean hasVisibleParent(Object cell, Set invisible) { boolean isVisible = false; do { isVisible = (invisible == null || !invisible.contains(cell)) ? isVisible(cell) : false; cell = getModel().getParent(cell); } while (cell != null && !isVisible); return isVisible; }
public int compare(Object c1, Object c2) { Object p1 = model.getParent(c1); Object p2 = model.getParent(c2); int index1 = (p1 == null) ? model.getIndexOfRoot(c1) : model .getIndexOfChild(p1, c1); int index2 = (p2 == null) ? model.getIndexOfRoot(c2) : model .getIndexOfChild(p2, c2); return new Integer(index1).compareTo(new Integer(index2)); }
/** * Returns the incoming or outgoing edges for cell. Cell should be a port or * a vertex. */ public static Object[] getEdges(GraphModel model, Object cell, boolean incoming) { Set edges = DefaultGraphModel.getEdges(model, new Object[] { cell }); // Base initial capacity on size of set, it can't be any larger ArrayList result = new ArrayList(edges.size()); Iterator it = edges.iterator(); while (it.hasNext()) { Object edge = it.next(); // TODO: Handle edge groups Object port = (incoming) ? model.getTarget(edge) : model .getSource(edge); Object parent = model.getParent(port); if (port == cell || parent == cell) result.add(edge); } return result.toArray(); }
/** * Empties the current selection. If this represents a change in the current * selection, the selection listeners are notified. */ public void clearSelection() { if (selection != null) { Vector change = new Vector(); Iterator it = cellStates.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Object cell = entry.getKey(); while (cell != null) { change.addElement(new CellPlaceHolder(cell, false)); cell = graph.getModel().getParent(cell); } } selection.clear(); cellStates.clear(); if (change.size() > 0) notifyCellChange(change); } }
protected boolean isDescendant(CellView parentView, CellView childView) { if (parentView == null || childView == null) { return false; } Object parent = parentView.getCell(); Object child = childView.getCell(); Object ancestor = child; do { if (ancestor == parent) return true; } while ((ancestor = graphModel.getParent(ancestor)) != null); return false; }
/** * @param model * @param node * @return all the edges leaving the given <code>node</code> */ public static Set getOutgoingEdges(GraphModel model, Object node) { Set result = new HashSet(); Set edges = DefaultGraphModel.getEdges(model, new Object[] { node }); Iterator it = edges.iterator(); while (it.hasNext()) { Object edge = it.next(); if (!DefaultGraphModel.isGroup(model, edge)) { Object source = model.getSource(edge); Object parent = model.getParent(source); if (source == node || parent == node) result.add(edge); } } return result; } }
/** * Returns the vertex that is connected to the target end of the specified * edge * * @param edge * the reference edge * @return any vertex connected as the target the specified edge */ public Object getTarget(Object edge) { Object cell = null; cell = DefaultGraphModel.getTargetVertex(model, edge); if (cell != null && !isVertex(cell)) { // Check to see if the edge has been promoted if (edgePromotion) { while (model.getParent(cell) != null && !isVertex(cell)) { cell = model.getParent(cell); } } else { return null; } if (isVertex(cell)) { return cell; } else { return null; } } return cell; }
/** * Removes the specified cells from the selection. * * @param cells * the cells to remove from the current selection */ public void removeSelectionCells(Object[] cells) { if (cells != null) { Vector change = new Vector(); for (int i = 0; i < cells.length; i++) { if (cells[i] != null) { boolean removed = deselect(cells[i]); if (removed) { change.addElement(new CellPlaceHolder(cells[i], false)); Object parent = graph.getModel().getParent(cells[i]); if (parent != null) change .addElement(new CellPlaceHolder(parent, false)); } } } if (change.size() > 0) notifyCellChange(change); } }
/** * Invoked after a cell has been selected in the mouseReleased method. * This can be used to do something interesting if the cell was already * selected, in which case this implementation selects the parent. * Override if you want different behaviour, such as start editing. */ protected void postProcessSelection(MouseEvent e, Object cell, boolean wasSelected) { if (wasSelected && graph.isCellSelected(cell) && e.getModifiers() != 0) { Object parent = cell; Object nextParent = null; while (((nextParent = graphModel.getParent(parent)) != null) && graphLayoutCache.isVisible(nextParent)) parent = nextParent; selectCellForEvent(parent, e); lastFocus = focus; focus = graphLayoutCache.getMapping(parent, false); } }