001: package org.objectweb.salome_tmf.ihm.main;
002:
003: import java.awt.BorderLayout;
004: import java.awt.Color;
005: import java.awt.Component;
006: import java.awt.Dimension;
007: import java.awt.GridLayout;
008: import java.awt.event.ActionEvent;
009: import java.awt.event.ActionListener;
010: import java.util.ArrayList;
011: import java.util.HashMap;
012: import java.util.Iterator;
013: import java.util.Set;
014: import java.util.Vector;
015:
016: import javax.swing.BorderFactory;
017: import javax.swing.JButton;
018: import javax.swing.JDialog;
019: import javax.swing.JPanel;
020: import javax.swing.JScrollPane;
021: import javax.swing.JTable;
022: import javax.swing.JTree;
023: import javax.swing.ListSelectionModel;
024: import javax.swing.event.ListSelectionEvent;
025: import javax.swing.event.ListSelectionListener;
026: import javax.swing.event.TreeSelectionEvent;
027: import javax.swing.event.TreeSelectionListener;
028: import javax.swing.table.DefaultTableCellRenderer;
029: import javax.swing.tree.DefaultMutableTreeNode;
030:
031: import org.objectweb.salome_tmf.api.data.AttachementWrapper;
032: import org.objectweb.salome_tmf.api.data.ExecutionWrapper;
033: import org.objectweb.salome_tmf.api.data.TestCampWrapper;
034: import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
035: import org.objectweb.salome_tmf.data.Attachment;
036: import org.objectweb.salome_tmf.data.Campaign;
037: import org.objectweb.salome_tmf.data.Execution;
038: import org.objectweb.salome_tmf.data.ExecutionResult;
039: import org.objectweb.salome_tmf.data.ExecutionTestResult;
040: import org.objectweb.salome_tmf.data.Test;
041: import org.objectweb.salome_tmf.data.UrlAttachment;
042: import org.objectweb.salome_tmf.ihm.languages.Language;
043: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
044: import org.objectweb.salome_tmf.ihm.models.DynamicTree;
045: import org.objectweb.salome_tmf.ihm.models.MyTableModel;
046: import org.objectweb.salome_tmf.ihm.models.TableSorter;
047: import org.objectweb.salome_tmf.plugins.UICompCst;
048: import org.objectweb.salome_tmf.plugins.core.BugTracker;
049:
050: public class AnomalieView extends JPanel implements ActionListener,
051: ListSelectionListener {
052:
053: JButton viewDefectButton;
054: JButton viewTestButton;
055: JPanel buttonsPanel;
056:
057: TableSorter sorter;
058: JTable defectTable;
059: JScrollPane tablePane;
060:
061: JTree salomeDynamicTree;
062: Vector data;
063:
064: MyTableModel myTableModel;
065: boolean dynamique = false;
066: JDialog pJDialog;
067:
068: AnomalieView(JDialog _pJDialog) {
069: pJDialog = _pJDialog;
070: if (pJDialog != null) {
071: dynamique = true;
072: }
073: data = new Vector();
074: initComponent();
075: }
076:
077: void updateData(Campaign pCamp) {
078: try {
079: //System.out.println("-------> Update data for defect in Campaigne : " + pCamp.getNameFromModel());
080: boolean doRefresh = false;
081: Vector tmpdata = pCamp.getAllResExecAttahFromDB();
082: DataModel.getDefectTableModel().clearTable();
083: data.clear();
084: for (int i = 0; i < tmpdata.size(); i++) {
085:
086: Vector ligne = (Vector) tmpdata.elementAt(i);
087: String execNam = ((ExecutionWrapper) ligne.elementAt(0))
088: .getName();
089: int idTest = ((TestCampWrapper) ligne.elementAt(1))
090: .getIdBDD();
091: Attachment pAttachment = null;
092: AttachementWrapper pAttachementWrapper = (AttachementWrapper) ligne
093: .elementAt(2);
094: if (pAttachementWrapper != null
095: && pAttachementWrapper instanceof UrlAttachementWrapper) {
096: pAttachment = new UrlAttachment(
097: (UrlAttachementWrapper) pAttachementWrapper);
098: }
099: Test pTest = DataModel.getCurrentProject()
100: .getTestFromModel(idTest);
101: if (pTest == null) {
102: doRefresh = true;
103: } else {
104: BugTracker pBugTracker = SalomeTMFContext
105: .getInstance().getBugTrackerFromAttachment(
106: pAttachment);
107: if (pBugTracker != null) {
108: ArrayList dataList = new ArrayList();
109: ArrayList dataList2 = new ArrayList();
110: dataList.add(execNam);
111: dataList.add(pTest.getNameFromModel());
112: dataList.add(pBugTracker.getBugTrackerName());
113: //dataList.add(pAttachment.getNameFromModel());
114:
115: String bugID = pBugTracker
116: .getBugID(pAttachment);
117: if (bugID != null) {
118: dataList.add("id = " + bugID);
119: DataModel.getDefectTableModel().addRow(
120: dataList);
121: dataList2.add(pTest);
122: dataList2.add(pBugTracker);
123: dataList2.add(pAttachment);
124: data.add(dataList2);
125: } else {
126: //remove attachement
127: }
128:
129: }
130: }
131: }
132: if (doRefresh == true) {
133: SalomeTMFContext.getInstance().showMessage(
134: Language.getInstance().getText(
135: "Veillez_rafraichier_les_données"));
136: }
137:
138: } catch (Exception e) {
139: e.printStackTrace();
140: data = new Vector();
141:
142: }
143: }
144:
145: void updateData(ExecutionResult pExec) {
146: try {
147: boolean doRefresh = false;
148: Vector tmpdata = pExec.getAllResExecTestAttachFromDB();
149: myTableModel.clearTable();
150:
151: for (int i = 0; i < tmpdata.size(); i++) {
152:
153: Vector ligne = (Vector) tmpdata.elementAt(i);
154: int idTest = ((Integer) ligne.elementAt(0)).intValue();
155: Attachment pAttachment = (Attachment) ligne
156: .elementAt(1);
157: Test pTest = DataModel.getCurrentProject()
158: .getTestFromModel(idTest);
159: if (pTest == null) {
160: doRefresh = true;
161: } else {
162: BugTracker pBugTracker = SalomeTMFContext
163: .getInstance().getBugTrackerFromAttachment(
164: pAttachment);
165: if (pBugTracker != null) {
166: ArrayList dataList = new ArrayList();
167: ArrayList dataList2 = new ArrayList();
168: dataList.add(pTest.getTestListFromModel()
169: .getFamilyFromModel()
170: .getNameFromModel());
171: dataList.add(pTest.getTestListFromModel()
172: .getNameFromModel());
173: dataList.add(pTest.getNameFromModel());
174: dataList.add(pBugTracker.getBugTrackerName());
175:
176: String bugID = pBugTracker
177: .getBugID(pAttachment);
178: if (bugID != null) {
179: //dataList.add(pAttachment.getNameFromModel());
180: dataList.add("id = " + bugID);
181: myTableModel.addRow(dataList);
182: dataList2.add(pTest);
183: dataList2.add(pBugTracker);
184: dataList2.add(pAttachment);
185: data.add(dataList2);
186: } else {
187: //remove attachement
188: try {
189: ExecutionTestResult pExecutionTestResult = pExec
190: .getExecutionTestResultFromModel(pTest);
191: pExecutionTestResult
192: .deleteAttachementInDBAndModel(pAttachment);
193: } catch (Exception e) {
194: // TODO: handle exception
195: e.printStackTrace();
196: }
197: }
198:
199: }
200: }
201: }
202: if (doRefresh == true) {
203: SalomeTMFContext.getInstance().showMessage(
204: Language.getInstance().getText(
205: "Veillez_rafraichier_les_données"));
206: }
207:
208: } catch (Exception e) {
209: data = new Vector();
210:
211: }
212: }
213:
214: Test getTest(int id) {
215: Test pTest = null;
216: pTest = DataModel.getCurrentProject().getTestFromModel(id);
217: return pTest;
218: }
219:
220: void initComponent() {
221: viewDefectButton = new JButton(Language.getInstance().getText(
222: "Visualiser")
223: + " " + Language.getInstance().getText("Anomalie"));
224: viewDefectButton.addActionListener(this );
225: viewDefectButton.setEnabled(false);
226:
227: viewTestButton = new JButton(Language.getInstance().getText(
228: "Visualiser")
229: + " " + Language.getInstance().getText("Test"));
230: viewTestButton.addActionListener(this );
231: viewTestButton.setEnabled(false);
232:
233: buttonsPanel = new JPanel(new GridLayout(1, 2));
234: buttonsPanel.add(viewTestButton);
235: buttonsPanel.add(viewDefectButton);
236:
237: if (dynamique == false) {
238: myTableModel = DataModel.getDefectTableModel();
239:
240: } else {
241: myTableModel = new MyTableModel();
242: myTableModel.addColumnNameAndColumn(Language.getInstance()
243: .getText("Famille"));
244: myTableModel.addColumnNameAndColumn(Language.getInstance()
245: .getText("Suite"));
246: myTableModel.addColumnNameAndColumn(Language.getInstance()
247: .getText("Test"));
248: myTableModel.addColumnNameAndColumn("Bug Tracker");
249: myTableModel.addColumnNameAndColumn(Language.getInstance()
250: .getText("Anomalies"));
251: }
252: sorter = new TableSorter(myTableModel);
253: defectTable = new JTable(sorter);
254: sorter.setTableHeader(defectTable.getTableHeader());
255:
256: try {
257: //reqTable.setDefaultRenderer(Class.forName( "java.lang.Object" ), new PriorityTableCellRenderer(reqCovered));
258: defectTable.setDefaultRenderer(Class
259: .forName("java.lang.Object"),
260: new StateTableCellRenderer());
261: } catch (Exception e) {
262: e.printStackTrace();
263: }
264:
265: defectTable.setPreferredScrollableViewportSize(new Dimension(
266: 600, 200));
267: defectTable
268: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
269: ListSelectionModel rowSM = defectTable.getSelectionModel();
270: rowSM.addListSelectionListener(this );
271:
272: tablePane = new JScrollPane(defectTable);
273: tablePane.setBorder(BorderFactory.createRaisedBevelBorder());
274:
275: setLayout(new BorderLayout());
276: add(buttonsPanel, BorderLayout.NORTH);
277: add(tablePane, BorderLayout.CENTER);
278:
279: /* Vector allBugTracker = SalomeTMFContext.getInstance().getBugTracker();
280: int size = allBugTracker.size();
281: if (size > 0){
282: boolean add = false;
283: JPanel statePanel = new JPanel(new GridLayout(size -1, 1 ));
284: for (int i = 0; i < size; i++) {
285: BugTracker pBugTracker = (BugTracker)allBugTracker.elementAt(i);
286: JPanel pJPanel = pBugTracker.getStateColorPanel();
287: if (pJPanel!=null){
288: statePanel.add(pJPanel);
289: add = true;
290: }
291: }
292: if (add){
293: add(statePanel, BorderLayout.SOUTH);
294: }
295: }
296: */
297: if (dynamique == false) {
298: DynamicTree pDynamicTree = (DynamicTree) SalomeTMFContext
299: .getInstance().getUIComponent(
300: UICompCst.CAMPAIGN_DYNAMIC_TREE);
301: salomeDynamicTree = pDynamicTree.getTree();
302: salomeDynamicTree
303: .addTreeSelectionListener(new TreeSelectionListener() {
304: public void valueChanged(TreeSelectionEvent e) {
305: DefaultMutableTreeNode node = (DefaultMutableTreeNode) salomeDynamicTree
306: .getLastSelectedPathComponent();
307:
308: if (node == null)
309: return;
310:
311: Object nodeInfo = node.getUserObject();
312: /* React to the node selection. */
313:
314: if ((nodeInfo instanceof Campaign)) {
315: //System.out.println("[requirementTestChangeListener-> Camp Changed] : " + e);
316: updateData((Campaign) nodeInfo);
317: }
318: }
319: });
320: } else {
321: updateData(DataModel.getObservedExecutionResult());
322: }
323: }
324:
325: public void valueChanged(ListSelectionEvent e) {
326: //Ignore extra messages.
327: if (e.getValueIsAdjusting()) {
328: return;
329: }
330:
331: ListSelectionModel lsm = (ListSelectionModel) e.getSource();
332: if (lsm.isSelectionEmpty()) {
333: //no rows are selected
334: viewDefectButton.setEnabled(false);
335: viewTestButton.setEnabled(false);
336: } else {
337: //int selectedRow = lsm.getMinSelectionIndex();
338: viewDefectButton.setEnabled(true);
339: viewTestButton.setEnabled(true);
340: //selectedRow is selected
341: }
342: }
343:
344: public void actionPerformed(ActionEvent e) {
345: if (e.getSource().equals(viewDefectButton)) {
346: if (pJDialog != null) {
347: pJDialog.dispose();
348: }
349: viewDefectPerformed(e);
350: } else if (e.getSource().equals(viewTestButton)) {
351: viewTestPerformed(e);
352: }
353: }
354:
355: void viewDefectPerformed(ActionEvent e) {
356: int selectedRowIndex = defectTable.getSelectedRow();
357:
358: if (selectedRowIndex != -1) {
359: int index = sorter.modelIndex(selectedRowIndex);
360: if (data.size() >= index) {
361: try {
362: ArrayList pArrayList = (ArrayList) data
363: .elementAt(index);
364: BugTracker pBugTracker = (BugTracker) pArrayList
365: .get(1);
366: Attachment pAttachment = (Attachment) pArrayList
367: .get(2);
368: pBugTracker.showBug(pAttachment);
369: } catch (Exception ex) {
370: ex.printStackTrace();
371: }
372:
373: }
374: }
375: }
376:
377: void viewTestPerformed(ActionEvent e) {
378: int selectedRowIndex = defectTable.getSelectedRow();
379:
380: if (selectedRowIndex != -1) {
381: int index = sorter.modelIndex(selectedRowIndex);
382: if (data.size() >= index) {
383: try {
384: ArrayList pArrayList = (ArrayList) data
385: .elementAt(index);
386: Test pTest = (Test) pArrayList.get(0);
387: DataModel.view(pTest);
388: } catch (Exception ex) {
389: ex.printStackTrace();
390: }
391: }
392: }
393: }
394:
395: public class StateTableCellRenderer extends
396: DefaultTableCellRenderer {
397: Color colorToUse = null;
398:
399: public Component getTableCellRendererComponent(JTable table,
400: Object value, boolean isSelected, boolean hasFocus,
401: int row, int column) {
402:
403: //super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
404: super .getTableCellRendererComponent(table, value,
405: isSelected, hasFocus, row, column);
406:
407: try {
408: int index = sorter.modelIndex(row);
409: if (data.size() >= index) {
410: try {
411: ArrayList pArrayList = (ArrayList) data
412: .elementAt(index);
413: Attachment pAttachment = (Attachment) pArrayList
414: .get(2);
415: BugTracker pBugTracker = SalomeTMFContext
416: .getInstance()
417: .getBugTrackerFromAttachment(
418: pAttachment);
419: colorToUse = pBugTracker
420: .getStateDefect(pAttachment);
421: } catch (Exception ex) {
422: ex.printStackTrace();
423: }
424: }
425: if (colorToUse == null) {
426: colorToUse = Color.WHITE;
427: }
428: if (isSelected) {
429: setBorder(BorderFactory
430: .createLineBorder(Color.BLACK));
431: }
432: setBackground(colorToUse);
433: setForeground(Color.BLACK);
434: //setOpaque(false);
435: setText((String) value);
436:
437: //super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
438:
439: } catch (Exception e) {
440: e.printStackTrace();
441: }
442: return this;
443: }
444: }
445: }
|