0001: /*
0002: * SalomeTMF is a Test Management Framework
0003: * Copyright (C) 2005 France Telecom R&D
0004: *
0005: * This library is free software; you can redistribute it and/or
0006: * modify it under the terms of the GNU Lesser General Public
0007: * License as published by the Free Software Foundation; either
0008: * version 2 of the License, or (at your option) any later version.
0009: *
0010: * This library is distributed in the hope that it will be useful,
0011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0013: * Lesser General Public License for more details.
0014: *
0015: * You should have received a copy of the GNU Lesser General Public
0016: * License along with this library; if not, write to the Free Software
0017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0018: *
0019: * @author Marche Mikael
0020: *
0021: * Contact: mikael.marche@rd.francetelecom.com
0022: */
0023:
0024: package salomeTMF_plug.requirements;
0025:
0026: import java.awt.Cursor;
0027: import java.awt.FlowLayout;
0028: import java.awt.event.ActionEvent;
0029: import java.awt.event.ActionListener;
0030: import java.io.File;
0031: import java.io.FileInputStream;
0032: import java.net.URL;
0033: import java.util.ArrayList;
0034: import java.util.Collection;
0035: import java.util.Enumeration;
0036: import java.util.HashMap;
0037: import java.util.Hashtable;
0038: import java.util.Iterator;
0039: import java.util.List;
0040: import java.util.Map;
0041: import java.util.Observable;
0042: import java.util.Observer;
0043: import java.util.Vector;
0044:
0045: import javax.swing.JButton;
0046: import javax.swing.JCheckBox;
0047: import javax.swing.JMenu;
0048: import javax.swing.JMenuItem;
0049: import javax.swing.JOptionPane;
0050: import javax.swing.JPanel;
0051: import javax.swing.JTabbedPane;
0052: import javax.swing.JTable;
0053: import javax.swing.JTree;
0054: import javax.swing.ListSelectionModel;
0055: import javax.swing.event.ListSelectionEvent;
0056: import javax.swing.event.ListSelectionListener;
0057: import javax.swing.tree.DefaultMutableTreeNode;
0058: import javax.swing.tree.DefaultTreeModel;
0059:
0060: import org.dom4j.Document;
0061: import org.dom4j.DocumentHelper;
0062: import org.dom4j.Element;
0063: import org.dom4j.io.SAXReader;
0064: import org.java.plugin.Extension;
0065: import org.java.plugin.ExtensionPoint;
0066: import org.java.plugin.Plugin;
0067: import org.java.plugin.PluginDescriptor;
0068: import org.java.plugin.PluginManager;
0069: import org.objectweb.salome_tmf.api.Api;
0070: import org.objectweb.salome_tmf.api.ApiConstants;
0071: import org.objectweb.salome_tmf.api.Util;
0072: import org.objectweb.salome_tmf.api.data.ProjectWrapper;
0073: import org.objectweb.salome_tmf.api.data.TestWrapper;
0074: import org.objectweb.salome_tmf.api.sql.ISQLProject;
0075: import org.objectweb.salome_tmf.data.Action;
0076: import org.objectweb.salome_tmf.data.Attachment;
0077: import org.objectweb.salome_tmf.data.Campaign;
0078: import org.objectweb.salome_tmf.data.DataConstants;
0079: import org.objectweb.salome_tmf.data.DataSet;
0080: import org.objectweb.salome_tmf.data.Environment;
0081: import org.objectweb.salome_tmf.data.Execution;
0082: import org.objectweb.salome_tmf.data.ExecutionResult;
0083: import org.objectweb.salome_tmf.data.ExecutionTestResult;
0084: import org.objectweb.salome_tmf.data.Family;
0085: import org.objectweb.salome_tmf.data.FileAttachment;
0086: import org.objectweb.salome_tmf.data.Parameter;
0087: import org.objectweb.salome_tmf.data.Project;
0088: import org.objectweb.salome_tmf.data.SalomeEvent;
0089: import org.objectweb.salome_tmf.data.Test;
0090: import org.objectweb.salome_tmf.data.TestList;
0091: import org.objectweb.salome_tmf.data.UrlAttachment;
0092: import org.objectweb.salome_tmf.data.WithAttachment;
0093: import org.objectweb.salome_tmf.ihm.languages.Language;
0094: import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
0095: import org.objectweb.salome_tmf.ihm.main.SalomeTMFPanels;
0096: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
0097: import org.objectweb.salome_tmf.ihm.models.DynamicTree;
0098: import org.objectweb.salome_tmf.ihm.tools.Tools;
0099: import org.objectweb.salome_tmf.plugins.IPlugObject;
0100: import org.objectweb.salome_tmf.plugins.UICompCst;
0101: import org.objectweb.salome_tmf.plugins.core.Admin;
0102: import org.objectweb.salome_tmf.plugins.core.Common;
0103: import org.objectweb.salome_tmf.plugins.core.ReqManager;
0104: import org.objectweb.salome_tmf.plugins.core.XMLLoaderPlugin;
0105: import org.objectweb.salome_tmf.plugins.core.XMLPrinterPlugin;
0106: import org.objectweb.salome_tmf.plugins.core.XMLWriterPlugin;
0107:
0108: import salomeTMF_plug.requirements.data.ReqLeaf;
0109: import salomeTMF_plug.requirements.data.Requirement;
0110: import salomeTMF_plug.requirements.ihm.ExecResultStatDialog;
0111: import salomeTMF_plug.requirements.ihm.RequirementActionPanel;
0112: import salomeTMF_plug.requirements.ihm.RequirementCampPanel;
0113: import salomeTMF_plug.requirements.ihm.RequirementPanel;
0114: import salomeTMF_plug.requirements.ihm.RequirementTestPanel;
0115: import salomeTMF_plug.requirements.ihm.SelectRequirement;
0116: import salomeTMF_plug.requirements.ihm.StatRequirement;
0117: import salomeTMF_plug.requirements.sqlWrapper.ISQLRequirement;
0118: import salomeTMF_plug.requirements.sqlWrapper.ReqWrapper;
0119: import salomeTMF_plug.requirements.sqlWrapper.SQLWrapper;
0120:
0121: public class ReqPlugin extends Plugin implements ReqManager, Common,
0122: Admin, XMLPrinterPlugin, XMLLoaderPlugin, Observer,
0123: ActionListener, ListSelectionListener {
0124: //JApplet ptrSalome;
0125: String id_plugin;
0126:
0127: RequirementPanel pRequirementPanel;
0128: RequirementTestPanel pRequirementMTestPanel;
0129: RequirementTestPanel pRequirementATestPanel;
0130: boolean ACTION_REQ = false;
0131: RequirementActionPanel pRequirementActionPanel;
0132: RequirementCampPanel pRequirementCampPanel;
0133: DynamicTree campaignDynamicTree;
0134: //ResultPanel pResultPanel;
0135:
0136: JButton statResExecButton;
0137: static JTabbedPane salomeMainTabs;
0138: static int tabIndex = -1;
0139: static Project project_ref = null;
0140: static boolean isGlobalProject;
0141: ISQLRequirement pSQLRequirement = null;
0142:
0143: StatRequirement pStatRequirement;
0144:
0145: ImportXMLReq pImportXMLReq;
0146:
0147: final static String REQ_NAME = "SALOME_REQ_PLUG";
0148:
0149: private boolean mandatoryImport = false;
0150: private boolean mandatoryExport = false;
0151:
0152: public ReqPlugin(PluginManager manager, PluginDescriptor descr) {
0153: super (manager, descr);
0154: pStatRequirement = new StatRequirement();
0155: id_plugin = descr.getId() + ".Common";
0156:
0157: project_ref = DataModel.getCurrentProject();
0158: isGlobalProject = false;
0159: Collection colExt = descr.getExtensions();
0160: Iterator it = colExt.iterator();
0161: while (it.hasNext()) {
0162: Extension ext = (Extension) it.next();
0163: if (ext.getUniqueId().equals(
0164: "requirements@requirements.ReqManager")) {
0165: Collection colAtt = ext.getParameters();
0166: Iterator it2 = colAtt.iterator();
0167: while (it2.hasNext()) {
0168:
0169: org.java.plugin.Extension.Parameter param = (org.java.plugin.Extension.Parameter) it2
0170: .next();
0171: if (param.getId().equals("projectref")) {
0172: try {
0173: String project_name = param.rawValue();
0174: ISQLProject pISQLProject = Api
0175: .getISQLObjectFactory()
0176: .getISQLProject();
0177: ProjectWrapper pProjectWrapper = pISQLProject
0178: .getProject(project_name);
0179: if (pProjectWrapper != null) {
0180: project_ref = new Project(
0181: pProjectWrapper);
0182: if (project_ref.getIdBdd() == DataModel
0183: .getCurrentProject().getIdBdd()) {
0184: isGlobalProject = true;
0185: }
0186: Util
0187: .log("[ReqPlugin-> ReqPlugin] Project is "
0188: + project_ref
0189: .getNameFromModel());
0190: } else {
0191: Util
0192: .log("[ReqPlugin-> ReqPlugin] Project "
0193: + project_name
0194: + " not found");
0195: }
0196: } catch (Exception e) {
0197:
0198: }
0199: }
0200: }
0201: }
0202: }
0203: }
0204:
0205: /********************* extends Plugin**********************************/
0206:
0207: /**
0208: * @see org.java.plugin.Plugin()
0209: */
0210: protected void doStart() throws Exception {
0211:
0212: }
0213:
0214: /**
0215: * @see org.java.plugin.Plugin()
0216: */
0217: protected void doStop() throws Exception {
0218: // no-op
0219: }
0220:
0221: //********************* interface common ********************//
0222:
0223: public void activatePluginInCampToolsMenu(javax.swing.JMenu jMenu) {
0224: jMenu.addSeparator();
0225: jMenu.add(createJMenu());
0226: }
0227:
0228: public void activatePluginInDataToolsMenu(javax.swing.JMenu jMenu) {
0229: }
0230:
0231: public void activatePluginInDynamicComponent(Integer uiCompCst) {
0232: if (ACTION_REQ) {
0233: if (uiCompCst.equals(UICompCst.ACTION_NEW_TAB)) {
0234:
0235: //System.out.println("ReqPlugin");
0236:
0237: JTabbedPane actionTabs = (JTabbedPane) SalomeTMFContext
0238: .getInstance().getUIComponent(uiCompCst);
0239: //System.out.println("ReqPlugin 2");
0240:
0241: actionTabs.addTab("Plug-in "
0242: + Language.getInstance().getText("Exigences"),
0243: pRequirementActionPanel);
0244: //System.out.println("ReqPlugin 3");
0245: // tabIndexAct = actionTabs.indexOfComponent(pRequirementActionPanel);
0246:
0247: pRequirementActionPanel.setParent(actionTabs);
0248: //System.out.println("ReqPlugin passed");
0249:
0250: }
0251: }
0252: }
0253:
0254: public void activatePluginInStaticComponent(Integer uiCompCst) {
0255: if (uiCompCst.equals(UICompCst.MAIN_TABBED_PANE)) {
0256: salomeMainTabs = (JTabbedPane) SalomeTMFContext
0257: .getInstance().getUIComponent(uiCompCst);
0258: salomeMainTabs.addTab("Plug-in "
0259: + Language.getInstance().getText("Exigences"),
0260: pRequirementPanel);
0261: tabIndex = salomeMainTabs
0262: .indexOfComponent(pRequirementPanel);
0263: /*salomeMainTabs.addChangeListener(new ChangeListener() {
0264: public void stateChanged(ChangeEvent e) {
0265: if (salomeMainTabs.getSelectedComponent().equals(pRequirementPanel)){
0266: pRequirementPanel.focusChange();
0267: }
0268: }
0269: });*/
0270: } else if (uiCompCst
0271: .equals(UICompCst.MANUAL_TEST_WORKSPACE_PANEL_FOR_TABS)) {
0272: JTabbedPane manTestTabs = (JTabbedPane) SalomeTMFContext
0273: .getInstance().getUIComponent(uiCompCst);
0274: manTestTabs.addTab("Plug-in "
0275: + Language.getInstance().getText("Exigences"),
0276: pRequirementMTestPanel);
0277: pRequirementMTestPanel.setParent(manTestTabs);
0278: /*manTestTabs.addChangeListener(new ChangeListener() {
0279: public void stateChanged(ChangeEvent e) {
0280: if (((JTabbedPane)e.getSource()).getSelectedComponent().equals(pRequirementMTestPanel)){
0281: System.out.println("Update Requiment Manual test");
0282: pRequirementMTestPanel.InitData(DataModel.getCurrentTest());
0283: }
0284: }
0285: });*/
0286: } else if (uiCompCst
0287: .equals(UICompCst.AUTOMATED_TEST_WORKSPACE_PANEL_FOR_TABS)) {
0288: JTabbedPane autTestTabs = (JTabbedPane) SalomeTMFContext
0289: .getInstance().getUIComponent(uiCompCst);
0290: autTestTabs.addTab("Plug-in "
0291: + Language.getInstance().getText("Exigences"),
0292: pRequirementATestPanel);
0293: pRequirementATestPanel.setParent(autTestTabs);
0294: /*autTestTabs.addChangeListener(new ChangeListener() {
0295: public void stateChanged(ChangeEvent e) {
0296: if (((JTabbedPane)e.getSource()).getSelectedComponent().equals(pRequirementATestPanel)){
0297: System.out.println("Update Requiment Automatic test");
0298: pRequirementATestPanel.InitData(DataModel.getCurrentTest());
0299: }
0300: }
0301: });*/
0302: } else if (uiCompCst
0303: .equals(UICompCst.CAMPAIGN_WORKSPACE_PANEL_FOR_TABS)) {
0304: JTabbedPane campTabs = (JTabbedPane) SalomeTMFContext
0305: .getInstance().getUIComponent(uiCompCst);
0306: campTabs.addTab("Plug-in "
0307: + Language.getInstance().getText("Exigences"),
0308: pRequirementCampPanel);
0309: pRequirementCampPanel.setParent(campTabs);
0310: } else if (uiCompCst.equals(UICompCst.TEST_DYNAMIC_TREE)) {
0311: DynamicTree pDynamicTree = (DynamicTree) SalomeTMFContext
0312: .getInstance().getUIComponent(uiCompCst);
0313: pRequirementATestPanel.setTestTree(pDynamicTree);
0314: pRequirementMTestPanel.setTestTree(pDynamicTree);
0315: pRequirementPanel.setTestTree(pDynamicTree);
0316: } else if (uiCompCst.equals(UICompCst.CAMPAIGN_DYNAMIC_TREE)) {
0317: campaignDynamicTree = (DynamicTree) SalomeTMFContext
0318: .getInstance().getUIComponent(uiCompCst);
0319: pRequirementCampPanel.setCampTree(campaignDynamicTree);
0320:
0321: } else if (uiCompCst
0322: .equals(UICompCst.CAMP_EXECUTION_RESULTS_BUTTONS_PANEL)) {
0323: JPanel panButton = (JPanel) SalomeTMFContext.getInstance()
0324: .getUIComponent(uiCompCst);
0325: panButton.add(statResExecButton);
0326: } else if (uiCompCst
0327: .equals(UICompCst.CAMP_EXECUTION_RESULTS_TABLE)) {
0328: JTable pTableResExec = (JTable) SalomeTMFContext
0329: .getInstance().getUIComponent(uiCompCst);
0330: ListSelectionModel rowSM = pTableResExec
0331: .getSelectionModel();
0332: rowSM.addListSelectionListener(this );
0333: }
0334: }
0335:
0336: public void activatePluginInTestToolsMenu(javax.swing.JMenu jMenu) {
0337:
0338: }
0339:
0340: public void freeze() {
0341: }
0342:
0343: public java.util.Vector getUsedUIComponents() {
0344: Vector uiComponentsUsed = new Vector();
0345: uiComponentsUsed.add(UICompCst.MAIN_TABBED_PANE);
0346: uiComponentsUsed
0347: .add(UICompCst.AUTOMATED_TEST_WORKSPACE_PANEL_FOR_TABS);
0348: uiComponentsUsed
0349: .add(UICompCst.MANUAL_TEST_WORKSPACE_PANEL_FOR_TABS);
0350: uiComponentsUsed
0351: .add(UICompCst.CAMPAIGN_WORKSPACE_PANEL_FOR_TABS);
0352: uiComponentsUsed.add(UICompCst.TEST_DYNAMIC_TREE);
0353: uiComponentsUsed.add(UICompCst.CAMPAIGN_DYNAMIC_TREE);
0354: uiComponentsUsed
0355: .add(UICompCst.CAMP_EXECUTION_RESULTS_BUTTONS_PANEL);
0356: uiComponentsUsed.add(UICompCst.CAMP_EXECUTION_RESULTS_TABLE);
0357: if (ACTION_REQ) {
0358: uiComponentsUsed.add(UICompCst.ACTION_NEW_TAB);
0359: }
0360: return uiComponentsUsed;
0361: }
0362:
0363: public void init(Object pIhm) {
0364: // ptrSalome = ((JApplet) pIhm);
0365:
0366: try {
0367: SQLWrapper.init(Api.getISQLObjectFactory());
0368: pRequirementPanel = new RequirementPanel(pStatRequirement,
0369: this );
0370:
0371: pRequirementCampPanel = new RequirementCampPanel(
0372: pRequirementPanel.getTree());
0373: pRequirementATestPanel = new RequirementTestPanel(1,
0374: pRequirementPanel.getTree(), pRequirementCampPanel);
0375: pRequirementMTestPanel = new RequirementTestPanel(0,
0376: pRequirementPanel.getTree(), pRequirementCampPanel);
0377:
0378: if (ACTION_REQ) {
0379: // Faute sur le parent mais on s'en fout!
0380: pRequirementActionPanel = new RequirementActionPanel(0,
0381: pRequirementPanel.getTree(),
0382: pRequirementCampPanel);
0383: }
0384: statResExecButton = new JButton(Language.getInstance()
0385: .getText("Statistique")
0386: + " " + Language.getInstance().getText("Exigences"));
0387: statResExecButton.addActionListener(this );
0388: statResExecButton.setEnabled(false);
0389: // pResultPanel = new ResultPanel();
0390: DataModel.getCurrentProject().registerObserver(this );
0391: } catch (Exception e) {
0392: e.printStackTrace();
0393: }
0394: }
0395:
0396: public boolean isActivableInCampToolsMenu() {
0397: return true;
0398: }
0399:
0400: public boolean isActivableInDataToolsMenu() {
0401: return false;
0402: }
0403:
0404: public boolean isActivableInTestToolsMenu() {
0405: return false;
0406: }
0407:
0408: public boolean isFreezable() {
0409: return false;
0410: }
0411:
0412: public boolean isFreezed() {
0413: return false;
0414: }
0415:
0416: public void unFreeze() {
0417: }
0418:
0419: public boolean usesOtherUIComponents() {
0420: return true;
0421: }
0422:
0423: public void allPluginActived(ExtensionPoint commonExtensions,
0424: ExtensionPoint testDriverExtensions,
0425: ExtensionPoint scriptEngineExtensions,
0426: ExtensionPoint bugTrackerExtensions) {
0427: }
0428:
0429: /************************************************************************************************/
0430:
0431: static public Project getProjectRef() {
0432: return project_ref;
0433: }
0434:
0435: /**
0436: *
0437: * @return true if projectref is defined in pulgin.xml and the currentProjet is the projectRef
0438: */
0439: static public boolean isGlobalProject() {
0440: return isGlobalProject;
0441: }
0442:
0443: public void update(Observable o, Object arg) {
0444: //System.out.println("[ReqPlugin->update] : " +arg);
0445: try {
0446: if (arg instanceof SalomeEvent) {
0447: SalomeEvent pSalomeEvent = (SalomeEvent) arg;
0448: int code = pSalomeEvent.getCode();
0449: if (code == ApiConstants.DELETE_TEST) {
0450: Test pTest = (Test) pSalomeEvent.getArg();
0451: Requirement.deleteAllCoverForTest(pTest.getIdBdd());
0452: } else if (code == ApiConstants.LOADING) {
0453: //reloadReq
0454: //System.out.println("------------------------Reload Req");
0455: pRequirementPanel.reloadReqPerformed();
0456: }
0457: }
0458:
0459: } catch (Exception e) {
0460: }
0461: }
0462:
0463: /*********************************************************************************************/
0464:
0465: public void actionPerformed(ActionEvent e) {
0466: if (e.getSource().equals(statResExecButton)) {
0467: statResExecPerformed(e);
0468: }
0469: }
0470:
0471: void statResExecPerformed(ActionEvent e) {
0472: if (DataModel.getObservedExecutionResult() != null) {
0473: //ExecResultStatDialog pResultPanel = new ExecResultStatDialog(DataModel.getObservedExecutionResult(), pRequirementPanel.getTree());
0474: new ExecResultStatDialog(DataModel
0475: .getObservedExecutionResult(), pRequirementPanel
0476: .getTree());
0477: //pResultPanel.show(DataModel.getObservedExecutionResult());
0478: }
0479: }
0480:
0481: /*********************************************************************************************/
0482:
0483: public void valueChanged(ListSelectionEvent e) {
0484: //Ignore extra messages.
0485: if (e.getValueIsAdjusting()) {
0486: return;
0487: }
0488:
0489: ListSelectionModel lsm = (ListSelectionModel) e.getSource();
0490: if (lsm.isSelectionEmpty()) {
0491: //no rows are selected
0492: statResExecButton.setEnabled(false);
0493: } else {
0494: statResExecButton.setEnabled(true);
0495: }
0496: }
0497:
0498: /*********************************************************************************************/
0499:
0500: static public void selectTestTab() {
0501: salomeMainTabs.setSelectedIndex(0);
0502: }
0503:
0504: static public void selectCampTab() {
0505: salomeMainTabs.setSelectedIndex(1);
0506: }
0507:
0508: static public void selectReqTab() {
0509: salomeMainTabs.setSelectedIndex(tabIndex);
0510: }
0511:
0512: public JTree getTreeRequirement() {
0513: if (pRequirementPanel != null) {
0514: pRequirementPanel.getTree().reload();
0515: return pRequirementPanel.getTree().getCopy(false);
0516: }
0517: return null;
0518: }
0519:
0520: public void reloadReq() {
0521: pRequirementPanel.getTree().reload();
0522: }
0523:
0524: private JMenu createJMenu() {
0525: JMenu reqSubMenu;
0526: reqSubMenu = new JMenu("Plug-in "
0527: + Language.getInstance().getText("Exigences"));
0528:
0529: JMenuItem importItem = new JMenuItem(Language.getInstance()
0530: .getText("Importer")
0531: + " " + Language.getInstance().getText("Exigences"));
0532: importItem.addActionListener(new ActionListener() {
0533: public void actionPerformed(ActionEvent e) {
0534: SalomeTMFPanels.setCursor(DataConstants.CAMPAIGN,
0535: Cursor.WAIT_CURSOR);
0536: importReqInCampPerformed();
0537: SalomeTMFPanels.setCursor(DataConstants.CAMPAIGN,
0538: Cursor.DEFAULT_CURSOR);
0539: }
0540: });
0541:
0542: reqSubMenu.add(importItem);
0543: return reqSubMenu;
0544: }
0545:
0546: void importReqInCampPerformed() {
0547: Campaign pCamp = DataModel.getCurrentCampaign();
0548:
0549: if (pCamp == null) {
0550: return;
0551: }
0552:
0553: if (pCamp.containsExecutionResultInModel()) {
0554: JOptionPane
0555: .showMessageDialog(
0556: SalomeTMFContext.getInstance()
0557: .getSalomeFrame(),
0558: org.objectweb.salome_tmf.ihm.languages.Language
0559: .getInstance()
0560: .getText(
0561: "Cette_campagne_contient_déjà_des_résultat_d'exécution.\nIl_n'est_plus_possible_de_la_modifier."),
0562: org.objectweb.salome_tmf.ihm.languages.Language
0563: .getInstance().getText("Erreur_!"),
0564: JOptionPane.ERROR_MESSAGE);
0565: } else {
0566: try {
0567: Vector reqCovered = InitData(pCamp);
0568: JTree pTree = pRequirementPanel.getTree().getCopy(true);
0569: DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((DefaultTreeModel) pTree
0570: .getModel()).getRoot();
0571: Hashtable<Integer, Requirement> removedReq = new Hashtable<Integer, Requirement>();
0572: removeReqWithNoTestLink((DefaultTreeModel) pTree
0573: .getModel(), node, removedReq);
0574: if (((DefaultMutableTreeNode) ((DefaultTreeModel) pTree
0575: .getModel()).getRoot()).getChildCount() == 0) {
0576: JOptionPane
0577: .showMessageDialog(
0578: SalomeTMFContext.getInstance()
0579: .getSalomeFrame(),
0580: org.objectweb.salome_tmf.ihm.languages.Language
0581: .getInstance()
0582: .getText(
0583: "Aucune_exigence_couverte"),
0584: org.objectweb.salome_tmf.ihm.languages.Language
0585: .getInstance().getText(
0586: "Attention_!"),
0587: JOptionPane.WARNING_MESSAGE);
0588: return;
0589: }
0590: SelectRequirement pSelectRequirement = new SelectRequirement(
0591: pTree, Language.getInstance().getText(
0592: "Selection"), reqCovered, false,
0593: removedReq);
0594: Hashtable selected = pSelectRequirement.getSelection();
0595: if (selected != null) {
0596: reqCovered.clear();
0597: Enumeration enumSelected = selected.elements();
0598: while (enumSelected.hasMoreElements()) {
0599: reqCovered.add(enumSelected.nextElement());
0600: }
0601: fillCamp(pCamp, reqCovered);
0602: }
0603: } catch (Exception e) {
0604: Tools.ihmExceptionView(e);
0605:
0606: }
0607: }
0608: }
0609:
0610: boolean removeReqWithNoTestLink(DefaultTreeModel treeModel,
0611: DefaultMutableTreeNode pTempNode,
0612: Hashtable<Integer, Requirement> removedReq) {
0613: Requirement pTempReq = (Requirement) pTempNode.getUserObject();
0614: if (pTempReq instanceof ReqLeaf) {
0615: try {
0616: Vector testLinked = pTempReq
0617: .getTestWrapperCoveredFromDB();
0618: if (testLinked.size() == 0) {
0619: treeModel.removeNodeFromParent(pTempNode);
0620: removedReq.put(pTempReq.getIdBdd(), pTempReq);
0621: return true;
0622: }
0623: } catch (Exception e) {
0624:
0625: }
0626: return false;
0627: } else {
0628: int nbChild = pTempNode.getChildCount();
0629:
0630: for (int i = 0; i < nbChild; i++) {
0631: if (removeReqWithNoTestLink(treeModel,
0632: (DefaultMutableTreeNode) pTempNode
0633: .getChildAt(i), removedReq)) {
0634: i--;
0635: nbChild--;
0636: }
0637: }
0638: if (pTempNode.getChildCount() == 0
0639: && !pTempNode.equals(treeModel.getRoot())) {
0640: treeModel.removeNodeFromParent(pTempNode);
0641: removedReq.put(pTempReq.getIdBdd(), pTempReq);
0642: return true;
0643: }
0644: }
0645: return false;
0646: }
0647:
0648: void fillCamp(Campaign pCamp, Vector reqCovered) {
0649: try {
0650: if (!pCamp.isValideModel()) {
0651: SalomeTMFContext.getInstance().showMessage(
0652: Language.getInstance().getText("Update_data"),
0653: Language.getInstance().getText("Erreur_!"),
0654: JOptionPane.ERROR_MESSAGE);
0655: return;
0656: }
0657: } catch (Exception e) {
0658: Tools.ihmExceptionView(e);
0659: SalomeTMFContext.getInstance().showMessage(
0660: Language.getInstance().getText("Update_data"),
0661: Language.getInstance().getText("Erreur_!"),
0662: JOptionPane.ERROR_MESSAGE);
0663: return;
0664: }
0665:
0666: Hashtable selectedTests = new Hashtable();
0667:
0668: int reqCoveredSize = reqCovered.size();
0669: for (int i = 0; i < reqCoveredSize; i++) {
0670: Requirement pRequirement = (Requirement) reqCovered
0671: .elementAt(i);
0672:
0673: try {
0674: Vector testCover = pRequirement
0675: .getTestWrapperCoveredFromDB();
0676: int testCoverSize = testCover.size();
0677:
0678: for (int j = 0; j < testCoverSize; j++) {
0679: TestWrapper pTestWrapper = (TestWrapper) testCover
0680: .elementAt(j);
0681: Test pTest = DataModel.getCurrentProject()
0682: .getTestFromModel(pTestWrapper.getIdBDD());
0683: if (pTest == null && !isGlobalProject()) {
0684: if (getProjectRef().getIdBdd() == DataModel
0685: .getCurrentProject().getIdBdd()) {
0686: DataModel.reloadFromBase(true);
0687: pTest = DataModel.getCurrentProject()
0688: .getTestFromModel(
0689: pTestWrapper.getIdBDD());
0690: }
0691: if (pTest != null) {
0692: selectedTests.put(new Integer(pTest
0693: .getIdBdd()), pTest);
0694: }
0695: } else {
0696: selectedTests.put(
0697: new Integer(pTest.getIdBdd()), pTest);
0698: }
0699: }
0700:
0701: } catch (Exception e) {
0702: //Hum ??
0703: }
0704: }
0705: reInitCamp(pCamp, selectedTests);
0706: }
0707:
0708: void reInitCamp(Campaign pCamp, Hashtable selectedTests) {
0709: ArrayList oldTestList = new ArrayList();
0710: ArrayList datasetsCreated;
0711: Hashtable oldAssignedUser = new Hashtable();
0712: boolean newDataSetCreated = false;
0713:
0714: ArrayList dataSets = pCamp.getDataSetListFromModel();
0715:
0716: for (int k = 0; k < pCamp.getTestListFromModel().size(); k++) {
0717: Test pTest = (Test) pCamp.getTestListFromModel().get(k);
0718: int idUserAssigned = pCamp.getAssignedUserID(pTest);
0719: if (idUserAssigned == -1) {
0720: idUserAssigned = pCamp.getIdBdd();
0721: }
0722: oldAssignedUser.put(new Integer(pTest.getIdBdd()),
0723: new Integer(idUserAssigned));
0724: oldTestList.add(pTest);
0725:
0726: }
0727: Hashtable testBySuite = new Hashtable();
0728: Enumeration enumSelected = selectedTests.elements();
0729:
0730: /* On classe les tests par suite*/
0731: while (enumSelected.hasMoreElements()) {
0732: Test pTest = (Test) enumSelected.nextElement();
0733: TestList pTestList = pTest.getTestListFromModel();
0734: Vector listTest = (Vector) testBySuite.get(pTestList);
0735: if (listTest != null) {
0736: listTest.add(0, pTest);
0737: } else {
0738: listTest = new Vector();
0739: listTest.add(0, pTest);
0740: testBySuite.put(pTestList, listTest);
0741: }
0742: }
0743:
0744: int transNumber = -1;
0745: try {
0746: // BDD & MODEL
0747:
0748: transNumber = Api.beginTransaction(110,
0749: ApiConstants.INSERT_TEST_INTO_CAMPAIGN);
0750: /* 1 On vide la campagne */
0751: for (int i = 0; i < oldTestList.size(); i++) {
0752: // pCamp.deleteTestFromCampInDB(((Test)oldTestList.get(i)).getIdBdd(), false);
0753: pCamp.deleteTestFromCampInDBAndModel((Test) oldTestList
0754: .get(i), false);
0755: }
0756: pCamp.clearAssignedUserForTest();
0757:
0758: /*2 On Import les Tests */
0759: Enumeration enumSuiteSelected = testBySuite.elements();
0760: while (enumSuiteSelected.hasMoreElements()) {
0761: Vector testlist = (Vector) enumSuiteSelected
0762: .nextElement();
0763: int testlistSize = testlist.size();
0764: for (int i = 0; i < testlistSize; i++) {
0765: Test pTest = (Test) testlist.elementAt(i);
0766: int id = DataModel.getCurrentUser().getIdBdd();
0767: Integer userID = (Integer) oldAssignedUser
0768: .get(new Integer(pTest.getIdBdd()));
0769: if (userID != null) {
0770: id = userID.intValue();
0771: }
0772: datasetsCreated = DataModel.getCurrentProject()
0773: .addTestInCampaignInDBAndModel(pTest,
0774: pCamp, id);
0775: if (datasetsCreated.size() > 0) {
0776: newDataSetCreated = true;
0777: for (int k = 0; k < pCamp
0778: .getExecutionListFromModel().size(); k++) {
0779: DataModel
0780: .getExecutionTableModel()
0781: .setValueAt(
0782: ((DataSet) datasetsCreated
0783: .get(k))
0784: .getNameFromModel(),
0785: k, 3);
0786: }
0787: }
0788: }
0789: }
0790:
0791: if (newDataSetCreated) {
0792: for (int i = 0; i < dataSets.size(); i++) {
0793: DataSet newDataSet = (DataSet) dataSets.get(i);
0794: ArrayList dataView = new ArrayList();
0795: dataView.add(newDataSet.getNameFromModel());
0796: dataView.add(newDataSet.getDescriptionFromModel());
0797: DataModel.getDataSetTableModel().addRow(dataView);
0798: }
0799: }
0800: //DataModel.reloadFromBase(true);
0801: DataModel.reloadCampaign(pCamp);
0802: Api.commitTrans(transNumber);
0803: } catch (Exception exception) {
0804: Api.forceRollBackTrans(transNumber);
0805: pCamp.setTestListInModel(oldTestList);
0806: Tools.ihmExceptionView(exception);
0807: }
0808: }
0809:
0810: Vector InitData(Campaign pCamp) throws Exception {
0811: Vector reqCovered = new Vector();
0812: Vector reqCoveredWrapper;
0813: reqCovered.clear();
0814: try {
0815: ArrayList pTestList = pCamp.getTestListFromModel();
0816: int nbTest = pTestList.size();
0817: for (int i = 0; i < nbTest; i++) {
0818: Test pTest = (Test) pTestList.get(i);
0819: reqCoveredWrapper = Requirement
0820: .getReqWrapperCoveredByTest(pTest.getIdBdd());
0821: int size = reqCoveredWrapper.size();
0822: for (int j = 0; j < size; j++) {
0823: ReqWrapper pReqWrapper = (ReqWrapper) reqCoveredWrapper
0824: .elementAt(j);
0825: DefaultMutableTreeNode node = pRequirementPanel
0826: .getTree().findRequirementFromParent(
0827: pReqWrapper);
0828: Requirement pReq = null;
0829: if (node != null) {
0830: pReq = (Requirement) node.getUserObject();
0831: if (!reqCovered.contains(pReq)) {
0832: reqCovered.add(pReq);
0833: }
0834: } else {
0835: pRequirementPanel.getTree().reload();
0836: node = pRequirementPanel.getTree()
0837: .findRequirementFromParent(pReqWrapper);
0838: if (node != null) {
0839: pReq = (Requirement) node.getUserObject();
0840: if (!reqCovered.contains(pReq)) {
0841: reqCovered.add(pReq);
0842: }
0843: } else {
0844: //Hum Data corruption !!!
0845: Tools
0846: .ihmExceptionView(new Exception(
0847: "Hum ??, it seem that data integrity are corrupted"));
0848:
0849: }
0850: }
0851: }
0852: }
0853:
0854: } catch (Exception e) {
0855: throw e;
0856: }
0857: return reqCovered;
0858: }
0859:
0860: //////////////////////////////// Admin interface ////////////////////////////////////
0861:
0862: /* (non-Javadoc)
0863: * @see org.objectweb.salome_tmf.plugins.core.Admin#activateInSalomeAdmin(java.util.Map)
0864: */
0865: public void activateInSalomeAdmin(Map adminUIComps,
0866: IPlugObject iPlugObject) {
0867:
0868: }
0869:
0870: public void onDeleteProject(Project p) {
0871: try {
0872: if (pSQLRequirement == null) {
0873: SQLWrapper.init(Api.getISQLObjectFactory());
0874: pSQLRequirement = SQLWrapper.getSQLRequirement();
0875: }
0876: pSQLRequirement.deleteProjectReq(p.getIdBdd());
0877: } catch (Exception e) {
0878: e.printStackTrace();
0879: }
0880: }
0881:
0882: boolean deleteConfirme(String quoi) {
0883: Object[] options = {
0884: org.objectweb.salome_tmf.ihm.languages.Language
0885: .getInstance().getText("Oui"),
0886: org.objectweb.salome_tmf.ihm.languages.Language
0887: .getInstance().getText("Non") };
0888: int choice = -1;
0889:
0890: choice = SalomeTMFContext.getInstance().askQuestion(
0891: org.objectweb.salome_tmf.ihm.languages.Language
0892: .getInstance().getText(
0893: "confimation_suppression2")
0894: + " " + quoi + " ?",
0895: org.objectweb.salome_tmf.ihm.languages.Language
0896: .getInstance().getText("Attention_!"),
0897: JOptionPane.WARNING_MESSAGE, options);
0898:
0899: if (choice == JOptionPane.YES_OPTION) {
0900: return true;
0901: } else {
0902: return false;
0903: }
0904: }
0905:
0906: /********************* DoxXML Implementation **********************/
0907:
0908: void writeRequirement(Element reqsElem,
0909: DefaultMutableTreeNode pTempNode, boolean first,
0910: String attachPath, XMLWriterPlugin pXMLWriter)
0911: throws Exception {
0912: if (!doExport()) {
0913: return;
0914: }
0915: Requirement pTempReq = (Requirement) pTempNode.getUserObject();
0916: HashMap attachs = null;
0917: try {
0918: if (!first) {
0919: attachs = pTempReq.getAttachmentMapFromModel();
0920: }
0921: } catch (Exception e) {
0922:
0923: }
0924: if (pTempReq instanceof ReqLeaf) {
0925: //Write leaf
0926: Element reqLeafElem = reqsElem.addElement("Requirement");
0927: reqLeafElem.addElement("Nom").setText(
0928: pTempReq.getNameFromModel());
0929: reqLeafElem.addAttribute("priority", ""
0930: + ((ReqLeaf) pTempReq).getPriorityFromModel());
0931: reqLeafElem.addAttribute("category", ""
0932: + ((ReqLeaf) pTempReq).getCatFromModel());
0933: reqLeafElem.addAttribute("complexity", ""
0934: + ((ReqLeaf) pTempReq).getComplexeFromModel());
0935: reqLeafElem.addAttribute("state", ""
0936: + ((ReqLeaf) pTempReq).getStateFromModel());
0937: reqLeafElem.addAttribute("origine", ((ReqLeaf) pTempReq)
0938: .getOrigineFromModel());
0939: reqLeafElem.addAttribute("verifway", ((ReqLeaf) pTempReq)
0940: .getVerifFromModel());
0941:
0942: reqLeafElem.addAttribute("version", ((ReqLeaf) pTempReq)
0943: .getVersionFromModel());
0944: reqLeafElem.addAttribute("reference", ((ReqLeaf) pTempReq)
0945: .getReferenceFromModel());
0946:
0947: reqLeafElem.addAttribute("id_req", "Req_"
0948: + new Integer(pTempReq.getIdBdd()).toString());
0949: reqLeafElem.addAttribute("id_req_parent", "Req_"
0950: + new Integer(pTempReq.getParent().getIdBdd())
0951: .toString());
0952: if (pTempReq.getDescriptionFromModel() != null
0953: && !pTempReq.getDescriptionFromModel().equals("")) {
0954: addHTMLDescription(reqLeafElem, pTempReq
0955: .getDescriptionFromModel());
0956: }
0957: if (attachs != null) {
0958: pXMLWriter.addAttach(reqLeafElem, attachPath
0959: + File.separator + "Attachements"
0960: + File.separator + "Requirements"
0961: + File.separator + pTempReq.getIdBdd(),
0962: attachs, "Attachements" + File.separator
0963: + "Requirements" + File.separator
0964: + pTempReq.getIdBdd());
0965: }
0966: } else {
0967: //Write family
0968: Element reqFamilyElem = reqsElem;
0969: if (!first) {
0970: reqFamilyElem = reqsElem
0971: .addElement("RequirementFamily");
0972:
0973: reqFamilyElem.addElement("Nom").setText(
0974: pTempReq.getNameFromModel());
0975: reqFamilyElem.addAttribute("id_req", "Req_"
0976: + new Integer(pTempReq.getIdBdd()).toString());
0977: reqFamilyElem.addAttribute("id_req_parent", "Req_"
0978: + new Integer(pTempReq.getParent().getIdBdd())
0979: .toString());
0980: if (pTempReq.getDescriptionFromModel() != null
0981: && !pTempReq.getDescriptionFromModel().equals(
0982: "")) {
0983: addHTMLDescription(reqFamilyElem, pTempReq
0984: .getDescriptionFromModel());
0985: }
0986: if (attachs != null) {
0987: pXMLWriter.addAttach(reqFamilyElem, attachPath
0988: + File.separator + "Attachements"
0989: + File.separator + "Requirements"
0990: + File.separator + pTempReq.getIdBdd(),
0991: attachs, "Attachements" + File.separator
0992: + "Requirements" + File.separator
0993: + pTempReq.getIdBdd());
0994: }
0995: } else {
0996: first = false;
0997: }
0998: int nbChild = pTempNode.getChildCount();
0999:
1000: for (int i = 0; i < nbChild; i++) {
1001: writeRequirement(reqFamilyElem,
1002: (DefaultMutableTreeNode) pTempNode
1003: .getChildAt(i), first, attachPath,
1004: pXMLWriter);
1005: }
1006:
1007: }
1008: }
1009:
1010: public void addXMLElement2Root(Element rootElement,
1011: XMLWriterPlugin pXMLWriter, String pathAttach) {
1012:
1013: }
1014:
1015: private void addHTMLDescription(Element parentElem,
1016: String description) throws Exception {
1017: String desc = description.replaceAll("<br>", "<br />");
1018: try {
1019: Document document = DocumentHelper.parseText(desc);
1020: Element bodyElem = (Element) document
1021: .selectSingleNode("//body");
1022: Element descElem = bodyElem.createCopy("Description");
1023: descElem.addAttribute("isHTML", "true");
1024: parentElem.add(descElem);
1025: } catch (Exception e) {
1026: parentElem.addElement("Description").setText(
1027: desc.replaceAll("\n", "\\\\n"));
1028: }
1029: }
1030:
1031: /* Test Plan */
1032: public void addXMLElement2Project(Element projectElement,
1033: Project pProject, XMLWriterPlugin pXMLWriter,
1034: String pathAttach) {
1035: if (!doExport()) {
1036: return;
1037: }
1038: try {
1039: //pReqPlugin = (ReqPlugin) pIPlugObject.getPluginManager().activateExtension(ext);
1040: JTree pTree = getTreeRequirement();
1041: DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((DefaultTreeModel) pTree
1042: .getModel()).getRoot();
1043: if (node.getChildCount() > 0) {
1044: Element reqsElem = projectElement
1045: .addElement("Requirements");
1046: Requirement pTempReq = (Requirement) node
1047: .getUserObject();
1048: reqsElem.addAttribute("id_req", "Req_"
1049: + new Integer(pTempReq.getIdBdd()).toString());
1050: writeRequirement(reqsElem, node, true, pathAttach,
1051: pXMLWriter);
1052: }
1053: /*
1054: pContexte.setHasCampRequirementsGraph(true);
1055: pContexte.setHasResExecRequirementsGraph(true);
1056: pContexte.setHasRequirementsGraph(true);
1057: */
1058: try {
1059: File dir = new File(pathAttach + File.separator
1060: + "Attachements" + File.separator
1061: + "Requirements");
1062: if (!dir.exists()) {
1063: dir.mkdirs();
1064: }
1065: Requirement.writeReqCoverChart(pathAttach
1066: + File.separator + "Attachements"
1067: + File.separator + "Requirements"
1068: + File.separator + "requirements.jpeg");
1069: } catch (Exception e) {
1070: //pContexte.setHasRequirementsGraph(false);
1071: }
1072: } catch (Exception e) {
1073:
1074: }
1075: }
1076:
1077: public void addXMLElement2Family(Element familyElement,
1078: Family pFamily, XMLWriterPlugin pXMLWriter,
1079: String pathAttach) {
1080:
1081: }
1082:
1083: public void addXMLElement2Suite(Element suiteElement,
1084: TestList ptestList, XMLWriterPlugin pXMLWriter,
1085: String pathAttach) {
1086:
1087: }
1088:
1089: public void addXMLElement2Test(Element testElement, Test pTest,
1090: XMLWriterPlugin pXMLWriter, String pathAttach) {
1091: if (!doExport()) {
1092: return;
1093: }
1094: Vector reqCoveredWrapper;
1095: try {
1096: reqCoveredWrapper = Requirement
1097: .getReqWrapperCoveredByTest(pTest.getIdBdd());
1098: int size = reqCoveredWrapper.size();
1099: if (size > 0) {
1100: Element reqLinkElem = testElement
1101: .addElement("LinkRequirement");
1102: for (int i = 0; i < size; i++) {
1103: ReqWrapper pReqWrapper = (ReqWrapper) reqCoveredWrapper
1104: .elementAt(i);
1105: Element reqRef = reqLinkElem
1106: .addElement("RequirementRef");
1107: reqRef.addAttribute("ref", "Req_"
1108: + new Integer(pReqWrapper.getIdBDD())
1109: .toString());
1110: reqRef.addElement("Nom").setText(
1111: pReqWrapper.getName());
1112: String description = pReqWrapper.getDescription();
1113: if (description != null && !description.equals("")) {
1114: addHTMLDescription(reqRef, pReqWrapper
1115: .getDescription());
1116: //reqRef.addElement("Description").setText(pReqWrapper.getDescription());
1117: }
1118: }
1119: }
1120: } catch (Exception e) {
1121: }
1122: }
1123:
1124: //void addXMLElement2ValuedParameter(Element paramElement, Test pTest, Parameter pParam);
1125: public void addXMLElement2Action(Element testElement,
1126: Action pAction, XMLWriterPlugin pXMLWriter,
1127: String pathAttach) {
1128: if (!doExport()) {
1129: return;
1130: }
1131: }
1132:
1133: /* Campaing plan */
1134: public void addXMLElement2Campaign(Element campaignElement,
1135: Campaign pCampaign, XMLWriterPlugin pXMLWriter,
1136: String pathAttach) {
1137: if (!doExport()) {
1138: return;
1139: }
1140: Vector reqCoveredWrapper = new Vector();
1141: try {
1142: ArrayList pTestList = pCampaign.getTestListFromModel();
1143: int nbTest = pTestList.size();
1144: for (int i = 0; i < nbTest; i++) {
1145: Test pTest = (Test) pTestList.get(i);
1146: Vector tempCoveredWrapper = Requirement
1147: .getReqWrapperCoveredByTest(pTest.getIdBdd());
1148: int size = tempCoveredWrapper.size();
1149: for (int j = 0; j < size; j++) {
1150: ReqWrapper pReqWrapper = (ReqWrapper) tempCoveredWrapper
1151: .elementAt(j);
1152: if (!reqCoveredWrapper.contains(pReqWrapper)) {
1153: reqCoveredWrapper.add(pReqWrapper);
1154: }
1155: }
1156: }
1157:
1158: try {
1159: File dir = new File(pathAttach
1160: + File.separator
1161: + "Attachements"
1162: + File.separator
1163: + "Campagnes"
1164: + File.separator
1165: + pXMLWriter.formater(pCampaign
1166: .getNameFromModel()));
1167: if (!dir.exists()) {
1168: dir.mkdirs();
1169: }
1170: Requirement.writeCampaingChart(reqCoveredWrapper,
1171: pathAttach
1172: + File.separator
1173: + "Attachements"
1174: + File.separator
1175: + "Campagnes"
1176: + File.separator
1177: + pXMLWriter.formater(pCampaign
1178: .getNameFromModel())
1179: + File.separator + "requirements.jpeg");
1180: } catch (Exception e) {
1181: //pContexte.setHasRequirementsGraph(false);
1182: }
1183:
1184: int size = reqCoveredWrapper.size();
1185: if (size > 0) {
1186: Element reqLinkElem = campaignElement
1187: .addElement("LinkRequirement");
1188: for (int i = 0; i < size; i++) {
1189: ReqWrapper pReqWrapper = (ReqWrapper) reqCoveredWrapper
1190: .elementAt(i);
1191: Element reqRef = reqLinkElem
1192: .addElement("RequirementRef");
1193: reqRef.addAttribute("ref", "Req_"
1194: + new Integer(pReqWrapper.getIdBDD())
1195: .toString());
1196: reqRef.addElement("Nom").setText(
1197: pReqWrapper.getName());
1198: String description = pReqWrapper.getDescription();
1199: if (description != null && !description.equals("")) {
1200: addHTMLDescription(reqRef, pReqWrapper
1201: .getDescription());
1202: //reqRef.addElement("Description").setText(pReqWrapper.getDescription());
1203: }
1204: }
1205: }
1206: } catch (Exception e) {
1207:
1208: }
1209: }
1210:
1211: public void addXMLElement2Execution(Element execElement,
1212: Execution pExecution, XMLWriterPlugin pXMLWriter,
1213: String pathAttach) {
1214:
1215: }
1216:
1217: public void addXMLElement2ResExecution(Element resExecElement,
1218: ExecutionResult pExecRes, XMLWriterPlugin pXMLWriter,
1219: String pathAttach) {
1220: if (!doExport()) {
1221: return;
1222: }
1223: try {
1224: Campaign pCamp = pExecRes.getExecution()
1225: .getCampagneFromModel();
1226: Execution pExec = pExecRes.getExecution();
1227: File dir = new File(pathAttach + File.separator
1228: + "Attachements" + File.separator + "Campagnes"
1229: + File.separator
1230: + pXMLWriter.formater(pCamp.getNameFromModel())
1231: + File.separator
1232: + pXMLWriter.formater(pExec.getNameFromModel())
1233: + File.separator
1234: + pXMLWriter.formater(pExecRes.getNameFromModel()));
1235: if (!dir.exists()) {
1236: dir.mkdirs();
1237: }
1238: Requirement.writeResExecChart(pExecRes, pathAttach
1239: + File.separator + "Attachements" + File.separator
1240: + "Campagnes" + File.separator
1241: + pXMLWriter.formater(pCamp.getNameFromModel())
1242: + File.separator
1243: + pXMLWriter.formater(pExec.getNameFromModel())
1244: + File.separator
1245: + pXMLWriter.formater(pExecRes.getNameFromModel())
1246: + File.separator + "requirements.jpeg");
1247: } catch (Exception e) {
1248: //Contexte.setHasRequirementsGraph(false);
1249: }
1250: }
1251:
1252: public void addXMLElement2ResTestExecution(Element resTestElem,
1253: ExecutionTestResult pExecTestRes, Test pTest,
1254: XMLWriterPlugin pXMLWriter, String pathAttach) {
1255:
1256: }
1257:
1258: public void addXMLElement2DataSet(Element dataSetElement,
1259: DataSet pDataSet, XMLWriterPlugin pXMLWriter,
1260: String pathAttach) {
1261:
1262: }
1263:
1264: /* Data */
1265: public void addXMLElement2Parameter(Element paramElement,
1266: Parameter pParam, XMLWriterPlugin pXMLWriter,
1267: String pathAttach) {
1268:
1269: }
1270:
1271: public void addXMLElement2Environment(Element envElement,
1272: Environment pEnv, XMLWriterPlugin pXMLWriter,
1273: String pathAttach) {
1274:
1275: }
1276:
1277: /***************** IMPORT ******************/
1278: public void manageDelete(Document doc, XMLLoaderPlugin pXMLLoader)
1279: throws Exception {
1280: if (!doImport()) {
1281: return;
1282: }
1283: pImportXMLReq = new ImportXMLReq(this , pXMLLoader);
1284: DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((DefaultTreeModel) getTreeRequirement()
1285: .getModel()).getRoot();
1286: pImportXMLReq.loadRequirementCacheFromModel(node, true);
1287: pImportXMLReq.loadRequirementCacheFromXML(doc);
1288: pImportXMLReq.gestionDesSuppressionsRequirements(doc);
1289: }
1290:
1291: public void updateProjectFromXML(Document doc, boolean isSupOption,
1292: Project project, XMLLoaderPlugin pXMLLoader)
1293: throws Exception {
1294: if (!doImport()) {
1295: return;
1296: }
1297: project_ref = project;
1298: //if (pImportXMLReq == null){
1299: pImportXMLReq = new ImportXMLReq(this , pXMLLoader);
1300: if (getTreeRequirement() != null) {
1301: DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((DefaultTreeModel) getTreeRequirement()
1302: .getModel()).getRoot();
1303: pImportXMLReq.loadRequirementCacheFromModel(node, true);
1304: }
1305: pImportXMLReq.loadRequirementCacheFromXML(doc);
1306: //}
1307: pImportXMLReq.updateProjectRequirement(doc);
1308: }
1309:
1310: public void updateProjectFromXML(String xmlFile) throws Exception {
1311: dirXml = xmlFile.substring(0, xmlFile.lastIndexOf(fs));
1312: SAXReader reader = new SAXReader(false);
1313: try {
1314: Document doc = reader.read(new FileInputStream(new File(
1315: xmlFile)));
1316:
1317: refreshNewData();
1318: //if (pImportXMLReq == null){
1319: pImportXMLReq = new ImportXMLReq(this , this );
1320: DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((DefaultTreeModel) getTreeRequirement()
1321: .getModel()).getRoot();
1322: pImportXMLReq.loadRequirementCacheFromModel(node, true);
1323: pImportXMLReq.loadRequirementCacheFromXML(doc);
1324: //}
1325: pImportXMLReq.updateProjectRequirement(doc);
1326: refreshNewData();
1327: SalomeTMFContext.getInstance().showMessage(
1328: Language.getInstance().getText(
1329: "L'import_s'est_terminée_avec_succès."),
1330: Language.getInstance().getText("Information_!"),
1331: JOptionPane.INFORMATION_MESSAGE);
1332: } catch (Exception e) {
1333: SalomeTMFContext.getInstance().showMessage(e.toString(),
1334: Language.getInstance().getText("Erreur_!"),
1335: JOptionPane.ERROR_MESSAGE);
1336: refreshNewData();
1337: }
1338:
1339: }
1340:
1341: public void updateFamilyFromXML(Element familyElement,
1342: Family pFamily, boolean isSupOption,
1343: XMLLoaderPlugin pXMLLoader) throws Exception {
1344:
1345: }
1346:
1347: public void updateSuiteFromXML(Element suiteElement,
1348: TestList pSuite, boolean isSupOption,
1349: XMLLoaderPlugin pXMLLoader) throws Exception {
1350:
1351: }
1352:
1353: public void updateTestFromXML(Element testElement, Test pTest,
1354: boolean isSupOption, XMLLoaderPlugin pXMLLoader)
1355: throws Exception {
1356: if (!doImport()) {
1357: return;
1358: }
1359: /*if (pImportXMLReq == null){
1360: pImportXMLReq = new ImportXMLReq(this, pXMLLoader);
1361: }*/
1362: pImportXMLReq.updateReqLink(testElement, pTest, isSupOption);
1363: }
1364:
1365: public void updateActionFromXML(Element actionElement,
1366: Action pAction, boolean isSupOption,
1367: XMLLoaderPlugin pXMLLoader) throws Exception {
1368:
1369: }
1370:
1371: /* Campaing plan */
1372: public void updateCampaignFromXML(Element campaignElement,
1373: Campaign pcampaign, boolean isSupOption,
1374: XMLLoaderPlugin pXMLLoader) throws Exception {
1375:
1376: }
1377:
1378: public void updateExecutionFromXML(Element execElement,
1379: Execution pExecution, boolean isSupOption,
1380: XMLLoaderPlugin pXMLLoader) throws Exception {
1381:
1382: }
1383:
1384: public void updateResExecutionFromXML(Element resExecElement,
1385: ExecutionResult pExecRes, boolean isSupOption,
1386: XMLLoaderPlugin pXMLLoader) throws Exception {
1387:
1388: }
1389:
1390: public void updateDataSetFromXML(Element dataSetElement,
1391: DataSet pDataSet, boolean isSupOption,
1392: XMLLoaderPlugin pXMLLoader) throws Exception {
1393:
1394: }
1395:
1396: /* Data */
1397: public void updateParameterFromXML(Element paramElement,
1398: Parameter pParam, boolean isSupOption,
1399: XMLLoaderPlugin pXMLLoader) throws Exception {
1400:
1401: }
1402:
1403: public void updateEnvironmentFromXML(Element envElement,
1404: Environment pEnv, boolean isSupOption,
1405: XMLLoaderPlugin pXMLLoader) throws Exception {
1406:
1407: }
1408:
1409: public void refreshNewData() {
1410: try {
1411: reloadReq();
1412: } catch (Exception e) {
1413: }
1414: }
1415:
1416: boolean doImport() {
1417: if (mandatoryImport)
1418: return true;
1419: if (importReqBox == null || !importReqBox.isSelected()) {
1420: return false;
1421: }
1422: return true;
1423: }
1424:
1425: boolean doExport() {
1426: if (mandatoryExport)
1427: return true;
1428: if (exportReqBox == null || !exportReqBox.isSelected()) {
1429: return false;
1430: }
1431: return true;
1432: }
1433:
1434: /******************* IHM *******************/
1435: JCheckBox importReqBox;
1436: JPanel importReqPanel;
1437:
1438: JCheckBox exportReqBox;
1439: JPanel exportReqPanel;
1440:
1441: public JPanel getExportOptionPanel() {
1442: exportReqBox = new JCheckBox(Language.getInstance().getText(
1443: "Exporter_les_exigences"));
1444: exportReqBox.setSelected(true);
1445: exportReqPanel = new JPanel();
1446: exportReqPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
1447: exportReqPanel.add(exportReqBox);
1448: exportReqPanel.setName(Language.getInstance().getText(
1449: "Exigences"));
1450: return exportReqPanel;
1451: }
1452:
1453: public JPanel getImportOptionPanel() {
1454: importReqBox = new JCheckBox(Language.getInstance().getText(
1455: "Importer_les_exigences"));
1456: importReqBox.setSelected(true);
1457: importReqPanel = new JPanel();
1458: importReqPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
1459: importReqPanel.add(importReqBox);
1460: importReqPanel.setName(Language.getInstance().getText(
1461: "Exigences"));
1462: return importReqPanel;
1463: }
1464:
1465: /**************** XSLT *******************/
1466: public File getXSLToImport(boolean dynamicMode, boolean multiFrame,
1467: boolean htmlFormat) {
1468: String _urlBase = SalomeTMFContext.getInstance().getUrlBase()
1469: .toString();
1470: String url_txt = _urlBase.substring(0, _urlBase
1471: .lastIndexOf("/"));
1472: String xsl = "";
1473: if (dynamicMode) {
1474: if (htmlFormat) {
1475: if (multiFrame) {
1476: xsl = "/plugins/requirements/xsl/frameDynaRequirements.xsl";
1477: } else {
1478: xsl = "/plugins/requirements/xsl/dynaRequirements.xsl";
1479: }
1480: } else
1481: xsl = "/plugins/requirements/xsl/dynaRequirementsDocBook.xsl";
1482:
1483: } else {//staticMode
1484: if (htmlFormat) {
1485: if (multiFrame) {
1486: xsl = "/plugins/requirements/xsl/frameRequirements.xsl";
1487: } else {
1488: xsl = "/plugins/requirements/xsl/requirements.xsl";
1489: }
1490: } else
1491: xsl = "/plugins/requirements/xsl/requirementsDocBook.xsl";
1492: }
1493: String temporaryFilePath = System.getProperties().getProperty(
1494: "java.io.tmpdir")
1495: + File.separator + "requirementsXSLT.xsl";
1496: try {
1497: URL xsltURL = new URL(url_txt + xsl);
1498: Tools.writeFile(xsltURL.openStream(), temporaryFilePath);
1499: } catch (Exception e) {
1500: Tools.writeFile(ReqPlugin.class
1501: .getResourceAsStream("/salome/" + xsl),
1502: temporaryFilePath);
1503: }
1504: File xsltFile = new File(temporaryFilePath);
1505: return xsltFile;
1506: }
1507:
1508: public File getTranslationFile() {
1509: String _urlBase = SalomeTMFContext.getInstance().getUrlBase()
1510: .toString();
1511: String url_txt = _urlBase.substring(0, _urlBase
1512: .lastIndexOf("/"));
1513: String translate = "/plugins/requirements/xsl/translate.xml";
1514: String temporaryFilePath = System.getProperties().getProperty(
1515: "java.io.tmpdir")
1516: + File.separator + "requirementsTranslate.xml";
1517: try {
1518: URL translateURL = new URL(url_txt + translate);
1519: Tools.writeFile(translateURL.openStream(),
1520: temporaryFilePath);
1521: } catch (Exception e) {
1522: Tools.writeFile(ReqPlugin.class
1523: .getResourceAsStream("/salome/" + translate),
1524: temporaryFilePath);
1525: }
1526: File translateFile = new File(temporaryFilePath);
1527: return translateFile;
1528: }
1529:
1530: /**************************************** XMLLoaderPlugin ***************************************/
1531: String fs = System.getProperties().getProperty("file.separator");
1532: String dirXml;
1533:
1534: public void updateElementAttachement(Element envElem,
1535: WithAttachment simpleElement, boolean newElement) {
1536: try {
1537: //URL
1538: List urlAttachementList = envElem
1539: .selectNodes("Attachements/UrlAttachement");
1540: Iterator itEnvUrlAttach = urlAttachementList.iterator();
1541: while (itEnvUrlAttach.hasNext()) {
1542: Element urlElem = (Element) itEnvUrlAttach.next();
1543: String url = urlElem.attributeValue("url");
1544: String description = (urlElem
1545: .elementText("Description") == null) ? ""
1546: : urlElem.elementText("Description");
1547: description = description.replaceAll("\\\\n", "\n");
1548: boolean appartient = false;
1549: Attachment attach = null;
1550: if (newElement == false) {
1551: HashMap envMap = simpleElement
1552: .getAttachmentMapFromModel();
1553: Iterator itEnvAttachs = envMap.values().iterator();
1554: while (itEnvAttachs.hasNext() && !appartient) {
1555: attach = (Attachment) itEnvAttachs.next();
1556: if ((attach instanceof UrlAttachment)
1557: && ((UrlAttachment) attach)
1558: .getNameFromModel().equals(url)) {
1559: appartient = true;
1560: }
1561: }
1562: }
1563: if (!appartient) {
1564: simpleElement
1565: .addAttachementInDBAndModel(new UrlAttachment(
1566: url, description));
1567: } else {
1568: ((UrlAttachment) attach)
1569: .updateDescriptionInDBdAndModel(description);
1570: }
1571: }
1572: //fichiers
1573: List envFileAttachementList = envElem
1574: .selectNodes("Attachements/FileAttachement");
1575: Iterator itEnvFileAttach = envFileAttachementList
1576: .iterator();
1577: while (itEnvFileAttach.hasNext()) {
1578: Element fileElem = (Element) itEnvFileAttach.next();
1579: String dirAtt = fileElem.attributeValue("dir");
1580: String nom = fileElem.attributeValue("nom");
1581: dirAtt = restorePath(dirAtt);
1582: File f = new File(dirXml + fs + dirAtt);
1583: String description = (fileElem
1584: .elementText("Description") == null) ? ""
1585: : fileElem.elementText("Description");
1586: description = description.replaceAll("\\\\n", "\n");
1587: boolean appartient = false;
1588: Attachment attach = null;
1589: if (newElement == false) {
1590: HashMap envMap = simpleElement
1591: .getAttachmentMapFromModel();
1592: Iterator itEnvAttachs = envMap.values().iterator();
1593: while (itEnvAttachs.hasNext() && !appartient) {
1594: attach = (Attachment) itEnvAttachs.next();
1595: if ((attach instanceof FileAttachment)
1596: && ((FileAttachment) attach)
1597: .getNameFromModel().equals(nom)) {
1598: appartient = true;
1599: }
1600: }
1601: }
1602: if (!appartient) {
1603: attach = new FileAttachment(f, description);
1604: simpleElement.addAttachementInDBAndModel(attach);
1605: } else {
1606: ((FileAttachment) attach).updateInDBAndModel(f);
1607: ((FileAttachment) attach)
1608: .updateDescriptionInDBdAndModel(description);
1609: }
1610:
1611: }
1612: } catch (Exception e) {
1613: e.printStackTrace();
1614: }
1615: }
1616:
1617: String restorePath(String path) throws Exception {
1618: if (fs.equals("\\")) {
1619: //Unix2Windows
1620: return path.replace('/', '\\');
1621: } else {
1622: return path.replace('\\', '/');
1623: }
1624: }
1625:
1626: private Vector getAllReqLeavesByCatAndPri(int cat, int pri) {
1627: Vector res = new Vector();
1628:
1629: JTree reqTree = getTreeRequirement();
1630: if (reqTree != null) {
1631: DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((DefaultTreeModel) reqTree
1632: .getModel()).getRoot();
1633: salomeTMF_plug.requirements.data.Requirement pTempReq = (salomeTMF_plug.requirements.data.Requirement) node
1634: .getUserObject();
1635: salomeTMF_plug.requirements.data.ReqFamily reqRoot = (salomeTMF_plug.requirements.data.ReqFamily) pTempReq;
1636:
1637: if (reqRoot != null) {
1638: Vector allLeaves = reqRoot.getAllLeaf();
1639: for (int i = 0; i < allLeaves.size(); i++) {
1640: ReqLeaf req = (ReqLeaf) allLeaves.elementAt(i);
1641: if ((req.getCatFromModel() == cat)
1642: && (req.getPriorityFromModel() == pri)) {
1643: res.add(req);
1644: }
1645: }
1646: }
1647: }
1648:
1649: return res;
1650: }
1651:
1652: private Vector getAllReqLeavesByCat(int cat) {
1653: Vector res = new Vector();
1654:
1655: JTree reqTree = getTreeRequirement();
1656: if (reqTree != null) {
1657: DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((DefaultTreeModel) reqTree
1658: .getModel()).getRoot();
1659: salomeTMF_plug.requirements.data.Requirement pTempReq = (salomeTMF_plug.requirements.data.Requirement) node
1660: .getUserObject();
1661: salomeTMF_plug.requirements.data.ReqFamily reqRoot = (salomeTMF_plug.requirements.data.ReqFamily) pTempReq;
1662:
1663: if (reqRoot != null) {
1664: Vector allLeaves = reqRoot.getAllLeaf();
1665: for (int i = 0; i < allLeaves.size(); i++) {
1666: ReqLeaf req = (ReqLeaf) allLeaves.elementAt(i);
1667: if (req.getCatFromModel() == cat) {
1668: res.add(req);
1669: }
1670: }
1671: }
1672: }
1673:
1674: return res;
1675: }
1676:
1677: //***********************************************************************************************//
1678: // Interface RegManager //
1679: //***********************************************************************************************//
1680:
1681: public int getNbReqForCat(int cat) {
1682: int res = 0;
1683: Vector reqs = getAllReqLeavesByCat(cat);
1684: if (reqs != null) {
1685: res = reqs.size();
1686: }
1687: return res;
1688: }
1689:
1690: public boolean isAllReqCovered(int cat, int pri) {
1691: boolean res = true;
1692:
1693: Vector reqs = getAllReqLeavesByCatAndPri(cat, pri);
1694: if ((reqs != null) && (reqs.size() != 0)) {
1695: int i = 0;
1696: while ((i < reqs.size()) && res) {
1697: ReqLeaf req = (ReqLeaf) reqs.elementAt(i);
1698: Vector associatedTests = new Vector();
1699: try {
1700: associatedTests = req.getTestWrapperCoveredFromDB();
1701: } catch (Exception e) {
1702: // TODO
1703: e.printStackTrace();
1704: }
1705: res = (associatedTests != null)
1706: && (associatedTests.size() != 0);
1707: i++;
1708: }
1709: }
1710:
1711: return res;
1712: }
1713:
1714: public boolean isAllReqCoveredExecuted(int cat, int pri) {
1715: boolean res = true;
1716:
1717: Vector reqs = getAllReqLeavesByCatAndPri(cat, pri);
1718: if (!isAllReqCovered(cat, pri)) {
1719: res = false;
1720: } else {
1721: int i = 0;
1722: while ((i < reqs.size()) && res) {
1723: ReqLeaf req = (ReqLeaf) reqs.elementAt(i);
1724: Vector associatedTests = new Vector();
1725: try {
1726: associatedTests = req.getTestWrapperCoveredFromDB();
1727: } catch (Exception e) {
1728: // TODO
1729: e.printStackTrace();
1730: }
1731: int j = 0;
1732: while ((j < associatedTests.size()) && res) {
1733: TestWrapper testWrap = (TestWrapper) associatedTests
1734: .elementAt(j);
1735: Test test = DataModel.getCurrentProject()
1736: .getTestFromModel(testWrap.getIdBDD());
1737: if (test == null && !isGlobalProject()) {
1738: if (getProjectRef().getIdBdd() == DataModel
1739: .getCurrentProject().getIdBdd()) {
1740: DataModel.reloadFromBase(true);
1741: test = DataModel.getCurrentProject()
1742: .getTestFromModel(
1743: testWrap.getIdBDD());
1744: }
1745: if (test == null) {
1746: res = false;
1747: }
1748: }
1749: ArrayList campaignList = DataModel
1750: .getCurrentProject()
1751: .getCampaignOfTest(test);
1752: if (campaignList == null
1753: || campaignList.size() == 0) {
1754: res = false;
1755: } else {
1756: int k = 0;
1757: int size = campaignList.size();
1758: while (k < size && res) {
1759: Campaign pCampaign = (Campaign) campaignList
1760: .get(k);
1761: if (!pCampaign
1762: .containsExecutionResultInModel()) {
1763: res = false;
1764: }
1765: k++;
1766: }
1767: }
1768: j++;
1769: }
1770: i++;
1771: }
1772: }
1773:
1774: return res;
1775: }
1776:
1777: public Vector getAssociatedTestsForReqCat(int cat) {
1778: Vector tests = new Vector();
1779: Vector reqs = getAllReqLeavesByCat(cat);
1780:
1781: if ((reqs != null) && (reqs.size() != 0)) {
1782: for (int i = 0; i < reqs.size(); i++) {
1783: ReqLeaf req = (ReqLeaf) reqs.elementAt(i);
1784: Vector testWrappers = new Vector();
1785: try {
1786: testWrappers = req.getTestWrapperCoveredFromDB();
1787: } catch (Exception e) {
1788: // TODO
1789: e.printStackTrace();
1790: }
1791: if (testWrappers != null) {
1792: for (int j = 0; j < testWrappers.size(); j++) {
1793: TestWrapper testWrap = (TestWrapper) testWrappers
1794: .elementAt(j);
1795: if (testWrap != null) {
1796: Test test = DataModel.getCurrentProject()
1797: .getTestFromModel(
1798: testWrap.getIdBDD());
1799: if (test == null && !isGlobalProject()) {
1800: if (getProjectRef().getIdBdd() == DataModel
1801: .getCurrentProject().getIdBdd()) {
1802: DataModel.reloadFromBase(true);
1803: test = DataModel
1804: .getCurrentProject()
1805: .getTestFromModel(
1806: testWrap.getIdBDD());
1807: }
1808: }
1809: if (test != null) {
1810: tests.add(test);
1811: }
1812: }
1813: }
1814: }
1815: }
1816: }
1817: return tests;
1818: }
1819:
1820: public String getReqManagerName() {
1821: return REQ_NAME;
1822: }
1823:
1824: public void deleteReqLinkWithTest(int idTest) {
1825: try {
1826: Requirement.deleteAllCoverForTest(idTest);
1827: } catch (Exception e) {
1828: Tools.ihmExceptionView(e);
1829: }
1830: }
1831:
1832: public void setExport(boolean b) {
1833: mandatoryExport = b;
1834: }
1835:
1836: public void setImport(boolean b) {
1837: mandatoryImport = b;
1838: }
1839:
1840: public String getChapterTitleInReport() {
1841: if (doExport()) {
1842: return Language.getInstance().getText("Exigences");
1843: } else {
1844: return null;
1845: }
1846: }
1847:
1848: public String getParameterName(String chapterName) {
1849: if (chapterName.equals(Language.getInstance().getText(
1850: "Exigences"))) {
1851: return "requirements";
1852: }
1853: return null;
1854: }
1855:
1856: public void addReqLinkWithTest(Test test, int idReq) {
1857: try {
1858: if (pSQLRequirement == null) {
1859: SQLWrapper.init(Api.getISQLObjectFactory());
1860: pSQLRequirement = SQLWrapper.getSQLRequirement();
1861: }
1862: pSQLRequirement.addReqConvert(idReq, test.getIdBdd());
1863: } catch (Exception e) {
1864: Util
1865: .log("[ReqPlugin->addReqLinkWithTest] Unable to link test and requirement");
1866: }
1867: }
1868: }
|