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.admin;
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.sql.Time;
039: import java.util.Vector;
040:
041: import javax.swing.BorderFactory;
042: import javax.swing.JButton;
043: import javax.swing.JLabel;
044: import javax.swing.JPanel;
045: import javax.swing.JScrollPane;
046: import javax.swing.JTable;
047:
048: import org.objectweb.salome_tmf.api.Api;
049: import org.objectweb.salome_tmf.api.data.ConnectionWrapper;
050: import org.objectweb.salome_tmf.api.sql.ISQLSession;
051: import org.objectweb.salome_tmf.ihm.languages.Language;
052: import org.objectweb.salome_tmf.ihm.models.MyTableModel;
053:
054: public class AdminSessionPanel extends JPanel implements ActionListener {
055:
056: JTable sessiontTable;
057:
058: MyTableModel sessionTableModel;
059:
060: JButton refreshSessionButton;
061: JButton deleteSessionButton;
062: JButton deleteAllSessionButton;
063:
064: ISQLSession pISQLSession;
065:
066: Vector datasessionTable;
067:
068: public AdminSessionPanel() {
069: super (new BorderLayout());
070: initComponent();
071: }
072:
073: void initComponent() {
074: sessionTableModel = new MyTableModel();
075: sessiontTable = new JTable();
076:
077: deleteSessionButton = new JButton(Language.getInstance()
078: .getText("Supprimer"));
079: deleteSessionButton.addActionListener(this );
080:
081: deleteAllSessionButton = new JButton(Language.getInstance()
082: .getText("Supprimer_les_sessions"));
083: deleteAllSessionButton.addActionListener(this );
084:
085: refreshSessionButton = new JButton(Language.getInstance()
086: .getText("Actualiser"));
087: refreshSessionButton.addActionListener(this );
088:
089: sessionTableModel.addColumnNameAndColumn("Id");
090: sessionTableModel.addColumnNameAndColumn(Language.getInstance()
091: .getText("Projet"));
092: sessionTableModel.addColumnNameAndColumn(Language.getInstance()
093: .getText("Login"));
094: sessionTableModel.addColumnNameAndColumn(Language.getInstance()
095: .getText("Host"));
096: sessionTableModel.addColumnNameAndColumn(Language.getInstance()
097: .getText("Date"));
098: sessionTableModel.addColumnNameAndColumn(Language.getInstance()
099: .getText("Time"));
100:
101: sessiontTable.setModel(sessionTableModel);
102:
103: sessiontTable.setPreferredScrollableViewportSize(new Dimension(
104: 500, 200));
105: JScrollPane tablePane = new JScrollPane(sessiontTable);
106:
107: //loadDataFromDB();
108:
109: JPanel buttonSet = new JPanel(new FlowLayout());
110: buttonSet.setAlignmentY(FlowLayout.LEFT);
111: buttonSet.add(refreshSessionButton);
112: buttonSet.add(deleteSessionButton);
113: buttonSet.add(deleteAllSessionButton);
114: buttonSet.setBorder(BorderFactory.createRaisedBevelBorder());
115:
116: JLabel sessionsTableLabel = new JLabel(Language.getInstance()
117: .getText("Liste_des_sessions_existantes_:_"));
118: sessionsTableLabel.setFont(new Font(null, Font.BOLD, 20));
119: sessionsTableLabel.setSize(300, 60);
120:
121: JPanel center = new JPanel(new BorderLayout());
122: center.add(BorderLayout.NORTH, sessionsTableLabel);
123: center.add(BorderLayout.CENTER, tablePane);
124: center.setBorder(BorderFactory
125: .createEmptyBorder(20, 10, 10, 10));
126: this .add(BorderLayout.NORTH, buttonSet);
127: this .add(BorderLayout.CENTER, center);
128: }
129:
130: public void loadDataFromDB() {
131: // On crée une instance pour les méthodes de sélection
132: pISQLSession = Api.getISQLObjectFactory().getISQLSession();
133: refreshData();
134: }
135:
136: void refreshData() {
137: try {
138: ConnectionWrapper[] tmpArray = pISQLSession.getAllSession();
139: Vector tmpVector = new Vector();
140: for (int i = 0; i < tmpArray.length; i++) {
141: tmpVector.add(tmpArray[i]);
142: }
143:
144: datasessionTable = tmpVector;
145: sessionTableModel.clearTable();
146: int nbData = datasessionTable.size();
147: for (int i = 0; i < nbData; i++) {
148: ConnectionWrapper pConnectionWrapper = (ConnectionWrapper) datasessionTable
149: .elementAt(i);
150: sessionTableModel.addValueAt(new Integer(
151: pConnectionWrapper.getId()), i, 0);
152: sessionTableModel.addValueAt(pConnectionWrapper
153: .getProjectConnected(), i, 1);
154: sessionTableModel.addValueAt(pConnectionWrapper
155: .getLoginConnected(), i, 2);
156: sessionTableModel.addValueAt(pConnectionWrapper
157: .getHostConnected(), i, 3);
158: sessionTableModel.addValueAt(pConnectionWrapper
159: .getDateConnected(), i, 4);
160: sessionTableModel.addValueAt(new Time(
161: pConnectionWrapper.getTimeConnected()), i, 5);
162: }
163: } catch (Exception ex) {
164: }
165: }
166:
167: public void actionPerformed(ActionEvent e) {
168: if (e.getSource().equals(deleteSessionButton)) {
169: try {
170: int selectedRow = sessiontTable.getSelectedRow();
171: if (selectedRow != -1) {
172: Integer value = (Integer) sessionTableModel
173: .getValueAt(selectedRow, 0);
174: deleteSession(value.intValue());
175: }
176: } catch (Exception ex) {
177: }
178:
179: } else if (e.getSource().equals(deleteAllSessionButton)) {
180: deleteAllSession();
181: } else if (e.getSource().equals(refreshSessionButton)) {
182: refreshData();
183: }
184: }
185:
186: void deleteSession(int id_session) {
187: try {
188: pISQLSession.deleteSession(id_session);
189: refreshData();
190: } catch (Exception e) {
191: }
192:
193: }
194:
195: void deleteAllSession() {
196: try {
197: pISQLSession.deleteAllSession();
198: refreshData();
199: } catch (Exception e) {
200: }
201: }
202: }
|