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