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.Color;
028: import java.awt.Component;
029: import java.awt.Container;
030: import java.awt.Dimension;
031: import java.awt.FlowLayout;
032: import java.awt.Font;
033: import java.awt.Frame;
034: import java.awt.GridLayout;
035: import java.awt.event.ActionEvent;
036: import java.awt.event.ActionListener;
037: import java.awt.event.WindowEvent;
038: import java.awt.event.WindowListener;
039:
040: import javax.swing.BorderFactory;
041: import javax.swing.BoxLayout;
042: import javax.swing.DefaultComboBoxModel;
043: import javax.swing.JButton;
044: import javax.swing.JCheckBox;
045: import javax.swing.JComboBox;
046: import javax.swing.JDialog;
047: import javax.swing.JLabel;
048: import javax.swing.JOptionPane;
049: import javax.swing.JPanel;
050: import javax.swing.JScrollPane;
051: import javax.swing.JTextField;
052: import javax.swing.JTextPane;
053:
054: import org.objectweb.salome_tmf.data.AdminVTData;
055: import org.objectweb.salome_tmf.data.Project;
056: import org.objectweb.salome_tmf.data.User;
057: import org.objectweb.salome_tmf.ihm.languages.Language;
058: import org.objectweb.salome_tmf.ihm.models.UserListRenderer;
059:
060: /**
061: * Classe qui permet d'afficher une fenêtre demandant d'entrer les
062: * informations pour un nouveau projet.
063: * @author teaml039
064: * @version 0.1
065: */
066: public class AskNewProject extends JDialog {
067:
068: /**
069: * le nouveau projet
070: */
071: private Project project;
072:
073: /**
074: * Champ pour récupérer le nom du projet
075: */
076: private JTextField projetNameTextField;
077:
078: /**
079: * Modèle de données pour la liste des utilisateurs pouvant être admin
080: */
081: private DefaultComboBoxModel comboModel;
082:
083: /**
084: * La description du projet
085: */
086: private JTextPane descriptionArea;
087:
088: /**
089: * La liste des utilisateurs pouvant être admin
090: */
091: JComboBox adminNameComboBox;
092:
093: DefaultComboBoxModel comboModelForProjects;
094:
095: JCheckBox oldOrNewProject;
096:
097: JComboBox fromProjetNameComboBox;
098:
099: JCheckBox testListChoice;
100: JCheckBox testCampagneChoice;
101: JCheckBox usersChoice;
102: JCheckBox groupsChoice;
103:
104: JScrollPane descriptionScrollPane;
105:
106: JLabel dataToBeCopied;
107:
108: JLabel fromProjectNameLabel;
109:
110: JLabel newProjectNameLabel;
111:
112: boolean fromProjet;
113:
114: String fromProjectName;
115:
116: boolean fromProjetGroups;
117: boolean fromProjectUsers;
118: boolean fromProjectCampaigns;
119: boolean fromProjectSuites;
120:
121: boolean newProject = false;
122: String oldProjectName = "";
123:
124: /******************************************************************************/
125: /** CONSTRUCTEUR ***/
126: /******************************************************************************/
127:
128: /**
129: * Constructeur de la fenêtre permettant d'entrer un nouveau projet
130: *
131: */
132: public AskNewProject(Project oldProject, Frame owner) {
133:
134: super (owner, true);
135:
136: if (oldProject == null) {
137: newProject = true;
138: } else {
139: oldProjectName = oldProject.getName();
140: }
141:
142: projetNameTextField = new JTextField(20);
143: comboModel = new DefaultComboBoxModel();
144: descriptionArea = new JTextPane();
145: adminNameComboBox = new JComboBox(comboModel);
146: // Partie supérieure
147: JLabel adminNameLabel = new JLabel(Language.getInstance()
148: .getText("Administrateur_du_projet"));
149:
150: adminNameComboBox.setRenderer(new UserListRenderer());
151: for (int i = 0; i < AdminVTData.getAllUsersCount(); i++) {
152: comboModel.addElement(AdminVTData.getAllUsers().get(i));
153: }
154:
155: JPanel adminPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
156: adminPanel.add(adminNameLabel);
157: adminPanel.add(adminNameComboBox);
158: adminPanel.setBorder(BorderFactory.createRaisedBevelBorder());
159:
160: JLabel newProjectLabel = new JLabel(Language.getInstance()
161: .getText("Nouveau_Projet"));
162: newProjectLabel.setFont(new Font(null, Font.BOLD, 18));
163: newProjectNameLabel = new JLabel(Language.getInstance()
164: .getText("Nom_du_nouveau_projet_:"));
165:
166: JPanel newProjectNamePanel = new JPanel(new FlowLayout(
167: FlowLayout.LEFT));
168: newProjectNamePanel.add(newProjectNameLabel);
169: newProjectNamePanel.add(projetNameTextField);
170:
171: descriptionArea.setPreferredSize(new Dimension(100, 150));
172: descriptionScrollPane = new JScrollPane(descriptionArea,
173: JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
174: JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
175: descriptionScrollPane.setBorder(BorderFactory
176: .createTitledBorder(BorderFactory
177: .createLineBorder(Color.BLACK), Language
178: .getInstance().getText("Description")));
179:
180: JPanel newProjectPanel = new JPanel();
181: newProjectPanel.setLayout(new BoxLayout(newProjectPanel,
182: BoxLayout.Y_AXIS));
183: newProjectPanel.add(newProjectLabel);
184: newProjectPanel.add(newProjectNamePanel);
185: newProjectPanel.add(descriptionScrollPane);
186: newProjectPanel.setBorder(BorderFactory
187: .createRaisedBevelBorder());
188:
189: // Partie inférieure
190:
191: JLabel copyLabel = new JLabel(Language.getInstance().getText(
192: "Copier_à_partir_d'un_projet_existant"));
193: copyLabel.setFont(new Font(null, Font.BOLD, 18));
194: fromProjectNameLabel = new JLabel(Language.getInstance()
195: .getText("A_partir_du_projet_:"));
196: fromProjectNameLabel.setEnabled(false);
197:
198: comboModelForProjects = new DefaultComboBoxModel();
199:
200: fromProjetNameComboBox = new JComboBox(comboModelForProjects);
201: fromProjetNameComboBox.setEnabled(false);
202: dataToBeCopied = new JLabel(Language.getInstance().getText(
203: "Données_à_copier_:"));
204: dataToBeCopied.setEnabled(false);
205:
206: JPanel fromProjectNamePanelData = new JPanel(new FlowLayout(
207: FlowLayout.LEFT));
208: fromProjectNamePanelData.add(fromProjectNameLabel);
209: fromProjectNamePanelData.add(fromProjetNameComboBox);
210:
211: oldOrNewProject = new JCheckBox();
212: oldOrNewProject.addActionListener(new ActionListener() {
213: public void actionPerformed(ActionEvent e) {
214: if (oldOrNewProject.isSelected()) {
215: fromProjetNameComboBox.setEnabled(true);
216: testListChoice.setEnabled(true);
217: testCampagneChoice.setEnabled(true);
218: usersChoice.setEnabled(true);
219: groupsChoice.setEnabled(true);
220: dataToBeCopied.setEnabled(true);
221: fromProjectNameLabel.setEnabled(true);
222: } else {
223: fromProjetNameComboBox.setEnabled(false);
224: testListChoice.setEnabled(false);
225: testCampagneChoice.setEnabled(false);
226: usersChoice.setEnabled(false);
227: groupsChoice.setEnabled(false);
228: dataToBeCopied.setEnabled(false);
229: fromProjectNameLabel.setEnabled(false);
230: }
231: }
232: });
233:
234: JPanel oldPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
235: oldPanel.add(copyLabel);
236: oldPanel.add(oldOrNewProject);
237:
238: JPanel names = new JPanel(new GridLayout(0, 1));
239: names.setAlignmentX(Component.LEFT_ALIGNMENT);
240: //names.add(copyLabel);
241: names.add(oldPanel);
242: names.add(fromProjectNamePanelData);
243:
244: ///////////////////////////////////////////
245:
246: testListChoice = new JCheckBox(Language.getInstance().getText(
247: "Suites_de_test"));
248: testListChoice.setEnabled(false);
249: testCampagneChoice = new JCheckBox(Language.getInstance()
250: .getText("Campagnes_de_test"));
251: testCampagneChoice.setEnabled(false);
252: usersChoice = new JCheckBox(Language.getInstance().getText(
253: "Utilisateurs"));
254: usersChoice.setEnabled(false);
255: groupsChoice = new JCheckBox(Language.getInstance().getText(
256: "Groupes"));
257: groupsChoice.setEnabled(false);
258:
259: JPanel checkPanel = new JPanel(new GridLayout(0, 1));
260: checkPanel.add(testListChoice);
261: checkPanel.add(testCampagneChoice);
262: checkPanel.add(usersChoice);
263: checkPanel.add(groupsChoice);
264:
265: JPanel dataPanel = new JPanel(new GridLayout(1, 0));
266: dataPanel.add(dataToBeCopied);
267: dataPanel.add(checkPanel);
268:
269: ///////////////////////////////////////////
270: JButton validation = new JButton(Language.getInstance()
271: .getText("Valider"));
272: validation.setToolTipText(Language.getInstance().getText(
273: "Valider"));
274: validation.addActionListener(new ActionListener() {
275: public void actionPerformed(ActionEvent e) {
276: if (projetNameTextField.getText().trim() != null
277: && !projetNameTextField.getText().trim()
278: .equals("")) {
279: if ((!AdminVTData
280: .containsProject(projetNameTextField
281: .getText().trim()))
282: || (oldProjectName
283: .equals(projetNameTextField
284: .getText().trim()))) {
285: if (adminNameComboBox.getSelectedItem() != null) {
286: if (oldOrNewProject.isSelected()) {
287: fromProjet = true;
288: if (testListChoice.isSelected())
289: fromProjectSuites = true;
290: if (testCampagneChoice.isSelected())
291: fromProjectCampaigns = true;
292: if (usersChoice.isSelected())
293: fromProjectUsers = true;
294: if (groupsChoice.isSelected())
295: fromProjetGroups = true;
296: fromProjectName = fromProjetNameComboBox
297: .getSelectedItem().toString();
298: }
299: project.setName(projetNameTextField
300: .getText().trim());
301: project
302: .setAdministrator((User) adminNameComboBox
303: .getSelectedItem());
304: project.setDescription(descriptionArea
305: .getText());
306: AskNewProject.this .dispose();
307: } else {
308: JOptionPane
309: .showMessageDialog(
310: AskNewProject.this ,
311: Language
312: .getInstance()
313: .getText(
314: "Il_faut_obligatoirement_nommer_un_administrateur_au_projet_!"),
315: Language
316: .getInstance()
317: .getText(
318: "Attention_!"),
319: JOptionPane.WARNING_MESSAGE);
320: }
321: } else {
322: JOptionPane
323: .showMessageDialog(
324: AskNewProject.this ,
325: Language
326: .getInstance()
327: .getText(
328: "Ce_nom_de_projet_existe_déjà_!"),
329: Language.getInstance().getText(
330: "Attention_!"),
331: JOptionPane.WARNING_MESSAGE);
332: }
333: } else {
334: JOptionPane
335: .showMessageDialog(
336: AskNewProject.this ,
337: Language
338: .getInstance()
339: .getText(
340: "Il_faut_obligatoirement_donner_un_nom_au_projet_!"),
341: Language.getInstance().getText(
342: "Attention_!"),
343: JOptionPane.WARNING_MESSAGE);
344: }
345: }
346: });
347:
348: JButton cancel = new JButton(Language.getInstance().getText(
349: "Annuler"));
350: cancel
351: .setToolTipText(Language.getInstance().getText(
352: "Annuler"));
353: cancel.addActionListener(new ActionListener() {
354: public void actionPerformed(ActionEvent e) {
355: project = null;
356: AskNewProject.this .dispose();
357: }
358: });
359:
360: JPanel buttonsSet = new JPanel(new FlowLayout(FlowLayout.RIGHT));
361: buttonsSet.add(validation);
362: buttonsSet.add(cancel);
363:
364: // Assemblage des composants
365:
366: JPanel copyPanel = new JPanel(new BorderLayout());
367: copyPanel.add(BorderLayout.NORTH, names);
368: copyPanel.add(BorderLayout.CENTER, dataPanel);
369: //copyPanel.add(BorderLayout.SOUTH, buttonsSet);
370: copyPanel.setBorder(BorderFactory.createRaisedBevelBorder());
371:
372: JPanel upPanel = new JPanel();
373: upPanel.setLayout(new BoxLayout(upPanel, BoxLayout.Y_AXIS));
374: if (newProject)
375: upPanel.add(adminPanel);
376:
377: upPanel.add(newProjectPanel);
378:
379: JPanel allPanel = new JPanel();
380: allPanel.setLayout(new BoxLayout(allPanel, BoxLayout.Y_AXIS));
381: allPanel.add(upPanel);
382: if (newProject)
383: allPanel.add(copyPanel);
384:
385: allPanel.add(buttonsSet);
386:
387: Container contentPane = this .getContentPane();
388: contentPane.add(allPanel, BorderLayout.CENTER);
389:
390: initData(oldProject);
391:
392: this .addWindowListener(new WindowListener() {
393: public void windowClosing(WindowEvent e) {
394: project = null;
395:
396: }
397:
398: public void windowDeiconified(WindowEvent e) {
399: }
400:
401: public void windowOpened(WindowEvent e) {
402: }
403:
404: public void windowActivated(WindowEvent e) {
405: }
406:
407: public void windowDeactivated(WindowEvent e) {
408: }
409:
410: public void windowClosed(WindowEvent e) {
411: }
412:
413: public void windowIconified(WindowEvent e) {
414: }
415: });
416:
417: if (oldProject != null) {
418: this .setTitle(Language.getInstance().getText(
419: "Modifier_un_projet"));
420: } else {
421: this .setTitle(Language.getInstance().getText(
422: "Créer_un_nouveau_projet"));
423: }
424: this .pack();
425: this .setLocation(300, 100);
426: this .setVisible(true);
427: this .setResizable(false);
428: } // Fin du constructeur NewProject/0
429:
430: /******************************************************************************/
431: /** ACCESSEURS ET MUTATEURS ***/
432: /******************************************************************************/
433:
434: /**
435: * Retourne le projet créé
436: * @return le projet créé
437: */
438: public Project getProject() {
439: return project;
440: } // Fin de la méthode getProject/0
441:
442: private void initData(Project oldProject) {
443: if (oldProject != null) {
444: project = oldProject;
445: projetNameTextField.setText(oldProject.getName());
446: descriptionArea.setText(oldProject.getDescription());
447: User u = oldProject.getAdministrator();
448: comboModel.setSelectedItem(u);
449: adminNameComboBox.setSelectedItem(u);
450: } else {
451: project = new Project();
452: }
453: for (int j = 0; j < AdminVTData.getProjectList().size(); j++) {
454: comboModelForProjects.addElement(AdminVTData
455: .getProjectList().get(j));
456: }
457: //boolean fromProjet = false;
458:
459: //String fromProjectName = "";
460:
461: //boolean fromProjetGroups = false;
462: //boolean fromProjectUsers = false;
463: //boolean fromProjectCampaigns = false;
464: //boolean fromProjectSuites = false;
465:
466: }
467:
468: /**
469: * @return
470: */
471: public boolean isFromProjectCampaigns() {
472: return fromProjectCampaigns;
473: }
474:
475: /**
476: * @return
477: */
478: public String getFromProjectName() {
479: return fromProjectName;
480: }
481:
482: /**
483: * @return
484: */
485: public boolean isFromProjectSuites() {
486: return fromProjectSuites;
487: }
488:
489: /**
490: * @return
491: */
492: public boolean isFromProjectUsers() {
493: return fromProjectUsers;
494: }
495:
496: /**
497: * @return
498: */
499: public boolean isFromProjet() {
500: return fromProjet;
501: }
502:
503: /**
504: * @return
505: */
506: public boolean isFromProjetGroups() {
507: return fromProjetGroups;
508: }
509:
510: } //Fin de la classe NewProject
|