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.BorderLayout;
027: import java.awt.Dimension;
028: import java.awt.event.ActionEvent;
029: import java.awt.event.ActionListener;
030: import java.util.ArrayList;
031: import java.util.HashMap;
032: import java.util.Map;
033: import java.util.Vector;
034:
035: import javax.swing.BorderFactory;
036: import javax.swing.JButton;
037: import javax.swing.JPanel;
038: import javax.swing.JScrollPane;
039: import javax.swing.JTable;
040: import javax.swing.ListSelectionModel;
041: import javax.swing.event.ListSelectionEvent;
042: import javax.swing.event.ListSelectionListener;
043:
044: import org.java.plugin.Extension;
045: import org.java.plugin.PluginManager;
046: import org.objectweb.salome_tmf.ihm.languages.Language;
047: import org.objectweb.salome_tmf.ihm.models.MyTableModel;
048: import org.objectweb.salome_tmf.ihm.models.RowTransferHandler;
049: import org.objectweb.salome_tmf.ihm.models.TableSorter;
050: import org.objectweb.salome_tmf.plugins.UICompCst;
051: import org.objectweb.salome_tmf.plugins.core.Common;
052:
053: public class PluginsView extends javax.swing.JPanel implements
054: ActionListener, ListSelectionListener {
055:
056: // Variables declaration
057: JButton activateButton;
058: JButton freezeButton;
059: //MyTableModel pluginsTableModel = null;
060: TableSorter sorter = null;
061: //TableSorter sorter2 = null;
062: JTable pluginsTable = null;
063: ListSelectionModel rowSM = null;
064: Extension currentExt = null;
065: Common currentCommonPlg = null;
066: String currentPlgID = null;
067: PluginManager pluginMgr = null;
068: Map extensions = new HashMap();
069: int selectedRow = -1;
070: Vector commonExtensions = new Vector();
071: Vector testDriverExtensions = new Vector();
072: Vector scriptEngineExtensions = new Vector();
073: Vector bugTrackingExtensions = new Vector();
074: Vector reqMgrExtensions = new Vector();
075:
076: //FOR TEST
077: RowTransferHandler transferHandler;
078:
079: /** Creates new form PluginsView */
080: public PluginsView(Vector commonExtensions,
081: Vector testDriverExtensions, Vector scriptEngineExtensions,
082: Vector bugTrackingExtensions, Vector reqMgrExtensions,
083: PluginManager plgMgr) {
084:
085: pluginMgr = plgMgr;
086: this .commonExtensions = commonExtensions;
087: this .testDriverExtensions = testDriverExtensions;
088: this .scriptEngineExtensions = scriptEngineExtensions;
089: this .bugTrackingExtensions = bugTrackingExtensions;
090: this .reqMgrExtensions = reqMgrExtensions;
091:
092: activateButton = new JButton(Language.getInstance().getText(
093: "Activer"));
094: activateButton.setEnabled(false);
095: activateButton.addActionListener(this );
096:
097: freezeButton = new JButton(Language.getInstance().getText(
098: "Geler"));
099: freezeButton.setEnabled(false);
100: freezeButton.addActionListener(this );
101:
102: sorter = new TableSorter(createPluginTableModel(
103: commonExtensions, testDriverExtensions,
104: scriptEngineExtensions, plgMgr));
105: pluginsTable = new JTable(sorter);
106: sorter.setTableHeader(pluginsTable.getTableHeader());
107: //sorter.addMouseListenerToHeaderInTable(pluginsTable);
108:
109: /*sorter = new MyTableSorter(createPluginTableModel(commonExtensions, testDriverExtensions, scriptEngineExtensions, plgMgr ));
110: pluginsTable = new JTable(sorter);
111: //sorter.setTableHeader(pluginsTable.getTableHeader());
112: sorter.addMouseListenerToHeaderInTable(pluginsTable);
113: */
114: pluginsTable.setPreferredScrollableViewportSize(new Dimension(
115: 700, 350));
116: pluginsTable.setTransferHandler(transferHandler);
117: pluginsTable
118: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
119:
120: JScrollPane pluginsTableScrollPane = new JScrollPane(
121: pluginsTable);
122: // Gestion des sélection dans la table
123: rowSM = pluginsTable.getSelectionModel();
124: rowSM.addListSelectionListener(this );
125:
126: JPanel buttonsPanel = new JPanel();
127:
128: buttonsPanel.add(activateButton);
129: buttonsPanel.add(freezeButton);
130: buttonsPanel.setBorder(BorderFactory.createRaisedBevelBorder());
131:
132: this .setLayout(new BorderLayout());
133: this .add(BorderLayout.NORTH, buttonsPanel);
134: this .add(BorderLayout.CENTER, pluginsTableScrollPane);
135:
136: // Mapping GUI Object for plugins//
137: SalomeTMFContext.getInstance().addToUIComponentsMap(
138: UICompCst.PLUGINS_BUTTONS_PANEL, buttonsPanel);
139: UICompCst.staticUIComps.add(UICompCst.PLUGINS_BUTTONS_PANEL);
140:
141: SalomeTMFContext.getInstance().addToUIComponentsMap(
142: UICompCst.PLUGINS_TABLE, pluginsTable);
143: UICompCst.staticUIComps.add(UICompCst.PLUGINS_TABLE);
144:
145: SalomeTMFContext.getInstance().addToUIComponentsMap(
146: UICompCst.PLUGINS_PANEL, this );
147: UICompCst.staticUIComps.add(UICompCst.PLUGINS_PANEL);
148:
149: }
150:
151: MyTableModel createPluginTableModel(Vector commonExtensions,
152: Vector testDriverExtensions, Vector scriptEngineExtensions,
153: PluginManager plgMgr) {
154: MyTableModel pluginsTableModel = new MyTableModel();
155:
156: pluginsTableModel.addColumnNameAndColumn(Language.getInstance()
157: .getText("Plugin"));
158: pluginsTableModel.addColumnNameAndColumn(Language.getInstance()
159: .getText("Nom_d'extension"));
160: pluginsTableModel.addColumnNameAndColumn(Language.getInstance()
161: .getText("Description"));
162: pluginsTableModel.addColumnNameAndColumn(Language.getInstance()
163: .getText("Extension"));
164: pluginsTableModel.addColumnNameAndColumn(Language.getInstance()
165: .getText("Statut"));
166:
167: // Common Plugins
168: for (int i = 0; i < commonExtensions.size(); i++) {
169: ArrayList row = new ArrayList(5);
170: Extension commonExt = (Extension) commonExtensions
171: .elementAt(i);
172: row
173: .add(0, commonExt.getDeclaringPluginDescriptor()
174: .getId());
175: row.add(1, commonExt.getId());
176: row.add(2, commonExt.getParameter(
177: Language.getInstance().getText("description"))
178: .valueAsString());
179: row.add(3, commonExt.getExtendedPointId());
180: String activated = Language.getInstance()
181: .getText("Inactif");
182: if (plgMgr.isPluginActivated(commonExt
183: .getDeclaringPluginDescriptor())) {
184: activated = Language.getInstance().getText("Actif");
185: }
186:
187: row.add(4, activated);
188: pluginsTableModel.addRow(row);
189: extensions.put(commonExt.getParameter("name")
190: .valueAsString()
191: + commonExt.getExtendedPointId(), commonExt);
192: }
193:
194: // TestDriver Plugins
195: for (int i = 0; i < testDriverExtensions.size(); i++) {
196: ArrayList row = new ArrayList(5);
197: Extension testDriverExt = (Extension) testDriverExtensions
198: .elementAt(i);
199: row.add(0, testDriverExt.getDeclaringPluginDescriptor()
200: .getId());
201: row.add(1, testDriverExt.getId());
202: row.add(2, testDriverExt.getParameter(
203: Language.getInstance().getText("description"))
204: .valueAsString());
205: row.add(3, testDriverExt.getExtendedPointId());
206: String activated = Language.getInstance()
207: .getText("Inactif");
208: if (plgMgr.isPluginActivated(testDriverExt
209: .getDeclaringPluginDescriptor())) {
210: activated = Language.getInstance().getText("Actif");
211: }
212:
213: row.add(4, activated);
214: pluginsTableModel.addRow(row);
215: extensions
216: .put(testDriverExt.getParameter("name")
217: .valueAsString()
218: + testDriverExt.getExtendedPointId(),
219: testDriverExt);
220:
221: }
222:
223: // ScriptEngine Plugins
224: for (int i = 0; i < scriptEngineExtensions.size(); i++) {
225: ArrayList row = new ArrayList(5);
226: Extension scriptEngineExt = (Extension) scriptEngineExtensions
227: .elementAt(i);
228: row.add(0, scriptEngineExt.getDeclaringPluginDescriptor()
229: .getId());
230: row.add(1, scriptEngineExt.getId());
231: row.add(2, scriptEngineExt.getParameter(
232: Language.getInstance().getText("description"))
233: .valueAsString());
234: row.add(3, scriptEngineExt.getExtendedPointId());
235: String activated = Language.getInstance()
236: .getText("Inactif");
237: if (plgMgr.isPluginActivated(scriptEngineExt
238: .getDeclaringPluginDescriptor())) {
239: activated = Language.getInstance().getText("Actif");
240: }
241:
242: row.add(4, activated);
243: pluginsTableModel.addRow(row);
244: extensions.put(scriptEngineExt.getParameter("name")
245: .valueAsString()
246: + scriptEngineExt.getExtendedPointId(),
247: scriptEngineExt);
248:
249: }
250:
251: // Bug tracking Plugins
252: for (int i = 0; i < bugTrackingExtensions.size(); i++) {
253: ArrayList row = new ArrayList(5);
254: Extension bTrackExt = (Extension) bugTrackingExtensions
255: .elementAt(i);
256: row
257: .add(0, bTrackExt.getDeclaringPluginDescriptor()
258: .getId());
259: row.add(1, bTrackExt.getId());
260: row.add(2, bTrackExt.getParameter(
261: Language.getInstance().getText("description"))
262: .valueAsString());
263: row.add(3, bTrackExt.getExtendedPointId());
264: String activated = Language.getInstance()
265: .getText("Inactif");
266: if (plgMgr.isPluginActivated(bTrackExt
267: .getDeclaringPluginDescriptor())) {
268: activated = Language.getInstance().getText("Actif");
269: }
270:
271: row.add(4, activated);
272: pluginsTableModel.addRow(row);
273: extensions.put(bTrackExt.getParameter("name")
274: .valueAsString()
275: + bTrackExt.getExtendedPointId(), bTrackExt);
276:
277: }
278:
279: // ReqManager Plugins
280: for (int i = 0; i < reqMgrExtensions.size(); i++) {
281: ArrayList row = new ArrayList(5);
282: Extension reqMgrExt = (Extension) reqMgrExtensions
283: .elementAt(i);
284: row
285: .add(0, reqMgrExt.getDeclaringPluginDescriptor()
286: .getId());
287: row.add(1, reqMgrExt.getId());
288: row.add(2, reqMgrExt.getParameter(
289: Language.getInstance().getText("description"))
290: .valueAsString());
291: row.add(3, reqMgrExt.getExtendedPointId());
292: String activated = Language.getInstance()
293: .getText("Inactif");
294: if (plgMgr.isPluginActivated(reqMgrExt
295: .getDeclaringPluginDescriptor())) {
296: activated = Language.getInstance().getText("Actif");
297: }
298:
299: row.add(4, activated);
300: pluginsTableModel.addRow(row);
301: extensions.put(reqMgrExt.getParameter("name")
302: .valueAsString()
303: + reqMgrExt.getExtendedPointId(), reqMgrExt);
304:
305: }
306:
307: return pluginsTableModel;
308: }
309:
310: public void actionPerformed(ActionEvent e) {
311: Object source = e.getSource();
312: if (source.equals(activateButton)) {
313: // activatePerformed(e);
314: } else if (source.equals(freezeButton)) {
315: // freezePerformed(e);
316: }
317: }
318:
319: public void activatePerformed(ActionEvent e) {
320: try {
321: if ((currentPlgID != null) && (currentExt != null)) {
322: JButton button = (JButton) e.getSource();
323: if (button.getText() == Language.getInstance().getText(
324: "Activer")) {
325: SalomeTMFContext.getInstance().jpf
326: .activateExtension(currentExt);
327: activateButton.setText(Language.getInstance()
328: .getText("Desactiver"));
329: for (int i = 0; i < extensions.size(); i++) {
330: if (sorter.getValueAt(i, 0).equals(
331: currentExt.getParameter("name")
332: .valueAsString()))
333: sorter.setValueAt(Language.getInstance()
334: .getText("Actif"), i, 4);
335: }
336: } else if (button.getText() == Language.getInstance()
337: .getText("Desactiver")) {
338: /*
339: pluginMgr.deactivatePlugin(currentPlgID);
340: activateButton.setText("Activer");
341: for (int i=0 ; i<extensions.size() ; i++) {
342: if (sorter.getValueAt(i,0).equals(currentExt.getParameter("name").valueAsString()))
343: sorter.setValueAt("Inactif", i, 3);
344: }*/
345: }
346: }
347: } catch (Exception E) {
348: E.printStackTrace();
349: }
350: }
351:
352: public void freezePerformed(ActionEvent e) {
353: try {
354: if (currentCommonPlg != null) {
355: JButton button = (JButton) e.getSource();
356: if (button.getText() == Language.getInstance().getText(
357: "Geler")) {
358: currentCommonPlg.freeze();
359: freezeButton.setText(Language.getInstance()
360: .getText("Degeler"));
361: } else if (button.getText() == Language.getInstance()
362: .getText("Degeler")) {
363: currentCommonPlg.unFreeze();
364: freezeButton.setText(Language.getInstance()
365: .getText("Geler"));
366: }
367: }
368: } catch (Exception E) {
369: E.printStackTrace();
370: }
371: }
372:
373: public void refreshPluginsActivation() {
374: for (int row = 0; row < sorter.getRowCount(); row++) {
375: if (pluginMgr.isPluginActivated(pluginMgr.getRegistry()
376: .getPluginDescriptor(
377: sorter.getValueAt(row, 0).toString()))) {
378: sorter.setValueAt(Language.getInstance().getText(
379: "Actif"), row, 4);
380: } else {
381: sorter.setValueAt(Language.getInstance().getText(
382: "Inactif"), row, 4);
383: }
384: }
385: }
386:
387: public void valueChanged(ListSelectionEvent e) {
388: if (e.getSource().equals(pluginsTable.getSelectionModel())) {
389: //pluginsTableValueChanged(e);
390: }
391: }
392:
393: public void pluginsTableValueChanged(ListSelectionEvent e) {
394: try {
395: if (e.getValueIsAdjusting())
396: return;
397:
398: selectedRow = pluginsTable.getSelectedRow();
399: if (selectedRow != -1) {
400: activateButton.setEnabled(true);
401: currentPlgID = sorter.getValueAt(selectedRow, 0)
402: .toString();
403: currentExt = (Extension) extensions.get(currentPlgID
404: + sorter.getValueAt(selectedRow, 3).toString());
405: //String activated = "Inactif";
406:
407: if (sorter.getValueAt(selectedRow, 4).equals(
408: Language.getInstance().getText("Actif"))) {
409: activateButton.setText(Language.getInstance()
410: .getText("Desactiver"));
411:
412: if (sorter.getValueAt(selectedRow, 3).equals(
413: Language.getInstance().getText("Common"))) {
414: Common common = (Common) pluginMgr
415: .getPlugin(currentPlgID);
416: currentCommonPlg = common;
417:
418: if (common.isFreezable()) {
419: freezeButton.setEnabled(true);
420: if (!common.isFreezed()) {
421: freezeButton
422: .setText(Language.getInstance()
423: .getText("Geler"));
424: } else {
425: freezeButton.setText(Language
426: .getInstance().getText(
427: "Degeler"));
428: }
429: } else {
430: freezeButton.setEnabled(false);
431: }
432: } else {
433: freezeButton.setEnabled(false);
434: }
435: } else {
436: freezeButton.setEnabled(false);
437: activateButton.setText(Language.getInstance()
438: .getText("Activer"));
439: }
440: } else {
441: activateButton.setEnabled(false);
442: freezeButton.setEnabled(false);
443: }
444: } catch (Exception E) {
445: E.printStackTrace();
446: }
447:
448: }
449:
450: }
|