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.ihm;
024:
025: import java.awt.BorderLayout;
026: import java.awt.Color;
027: import java.awt.Dimension;
028: import java.awt.FlowLayout;
029: import java.awt.FontMetrics;
030: import java.awt.GraphicsConfiguration;
031: import java.awt.GraphicsDevice;
032: import java.awt.GraphicsEnvironment;
033: import java.awt.Rectangle;
034: import java.awt.event.ActionEvent;
035: import java.awt.event.ActionListener;
036: import java.awt.event.MouseEvent;
037: import java.awt.event.MouseListener;
038: import java.sql.Date;
039: import java.text.SimpleDateFormat;
040: import java.util.Hashtable;
041: import java.util.Vector;
042:
043: import javax.swing.BorderFactory;
044: import javax.swing.JButton;
045: import javax.swing.JPanel;
046: import javax.swing.JScrollPane;
047: import javax.swing.JTable;
048: import javax.swing.ListSelectionModel;
049: import javax.swing.event.ListSelectionEvent;
050: import javax.swing.event.ListSelectionListener;
051:
052: import org.objectweb.salome_tmf.data.Test;
053: import org.objectweb.salome_tmf.ihm.languages.Language;
054: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
055: import org.objectweb.salome_tmf.ihm.models.TableSorter;
056:
057: import salomeTMF_plug.requirements.data.ReqFilter;
058: import salomeTMF_plug.requirements.data.Requirement;
059: import salomeTMF_plug.requirements.sqlWrapper.HistoryWrapper;
060:
061: public class HistoryPanel extends JPanel implements
062: ListSelectionListener, ActionListener {
063: JTable historyTable;
064: TableSorter sorter;
065: SimpleTableModel model;
066: Requirement currentReq;
067:
068: JButton viewButton;
069: HistoryWrapper[] tabHisto;
070:
071: Hashtable<Integer, String> itemComplex;
072: Hashtable<Integer, String> itemPriority;
073: Hashtable<Integer, String> itemCat;
074: Hashtable<Integer, String> itemState;
075:
076: public HistoryPanel() {
077: super (new BorderLayout());
078: initData();
079: initComponent();
080: }
081:
082: void initData() {
083: itemPriority = new Hashtable<Integer, String>();
084: itemPriority.put(ReqFilter.P_HIGHT, Language.getInstance()
085: .getText("Filtre_Exigence_Haute"));
086: itemPriority.put(ReqFilter.P_MEDIUM, Language.getInstance()
087: .getText("Filtre_Exigence_Moyenne"));
088: itemPriority.put(ReqFilter.P_LOW, Language.getInstance()
089: .getText("Filtre_Exigence_Faible"));
090: itemPriority.put(ReqFilter.P_NONE, Language.getInstance()
091: .getText("Filtre_Exigence_Option"));
092:
093: itemCat = new Hashtable<Integer, String>();
094: itemCat.put(0, Language.getInstance()
095: .getText("Cat_Fonctionnel"));
096: itemCat.put(1, Language.getInstance().getText(
097: "Cat_Interoperabilite"));
098: itemCat.put(2, Language.getInstance().getText("Cat_Charge"));
099: itemCat.put(3, Language.getInstance()
100: .getText("Cat_Performance"));
101: itemCat.put(4, Language.getInstance().getText(
102: "Cat_Disponibilite"));
103: itemCat.put(5, Language.getInstance().getText("Cat_Securite"));
104: itemCat.put(6, Language.getInstance().getText(
105: "Cat_Exploitabilite"));
106: itemCat.put(7, Language.getInstance().getText("Cat_Autre"));
107:
108: itemState = new Hashtable<Integer, String>();
109: itemState.put(0, Language.getInstance().getText(
110: "State_A_Analyser"));
111: itemState.put(1, Language.getInstance().getText(
112: "State_Analysee"));
113: itemState.put(2, Language.getInstance().getText(
114: "State_Approuvee"));
115: itemState.put(3, Language.getInstance().getText(
116: "State_Verifiee"));
117: itemState.put(4, Language.getInstance().getText(
118: "State_Finalisee"));
119: itemState.put(5, Language.getInstance().getText(
120: "State_Reportee"));
121: itemState.put(6, Language.getInstance().getText(
122: "State_Abandonnee"));
123:
124: itemComplex = new Hashtable<Integer, String>();
125: itemComplex.put(ReqFilter.C0, Language.getInstance().getText(
126: "Com_C0"));
127: itemComplex.put(ReqFilter.C1, Language.getInstance().getText(
128: "Com_C1"));
129: itemComplex.put(ReqFilter.C2, Language.getInstance().getText(
130: "Com_C2"));
131: itemComplex.put(ReqFilter.C3, Language.getInstance().getText(
132: "Com_C3"));
133: }
134:
135: void initComponent() {
136: int t_y = 768;
137: int t_x = 1024;
138: try {
139: GraphicsEnvironment ge = GraphicsEnvironment
140: .getLocalGraphicsEnvironment();
141: GraphicsDevice[] gs = ge.getScreenDevices();
142: GraphicsDevice gd = gs[0];
143: GraphicsConfiguration[] gc = gd.getConfigurations();
144: Rectangle r = gc[0].getBounds();
145: t_y = r.height;
146: ;
147: } catch (Exception E) {
148:
149: }
150: model = new SimpleTableModel();
151: model.addColumn(Language.getInstance().getText("Date"));
152: model.addColumn(Language.getInstance().getText("Action"));
153: model.addColumn(Language.getInstance().getText(
154: "Nouvelle_valeur"));
155: sorter = new TableSorter(model);
156:
157: historyTable = new JTable(sorter);
158:
159: historyTable.addMouseListener(new MouseListener() {
160: public void mouseClicked(MouseEvent me) {
161: if (me.getButton() == MouseEvent.BUTTON1) {
162: if (me.getClickCount() == 2) {
163: viewDescriptionPerformed();
164: }
165: }
166: }
167:
168: public void mouseEntered(MouseEvent me) {
169: }
170:
171: public void mouseExited(MouseEvent me) {
172: }
173:
174: public void mousePressed(MouseEvent me) {
175: }
176:
177: public void mouseReleased(MouseEvent me) {
178: }
179: });
180:
181: ListSelectionModel rowSM = historyTable.getSelectionModel();
182: rowSM.addListSelectionListener(this );
183: setColumnSize(historyTable);
184: sorter.setTableHeader(historyTable.getTableHeader());
185:
186: historyTable
187: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
188: JScrollPane tablePane = new JScrollPane(historyTable,
189: JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
190: JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
191: tablePane.setBorder(BorderFactory.createRaisedBevelBorder());
192: setBorder(BorderFactory.createTitledBorder(BorderFactory
193: .createLineBorder(Color.BLACK), Language.getInstance()
194: .getText("Historique")));
195: add(tablePane, BorderLayout.CENTER);
196:
197: JPanel panelButton = new JPanel(new FlowLayout());
198: viewButton = new JButton(Language.getInstance().getText(
199: "Visualiser")
200: + " " + Language.getInstance().getText("Test"));
201: viewButton.setEnabled(false);
202: viewButton.addActionListener(this );
203: panelButton.add(viewButton);
204: add(panelButton, BorderLayout.SOUTH);
205:
206: setMaximumSize(new Dimension(t_x / 3 * 2, t_y / 5)); //MM
207:
208: }
209:
210: public void updateData(Requirement pReq, boolean force) {
211: if (pReq == null) {
212: return;
213: }
214: if (currentReq != null && !force) {
215: if (currentReq.getIdBdd() == pReq.getIdBdd()) {
216: return;
217: }
218: }
219: boolean isSorting = sorter.isSorting();
220: int statusSort_col0 = -1;
221: int statusSort_col1 = -1;
222: int statusSort_col2 = -1;
223: if (isSorting) {
224: statusSort_col0 = sorter.getSortingStatus(0);
225: statusSort_col1 = sorter.getSortingStatus(1);
226: statusSort_col2 = sorter.getSortingStatus(2);
227: }
228: model.clearTable();
229: //System.out.println("UpDateHistory for " + pReq.getLongName());
230:
231: try {
232: tabHisto = pReq.getHistory();
233: for (int i = 0; i < tabHisto.length; i++) {
234: HistoryWrapper pHistoryWrapper = tabHisto[i];
235: Date pDate = pHistoryWrapper.getDate();
236: int code = pHistoryWrapper.getCode();
237: String strcode = Requirement.getStringCodeValue(code);
238: String valeur = pHistoryWrapper.getValeur();
239: if (Requirement.isTestIdValeur(code)) {
240: Test pTest = (Test) DataModel.getCurrentProject()
241: .getTestFromModel(
242: new Integer(valeur).intValue());
243: if (pTest != null) {
244: valeur = pTest.getNameFromModel();
245: }
246: } else if (Requirement.isStateValeur(code)) {
247: int state = new Integer(valeur).intValue();
248: valeur = itemState.get(state);
249: } else if (Requirement.isPriorityValeur(code)) {
250: int priority = new Integer(valeur).intValue();
251: valeur = itemPriority.get(priority);
252: } else if (Requirement.isComplexityValeur(code)) {
253: int comp = new Integer(valeur).intValue();
254: valeur = itemComplex.get(comp);
255: } else if (Requirement.isCategoryValeur(code)) {
256: int cat = new Integer(valeur).intValue();
257: valeur = itemCat.get(cat);
258: }
259:
260: Vector<String> data = new Vector<String>();
261: SimpleDateFormat sdf = new SimpleDateFormat(
262: "dd-MMM-yyyy");
263: data.add(sdf.format(pDate));
264: data.add(strcode);
265: data.add(valeur);
266: model.insertRow(i, data);
267: }
268: } catch (Exception e) {
269: e.printStackTrace();
270: }
271: currentReq = pReq;
272: setColumnSize(historyTable);
273: if (isSorting) {
274: sorter.setSortingStatus(0, statusSort_col0);
275: sorter.setSortingStatus(1, statusSort_col1);
276: sorter.setSortingStatus(2, statusSort_col2);
277: }
278: }
279:
280: /**
281: * redefine size of table columns
282: */
283: public void setColumnSize(JTable table) {
284: FontMetrics fm = table.getFontMetrics(table.getFont());
285: for (int i = 0; i < table.getColumnCount(); i++) {
286: int max = 0;
287: for (int j = 0; j < table.getRowCount(); j++) {
288: int taille = fm.stringWidth((String) table.getValueAt(
289: j, i));
290: if (taille > max)
291: max = taille;
292: }
293: String nom = (String) table.getColumnModel().getColumn(i)
294: .getIdentifier();
295: int taille = fm.stringWidth(nom);
296: if (taille > max) {
297: max = taille;
298: }
299: table.getColumnModel().getColumn(i).setPreferredWidth(
300: max + 10);
301: }
302: }
303:
304: /********************** ListSelectionListener ***************************/
305: public void valueChanged(ListSelectionEvent e) {
306: if (e.getSource().equals(historyTable.getSelectionModel())) {
307: assigendTableValueChanged(e);
308: }
309: }
310:
311: void assigendTableValueChanged(ListSelectionEvent e) {
312:
313: if (e.getValueIsAdjusting())
314: return;
315:
316: int selectedRow = historyTable.getSelectedRow();
317: if (selectedRow != -1) {
318: /* Mono Selection */
319: int modeIndex = sorter.modelIndex(selectedRow);
320: if (tabHisto != null) {
321: HistoryWrapper pHistoryWrapper = tabHisto[modeIndex];
322: int code = pHistoryWrapper.getCode();
323: String valeur = pHistoryWrapper.getValeur();
324: if (Requirement.isTestIdValeur(code)) {
325: Test pTest = (Test) DataModel.getCurrentProject()
326: .getTestFromModel(
327: new Integer(valeur).intValue());
328: if (pTest != null) {
329: viewButton.setEnabled(true);
330: }
331: } else {
332: viewButton.setEnabled(false);
333: }
334: } else {
335: viewButton.setEnabled(false);
336: }
337:
338: //viewButton.setEnabled(true);
339: } else {
340: /* Pas de Selection */
341: viewButton.setEnabled(false);
342: }
343:
344: }
345:
346: /********************************** Implements ActionListener *********************************/
347:
348: public void actionPerformed(ActionEvent e) {
349: if (e.getSource().equals(viewButton)) {
350: viewTestPerformed();
351: }
352: }
353:
354: void doubleClicPerformed() {
355: viewDescriptionPerformed();
356: }
357:
358: void viewTestPerformed() {
359: int selectedRow = historyTable.getSelectedRow();
360: if (selectedRow != -1) {
361: int modeIndex = sorter.modelIndex(selectedRow);
362: if (tabHisto != null) {
363: HistoryWrapper pHistoryWrapper = tabHisto[modeIndex];
364: int code = pHistoryWrapper.getCode();
365: String valeur = pHistoryWrapper.getValeur();
366: if (Requirement.isTestIdValeur(code)) {
367: Test pTest = (Test) DataModel.getCurrentProject()
368: .getTestFromModel(
369: new Integer(valeur).intValue());
370: if (pTest != null) {
371: DataModel.view(pTest);
372: }
373: }
374: }
375: }
376: }
377:
378: void viewDescriptionPerformed() {
379: int selectedRow = historyTable.getSelectedRow();
380: if (selectedRow != -1) {
381: int modeIndex = sorter.modelIndex(selectedRow);
382: if (tabHisto != null) {
383: HistoryWrapper pHistoryWrapper = tabHisto[modeIndex];
384: int code = pHistoryWrapper.getCode();
385: if (Requirement.isDescriptionValeur(code)) {
386: String valeur = pHistoryWrapper.getValeur();
387: System.out.println("Valeur = " + valeur);
388: HistoryDescViewDialog pHistoryDescViewDialog = new HistoryDescViewDialog(
389: valeur);
390: }
391: }
392: }
393: }
394: }
|