Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / gui / ProjectWindow.java @ 36631

History | View | Annotate | Download (36.5 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22
package org.gvsig.app.project.documents.gui;
23

    
24
import java.awt.Component;
25
import java.awt.FlowLayout;
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.GridLayout;
29
import java.awt.Insets;
30
import java.beans.PropertyChangeEvent;
31
import java.beans.PropertyChangeListener;
32
import java.io.File;
33
import java.util.ArrayList;
34
import java.util.Collections;
35
import java.util.Comparator;
36
import java.util.Enumeration;
37
import java.util.Iterator;
38
import java.util.List;
39

    
40
import javax.swing.AbstractButton;
41
import javax.swing.ButtonGroup;
42
import javax.swing.JDialog;
43
import javax.swing.JLabel;
44
import javax.swing.JList;
45
import javax.swing.JOptionPane;
46
import javax.swing.JPanel;
47
import javax.swing.JRadioButton;
48
import javax.swing.JScrollPane;
49
import javax.swing.border.TitledBorder;
50

    
51
import org.gvsig.andami.PluginServices;
52
import org.gvsig.andami.help.Help;
53
import org.gvsig.andami.messages.NotificationManager;
54
import org.gvsig.andami.ui.mdiManager.IWindow;
55
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
56
import org.gvsig.andami.ui.mdiManager.WindowInfo;
57
import org.gvsig.app.extension.ProjectExtension;
58
import org.gvsig.app.project.Project;
59
import org.gvsig.app.project.ProjectManager;
60
import org.gvsig.app.project.documents.AbstractDocument;
61
import org.gvsig.app.project.documents.Document;
62
import org.gvsig.app.project.documents.DocumentManager;
63
import org.gvsig.gui.beans.swing.JButton;
64
import org.gvsig.tools.observer.Observable;
65
import org.gvsig.tools.observer.Observer;
66
import org.gvsig.utils.DefaultListModel;
67

    
68
/**
69
 * Clase principal del proyecto donde se puede operar para crear cualquier tipo
70
 * de documento.
71
 * 
72
 * @author Vicente Caballero Navarro
73
 */
74
public class ProjectWindow extends JPanel implements PropertyChangeListener,
75
    IWindow, SingletonWindow, Observer {
76

    
77
    /**
78
         * 
79
         */
80
    private static final long serialVersionUID = 7315293357719796556L;
81

    
82
    public static final String PERSISTENCE_DEFINITION_NAME = "ProjectWindow";
83

    
84
    private JPanel jPanel = null;
85
    private JRadioButton[] btnsDocuments = null;
86
    private ButtonGroup grupo = new ButtonGroup();
87
    private JPanel jPanel1 = null;
88
    private JList lstDocs = null;
89
    private JPanel jPanel2 = null;
90
    private JButton btnNuevo = null;
91
    private JButton btnPropiedades = null;
92
    private JButton btnAbrir = null;
93
    private JButton btnBorrar = null;
94
    private JButton btnRenombrar = null;
95
    private JPanel jPanel3 = null;
96
    private JLabel jLabel = null;
97
    private JLabel lblNombreSesion = null;
98
    private JLabel jLabel1 = null;
99
    private JLabel lblGuardado = null;
100
    private JLabel jLabel2 = null;
101
    private JLabel lblFecha = null;
102
    private JButton btnImportar = null;
103
    private JButton btnExportar = null;
104
    private JButton btnEditar = null;
105
    // The properties of the Project Manager window (size, position, etc):
106
    private WindowInfo m_viewInfo = null;
107

    
108
    private Project project;
109

    
110
    private JScrollPane jScrollPane = null;
111
    private JPanel jPanel4 = null;
112
    private JScrollPane jScrollPane1 = null;
113

    
114
    /**
115
     * This is the default constructor
116
     * 
117
     * @param project
118
     *            Extension
119
     */
120
    public ProjectWindow() {
121
        super();
122
        initialize();
123
        refreshControls();
124
        Help.getHelp().enableHelp(this, this.getClass().getName());
125
        // Observe document factory registration changes
126
        ProjectManager.getInstance().addObserver(this);
127
    }
128

    
129
    /**
130
     * Asigna el proyecto a la ventana
131
     * 
132
     * @param project
133
     *            Proyecto con el que se operar? a trav?s de este di?logo
134
     */
135
    public void setProject(Project project) {
136
        this.project = project;
137
        project.addPropertyChangeListener(this);
138
        refreshControls();
139
    }
140

    
141
    /**
142
     * Activa los botones de la botonera del medio o los desactiva en funci?n de
143
     * que est? seleccionado o no un elemento de proyecto en la lista del medio
144
     */
145
    private void activarBotones() {
146
        if (lstDocs.getSelectedIndex() != -1) {
147
            btnAbrir.setEnabled(true);
148
            btnBorrar.setEnabled(true);
149
            if (lstDocs.getSelectedIndices().length == 1) {
150
                btnRenombrar.setEnabled(true);
151
                btnPropiedades.setEnabled(true);
152
            } else {
153
                btnRenombrar.setEnabled(false);
154
                btnPropiedades.setEnabled(false);
155
            }
156
        } else {
157
            btnAbrir.setEnabled(false);
158
            btnBorrar.setEnabled(false);
159
            btnRenombrar.setEnabled(false);
160
            btnPropiedades.setEnabled(false);
161
        }
162
    }
163

    
164
    /**
165
     * Refresca la lista de elementos de proyecto con vistas, mapas o tablas,
166
     * seg?n la opci?n activada
167
     */
168
    private void refreshList() {
169
        if (project != null) {
170
            DefaultListModel model = null;
171
            String tituloMarco =
172
                PluginServices.getText(this, "documentos_existentes");
173

    
174
            String doctype = getDocumentSelected();
175
            model = new DefaultListModel(project.getDocuments(doctype));
176
            tituloMarco = getDocumentSelectedName();
177

    
178
            lstDocs.setModel(model);
179
            ((TitledBorder) getJPanel1().getBorder()).setTitle(tituloMarco);
180
            getJPanel1().repaint(1);
181
            activarBotones();
182
        }
183
    }
184

    
185
    /**
186
     * Devuelve el nombre del tipo de documento activo (el mismo que
187
     * ProjectDocumentFactory.getRegisterName)
188
     * 
189
     * 
190
     * @return
191
     */
192

    
193
    public String getDocumentSelected() {
194
        JRadioButton btnSelected = null;
195
        for (int i = 0; i < btnsDocuments.length; i++) {
196
            if (btnsDocuments[i].isSelected()) {
197
                btnSelected = btnsDocuments[i];
198
                return btnSelected.getName();
199
            }
200
        }
201

    
202
        return null;
203
    }
204

    
205
    private String getDocumentSelectedName() {
206
        JRadioButton btnSelected = null;
207
        for (int i = 0; i < btnsDocuments.length; i++) {
208
            if (btnsDocuments[i].isSelected()) {
209
                btnSelected = btnsDocuments[i];
210
                return btnSelected.getText();
211
            }
212
        }
213

    
214
        return null;
215
    }
216

    
217
    /**
218
     * Refresca las etiquetas con la informaci?n del proyecto
219
     */
220
    private void refreshProperties() {
221
        if (project != null) {
222
            lblNombreSesion.setText(project.getName());
223
            String path = ProjectExtension.getPath();
224
            if (path != null) {
225
                File f = new File(path);
226
                lblGuardado.setText(f.toString());
227
            } else {
228
                lblGuardado.setText("");
229
            }
230
            lblFecha.setText(project.getCreationDate());
231
        }
232
    }
233

    
234
    /**
235
     * Refresca todo el di?logo
236
     */
237
    public void refreshControls() {
238
        refreshList();
239
        refreshProperties();
240
    }
241

    
242
    /**
243
     * This method initializes this
244
     */
245
    private void initialize() {
246
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
247
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
248
        gridBagConstraints.weightx = 1.0;
249
        gridBagConstraints.weighty = 1.0;
250
        GridBagLayout layout = new GridBagLayout();
251
        setLayout(layout);
252
        GridBagConstraints c = new GridBagConstraints();
253
        c.fill = GridBagConstraints.HORIZONTAL;
254
        c.weightx = 1.0;
255
        c.weighty = 0;
256
        c.gridy = 0;
257
        c.insets = new Insets(2, 5, 2, 5);
258

    
259
        layout.setConstraints(getJPanel(), c);
260
        add(getJPanel(), null);
261

    
262
        c.fill = GridBagConstraints.BOTH;
263
        c.gridy = 1;
264
        c.weightx = 1.0;
265
        c.weighty = 1.0;
266
        layout.setConstraints(getJPanel1(), c);
267
        add(getJPanel1(), null);
268
        c.fill = GridBagConstraints.HORIZONTAL;
269
        c.weightx = 0;
270
        c.weighty = 0;
271
        c.gridy = 2;
272
        layout.setConstraints(getJPanel3(), c);
273
        add(getJPanel3(), null);
274

    
275
        this.setSize(430, 544);
276
        this.setPreferredSize(new java.awt.Dimension(430, 554));
277
        this.setMinimumSize(new java.awt.Dimension(430, 554));
278
        this.add(getJScrollPane1(), gridBagConstraints);
279
        refreshDocuments();
280
    }
281

    
282
    private void createDocumentsInProject(String doctype) {
283
        Iterator<? extends Document> documents =
284
            ProjectManager.getInstance().createDocumentsByUser(doctype);
285
        for (; documents.hasNext();) {
286
            try {
287
                Document document = documents.next();
288
                project.add(document);
289
                int index =
290
                    ((DefaultListModel) lstDocs.getModel()).indexOf(document);
291
                lstDocs.setSelectedIndex(index);
292
                lstDocs.requestFocus();
293
                openDocumentWindow(document);
294
            } catch (Exception e) {
295
                NotificationManager.addError(e);
296
            }
297
        }
298
    }
299

    
300
    /**
301
     * Crea un nuevo project element
302
     * 
303
     * @throws Exception
304
     *             DOCUMENT ME!
305
     */
306
    private void newProjectDocument() throws Exception {
307
        String doctype = getDocumentSelected();
308
        createDocumentsInProject(doctype);
309
    }
310

    
311
    /**
312
     * Abre la ventana de un nuevo documento
313
     */
314
    private void abrir() {
315
        int[] indexes = lstDocs.getSelectedIndices();
316
        for (int i = indexes.length - 1; i >= 0; i--) {
317
            int index = indexes[i];
318
            if (index == -1) {
319
                return;
320
            }
321
            String doctype = getDocumentSelected();
322
            List<Document> documents = project.getDocuments(doctype);
323
            Document doc = documents.get(index);
324
            openDocumentWindow(doc);
325
        }
326
    }
327

    
328
    private void openDocumentWindow(Document doc) {
329
        if (doc != null) {
330
            IWindow window = doc.getFactory().getMainWindow(doc);
331
            if (window == null) {
332
                JOptionPane.showMessageDialog(
333
                    (Component) PluginServices.getMainFrame(),
334
                    PluginServices.getText(this, "error_opening_the_document"));
335
                return;
336
            }
337
            PluginServices.getMDIManager().addWindow(window,
338
                GridBagConstraints.FIRST_LINE_END);
339
            project.setModified(true);
340
        }
341
    }
342

    
343
    /**
344
     * Cambia el nombre de un project element
345
     */
346
    private void renombrar() {
347
        int index = lstDocs.getSelectedIndex();
348

    
349
        if (index == -1) {
350
            return;
351
        }
352
        String doctype = getDocumentSelected();
353
        List<Document> documents = project.getDocuments(doctype);
354
        Document doc = documents.get(index);
355

    
356
        if (doc.isLocked()) {
357
            JOptionPane.showMessageDialog(this, PluginServices.getText(this,
358
                "locked_element_it_cannot_be_renamed"));
359
            return;
360
        }
361

    
362
        JOptionPane pane = new JOptionPane();
363
        pane.setMessage(PluginServices.getText(this, "introduce_nombre"));
364
        pane.setMessageType(JOptionPane.QUESTION_MESSAGE);
365
        pane.setWantsInput(true);
366
        pane.setInitialSelectionValue(doc.getName());
367
        pane.setInputValue(doc.getName());
368
        JDialog dlg =
369
            pane.createDialog((Component) PluginServices.getMainFrame(),
370
                PluginServices.getText(this, "renombrar"));
371
        dlg.setModal(true);
372
        dlg.setVisible(true);
373

    
374
        String nuevoNombre = pane.getInputValue().toString().trim();
375

    
376
        if (nuevoNombre.length() == 0) {
377
            return;
378
        }
379

    
380
        if (nuevoNombre == null) {
381
            return;
382
        }
383

    
384
        for (int i = 0; i < lstDocs.getModel().getSize(); i++) {
385
            if (i == index) {
386
                continue;
387
            }
388
            if (((AbstractDocument) lstDocs.getModel().getElementAt(i))
389
                .getName().equals(nuevoNombre)) {
390
                JOptionPane.showMessageDialog(
391
                    (Component) PluginServices.getMainFrame(),
392
                    PluginServices.getText(this, "elemento_ya_existe"));
393
                return;
394
            }
395

    
396
        }
397
        doc.setName(nuevoNombre);
398

    
399
        refreshList();
400
        project.setModified(true);
401
    }
402

    
403
    /**
404
     * Borra un project element
405
     */
406
    private void borrar() {
407
        int res =
408
            JOptionPane.showConfirmDialog(
409
                (Component) PluginServices.getMainFrame(),
410
                PluginServices.getText(this, "confirmar_borrar"),
411
                PluginServices.getText(this, "borrar"),
412
                JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
413

    
414
        int lastremoved = 0;
415
        if (res == JOptionPane.YES_OPTION) {
416
            int[] indexes = lstDocs.getSelectedIndices();
417
            for (int i = indexes.length - 1; i >= 0; i--) {
418
                int index = indexes[i];
419
                String s = getDocumentSelected();
420
                List<Document> documents = project.getDocuments(s);
421
                Document doc = (AbstractDocument) documents.get(index);
422
                if (doc.isLocked()) {
423
                    JOptionPane.showMessageDialog(this, PluginServices.getText(
424
                        this, "locked_element_it_cannot_be_deleted"));
425
                    return;
426
                }
427
                PluginServices.getMDIManager().closeSingletonWindow(doc);
428
                project.remove(doc);
429
                lastremoved = index;
430
            }
431
            if (lastremoved > lstDocs.getModel().getSize()) {
432
                lastremoved = lstDocs.getModel().getSize();
433
            }
434
            if (lastremoved > 0) {
435
                lstDocs.setSelectedIndex(lastremoved);
436
            }
437
            refreshList();
438
            project.setModified(true);
439
        }
440
    }
441

    
442
    /**
443
     * Muestra el di?logo de propiedades de un project element
444
     */
445
    private void propiedades() {
446
        int index = lstDocs.getSelectedIndex();
447

    
448
        if (index == -1) {
449
            return;
450
        }
451

    
452
        IWindow dlg = null;
453
        String doctype = getDocumentSelected();
454
        List<Document> documents = project.getDocuments(doctype);
455
        Document doc = (AbstractDocument) documents.get(index);
456
        if (doc.isLocked()) {
457
            JOptionPane.showMessageDialog(this,
458
                PluginServices.getText(this, "locked_element"));
459
            return;
460
        }
461
        dlg = doc.getFactory().getPropertiesWindow(doc);
462
        PluginServices.getMDIManager().addWindow(dlg);
463

    
464
        refreshControls();
465
        lstDocs.setSelectedIndex(index);
466
        project.setModified(true);
467
    }
468

    
469
    /**
470
     * This method initializes jPanel
471
     * 
472
     * @return JPanel
473
     */
474
    private JPanel getJPanel() {
475
        if (jPanel == null) {
476
            jPanel = new JPanel();
477

    
478
            java.awt.FlowLayout layFlowLayout1 = new java.awt.FlowLayout();
479
            layFlowLayout1.setHgap(15);
480
            jPanel.setLayout(layFlowLayout1);
481
            fillDocumentTypeButtons();
482
            jPanel.setName("tipoDocPanel");
483
            // jPanel.setPreferredSize(new java.awt.Dimension(700, 200));
484
            jPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
485
                PluginServices.getText(this, "tipos_de_documentos"),
486
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
487
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
488
        }
489

    
490
        return jPanel;
491
    }
492

    
493
    /**
494
     * Adds a button for each document type
495
     */
496
    private void fillDocumentTypeButtons() {
497
        JRadioButton[] btns = getBtnDocuments();
498
        for (int i = 0; i < btns.length; i++) {
499
            jPanel.add(btns[i], null);
500
        }
501
    }
502

    
503
    /**
504
     * This method initializes btnVistas
505
     * 
506
     * @return JRadioButton
507
     */
508
    private JRadioButton[] getBtnDocuments() {
509
        if (btnsDocuments == null) {
510

    
511
            List<JRadioButton> btns = new ArrayList<JRadioButton>();
512
            List<DocumentManager> factories =
513
                ProjectManager.getInstance().getDocumentManagers();
514
            Collections.sort(factories, new Comparator<DocumentManager>() {
515

    
516
                public int compare(DocumentManager arg0, DocumentManager arg1) {
517
                    return arg0.getPriority() - arg1.getPriority();
518
                }
519

    
520
            });
521
            for (DocumentManager documentFactory : factories) {
522
                JRadioButton rb = new JRadioButton();
523

    
524
                rb.setIcon(documentFactory.getIcon());
525
                rb.setSelectedIcon(documentFactory.getIconSelected());
526
                rb.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
527
                rb.setText(documentFactory.getTitle());
528
                rb.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
529
                rb.setName(documentFactory.getTypeName());
530
                rb.addChangeListener(new javax.swing.event.ChangeListener() {
531

    
532
                    public void stateChanged(javax.swing.event.ChangeEvent e) {
533
                        refreshList();
534
                    }
535
                });
536
                btns.add(rb);
537
            }
538
            btnsDocuments = btns.toArray(new JRadioButton[0]);
539
        }
540
        return btnsDocuments;
541
    }
542

    
543
    /**
544
     * This method initializes jPanel1
545
     * 
546
     * @return JPanel
547
     */
548
    private JPanel getJPanel1() {
549
        if (jPanel1 == null) {
550
            jPanel1 = new JPanel();
551

    
552
            GridBagLayout layout2 = new GridBagLayout();
553
            GridBagConstraints c = new GridBagConstraints();
554

    
555
            jPanel1.setLayout(layout2);
556
            c.insets = new Insets(2, 5, 2, 5);
557
            c.anchor = GridBagConstraints.WEST;
558
            c.fill = GridBagConstraints.BOTH;
559
            c.weightx = 1.0;
560
            c.weighty = 1.0;
561
            layout2.setConstraints(getJScrollPane(), c);
562
            jPanel1.add(getJScrollPane());
563

    
564
            c.anchor = GridBagConstraints.EAST;
565

    
566
            c.fill = GridBagConstraints.NONE;
567
            c.weightx = 0;
568
            c.weighty = 0;
569
            layout2.setConstraints(getJPanel2(), c);
570
            jPanel1.add(getJPanel2());
571

    
572
            // jPanel1.setPreferredSize(new java.awt.Dimension(430,170));
573
            jPanel1.setMinimumSize(new java.awt.Dimension(430, 170));
574
            jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(
575
                null, PluginServices.getText(this, "documentos_existentes"),
576
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
577
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
578
        }
579

    
580
        return jPanel1;
581
    }
582

    
583
    /**
584
     * This method initializes lstDocs
585
     * 
586
     * @return JList
587
     */
588
    private JList getLstDocs() {
589
        if (lstDocs == null) {
590
            lstDocs = new JList();
591
            lstDocs.addMouseListener(new java.awt.event.MouseAdapter() {
592

    
593
                public AbstractDocument[] getSelecteds() {
594
                    if (lstDocs.getSelectedIndex() < 0) {
595
                        return new AbstractDocument[0];
596
                    }
597
                    Object[] seleteds = lstDocs.getSelectedValues();
598
                    AbstractDocument[] returnValue =
599
                        new AbstractDocument[seleteds.length];
600
                    System.arraycopy(seleteds, 0, returnValue, 0,
601
                        seleteds.length);
602
                    return returnValue;
603
                }
604

    
605
                public AbstractDocument getItem(java.awt.event.MouseEvent e) {
606
                    if (lstDocs.getSelectedIndex() < 0) {
607
                        return null;
608
                    }
609
                    // Component c = lstDocs.getComponentAt(e.getPoint());
610

    
611
                    return null;
612
                }
613

    
614
                public void mouseClicked(java.awt.event.MouseEvent e) {
615
                    if (e.getButton() == java.awt.event.MouseEvent.BUTTON3) {
616
                        /*
617
                         * getDocumentSelected();//ProjectView
618
                         * getDocumentSelectedName();//Vista
619
                         */
620
                        String docType = getDocumentSelected();
621
                        AbstractDocument[] selecteds = this.getSelecteds();
622

    
623
                        if (selecteds == null) {
624
                            return;
625
                        }
626
                        DocumentContextMenu menu =
627
                            new DocumentContextMenu(docType, this.getItem(e),
628
                                selecteds);
629
                        if (!menu.hasActions()) {
630
                            return;
631
                        }
632
                        lstDocs.add(menu);
633
                        menu.show(e.getComponent(), e.getX(), e.getY());
634
                        return;
635
                    }
636

    
637
                    if (e.getClickCount() == 2) {
638
                        abrir();
639
                    }
640

    
641
                }
642
            });
643
            lstDocs
644
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
645

    
646
                    public void valueChanged(
647
                        javax.swing.event.ListSelectionEvent e) {
648
                        activarBotones();
649
                    }
650
                });
651
        }
652

    
653
        return lstDocs;
654
    }
655

    
656
    /**
657
     * This method initializes jPanel2
658
     * 
659
     * @return JPanel
660
     */
661
    private JPanel getJPanel2() {
662
        if (jPanel2 == null) {
663
            jPanel2 = new JPanel();
664

    
665
            // FlowLayout layout = new FlowLayout();
666
            GridLayout layout = new GridLayout(5, 1);
667
            layout.setVgap(7);
668

    
669
            jPanel2.setLayout(layout);
670
            jPanel2.add(getBtnNuevo(), null);
671
            jPanel2.add(getBtnAbrir(), null);
672
            jPanel2.add(getBtnRenombrar(), null);
673
            jPanel2.add(getBtnBorrar(), null);
674
            jPanel2.add(getBtnPropiedades(), null);
675
            jPanel2.setPreferredSize(new java.awt.Dimension(100, 150));
676
            jPanel2.setMinimumSize(new java.awt.Dimension(100, 150));
677
            jPanel2.setMaximumSize(new java.awt.Dimension(100, 150));
678
        }
679

    
680
        return jPanel2;
681
    }
682

    
683
    /**
684
     * This method initializes btnNuevo
685
     * 
686
     * @return JButton
687
     */
688
    private JButton getBtnNuevo() {
689
        if (btnNuevo == null) {
690
            btnNuevo = new JButton();
691
            btnNuevo.setName("btnNuevo");
692
            btnNuevo.setText(PluginServices.getText(this, "nuevo"));
693
            btnNuevo.setMargin(new java.awt.Insets(2, 2, 2, 2));
694
            btnNuevo.addActionListener(new java.awt.event.ActionListener() {
695

    
696
                public void actionPerformed(java.awt.event.ActionEvent e) {
697
                    try {
698
                        newProjectDocument();
699
                    } catch (Exception e1) {
700
                        NotificationManager.addError(e1.getLocalizedMessage(),
701
                            e1);
702
                    }
703
                }
704
            });
705
        }
706

    
707
        return btnNuevo;
708
    }
709

    
710
    /**
711
     * This method initializes btnPropiedades
712
     * 
713
     * @return JButton
714
     */
715
    private JButton getBtnPropiedades() {
716
        if (btnPropiedades == null) {
717
            btnPropiedades = new JButton();
718
            btnPropiedades.setText(PluginServices.getText(this, "propiedades"));
719
            btnPropiedades.setName("btnPropiedades");
720
            btnPropiedades.setEnabled(false);
721
            btnPropiedades.setMargin(new java.awt.Insets(2, 2, 2, 2));
722
            btnPropiedades
723
                .addActionListener(new java.awt.event.ActionListener() {
724

    
725
                    public void actionPerformed(java.awt.event.ActionEvent e) {
726
                        propiedades();
727
                    }
728
                });
729
        }
730

    
731
        return btnPropiedades;
732
    }
733

    
734
    /**
735
     * This method initializes btnAbrir
736
     * 
737
     * @return JButton
738
     */
739
    private JButton getBtnAbrir() {
740
        if (btnAbrir == null) {
741
            btnAbrir = new JButton();
742
            btnAbrir.setName("btnAbrir");
743
            btnAbrir.setText(PluginServices.getText(this, "abrir"));
744
            btnAbrir.setEnabled(false);
745
            btnAbrir.setMargin(new java.awt.Insets(2, 2, 2, 2));
746
            btnAbrir.addActionListener(new java.awt.event.ActionListener() {
747

    
748
                public void actionPerformed(java.awt.event.ActionEvent e) {
749
                    abrir();
750
                }
751
            });
752
        }
753

    
754
        return btnAbrir;
755
    }
756

    
757
    /**
758
     * This method initializes btnBorrar
759
     * 
760
     * @return JButton
761
     */
762
    private JButton getBtnBorrar() {
763
        if (btnBorrar == null) {
764
            btnBorrar = new JButton();
765
            btnBorrar.setText(PluginServices.getText(this, "borrar"));
766
            btnBorrar.setName("btnBorrar");
767
            btnBorrar.setEnabled(false);
768
            btnBorrar.setMargin(new java.awt.Insets(2, 2, 2, 2));
769
            btnBorrar.addActionListener(new java.awt.event.ActionListener() {
770

    
771
                public void actionPerformed(java.awt.event.ActionEvent e) {
772
                    borrar();
773
                }
774
            });
775
        }
776

    
777
        return btnBorrar;
778
    }
779

    
780
    /**
781
     * This method initializes btnRenombrar
782
     * 
783
     * @return JButton
784
     */
785
    private JButton getBtnRenombrar() {
786
        if (btnRenombrar == null) {
787
            btnRenombrar = new JButton();
788
            btnRenombrar.setName("btnRenombrar");
789
            btnRenombrar.setText(PluginServices.getText(this, "renombrar"));
790
            btnRenombrar.setEnabled(false);
791
            btnRenombrar.setMargin(new java.awt.Insets(2, 2, 2, 2));
792
            btnRenombrar.addActionListener(new java.awt.event.ActionListener() {
793

    
794
                public void actionPerformed(java.awt.event.ActionEvent e) {
795
                    renombrar();
796
                }
797
            });
798
        }
799

    
800
        return btnRenombrar;
801
    }
802

    
803
    /**
804
     * This method initializes jPanel3
805
     * 
806
     * @return JPanel
807
     */
808
    private JPanel getJPanel3() {
809
        if (jPanel3 == null) {
810
            jPanel3 = new JPanel();
811

    
812
            GridBagLayout layout3 = new GridBagLayout();
813
            GridBagConstraints c = new GridBagConstraints();
814
            jPanel3.setLayout(layout3);
815
            c.insets = new Insets(2, 5, 0, 5);
816
            c.anchor = GridBagConstraints.WEST;
817
            c.gridx = 0;
818
            c.gridy = 0;
819
            layout3.setConstraints(getJLabel(), c);
820
            jPanel3.add(getJLabel(), null);
821
            c.fill = GridBagConstraints.HORIZONTAL;
822
            c.weightx = 1.0;
823
            c.gridx = 1;
824
            layout3.setConstraints(getLblNombreSesion(), c);
825
            jPanel3.add(getLblNombreSesion(), null);
826

    
827
            c.gridx = 0;
828
            c.gridy = 1;
829
            c.fill = GridBagConstraints.NONE;
830
            c.weightx = 0.0;
831
            layout3.setConstraints(getJLabel1(), c);
832
            jPanel3.add(getJLabel1(), null);
833
            c.fill = GridBagConstraints.HORIZONTAL;
834
            c.weightx = 1.0;
835
            c.gridx = 1;
836
            layout3.setConstraints(getLblGuardado(), c);
837
            jPanel3.add(getLblGuardado(), null);
838

    
839
            c.gridx = 0;
840
            c.gridy = 2;
841
            c.fill = GridBagConstraints.NONE;
842
            c.weightx = 0.0;
843
            layout3.setConstraints(getJLabel2(), c);
844
            jPanel3.add(getJLabel2(), null);
845

    
846
            c.fill = GridBagConstraints.HORIZONTAL;
847
            c.weightx = 1.0;
848
            c.gridx = 1;
849
            layout3.setConstraints(getLblFecha(), c);
850
            jPanel3.add(getLblFecha(), null);
851
            jPanel3.setPreferredSize(new java.awt.Dimension(430, 125));
852
            jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(
853
                null, PluginServices.getText(this, "propiedades_sesion"),
854
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
855
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
856
            c.gridx = 1;
857
            c.gridy = 4;
858
            c.anchor = GridBagConstraints.EAST;
859
            layout3.setConstraints(getJPanel4(), c);
860
            jPanel3.add(getJPanel4(), null);
861
        }
862

    
863
        return jPanel3;
864
    }
865

    
866
    /**
867
     * This method initializes jLabel
868
     * 
869
     * @return JLabel
870
     */
871
    private JLabel getJLabel() {
872
        if (jLabel == null) {
873
            jLabel = new JLabel();
874
            jLabel.setText(PluginServices.getText(this, "nombre_sesion") + ":");
875
            jLabel.setPreferredSize(new java.awt.Dimension(150, 16));
876
        }
877

    
878
        return jLabel;
879
    }
880

    
881
    /**
882
     * This method initializes lblNombreSesion
883
     * 
884
     * @return JLabel
885
     */
886
    private JLabel getLblNombreSesion() {
887
        if (lblNombreSesion == null) {
888
            lblNombreSesion = new JLabel();
889
            lblNombreSesion.setText("");
890
            lblNombreSesion.setName("lblNombreSesion");
891
            lblNombreSesion.setPreferredSize(new java.awt.Dimension(200, 16));
892
            lblNombreSesion.setAutoscrolls(true);
893
        }
894

    
895
        return lblNombreSesion;
896
    }
897

    
898
    /**
899
     * This method initializes jLabel1
900
     * 
901
     * @return JLabel
902
     */
903
    private JLabel getJLabel1() {
904
        if (jLabel1 == null) {
905
            jLabel1 = new JLabel();
906
            jLabel1.setText(PluginServices.getText(this, "guardado") + ":");
907
            jLabel1.setPreferredSize(new java.awt.Dimension(150, 16));
908
        }
909

    
910
        return jLabel1;
911
    }
912

    
913
    /**
914
     * This method initializes lblGuardado
915
     * 
916
     * @return JLabel
917
     */
918
    private JLabel getLblGuardado() {
919
        if (lblGuardado == null) {
920
            lblGuardado = new JLabel();
921
            lblGuardado.setText("");
922
            lblGuardado.setPreferredSize(new java.awt.Dimension(200, 16));
923
            lblGuardado.setAutoscrolls(true);
924
        }
925

    
926
        return lblGuardado;
927
    }
928

    
929
    /**
930
     * This method initializes jLabel2
931
     * 
932
     * @return JLabel
933
     */
934
    private JLabel getJLabel2() {
935
        if (jLabel2 == null) {
936
            jLabel2 = new JLabel();
937
            jLabel2
938
                .setText(PluginServices.getText(this, "creation_date") + ":");
939
            jLabel2.setPreferredSize(new java.awt.Dimension(150, 16));
940
        }
941

    
942
        return jLabel2;
943
    }
944

    
945
    /**
946
     * This method initializes lblFecha
947
     * 
948
     * @return JLabel
949
     */
950
    private JLabel getLblFecha() {
951
        if (lblFecha == null) {
952
            lblFecha = new JLabel();
953
            lblFecha.setText("");
954
            lblFecha.setPreferredSize(new java.awt.Dimension(200, 16));
955
            lblFecha.setAutoscrolls(true);
956
        }
957

    
958
        return lblFecha;
959
    }
960

    
961
    /**
962
     * This method initializes btnImportar
963
     * 
964
     * @return JButton
965
     */
966
    private JButton getBtnImportar() {
967
        if (btnImportar == null) {
968
            btnImportar = new JButton();
969
            btnImportar.setPreferredSize(new java.awt.Dimension(80, 23));
970
            btnImportar.setText(PluginServices.getText(this, "importar"));
971
            btnImportar.setName("btnImportar");
972
            btnImportar.setMargin(new java.awt.Insets(2, 2, 2, 2));
973
            // TODO implement import
974
            btnImportar.setVisible(false);
975
        }
976

    
977
        return btnImportar;
978
    }
979

    
980
    /**
981
     * This method initializes btnExportar
982
     * 
983
     * @return JButton
984
     */
985
    private JButton getBtnExportar() {
986
        if (btnExportar == null) {
987
            btnExportar = new JButton();
988
            btnExportar.setPreferredSize(new java.awt.Dimension(80, 23));
989
            btnExportar.setText(PluginServices.getText(this, "exportar"));
990
            btnExportar.setName("btnExportar");
991
            btnExportar.setMargin(new java.awt.Insets(2, 2, 2, 2));
992
            // TODO implement export
993
            btnExportar.setVisible(false);
994
        }
995

    
996
        return btnExportar;
997
    }
998

    
999
    /**
1000
     * This method initializes btnEditar
1001
     * 
1002
     * @return JButton
1003
     */
1004
    private JButton getBtnEditar() {
1005
        if (btnEditar == null) {
1006
            btnEditar = new JButton();
1007
            btnEditar.setPreferredSize(new java.awt.Dimension(80, 23));
1008
            btnEditar.setText(PluginServices.getText(this, "propiedades"));
1009

    
1010
            btnEditar.setName("btnEditar");
1011
            btnEditar.setMargin(new java.awt.Insets(2, 2, 2, 2));
1012

    
1013
            btnEditar.addActionListener(new java.awt.event.ActionListener() {
1014

    
1015
                public void actionPerformed(java.awt.event.ActionEvent e) {
1016
                    ProjectProperties dlg = new ProjectProperties(project);
1017
                    PluginServices.getMDIManager().addWindow(dlg);
1018
                    refreshProperties();
1019
                }
1020
            });
1021
        }
1022

    
1023
        return btnEditar;
1024
    }
1025

    
1026
    /**
1027
     * This method initializes jScrollPane
1028
     * 
1029
     * @return JScrollPane
1030
     */
1031
    private JScrollPane getJScrollPane() {
1032
        if (jScrollPane == null) {
1033
            jScrollPane = new JScrollPane();
1034
            jScrollPane.setViewportView(getLstDocs());
1035
            jScrollPane.setPreferredSize(new java.awt.Dimension(200, 100));
1036
            jScrollPane
1037
                .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
1038
        }
1039

    
1040
        return jScrollPane;
1041
    }
1042

    
1043
    /**
1044
     * @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
1045
     */
1046
    public Object getWindowModel() {
1047
        return project;
1048
    }
1049

    
1050
    public Project getProject() {
1051
        return project;
1052
    }
1053

    
1054
    /**
1055
     * This method is used to get <strong>an initial</strong> ViewInfo object
1056
     * for this Project Manager window. It is not intended to retrieve the
1057
     * ViewInfo object in a later time. <strong>Use
1058
     * PluginServices.getMDIManager().getViewInfo(view) to retrieve the ViewInfo
1059
     * object at any time after the creation of the object.
1060
     * 
1061
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
1062
     */
1063
    public WindowInfo getWindowInfo() {
1064
        if (m_viewInfo == null) {
1065
            m_viewInfo = new WindowInfo(WindowInfo.MAXIMIZABLE);
1066
            // m_viewInfo = new
1067
            // ViewInfo(ViewInfo.MAXIMIZABLE+ViewInfo.RESIZABLE);
1068
            m_viewInfo.setWidth(this.getWidth());
1069
            m_viewInfo.setHeight(this.getHeight());
1070
            m_viewInfo.setNormalWidth(this.getPreferredSize().width);
1071
            m_viewInfo.setNormalHeight(this.getPreferredSize().height);
1072

    
1073
            m_viewInfo.setTitle(PluginServices.getText(this, "titulo"));
1074
        }
1075
        return m_viewInfo;
1076
    }
1077

    
1078
    public void propertyChange(PropertyChangeEvent evt) {
1079
        refreshControls();
1080
    }
1081

    
1082
    /**
1083
     * This method initializes jPanel4
1084
     * 
1085
     * @return JPanel
1086
     */
1087
    private JPanel getJPanel4() {
1088
        if (jPanel4 == null) {
1089
            jPanel4 = new JPanel();
1090

    
1091
            jPanel4.setLayout(new FlowLayout(FlowLayout.RIGHT));
1092
            jPanel4.setPreferredSize(new java.awt.Dimension(414, 30));
1093
            jPanel4
1094
                .setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT);
1095
            jPanel4.add(getBtnImportar(), null);
1096
            jPanel4.add(getBtnExportar(), null);
1097
            jPanel4.add(getBtnEditar(), null);
1098
        }
1099

    
1100
        return jPanel4;
1101
    }
1102

    
1103
    /**
1104
     * This method initializes jScrollPane1
1105
     * 
1106
     * @return javax.swing.JScrollPane
1107
     */
1108
    private JScrollPane getJScrollPane1() {
1109
        if (jScrollPane1 == null) {
1110
            jScrollPane1 = new JScrollPane();
1111
            jScrollPane1
1112
                .setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_NEVER);
1113
            jScrollPane1.setPreferredSize(new java.awt.Dimension(433, 200));
1114
            jScrollPane1.setViewportView(getJPanel());
1115
        }
1116
        return jScrollPane1;
1117
    }
1118

    
1119
    public Object getWindowProfile() {
1120
        return WindowInfo.PROJECT_PROFILE;
1121
    }
1122

    
1123
    public void update(Observable observable, Object notification) {
1124
        if (observable instanceof ProjectManager) {
1125
            refreshDocuments();
1126
        }
1127
    }
1128

    
1129
    private void refreshDocuments() {
1130
        // Setting it to null will make it recreate in the next
1131
        // getBtnDocuments() call
1132
        this.btnsDocuments = null;
1133

    
1134
        // Clear previous document type buttons
1135
        jPanel.removeAll();
1136
        for (Enumeration<AbstractButton> buttons = grupo.getElements(); buttons
1137
            .hasMoreElements();) {
1138
            grupo.remove(buttons.nextElement());
1139
        }
1140

    
1141
        JRadioButton[] btnDocuments = getBtnDocuments();
1142
        for (int i = 0; i < btnDocuments.length; i++) {
1143
            grupo.add(btnDocuments[i]);
1144
        }
1145
        if (btnDocuments.length > 0) {
1146
            btnDocuments[0].setSelected(true);
1147
        }
1148
        fillDocumentTypeButtons();
1149
    }
1150

    
1151
}