001: package org.objectweb.salome_tmf.ihm.main;
002:
003: import java.awt.BorderLayout;
004: import java.awt.Dimension;
005: import java.awt.FlowLayout;
006: import java.awt.Font;
007: import java.awt.event.ActionEvent;
008: import java.awt.event.ActionListener;
009: import java.util.Vector;
010:
011: import javax.swing.BorderFactory;
012: import javax.swing.JButton;
013: import javax.swing.JLabel;
014: import javax.swing.JPanel;
015: import javax.swing.JScrollPane;
016: import javax.swing.JTable;
017:
018: import org.objectweb.salome_tmf.api.Api;
019: import org.objectweb.salome_tmf.api.data.ExecutionAttachmentWrapper;
020: import org.objectweb.salome_tmf.api.data.LockInfoWrapper;
021: import org.objectweb.salome_tmf.api.sql.ISQLPersonne;
022: import org.objectweb.salome_tmf.api.sql.ISQLSalomeLock;
023: import org.objectweb.salome_tmf.ihm.languages.Language;
024: import org.objectweb.salome_tmf.ihm.models.MyTableModel;
025:
026: public class SalomeLocksPanel extends JPanel implements ActionListener {
027:
028: JTable locksTable;
029:
030: MyTableModel locksTableModel;
031:
032: JButton deletelockButton;
033: JButton deleteAlllocksButton;
034: JButton refreshlocksButton;
035:
036: ISQLSalomeLock pSQLlock;
037: ISQLPersonne pSQLPersone;
038:
039: Vector locksVector;
040:
041: int project_id = -1;
042:
043: public SalomeLocksPanel(int project_id) {
044: super (new BorderLayout());
045: this .project_id = project_id;
046: initComponent();
047: }
048:
049: void initComponent() {
050: locksTableModel = new MyTableModel();
051: locksTable = new JTable();
052:
053: deletelockButton = new JButton(Language.getInstance().getText(
054: "Supprimer"));
055: deletelockButton.addActionListener(this );
056:
057: deleteAlllocksButton = new JButton(Language.getInstance()
058: .getText("Supprimer_tous_les_locks"));
059: deleteAlllocksButton.addActionListener(this );
060:
061: refreshlocksButton = new JButton(Language.getInstance()
062: .getText("Actualiser"));
063: refreshlocksButton.addActionListener(this );
064:
065: locksTableModel.addColumnNameAndColumn("PID");
066: locksTableModel.addColumnNameAndColumn(Language.getInstance()
067: .getText("Login"));
068: locksTableModel.addColumnNameAndColumn(Language.getInstance()
069: .getText("Lock_Type"));
070: locksTableModel.addColumnNameAndColumn(Language.getInstance()
071: .getText("Action_Code"));
072: locksTableModel.addColumnNameAndColumn(Language.getInstance()
073: .getText("Date"));
074:
075: locksTable.setModel(locksTableModel);
076:
077: locksTable.setPreferredScrollableViewportSize(new Dimension(
078: 500, 200));
079: JScrollPane tablePane = new JScrollPane(locksTable);
080:
081: JPanel buttonSet = new JPanel(new FlowLayout());
082: buttonSet.setAlignmentY(FlowLayout.LEFT);
083: buttonSet.add(refreshlocksButton);
084: buttonSet.add(deletelockButton);
085: buttonSet.add(deleteAlllocksButton);
086: buttonSet.setBorder(BorderFactory.createRaisedBevelBorder());
087:
088: JLabel locksTableLabel = new JLabel(Language.getInstance()
089: .getText("Liste_des_locks_existantes"));
090: locksTableLabel.setFont(new Font(null, Font.BOLD, 20));
091: locksTableLabel.setSize(300, 60);
092:
093: JLabel noteLabel = new JLabel(Language.getInstance().getText(
094: "locks_types_precisions"));
095: Language.getInstance().getText("Liste_des_locks_existantes");
096: JPanel notePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
097: notePanel.add(noteLabel);
098:
099: JPanel center = new JPanel(new BorderLayout());
100: center.add(BorderLayout.NORTH, locksTableLabel);
101: center.add(BorderLayout.CENTER, tablePane);
102: center.add(notePanel, BorderLayout.SOUTH);
103: center.setBorder(BorderFactory
104: .createEmptyBorder(20, 10, 10, 10));
105: this .add(BorderLayout.NORTH, buttonSet);
106: this .add(BorderLayout.CENTER, center);
107: pSQLlock = Api.getISQLObjectFactory().getISQLSalomeLock();
108: pSQLPersone = Api.getISQLObjectFactory().getISQLPersonne();
109: }
110:
111: public void loadDataFromDB() {
112: //On crée une instance pour les méthodes de sélection
113: //pISQLlock = Api.getISQLObjectFactory().getISQLSalomeLock();
114: if (pSQLlock != null) {
115: refreshData();
116: }
117: }
118:
119: public void actionPerformed(ActionEvent e) {
120: if (e.getSource().equals(deletelockButton)) {
121: try {
122: int selectedRow = locksTable.getSelectedRow();
123: if (selectedRow != -1) {
124: Integer value = (Integer) locksTableModel
125: .getValueAt(selectedRow, 0);
126: deleteLock(value.intValue());
127: }
128: } catch (Exception ex) {
129: }
130:
131: } else if (e.getSource().equals(deleteAlllocksButton)) {
132: deleteAllSession();
133: } else if (e.getSource().equals(refreshlocksButton)) {
134: refreshData();
135: }
136: }
137:
138: void deleteLock(int pid) {
139: try {
140: if (pSQLlock != null) {
141: pSQLlock.delete(project_id, pid);
142: refreshData();
143: }
144: } catch (Exception e) {
145: }
146:
147: }
148:
149: void deleteAllSession() {
150: try {
151: if (pSQLlock != null) {
152: pSQLlock.delete(project_id);
153: refreshData();
154: }
155: } catch (Exception e) {
156: }
157: }
158:
159: void refreshData() {
160: try {
161: LockInfoWrapper[] tmpArray = pSQLlock
162: .getAllProjectLocks(project_id);
163: Vector tmpVector = new Vector();
164: for (int i = 0; i < tmpArray.length; i++) {
165: tmpVector.add(tmpArray[i]);
166: }
167: locksVector = tmpVector;
168: locksTableModel.clearTable();
169: int nbData = locksVector.size();
170: for (int i = 0; i < nbData; i++) {
171: LockInfoWrapper pLockInfo = (LockInfoWrapper) locksVector
172: .elementAt(i);
173:
174: int lock_type = pLockInfo.getLock_code();
175: int test = lock_type / 100;
176: if (test == 1)
177: lock_type -= 100;
178: int camp = lock_type / 10;
179: if (camp == 1)
180: lock_type -= 10;
181: int data = lock_type;
182: String lockTypeStr = new String("[T=" + test + ", C="
183: + camp + ", D=" + data + "]");
184:
185: String login = "unknow";
186: if (pSQLPersone != null) {
187: login = pSQLPersone.getLogin(pLockInfo
188: .getPersonne_id());
189: }
190: locksTableModel.addValueAt(new Integer(pLockInfo
191: .getPid()), i, 0);
192: locksTableModel.addValueAt(login, i, 1);
193: locksTableModel.addValueAt(lockTypeStr, i, 2);
194: locksTableModel.addValueAt(new Integer(pLockInfo
195: .getAction_code()), i, 3);
196: locksTableModel.addValueAt(pLockInfo.getLockdate(), i,
197: 4);
198: }
199: } catch (Exception ex) {
200: ex.printStackTrace();
201: }
202: }
203:
204: }
|