001: package salomeTMF_plug.requirements.ihm;
002:
003: import java.awt.Cursor;
004: import java.awt.GridLayout;
005: import java.awt.event.ActionEvent;
006: import java.awt.event.ActionListener;
007: import java.util.Hashtable;
008: import java.util.Observer;
009: import java.util.Vector;
010:
011: import javax.swing.JPanel;
012: import javax.swing.JRadioButton;
013:
014: import org.objectweb.salome_tmf.ihm.languages.Language;
015: import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
016:
017: import salomeTMF_plug.requirements.data.IReqFilter;
018: import salomeTMF_plug.requirements.data.Requirement;
019: import salomeTMF_plug.requirements.sqlWrapper.ReqWrapper;
020:
021: public class CoverFiltrePanel extends JPanel implements ActionListener {
022: JRadioButton bCover;
023: JRadioButton bNotCover;
024: IReqFilter m_ReqFilter;
025: FilterReqTreeModel m_FilterReqTreeModel;
026: Hashtable reqsWrapCoveredHash;
027:
028: int filtre = 11;
029: Observer pObserver = null;
030:
031: public CoverFiltrePanel(FilterReqTreeModel pFilterReqTreeModel,
032: Observer _pObserver) {
033: super ();
034: m_FilterReqTreeModel = pFilterReqTreeModel;
035: if (m_FilterReqTreeModel != null) {
036: m_ReqFilter = pFilterReqTreeModel.getFilter();
037: }
038: reqsWrapCoveredHash = new Hashtable();
039: pObserver = _pObserver;
040: initComponent();
041: }
042:
043: void initComponent() {
044: setLayout(new GridLayout(1, 2));
045:
046: bCover = new JRadioButton(Language.getInstance().getText(
047: "Filtre_Exigence_Couverte"), true);
048: bNotCover = new JRadioButton(Language.getInstance().getText(
049: "Filtre_Exigence_Non_Couverte"), true);
050:
051: bCover.addActionListener(this );
052: bNotCover.addActionListener(this );
053:
054: add(bCover);
055: add(bNotCover);
056:
057: }
058:
059: void reInit(boolean filter) {
060: bCover.setSelected(true);
061: bNotCover.setSelected(true);
062: if (filter) {
063: m_ReqFilter.reInit();
064: }
065: }
066:
067: public void actionPerformed(ActionEvent evt) {
068: if (evt.getSource().equals(bCover)) {
069: bCoverPerformed();
070: } else if (evt.getSource().equals(bNotCover)) {
071: bNotCoverPerformed();
072: }
073: }
074:
075: void updateReqCover() {
076: try {
077: if (Requirement.coverChange) {
078: reqsWrapCoveredHash.clear();
079: Vector reqsWrapCovered = Requirement
080: .getReqWrapperCovered();
081: int size = reqsWrapCovered.size();
082: for (int i = 0; i < size; i++) {
083: ReqWrapper pReq = (ReqWrapper) reqsWrapCovered
084: .elementAt(i);
085: reqsWrapCoveredHash.put(
086: new Integer(pReq.getIdBDD()), pReq);
087: }
088: }
089: Requirement.coverChange = false;
090: } catch (Exception e) {
091:
092: }
093: }
094:
095: int getFiltre() {
096: int f = 0;
097: if (bCover.isSelected()) {
098: f += 10;
099: }
100: if (bNotCover.isSelected()) {
101: f += 1;
102: }
103: return f;
104: }
105:
106: void bCoverPerformed() {
107: filtre = getFiltre();
108: if (filtre != 11) {
109: updateReqCover();
110: }
111: applyFilter();
112: }
113:
114: void bNotCoverPerformed() {
115: filtre = getFiltre();
116: if (filtre != 11) {
117: updateReqCover();
118: }
119: applyFilter();
120: }
121:
122: void applyFilter() {
123: if (m_ReqFilter != null) {
124: SalomeTMFContext.getInstance().getSalomeFrame().setCursor(
125: new Cursor(Cursor.WAIT_CURSOR));
126: m_ReqFilter.setCoverFiltre(filtre, reqsWrapCoveredHash);
127: m_FilterReqTreeModel.setFiltered(true);
128: if (pObserver != null) {
129: pObserver.update(null, new ReqEvent(
130: ReqEvent.FILTRE_REQ_CHANGE, null));
131: }
132: SalomeTMFContext.getInstance().getSalomeFrame().setCursor(
133: new Cursor(Cursor.DEFAULT_CURSOR));
134: }
135:
136: }
137:
138: }
|