001: package salomeTMF_plug.mantis;
002:
003: import java.awt.GridLayout;
004: import java.awt.event.ActionEvent;
005: import java.awt.event.ActionListener;
006: import java.util.ArrayList;
007: import java.util.HashMap;
008: import java.util.Iterator;
009: import java.util.Set;
010:
011: import javax.swing.JButton;
012: import javax.swing.JPanel;
013:
014: import org.objectweb.salome_tmf.data.Action;
015: import org.objectweb.salome_tmf.data.Attachment;
016: import org.objectweb.salome_tmf.data.Execution;
017: import org.objectweb.salome_tmf.data.ExecutionResult;
018: import org.objectweb.salome_tmf.data.ExecutionTestResult;
019: import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
020: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
021:
022: import salomeTMF_plug.mantis.languages.Language;
023: import salomeTMF_plug.mantis.sqlWrapper.DefectWrapper;
024:
025: public class ExecResDefectActionPanel extends JPanel implements
026: ActionListener {
027:
028: JButton newDefectButton;
029: JButton linkDefectButton;
030: JButton editDefectButton;
031: JButton deleteButton;
032:
033: DefectPanel pDefectPanel;
034: MantisPlugin pMantisPlugin;
035: ExecutionTestResult pExecutionTestResult;
036: Execution pExecution;
037: boolean workOnModel;
038:
039: ExecResDefectActionPanel(MantisPlugin pMantisPlugin,
040: boolean workOnModel) {
041: super (new GridLayout(1, 3));
042: this .pMantisPlugin = pMantisPlugin;
043: this .workOnModel = workOnModel;
044: initActionPanel();
045: }
046:
047: void setDefectPanel(DefectPanel pDefectPanel) {
048: this .pDefectPanel = pDefectPanel;
049: }
050:
051: void setExecutionResult(ExecutionTestResult pExecutionTestResult) {
052: this .pExecutionTestResult = pExecutionTestResult;
053: }
054:
055: void setExecution(Execution pExecution) {
056: this .pExecution = pExecution;
057: }
058:
059: void initActionPanel() {
060: newDefectButton = new JButton(
061: salomeTMF_plug.mantis.languages.Language.getInstance()
062: .getText("Ajouter"));
063: newDefectButton.addActionListener(this );
064: linkDefectButton = new JButton(Language.getInstance().getText(
065: "Lier_a_annomalie"));
066: linkDefectButton.addActionListener(this );
067: editDefectButton = new JButton(
068: salomeTMF_plug.mantis.languages.Language.getInstance()
069: .getText("Editer"));
070: editDefectButton.addActionListener(this );
071: deleteButton = new JButton(
072: org.objectweb.salome_tmf.ihm.languages.Language
073: .getInstance().getText("Supprimer"));
074: deleteButton.addActionListener(this );
075: add(newDefectButton);
076: add(linkDefectButton);
077: add(editDefectButton);
078: add(deleteButton);
079: }
080:
081: public void actionPerformed(ActionEvent e) {
082: if (e.getSource().equals(newDefectButton)) {
083: newDefectPerformed();
084: } else if (e.getSource().equals(editDefectButton)) {
085: editDefectPerformed();
086: } else if (e.getSource().equals(deleteButton)) {
087: deleteDefectPerformed();
088: } else if (e.getSource().equals(linkDefectButton)) {
089: linkPerformed();
090: }
091: }
092:
093: void linkPerformed() {
094: String envRestrictionName = null;
095: if (pExecution == null) {
096: try {
097: pExecution = DataModel.getObservedExecutionResult()
098: .getExecution();
099: envRestrictionName = pExecution
100: .getEnvironmentFromModel().getNameFromModel();
101: } catch (Exception e1) {
102: e1.printStackTrace();
103: }
104: } else {
105: envRestrictionName = pExecution.getEnvironmentFromModel()
106: .getNameFromModel();
107: }
108: LinkDefectDialog pLinkDefectDialog = new LinkDefectDialog(
109: pMantisPlugin, pDefectPanel.defectsWrapper,
110: envRestrictionName);
111: DefectWrapper pDefectWrapper = pLinkDefectDialog
112: .getSelectedDefectWrapper();
113: if (pDefectWrapper != null) {
114: try {
115: Attachment pAttch = pMantisPlugin
116: .makeAttachement(pDefectWrapper.getId());
117: //if (pExecutionTestResult == null){
118: pExecutionTestResult = DataModel
119: .getCurrentExecutionTestResult();
120: //}
121: if (workOnModel) {
122: pExecutionTestResult.addAttachementInModel(pAttch);
123: } else {
124: pExecutionTestResult
125: .addAttachementInDBAndModel(pAttch);
126: }
127: pDefectPanel.defectsWrapper.put(new Integer(
128: pDefectWrapper.getId()), pDefectWrapper);
129: pDefectPanel.reloadData();
130: } catch (Exception e) {
131: e.printStackTrace();
132: }
133: }
134: }
135:
136: void newDefectPerformed() {
137:
138: if (pExecution == null) {
139: try {
140: pExecution = DataModel.getObservedExecutionResult()
141: .getExecution();
142: } catch (Exception e1) {
143: e1.printStackTrace();
144: }
145: }
146: //if (pExecutionTestResult == null){
147: pExecutionTestResult = DataModel
148: .getCurrentExecutionTestResult();
149: //}
150: DefectView pDefectView = null;
151: if (DataModel.getObservedExecutionResult() != null
152: && pExecutionTestResult != null) {
153: pDefectView = new DefectView(SalomeTMFContext.getInstance()
154: .getSalomeFrame(), DataModel
155: .getObservedExecutionResult(),
156: pExecutionTestResult, null, null, null, null,
157: pMantisPlugin);
158: } else if (pExecution != null) {
159: pDefectView = new DefectView(SalomeTMFContext.getInstance()
160: .getSalomeFrame(), pMantisPlugin, pExecution
161: .getEnvironmentFromModel().getNameFromModel());
162:
163: } else {
164: pDefectView = new DefectView(SalomeTMFContext.getInstance()
165: .getSalomeFrame(), pMantisPlugin);
166: }
167: try {
168: if (pDefectView.isDoingModification()) {
169: DefectWrapper pDefectWrapper = pDefectView
170: .getDefectWrapper();
171: if (pDefectWrapper != null) {
172: Attachment pAttch = pMantisPlugin
173: .makeAttachement(pDefectWrapper.getId());
174:
175: if (workOnModel) {
176: pExecutionTestResult
177: .addAttachementInModel(pAttch);
178: } else {
179: pExecutionTestResult
180: .addAttachementInDBAndModel(pAttch);
181: }
182: pDefectPanel.defectsWrapper.put(new Integer(
183: pDefectWrapper.getId()), pDefectWrapper);
184: pDefectPanel.reloadData();
185: }
186: }
187: } catch (Exception e) {
188: e.printStackTrace();
189: }
190: }
191:
192: void editDefectPerformed() {
193: DefectWrapper pDefectWrapper = pDefectPanel.getSelectedDefect();
194: if (pDefectWrapper != null) {
195: DefectView pDefectView = new DefectView(SalomeTMFContext
196: .getInstance().getSalomeFrame(), pDefectWrapper,
197: pMantisPlugin, true);
198: try {
199: if (pDefectView.isDoingModification()) {
200: pDefectPanel.reloadData();
201: }
202: } catch (Exception e) {
203: e.printStackTrace();
204: }
205: }
206: }
207:
208: void deleteDefectPerformed() {
209: DefectWrapper pDefectWrapper = pDefectPanel.getSelectedDefect();
210: if (pDefectWrapper != null) {
211: if (pMantisPlugin.deleteConfirme(Language.getInstance()
212: .getText("Le_lien"))) {
213: int defectID = pDefectWrapper.getId();
214: //if (pExecutionTestResult == null){
215: pExecutionTestResult = DataModel
216: .getCurrentExecutionTestResult();
217: //}
218: HashMap attacMap = pExecutionTestResult
219: .getAttachmentMapFromModel();
220: Set keysSet = attacMap.keySet();
221: boolean trouve = false;
222: Iterator iter = keysSet.iterator();
223: while (!trouve && iter.hasNext()) {
224: try {
225: Object attachName = iter.next();
226: Attachment pAttach = (Attachment) attacMap
227: .get(attachName);
228: int bugid = pMantisPlugin.getIDofBug(pAttach);
229: if (bugid == defectID) {
230: if (workOnModel) {
231: pExecutionTestResult
232: .deleteAttachmentInModel(pAttach);
233: } else {
234: pExecutionTestResult
235: .deleteAttachementInDBAndModel(pAttach);
236: }
237: pDefectPanel.defectsWrapper
238: .remove(new Integer(bugid));
239: pDefectPanel.reloadData();
240: trouve = true;
241: }
242: } catch (Exception ex) {
243: ex.printStackTrace();
244: }
245: }
246: }
247: }
248: }
249: }
|