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:
024: package salomeTMF_plug.requirements.ihm;
025:
026: import java.awt.BorderLayout;
027: import java.awt.Color;
028: import java.awt.Cursor;
029: import java.awt.Dimension;
030: import java.awt.GraphicsConfiguration;
031: import java.awt.GraphicsDevice;
032: import java.awt.GraphicsEnvironment;
033: import java.awt.GridLayout;
034: import java.awt.Rectangle;
035: import java.awt.event.ActionEvent;
036: import java.awt.event.ActionListener;
037: import java.io.File;
038: import java.io.FileInputStream;
039: import java.util.HashMap;
040: import java.util.Iterator;
041: import java.util.List;
042: import java.util.Observable;
043: import java.util.Observer;
044:
045: import javax.swing.BorderFactory;
046: import javax.swing.JButton;
047: import javax.swing.JFileChooser;
048: import javax.swing.JOptionPane;
049: import javax.swing.JPanel;
050: import javax.swing.JScrollPane;
051: import javax.swing.JSplitPane;
052: import javax.swing.ScrollPaneConstants;
053: import javax.swing.tree.DefaultMutableTreeNode;
054:
055: import org.dom4j.Document;
056: import org.dom4j.Element;
057: import org.dom4j.io.SAXReader;
058: import org.objectweb.salome_tmf.data.Attachment;
059: import org.objectweb.salome_tmf.data.FileAttachment;
060: import org.objectweb.salome_tmf.data.UrlAttachment;
061: import org.objectweb.salome_tmf.data.WithAttachment;
062: import org.objectweb.salome_tmf.ihm.languages.Language;
063: import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
064: import org.objectweb.salome_tmf.ihm.models.DynamicTree;
065: import org.objectweb.salome_tmf.ihm.models.ScriptFileFilter;
066: import org.objectweb.salome_tmf.ihm.tools.Tools;
067: import org.objectweb.salome_tmf.plugins.core.XMLLoaderPlugin;
068:
069: import salomeTMF_plug.requirements.ReqPlugin;
070: import salomeTMF_plug.requirements.data.ReqFamily;
071: import salomeTMF_plug.requirements.data.ReqLeaf;
072: import salomeTMF_plug.requirements.data.Requirement;
073:
074: public class RequirementPanel extends JPanel implements ActionListener,
075: Observer {
076: JButton addReqButton;
077: JButton delReqButton;
078: JButton addReqFamilyButton;
079: JButton findReqButton;
080: JButton renameReqButton;
081: JButton reloadReqButton;
082: JButton creatTestReqButton;
083: JButton importerReqButton;
084:
085: JPanel buttonPanel;
086: JPanel treePanel;
087:
088: RequirementTree reqTree;
089: RequirementDescriptionPanel pRequirementDescriptionPanel;
090:
091: //JApplet ptrSalome;
092: FiltrePanel pFiltrePanel;
093: CoverFiltrePanel pCoverFiltrePanel;
094: InfoFiltrePanel pInfoFiltrePanel;
095:
096: boolean loadData = false;
097: Requirement pReq = null;
098: ReqPlugin pReqPlugin;
099: StatRequirement pStatRequirement;
100:
101: public RequirementPanel(StatRequirement _pStatRequirement,
102: ReqPlugin pReqPlugin) {
103: super (new BorderLayout());
104: this .pReqPlugin = pReqPlugin;
105: //this.ptrSalome = ptrSalome;
106: initComponent(_pStatRequirement);
107: }
108:
109: void initComponent(StatRequirement _pStatRequirement) {
110: int t_x = 1024;
111: int t_y = 768;
112: try {
113: GraphicsEnvironment ge = GraphicsEnvironment
114: .getLocalGraphicsEnvironment();
115: GraphicsDevice[] gs = ge.getScreenDevices();
116: GraphicsDevice gd = gs[0];
117: GraphicsConfiguration[] gc = gd.getConfigurations();
118: Rectangle r = gc[0].getBounds();
119: t_x = r.width;
120: t_y = r.height;
121:
122: } catch (Exception E) {
123:
124: }
125: pStatRequirement = _pStatRequirement;
126: addReqButton = new JButton(Language.getInstance().getText(
127: "Ajouter")
128: + " " + Language.getInstance().getText("Exigence"));
129: addReqButton.addActionListener(this );
130:
131: delReqButton = new JButton(Language.getInstance().getText(
132: "Supprimer")
133: + " " + Language.getInstance().getText("Exigence"));
134: delReqButton.addActionListener(this );
135: delReqButton.setEnabled(false);
136:
137: addReqFamilyButton = new JButton(Language.getInstance()
138: .getText("Ajouter")
139: + " " + Language.getInstance().getText("Branche"));
140: addReqFamilyButton.addActionListener(this );
141:
142: findReqButton = new JButton(Language.getInstance().getText(
143: "Chercher..."));
144: findReqButton.addActionListener(this );
145:
146: renameReqButton = new JButton(Language.getInstance().getText(
147: "Renommer"));
148: renameReqButton.addActionListener(this );
149: renameReqButton.setEnabled(false);
150:
151: reloadReqButton = new JButton(Language.getInstance().getText(
152: "Rafraichir"));
153: reloadReqButton.addActionListener(this );
154: reloadReqButton.setEnabled(true);
155:
156: creatTestReqButton = new JButton(Language.getInstance()
157: .getText("Generer_les_tests"));
158: creatTestReqButton.addActionListener(this );
159: creatTestReqButton.setEnabled(true);
160:
161: importerReqButton = new JButton(Language.getInstance().getText(
162: "Importer")
163: + " " + Language.getInstance().getText("Exigence"));
164: importerReqButton.addActionListener(this );
165: importerReqButton.setEnabled(true);
166:
167: buttonPanel = new JPanel(new GridLayout(3, 3));
168: buttonPanel.add(addReqFamilyButton);
169: buttonPanel.add(addReqButton);
170: buttonPanel.add(delReqButton);
171: buttonPanel.add(findReqButton);
172: buttonPanel.add(renameReqButton);
173: buttonPanel.add(creatTestReqButton);
174: buttonPanel.add(reloadReqButton);
175: buttonPanel.add(importerReqButton);
176: buttonPanel.setBorder(BorderFactory.createRaisedBevelBorder());
177:
178: reqTree = new RequirementTree();
179: JScrollPane scrollPane = new JScrollPane(reqTree,
180: ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
181: ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
182: treePanel = new JPanel(new GridLayout(1, 0));
183: treePanel.add(scrollPane);
184:
185: JPanel lesFiltresPanel = new JPanel(new GridLayout(2, 1));
186: lesFiltresPanel.setBorder(BorderFactory.createTitledBorder(
187: BorderFactory.createLineBorder(Color.BLACK), "Filtre"));
188:
189: JPanel filtresPanel1 = new JPanel(new GridLayout(2, 1));
190:
191: pFiltrePanel = new FiltrePanel((FilterReqTreeModel) reqTree
192: .getModel(), this );
193: pCoverFiltrePanel = new CoverFiltrePanel(
194: (FilterReqTreeModel) reqTree.getModel(), this );
195: filtresPanel1.add(pFiltrePanel);
196: filtresPanel1.add(pCoverFiltrePanel);
197: lesFiltresPanel.add(filtresPanel1);
198: pInfoFiltrePanel = new InfoFiltrePanel(
199: (FilterReqTreeModel) reqTree.getModel(), this );
200: lesFiltresPanel.add(pInfoFiltrePanel);
201: reqTree.setStatTools(pStatRequirement, pFiltrePanel);
202:
203: JPanel buttonsAndTree = new JPanel(new BorderLayout());
204: buttonsAndTree.add(buttonPanel, BorderLayout.NORTH);
205: buttonsAndTree.add(treePanel, BorderLayout.CENTER);
206: buttonsAndTree.add(lesFiltresPanel, BorderLayout.SOUTH);
207:
208: //buttonsAndTree.setPreferredSize(new Dimension(380,380));
209: buttonsAndTree.setMinimumSize(new Dimension(t_x / 4, t_y));
210: buttonsAndTree.setMaximumSize(new Dimension(t_x / 2, t_y));
211:
212: pRequirementDescriptionPanel = new RequirementDescriptionPanel(
213: pStatRequirement, pFiltrePanel, reqTree);
214: pRequirementDescriptionPanel.setPreferredSize(new Dimension(
215: t_x / 4 * 2, t_y));
216: reqTree.addObserver(this );
217:
218: JSplitPane splitPane = new JSplitPane(
219: JSplitPane.HORIZONTAL_SPLIT, buttonsAndTree,
220: pRequirementDescriptionPanel);
221: splitPane.setDividerLocation(t_x / 3);
222: add(splitPane);
223:
224: //add(pRequirementDescriptionPanel, BorderLayout.CENTER);
225: //add(buttonsAndTree,BorderLayout.WEST);
226: pReq = (Requirement) reqTree.parent.getUserObject();
227: pRequirementDescriptionPanel.setRequirement(pReq);
228: //pRequirementDescriptionPanel.setVisible(false);
229: pRequirementDescriptionPanel.initCalcStatAllCover(pFiltrePanel
230: .getFiltre());
231: //pRequirementDescriptionPanel.setPie3D(pFiltrePanel.getFiltre());
232: reloadReqPerformed();
233: }
234:
235: public void update(Observable pObservable, Object arg) {
236: //System.out.println("[RequirementDescriptionPanel->update] : " + arg + ", observable " + pObservable);
237: if (loadData) {
238: return;
239: }
240:
241: reqTree.setCursor(new Cursor(Cursor.WAIT_CURSOR));
242:
243: if (arg instanceof ReqEvent) {
244: ReqEvent event = (ReqEvent) arg;
245: if (event.code == ReqEvent.REQSELECTED) {
246: pReq = (Requirement) event.arg;
247: if (pReq.isFamilyReq()) {
248: addReqFamilyButton.setEnabled(true);
249: addReqButton.setEnabled(true);
250: } else {
251: addReqFamilyButton.setEnabled(false);
252: addReqButton.setEnabled(false);
253: }
254: if (pReq.getParent() == null) {
255: delReqButton.setEnabled(false);
256: renameReqButton.setEnabled(false);
257: //pRequirementDescriptionPanel.setVisible(false);
258: //pRequirementDescriptionPanel.setPie3D(pFiltrePanel.getFiltre());
259: } else {
260: delReqButton.setEnabled(true);
261: renameReqButton.setEnabled(true);
262: //pRequirementDescriptionPanel.unsetPie3D(pFiltrePanel.getFiltre(), pReq);
263: }
264: } else if (event.code == ReqEvent.FILTRE_REQ_CHANGE) {
265: Requirement pReq = reqTree.getCurrentRequirement();
266: try {
267: if (pReq != null) {
268: //if (pReq != null && pReq.getParent() != null) {
269: pStatRequirement.update(pReq, pFiltrePanel
270: .getFilter(), true);
271: pRequirementDescriptionPanel
272: .setRequirement(pReq);
273: }
274: } catch (Exception e) {
275: e.printStackTrace();
276: }
277:
278: }
279: if (pObservable != null) {
280: pRequirementDescriptionPanel.update(pObservable, arg);
281: }
282: }
283: reqTree.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
284: }
285:
286: public void setTestTree(DynamicTree pDynamicTree) {
287: pRequirementDescriptionPanel.setTestTree(pDynamicTree);
288: }
289:
290: public void actionPerformed(ActionEvent e) {
291: if (e.getSource().equals(addReqButton)) {
292: addReqPerformed(e);
293: } else if (e.getSource().equals(addReqFamilyButton)) {
294: addReqFamilyPerformed(e);
295: } else if (e.getSource().equals(delReqButton)) {
296: delReqPerformed(e);
297: } else if (e.getSource().equals(findReqButton)) {
298: findReqPerformed(e);
299: } else if (e.getSource().equals(renameReqButton)) {
300: renameReqPerformed(e);
301: } else if (e.getSource().equals(reloadReqButton)) {
302: reloadReqPerformed();
303: } else if (e.getSource().equals(creatTestReqButton)) {
304: //reqTree.print();reqTree.
305: setCursor(new Cursor(Cursor.WAIT_CURSOR));
306: new SelectReqTree(reqTree, Language.getInstance().getText(
307: "Gestion_des_tests"));
308: setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
309:
310: } else if (e.getSource().equals(importerReqButton)) {
311: importerReqPerformed();
312: }
313: }
314:
315: void importerReqPerformed() {
316: try {
317: String xmlFile = null;
318: JFileChooser fileChooser = new JFileChooser();
319: fileChooser.addChoosableFileFilter(new ScriptFileFilter(
320: ("XML [*.xml]"), ".xml"));
321: int returnVal = fileChooser.showDialog(this , Language
322: .getInstance().getText("Selection"));
323: if (returnVal == JFileChooser.APPROVE_OPTION) {
324: xmlFile = fileChooser.getSelectedFile()
325: .getAbsolutePath();
326: if (xmlFile.indexOf(".") != -1) {
327: if (!xmlFile.substring(xmlFile.lastIndexOf("."))
328: .equals(".xml")) {
329: xmlFile += ".xml";
330: }
331: } else {
332: xmlFile += ".xml";
333: }
334:
335: }
336: if (xmlFile != null && !xmlFile.equals("")) {
337: pReqPlugin.updateProjectFromXML(xmlFile);
338: }
339: } catch (Exception ex) {
340: Tools.ihmExceptionView(ex);
341: }
342: }
343:
344: public void reloadReqPerformed() {
345: try {
346: SalomeTMFContext.getInstance().getSalomeFrame().setCursor(
347: new Cursor(Cursor.WAIT_CURSOR));
348: loadData = true;
349: reqTree.reload();
350: //DataLoader.loadData(reqTree);
351: loadData = false;
352: reqTree.setPathToRoot();
353: pRequirementDescriptionPanel.pStatRequirement
354: .clearStat(true);
355: SalomeTMFContext.getInstance().getSalomeFrame().setCursor(
356: new Cursor(Cursor.DEFAULT_CURSOR));
357:
358: } catch (Exception ex) {
359: SalomeTMFContext.getInstance().getSalomeFrame().setCursor(
360: new Cursor(Cursor.DEFAULT_CURSOR));
361: ex.printStackTrace();
362: }
363: }
364:
365: void renameReqPerformed(ActionEvent e) {
366: Requirement pReq = reqTree.getCurrentRequirement();
367:
368: if (pReq == null) {
369: //System.out.println("Current req is null");
370: return;
371: }
372: CustomDialog dialog = new CustomDialog(SalomeTMFContext
373: .getInstance().getSalomeFrame(), Language.getInstance()
374: .getText("Renommer")
375: + " " + Language.getInstance().getText("Exigence"),
376: Language.getInstance().getText("Entrer_nom_exigence"),
377: pReq.getNameFromModel());
378: dialog.setVisible(true);
379: if (dialog.getValue() != null) {
380: try {
381: pReq.updateNameInDBAndModel(dialog.getValue());
382: DefaultMutableTreeNode node = reqTree.getCurrentNode();
383: reqTree.refreshCurrent();
384: } catch (Exception ex) {
385: //msg
386: SalomeTMFContext.getInstance().showMessage(
387: Language.getInstance().getText("Nom_existe"));
388: ex.printStackTrace();
389: }
390: }
391: }
392:
393: void addReqPerformed(ActionEvent e) {
394: CustomDialog dialog = new CustomDialog(SalomeTMFContext
395: .getInstance().getSalomeFrame(), Language.getInstance()
396: .getText("Nouvelle_exigence"), Language.getInstance()
397: .getText("Entrer_nom_exigence"), null);
398: dialog.setVisible(true);
399: if (dialog.getValue() != null) {
400: Requirement req = new ReqLeaf(dialog.getValue(), "", null,
401: pFiltrePanel.getMaxSelected());
402: // Desactiver le filtre
403: addReq(req);
404: // Reactiver le filtre
405: }
406: }
407:
408: void addReqFamilyPerformed(ActionEvent e) {
409: CustomDialog dialog = new CustomDialog(SalomeTMFContext
410: .getInstance().getSalomeFrame(), Language.getInstance()
411: .getText("Nouvelle_exigence"), Language.getInstance()
412: .getText("Entrer_nom_branche"), null);
413: dialog.setVisible(true);
414: if (dialog.getValue() != null) {
415: reInitFiltre();
416: Requirement req = new ReqFamily(dialog.getValue(), "", null);
417: addReq(req);
418:
419: }
420: }
421:
422: void addReq(Requirement req) {
423: try {
424: ReqFamily pReqParent = (ReqFamily) reqTree
425: .getCurrentRequirement();
426: req.setParent(pReqParent);
427: req.addInDB();
428: reqTree.addRequirementToCurrent(req);
429: if (pReqParent != null) {
430: pReqParent.addRequirement(req);
431: }
432:
433: } catch (Exception ex) {
434: Tools.ihmExceptionView(ex);
435: ex.printStackTrace();
436: }
437: }
438:
439: void delReqPerformed(ActionEvent e) {
440: if (deleteConfirme(org.objectweb.salome_tmf.ihm.languages.Language
441: .getInstance().getText("Exigence"))) {
442: reqTree.deleteCurrentRequirement();
443: }
444: }
445:
446: boolean deleteConfirme(String quoi) {
447: Object[] options = {
448: org.objectweb.salome_tmf.ihm.languages.Language
449: .getInstance().getText("Oui"),
450: org.objectweb.salome_tmf.ihm.languages.Language
451: .getInstance().getText("Non") };
452: int choice = -1;
453:
454: choice = SalomeTMFContext.getInstance().askQuestion(
455: org.objectweb.salome_tmf.ihm.languages.Language
456: .getInstance().getText(
457: "confimation_suppression2")
458: + " " + quoi + " ?",
459: org.objectweb.salome_tmf.ihm.languages.Language
460: .getInstance().getText("Attention_!"),
461: JOptionPane.WARNING_MESSAGE, options);
462:
463: if (choice == JOptionPane.YES_OPTION) {
464: return true;
465: } else {
466: return false;
467: }
468: }
469:
470: void findReqPerformed(ActionEvent e) {
471: CustomDialog dialog = new CustomDialog(SalomeTMFContext
472: .getInstance().getSalomeFrame(), Language.getInstance()
473: .getText("Rechercher_exigence"), Language.getInstance()
474: .getText("Entrer_nom_exigence"), null);
475: dialog.setVisible(true);
476: if (dialog.getValue() != null) {
477: boolean isID = false;
478: try {
479: Integer.parseInt(dialog.getValue());
480: isID = true;
481: } catch (Exception ex) {
482: isID = false;
483: }
484: SalomeTMFContext.getInstance().getSalomeFrame().setCursor(
485: new Cursor(Cursor.WAIT_CURSOR));
486: reqTree.findRequirementFromCurrent(dialog.getValue(), isID);
487: SalomeTMFContext.getInstance().getSalomeFrame().setCursor(
488: new Cursor(Cursor.DEFAULT_CURSOR));
489: }
490: }
491:
492: public RequirementTree getTree() {
493: return reqTree;
494: }
495:
496: /*public void focusChange(){
497: if (pRequirementDescriptionPanel != null){
498: pRequirementDescriptionPanel.doUpdateDesc();
499: }
500: }*/
501:
502: /*public static void main(String arg[]){
503: JFrame pFrame = new JFrame("Requirement Plugins");
504: RequirementPanel pRequirementPanel = new RequirementPanel();
505: pFrame.getContentPane().add(pRequirementPanel);
506: pFrame.pack();
507: pFrame.setVisible(true);
508: }*/
509:
510: void reInitFiltre() {
511: pFiltrePanel.reInit(true);
512: pCoverFiltrePanel.reInit(true);
513: pInfoFiltrePanel.reInit(true);
514: }
515:
516: }
|