PageRenderTime 2ms CodeModel.GetById 16ms app.highlight 19ms RepoModel.GetById 0ms app.codeStats 0ms

/xlim/services/isabel/services/options/AdministrativeInfoPanel.java

https://github.com/diegocarrera/isabel
Java | 597 lines | 400 code | 85 blank | 112 comment | 34 complexity | 76eba282842cc262e0a287af9fb47096 MD5 | raw file
  1/*
  2 * ISABEL: A group collaboration tool for the Internet
  3 * Copyright (C) 2009 Agora System S.A.
  4 * 
  5 * This file is part of Isabel.
  6 * 
  7 * Isabel is free software: you can redistribute it and/or modify
  8 * it under the terms of the Affero GNU General Public License as published by
  9 * the Free Software Foundation, either version 3 of the License, or
 10 * (at your option) any later version.
 11 * 
 12 * Isabel is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 * Affero GNU General Public License for more details.
 16 * 
 17 * You should have received a copy of the Affero GNU General Public License
 18 * along with Isabel.  If not, see <http://www.gnu.org/licenses/>.
 19 */
 20/*
 21 * AdministartiveInfoPanel.java
 22 *
 23 * Created on 23 de septiembre de 2003, 11:05
 24 */
 25
 26package services.isabel.services.options;
 27
 28import javax.swing.*;
 29import javax.swing.event.*;
 30import javax.swing.border.*;
 31
 32import java.awt.*;
 33import java.awt.event.*;
 34import java.util.Iterator;
 35import java.util.List;
 36
 37import xedl.lib.jaxb.PersonalInformation;
 38import xedl.lib.jaxb.SITE;
 39import xedl.lib.jaxb.SiteIdentification;
 40import xedl.lib.jaxb.SiteIdentification.ADMINISTRATIVEINFORMATION;
 41
 42//import isabel.lim.HelpBrowser;
 43
 44/**
 45 * Esta clase implementa un panel para introducir datos sobre la identidad
 46 * del usuario. Tiene un titulo, un icono, un panel para las etiquetas y
 47 * otro para los campos.
 48 */
 49public class AdministrativeInfoPanel extends JPanel implements OptionsStrings, ValidablePanel, XEDLSiteDataPanel {
 50    
 51    /**
 52     * Crea un objeto AdminInfoPanel.
 53     */
 54    public AdministrativeInfoPanel() {
 55        initComponents();
 56    }
 57    
 58    /** Este m�todo comprueba que los datso contenidos en el panel son
 59     * correctos. Es decir son numeros, letras, tienen la longitud adecuada
 60     * o cualquier regla que se pueda definir para ellos.
 61     * En este caso comprueba que los caracteres de los nombres son letras,
 62     * numeros o espacio, punto, guion, o subrayado y que los emails son formalmente
 63     * validos.
 64     * @return True si los datos son correctos y false si no lo son.
 65     */
 66    public boolean validateData() {
 67        // Compruebo los direferentes campos. O bien estan vacios o bien cumplen la
 68        // expresion regular adecuada.
 69        if ((!getInstitutionName().equals("")) && (!getInstitutionName().matches(INSTITUTION_NAME_REGEX))) {
 70            JOptionPane.showMessageDialog(this, "Inavlid institution name",
 71            "Error", JOptionPane.ERROR_MESSAGE);
 72            return false;
 73        }
 74        
 75        if ((!getAdmin1Name().equals("")) && (!getAdmin1Name().matches(NAME_REGEX))) {
 76            JOptionPane.showMessageDialog(this, "Inavlid administrative Contact 1 name",
 77            "Error", JOptionPane.ERROR_MESSAGE);
 78            return false;
 79        }
 80        
 81        if ((!getAdmin2Name().equals("")) && (!getAdmin2Name().matches(NAME_REGEX))) {
 82            JOptionPane.showMessageDialog(this, "Inavlid administrative Contact 2 name",
 83            "Error", JOptionPane.ERROR_MESSAGE);
 84            return false;
 85        }
 86        
 87        if ((!getAdmin1Mail().equals("")) && (!getAdmin1Mail().matches(EMAIL_REGEX))) {
 88            JOptionPane.showMessageDialog(this, "Inavlid Administrative Contact 1 e-mail",
 89            "Error", JOptionPane.ERROR_MESSAGE);
 90            return false;
 91        }
 92        
 93        if ((!getAdmin2Mail().equals("")) && (!getAdmin2Mail().matches(EMAIL_REGEX))) {
 94            JOptionPane.showMessageDialog(this, "Inavlid Administrative Contact 2 e-mail",
 95            "Error", JOptionPane.ERROR_MESSAGE);
 96            return false;
 97        }
 98        
 99        if ((!getTech1Name().equals("")) && (!getTech1Name().matches(NAME_REGEX))) {
100            JOptionPane.showMessageDialog(this, "Inavlid Technical Contact 1 name",
101            "Error", JOptionPane.ERROR_MESSAGE);
102            return false;
103        }
104        
105        if ((!getTech2Name().equals("")) && (!getTech2Name().matches(NAME_REGEX))) {
106            JOptionPane.showMessageDialog(this, "Inavlid Technical Contact 2 name",
107            "Error", JOptionPane.ERROR_MESSAGE);
108            return false;
109        }
110        
111        if ((!getTech1Mail().equals("")) && (!getTech1Mail().matches(EMAIL_REGEX))) {
112            JOptionPane.showMessageDialog(this, "Inavlid Technical Contact 1 e-mail",
113            "Error", JOptionPane.ERROR_MESSAGE);
114            return false;
115        }
116        
117        if ((!getTech2Mail().equals("")) && (!getTech2Mail().matches(EMAIL_REGEX))) {
118            JOptionPane.showMessageDialog(this, "Inavlid Technical Contact 2 e-mail",
119            "Error", JOptionPane.ERROR_MESSAGE);
120            return false;
121        }
122        
123        return true;
124    }
125    
126    /**
127     * Carga los datos del sitio que se pasa como par�metro en el panel.
128     * @param site Objeto xedl.Site que describe el sitio cuyos datos quieren cargarse.
129     */
130    public void loadData(SITE site) {
131        setInstitutionName(site.getInstitution());
132        
133        // Contactos administrativos
134        Iterator admins = site.getAdminInfoEmails().iterator();
135        Iterator names = site.getAdminInfoNames().iterator();
136        
137        //ENRIQUE, si no hay next hay que fijar el valor a "", que si no se queda el de antes
138        if (admins.hasNext()) {
139            String mail = (String)admins.next();
140            String name = (String)names.next();
141            setAdmin1Mail(mail);
142            setAdmin1Name(name);
143        }
144        else {
145        	setAdmin1Mail("");
146            setAdmin1Name("");
147        }
148        
149        if (admins.hasNext()) {
150            String mail = (String)admins.next();
151            String name = (String)names.next();
152            setAdmin2Mail(mail);
153            setAdmin2Name(name);
154        }
155        else {
156        	setAdmin2Mail("");
157            setAdmin2Name("");
158        }
159        
160        // Contactos tecnicos
161        Iterator techs = site.getTechInfoEmails().iterator();
162        Iterator namestechs = site.getTechInfoNames().iterator();
163        if (techs.hasNext()) {
164            String mail = (String)techs.next();
165            String name = (String)namestechs.next();
166            setTech1Mail(mail);
167            setTech1Name(name);
168        }
169        else {
170        	setTech1Mail("");
171        	setTech1Name("");
172        }
173        
174        if (techs.hasNext()) {
175            String mail = (String)techs.next();
176            String name = (String)namestechs.next();
177            setTech2Mail(mail);
178            setTech2Name(name);
179        }
180        else {
181        	setTech2Mail("");
182        	setTech2Name("");
183        }
184        
185    }
186    
187    /**
188     * Devuelve el panel a sus valores por defecto.
189     */
190    public void resetData() {
191        setInstitutionName("");
192       
193        // Contactos administrativos
194        setAdmin1Mail("");
195        setAdmin1Name("");
196        setAdmin2Mail("");
197        setAdmin2Name("");
198        
199        // Contactos tecnicos
200        setTech1Mail("");
201        setTech1Name("");
202        
203        setTech2Mail("");
204        setTech2Name("");
205    }
206
207    
208    /**
209     * Guarda los datos del panel en el objeto site que se pasa como par�metro.
210     * @param site Objeto xedl.Site donde se almacenar�n los datos.
211     */
212    public void saveData(SITE site) {
213        site.setInstitution(getInstitutionName());
214        
215        // Borro los contactos y pongo los nuevos
216        List<PersonalInformation> lista_tech = null;
217        List<PersonalInformation> lista_admins = null;
218        if(site.getSiteIdentification()!=null && site.getSiteIdentification().getADMINISTRATIVEINFORMATION()!=null)
219        {
220        	lista_tech = site.getSiteIdentification().getADMINISTRATIVEINFORMATION().getTECHNICALCONTACT();
221        	lista_tech.clear();
222        	lista_admins = site.getSiteIdentification().getADMINISTRATIVEINFORMATION().getADMINISTRATIVECONTACT();
223        	lista_admins.clear();
224        }
225        else
226        {
227        	if(site.getSiteIdentification()==null)
228        		site.setSiteIdentification(new SiteIdentification());
229        	if(site.getSiteIdentification().getADMINISTRATIVEINFORMATION()==null)
230        		site.getSiteIdentification().setADMINISTRATIVEINFORMATION(new ADMINISTRATIVEINFORMATION());
231        	lista_tech = site.getSiteIdentification().getADMINISTRATIVEINFORMATION().getTECHNICALCONTACT();
232        	lista_admins = site.getSiteIdentification().getADMINISTRATIVEINFORMATION().getADMINISTRATIVECONTACT();
233        	
234        }
235                
236        PersonalInformation pi = null;
237        if (!getAdmin1Mail().equals("")) {
238            pi = new PersonalInformation();
239            pi.setEMAIL(getAdmin1Mail());
240            pi.setNAME(getAdmin1Name());
241            lista_admins.add(pi);
242        }
243        if (!getAdmin2Mail().equals("")) {
244        	pi = new PersonalInformation();
245            pi.setEMAIL(getAdmin2Mail());
246            pi.setNAME(getAdmin2Name());
247            lista_admins.add(pi);
248        }
249        if (!getTech1Mail().equals("")) {
250        	pi = new PersonalInformation();
251            pi.setEMAIL(getTech1Mail());
252            pi.setNAME(getTech1Name());
253            lista_tech.add(pi);
254        }
255        if (!getTech2Mail().equals("")) {
256        	pi = new PersonalInformation();
257            pi.setEMAIL(getTech2Mail());
258            pi.setNAME(getTech2Name());
259            lista_tech.add(pi);
260        }
261    }
262    
263    /***************************************************************************
264     *               METODOS SET Y GET DE DATOS DEL PANEL SITEID               *
265     ***************************************************************************/
266    
267    public String getInstitutionName() {
268        return institutionNameField.getText();
269    }
270    
271    public void setInstitutionName(String name) {
272        institutionNameField.setText(name);
273    }
274    
275    public String getTech1Name() {
276        return tech1NameField.getText();
277    }
278    
279    public void setTech1Name(String name) {
280        tech1NameField.setText(name);
281    }
282    
283    public String getTech2Name() {
284        return tech2NameField.getText();
285    }
286    
287    public void setTech2Name(String name) {
288        tech2NameField.setText(name);
289    }
290    
291    public String getTech1Mail() {
292        return tech1MailField.getText();
293    }
294    
295    public void setTech1Mail(String mail) {
296        tech1MailField.setText(mail);
297    }
298    
299    public String getTech2Mail() {
300        return tech2MailField.getText();
301    }
302    
303    public void setTech2Mail(String mail) {
304        tech2MailField.setText(mail);
305    }
306    
307    public String getAdmin1Name() {
308        return admin1NameField.getText();
309    }
310    
311    public void setAdmin1Name(String name) {
312        admin1NameField.setText(name);
313    }
314    
315    public String getAdmin2Name() {
316        return admin2NameField.getText();
317    }
318    
319    public void setAdmin2Name(String name) {
320        admin2NameField.setText(name);
321    }
322    
323    public String getAdmin1Mail() {
324        return admin1MailField.getText();
325    }
326    
327    public void setAdmin1Mail(String mail) {
328        admin1MailField.setText(mail);
329    }
330    
331    public String getAdmin2Mail() {
332        return admin2MailField.getText();
333    }
334    
335    public void setAdmin2Mail(String mail) {
336        admin2MailField.setText(mail);
337    }
338    
339    /***************************************************************************
340     **************************************************************************/
341    
342    //    /**
343    //     * M�todo ejecutado cuando se pulsa el boton de ayuda.
344    //     */
345    //    private void helpButtonActionPerformed(ActionEvent evt) {
346    //        if (helpBrowser == null)
347    //            helpBrowser = new HelpBrowser(ADMIN_HELP_HOME);
348    //        helpBrowser.show();
349    //    }
350    //
351    /**
352     * Este m�todo crea todos los componentes que forman el panel.
353     */
354    private void initComponents() {
355        
356        // Configuro el panel principal
357        setLayout(new BorderLayout());
358        setBorder(new CompoundBorder(new EtchedBorder(EtchedBorder.RAISED),
359        new EmptyBorder(new Insets(10,10,10,10))));
360        
361               
362        // Etiqueta con el icono
363        JLabel iconLabel = new JLabel();
364        iconLabel.setIcon(new ImageIcon(getClass().getResource(ADMIN_INFO_ICON)));
365        iconLabel.setBorder(new CompoundBorder(new EtchedBorder(EtchedBorder.RAISED),
366        new EtchedBorder()));
367        add(iconLabel, BorderLayout.WEST);
368        
369        // Un panel que contiene otros 3 paneles. Uno para el nombre
370        // de la institucion, otro para los contactos tecnicos
371        // y otro para los contactos administrativos.
372        JPanel mainPane = new JPanel();
373        mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
374        mainPane.setBorder(new EtchedBorder(EtchedBorder.RAISED));
375        add(mainPane, BorderLayout.CENTER);
376        
377        //Panel para la etiqueta del titulo y el boton de ayuda
378        JPanel titlePane = new JPanel();
379        titlePane.setLayout(new BoxLayout(titlePane, BoxLayout.X_AXIS));
380        mainPane.add(titlePane);
381        
382        // Etiqueta con el titulo
383        JLabel titleLabel = new JLabel();
384        titleLabel.setFont(new Font(TITLE_FONT, Font.BOLD, 24));
385        titleLabel.setForeground(TITLE_COLOR);
386        titleLabel.setText(ADMIN_INFO_TITLE);
387        titlePane.add(titleLabel);
388        
389        // Panel con el nombre de la institucion. Tiene una etiqueta y un campo.
390        JPanel instituionNamePane = new JPanel();
391        //instituionNamePane.setBorder(new EtchedBorder());
392        instituionNamePane.setLayout(new BoxLayout(instituionNamePane, BoxLayout.X_AXIS));
393        mainPane.add(instituionNamePane);
394        
395        // Espacio entre el borde y la etiqueta
396        instituionNamePane.add(Box.createHorizontalStrut(10));
397        
398        // La Etiqueta y el campo
399        JLabel instituionNameLabel = new JLabel();
400        instituionNameLabel.setText("Institution Name");
401        instituionNameLabel.setFont(new Font("Dialog", Font.BOLD, 14));
402        instituionNamePane.add(instituionNameLabel);
403        
404        // Espacio entre la etiqueta y el campo
405        instituionNamePane.add(Box.createHorizontalStrut(10));
406        
407        institutionNameField = new JTextField();
408        institutionNameField.setColumns(13);
409        institutionNameField.setMaximumSize(new Dimension(1000,25));
410        institutionNameField.addKeyListener(new KeyListener(){
411			public void keyPressed(KeyEvent arg0) {				
412			}
413			public void keyReleased(KeyEvent arg0) {				
414			}
415			public void keyTyped(KeyEvent arg0) {
416				Options.setProfile_edited(true);
417			}        	
418        });
419       
420        instituionNamePane.add(institutionNameField);
421        
422        // Espacio entre el campo y el final
423        instituionNamePane.add(Box.createHorizontalStrut(10));
424        
425        // Panel de los contactos administrativos
426        JPanel adminPane = new JPanel();
427        //adminPane.setBorder(new EtchedBorder());
428        adminPane.setLayout(new BoxLayout(adminPane, BoxLayout.X_AXIS));
429        mainPane.add(adminPane);
430        
431        // Panel del contacto administrativo 1
432        admin1MailField = new JTextField();
433        admin1NameField = new JTextField();        
434        admin1MailField.addKeyListener(new KeyListener(){
435			public void keyPressed(KeyEvent arg0) {				
436			}
437			public void keyReleased(KeyEvent arg0) {				
438			}
439			public void keyTyped(KeyEvent arg0) {
440				Options.setProfile_edited(true);
441			}        	
442        });
443        admin1NameField.addKeyListener(new KeyListener(){
444			public void keyPressed(KeyEvent arg0) {				
445			}
446			public void keyReleased(KeyEvent arg0) {				
447			}
448			public void keyTyped(KeyEvent arg0) {
449				Options.setProfile_edited(true);
450			}        	
451        });
452        JPanel admin1Pane = createInfoPanel(admin1NameField, admin1MailField,
453        "Administrative Contact 1");
454        adminPane.add(admin1Pane);
455        
456        // Separacion entre los paneles
457        //adminPane.add(Box.createHorizontalGlue());
458        
459        // Panel del contacto administrativo 2
460        admin2MailField = new JTextField();
461        admin2NameField = new JTextField();
462        admin2MailField.addKeyListener(new KeyListener(){
463			public void keyPressed(KeyEvent arg0) {				
464			}
465			public void keyReleased(KeyEvent arg0) {				
466			}
467			public void keyTyped(KeyEvent arg0) {
468				Options.setProfile_edited(true);
469			}        	
470        });
471        admin2NameField.addKeyListener(new KeyListener(){
472			public void keyPressed(KeyEvent arg0) {				
473			}
474			public void keyReleased(KeyEvent arg0) {				
475			}
476			public void keyTyped(KeyEvent arg0) {
477				Options.setProfile_edited(true);
478			}        	
479        });
480        JPanel admin2Pane = createInfoPanel(admin2NameField, admin2MailField,
481        "Administrative Contact 2");
482        adminPane.add(admin2Pane);
483        
484        
485        // Panel de los contactos tecnicos
486        JPanel techPane = new JPanel();
487        //techPane.setBorder(new EtchedBorder());
488        techPane.setLayout(new BoxLayout(techPane, BoxLayout.X_AXIS));
489        mainPane.add(techPane);
490        
491        // Panel del contacto tecnico 1
492        tech1MailField = new JTextField();
493        tech1NameField = new JTextField();
494        	tech1MailField.addKeyListener(new KeyListener(){
495    			public void keyPressed(KeyEvent arg0) {				
496    			}
497    			public void keyReleased(KeyEvent arg0) {				
498    			}
499    			public void keyTyped(KeyEvent arg0) {
500    				Options.setProfile_edited(true);
501    			}        	
502            });
503        	tech1NameField.addKeyListener(new KeyListener(){
504    			public void keyPressed(KeyEvent arg0) {				
505    			}
506    			public void keyReleased(KeyEvent arg0) {				
507    			}
508    			public void keyTyped(KeyEvent arg0) {
509    				Options.setProfile_edited(true);
510    			}        	
511            });
512        JPanel tech1Pane = createInfoPanel(tech1NameField, tech1MailField,
513        "Technical Contact 1");
514        techPane.add(tech1Pane);
515        
516        // Separacion entre los paneles
517        //techPane.add(Box.createHorizontalGlue());
518        
519        // Panel del contacto tecnico 2
520        tech2MailField = new JTextField();
521        tech2NameField = new JTextField();
522        tech2MailField.addKeyListener(new KeyListener(){
523    			public void keyPressed(KeyEvent arg0) {				
524    			}
525    			public void keyReleased(KeyEvent arg0) {				
526    			}
527    			public void keyTyped(KeyEvent arg0) {
528    				Options.setProfile_edited(true);
529    			}        	
530            });
531        tech2NameField.addKeyListener(new KeyListener(){
532    			public void keyPressed(KeyEvent arg0) {				
533    			}
534    			public void keyReleased(KeyEvent arg0) {				
535    			}
536    			public void keyTyped(KeyEvent arg0) {
537    				Options.setProfile_edited(true);
538    			}        	
539            });
540        JPanel tech2Pane = createInfoPanel(tech2NameField, tech2MailField,
541        "Technical Contact 2");
542        techPane.add(tech2Pane);
543    }
544    
545    /**
546     * Crea un panel con los elementos para meter el nombre y mail de un
547     * contacto.
548     */
549    private JPanel createInfoPanel(JTextField nameField, JTextField mailField, String title) {
550        // Panel que se devuelve como resultado
551        JPanel pane = new JPanel();
552        pane.setBorder(new CompoundBorder(null, new TitledBorder(title)));
553        pane.setLayout(new GridLayout(0,1));
554        
555        // Panel con el campo de nombre
556        JPanel namePane = new JPanel();
557        namePane.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
558        namePane.setBorder(new TitledBorder("Name"));
559        pane.add(namePane);
560        
561        nameField.setColumns(11);
562        namePane.add(nameField);
563        
564        // Panel con el campo para el mail
565        JPanel mailPane = new JPanel();
566        mailPane.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
567        mailPane.setBorder(new TitledBorder("E-Mail"));
568        pane.add(mailPane);
569        
570        mailField.setColumns(11);
571        mailPane.add(mailField);
572        
573        return pane;
574    }
575    
576    // Componentes visuales que guardan datos
577    private JTextField institutionNameField;
578    private JTextField tech1NameField;
579    private JTextField tech2NameField;
580    private JTextField admin1NameField;
581    private JTextField admin2NameField;
582    private JTextField tech1MailField;
583    private JTextField tech2MailField;
584    private JTextField admin1MailField;
585    private JTextField admin2MailField;
586    
587    // Ventana para mostrar la ayuda
588    //    private JFrame helpBrowser;
589    public static void main(String[] args) {
590        JFrame f = new JFrame();
591        f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
592        f.getContentPane().add(new AdministrativeInfoPanel());
593        f.pack();
594        f.setVisible(true);
595    }
596    
597} // Class AdminInfoPanel