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