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.Container;
028: import java.awt.Dimension;
029: import java.awt.event.ActionEvent;
030: import java.awt.event.ActionListener;
031: import java.util.ArrayList;
032:
033: import javax.swing.BorderFactory;
034: import javax.swing.Box;
035: import javax.swing.BoxLayout;
036: import javax.swing.DefaultComboBoxModel;
037: import javax.swing.DefaultListModel;
038: import javax.swing.Icon;
039: import javax.swing.JButton;
040: import javax.swing.JComboBox;
041: import javax.swing.JDialog;
042: import javax.swing.JList;
043: import javax.swing.JPanel;
044: import javax.swing.JScrollPane;
045: import javax.swing.ListSelectionModel;
046: import javax.swing.event.ListSelectionEvent;
047: import javax.swing.event.ListSelectionListener;
048:
049: import org.objectweb.salome_tmf.data.Action;
050: import org.objectweb.salome_tmf.ihm.datawrapper.DataModel;
051: import org.objectweb.salome_tmf.ihm.languages.Language;
052: import org.objectweb.salome_tmf.ihm.tools.Tools;
053:
054: /**
055: * Classe qui définit la fenêtre pour ordonner les suites de tests
056: * @author teaml039
057: * @version : 0.1
058: */
059: public class ActionOrdering extends JDialog implements IHMConstants {
060:
061: /**
062: * Ancien modèle de données avant organisation
063: */
064: DefaultListModel listModel;
065:
066: JList list;
067: /**
068: * Modèle de données pour le choix
069: */
070: private DefaultComboBoxModel comboModel;
071:
072: /**
073: * Liste déroulante pour le choix des suites ou des tests.
074: */
075: JComboBox choiceComboBox;
076:
077: JButton upButton;
078:
079: JButton downButton;
080:
081: ArrayList workingList;
082:
083: /******************************************************************************/
084: /** CONSTRUCTEUR ***/
085: /******************************************************************************/
086:
087: /**
088: * Constructeur de la fenêtre
089: * @param listModel le modèle de liste
090: */
091: public ActionOrdering(ArrayList listToBeSort) {
092: super (SalomeTMF.ptrFrame, true);
093:
094: comboModel = new DefaultComboBoxModel();
095: choiceComboBox = new JComboBox(comboModel);
096: upButton = new JButton();
097: downButton = new JButton();
098: upButton.setEnabled(false);
099: Icon icon = Tools.createAppletImageIcon(PATH_TO_ARROW_UP_ICON,
100: "");
101: upButton.setIcon(icon);
102: upButton.setToolTipText(Language.getInstance().getText(
103: "Monter_d'un_cran"));
104: upButton.addActionListener(new ActionListener() {
105: public void actionPerformed(ActionEvent e) {
106: int selectedIndex = list.getSelectedIndex();
107: if (selectedIndex != -1) {
108: Object objToGoUp = listModel
109: .getElementAt(selectedIndex);
110: Object objToGoDown = listModel
111: .getElementAt(selectedIndex - 1);
112: try {
113: //BDD
114: ((Action) objToGoUp)
115: .updateOrderInBddAndModel(false);
116:
117: //IHM
118: listModel.setElementAt(objToGoUp,
119: selectedIndex - 1);
120: listModel.setElementAt(objToGoDown,
121: selectedIndex);
122: list.setSelectedIndex(selectedIndex - 1);
123: } catch (Exception exception) {
124: Tools.ihmExceptionView(exception.toString());
125: }
126:
127: }
128: }
129: });
130:
131: icon = Tools.createAppletImageIcon(PATH_TO_ARROW_DOWN_ICON, "");
132: if (listToBeSort.size() < 2) {
133: downButton.setEnabled(false);
134: }
135: downButton.setIcon(icon);
136: downButton.setToolTipText(Language.getInstance().getText(
137: "Descendre_d'un_cran"));
138: downButton.addActionListener(new ActionListener() {
139: public void actionPerformed(ActionEvent e) {
140: int selectedIndex = list.getSelectedIndex();
141: if (selectedIndex != -1) {
142: Object objToGoUp = listModel
143: .getElementAt(selectedIndex + 1);
144: Object objToGoDown = listModel
145: .getElementAt(selectedIndex);
146: try {
147: //BDD
148: ((Action) objToGoDown)
149: .updateOrderInBddAndModel(true);
150:
151: //IHM
152: listModel
153: .setElementAt(objToGoUp, selectedIndex);
154: listModel.setElementAt(objToGoDown,
155: selectedIndex + 1);
156: list.setSelectedIndex(selectedIndex + 1);
157:
158: } catch (Exception exception) {
159: Tools.ihmExceptionView(exception.toString());
160: }
161:
162: }
163: }
164: });
165:
166: JPanel buttonSet = new JPanel();
167: buttonSet.setLayout(new BoxLayout(buttonSet, BoxLayout.Y_AXIS));
168: buttonSet.add(upButton);
169: buttonSet.add(Box.createRigidArea(new Dimension(1, 25)));
170: buttonSet.add(downButton);
171:
172: initData(listToBeSort);
173:
174: list = new JList(listModel);
175: list.setModel(listModel);
176: list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
177: list.setSelectedIndex(0);
178: list.setVisibleRowCount(15);
179: list.setPreferredSize(new Dimension(250, 150));
180: list.addListSelectionListener(new ListSelectionListener() {
181: public void valueChanged(ListSelectionEvent e) {
182: int selectedIndex = list.getSelectedIndex();
183: if (selectedIndex != -1) {
184: if (selectedIndex == 0) {
185: upButton.setEnabled(false);
186: downButton.setEnabled(true);
187: } else if (selectedIndex == listModel.getSize() - 1) {
188: upButton.setEnabled(true);
189: downButton.setEnabled(false);
190: } else {
191: upButton.setEnabled(true);
192: downButton.setEnabled(true);
193: }
194: } else {
195: upButton.setEnabled(false);
196: downButton.setEnabled(false);
197: }
198: }
199: });
200:
201: JScrollPane usersListScrollPane = new JScrollPane(list);
202: usersListScrollPane.setBorder(BorderFactory
203: .createTitledBorder(Language.getInstance().getText(
204: "Actions")));
205:
206: JButton validate = new JButton(Language.getInstance().getText(
207: "Fermer"));
208: validate.setToolTipText(Language.getInstance()
209: .getText("Fermer"));
210: validate.addActionListener(new ActionListener() {
211: public void actionPerformed(ActionEvent e) {
212: workingList.clear();
213: DataModel.getActionTableModel().clearTable();
214: for (int i = 0; i < listModel.size(); i++) {
215: workingList.add(listModel.get(i));
216: DataModel.getActionTableModel()
217: .addValueAt(
218: ((Action) listModel.get(i))
219: .getName(), i, 0);
220: DataModel.getActionTableModel().addValueAt(
221: ((Action) listModel.get(i))
222: .getDescription(), i, 1);
223: DataModel.getActionTableModel().addValueAt(
224: ((Action) listModel.get(i))
225: .getAwaitedResult(), i, 2);
226: DataModel.getActionTableModel().addValueAt(
227: ((Action) listModel.get(i))
228: .getAttachmentMap(), i, 3);
229: }
230: ActionOrdering.this .dispose();
231: }
232: });
233:
234: /*JButton cancel = new JButton("Annuler");
235: cancel.setToolTipText("Annuler");
236: cancel.addActionListener(new ActionListener() {
237: public void actionPerformed(ActionEvent e) {
238: ActionOrdering.this.dispose();
239: }
240: });
241: */
242: JPanel secondButtonSet = new JPanel();
243: secondButtonSet.add(validate);
244: //secondButtonSet.add(cancel);
245:
246: JPanel center = new JPanel();
247: center.add(usersListScrollPane);
248: center.add(buttonSet);
249:
250: JPanel page = new JPanel();
251: page.setLayout(new BoxLayout(page, BoxLayout.Y_AXIS));
252:
253: page.add(center);
254: page.add(secondButtonSet);
255:
256: Container contentPaneFrame = this .getContentPane();
257: contentPaneFrame.add(page, BorderLayout.CENTER);
258:
259: this .setLocation(400, 400);
260: this .setTitle(Language.getInstance().getText("Ordonner"));
261: this .pack();
262: this .setVisible(true);
263:
264: } // Fin du constructeur Ordering/1
265:
266: public void initData(ArrayList list) {
267: listModel = new DefaultListModel();
268: for (int i = 0; i < list.size(); i++) {
269: listModel.addElement(list.get(i));
270: }
271: workingList = list;
272: }
273: } // Fin de la classe ActionOrdering
|