001: package org.objectweb.salome_tmf.ihm.main;
002:
003: import java.awt.GraphicsConfiguration;
004: import java.awt.GraphicsDevice;
005: import java.awt.GraphicsEnvironment;
006: import java.awt.Point;
007: import java.awt.Rectangle;
008: import java.awt.event.ActionEvent;
009: import java.awt.event.ActionListener;
010: import java.awt.event.WindowAdapter;
011: import java.awt.event.WindowEvent;
012:
013: import javax.swing.JDialog;
014:
015: import org.objectweb.salome_tmf.api.Api;
016: import org.objectweb.salome_tmf.api.JavaScriptUtils;
017: import org.objectweb.salome_tmf.api.Util;
018: import org.objectweb.salome_tmf.ihm.common.CommonLogin;
019: import org.objectweb.salome_tmf.ihm.languages.Language;
020:
021: public class ProjectLogin extends JDialog implements ActionListener {
022:
023: CommonLogin pCommonLogin;
024: String usedLocale = "";
025: String strProjet = null;
026: String strUser = null;
027: String strPassword = null;
028: JavaScriptUtils pJWS;
029:
030: ProjectLogin(JavaScriptUtils pJWS) {
031: setModal(true);
032: this .pJWS = pJWS;
033: pCommonLogin = new CommonLogin(true, false, false, this );
034: setTitle("SalomeTMF Login");
035: initComponents();
036: }
037:
038: public void actionPerformed(ActionEvent e) {
039: if (e.getActionCommand()
040: .equals(CommonLogin.ACTION_START_SALOME)) {
041: if (pCommonLogin.validPassword()) {
042: try {
043: usedLocale = pCommonLogin.getUsedLocal();
044: Api.saveLocale(usedLocale);
045: strProjet = pCommonLogin.getSelectedSalomeProject();
046: strUser = pCommonLogin.getSelectedSalomeUser()
047: .getLogin();
048: strPassword = pCommonLogin.getPassword();
049:
050: setVisible(false);
051: } catch (Exception me) {
052: Util.log("[LoginSalomeTMF->b_startActionPerformed]"
053: + me);
054: }
055: } else {
056: strProjet = null;
057: strUser = null;
058: pCommonLogin.error(Language.getInstance().getText(
059: "Mot_de_passe_invalide"));
060: }
061: }
062: }
063:
064: public String getSelectedProject() {
065: return strProjet;
066: }
067:
068: public String getSelectedUser() {
069: return strUser;
070: }
071:
072: public String getSelectedPassword() {
073: return strPassword;
074: }
075:
076: private void initComponents() {
077:
078: try {
079: GraphicsEnvironment ge = GraphicsEnvironment
080: .getLocalGraphicsEnvironment();
081: GraphicsDevice[] gs = ge.getScreenDevices();
082: GraphicsDevice gd = gs[0];
083: GraphicsConfiguration[] gc = gd.getConfigurations();
084: Rectangle r = gc[0].getBounds();
085: Point pt = new Point(r.width / 2, r.height / 2);
086: Point loc = new Point(pt.x - 200, pt.y - 150);
087:
088: // Affichage
089: setLocation(loc);
090: } catch (Exception e) {
091:
092: }
093:
094: setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
095: addWindowListener(new WindowAdapter() {
096: public void windowClosing(WindowEvent we) {
097: if (pJWS != null) {
098: pJWS.closeWindow();
099: dispose();
100: } else {
101: System.exit(0);
102: }
103: }
104: });
105:
106: setContentPane(pCommonLogin);
107: pack();
108:
109: }
110:
111: /*
112: Vector porjectsList;
113: Vector usersProject;
114:
115: Vector languages = new Vector();
116:
117: ISQLProject pISQLProject;
118: ISQLPersonne pISQLPersonne;
119:
120: boolean init;
121: String proj;
122:
123:
124: JTabbedPane pJTabbedPane;
125:
126:
127:
128:
129:
130: ProjectLogin(){
131: setModal(true);
132: setTitle("SalomeTMF Login");
133:
134: connectToAPI();
135: initData();
136: initComponents();
137: init = true;
138: initList();
139: init = false;
140: }
141:
142: void connectToAPI(){;
143:
144: pISQLProject = Api.getISQLObjectFactory().getISQLProject();
145: pISQLPersonne = Api.getISQLObjectFactory().getISQLPersonne();
146: usedLocale = Api.getUsedLocale();
147: Util.log("[LoginSalomeTMF->connectToAPI] Used Local is "+ usedLocale);
148: Language.getInstance().setLocale(new Locale(usedLocale));
149: languages = Api.getLocales();
150: Util.log("[LoginSalomeTMF->connectToAPI] Available Languages is "+ languages);
151: if (languages == null){
152: Util.log("[LoginSalomeTMF->connectToAPI] Set default languages list to fr");
153: languages = new Vector();
154: languages.add("fr");
155: }
156: }
157:
158:
159:
160:
161:
162: void initData(){
163: try {
164: porjectsList = pISQLProject.getAllProjects();
165: Util.log("[LoginSalomeTMF->initData] Projects list is "+ porjectsList);
166: if (porjectsList.size()>0) {
167: ProjectWrapper pProjectWrapper = (ProjectWrapper) porjectsList.elementAt(0);
168: usersProject = pISQLProject.getUsersOfProject(pProjectWrapper.getName());
169: Util.log("[LoginSalomeTMF->initData] Users Project list is "+ usersProject + ", for project "+ pProjectWrapper.getName());
170: } else {
171: usersProject = new Vector();
172: }
173:
174: } catch (Exception e ){
175: Util.log("[LoginSalomeTMF->initData]" + e);
176: porjectsList = null;
177: }
178: }
179:
180: private void error(String err){
181: javax.swing.JOptionPane.showMessageDialog(this,
182: err,
183: Language.getInstance().getText("Authentification"),
184: javax.swing.JOptionPane.ERROR_MESSAGE);
185:
186: }
187:
188: private void projectChange(ProjectWrapper pProjectWrapper){
189: String project = pProjectWrapper.getName();
190: proj = project;
191: if (!init){
192: try {
193: proj = project;
194: //users = db_AdminVT.getAllUserOfProject(proj);
195:
196: usersProject = pISQLProject.getUsersOfProject(project);
197:
198:
199: user_List.removeAllItems();
200:
201: //Enumeration e = users.keys();
202: Enumeration e = usersProject.elements();
203: while (e.hasMoreElements() ) {
204: Object pUser = e.nextElement();
205: Util.log("[LoginSalomeTMF->projectChange] add user_List " + pUser);
206: user_List.addItem(pUser);
207: }
208: } catch (Exception e ){
209:
210: }
211: }
212: }
213:
214:
215:
216: private UserWrapper getUser(){
217: return (UserWrapper) user_List.getSelectedItem();
218: }
219:
220:
221: private boolean validPassword(){
222: //String paswd = (String) users.get(getUser());
223: String paswd = getUser().getPassword();
224: String typed_paswd = new String(password_Field.getPassword());
225: if (paswd != null){
226: try {
227: return org.objectweb.salome_tmf.api.MD5paswd.testPassword(typed_paswd, paswd);
228: }catch(Exception e){
229: Util.log("[LoginSalomeTMF->validPassword]"+ e);
230: }
231: }
232: return false;
233: }
234:
235:
236:
237:
238: private void initList(){
239: project_List.removeAllItems();
240:
241: user_List.removeAllItems();
242:
243: languages_List.removeAllItems();
244: user_List.removeAllItems();
245: for (int i = 0 ; i < porjectsList.size(); i++) {
246: project_List.addItem(porjectsList.elementAt(i));
247:
248: }
249:
250: Enumeration e = usersProject.elements();
251: while (e.hasMoreElements() ) {
252: Object pUser = e.nextElement();
253: Util.log("[LoginSalomeTMF->initList] add user_List " + pUser);
254: user_List.addItem(pUser);
255: }
256:
257: for(int j=0 ; j < languages.size() ; j++) {
258:
259: languages_List.addItem(((String)languages.elementAt(j)).trim());
260: }
261: //languages_List.setSelectedItem(new Locale(Api.LOCALE).getDisplayName());
262: languages_List.setSelectedItem(usedLocale);
263:
264: }
265:
266:
267: private void initComponents() {
268:
269: try {
270: GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
271: GraphicsDevice[] gs = ge.getScreenDevices();
272: GraphicsDevice gd = gs[0];
273: GraphicsConfiguration[] gc = gd.getConfigurations();
274: Rectangle r = gc[0].getBounds();
275: Point pt = new Point( r.width/2, r.height/2 );
276: Point loc = new Point( pt.x - 200, pt.y - 150 );
277:
278: // Affichage
279: setLocation(loc);
280: } catch (Exception e){
281:
282: }
283: pJTabbedPane = new JTabbedPane();
284: jPanel4 = new javax.swing.JPanel();
285: jPanel1 = new javax.swing.JPanel();
286: jLabel2 = new javax.swing.JLabel();
287: jLabel3 = new javax.swing.JLabel();
288: jLabel4 = new javax.swing.JLabel();
289: project_List = new javax.swing.JComboBox();
290: user_List = new javax.swing.JComboBox();
291: password_Field = new javax.swing.JPasswordField();
292: password_Field.addKeyListener(new passwordKeyListener(0));
293:
294: jPanel2 = new javax.swing.JPanel();
295: jLabel1 = new javax.swing.JLabel();
296: jPanel3 = new javax.swing.JPanel();
297: b_start = new javax.swing.JButton();
298:
299: jPanel14 = new javax.swing.JPanel();
300: jPanel16 = new javax.swing.JPanel();
301: jPanel19 = new javax.swing.JPanel();
302: jLabel15 = new javax.swing.JLabel();
303: jPanel17 = new javax.swing.JPanel();
304: jLabel13 = new javax.swing.JLabel();
305: jLabel14 = new javax.swing.JLabel();
306: jLabel16 = new javax.swing.JLabel();
307: jLabel17 = new javax.swing.JLabel();
308: languages_List = new javax.swing.JComboBox();
309: jLabel19 = new javax.swing.JLabel();
310: jPanel18 = new javax.swing.JPanel();
311: jLabel9 = new javax.swing.JLabel();
312: jLabel18 = new javax.swing.JLabel();
313:
314:
315: pJTabbedPane.setBackground(new java.awt.Color(255, 255, 255));
316: pJTabbedPane.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(1, 1, 1, 1)));
317: pJTabbedPane.setForeground(new java.awt.Color(255, 102, 0));
318: pJTabbedPane.setOpaque(true);
319:
320: jPanel4.setLayout(new java.awt.BorderLayout());
321:
322: jPanel4.setBackground(new java.awt.Color(255, 255, 255));
323: jPanel4.setForeground(new java.awt.Color(51, 51, 51));
324: jPanel1.setLayout(new java.awt.GridLayout(2, 3, 10, 0));
325:
326: jPanel1.setBackground(new java.awt.Color(255, 255, 255));
327: jPanel1.setForeground(new java.awt.Color(51, 51, 51));
328: jLabel2.setBackground(new java.awt.Color(255, 255, 255));
329: jLabel2.setText(Language.getInstance().getText("Projet"));
330: jLabel2.setOpaque(true);
331: jPanel1.add(jLabel2);
332:
333: jLabel3.setBackground(new java.awt.Color(255, 255, 255));
334: jLabel3.setText(Language.getInstance().getText("Utilisateur"));
335: jLabel3.setOpaque(true);
336: jPanel1.add(jLabel3);
337:
338: jLabel4.setBackground(new java.awt.Color(255, 255, 255));
339: jLabel4.setText(Language.getInstance().getText("Mot_de_passe"));
340: jLabel4.setOpaque(true);
341: jPanel1.add(jLabel4);
342:
343: project_List.setBackground(new java.awt.Color(255, 204, 0));
344: project_List.setName("l_projet");
345: project_List.addActionListener(new java.awt.event.ActionListener() {
346: public void actionPerformed(java.awt.event.ActionEvent evt) {
347: project_ListActionPerformed(evt);
348: }
349: });
350: project_List.addItemListener(new java.awt.event.ItemListener() {
351: public void itemStateChanged(java.awt.event.ItemEvent evt) {
352: project_ListItemStateChanged(evt);
353: }
354: });
355:
356: jPanel1.add(project_List);
357:
358: user_List.setBackground(new java.awt.Color(255, 204, 0));
359: user_List.addItemListener(new java.awt.event.ItemListener() {
360: public void itemStateChanged(java.awt.event.ItemEvent evt) {
361: user_ListItemStateChanged(evt);
362: }
363: });
364:
365: jPanel1.add(user_List);
366:
367: jPanel1.add(password_Field);
368:
369: jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER);
370:
371: jPanel2.setBackground(new java.awt.Color(255, 255, 255));
372: jPanel2.setForeground(new java.awt.Color(51, 51, 51));
373: jLabel1.setBackground(new java.awt.Color(255, 255, 255));
374: jLabel1.setFont(new java.awt.Font("Dialog", 1, 24));
375: jLabel1.setText(Language.getInstance().getText("Se_connecter_à_Salom\u00e9_TMF"));
376: jPanel2.add(jLabel1);
377:
378: jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH);
379:
380: jPanel3.setBackground(new java.awt.Color(255, 255, 255));
381: jPanel3.setForeground(new java.awt.Color(51, 51, 51));
382: b_start.setText(Language.getInstance().getText("Démarrer_Salom\u00e9_TMF"));
383: b_start.addActionListener(new java.awt.event.ActionListener() {
384: public void actionPerformed(java.awt.event.ActionEvent evt) {
385: b_startActionPerformed(evt);
386: }
387: });
388:
389: jPanel3.add(b_start);
390:
391: jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH);
392:
393: pJTabbedPane.addTab(Language.getInstance().getText("Démarrer_Salom\u00e9_TMF"), jPanel4);
394:
395:
396:
397:
398:
399: jPanel14.setLayout(new java.awt.BorderLayout());
400:
401: jPanel14.setBackground(new java.awt.Color(255, 255, 255));
402: jPanel16.setLayout(new java.awt.BorderLayout());
403:
404: jPanel16.setBackground(new java.awt.Color(255, 255, 255));
405: jPanel19.setBackground(new java.awt.Color(255, 255, 255));
406: jLabel15.setBackground(new java.awt.Color(255, 255, 255));
407: jLabel15.setFont(new java.awt.Font("Dialog", 1, 24));
408: jLabel15.setText(Language.getInstance().getText("Choissisez_votre_langue_:"));
409: jPanel19.add(jLabel15);
410:
411: jPanel16.add(jPanel19, java.awt.BorderLayout.NORTH);
412:
413: jPanel17.setLayout(new java.awt.GridLayout(2, 3, 10, 0));
414:
415: jPanel17.setBackground(new java.awt.Color(255, 255, 255));
416: jPanel17.setForeground(new java.awt.Color(51, 51, 51));
417: jPanel17.add(jLabel13);
418:
419: jLabel14.setText(Language.getInstance().getText("Langue_:"));
420: jPanel17.add(jLabel14);
421:
422: jPanel17.add(jLabel16);
423:
424: jPanel17.add(jLabel17);
425:
426: languages_List.setBackground(new java.awt.Color(255, 204, 0));
427: jPanel17.add(languages_List);
428:
429: jPanel17.add(jLabel19);
430:
431: jPanel16.add(jPanel17, java.awt.BorderLayout.CENTER);
432:
433: jPanel18.setBackground(new java.awt.Color(255, 255, 255));
434: jPanel18.setPreferredSize(new java.awt.Dimension(15, 33));
435: jPanel18.add(jLabel9);
436:
437: jPanel18.add(jLabel18);
438:
439: jPanel16.add(jPanel18, java.awt.BorderLayout.SOUTH);
440:
441: jPanel14.add(jPanel16, java.awt.BorderLayout.CENTER);
442:
443: pJTabbedPane.addTab(Language.getInstance().getText("Langues"), jPanel14);
444:
445: setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
446: addWindowListener(new WindowAdapter() {
447: public void windowClosing(WindowEvent we) {
448: System.exit(0);
449: }
450: });
451:
452: setContentPane(pJTabbedPane);
453: pack();
454:
455: }//GEN-END:initComponents
456:
457:
458:
459:
460: private void project_ListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_project_ListActionPerformed
461: // TODO add your handling code here:
462: }//GEN-LAST:event_project_ListActionPerformed
463:
464: private void project_ListItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_project_ListItemStateChanged
465: // TODO add your handling code here:
466: projectChange((ProjectWrapper) evt.getItem());
467: }//GEN-LAST:event_project_ListItemStateChanged
468:
469: private void user_ListItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_user_ListItemStateChanged
470: // TODO add your handling code here:
471: }//GEN-LAST:event_user_ListItemStateChanged
472:
473: private void b_startActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_startActionPerformed
474: // TODO add your handling code here:
475: if (validPassword()) {
476: try {
477: usedLocale = ((String)languages_List.getSelectedItem()).trim();
478: Api.saveLocale(usedLocale);
479: strProjet = proj;
480: strUser = getUser().getLogin();
481: setVisible(false);
482: } catch (Exception me) {
483: Util.log("[LoginSalomeTMF->b_startActionPerformed]" + me);
484: }
485: }else {
486: strProjet = null;
487: strUser = null;
488: error(Language.getInstance().getText("Mot_de_passe_invalide"));
489: }
490: }//GEN-LAST:event_b_startActionPerformed
491:
492:
493: // Variables declaration - do not modify//GEN-BEGIN:variables
494: private javax.swing.JButton b_start;
495:
496:
497: private javax.swing.JLabel jLabel1;
498: private javax.swing.JLabel jLabel13;
499: private javax.swing.JLabel jLabel14;
500: private javax.swing.JLabel jLabel15;
501: private javax.swing.JLabel jLabel16;
502: private javax.swing.JLabel jLabel17;
503: private javax.swing.JLabel jLabel18;
504: private javax.swing.JLabel jLabel19;
505: private javax.swing.JLabel jLabel2;
506: private javax.swing.JLabel jLabel3;
507: private javax.swing.JLabel jLabel4;
508: private javax.swing.JLabel jLabel9;
509: private javax.swing.JPanel jPanel1;
510: private javax.swing.JPanel jPanel14;
511: private javax.swing.JPanel jPanel16;
512: private javax.swing.JPanel jPanel17;
513: private javax.swing.JPanel jPanel18;
514: private javax.swing.JPanel jPanel19;
515: private javax.swing.JPanel jPanel2;
516: private javax.swing.JPanel jPanel3;
517: private javax.swing.JPanel jPanel4;
518:
519:
520:
521:
522:
523:
524:
525: private javax.swing.JComboBox languages_List;
526: private javax.swing.JPasswordField password_Field;
527:
528: private javax.swing.JComboBox project_List;
529:
530: private javax.swing.JComboBox user_List;
531:
532:
533:
534: class passwordKeyListener implements KeyListener {
535: int paswdType = -1;
536:
537: passwordKeyListener(int t){
538: paswdType = t;
539: }
540:
541: public void keyTyped(KeyEvent ke){
542:
543: }
544:
545: public void keyPressed(KeyEvent ke){
546:
547: }
548:
549: public void keyReleased(KeyEvent ke){
550: if (ke.getKeyCode() == KeyEvent.VK_ENTER){
551: if (paswdType == 0){
552: b_startActionPerformed(null);
553: }
554: }
555: }
556: }
557: */
558: }
|