001: package org.objectweb.salome_tmf.ihm.main;
002:
003: import java.awt.BorderLayout;
004: import java.awt.Container;
005: import java.awt.Dimension;
006: import java.awt.FlowLayout;
007: import java.awt.GraphicsConfiguration;
008: import java.awt.GraphicsDevice;
009: import java.awt.GraphicsEnvironment;
010: import java.awt.Rectangle;
011: import java.awt.event.ActionEvent;
012: import java.awt.event.ActionListener;
013: import java.util.ArrayList;
014: import java.util.Enumeration;
015: import java.util.Hashtable;
016: import java.util.Vector;
017:
018: import javax.swing.BorderFactory;
019: import javax.swing.JButton;
020: import javax.swing.JDialog;
021: import javax.swing.JPanel;
022: import javax.swing.JScrollPane;
023: import javax.swing.JTabbedPane;
024: import javax.swing.JTable;
025: import javax.swing.ListSelectionModel;
026: import javax.swing.event.ListSelectionEvent;
027: import javax.swing.event.ListSelectionListener;
028: import javax.swing.table.DefaultTableModel;
029: import javax.swing.tree.DefaultMutableTreeNode;
030: import javax.swing.tree.TreePath;
031:
032: import org.objectweb.salome_tmf.data.Campaign;
033: import org.objectweb.salome_tmf.data.Execution;
034: import org.objectweb.salome_tmf.data.ExecutionResult;
035: import org.objectweb.salome_tmf.data.Test;
036: import org.objectweb.salome_tmf.ihm.languages.Language;
037: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
038: import org.objectweb.salome_tmf.ihm.models.DynamicTree;
039: import org.objectweb.salome_tmf.plugins.UICompCst;
040:
041: public class ViewCampaignOfTest extends JDialog implements
042: ActionListener, ListSelectionListener {
043:
044: Test pTest;
045: Hashtable campHash;
046: JButton validateButton;
047: JButton viewButton;
048: JTable campTable;
049: JScrollPane tablePane;
050:
051: public ViewCampaignOfTest(Test _pTest) {
052: super (SalomeTMFContext.getInstance().getSalomeFrame());
053:
054: int t_x = 1024 - 100;
055: int t_y = 768 - 50;
056: try {
057: GraphicsEnvironment ge = GraphicsEnvironment
058: .getLocalGraphicsEnvironment();
059: GraphicsDevice[] gs = ge.getScreenDevices();
060: GraphicsDevice gd = gs[0];
061: GraphicsConfiguration[] gc = gd.getConfigurations();
062: Rectangle r = gc[0].getBounds();
063: t_x = r.width - 100;
064: t_y = r.height - 50;
065: } catch (Exception E) {
066:
067: }
068:
069: pTest = _pTest;
070: campHash = new Hashtable();
071:
072: setResizable(false);
073: setModal(true);
074: setTitle(Language.getInstance().getText("Campagnes_de_test"));
075:
076: JPanel panelButton = new JPanel(new FlowLayout());
077: validateButton = new JButton(Language.getInstance().getText(
078: "Valider"));
079: validateButton.addActionListener(this );
080: viewButton = new JButton(Language.getInstance().getText(
081: "Visualiser"));
082: viewButton.addActionListener(this );
083: panelButton.add(viewButton);
084: panelButton.add(validateButton);
085:
086: CampTableModel model = new CampTableModel();
087: campTable = new JTable(model);
088: model.addColumn(Language.getInstance().getText("Campagne"));
089: model.addColumn(Language.getInstance().getText(
090: "Détails_d'exécutions"));
091: campTable.setPreferredScrollableViewportSize(new Dimension(600,
092: 200));
093: campTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
094: ListSelectionModel rowSM = campTable.getSelectionModel();
095: rowSM.addListSelectionListener(this );
096:
097: tablePane = new JScrollPane(campTable);
098: tablePane.setBorder(BorderFactory.createRaisedBevelBorder());
099:
100: Container contentPaneFrame = this .getContentPane();
101: contentPaneFrame.add(tablePane, BorderLayout.CENTER);
102: contentPaneFrame.add(panelButton, BorderLayout.SOUTH);
103: initData();
104:
105: /*
106: this.pack();
107: this.setLocationRelativeTo(this.getParent());
108: this.setVisible(true);
109: */
110: centerScreen();
111: }
112:
113: void centerScreen() {
114: Dimension dim = getToolkit().getScreenSize();
115: this .pack();
116: Rectangle abounds = getBounds();
117: setLocation((dim.width - abounds.width) / 2,
118: (dim.height - abounds.height) / 2);
119: this .setVisible(true);
120: requestFocus();
121: }
122:
123: void initData() {
124: if (pTest == null) {
125: close();
126: return;
127: }
128: campHash.clear();
129: ArrayList campaignList = DataModel.getCurrentProject()
130: .getCampaignOfTest(pTest);
131: if (campaignList != null && campaignList.size() > 0) {
132: int size = campaignList.size();
133: for (int i = 0; i < size; i++) {
134: Campaign pCampaign = (Campaign) campaignList.get(i);
135: campHash.put(pCampaign.getNameFromModel(), pCampaign);
136: }
137: Enumeration enumCamp = campHash.elements();
138: int num = 0;
139: while (enumCamp.hasMoreElements()) {
140: Vector data = new Vector();
141: Campaign pCampaign = (Campaign) enumCamp.nextElement();
142: data.add(pCampaign.getNameFromModel());
143: ArrayList executionList = pCampaign
144: .getExecutionListFromModel();
145: if (executionList != null && executionList.size() > 0) {
146: //Echec=Echec Inconclusif=Inconclusif Succ\u00E8s=Succ\u00E8s
147: int sizeExecutionList = executionList.size();
148: Hashtable statusTable = new Hashtable();
149: String res = "";
150: boolean first = true;
151:
152: for (int j = 0; j < sizeExecutionList; j++) {
153: Execution pExec = (Execution) executionList
154: .get(j);
155: if (pExec != null
156: && pExec
157: .getExecutionResultListFromModel() != null
158: && pExec
159: .getExecutionResultListFromModel()
160: .size() > 0) {
161: ArrayList executionResultList = pExec
162: .getExecutionResultListFromModel();
163: int sizeExecutionResList = executionResultList
164: .size();
165: for (int k = 0; k < sizeExecutionResList; k++) {
166: ExecutionResult pExecutionResult = (ExecutionResult) executionResultList
167: .get(k);
168: String status = pExecutionResult
169: .getTestResultStatusFromModel(pTest);
170: Integer occStatus = (Integer) statusTable
171: .get(status);
172: int val = 1;
173: if (occStatus != null) {
174: val = occStatus.intValue() + 1;
175: }
176: statusTable.put(status,
177: new Integer(val));
178: }
179: }
180: }
181: if (statusTable.isEmpty()) {
182: data.add(Language.getInstance().getText(
183: "Pas_d_resultat_execution"));
184: } else {
185: Enumeration enumStatus = statusTable.keys();
186: while (enumStatus.hasMoreElements()) {
187: String key = (String) enumStatus
188: .nextElement();
189: if (first) {
190: res += key + " : "
191: + statusTable.get(key);
192: first = false;
193: } else {
194: res += ", " + key + " : "
195: + statusTable.get(key);
196: }
197: }
198: data.add(res);
199: }
200:
201: } else {
202: data.add(Language.getInstance().getText(
203: "Pas_d_execution"));
204: }
205: ((CampTableModel) campTable.getModel()).insertRow(num,
206: data);
207: num++;
208: }
209:
210: } else {
211: close();
212: return;
213: }
214: }
215:
216: void viewCampPerformed(ActionEvent e) {
217: int selectedRow = campTable.getSelectedRow();
218:
219: if (selectedRow > -1) {
220: Campaign pCamp = (Campaign) campHash.get(campTable
221: .getValueAt(selectedRow, 0));
222: DataModel.view(pCamp);
223: close();
224: }
225: }
226:
227: /*************************** Listener *************************/
228:
229: void close() {
230: setVisible(false);
231: dispose();
232: }
233:
234: public void actionPerformed(ActionEvent e) {
235: if (e.getSource().equals(validateButton)) {
236: close();
237: } else if (e.getSource().equals(viewButton)) {
238: viewCampPerformed(e);
239: }
240: }
241:
242: public void valueChanged(ListSelectionEvent e) {
243: //Ignore extra messages.
244: if (e.getValueIsAdjusting()) {
245: return;
246: }
247:
248: ListSelectionModel lsm = (ListSelectionModel) e.getSource();
249: if (lsm.isSelectionEmpty()) {
250: //no rows are selected
251: viewButton.setEnabled(false);
252: } else {
253: //int selectedRow = lsm.getMinSelectionIndex();
254: viewButton.setEnabled(true);
255: //selectedRow is selected
256: }
257: }
258:
259: class CampTableModel extends DefaultTableModel {
260: public boolean isCellEditable(int row, int col) {
261: return false;
262: } // Fin de la m?thode isCellEditable/2
263:
264: public void clearTable() {
265: int nbRow = getRowCount();
266: for (int i = 0; i < nbRow; i++) {
267: removeRow(0);
268: }
269: fireTableStructureChanged();
270: }
271: }
272: }
|