001: package salomeTMF_plug.mantis;
002:
003: import java.awt.BorderLayout;
004: import java.awt.GridLayout;
005: import java.awt.event.ActionEvent;
006: import java.awt.event.ActionListener;
007: import java.util.ArrayList;
008: import java.util.HashMap;
009: import java.util.Hashtable;
010: import java.util.Iterator;
011: import java.util.Set;
012: import java.util.Vector;
013:
014: import javax.swing.JButton;
015: import javax.swing.JDialog;
016: import javax.swing.JPanel;
017: import javax.swing.JScrollPane;
018: import javax.swing.JTable;
019: import javax.swing.ListSelectionModel;
020: import javax.swing.event.ListSelectionEvent;
021: import javax.swing.event.ListSelectionListener;
022:
023: import org.objectweb.salome_tmf.data.Attachment;
024: import org.objectweb.salome_tmf.data.Campaign;
025: import org.objectweb.salome_tmf.data.DataConstants;
026: import org.objectweb.salome_tmf.data.Execution;
027: import org.objectweb.salome_tmf.data.ExecutionResult;
028: import org.objectweb.salome_tmf.data.ExecutionTestResult;
029: import org.objectweb.salome_tmf.data.ManualTest;
030: import org.objectweb.salome_tmf.data.Project;
031: import org.objectweb.salome_tmf.data.Test;
032: import org.objectweb.salome_tmf.ihm.main.ActionDetailsView;
033: import org.objectweb.salome_tmf.ihm.main.AttachmentViewWindow;
034: import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
035: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
036: import org.objectweb.salome_tmf.ihm.models.MyTableModel;
037: import org.objectweb.salome_tmf.ihm.models.TableSorter;
038:
039: import salomeTMF_plug.mantis.sqlWrapper.DefectWrapper;
040:
041: public class ViewLinkPanel extends JPanel implements ActionListener,
042: ListSelectionListener {
043:
044: MyTableModel execTestTableModel;
045: TableSorter sorter;
046: JTable execTestTable;
047: JScrollPane execTestTableScrollPane;
048: Vector ligneTbable;
049:
050: JButton viewCampButton;
051: JButton viewTestButton;
052: JButton viewExecTestButton;
053: JButton closeButton;
054: JPanel buttonsPanel;
055:
056: JDialog pDialog;
057: MantisPlugin pMantisPlugin;
058: boolean viewTest = true; // else view resexectest
059:
060: ViewLinkPanel(JDialog pDialog, DefectWrapper pDefectWrapper,
061: MantisPlugin pMantisPlugin) {
062: this .pDialog = pDialog;
063: this .pMantisPlugin = pMantisPlugin;
064: ligneTbable = new Vector();
065: viewTest = true;
066: initComponent();
067: loadData(pDefectWrapper, null);
068: }
069:
070: ViewLinkPanel(JDialog pDialog, DefectWrapper pDefectWrapper,
071: MantisPlugin pMantisPlugin, Test pTes) {
072: this .pDialog = pDialog;
073: this .pMantisPlugin = pMantisPlugin;
074: ligneTbable = new Vector();
075: viewTest = false;
076: initComponent();
077: loadData(pDefectWrapper, pTes);
078: }
079:
080: void initComponent() {
081: execTestTable = new JTable();
082:
083: execTestTableModel = new MyTableModel();
084: execTestTableModel
085: .addColumnNameAndColumn(org.objectweb.salome_tmf.ihm.languages.Language
086: .getInstance().getText("Environnements")); //Produit
087: execTestTableModel
088: .addColumnNameAndColumn(org.objectweb.salome_tmf.ihm.languages.Language
089: .getInstance().getText("Campagnes")); //Produit
090: execTestTableModel
091: .addColumnNameAndColumn(org.objectweb.salome_tmf.ihm.languages.Language
092: .getInstance().getText("Ex\u00E9cutions")
093: + "/"
094: + org.objectweb.salome_tmf.ihm.languages.Language
095: .getInstance()
096: .getText("R\u00E9sultats"));
097: execTestTableModel
098: .addColumnNameAndColumn(org.objectweb.salome_tmf.ihm.languages.Language
099: .getInstance().getText("Familles")
100: + "/"
101: + org.objectweb.salome_tmf.ihm.languages.Language
102: .getInstance().getText("Suites")); //Produit
103: execTestTableModel
104: .addColumnNameAndColumn(org.objectweb.salome_tmf.ihm.languages.Language
105: .getInstance().getText("Tests")); //Etat
106:
107: sorter = new TableSorter(execTestTableModel);
108: execTestTable.setModel(sorter);
109: sorter.setTableHeader(execTestTable.getTableHeader());
110: execTestTable
111: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
112: execTestTableScrollPane = new JScrollPane(execTestTable);
113: ListSelectionModel rowSM = execTestTable.getSelectionModel();
114: rowSM.addListSelectionListener(this );
115:
116: closeButton = new JButton(
117: org.objectweb.salome_tmf.ihm.languages.Language
118: .getInstance().getText("Fermer"));
119: closeButton.addActionListener(this );
120:
121: viewCampButton = new JButton(
122: org.objectweb.salome_tmf.ihm.languages.Language
123: .getInstance().getText("Visualiser")
124: + " "
125: + org.objectweb.salome_tmf.ihm.languages.Language
126: .getInstance().getText("Campagne"));
127: viewCampButton.addActionListener(this );
128: viewCampButton.setEnabled(false);
129:
130: viewTestButton = new JButton(
131: org.objectweb.salome_tmf.ihm.languages.Language
132: .getInstance().getText("Visualiser")
133: + " "
134: + org.objectweb.salome_tmf.ihm.languages.Language
135: .getInstance().getText("Test"));
136: viewTestButton.addActionListener(this );
137: viewTestButton.setEnabled(false);
138:
139: viewExecTestButton = new JButton(
140: org.objectweb.salome_tmf.ihm.languages.Language
141: .getInstance().getText("Visualiser")
142: + " "
143: + org.objectweb.salome_tmf.ihm.languages.Language
144: .getInstance().getText(
145: "Ex\u00E9cutions"));
146: viewExecTestButton.addActionListener(this );
147: viewExecTestButton.setEnabled(false);
148:
149: if (viewTest) {
150: buttonsPanel = new JPanel(new GridLayout(1, 4));
151: buttonsPanel.add(closeButton);
152: buttonsPanel.add(viewTestButton);
153: buttonsPanel.add(viewCampButton);
154: buttonsPanel.add(viewExecTestButton);
155:
156: } else {
157: buttonsPanel = new JPanel(new GridLayout(1, 3));
158: buttonsPanel.add(closeButton);
159: buttonsPanel.add(viewCampButton);
160: buttonsPanel.add(viewExecTestButton);
161: }
162:
163: setLayout(new BorderLayout());
164:
165: add(execTestTableScrollPane, BorderLayout.CENTER);
166: add(buttonsPanel, BorderLayout.SOUTH);
167: }
168:
169: void loadData(DefectWrapper pDefectWrapper, Test pTest) {
170: Project pProject = DataModel.getCurrentProject();
171: ArrayList listOfCampaign = pProject.getCampaignListFromModel();
172:
173: for (int i = 0; i < listOfCampaign.size(); i++) {
174: Campaign pCamp = (Campaign) listOfCampaign.get(i);
175: ArrayList listOfExecution = pCamp
176: .getExecutionListFromModel();
177: for (int j = 0; j < listOfExecution.size(); j++) {
178: Execution pExec = (Execution) listOfExecution.get(j);
179: ArrayList listOfExecutionRes = pExec
180: .getExecutionResultListFromModel();
181: for (int k = 0; k < listOfExecutionRes.size(); k++) {
182: ExecutionResult pExecutionResult = (ExecutionResult) listOfExecutionRes
183: .get(k);
184: Test[] tests = pExecutionResult
185: .getTestOrderedFromModel();
186: for (int l = 0; l < tests.length; l++) {
187: if (canTest(pTest, tests[l])) {
188: ExecutionTestResult pExecutionTestResult = pExecutionResult
189: .getExecutionTestResultFromModel(tests[l]);
190: if (isLinkToDefect(pExecutionTestResult,
191: pDefectWrapper)) {
192:
193: ArrayList dataList = new ArrayList();
194:
195: dataList.add(pExec
196: .getEnvironmentFromModel()
197: .getNameFromModel());
198: dataList.add(pCamp.getNameFromModel());
199: dataList.add(pExec.getNameFromModel()
200: + "/"
201: + pExecutionResult
202: .getNameFromModel());
203: dataList.add(tests[l]
204: .getTestListFromModel()
205: .getFamilyFromModel()
206: .getNameFromModel()
207: + "/"
208: + tests[l]
209: .getTestListFromModel()
210: .getNameFromModel());
211: dataList.add(tests[l]
212: .getNameFromModel());
213: execTestTableModel.addRow(dataList);
214:
215: ArrayList dataList2 = new ArrayList();
216: dataList2.add(pExec
217: .getEnvironmentFromModel());
218: dataList2.add(pCamp);
219: dataList2.add(pExec);
220: dataList2.add(pExecutionResult);
221: dataList2.add(tests[l]);
222: ligneTbable.add(dataList2);
223:
224: }
225: }
226: }
227: }
228: }
229: }
230: }
231:
232: boolean canTest(Test filtredTest, Test pTest) {
233: if (filtredTest == null) {
234: return true;
235: }
236: if (filtredTest.getIdBdd() == pTest.getIdBdd()) {
237: return true;
238: }
239: return false;
240: }
241:
242: boolean isLinkToDefect(ExecutionTestResult pExecutionTestResult,
243: DefectWrapper pDefectWrapper) {
244: Hashtable defectsWrapper = new Hashtable();
245: if (pExecutionTestResult != null) {
246: HashMap attacMap = pExecutionTestResult
247: .getAttachmentMapFromModel();
248: Set keysSet = attacMap.keySet();
249: for (Iterator iter = keysSet.iterator(); iter.hasNext();) {
250: try {
251: Object attachName = iter.next();
252: Attachment pAttach = (Attachment) attacMap
253: .get(attachName);
254: int bugid = pMantisPlugin.getIDofBug(pAttach);
255: if (bugid == pDefectWrapper.getId()) {
256: return true;
257: }
258: } catch (Exception ex) {
259: ex.printStackTrace();
260: }
261: }
262: }
263: return false;
264: }
265:
266: /********************* Listener *************************/
267: public void valueChanged(ListSelectionEvent e) {
268: //Ignore extra messages.
269: if (e.getValueIsAdjusting()) {
270: return;
271: }
272:
273: ListSelectionModel lsm = (ListSelectionModel) e.getSource();
274: if (lsm.isSelectionEmpty()) {
275: //no rows are selected
276: viewCampButton.setEnabled(false);
277: viewTestButton.setEnabled(false);
278: viewExecTestButton.setEnabled(false);
279: } else {
280: //int selectedRow = lsm.getMinSelectionIndex();
281: viewCampButton.setEnabled(true);
282: viewTestButton.setEnabled(true);
283: viewExecTestButton.setEnabled(true);
284: //selectedRow is selected
285: }
286: }
287:
288: public void actionPerformed(ActionEvent e) {
289: if (e.getSource().equals(viewCampButton)) {
290: viewCampPerformed(e);
291: } else if (e.getSource().equals(viewTestButton)) {
292: viewTestPerformed(e);
293: } else if (e.getSource().equals(viewExecTestButton)) {
294: viewExecTestPerformed(e);
295: } else if (e.getSource().equals(closeButton)) {
296: pDialog.dispose();
297: }
298: }
299:
300: void viewCampPerformed(ActionEvent e) {
301: int selectedRowIndex = execTestTable.getSelectedRow();
302:
303: if (selectedRowIndex != -1) {
304: int index = sorter.modelIndex(selectedRowIndex);
305: if (ligneTbable.size() >= index) {
306: try {
307: ArrayList pArrayList = (ArrayList) ligneTbable
308: .elementAt(index);
309: Campaign pCamp = (Campaign) pArrayList.get(1);
310: pDialog.dispose();
311: DataModel.view(pCamp);
312: } catch (Exception ex) {
313: ex.printStackTrace();
314: }
315: }
316: }
317: }
318:
319: void viewExecTestPerformed(ActionEvent e) {
320: int selectedRowIndex = execTestTable.getSelectedRow();
321:
322: if (selectedRowIndex != -1) {
323: int index = sorter.modelIndex(selectedRowIndex);
324: if (ligneTbable.size() >= index) {
325: try {
326: ArrayList pArrayList = (ArrayList) ligneTbable
327: .elementAt(index);
328: Test pTest = (Test) pArrayList.get(4);
329: ExecutionResult lastExecutionResult = (ExecutionResult) pArrayList
330: .get(3);
331: DataModel
332: .setCurrentExecutionTestResult(lastExecutionResult
333: .getExecutionTestResultFromModel(pTest));
334: DataModel
335: .setObervedExecutionResult(lastExecutionResult);
336: pDialog.dispose();
337: if (pTest instanceof ManualTest) {
338: new ActionDetailsView(
339: (ManualTest) pTest,
340: lastExecutionResult.getExecution(),
341: lastExecutionResult,
342: lastExecutionResult
343: .getExecutionTestResultFromModel(pTest));
344: } else {
345: new AttachmentViewWindow(
346: SalomeTMFContext.getBaseIHM(),
347: DataConstants.EXECUTION_RESULT_TEST,
348: DataModel
349: .getCurrentExecutionTestResult());
350: }
351: } catch (Exception ex) {
352: ex.printStackTrace();
353: }
354: }
355: }
356: }
357:
358: void viewTestPerformed(ActionEvent e) {
359: int selectedRowIndex = execTestTable.getSelectedRow();
360:
361: if (selectedRowIndex != -1) {
362: int index = sorter.modelIndex(selectedRowIndex);
363: if (ligneTbable.size() >= index) {
364: try {
365: ArrayList pArrayList = (ArrayList) ligneTbable
366: .elementAt(index);
367: Test pTest = (Test) pArrayList.get(4);
368: pDialog.dispose();
369: DataModel.view(pTest);
370: } catch (Exception ex) {
371: ex.printStackTrace();
372: }
373: }
374: }
375: }
376: }
|