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 Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package org.objectweb.salome_tmf.ihm.main;
025:
026: import java.awt.Frame;
027: import java.net.URL;
028: import java.util.Enumeration;
029: import java.util.HashMap;
030: import java.util.Hashtable;
031: import java.util.Iterator;
032: import java.util.Map;
033: import java.util.Vector;
034:
035: import javax.swing.JOptionPane;
036:
037: import org.java.plugin.Extension;
038: import org.java.plugin.ExtensionPoint;
039: import org.java.plugin.PluginManager;
040: import org.objectweb.salome_tmf.api.Api;
041: import org.objectweb.salome_tmf.data.Attachment;
042: import org.objectweb.salome_tmf.ihm.languages.Language;
043: import org.objectweb.salome_tmf.plugins.IPlugObject;
044: import org.objectweb.salome_tmf.plugins.JPFManager;
045: import org.objectweb.salome_tmf.plugins.PluginClassLoader;
046: import org.objectweb.salome_tmf.plugins.core.BugTracker;
047: import org.objectweb.salome_tmf.plugins.core.Common;
048:
049: public class SalomeTMFContext implements IPlugObject {
050:
051: public Hashtable associatedTestDriver;
052: public Hashtable associatedScriptEngine;
053: public Hashtable associatedExtension;
054: public Vector bugTrackers;
055: public Vector reqManagers;
056: Vector xmlPrinters;
057: public Hashtable bugTrackerExtensions;
058:
059: /**
060: * JPF Parameters
061: */
062: PluginManager pluginManager;
063: ExtensionPoint CommonExtPoint;
064: ExtensionPoint testDriverExtPoint;
065: ExtensionPoint scriptEngineExtPoint;
066: ExtensionPoint bugTrackerExtPoint;
067: ExtensionPoint reqManagerExtPoint;
068: JPFManager jpf;
069:
070: /**
071: * Mapping between UI components and constants defined in org.objectweb.salome_tmf.ihm.UICompCst
072: */
073: Map UIComponentsMap;
074:
075: /**
076: * Associated plugins to UI components
077: * key = associated constante to UI Component , value = List of associated plugins
078: */
079: Map associatedPlgsToCompsMap;
080:
081: URL urlSalome;
082: Frame ptrFrame;
083: static BaseIHM pBaseIHM;
084:
085: static SalomeTMFContext pSalomeTMFContext = null;
086:
087: public SalomeTMFContext(URL documentBase, Frame pFrame,
088: BaseIHM _BaseIHM) {
089: urlSalome = documentBase;
090: ptrFrame = pFrame;
091: pBaseIHM = _BaseIHM;
092:
093: associatedTestDriver = new Hashtable();
094: associatedScriptEngine = new Hashtable();
095: associatedExtension = new Hashtable();
096: bugTrackers = new Vector();
097: reqManagers = new Vector();
098: xmlPrinters = new Vector();
099: //bugTrackerExtensions = new Vector();
100: bugTrackerExtensions = new Hashtable();
101: UIComponentsMap = new HashMap();
102: associatedPlgsToCompsMap = new HashMap();
103: pSalomeTMFContext = this ;
104: /*try
105: {
106: EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
107: eq.invokeAndWait(new Runnable() {
108: public void run() {
109: Thread.currentThread().setContextClassLoader(pSalomeClassLoader);
110: }
111: });
112: }
113: catch (Exception e)
114: {
115: e.printStackTrace();
116: }*/
117: }
118:
119: public PluginClassLoader getSalomeClassLoader() {
120: return jpf.getClassLoader();
121: }
122:
123: public void addJarToClassLoader(URL jar) {
124: jpf.getClassLoader().AddJar(jar);
125: }
126:
127: public static BaseIHM getBaseIHM() {
128: return pBaseIHM;
129: }
130:
131: public static SalomeTMFContext getInstance() {
132: return pSalomeTMFContext;
133: }
134:
135: public Frame getSalomeFrame() {
136: return ptrFrame;
137: }
138:
139: /********************************* BDD/API***************************************/
140:
141: /************************ Plugin Method ***********************************************/
142:
143: public void loadPlugin(SalomeTMFPanels pSalomeTMFPanels) {
144: if (Api.isALLOW_PLUGINS()) {
145: jpf = new JPFManager();
146: jpf.startJPF(this , urlSalome, UIComponentsMap);
147: pSalomeTMFPanels.loadPlugin();
148: }
149: }
150:
151: void reloadPlugin(SalomeTMFPanels pSalomeTMFPanels) {
152: if (Api.isALLOW_PLUGINS()) {
153: jpf.reActivatePlugin(this , CommonExtPoint,
154: bugTrackerExtPoint, UIComponentsMap);
155: pSalomeTMFPanels.loadPlugin();
156: }
157: }
158:
159: void startPlugin() {
160: if (Api.isALLOW_PLUGINS()) {
161: for (Iterator it = CommonExtPoint.getConnectedExtensions()
162: .iterator(); it.hasNext();) {
163: Extension commonExt = (Extension) it.next();
164: try {
165: Object ob = jpf.activateExtension(commonExt);
166: if (ob != null) {
167: ((Common) ob).allPluginActived(CommonExtPoint,
168: testDriverExtPoint,
169: scriptEngineExtPoint,
170: bugTrackerExtPoint);
171: }
172: } catch (Exception e) {
173: e.printStackTrace();
174: }
175: }
176: }
177: }
178:
179: void suspendPlugin() {
180: if (Api.isALLOW_PLUGINS()) {
181: int size = bugTrackers.size();
182: for (int i = 0; i < size; i++) {
183: BugTracker tracker = (BugTracker) bugTrackers
184: .elementAt(i);
185: tracker.suspend();
186: }
187: }
188: }
189:
190: /**
191: * M?thode utilis?e par les autres classes de l'IHM pour remplir la table
192: * de hachage pour le mapping entre composants graphiques et constantes
193: * @param uiConst
194: * @param uiComp
195: */
196: public void addToUIComponentsMap(Integer uiConst, Object uiComp) {
197: if (UIComponentsMap != null)
198: UIComponentsMap.put(uiConst, uiComp);
199: }
200:
201: /************************ IPlugObject IMPLEMENTATION ***********************************/
202:
203: public Object associatedExtension(Object key, Object value) {
204: //implementation by Hastable
205: return associatedExtension.put(key, value);
206: }
207:
208: public Object associatedBugTrackerExtension(Object key, Object value) {
209: //implementation by Hastable
210: System.out.println("Associate " + key + " with " + value);
211: return bugTrackerExtensions.put(key, value);
212: }
213:
214: public Vector getAllTracker() {
215: Vector listTracker = new Vector();
216: Enumeration e = bugTrackerExtensions.elements();
217: while (e.hasMoreElements()) {
218: listTracker.add(e.nextElement());
219: }
220: return listTracker;
221:
222: }
223:
224: public Object associatedScriptEngine(Object key, Object value) {
225: //implementation by Hastable
226: //associatedExtension.put(key, value);
227: return associatedScriptEngine.put(key, value);
228: }
229:
230: public Object associatedTestDriver(Object key, Object value) {
231: //implementation by Hastable
232: //associatedExtension.put(key, value);
233: return associatedTestDriver.put(key, value);
234: }
235:
236: public Object getAssociatedExtension(Object key) {
237: return associatedExtension.get(key);
238: }
239:
240: public Object getAssociatedScriptEngine(Object key) {
241: return associatedScriptEngine.get(key);
242: }
243:
244: public Object get1ssociatedTestDriver(Object key) {
245: return associatedTestDriver.get(key);
246: }
247:
248: public void initExtsionTestDriver(ExtensionPoint ext) {
249: }
250:
251: public void initExtsionScriptEngine(ExtensionPoint ext) {
252: }
253:
254: public void showMessage(String msg) {
255: JOptionPane.showMessageDialog(ptrFrame, msg, Language
256: .getInstance().getText("Information_!"),
257: JOptionPane.INFORMATION_MESSAGE);
258: }
259:
260: public void init_Component(PluginManager pluginM,
261: ExtensionPoint commonE, ExtensionPoint testE,
262: ExtensionPoint scriptE, ExtensionPoint bugTrackerE,
263: ExtensionPoint reqMgr) {
264: pluginManager = pluginM;
265: CommonExtPoint = commonE;
266: testDriverExtPoint = testE;
267: scriptEngineExtPoint = scriptE;
268: bugTrackerExtPoint = bugTrackerE;
269: reqManagerExtPoint = reqMgr;
270: }
271:
272: public URL getUrlBase() {
273: return urlSalome;
274: }
275:
276: public JPFManager getPluginManager() {
277: return jpf;
278: }
279:
280: public void addBugTrackers(Object bugTracker) {
281: bugTrackers.add(bugTracker);
282: }
283:
284: public Vector getBugTracker() {
285: return bugTrackers;
286: }
287:
288: public void addXMLPrinterExtension(Object xmlPrinter) {
289: if (!xmlPrinters.contains(xmlPrinter)) {
290: xmlPrinters.add(xmlPrinter);
291: }
292: }
293:
294: public Vector getXMLPrintersExtension() {
295: return xmlPrinters;
296: }
297:
298: public BugTracker getBugTrackerFromAttachment(Attachment pAttachment) {
299: BugTracker pBugTracker = null;
300: if (pAttachment == null) {
301: return null;
302: }
303: int size = bugTrackers.size();
304: if (size == 0) {
305: return null;
306: }
307: String description = pAttachment.getDescriptionFromModel();
308: int i = 0;
309: while (i < size && pBugTracker == null) {
310: pBugTracker = (BugTracker) bugTrackers.elementAt(i);
311: if (!pBugTracker.getBugTrackerAttachDesc().equals(
312: description)) {
313: pBugTracker = null;
314: }
315: i++;
316: }
317: return pBugTracker;
318: }
319:
320: public void addPlgToUICompList(Integer uiConst, Common commonPlg) {
321: if (associatedPlgsToCompsMap != null) {
322: Object listPlgs = associatedPlgsToCompsMap.get(uiConst);
323:
324: if (listPlgs == null) {
325: java.util.LinkedList list = new java.util.LinkedList();
326: list.add(commonPlg);
327: associatedPlgsToCompsMap.put(uiConst, list);
328: } else {
329: ((java.util.LinkedList) listPlgs).add(commonPlg);
330: }
331: }
332: }
333:
334: public Object getUIComponent(Integer uiConst) {
335: Object comp = null;
336: if (UIComponentsMap != null)
337: comp = UIComponentsMap.get(uiConst);
338: return comp;
339: }
340:
341: /**
342: * Methode qui retourne la liste des plugins associ? ? un composant graphique
343: * @param uiConst
344: * @return
345: */
346: public java.util.LinkedList getAssociatedPluginsToUIComp(
347: Integer uiConst) {
348: java.util.LinkedList associatedPlgs = null;
349: if (associatedPlgsToCompsMap != null)
350: associatedPlgs = (java.util.LinkedList) associatedPlgsToCompsMap
351: .get(uiConst);
352: return associatedPlgs;
353: }
354:
355: public JPFManager getJpf() {
356: return jpf;
357: }
358:
359: public void setJpf(JPFManager jpf) {
360: this .jpf = jpf;
361: }
362:
363: public Map getUIComponentsMap() {
364: return UIComponentsMap;
365: }
366:
367: /************************* Context Messaging *************************/
368: /**
369: * @param type @see JOptionPane dialog type (WARNING_MESSAGE, QUESTION_MESSAGE, ...)
370: */
371: public void showMessage(String msg, String info, int type) {
372: JOptionPane.showMessageDialog(ptrFrame, msg, info, type);
373: }
374:
375: /**
376: * @param type @see JOptionPane dialog type (WARNING_MESSAGE, QUESTION_MESSAGE, ...)
377: */
378: public int askQuestion(String msg, String info, int type,
379: Object[] options) {
380: return JOptionPane.showOptionDialog(ptrFrame, msg, info,
381: JOptionPane.YES_NO_OPTION, type, null, options,
382: options[1]);
383: }
384:
385: public void addReqManager(Object reqManager) {
386: reqManagers.add(reqManager);
387: }
388:
389: public Vector getReqManagers() {
390: return reqManagers;
391: }
392: }
|