001: /* PEGraphSelectionModel.java
002: *
003: * Authors:
004: * Stefanovic Nenad chupo@iis.ns.ac.yu
005: * Bojanic Sasa sasaboy@neobee.net
006: * Puskas Vladimir vpuskas@eunet.yu
007: * Pilipovic Goran zboniek@uns.ac.yu
008: *
009: */
010:
011: package org.enhydra.jawe.components.graph;
012:
013: import java.util.HashSet;
014: import java.util.Iterator;
015: import java.util.List;
016: import java.util.Set;
017: import java.util.Vector;
018:
019: import org.jgraph.JGraph;
020: import org.jgraph.graph.DefaultGraphCell;
021: import org.jgraph.graph.DefaultGraphSelectionModel;
022:
023: /**
024: * JaWE implementation of selection model.
025: */
026: public class JaWEGraphSelectionModel extends DefaultGraphSelectionModel {
027:
028: /** Constructs a DefaultGraphSelectionModel for the specified graph. */
029: public JaWEGraphSelectionModel(JGraph graph) {
030: super (graph);
031: }
032:
033: /**
034: * Modifies original method to avoid selection of in/out of subflow.
035: */
036: public void setSelectionCells(Object[] cells) {
037: super .setSelectionCells(removeForbiddenCells(cells));
038: graph.getModel().toFront(cells);
039: }
040:
041: /**
042: * Modifies original method to avoid selection of in/out of subflow.
043: */
044: public void addSelectionCells(Object[] cells) {
045: super .addSelectionCells(removeForbiddenCells(cells));
046: graph.getModel().toFront(cells);
047: }
048:
049: /**
050: * Modifies original method to avoid deselection of in/out of subflow.
051: */
052: public void removeSelectionCells(Object[] cells) {
053: Vector change = new Vector();
054: HashSet parents = new HashSet();
055: for (int i = 0; i < cells.length; i++) {
056: if (((DefaultGraphCell) cells[i]).getParent() != null) {
057: parents.add(((DefaultGraphCell) cells[i]).getParent());
058: deselect(cells[i]);
059: change.addElement(new JaWECellPlaceHolder(cells[i],
060: false));
061: } else {
062: deselect(cells[i]);
063: change.addElement(new JaWECellPlaceHolder(cells[i],
064: false));
065: }
066: }
067:
068: for (Iterator it = parents.iterator(); it.hasNext();) {
069: DefaultGraphCell parent = (DefaultGraphCell) it.next();
070: List children = parent.getChildren();
071: boolean hasSelected = false;
072: for (int i = 0; i < children.size(); i++) {
073: if (graph.isCellSelected(children.get(i))) {
074: hasSelected = true;
075: break;
076: }
077: }
078: if (!hasSelected) {
079: deselect(parent);
080: change
081: .addElement(new JaWECellPlaceHolder(parent,
082: false));
083: }
084: }
085:
086: if (change.size() > 0)
087: notifyCellChange(change);
088: }
089:
090: /**
091: * Removes forbiden objects from selection.
092: */
093: private Object[] removeForbiddenCells(Object[] cells) {
094: /*
095: if (cells != null && cells.length>0) {
096: Set cellsToSelect=new HashSet();
097: for (int i=0; i<cells.length; i++) {
098: if (!(cells[i] instanceof SubflowPort)) {
099: cellsToSelect.add(cells[i]);
100: }
101: }
102: if (cellsToSelect.size()>0) {
103: cells=cellsToSelect.toArray();
104: }
105: else {
106: cells=null;
107: }
108: }
109: */
110: return cells;
111: }
112:
113: // NOTE: FOLLOWING METHOD IS NEVER CALLED BECAUSE PEJGRAPH IMPLEMENTS
114: // IT'S OWN METHOD TO DO THIS. IT COULD BE CHANGED.
115: /**
116: * Returns the cells that are currently selectable.
117: */
118: public Object[] getSelectables() {
119: Object[] selectables = super .getSelectables();
120:
121: if (selectables != null && selectables.length > 0) {
122: Set removedForbiddenElements = new HashSet();
123: for (int i = 0; i < selectables.length; i++) {
124: //if (!(selectables[i] instanceof SubflowPort)) {
125: removedForbiddenElements.add(selectables[i]);
126: //}
127: }
128: selectables = removedForbiddenElements.toArray();
129: }
130: return selectables;
131: }
132:
133: protected class JaWECellPlaceHolder extends
134: DefaultGraphSelectionModel.CellPlaceHolder {
135:
136: protected JaWECellPlaceHolder(Object cell, boolean isNew) {
137: super (cell, isNew);
138: }
139: }
140: }
141:
142: /* End of PEGraphSelectionModel.java */
|