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