001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023: package salomeTMF_plug.requirements.data;
024:
025: import java.util.Hashtable;
026: import java.util.Vector;
027:
028: import javax.swing.tree.DefaultMutableTreeNode;
029:
030: import org.objectweb.salome_tmf.data.SimpleData;
031:
032: public class ReqFilter implements IReqFilter {
033: //boolean pass=true;
034: boolean actived = true;
035:
036: public final static int P_HIGHT = 1000;
037: public final static int P_MEDIUM = 100;
038: public final static int P_LOW = 10;
039: public final static int P_NONE = 1;
040: public final static int P_FILTRE = 1007;
041:
042: public final static int C0 = 1000;
043: public final static int C1 = 100;
044: public final static int C2 = 10;
045: public final static int C3 = 1;
046:
047: int catSelected = -1;
048: int complexSelected = -1;
049: int stateSelected = -1;
050: int m_filtre = P_FILTRE; //1000 H, 100 M, 10 L, 1 N (combinaison)
051: int coverFiltre = 11;
052: Hashtable reqsWrapCoveredHash;
053:
054: public ReqFilter(int filtre) {
055: m_filtre = filtre;
056: }
057:
058: public boolean pass(Object obj) {
059: if (!isActived())
060: return true;
061: if (!isFiltred())
062: return true;
063: if (obj instanceof DefaultMutableTreeNode) {
064: Object req = ((DefaultMutableTreeNode) obj).getUserObject();
065: if (req instanceof Requirement) {
066: return isFiltred((Requirement) req);
067: }
068: }
069: return false;
070: }
071:
072: /*public boolean pass(Object obj) {
073: //if (pass) return true;
074: if (!isActived()) return true;
075: if (!isFiltred()) return true;
076: if (obj instanceof DefaultMutableTreeNode) {
077: Object req = ((DefaultMutableTreeNode)obj).getUserObject();
078: if (req instanceof ReqLeaf){
079: int reqP = ((ReqLeaf)req).getPriorityFromModel();
080: //System.out.println("Le filtre est :" + m_filtre);
081: //System.out.println(((ReqLeaf)req).getNameFromModel() + " P="+ reqP + ", filtred& = " + (m_filtre & reqP) + ", filtred| = " + (m_filtre | reqP));
082: //if ((reqP & m_filtre) > 0){
083: if ((reqP | m_filtre) == m_filtre){
084: if (coverFiltre == 11 || reqsWrapCoveredHash == null) { // Toutes les exigences
085: //return true;
086: return isFiltredByInfo((ReqLeaf)req);
087: } else if (coverFiltre == 10){ // Seulement les exigences couverte
088: Integer id = new Integer(((ReqLeaf)req).getIdBdd());
089: if (reqsWrapCoveredHash.get(id) != null){
090: //return true;
091: return isFiltredByInfo((ReqLeaf)req);
092: }
093: return false;
094: } else if (coverFiltre == 1){ // Seulement les exigences non couverte
095: Integer id = new Integer(((ReqLeaf)req).getIdBdd());
096: if (reqsWrapCoveredHash.get(id) == null){
097: //return true;
098: return isFiltredByInfo((ReqLeaf)req);
099: }
100: return false;
101: } else {
102: return false;
103: }
104: }
105: } else {
106: if (!isFiltred()){
107: return true;
108: }else {
109: ReqFamily pReq = ((ReqFamily)req);
110: Vector list_of_leaf = pReq.getAllLeaf(m_filtre);
111: int size = list_of_leaf.size();
112: boolean trouve = false;
113: int cpt = 0;
114: while (cpt < size && !trouve){
115: Requirement pTempReq = (Requirement) list_of_leaf.get(cpt);
116: if (isFiltred(pTempReq)){
117: trouve = true; //Au moins une exigence est filtrée
118: }
119: cpt ++;
120: }
121: return trouve;
122: }
123: //return true;
124: }
125: }
126: return false;
127: }*/
128:
129: /**
130: *
131: * @param pReq
132: * @return true if pReq is filtred by info (catSelected, complexSelected, stateSelected)
133: */
134: public boolean isFiltredByInfo(ReqLeaf pReq) {
135: int _catSelected = pReq.getCatFromModel();
136: int _complexSelected = pReq.getComplexeFromModel();
137: int _stateSelected = pReq.getStateFromModel();
138:
139: // Matching complex box <-> complexity values
140: Vector com_values = new Vector();
141: com_values.add(0, new Integer(C0));
142: com_values.add(1, new Integer(C1));
143: com_values.add(2, new Integer(C2));
144: com_values.add(3, new Integer(C3));
145:
146: if ((catSelected == -1 || catSelected == _catSelected)
147: && (complexSelected == -1 || ((Integer) com_values
148: .elementAt(complexSelected)).intValue() == _complexSelected)
149: && (stateSelected == -1 || stateSelected == _stateSelected)) {
150: return true;
151: } else {
152: return false;
153: }
154: }
155:
156: public boolean isFiltred(Requirement req) {
157: if (req instanceof ReqLeaf) {
158: int reqP = ((ReqLeaf) req).getPriorityFromModel();
159: //if ((reqP & m_filtre) > 0){
160: if ((reqP | m_filtre) == m_filtre) {
161: if (coverFiltre == 11 || reqsWrapCoveredHash == null) { // Toutes les exigences
162: //return true;
163: return isFiltredByInfo((ReqLeaf) req);
164: } else if (coverFiltre == 10) { // Seulement les exigences couverte
165: Integer id = new Integer(((ReqLeaf) req).getIdBdd());
166: if (reqsWrapCoveredHash.get(id) != null) {
167: //return true;
168: return isFiltredByInfo((ReqLeaf) req);
169: }
170: return false;
171: } else if (coverFiltre == 1) { // Seulement les exigences non couverte
172: Integer id = new Integer(((ReqLeaf) req).getIdBdd());
173: if (reqsWrapCoveredHash.get(id) == null) {
174: //return true;
175: return isFiltredByInfo((ReqLeaf) req);
176: }
177: return false;
178: } else {
179: return false;
180: }
181:
182: }
183: } else {
184: if (!isFiltred()) {
185: return true;
186: } else {
187: ReqFamily pReq = ((ReqFamily) req);
188: //Vector list_of_leaf = pReq.getAllLeaf(m_filtre);
189: Vector list_of_leaf = pReq
190: .getAllLeafByPriority(m_filtre);
191: int size = list_of_leaf.size();
192: boolean trouve = false;
193: int cpt = 0;
194: while (cpt < size && !trouve) {
195: Requirement pTempReq = (Requirement) list_of_leaf
196: .get(cpt);
197: if (isFiltred(pTempReq)) {
198: trouve = true; //Au moins une exigence est filtrée
199: }
200: cpt++;
201: }
202: return trouve;
203: }
204: //return true;
205: }
206: return false;
207: }
208:
209: public void setCoverFiltre(int filtre, Hashtable reqsWrapCoveredHash) {
210: coverFiltre = filtre;
211: this .reqsWrapCoveredHash = reqsWrapCoveredHash;
212: }
213:
214: public void setInfoFiltre(int _catSelected, int _complexSelected,
215: int _stateSelected) {
216: catSelected = _catSelected;
217: complexSelected = _complexSelected;
218: stateSelected = _stateSelected;
219: }
220:
221: public void setActived(boolean actived) {
222: this .actived = actived;
223: }
224:
225: public boolean isActived() {
226: return actived;
227: }
228:
229: public boolean isFiltred() {
230: /*System.out.println("m_filtre = " + m_filtre);
231: System.out.println("coverFiltre = " + coverFiltre);
232: System.out.println("catSelected = " + catSelected);
233: System.out.println("complexSelected = " + complexSelected);
234: System.out.println("stateSelected = " + stateSelected);
235: */
236: if (coverFiltre != 11) {
237: return true;
238: }
239: if (m_filtre != P_FILTRE) {
240: return true;
241: }
242: if (catSelected != -1 || complexSelected != -1
243: || stateSelected != -1) {
244: return true;
245: }
246: return false;
247: }
248:
249: public void reInit() {
250: m_filtre = P_FILTRE;
251: coverFiltre = 11;
252: catSelected = -1;
253: complexSelected = -1;
254: stateSelected = -1;
255: }
256:
257: public void setFilter(int filtre) {
258: m_filtre = filtre;
259: }
260:
261: public int getFilter() {
262: return m_filtre;
263: }
264: }
|