0001: /*
0002: * SalomeTMF is a Test Management Framework
0003: * Copyright (C) 2005 France Telecom R&D
0004: *
0005: * This library is free software; you can redistribute it and/or
0006: * modify it under the terms of the GNU Lesser General Public
0007: * License as published by the Free Software Foundation; either
0008: * version 2 of the License, or (at your option) any later version.
0009: *
0010: * This library is distributed in the hope that it will be useful,
0011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0013: * Lesser General Public License for more details.
0014: *
0015: * You should have received a copy of the GNU Lesser General Public
0016: * License along with this library; if not, write to the Free Software
0017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0018: *
0019: * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
0020: *
0021: * Contact: mikael.marche@rd.francetelecom.com
0022: */
0023:
0024: package org.objectweb.salome_tmf.ihm;
0025:
0026: import java.awt.BorderLayout;
0027: import java.awt.Color;
0028: import java.awt.Container;
0029: import java.awt.Dimension;
0030: import java.awt.FlowLayout;
0031: import java.awt.Font;
0032: import java.awt.Frame;
0033: import java.awt.GridLayout;
0034: import java.awt.event.ActionEvent;
0035: import java.awt.event.ActionListener;
0036: import java.net.MalformedURLException;
0037: import java.net.URL;
0038: import java.sql.Date;
0039: import java.util.ArrayList;
0040: import java.util.HashMap;
0041: import java.util.Hashtable;
0042: import java.util.Locale;
0043: import java.util.Map;
0044: import java.util.Observable;
0045: import java.util.Observer;
0046: import java.util.Vector;
0047:
0048: import javax.swing.BorderFactory;
0049: import javax.swing.Box;
0050: import javax.swing.BoxLayout;
0051: import javax.swing.ButtonGroup;
0052: import javax.swing.JApplet;
0053: import javax.swing.JButton;
0054: import javax.swing.JLabel;
0055: import javax.swing.JOptionPane;
0056: import javax.swing.JPanel;
0057: import javax.swing.JPasswordField;
0058: import javax.swing.JRadioButton;
0059: import javax.swing.JScrollPane;
0060: import javax.swing.JTabbedPane;
0061: import javax.swing.JTable;
0062: import javax.swing.ListSelectionModel;
0063: import javax.swing.LookAndFeel;
0064: import javax.swing.UIManager;
0065: import javax.swing.event.ListSelectionEvent;
0066: import javax.swing.event.ListSelectionListener;
0067:
0068: import org.objectweb.salome_tmf.api.Api;
0069: import org.objectweb.salome_tmf.api.ApiConstants;
0070: import org.objectweb.salome_tmf.api.api2ihm.AdminProject;
0071: import org.objectweb.salome_tmf.api.api2ihm.AdminVT;
0072: import org.objectweb.salome_tmf.data.AdminProjectData;
0073: import org.objectweb.salome_tmf.data.AdminVTData;
0074: import org.objectweb.salome_tmf.data.ConnectionData;
0075: import org.objectweb.salome_tmf.data.Lock;
0076: import org.objectweb.salome_tmf.data.Project;
0077: import org.objectweb.salome_tmf.data.User;
0078: import org.objectweb.salome_tmf.ihm.datawrapper.DataModel;
0079: import org.objectweb.salome_tmf.ihm.languages.Language;
0080: import org.objectweb.salome_tmf.ihm.models.MyTableModel;
0081: import org.objectweb.salome_tmf.ihm.models.ProjectTableCellRenderer;
0082: import org.objectweb.salome_tmf.ihm.tools.Tools;
0083: import org.objectweb.salome_tmf.plugins.JPFManager;
0084:
0085: /**
0086: * Cette classe définit l'écran d'administration de l'outil.
0087: * @author teaml039
0088: */
0089: public class Administration extends JApplet implements ApiConstants,
0090: Observer, IHMConstants {
0091:
0092: boolean problemURL = false;
0093:
0094: /**
0095: * Ancien mot de passe
0096: */
0097: JPasswordField oldPassword;
0098:
0099: /**
0100: * Nouveau mot de passe : premier
0101: */
0102: JPasswordField newPasswordFirst;
0103:
0104: /**
0105: * Nouveau mot de passe : second
0106: */
0107: JPasswordField newPasswordSecond;
0108:
0109: /**
0110: * Les onglets d'administration
0111: */
0112: JTabbedPane tabs;
0113:
0114: /**
0115: * Le panel de la fenêtre dans son ensemble
0116: */
0117: JPanel adminVoiceTesting;
0118:
0119: /**
0120: * Vue pour changer les mots de passe
0121: */
0122: JPanel changePwdView;
0123:
0124: /**
0125: * Vue pour la gestion des projets
0126: */
0127: JPanel projectView;
0128:
0129: /**
0130: * Vue pour la gestion des utilisateurs
0131: */
0132: JPanel usersView;
0133:
0134: /**
0135: * Vue de droite de la fenêtre
0136: */
0137: JPanel adminView;
0138:
0139: /**
0140: * Vue de droite de la fenêtre pour le controle des sessions
0141: */
0142: AdminSessionPanel sessionView;
0143: /**
0144: * Modèle de données de la table des projets
0145: */
0146: MyTableModel projectTableModel;
0147:
0148: /**
0149: * Table des projets
0150: */
0151: JTable projectTable;
0152:
0153: /**
0154: * Modèle de données de la table des utilisateurs
0155: */
0156: MyTableModel usersTableModel;
0157:
0158: /**
0159: * Table des utilisateurs
0160: */
0161: JTable userTable;
0162:
0163: /**
0164: * Bouton pour supprimer un projet
0165: */
0166: JButton deleteProjectButton;
0167:
0168: /**
0169: * Bouton pour la suppression d'un utilisateur
0170: */
0171: JButton deleteUserButton;
0172:
0173: /**
0174: * Bouton pour le changement de mot de passe d'un utilisateur
0175: */
0176: JButton changePwdButton;
0177:
0178: Color normalColor;
0179:
0180: Color freezeColor;
0181:
0182: Color localColor;
0183:
0184: JButton modifyButton;
0185: JButton freezeButton;
0186: JButton modifyUserButton;
0187:
0188: /**
0189: * Mapping between UI components and constants defined in org.objectweb.salome_tmf.ihm.UICompCst
0190: */
0191: static Map UIComponentsMap;
0192:
0193: public static Frame ptrFrame;
0194:
0195: public static Hashtable associatedTestDriver;
0196: public static Hashtable associatedScriptEngine;
0197: public static Hashtable associatedExtension;
0198:
0199: public static JPFManager jpf;
0200:
0201: public static URL urlAdmin = null;
0202:
0203: URL recup;
0204:
0205: /* dbClosed = true if connection to database is close normaly (no reload or back from browser) */
0206: boolean dbClosed = true;
0207: /* reload = true if applet is start again from same JVM (reload or back from browser) */
0208: static boolean reload = false;
0209:
0210: /******************************************************************************/
0211: /** METHODES PUBLIQUES ***/
0212: /******************************************************************************/
0213:
0214: /**
0215: * Méthode d'initialisation de l'applet
0216: */
0217: public void init() {
0218: recup = null;
0219: System.runFinalization();
0220: System.gc();
0221: Api.log("[Administration] init : " + reload);
0222: if (reload) {
0223: Api.closeConnection();
0224: dbClosed = true;
0225: } else {
0226: reload = true;
0227: }
0228: Api.setUrlBase(getDocumentBase());
0229: Language.getInstance().setLocale(
0230: new Locale(Api.getUsedLocale()));
0231: ptrFrame = javax.swing.JOptionPane
0232: .getFrameForComponent(Administration.this );
0233: try {
0234: Class lnfClass = Class.forName(UIManager
0235: .getSystemLookAndFeelClassName());
0236: LookAndFeel newLAF = (LookAndFeel) (lnfClass.newInstance());
0237: UIManager.setLookAndFeel(newLAF);
0238: } catch (Exception exc) {
0239: System.err.println("Error loading L&F: " + exc);
0240: }
0241:
0242: oldPassword = new JPasswordField(20);
0243:
0244: newPasswordFirst = new JPasswordField(20);
0245:
0246: newPasswordSecond = new JPasswordField(20);
0247:
0248: tabs = new JTabbedPane();
0249:
0250: adminVoiceTesting = new JPanel(new BorderLayout());
0251:
0252: changePwdView = new JPanel(new BorderLayout());
0253:
0254: projectView = new JPanel(new BorderLayout());
0255:
0256: usersView = new JPanel(new BorderLayout());
0257:
0258: sessionView = new AdminSessionPanel();
0259:
0260: adminView = new JPanel(new BorderLayout());
0261:
0262: projectTableModel = new MyTableModel();
0263:
0264: usersTableModel = new MyTableModel();
0265:
0266: userTable = new JTable();
0267:
0268: associatedTestDriver = new Hashtable();
0269: associatedScriptEngine = new Hashtable();
0270: associatedExtension = new Hashtable();
0271:
0272: deleteProjectButton = new JButton(Language.getInstance()
0273: .getText("Supprimer"));
0274:
0275: deleteUserButton = new JButton(Language.getInstance().getText(
0276: "Supprimer"));
0277:
0278: changePwdButton = new JButton(Language.getInstance().getText(
0279: "Changer_le_mot_de_passe"));
0280:
0281: normalColor = new Color(204, 255, 204);
0282: freezeColor = new Color(204, 204, 255);
0283: localColor = Color.RED;
0284:
0285: // Mapping between UI components and constants
0286: UIComponentsMap = new HashMap();
0287:
0288: // Onglets
0289: tabs.addTab(Language.getInstance().getText(
0290: "Administration_SalomeTMF"), adminVoiceTesting);
0291: tabs.setPreferredSize(new Dimension(500, 500));
0292:
0293: //Create the radio buttons.
0294: JRadioButton changePwdButton = new JRadioButton(Language
0295: .getInstance().getText("Changer_le_mot_de_passe"));
0296: changePwdButton.addActionListener(new ActionListener() {
0297: public void actionPerformed(ActionEvent e) {
0298: adminView.removeAll();
0299: adminView.add(changePwdView, BorderLayout.CENTER);
0300: adminView.validate();
0301: adminView.repaint();
0302: }
0303: });
0304:
0305: JRadioButton projectButton = new JRadioButton(Language
0306: .getInstance().getText("Gérer_les_projets"));
0307: projectButton.addActionListener(new ActionListener() {
0308: public void actionPerformed(ActionEvent e) {
0309: adminView.removeAll();
0310: adminView.add(projectView, BorderLayout.CENTER);
0311: adminView.validate();
0312: adminView.repaint();
0313: }
0314: });
0315:
0316: JRadioButton usersButton = new JRadioButton(Language
0317: .getInstance().getText("Gérer_les_utilisateurs"));
0318: usersButton.addActionListener(new ActionListener() {
0319: public void actionPerformed(ActionEvent e) {
0320: adminView.removeAll();
0321: adminView.add(usersView, BorderLayout.CENTER);
0322: adminView.validate();
0323: adminView.repaint();
0324: }
0325: });
0326: //***************** Panel de controle des sessions *********************//
0327: JRadioButton sessionButton = new JRadioButton(Language
0328: .getInstance().getText("Gerer_les_sessions"));
0329: sessionButton.addActionListener(new ActionListener() {
0330: public void actionPerformed(ActionEvent e) {
0331: adminView.removeAll();
0332: adminView.add(sessionView, BorderLayout.CENTER);
0333: adminView.validate();
0334: adminView.repaint();
0335: }
0336: });
0337:
0338: //////////////////////////////////////////////////////////////////////////
0339: //On groupe les radiobuttons
0340: ButtonGroup adminButtonGroup = new ButtonGroup();
0341: adminButtonGroup.add(changePwdButton);
0342: adminButtonGroup.add(projectButton);
0343: adminButtonGroup.add(usersButton);
0344: adminButtonGroup.add(sessionButton);
0345:
0346: JPanel radioPanel = new JPanel(new GridLayout(0, 1));
0347: radioPanel.add(Box.createRigidArea(new Dimension(1, 40)));
0348: radioPanel.add(changePwdButton);
0349: radioPanel.add(Box.createRigidArea(new Dimension(1, 40)));
0350: radioPanel.add(projectButton);
0351: radioPanel.add(Box.createRigidArea(new Dimension(1, 40)));
0352: radioPanel.add(usersButton);
0353: radioPanel.add(Box.createRigidArea(new Dimension(1, 40)));
0354: radioPanel.add(sessionButton);
0355:
0356: JPanel testPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
0357: testPanel.add(radioPanel);
0358:
0359: JButton backButton = new JButton(Language.getInstance()
0360: .getText("Quitter"));
0361: backButton.addActionListener(new ActionListener() {
0362: public void actionPerformed(ActionEvent e) {
0363: quit(true);
0364: }
0365: });
0366:
0367: JPanel radioPanelAll = new JPanel(new BorderLayout());
0368: radioPanelAll.add(testPanel);
0369: radioPanelAll.add(backButton, BorderLayout.SOUTH);
0370: radioPanelAll
0371: .setBorder(BorderFactory.createRaisedBevelBorder());
0372:
0373: AdminProjectData.initData();
0374: AdminVTData.initData();
0375: createChangePwdView();
0376: createUsersView();
0377: createProjectView();
0378: adminView.removeAll();
0379:
0380: // On remplit le panel adminVoiceTesting
0381: adminVoiceTesting.add(BorderLayout.WEST, radioPanelAll);
0382: adminVoiceTesting.add(BorderLayout.CENTER, adminView);
0383:
0384: Container cp = this .getContentPane();
0385: cp.add(tabs);
0386:
0387: } // Fin de la méthode init/0
0388:
0389: /**
0390: * Méthode appelée à chaque chargement de la page
0391: */
0392: public void start() {
0393: Api.log("[Administration] start");
0394: if (Api.isAlreadyConnected) {
0395: JOptionPane
0396: .showMessageDialog(
0397: Administration.this ,
0398: Language
0399: .getInstance()
0400: .getText(
0401: "Vous_avez_déjà_une_session_Salomé_ouverte_avec_ce_navigateur.\n")
0402: + Language
0403: .getInstance()
0404: .getText(
0405: "Une_seule_session_est_autorisée_par_navigateur_afin_d'éviter_les_conflits_!"),
0406: Language.getInstance().getText("Erreur_!"),
0407: JOptionPane.ERROR_MESSAGE);
0408: quit(false);
0409: Api.isAlreadyConnected = true;
0410: } else {
0411: //super.start();
0412: Api.openConnection(getDocumentBase());
0413: dbClosed = false;
0414: String[] params = Tools
0415: .chooseProjectAndUser(getDocumentBase());
0416: Api.log("[Administration.start()] conn. with project = "
0417: + params[0]);
0418: Api.log("[Administration.start()] conn. with user = "
0419: + params[1]);
0420: if ((params[0] == null) || (params[0].equals(""))) {
0421: JOptionPane.showMessageDialog(Administration.this ,
0422: Language.getInstance().getText(
0423: "Probleme_dans_l'URL_saisie_!"),
0424: Language.getInstance().getText("Erreur_!"),
0425: JOptionPane.ERROR_MESSAGE);
0426:
0427: ////////// TEST ///////////
0428: // JPF initialization
0429: if (Api.ALLOW_PLUGINS) {
0430: jpf = new JPFManager();
0431: jpf.startJPFInAdmin(this .getDocumentBase(),
0432: UIComponentsMap);
0433: }
0434: ///////////////////////////
0435:
0436: problemURL = true;
0437: //Api.closeConnection();
0438: quit(true);
0439: } else {
0440: initDataVoiceTesting();
0441: Api.addObservers(this );
0442: // JPF initialization
0443: if (Api.ALLOW_PLUGINS) {
0444: jpf = new JPFManager();
0445: jpf.startJPFInAdmin(this .getDocumentBase(),
0446: UIComponentsMap);
0447: }
0448:
0449: urlAdmin = getDocumentBase();
0450: }
0451: }
0452: } // Fin de la méthode start();
0453:
0454: /**
0455: * Méthode qui créer l'écran permettant de changer le mot de passe.
0456: */
0457: public void createChangePwdView() {
0458: adminView.removeAll();
0459:
0460: JButton validateButton = new JButton(Language.getInstance()
0461: .getText("Valider"));
0462: validateButton.setToolTipText(Language.getInstance().getText(
0463: "Valider"));
0464: validateButton.addActionListener(new ActionListener() {
0465: public void actionPerformed(ActionEvent e) {
0466: if (ConnectionData.isConnected()) {
0467: String pass = ConnectionData.getAdminVTSelect()
0468: .getUserPassword(ADMIN_SALOME_NAME);
0469:
0470: boolean _valid = false;
0471: try {
0472: _valid = org.objectweb.salome_tmf.api.MD5paswd
0473: .testPassword(new String(oldPassword
0474: .getPassword()).trim(), pass);
0475: } catch (Exception ex) {
0476: }
0477: if (_valid) {
0478: if (new String(newPasswordFirst.getPassword())
0479: .trim().equals(
0480: new String(newPasswordSecond
0481: .getPassword()).trim())) {
0482: int transNumber = -1;
0483: try {
0484: transNumber = Api
0485: .beginTransaction(Api.UPDATE_PASSWORD);
0486: ConnectionData
0487: .getAdminVTUpdate()
0488: .updateAdminPassword(
0489: ADMIN_SALOME_NAME,
0490: new String(
0491: newPasswordSecond
0492: .getPassword())
0493: .trim());
0494: Api.commitTrans(transNumber);
0495: } catch (Exception exception) {
0496: Api.forceRollBackTrans(transNumber);
0497: Tools.ihmExceptionView(exception
0498: .toString());
0499: }
0500: if (Api.getException() == null
0501: || Api.getException().size() == 0) {
0502: oldPassword.setText("");
0503: newPasswordFirst.setText("");
0504: newPasswordSecond.setText("");
0505: JOptionPane
0506: .showMessageDialog(
0507: Administration.this ,
0508: Language
0509: .getInstance()
0510: .getText(
0511: "Votre_mot_de_passe_a_été_modifié."),
0512: Language
0513: .getInstance()
0514: .getText(
0515: "Succès_!"),
0516: JOptionPane.INFORMATION_MESSAGE);
0517: }
0518:
0519: } else {
0520: newPasswordFirst.setText("");
0521: newPasswordSecond.setText("");
0522: JOptionPane
0523: .showMessageDialog(
0524: Administration.this ,
0525: Language
0526: .getInstance()
0527: .getText(
0528: "Impossible_de_changer_le_mot_de_passe.\nVous_n'avez_pas_entrer_deux_fois_le_même_mot_de_passe."),
0529: Language
0530: .getInstance()
0531: .getText("Erreur_!"),
0532: JOptionPane.ERROR_MESSAGE);
0533: }
0534: } else {
0535: oldPassword.setText("");
0536: JOptionPane
0537: .showMessageDialog(
0538: Administration.this ,
0539: Language
0540: .getInstance()
0541: .getText(
0542: "Impossible_de_changer_le_mot_de_passe.\nL'ancien_mot_de_passe_est_incorrect."),
0543: Language.getInstance().getText(
0544: "Erreur_!"),
0545: JOptionPane.ERROR_MESSAGE);
0546: }
0547: } else {
0548: JOptionPane
0549: .showMessageDialog(
0550: Administration.this ,
0551: Language
0552: .getInstance()
0553: .getText(
0554: "Impossible_de_changer_le_mot_de_passe.\nVous_n'êtes_pas_connecter_à_la_base."),
0555: Language.getInstance().getText(
0556: "Erreur_!"),
0557: JOptionPane.ERROR_MESSAGE);
0558: }
0559: }
0560: });
0561:
0562: JButton cancelButton = new JButton(Language.getInstance()
0563: .getText("Annuler"));
0564: cancelButton.setToolTipText(Language.getInstance().getText(
0565: "Annuler"));
0566: cancelButton.addActionListener(new ActionListener() {
0567: public void actionPerformed(ActionEvent e) {
0568: oldPassword.setText(null);
0569: newPasswordFirst.setText(null);
0570: newPasswordSecond.setText(null);
0571:
0572: }
0573: });
0574:
0575: JLabel oldQuestion = new JLabel(Language.getInstance().getText(
0576: "Entrez_votre_ancien_mot_de_passe_:"));
0577:
0578: JLabel question = new JLabel(Language.getInstance().getText(
0579: "Entrez_votre_nouveau_mot_de_passe_:"));
0580:
0581: JLabel confirmation = new JLabel(Language.getInstance()
0582: .getText("Confirmer_le_nouveau_mot_de_passe_:"));
0583:
0584: JPanel textFieldPane = new JPanel();
0585: textFieldPane.setLayout(new BoxLayout(textFieldPane,
0586: BoxLayout.Y_AXIS));
0587: textFieldPane.add(oldPassword);
0588: textFieldPane.add(Box.createRigidArea(new Dimension(1, 50)));
0589: textFieldPane.add(newPasswordFirst);
0590: textFieldPane.add(Box.createRigidArea(new Dimension(1, 50)));
0591: textFieldPane.add(newPasswordSecond);
0592:
0593: JPanel textPane = new JPanel();
0594: textPane.setLayout(new BoxLayout(textPane, BoxLayout.Y_AXIS));
0595: textPane.add(oldQuestion);
0596: textPane.add(Box.createRigidArea(new Dimension(1, 50)));
0597: textPane.add(question);
0598: textPane.add(Box.createRigidArea(new Dimension(1, 50)));
0599: textPane.add(confirmation);
0600:
0601: JPanel textPaneAll = new JPanel(new FlowLayout(
0602: FlowLayout.CENTER));
0603: textPaneAll.add(textPane);
0604: textPaneAll.add(textFieldPane);
0605:
0606: JPanel buttonPanel = new JPanel(new FlowLayout(
0607: FlowLayout.CENTER));
0608: buttonPanel.add(validateButton);
0609: buttonPanel.add(cancelButton);
0610:
0611: JPanel labelSet = new JPanel();
0612: labelSet.add(textPaneAll);
0613: labelSet.setBorder(BorderFactory.createEmptyBorder(100, 10, 10,
0614: 100));
0615:
0616: changePwdView.setLayout(new BoxLayout(changePwdView,
0617: BoxLayout.Y_AXIS));
0618: changePwdView.add(labelSet);
0619: changePwdView.add(buttonPanel);
0620: changePwdView
0621: .setBorder(BorderFactory.createRaisedBevelBorder());
0622: changePwdView.validate();
0623: } // Fin de la classe createChangePwdView/0
0624:
0625: /**
0626: * Méthode qui permet de créer l'écran permettant de gérer les projets.
0627: *
0628: */
0629: public void createProjectView() {
0630:
0631: adminView.removeAll();
0632:
0633: // Les boutons
0634: JButton createButton = new JButton(Language.getInstance()
0635: .getText("Créer"));
0636: createButton.setToolTipText(Language.getInstance().getText(
0637: "Créer_un_nouveau_projet"));
0638: createButton.addActionListener(new ActionListener() {
0639: public void actionPerformed(ActionEvent e) {
0640: AskNewProject askProject = new AskNewProject(
0641: null,
0642: javax.swing.JOptionPane
0643: .getFrameForComponent(Administration.this ));
0644: ArrayList data = new ArrayList();
0645: if (askProject.getProject() != null) {
0646:
0647: if (ConnectionData.isConnected()) {
0648: int transNumber = -1;
0649: ;
0650: try {
0651: transNumber = Api
0652: .beginTransaction(Api.INSERT_PROJECT);
0653: if (!askProject.isFromProjet()) {
0654: ConnectionData
0655: .getAdminVTInsert()
0656: .addProject(
0657: askProject.getProject()
0658: .getName(),
0659: askProject
0660: .getProject()
0661: .getDescription(),
0662: askProject
0663: .getProject()
0664: .getAdministrator()
0665: .getLogin());
0666: } else {
0667: ConnectionData
0668: .getAdminVTInsert()
0669: .addProject(
0670: askProject.getProject()
0671: .getName(),
0672: askProject
0673: .getProject()
0674: .getDescription(),
0675: askProject
0676: .getProject()
0677: .getAdministrator()
0678: .getLogin(),
0679: askProject
0680: .getFromProjectName(),
0681: askProject
0682: .isFromProjectSuites(),
0683: askProject
0684: .isFromProjectCampaigns(),
0685: askProject
0686: .isFromProjectUsers(),
0687: askProject
0688: .isFromProjetGroups());
0689: }
0690: ConnectionData.getAdminProjectUpdate()
0691: .setProject(
0692: askProject.getProject()
0693: .getName().trim());
0694: int perm = 0;
0695: ConnectionData.getAdminProjectUpdate()
0696: .updatePermission(GUESTNAME, perm);
0697: perm |= AdminProject.ALLOW_CREATE_TEST;
0698: perm |= AdminProject.ALLOW_CREATE_CAMP;
0699: perm |= AdminProject.ALLOW_UPDATE_CAMP;
0700: perm |= AdminProject.ALLOW_UPDATE_TEST;
0701: perm |= AdminProject.ALLOW_EXECUT_CAMP;
0702: ConnectionData.getAdminProjectUpdate()
0703: .updatePermission(DEVNAME, perm);
0704: perm |= AdminProject.ALLOW_DELETE_CAMP;
0705: perm |= AdminProject.ALLOW_DELETE_TEST;
0706: ConnectionData.getAdminProjectUpdate()
0707: .updatePermission(ADMINNAME, perm);
0708: askProject
0709: .getProject()
0710: .setIdBdd(
0711: ConnectionData
0712: .getAdminVTSelect()
0713: .getProjetID(
0714: askProject
0715: .getProject()
0716: .getName()));
0717: Api.commitTrans(transNumber);
0718: } catch (Exception exception) {
0719: Api.forceRollBackTrans(transNumber);
0720: Tools
0721: .ihmExceptionView(exception
0722: .toString());
0723: }
0724: }
0725: if (Api.getException() == null
0726: || Api.getException().size() == 0) {
0727: data.add(Tools.createAppletImageIcon(
0728: PATH_TO_PROJECT_ICON, ""));
0729: data.add(askProject.getProject().getName()
0730: .trim());
0731: data.add(askProject.getProject()
0732: .getAdministrator().getLogin());
0733: data.add(askProject.getProject()
0734: .getCreationDate().toString());
0735: data.add(askProject.getProject()
0736: .getDescription());
0737: projectTableModel.addRow(data);
0738: //TableCellRenderer re = projectTable.getCellRenderer(0,0);
0739: //TableCellRenderer re2 = projectTable.getCellRenderer(0,1);
0740: AdminVTData.addProject(askProject.getProject());
0741: AdminVTData.addAdminToProject(askProject
0742: .getProject().getAdministrator()
0743: .getLogin(), askProject.getProject());
0744: ProjectTableCellRenderer.setColor(normalColor);
0745: projectTable.getColumnModel().getColumn(0)
0746: .setMaxWidth(18);
0747: deleteProjectButton.setEnabled(true);
0748: }
0749: }
0750: }
0751: });
0752:
0753: modifyButton = new JButton(Language.getInstance().getText(
0754: "Modifier"));
0755: modifyButton.setEnabled(false);
0756: modifyButton.setToolTipText(Language.getInstance().getText(
0757: "Modifier_un_projet"));
0758: modifyButton.addActionListener(new ActionListener() {
0759: public void actionPerformed(ActionEvent e) {
0760: int selectedRow = projectTable.getSelectedRow();
0761: if (selectedRow != -1) {
0762: Project project = AdminVTData
0763: .getProject((String) projectTableModel
0764: .getValueAt(selectedRow, 1));
0765: AskNewProject askProject = new AskNewProject(
0766: project,
0767: javax.swing.JOptionPane
0768: .getFrameForComponent(Administration.this ));
0769: if (askProject.getProject() != null) {
0770: if (ConnectionData.isConnected()) {
0771: int transNumber = -1;
0772: try {
0773: transNumber = Api
0774: .beginTransaction(Api.UPDATE_PROJECT);
0775: ConnectionData
0776: .getAdminVTUpdate()
0777: .updateProject(
0778: project.getIdBdd(),
0779: askProject.getProject()
0780: .getName(),
0781: askProject
0782: .getProject()
0783: .getDescription());
0784: Api.commitTrans(transNumber);
0785: } catch (Exception exception) {
0786: Api.forceRollBackTrans(transNumber);
0787: Tools.ihmExceptionView(exception
0788: .toString());
0789: }
0790: }
0791: if (Api.getException() == null
0792: || Api.getException().size() == 0) {
0793: ArrayList data = new ArrayList();
0794: data.add(Tools.createAppletImageIcon(
0795: PATH_TO_PROJECT_ICON, ""));
0796: data.add(askProject.getProject().getName()
0797: .trim());
0798: data.add(askProject.getProject()
0799: .getAdministrator().getLogin());
0800: data.add(askProject.getProject()
0801: .getCreationDate().toString());
0802: data.add(askProject.getProject()
0803: .getDescription());
0804: projectTableModel.modifyData(data,
0805: selectedRow);
0806: AdminVTData
0807: .removeProject(project.getName());
0808: AdminVTData.addProject(askProject
0809: .getProject());
0810: projectTable.getColumnModel().getColumn(0)
0811: .setMaxWidth(18);
0812: }
0813: }
0814: }
0815: }
0816: });
0817:
0818: freezeButton = new JButton(Language.getInstance().getText(
0819: "Geler"));
0820: freezeButton.setEnabled(false);
0821: freezeButton.setToolTipText(Language.getInstance().getText(
0822: "Geler_un_projet"));
0823: freezeButton.addActionListener(new ActionListener() {
0824: public void actionPerformed(ActionEvent e) {
0825: int selectedRow = projectTable.getSelectedRow();
0826: if (selectedRow != -1) {
0827: Project project = AdminVTData
0828: .getProject((String) projectTableModel
0829: .getValueAt(selectedRow, 1));
0830: if (project.getLock() == null) {
0831: ProjectTableCellRenderer.setColor(selectedRow,
0832: freezeColor);
0833: projectTableModel.setValueAt(Tools
0834: .createAppletImageIcon(
0835: PATH_TO_FREEZED_PROJECT_ICON,
0836: ""), selectedRow, 0);
0837: project.setLock(new Lock());
0838: } else {
0839: ProjectTableCellRenderer.setColor(selectedRow,
0840: normalColor);
0841: projectTableModel.setValueAt(Tools
0842: .createAppletImageIcon(
0843: PATH_TO_PROJECT_ICON, ""),
0844: selectedRow, 0);
0845: project.setLock(null);
0846: }
0847: }
0848: }
0849: });
0850:
0851: deleteProjectButton.setToolTipText(Language.getInstance()
0852: .getText("Supprimer_un_projet"));
0853: deleteProjectButton.setEnabled(false);
0854: deleteProjectButton.addActionListener(new ActionListener() {
0855: public void actionPerformed(ActionEvent e) {
0856: int selectedRow = projectTable.getSelectedRow();
0857: if (selectedRow != -1) {
0858: Object[] options = {
0859: Language.getInstance().getText("Oui"),
0860: Language.getInstance().getText("Non") };
0861:
0862: int choice = JOptionPane
0863: .showOptionDialog(
0864: Administration.this ,
0865: Language
0866: .getInstance()
0867: .getText(
0868: "Etes_vous_sûr_de_vouloir_supprimer_le_projet_:_")
0869: + projectTableModel
0870: .getData(
0871: selectedRow)
0872: .get(1), Language
0873: .getInstance().getText(
0874: "Attention_!"),
0875: JOptionPane.YES_NO_OPTION,
0876: JOptionPane.QUESTION_MESSAGE, null,
0877: options, options[1]);
0878: if (choice == JOptionPane.YES_OPTION) {
0879: if (ConnectionData.isConnected()) {
0880: try {
0881: int transNumber = Api
0882: .beginTransaction(Api.DELETE_PROJECT);
0883: ConnectionData
0884: .getAdminVTDelete()
0885: .deleteProjectFromVT(
0886: (String) projectTableModel
0887: .getValueAt(
0888: selectedRow,
0889: 1));
0890: Api.commitTrans(transNumber);
0891: } catch (Exception exception) {
0892: Tools.ihmExceptionView(exception
0893: .toString());
0894: }
0895: }
0896: if (Api.getException() == null
0897: || Api.getException().size() == 0) {
0898: AdminVTData
0899: .removeProject((String) projectTableModel
0900: .getValueAt(selectedRow, 1));
0901: projectTableModel.removeData(selectedRow);
0902: projectTable.getColumnModel().getColumn(0)
0903: .setMaxWidth(18);
0904: if (projectTableModel.getRowCount() == 0) {
0905: deleteProjectButton.setEnabled(false);
0906: }
0907: }
0908: }
0909: }
0910: }
0911: });
0912:
0913: JPanel buttonSet = new JPanel(new FlowLayout());
0914: buttonSet.setAlignmentY(FlowLayout.LEFT);
0915: buttonSet.add(createButton);
0916: buttonSet.add(modifyButton);
0917: buttonSet.add(freezeButton);
0918: buttonSet.add(deleteProjectButton);
0919: buttonSet.setBorder(BorderFactory.createRaisedBevelBorder());
0920: // Mapping entre composants graphiques et constantes
0921: UIComponentsMap.put(
0922: UICompCst.ADMIN_PROJECT_MANAGEMENT_BUTTONS_PANEL,
0923: buttonSet);
0924:
0925: // La table des projets
0926: JLabel projectsTableLabel = new JLabel(Language.getInstance()
0927: .getText("Liste_des_projets_existants_:_"));
0928: projectsTableLabel.setFont(new Font(null, Font.BOLD, 20));
0929: projectsTableLabel.setSize(300, 60);
0930:
0931: projectTableModel.addColumnNameAndColumn("");
0932: projectTableModel.addColumnNameAndColumn(Language.getInstance()
0933: .getText("Nom_du_projet"));
0934: projectTableModel.addColumnNameAndColumn(Language.getInstance()
0935: .getText("Administrateur"));
0936: projectTableModel.addColumnNameAndColumn(Language.getInstance()
0937: .getText("Date_de_création"));
0938: projectTableModel.addColumnNameAndColumn(Language.getInstance()
0939: .getText("Description"));
0940:
0941: projectTable = new JTable();
0942: projectTable.setDefaultRenderer(String.class,
0943: new ProjectTableCellRenderer());
0944: projectTable.setModel(projectTableModel);
0945: projectTable.setPreferredScrollableViewportSize(new Dimension(
0946: 600, 200));
0947: projectTable
0948: .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
0949:
0950: // Mapping between UI components and constants
0951: UIComponentsMap.put(UICompCst.ADMIN_PROJECT_MANAGEMENT_TABLE,
0952: projectTable);
0953:
0954: projectTable.setModel(projectTableModel);
0955:
0956: JScrollPane tablePane = new JScrollPane(projectTable);
0957:
0958: ListSelectionModel rowSMForUserTable = projectTable
0959: .getSelectionModel();
0960: rowSMForUserTable
0961: .addListSelectionListener(new ListSelectionListener() {
0962: public void valueChanged(ListSelectionEvent e) {
0963: int[] selectedRows = projectTable
0964: .getSelectedRows();
0965: if (selectedRows.length > 0) {
0966: if (selectedRows.length == 1) {
0967: modifyButton.setEnabled(true);
0968: } else {
0969: modifyButton.setEnabled(false);
0970: }
0971: deleteProjectButton.setEnabled(true);
0972: freezeButton.setEnabled(true);
0973: } else {
0974: deleteProjectButton.setEnabled(false);
0975: modifyButton.setEnabled(false);
0976: freezeButton.setEnabled(false);
0977: }
0978: }
0979: });
0980:
0981: JPanel center = new JPanel(new BorderLayout());
0982: center.add(BorderLayout.NORTH, projectsTableLabel);
0983: center.add(BorderLayout.CENTER, tablePane);
0984: center.setBorder(BorderFactory
0985: .createEmptyBorder(20, 10, 10, 10));
0986:
0987: projectView.add(BorderLayout.NORTH, buttonSet);
0988: projectView.add(BorderLayout.CENTER, center);
0989:
0990: } // Fin de la classe createProjectView/0
0991:
0992: /**
0993: * Méthode qui permet de créer l'écran permettant de gérer les utilisateurs.
0994: *
0995: */
0996: public void createUsersView() {
0997:
0998: // Les boutons
0999: JButton createButton = new JButton(Language.getInstance()
1000: .getText("Créer"));
1001: createButton.setToolTipText(Language.getInstance().getText(
1002: "Créer_un_nouvel_utilisateur"));
1003: createButton.addActionListener(new ActionListener() {
1004: public void actionPerformed(ActionEvent e) {
1005: AskNewUser askNewUser = new AskNewUser(
1006: null,
1007: javax.swing.JOptionPane
1008: .getFrameForComponent(Administration.this ));
1009: if (askNewUser.getUser() != null) {
1010: if (AdminVTData.containsLogin(askNewUser.getUser()
1011: .getLogin())) {
1012: JOptionPane.showMessageDialog(
1013: Administration.this ,
1014: Language.getInstance().getText(
1015: "Ce_login_existe_déjà_!"),
1016: Language.getInstance().getText(
1017: "Erreur_!"),
1018: JOptionPane.ERROR_MESSAGE);
1019: } else {
1020: if (ConnectionData.isConnected()) {
1021: int transNumber = -1;
1022: try {
1023: transNumber = Api
1024: .beginTransaction(Api.INSERT_USER);
1025: ConnectionData
1026: .getAdminVTInsert()
1027: .addPerson(
1028: askNewUser.getUser()
1029: .getLogin(),
1030: askNewUser.getUser()
1031: .getLastName(),
1032: askNewUser.getUser()
1033: .getFirstName(),
1034: askNewUser
1035: .getUser()
1036: .getDescription(),
1037: askNewUser.getUser()
1038: .getEmail(),
1039: askNewUser
1040: .getUser()
1041: .getPhoneNumber(),
1042: new String(askNewUser
1043: .getPassword()));
1044: askNewUser
1045: .getUser()
1046: .setIdBdd(
1047: ConnectionData
1048: .getAdminVTSelect()
1049: .getPersonID(
1050: askNewUser
1051: .getUser()
1052: .getLogin()));
1053: Api.commitTrans(transNumber);
1054: } catch (Exception exception) {
1055: Api.forceRollBackTrans(transNumber);
1056: Tools.ihmExceptionView(exception
1057: .toString());
1058: }
1059: }
1060: if (Api.getException() == null
1061: || Api.getException().size() == 0) {
1062: ArrayList data = new ArrayList();
1063: data.add(askNewUser.getUser().getLogin());
1064: data
1065: .add(askNewUser.getUser()
1066: .getLastName());
1067: data.add(askNewUser.getUser()
1068: .getFirstName());
1069: data.add(askNewUser.getUser().getEmail());
1070: data.add(askNewUser.getUser()
1071: .getPhoneNumber());
1072: usersTableModel.addRow(data);
1073: AdminVTData.addUser(askNewUser.getUser());
1074: }
1075: }
1076: }
1077:
1078: }
1079: });
1080:
1081: modifyUserButton = new JButton(Language.getInstance().getText(
1082: "Modifier"));
1083: modifyUserButton.setToolTipText(Language.getInstance().getText(
1084: "Modifier_un_utilisateur"));
1085: modifyUserButton.setEnabled(false);
1086: modifyUserButton.addActionListener(new ActionListener() {
1087: public void actionPerformed(ActionEvent e) {
1088: int selectedRow = userTable.getSelectedRow();
1089: if (selectedRow != -1) {
1090: User user = AdminVTData
1091: .getUser((String) usersTableModel
1092: .getValueAt(selectedRow, 0));
1093: AskNewUser askNewUser = new AskNewUser(
1094: user,
1095: javax.swing.JOptionPane
1096: .getFrameForComponent(Administration.this ));
1097: if (askNewUser.getUser() != null) {
1098: if (ConnectionData.isConnected()) {
1099: int transNumber = -1;
1100: try {
1101: transNumber = Api
1102: .beginTransaction(Api.INSERT_USER);
1103: User usr = askNewUser.getUser();
1104: ConnectionData.getAdminVTUpdate()
1105: .updatePerson(user.getIdBdd(),
1106: usr.getLogin(),
1107: usr.getLastName(),
1108: usr.getFirstName(),
1109: usr.getDescription(),
1110: usr.getEmail(),
1111: usr.getPhoneNumber());
1112: Api.commitTrans(transNumber);
1113: } catch (Exception exception) {
1114: Api.forceRollBackTrans(transNumber);
1115: Tools.ihmExceptionView(exception
1116: .toString());
1117: }
1118: }
1119: if (Api.getException() == null
1120: || Api.getException().size() == 0) {
1121: ArrayList data = new ArrayList();
1122: data.add(askNewUser.getUser().getLogin());
1123: data
1124: .add(askNewUser.getUser()
1125: .getLastName());
1126: data.add(askNewUser.getUser()
1127: .getFirstName());
1128: data.add(askNewUser.getUser().getEmail());
1129: data.add(askNewUser.getUser()
1130: .getPhoneNumber());
1131: usersTableModel.modifyData(data,
1132: selectedRow);
1133: AdminVTData.removeUser(user.getLogin());
1134: AdminVTData.addUser(askNewUser.getUser());
1135: }
1136: }
1137: }
1138: }
1139: });
1140:
1141: deleteUserButton.setToolTipText(Language.getInstance().getText(
1142: "Supprimer_un_utilisateur"));
1143: deleteUserButton.setEnabled(false);
1144: deleteUserButton.addActionListener(new ActionListener() {
1145: public void actionPerformed(ActionEvent e) {
1146: int[] selectedRowsTab = userTable.getSelectedRows();
1147: String message = "";
1148: for (int i = selectedRowsTab.length - 1; i >= 0; i--) {
1149: message = message
1150: + " * "
1151: + usersTableModel.getValueAt(
1152: selectedRowsTab[i], 0);
1153: if (i == 0) {
1154: message = message + "?";
1155: } else {
1156: message = message + "\n";
1157: }
1158: }
1159: Object[] options = {
1160: Language.getInstance().getText("Oui"),
1161: Language.getInstance().getText("Non") };
1162: int choice = JOptionPane
1163: .showOptionDialog(
1164: Administration.this ,
1165: Language
1166: .getInstance()
1167: .getText(
1168: "Etes_vous_sûr_de_vouloir_supprimer_les_utilisateurs_:_\n")
1169: + message, Language
1170: .getInstance().getText(
1171: "Attention_!"),
1172: JOptionPane.YES_NO_OPTION,
1173: JOptionPane.QUESTION_MESSAGE, null,
1174: options, options[1]);
1175: if (choice == JOptionPane.YES_OPTION) {
1176: for (int i = selectedRowsTab.length - 1; i >= 0; i--) {
1177: ArrayList projectsList = AdminVTData
1178: .getProjectsWithThisUserAdmin((String) usersTableModel
1179: .getValueAt(selectedRowsTab[i],
1180: 0));
1181: ArrayList prjsWithUsrAsUniqueAdmin = new ArrayList();
1182: if (projectsList.size() > 0) {
1183: message = "";
1184: boolean prjWithUniqueAdmin = false;
1185: for (int k = projectsList.size() - 1; k >= 0; k--) {
1186: if (AdminVTData
1187: .getAdminCount((Project) projectsList
1188: .get(k)) == 1) {
1189: message = message
1190: + " * "
1191: + ((Project) projectsList
1192: .get(k)).getName()
1193: + "\n";
1194: prjsWithUsrAsUniqueAdmin
1195: .add(projectsList.get(k));
1196: prjWithUniqueAdmin = true;
1197: }
1198: }
1199: if (prjWithUniqueAdmin) {
1200: choice = JOptionPane
1201: .showOptionDialog(
1202: Administration.this ,
1203: Language
1204: .getInstance()
1205: .getText(
1206: "L'utilisateur_<")
1207: + (String) usersTableModel
1208: .getValueAt(
1209: selectedRowsTab[i],
1210: 0)
1211: + Language
1212: .getInstance()
1213: .getText(
1214: ">_est_le_seul_administrateur_des_projets_:_\n")
1215: + message
1216: + Language
1217: .getInstance()
1218: .getText(
1219: "Sa_suppression_entrainera_la_suppression_des_projets_dans_leur_ensemble.\nEtes-vous_sûr_de_vouloir_supprimer_cet_utilisateur_?"),
1220: Language
1221: .getInstance()
1222: .getText(
1223: "Attention_!"),
1224: JOptionPane.YES_NO_OPTION,
1225: JOptionPane.QUESTION_MESSAGE,
1226: null, options,
1227: options[1]);
1228: if (choice == JOptionPane.YES_OPTION) {
1229: for (int k = prjsWithUsrAsUniqueAdmin
1230: .size() - 1; k >= 0; k--) {
1231: if (ConnectionData
1232: .isConnected()) {
1233: try {
1234: int transNumber = Api
1235: .beginTransaction(Api.DELETE_PROJECT);
1236: ConnectionData
1237: .getAdminVTDelete()
1238: .deleteProjectFromVT(
1239: ((Project) prjsWithUsrAsUniqueAdmin
1240: .get(k))
1241: .getName());
1242: Api
1243: .commitTrans(transNumber);
1244: } catch (Exception exception) {
1245: Tools
1246: .ihmExceptionView(exception
1247: .toString());
1248: break;
1249: }
1250: }
1251: if (Api.getException() == null
1252: || Api.getException()
1253: .size() == 0) {
1254: AdminVTData
1255: .removeProject((Project) prjsWithUsrAsUniqueAdmin
1256: .get(k));
1257: projectTableModel
1258: .removeData(getIndexOfProject((Project) prjsWithUsrAsUniqueAdmin
1259: .get(k)));
1260: }
1261: }
1262: if (Api.getException() == null
1263: || Api.getException()
1264: .size() == 0) {
1265:
1266: if (ConnectionData
1267: .isConnected()) {
1268: try {
1269: int transNumber = Api
1270: .beginTransaction(Api.DELETE_USER);
1271: ConnectionData
1272: .getAdminVTDelete()
1273: .deleteUserFromVT(
1274: (String) usersTableModel
1275: .getValueAt(
1276: selectedRowsTab[i],
1277: 0));
1278: Api
1279: .commitTrans(transNumber);
1280: } catch (Exception exception) {
1281: Tools
1282: .ihmExceptionView(exception
1283: .toString());
1284: }
1285:
1286: }
1287: if (Api.getException() == null
1288: || Api.getException()
1289: .size() == 0) {
1290: projectTable
1291: .getColumnModel()
1292: .getColumn(0)
1293: .setMaxWidth(18);
1294: AdminVTData
1295: .removeUser((String) usersTableModel
1296: .getValueAt(
1297: selectedRowsTab[i],
1298: 0));
1299: if (usersTableModel
1300: .getRowCount() == 0) {
1301: deleteUserButton
1302: .setEnabled(false);
1303: }
1304: usersTableModel
1305: .removeData(selectedRowsTab[i]);
1306: }
1307: }
1308: }
1309: } else {
1310: if (Api.getException() == null
1311: || Api.getException().size() == 0) {
1312:
1313: if (ConnectionData.isConnected()) {
1314: try {
1315: int transNumber = Api
1316: .beginTransaction(Api.DELETE_USER);
1317: ConnectionData
1318: .getAdminVTDelete()
1319: .deleteUserFromVT(
1320: (String) usersTableModel
1321: .getValueAt(
1322: selectedRowsTab[i],
1323: 0));
1324: Api
1325: .commitTrans(transNumber);
1326: } catch (Exception exception) {
1327: Tools
1328: .ihmExceptionView(exception
1329: .toString());
1330: }
1331:
1332: }
1333: if (Api.getException() == null
1334: || Api.getException()
1335: .size() == 0) {
1336: projectTable.getColumnModel()
1337: .getColumn(0)
1338: .setMaxWidth(18);
1339: AdminVTData
1340: .removeUser((String) usersTableModel
1341: .getValueAt(
1342: selectedRowsTab[i],
1343: 0));
1344: if (usersTableModel
1345: .getRowCount() == 0) {
1346: deleteUserButton
1347: .setEnabled(false);
1348: }
1349: usersTableModel
1350: .removeData(selectedRowsTab[i]);
1351: }
1352: }
1353: }
1354: } else {
1355: if (ConnectionData.isConnected()) {
1356: try {
1357: int transNumber = Api
1358: .beginTransaction(Api.DELETE_USER);
1359:
1360: ConnectionData
1361: .getAdminVTDelete()
1362: .deleteUserFromVT(
1363: (String) usersTableModel
1364: .getValueAt(
1365: selectedRowsTab[i],
1366: 0));
1367: Api.commitTrans(transNumber);
1368: } catch (Exception exception) {
1369: Tools.ihmExceptionView(exception
1370: .toString());
1371: }
1372: }
1373: if (Api.getException() == null
1374: || Api.getException().size() == 0) {
1375: AdminVTData
1376: .removeUser((String) usersTableModel
1377: .getValueAt(
1378: selectedRowsTab[i],
1379: 0));
1380: if (usersTableModel.getRowCount() == 0) {
1381: deleteUserButton.setEnabled(false);
1382: }
1383: usersTableModel
1384: .removeData(selectedRowsTab[i]);
1385: }
1386: }
1387: }
1388: }
1389: }
1390: });
1391:
1392: changePwdButton.setToolTipText(Language.getInstance().getText(
1393: "Changer_le_mot_de_passe"));
1394: changePwdButton.setEnabled(false);
1395: changePwdButton.addActionListener(new ActionListener() {
1396: public void actionPerformed(ActionEvent e) {
1397: AskName askName = new AskName(
1398: Language.getInstance().getText(
1399: "Nouveau_mot_de_passe_:_"),
1400: Language.getInstance().getText(
1401: "Changer_le_mot_de_passe"),
1402: Language.getInstance().getText("passe"),
1403: null,
1404: javax.swing.JOptionPane
1405: .getFrameForComponent(Administration.this ));
1406: if (askName.getResult() != null) {
1407: if (ConnectionData.isConnected()) {
1408: int selectedIndex = userTable.getSelectedRow();
1409: if (selectedIndex != -1) {
1410: try {
1411: int transNumber = Api
1412: .beginTransaction(Api.UPDATE_PASSWORD);
1413: ConnectionData
1414: .getAdminVTUpdate()
1415: .updateAdminPassword(
1416: (String) usersTableModel
1417: .getValueAt(
1418: selectedIndex,
1419: 0),
1420: askName.getResult());
1421: Api.commitTrans(transNumber);
1422: } catch (Exception exception) {
1423: Tools.ihmExceptionView(exception
1424: .toString());
1425: }
1426: }
1427: }
1428: }
1429: }
1430: });
1431:
1432: JPanel buttonSet = new JPanel(new FlowLayout());
1433: buttonSet.setAlignmentY(FlowLayout.LEFT);
1434: buttonSet.add(createButton);
1435: buttonSet.add(modifyUserButton);
1436: buttonSet.add(deleteUserButton);
1437: buttonSet.add(changePwdButton);
1438: buttonSet.setBorder(BorderFactory.createRaisedBevelBorder());
1439:
1440: // La table des projets
1441: JLabel projectsTableLabel = new JLabel(Language.getInstance()
1442: .getText("Liste_des_utilisateurs_:_"));
1443: projectsTableLabel.setFont(new Font(null, Font.BOLD, 20));
1444: projectsTableLabel.setSize(300, 60);
1445:
1446: usersTableModel.addColumnNameAndColumn(Language.getInstance()
1447: .getText("Login"));
1448: usersTableModel.addColumnNameAndColumn(Language.getInstance()
1449: .getText("Nom"));
1450: usersTableModel.addColumnNameAndColumn(Language.getInstance()
1451: .getText("Prénom"));
1452: usersTableModel.addColumnNameAndColumn(Language.getInstance()
1453: .getText("Email"));
1454: usersTableModel.addColumnNameAndColumn(Language.getInstance()
1455: .getText("Téléphone"));
1456:
1457: userTable.setModel(usersTableModel);
1458:
1459: userTable.setPreferredScrollableViewportSize(new Dimension(500,
1460: 200));
1461: JScrollPane tablePane = new JScrollPane(userTable);
1462: userTable
1463: .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
1464:
1465: ListSelectionModel rowSMForUserTable = userTable
1466: .getSelectionModel();
1467: rowSMForUserTable
1468: .addListSelectionListener(new ListSelectionListener() {
1469: public void valueChanged(ListSelectionEvent e) {
1470: int[] selectedRows = userTable
1471: .getSelectedRows();
1472: if (selectedRows.length > 0) {
1473: if (selectedRows.length == 1) {
1474: changePwdButton.setEnabled(true);
1475: modifyUserButton.setEnabled(true);
1476: } else {
1477: changePwdButton.setEnabled(false);
1478: modifyUserButton.setEnabled(false);
1479: }
1480: deleteUserButton.setEnabled(true);
1481: } else {
1482: deleteUserButton.setEnabled(false);
1483: changePwdButton.setEnabled(false);
1484: modifyUserButton.setEnabled(false);
1485: }
1486: }
1487: });
1488:
1489: JPanel center = new JPanel(new BorderLayout());
1490: center.add(BorderLayout.NORTH, projectsTableLabel);
1491: center.add(BorderLayout.CENTER, tablePane);
1492: center.setBorder(BorderFactory
1493: .createEmptyBorder(20, 10, 10, 10));
1494:
1495: usersView.add(BorderLayout.NORTH, buttonSet);
1496: usersView.add(BorderLayout.CENTER, center);
1497: } // Fin de la méthode createUsersView/0
1498:
1499: /**
1500: * Méthode d'initialisation des données à la connection sur la base de
1501: * données.
1502: */
1503: private void initDataVoiceTesting() {
1504: try {
1505: if (ConnectionData.isConnected()) {
1506:
1507: // On crée une instance pour les méthodes de sélection
1508: AdminVT adminVT = Api.getInstanceOfAdminVT();
1509: ConnectionData.setAdminVTSelect(adminVT
1510: .getAdminVTSelect());
1511:
1512: // On cree une instance de la classe pour les methodes d'insertion
1513: ConnectionData.setAdminVTInsert(adminVT
1514: .getAdminVTInsert());
1515:
1516: ConnectionData.setAdminVTDelete(adminVT
1517: .getAdminVTDelete());
1518:
1519: // pour les méthodes update
1520: ConnectionData.setAdminVTUpdate(adminVT
1521: .getAdminVTUpdate());
1522:
1523: // gestion de projet
1524: AdminProject adminProject = Api
1525: .getInstanceOfAdminProject();
1526: adminProject.setUser(ADMIN_SALOME_NAME);
1527:
1528: ConnectionData.setAdminProjectInsert(adminProject
1529: .getAdminProjectInsert());
1530:
1531: ConnectionData.setAdminProjectUpdate(adminProject
1532: .getAdminProjectUpdate());
1533:
1534: ConnectionData.setAdminProjectSelect(adminProject
1535: .getAdminProjectSelect());
1536:
1537: // Initialisation des données pour les utilisateurs
1538:
1539: Vector logins = ConnectionData.getAdminVTSelect()
1540: .getAllVTUsersLogin();
1541:
1542: Vector names = ConnectionData.getAdminVTSelect()
1543: .getAllVTUsersName();
1544: Vector firstNames = ConnectionData.getAdminVTSelect()
1545: .getAllVTUsersFirstName();
1546: Vector phones = ConnectionData.getAdminVTSelect()
1547: .getAllVTUsersTel();
1548: Vector emails = ConnectionData.getAdminVTSelect()
1549: .getAllVTUsersEmail();
1550: //Vector creationDates = ConnectionData.getAdminVTSelect().getAllVTUsersDate();
1551: Vector descriptions = ConnectionData.getAdminVTSelect()
1552: .getAllVTUsersDesc();
1553: usersTableModel.clearTable();
1554: AdminVTData.getAllUsers().clear();
1555: if (names != null)
1556: usersTableModel.addDataColumn(logins, 0);
1557: if (names != null)
1558: usersTableModel.addDataColumn(names, 1);
1559: if (firstNames != null)
1560: usersTableModel.addDataColumn(firstNames, 2);
1561: if (emails != null)
1562: usersTableModel.addDataColumn(emails, 3);
1563: if (phones != null)
1564: usersTableModel.addDataColumn(phones, 4);
1565: for (int i = 0; i < logins.size(); i++) {
1566: User user = new User();
1567: user.setIdBdd(ConnectionData.getAdminVTSelect()
1568: .getPersonID((String) logins.get(i)));
1569: user.setLogin((String) logins.get(i));
1570: user.setFirstName((String) firstNames.get(i));
1571: user.setLastName((String) names.get(i));
1572: if (descriptions != null) {
1573: user.setDescription((String) descriptions
1574: .get(i));
1575: } else {
1576: user.setDescription("");
1577: }
1578: if (phones != null) {
1579: user.setPhoneNumber((String) phones.get(i));
1580: } else {
1581: user.setPhoneNumber("");
1582: }
1583: user.setEmail((String) emails.get(i));
1584: AdminVTData.addUser(user);
1585: }
1586:
1587: // Initialisation des données pour les projets
1588:
1589: Vector projectNames = ConnectionData.getAdminVTSelect()
1590: .getAllVTProjectsName();
1591:
1592: Vector projectDescs = ConnectionData.getAdminVTSelect()
1593: .getAllVTProjectsDesc();
1594: Vector projectDate = ConnectionData.getAdminVTSelect()
1595: .getAllVTProjectsDate();
1596: Vector projectAdminLogins = ConnectionData
1597: .getAdminVTSelect().getAllProjectsAdminLogin();
1598: projectTableModel.clearTable();
1599: if (projectNames != null) {
1600: projectTableModel.addDataColumn(projectNames, 1);
1601: }
1602: if (projectAdminLogins != null)
1603: projectTableModel.addDataColumn(projectAdminLogins,
1604: 2);
1605: if (projectDate != null)
1606: projectTableModel.addDataColumn(projectDate, 3);
1607: if (projectDescs != null) {
1608: projectTableModel.addDataColumn(projectDescs, 4);
1609: }
1610:
1611: for (int j = 0; j < projectNames.size(); j++) {
1612: Project project = new Project();
1613: project.setIdBdd(ConnectionData.getAdminVTSelect()
1614: .getProjetID((String) projectNames.get(j)));
1615: project.setName((String) projectNames.get(j));
1616: project
1617: .setDescription((String) projectDescs
1618: .get(j));
1619: project.setCreationDate((Date) projectDate.get(j));
1620: project
1621: .setAdministrator(AdminVTData
1622: .getUser((String) projectAdminLogins
1623: .get(j)));
1624: projectTableModel.addValueAt(Tools
1625: .createAppletImageIcon(
1626: PATH_TO_PROJECT_ICON, ""), j, 0);
1627:
1628: //TableCellRenderer re = projectTable.getCellRenderer(0,0);
1629: //TableCellRenderer re2 = projectTable.getCellRenderer(0,1);
1630: AdminVTData.addProject(project);
1631: ProjectTableCellRenderer.setColor(normalColor);
1632:
1633: ConnectionData.getAdminProjectSelect().setProject(
1634: project.getName());
1635: Vector userLoginVector = ConnectionData
1636: .getAdminProjectSelect().getGroupUsers(
1637: ADMINNAME);
1638: for (int k = 0; k < userLoginVector.size(); k++) {
1639: AdminVTData.addAdminToProject(
1640: (String) userLoginVector.get(k),
1641: project);
1642: }
1643: }
1644:
1645: projectTable.getColumnModel().getColumn(0).setMaxWidth(
1646: 18);
1647: sessionView.loadDataFromDB();
1648: }
1649:
1650: } catch (NullPointerException npe) {
1651: npe.printStackTrace();
1652: ConnectionData.setConnected(false);
1653: JOptionPane
1654: .showMessageDialog(
1655: Administration.this ,
1656: Language
1657: .getInstance()
1658: .getText(
1659: "Impossible_de_se_connecter_à_la_base_:_on_travaille_en_local_!"),
1660: Language.getInstance().getText("Erreur_!"),
1661: JOptionPane.ERROR_MESSAGE);
1662: }
1663: } // Fin de la méthode initDataVoiceTesting/0
1664:
1665: /**
1666: *
1667: * @param project
1668: * @return
1669: */
1670: public int getIndexOfProject(Project project) {
1671: for (int i = 0; i < projectTableModel.getRowCount(); i++) {
1672: if (projectTableModel.getValueAt(i, 1).equals(
1673: project.getName())) {
1674: return i;
1675: }
1676: }
1677: return -1;
1678: }
1679:
1680: public void update(Observable observable, Object obj) {
1681: if (obj instanceof Vector) {
1682: if (((Vector) obj).size() > 0)
1683: DataModel.apiExceptionView((Vector) obj);
1684: }
1685: }
1686:
1687: public void destroy() {
1688: Api.log("[Administration] Destroy");
1689: Api.isAlreadyConnected = false;
1690: if (ConnectionData.isConnected() && !dbClosed) {
1691: Api.closeConnection();
1692: }
1693: Api.log("[Administration] End Destroy");
1694: }
1695:
1696: public void quit(boolean do_recup) {
1697: Api.log("[Administration] Quit");
1698: if (ConnectionData.isConnected()) {
1699: if (!problemURL) {
1700: String[] tab = getDocumentBase().toString().split(
1701: "[?=]");
1702: int idConn = Integer.parseInt(tab[2]);
1703: Api.deleteConnection(idConn);
1704: }
1705: Api.closeConnection();
1706: dbClosed = true;
1707: }
1708:
1709: try {
1710: if (do_recup) {
1711: /* récupère l'URL à partir du document courant et "page.html" */
1712: recup = new URL(getDocumentBase(), "index.html");
1713: /* Affiche le document après avoir recupérer le contexte courant */
1714: getAppletContext().showDocument(recup);
1715: repaint();
1716: } else {
1717: getAppletContext()
1718: .showDocument(
1719: new URL(
1720: "http://wiki.objectweb.org/salome-tmf"));
1721: }
1722: } catch (MalformedURLException me) {
1723: recup = null;
1724: me.printStackTrace();
1725: }
1726: }
1727:
1728: /**
1729: * Methode qui renvoie l'objet graphique associ? ? une constante
1730: * @return
1731: * @param uiConst
1732: */
1733: public static Object getUIComponent(Integer uiConst) {
1734: Object comp = null;
1735: if (UIComponentsMap != null)
1736: comp = UIComponentsMap.get(uiConst);
1737: return comp;
1738: }
1739: } // Fin de la classe Administration
|