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 Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: /* TODO */
025: /* Rendre accessible aux plugins */
026: /* ex : // Mapping entre composants graphiques et constantes
027: UIComponentsMap.put(UICompCst.ADMIN_PROJECT_MANAGEMENT_BUTTONS_PANEL,buttonSet);
028: */
029:
030: package org.objectweb.salome_tmf.ihm;
031:
032: import java.awt.BorderLayout;
033: import java.awt.Dimension;
034: import java.awt.FlowLayout;
035: import java.awt.Font;
036: import java.awt.event.ActionEvent;
037: import java.awt.event.ActionListener;
038: import java.util.Vector;
039:
040: import javax.swing.BorderFactory;
041: import javax.swing.JButton;
042: import javax.swing.JLabel;
043: import javax.swing.JPanel;
044: import javax.swing.JScrollPane;
045: import javax.swing.JTable;
046:
047: import org.objectweb.salome_tmf.api.Api;
048: import org.objectweb.salome_tmf.api.api2ihm.AdminVT;
049: import org.objectweb.salome_tmf.api.api2ihm.adminVT.AdminVTDelete;
050: import org.objectweb.salome_tmf.api.api2ihm.adminVT.AdminVTSelect;
051: import org.objectweb.salome_tmf.api.wrapper.ConnectionWrapper;
052: import org.objectweb.salome_tmf.data.ConnectionData;
053: import org.objectweb.salome_tmf.ihm.languages.Language;
054: import org.objectweb.salome_tmf.ihm.models.MyTableModel;
055:
056: public class AdminSessionPanel extends JPanel implements ActionListener {
057:
058: JTable sessiontTable;
059:
060: MyTableModel sessionTableModel;
061:
062: JButton refreshSessionButton;
063: JButton deleteSessionButton;
064: JButton deleteAllSessionButton;
065:
066: AdminVTDelete pAdminVTDelete;
067: AdminVTSelect pAdminVTSelect;
068:
069: Vector datasessionTable;
070:
071: public AdminSessionPanel() {
072: super (new BorderLayout());
073: initComponent();
074: }
075:
076: void initComponent() {
077: sessionTableModel = new MyTableModel();
078: sessiontTable = new JTable();
079:
080: deleteSessionButton = new JButton(Language.getInstance()
081: .getText("Supprimer"));
082: deleteSessionButton.addActionListener(this );
083:
084: deleteAllSessionButton = new JButton(Language.getInstance()
085: .getText("Supprimer_les_sessions"));
086: deleteAllSessionButton.addActionListener(this );
087:
088: refreshSessionButton = new JButton(Language.getInstance()
089: .getText("Actualiser"));
090: refreshSessionButton.addActionListener(this );
091:
092: sessionTableModel.addColumnNameAndColumn("Id");
093: sessionTableModel.addColumnNameAndColumn(Language.getInstance()
094: .getText("Projet"));
095: sessionTableModel.addColumnNameAndColumn(Language.getInstance()
096: .getText("Login"));
097: sessionTableModel.addColumnNameAndColumn(Language.getInstance()
098: .getText("Host"));
099: sessionTableModel.addColumnNameAndColumn(Language.getInstance()
100: .getText("Date"));
101: sessionTableModel.addColumnNameAndColumn(Language.getInstance()
102: .getText("Time"));
103:
104: sessiontTable.setModel(sessionTableModel);
105:
106: sessiontTable.setPreferredScrollableViewportSize(new Dimension(
107: 500, 200));
108: JScrollPane tablePane = new JScrollPane(sessiontTable);
109:
110: //loadDataFromDB();
111:
112: JPanel buttonSet = new JPanel(new FlowLayout());
113: buttonSet.setAlignmentY(FlowLayout.LEFT);
114: buttonSet.add(refreshSessionButton);
115: buttonSet.add(deleteSessionButton);
116: buttonSet.add(deleteAllSessionButton);
117: buttonSet.setBorder(BorderFactory.createRaisedBevelBorder());
118:
119: JLabel sessionsTableLabel = new JLabel(Language.getInstance()
120: .getText("Liste_des_sessions_existantes_:_"));
121: sessionsTableLabel.setFont(new Font(null, Font.BOLD, 20));
122: sessionsTableLabel.setSize(300, 60);
123:
124: JPanel center = new JPanel(new BorderLayout());
125: center.add(BorderLayout.NORTH, sessionsTableLabel);
126: center.add(BorderLayout.CENTER, tablePane);
127: center.setBorder(BorderFactory
128: .createEmptyBorder(20, 10, 10, 10));
129: this .add(BorderLayout.NORTH, buttonSet);
130: this .add(BorderLayout.CENTER, center);
131: }
132:
133: public void loadDataFromDB() {
134: // On crée une instance pour les méthodes de sélection
135: AdminVT adminVT = Api.getInstanceOfAdminVT();
136: pAdminVTDelete = adminVT.getAdminVTDelete();
137: pAdminVTSelect = adminVT.getAdminVTSelect();
138: refreshData();
139: }
140:
141: void refreshData() {
142: sessionTableModel.clearTable();
143: datasessionTable = pAdminVTSelect.getAllConnection();
144: int nbData = datasessionTable.size();
145: for (int i = 0; i < nbData; i++) {
146: ConnectionWrapper pConnectionWrapper = (ConnectionWrapper) datasessionTable
147: .elementAt(i);
148: sessionTableModel.addValueAt(new Integer(pConnectionWrapper
149: .getId()), i, 0);
150: sessionTableModel.addValueAt(pConnectionWrapper
151: .getProjectConnected(), i, 1);
152: sessionTableModel.addValueAt(pConnectionWrapper
153: .getLoginConnected(), i, 2);
154: sessionTableModel.addValueAt(pConnectionWrapper
155: .getHostConnected(), i, 3);
156: sessionTableModel.addValueAt(pConnectionWrapper
157: .getDateConnected(), i, 4);
158: sessionTableModel.addValueAt(pConnectionWrapper
159: .getTimeConnected(), i, 5);
160: }
161: }
162:
163: public void actionPerformed(ActionEvent e) {
164: if (e.getSource().equals(deleteSessionButton)) {
165: try {
166: int selectedRow = sessiontTable.getSelectedRow();
167: if (selectedRow != -1) {
168: Integer value = (Integer) sessionTableModel
169: .getValueAt(selectedRow, 0);
170: deleteSession(value.intValue());
171: }
172: } catch (Exception ex) {
173: }
174:
175: } else if (e.getSource().equals(deleteAllSessionButton)) {
176: deleteAllSession();
177: } else if (e.getSource().equals(refreshSessionButton)) {
178: refreshData();
179: }
180: }
181:
182: void deleteSession(int id_session) {
183: if (ConnectionData.isConnected()) {
184: pAdminVTDelete.deleteSession(id_session);
185: if ((Api.getException() != null)
186: && (Api.getException().size() != 0)) {
187: //Exception e = (Exception) Api.getException().elementAt(0);
188: Api.purgeException();
189: } else {
190: refreshData();
191: }
192: }
193: }
194:
195: void deleteAllSession() {
196: if (ConnectionData.isConnected()) {
197: pAdminVTDelete.deleteAllSession();
198: if ((Api.getException() != null)
199: && (Api.getException().size() != 0)) {
200: //Exception e = (Exception) Api.getException().elementAt(0);
201: Api.purgeException();
202: } else {
203: refreshData();
204: }
205: }
206: }
207: }
|