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