01: /*
02: * SalomeTMF is a Test Management Framework
03: * Copyright (C) 2005 France Telecom R&D
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *
19: * @author Marche Mikael
20: *
21: * Contact: mikael.marche@rd.francetelecom.com
22: */
23:
24: package salomeTMF_plug.requirements.ihm;
25:
26: import java.util.Observable;
27: import java.util.Observer;
28:
29: import javax.swing.event.TreeSelectionEvent;
30: import javax.swing.event.TreeSelectionListener;
31: import javax.swing.tree.DefaultMutableTreeNode;
32: import javax.swing.tree.TreePath;
33:
34: import salomeTMF_plug.requirements.data.Requirement;
35:
36: public class RequirementTreeObservable extends Observable implements
37: TreeSelectionListener {
38:
39: protected DefaultMutableTreeNode currentNode = null;
40: protected DefaultMutableTreeNode oldNode = null;
41:
42: protected StatRequirement pStatRequirement;
43: protected FiltrePanel pFiltrePanel;
44:
45: void setStatTools(StatRequirement _pStatRequirement,
46: FiltrePanel _pFiltrePanel) {
47: pStatRequirement = _pStatRequirement;
48: pFiltrePanel = _pFiltrePanel;
49: }
50:
51: public void addObserver(Observer o) throws NullPointerException {
52: super .addObserver(o);
53: //notifyObservers(new ReqEvent(ReqEvent.REQSELECTED, currentNode.getUserObject()));
54: setChanged();
55: }
56:
57: public void valueChanged(TreeSelectionEvent e) {
58: TreePath path = e.getPath();
59: oldNode = currentNode;
60: currentNode = (DefaultMutableTreeNode) path
61: .getLastPathComponent();
62: if (!currentNode.equals(oldNode)) {
63: //System.out.println("valueChanged : " + e);
64: calStat(false);
65: notifyObservers(new ReqEvent(ReqEvent.REQSELECTED,
66: currentNode.getUserObject()));
67: setChanged();
68: }
69: }
70:
71: public void refresh() {
72: if (currentNode != null) {
73: calStat(true);
74: notifyObservers(new ReqEvent(ReqEvent.REQSELECTED,
75: currentNode.getUserObject()));
76: setChanged();
77: }
78: }
79:
80: void calStat(boolean forceReload) {
81: if (pStatRequirement != null) {
82: //System.out.println("ReqTreeObseve-> : " + forceReload);
83: try {
84: pStatRequirement.update((Requirement) currentNode
85: .getUserObject(), pFiltrePanel.getFilter(),
86: forceReload);
87: //pStatRequirement.update((Requirement)currentNode.getUserObject(), pFiltrePanel.getFiltre(), forceReload);
88: } catch (Exception ex) {
89: ex.printStackTrace();
90: }
91: }
92: }
93: }
|