Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / gui / ProjectWindow.java @ 41003

History | View | Annotate | Download (35.3 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.project.documents.gui;
25

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

    
43
import javax.swing.AbstractButton;
44
import javax.swing.BorderFactory;
45
import javax.swing.ButtonGroup;
46
import javax.swing.JButton;
47
import javax.swing.JComponent;
48
import javax.swing.JDialog;
49
import javax.swing.JLabel;
50
import javax.swing.JList;
51
import javax.swing.JOptionPane;
52
import javax.swing.JPanel;
53
import javax.swing.JRadioButton;
54
import javax.swing.JScrollPane;
55
import javax.swing.ScrollPaneConstants;
56
import javax.swing.SwingUtilities;
57
import javax.swing.border.TitledBorder;
58

    
59
import org.gvsig.andami.PluginServices;
60
import org.gvsig.andami.help.Help;
61
import org.gvsig.andami.messages.NotificationManager;
62
import org.gvsig.andami.ui.mdiManager.IWindow;
63
import org.gvsig.andami.ui.mdiManager.MDIManager;
64
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
65
import org.gvsig.andami.ui.mdiManager.WindowInfo;
66
import org.gvsig.app.extension.ProjectExtension;
67
import org.gvsig.app.project.Project;
68
import org.gvsig.app.project.ProjectManager;
69
import org.gvsig.app.project.documents.AbstractDocument;
70
import org.gvsig.app.project.documents.Document;
71
import org.gvsig.app.project.documents.DocumentManager;
72
import org.gvsig.tools.observer.Observable;
73
import org.gvsig.tools.observer.Observer;
74
import org.gvsig.tools.swing.api.ToolsSwingLocator;
75
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
76
import org.gvsig.utils.DefaultListModel;
77

    
78
/**
79
 * Clase principal del proyecto donde se puede operar para crear cualquier tipo
80
 * de documento.
81
 * 
82
 * @author Vicente Caballero Navarro
83
 * @author gvSIG team
84
 */
85
public class ProjectWindow extends JPanel implements PropertyChangeListener,
86
    IWindow, SingletonWindow, Observer {
87

    
88
    private static final long serialVersionUID = 7315293357719796556L;
89

    
90
    public static final String PERSISTENCE_DEFINITION_NAME = "ProjectWindow";
91

    
92
    private JScrollPane documentTypes = null;
93
    private JPanel documentTypesList = null;
94
    private JRadioButton[] btnsDocuments = null;
95
    private ButtonGroup grupo = new ButtonGroup();
96
    private JPanel documentsPanel = null;
97
    private JList lstDocs = null;
98
    private JPanel jPanel2 = null;
99
    private JButton btnNuevo = null;
100
    private JButton btnPropiedades = null;
101
    private JButton btnAbrir = null;
102
    private JButton btnBorrar = null;
103
    private JButton btnRenombrar = null;
104
    private JPanel propertiesPanel = null;
105
    private JLabel jLabel = null;
106
    private JLabel lblNombreSesion = null;
107
    private JLabel jLabel1 = null;
108
    private JLabel lblGuardado = null;
109
    private JLabel jLabel2 = null;
110
    private JLabel lblFecha = null;
111
    private JButton btnImportar = null;
112
    private JButton btnExportar = null;
113
    private JButton btnEditar = null;
114
    // The properties of the Project Manager window (size, position, etc):
115
    private WindowInfo m_viewInfo = null;
116

    
117
    private Project project;
118
    private UsabilitySwingManager manager = ToolsSwingLocator
119
        .getUsabilitySwingManager();
120

    
121
    private JScrollPane documentsScrollPane = null;
122
    private JPanel projectButtonsPanel = null;
123

    
124
    /**
125
     * This is the default constructor
126
     * 
127
     * @param project
128
     *            Extension
129
     */
130
    public ProjectWindow() {
131
        super();
132
        initialize();
133
        refreshControls();
134
        Help.getHelp().enableHelp(this, this.getClass().getName());
135
        // Observe document factory registration changes
136
        ProjectManager.getInstance().addObserver(this);
137
    }
138

    
139
    /**
140
     * Asigna el proyecto a la ventana
141
     * 
142
     * @param project
143
     *            Proyecto con el que se operar? a trav?s de este di?logo
144
     */
145
    public void setProject(Project project) {
146
        this.project = project;
147
        project.addPropertyChangeListener(this);
148
        refreshControls();
149
    }
150

    
151
    /**
152
     * Activa los botones de la botonera del medio o los desactiva en funci?n de
153
     * que est? seleccionado o no un elemento de proyecto en la lista del medio
154
     */
155
    private void activarBotones() {
156
        if (lstDocs.getSelectedIndex() != -1) {
157
            btnAbrir.setEnabled(true);
158
            btnBorrar.setEnabled(true);
159
            if (lstDocs.getSelectedIndices().length == 1) {
160
                btnRenombrar.setEnabled(true);
161
                btnPropiedades.setEnabled(true);
162
            } else {
163
                btnRenombrar.setEnabled(false);
164
                btnPropiedades.setEnabled(false);
165
            }
166
        } else {
167
            btnAbrir.setEnabled(false);
168
            btnBorrar.setEnabled(false);
169
            btnRenombrar.setEnabled(false);
170
            btnPropiedades.setEnabled(false);
171
        }
172
    }
173

    
174
    /**
175
     * Refresca la lista de elementos de proyecto con vistas, mapas o tablas,
176
     * seg?n la opci?n activada
177
     */
178
    private void refreshList() {
179
        if (project != null) {
180
            DefaultListModel model = null;
181
            String tituloMarco =
182
                PluginServices.getText(this, "documentos_existentes");
183

    
184
            String doctype = getDocumentSelected();
185
            model = new DefaultListModel(project.getDocuments(doctype));
186
            tituloMarco = getDocumentSelectedName();
187

    
188
            lstDocs.setModel(model);
189
            ((TitledBorder) getDocumentsPanel().getBorder())
190
                .setTitle(tituloMarco);
191
            getDocumentsPanel().repaint(1);
192
            activarBotones();
193
        }
194
    }
195

    
196
    /**
197
     * Devuelve el nombre del tipo de documento activo (el mismo que
198
     * ProjectDocumentFactory.getRegisterName)
199
     * 
200
     * 
201
     * @return
202
     */
203

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

    
213
        return null;
214
    }
215

    
216
    private String getDocumentSelectedName() {
217
        JRadioButton btnSelected = null;
218
        for (int i = 0; i < btnsDocuments.length; i++) {
219
            if (btnsDocuments[i].isSelected()) {
220
                btnSelected = btnsDocuments[i];
221
                return btnSelected.getText();
222
            }
223
        }
224

    
225
        return null;
226
    }
227

    
228
    /**
229
     * Refresca las etiquetas con la informaci?n del proyecto
230
     */
231
    private void refreshProperties() {
232
        if (project != null) {
233
            lblNombreSesion.setText(project.getName());
234
            String path = ProjectExtension.getPath();
235
            if (path != null) {
236
                File f = new File(path);
237
                lblGuardado.setText(f.toString());
238
            } else {
239
                lblGuardado.setText("");
240
            }
241
            lblFecha.setText(project.getCreationDate());
242
        }
243
    }
244

    
245
    /**
246
     * Refresca todo el di?logo
247
     */
248
    public void refreshControls() {
249
        refreshList();
250
        refreshProperties();
251
    }
252

    
253
    /**
254
     * This method initializes this
255
     */
256
    private void initialize() {
257
        this.setLayout(new GridBagLayout());
258
        GridBagConstraints c = new GridBagConstraints();
259
        c.insets = new Insets(2, 5, 2, 5);
260

    
261
        c.fill = GridBagConstraints.HORIZONTAL;
262
        c.weightx = 1.0d;
263
        c.weighty = 0.0d;
264
        c.gridy = 0;
265
        add(getDocumentTypesPanel(), c);
266

    
267
        c.fill = GridBagConstraints.BOTH;
268
        c.gridy = 1;
269
        c.weightx = 1.0d;
270
        c.weighty = 1.0d;
271
        add(getDocumentsPanel(), c);
272

    
273
        c.fill = GridBagConstraints.HORIZONTAL;
274
        c.weightx = 1.0d;
275
        c.weighty = 0.0d;
276
        c.gridy = 2;
277
        add(getPropertiesPanel(), c);
278

    
279
        this.setMinimumSize(this.getPreferredSize());
280
        refreshDocuments();
281
    }
282

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

    
301
    /**
302
     * Crea un nuevo project element
303
     * 
304
     * @throws Exception
305
     *             DOCUMENT ME!
306
     */
307
    private void newProjectDocument() throws Exception {
308
        String doctype = getDocumentSelected();
309
        createDocumentsInProject(doctype);
310
        lstDocs.setSelectedIndex(lstDocs.getModel().getSize()-1);
311
    }
312

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

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

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

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

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

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

    
376
        String nuevoNombre = pane.getInputValue().toString().trim();
377

    
378
        if (nuevoNombre.length() == 0) {
379
            return;
380
        }
381

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

    
394
        }
395
        doc.setName(nuevoNombre);
396

    
397
        refreshList();
398
        project.setModified(true);
399
    }
400

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

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

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

    
446
        if (index == -1) {
447
            return;
448
        }
449

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

    
462
        refreshControls();
463
        lstDocs.setSelectedIndex(index);
464
        project.setModified(true);
465
    }
466

    
467
    /**
468
     * This method initializes jPanel
469
     * 
470
     * @return JPanel
471
     */
472
    private JComponent getDocumentTypesPanel() {
473
        if (documentTypes == null) {
474

    
475
            documentTypesList =
476
                new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
477
            documentTypesList.setName("tipoDocPanel");
478
            fillDocumentTypeButtons();
479

    
480
            documentTypes = new JScrollPane(documentTypesList);
481
            Dimension dim = documentTypesList.getPreferredSize();
482
            documentTypes.setMinimumSize(new Dimension(dim.width,
483
                dim.height + 35));
484
            documentTypes.setBorder(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 documentTypes;
491
    }
492

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

    
503
    /**
504
     * This method initializes btnVistas
505
     * 
506
     * @return JRadioButton
507
     */
508
    private JRadioButton[] getBtnDocumentTypes() {
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 getDocumentsPanel() {
549
        if (documentsPanel == null) {
550
            documentsPanel = new JPanel();
551

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

    
555
            documentsPanel.setLayout(layout2);
556

    
557
            c.insets = new Insets(2, 5, 2, 5);
558
            c.anchor = GridBagConstraints.WEST;
559
            c.fill = GridBagConstraints.BOTH;
560
            c.weightx = 1.0;
561
            c.weighty = 1.0;
562
            documentsPanel.add(getDocumentsScrollPane(), c);
563

    
564
            c.anchor = GridBagConstraints.EAST;
565
            c.fill = GridBagConstraints.NONE;
566
            c.weightx = 0;
567
            c.weighty = 0;
568
            documentsPanel.add(getDocumentButtonsPanel(), c);
569

    
570
            documentsPanel.setBorder(javax.swing.BorderFactory
571
                .createTitledBorder(null,
572
                    PluginServices.getText(this, "documentos_existentes"),
573
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
574
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
575
                    null));
576
        }
577

    
578
        return documentsPanel;
579
    }
580

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

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

    
603
                public AbstractDocument getItem(java.awt.event.MouseEvent e) {
604
                    if (lstDocs.getSelectedIndex() < 0) {
605
                        return null;
606
                    }
607

    
608
                    return null;
609
                }
610

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

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

    
635
                    if (e.getClickCount() == 2) {
636
                        abrir();
637
                    }
638

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

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

    
651
        return lstDocs;
652
    }
653

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

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

    
667
            jPanel2.setLayout(layout);
668
            jPanel2.add(getBtnNuevo(), null);
669
            jPanel2.add(getBtnAbrir(), null);
670
            jPanel2.add(getBtnRenombrar(), null);
671
            jPanel2.add(getBtnBorrar(), null);
672
            jPanel2.add(getBtnPropiedades(), null);
673
        }
674

    
675
        return jPanel2;
676
    }
677

    
678
    /**
679
     * This method initializes btnNuevo
680
     * 
681
     * @return JButton
682
     */
683
    private JButton getBtnNuevo() {
684
        if (btnNuevo == null) {
685
            btnNuevo = manager.createJButton();
686
            btnNuevo.setName("btnNuevo");
687
            btnNuevo.setText(PluginServices.getText(this, "nuevo"));
688
            btnNuevo.setMargin(new java.awt.Insets(2, 2, 2, 2));
689
            btnNuevo.addActionListener(new java.awt.event.ActionListener() {
690

    
691
                public void actionPerformed(java.awt.event.ActionEvent e) {
692
                    try {
693
                        newProjectDocument();
694
                    } catch (Exception e1) {
695
                        NotificationManager.addError(e1.getLocalizedMessage(),
696
                            e1);
697
                    }
698
                }
699
            });
700
        }
701

    
702
        return btnNuevo;
703
    }
704

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

    
721
                    public void actionPerformed(java.awt.event.ActionEvent e) {
722
                        propiedades();
723
                    }
724
                });
725
        }
726

    
727
        return btnPropiedades;
728
    }
729

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

    
744
                public void actionPerformed(java.awt.event.ActionEvent e) {
745
                    abrir();
746
                }
747
            });
748
        }
749

    
750
        return btnAbrir;
751
    }
752

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

    
767
                public void actionPerformed(java.awt.event.ActionEvent e) {
768
                    borrar();
769
                }
770
            });
771
        }
772

    
773
        return btnBorrar;
774
    }
775

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

    
790
                public void actionPerformed(java.awt.event.ActionEvent e) {
791
                    renombrar();
792
                }
793
            });
794
        }
795

    
796
        return btnRenombrar;
797
    }
798

    
799
    /**
800
     * This method initializes jPanel3
801
     * 
802
     * @return JPanel
803
     */
804
    private JPanel getPropertiesPanel() {
805
        if (propertiesPanel == null) {
806
            propertiesPanel = new JPanel(new GridBagLayout());
807
            GridBagConstraints c = new GridBagConstraints();
808

    
809
            c.insets = new Insets(2, 5, 0, 5);
810
            c.anchor = GridBagConstraints.WEST;
811
            c.gridx = 0;
812
            c.gridy = 0;
813
            propertiesPanel.add(getJLabel(), c);
814

    
815
            c.fill = GridBagConstraints.HORIZONTAL;
816
            c.weightx = 1.0;
817
            c.gridx = 1;
818
            propertiesPanel.add(getLblNombreSesion(), c);
819

    
820
            c.gridx = 0;
821
            c.gridy = 1;
822
            c.fill = GridBagConstraints.NONE;
823
            c.weightx = 0.0;
824
            propertiesPanel.add(getJLabel1(), c);
825

    
826
            c.fill = GridBagConstraints.HORIZONTAL;
827
            c.weightx = 1.0;
828
            c.gridx = 1;
829
            propertiesPanel.add(getLblGuardado(), c);
830

    
831
            c.gridx = 0;
832
            c.gridy = 2;
833
            c.fill = GridBagConstraints.NONE;
834
            c.weightx = 0.0;
835
            propertiesPanel.add(getJLabel2(), c);
836

    
837
            c.fill = GridBagConstraints.HORIZONTAL;
838
            c.weightx = 1.0;
839
            c.gridx = 1;
840
            propertiesPanel.add(getLblFecha(), c);
841

    
842
            c.gridx = 0;
843
            c.gridwidth = 2;
844
            c.gridy = 4;
845
            c.fill = GridBagConstraints.HORIZONTAL;
846
            c.anchor = GridBagConstraints.EAST;
847
            propertiesPanel.add(getProjectsButtonPanel(), c);
848

    
849
            propertiesPanel.setBorder(javax.swing.BorderFactory
850
                .createTitledBorder(null,
851
                    PluginServices.getText(this, "propiedades_sesion"),
852
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
853
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
854
                    null));
855
        }
856

    
857
        return propertiesPanel;
858
    }
859

    
860
    /**
861
     * This method initializes jLabel
862
     * 
863
     * @return JLabel
864
     */
865
    private JLabel getJLabel() {
866
        if (jLabel == null) {
867
            jLabel = new JLabel();
868
            jLabel.setText(PluginServices.getText(this, "nombre_sesion") + ":");
869
        }
870

    
871
        return jLabel;
872
    }
873

    
874
    /**
875
     * This method initializes lblNombreSesion
876
     * 
877
     * @return JLabel
878
     */
879
    private JLabel getLblNombreSesion() {
880
        if (lblNombreSesion == null) {
881
            lblNombreSesion = new JLabel();
882
            lblNombreSesion.setText("");
883
            lblNombreSesion.setName("lblNombreSesion");
884
            lblNombreSesion.setAutoscrolls(true);
885
        }
886

    
887
        return lblNombreSesion;
888
    }
889

    
890
    /**
891
     * This method initializes jLabel1
892
     * 
893
     * @return JLabel
894
     */
895
    private JLabel getJLabel1() {
896
        if (jLabel1 == null) {
897
            jLabel1 = new JLabel();
898
            jLabel1.setText(PluginServices.getText(this, "guardado") + ":");
899
        }
900

    
901
        return jLabel1;
902
    }
903

    
904
    /**
905
     * This method initializes lblGuardado
906
     * 
907
     * @return JLabel
908
     */
909
    private JLabel getLblGuardado() {
910
        if (lblGuardado == null) {
911
            lblGuardado = new JLabel();
912
            lblGuardado.setText("");
913
            lblGuardado.setAutoscrolls(true);
914
        }
915

    
916
        return lblGuardado;
917
    }
918

    
919
    /**
920
     * This method initializes jLabel2
921
     * 
922
     * @return JLabel
923
     */
924
    private JLabel getJLabel2() {
925
        if (jLabel2 == null) {
926
            jLabel2 = new JLabel();
927
            jLabel2
928
                .setText(PluginServices.getText(this, "creation_date") + ":");
929
        }
930

    
931
        return jLabel2;
932
    }
933

    
934
    /**
935
     * This method initializes lblFecha
936
     * 
937
     * @return JLabel
938
     */
939
    private JLabel getLblFecha() {
940
        if (lblFecha == null) {
941
            lblFecha = new JLabel();
942
            lblFecha.setText("");
943
            lblFecha.setAutoscrolls(true);
944
        }
945

    
946
        return lblFecha;
947
    }
948

    
949
    /**
950
     * This method initializes btnImportar
951
     * 
952
     * @return JButton
953
     */
954
    private JButton getBtnImportar() {
955
        if (btnImportar == null) {
956
            btnImportar = manager.createJButton();
957
            btnImportar.setPreferredSize(new java.awt.Dimension(80, 23));
958
            btnImportar.setText(PluginServices.getText(this, "importar"));
959
            btnImportar.setName("btnImportar");
960
            btnImportar.setMargin(new java.awt.Insets(2, 2, 2, 2));
961
        }
962

    
963
        return btnImportar;
964
    }
965

    
966
    /**
967
     * This method initializes btnExportar
968
     * 
969
     * @return JButton
970
     */
971
    private JButton getBtnExportar() {
972
        if (btnExportar == null) {
973
            btnExportar = manager.createJButton();
974
            btnExportar.setPreferredSize(new java.awt.Dimension(80, 23));
975
            btnExportar.setText(PluginServices.getText(this, "exportar"));
976
            btnExportar.setName("btnExportar");
977
            btnExportar.setMargin(new java.awt.Insets(2, 2, 2, 2));
978
        }
979

    
980
        return btnExportar;
981
    }
982

    
983
    /**
984
     * This method initializes btnEditar
985
     * 
986
     * @return JButton
987
     */
988
    private JButton getBtnEditar() {
989
        if (btnEditar == null) {
990
            btnEditar = manager.createJButton();
991
            btnEditar.setPreferredSize(new java.awt.Dimension(80, 23));
992
            btnEditar.setText(PluginServices.getText(this, "propiedades"));
993

    
994
            btnEditar.setName("btnEditar");
995
            btnEditar.setMargin(new java.awt.Insets(2, 2, 2, 2));
996

    
997
            btnEditar.addActionListener(new java.awt.event.ActionListener() {
998

    
999
                public void actionPerformed(java.awt.event.ActionEvent e) {
1000
                    ProjectProperties dlg = new ProjectProperties(project);
1001
                    PluginServices.getMDIManager().addWindow(dlg);
1002
                    refreshProperties();
1003
                }
1004
            });
1005
        }
1006

    
1007
        return btnEditar;
1008
    }
1009

    
1010
    /**
1011
     * This method initializes jScrollPane
1012
     * 
1013
     * @return JScrollPane
1014
     */
1015
    private JScrollPane getDocumentsScrollPane() {
1016
        if (documentsScrollPane == null) {
1017
            documentsScrollPane = new JScrollPane();
1018
            documentsScrollPane.setViewportView(getDocumentsList());
1019
            documentsScrollPane.setPreferredSize(new java.awt.Dimension(200,
1020
                100));
1021
            documentsScrollPane
1022
                .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
1023
        }
1024

    
1025
        return documentsScrollPane;
1026
    }
1027

    
1028
    /**
1029
     * @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
1030
     */
1031
    public Object getWindowModel() {
1032
        return project;
1033
    }
1034

    
1035
    public Project getProject() {
1036
        return project;
1037
    }
1038

    
1039
    /**
1040
     * This method is used to get <strong>an initial</strong> ViewInfo object
1041
     * for this Project Manager window. It is not intended to retrieve the
1042
     * ViewInfo object in a later time. <strong>Use
1043
     * PluginServices.getMDIManager().getViewInfo(view) to retrieve the ViewInfo
1044
     * object at any time after the creation of the object.
1045
     * 
1046
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
1047
     */
1048
    public WindowInfo getWindowInfo() {
1049
        if (m_viewInfo == null) {
1050
            m_viewInfo =
1051
                new WindowInfo(WindowInfo.MAXIMIZABLE | WindowInfo.RESIZABLE);
1052
            m_viewInfo.setWidth(this.getWidth());
1053
            m_viewInfo.setHeight(this.getHeight());
1054
            m_viewInfo.setNormalWidth(this.getPreferredSize().width);
1055
            m_viewInfo.setNormalHeight(this.getPreferredSize().height);
1056
            m_viewInfo.setMinimumSize(getPreferredSize());
1057

    
1058
            m_viewInfo.setTitle(PluginServices.getText(this, "_Project_manager"));
1059
        }
1060
        return m_viewInfo;
1061
    }
1062

    
1063
    public void propertyChange(final PropertyChangeEvent evt) {
1064
                if( !SwingUtilities.isEventDispatchThread() ) {
1065
                        SwingUtilities.invokeLater( new Runnable() {
1066
                                public void run() {
1067
                                        propertyChange(evt);
1068
                                }
1069
                        });
1070
                        return;
1071
                }
1072
        refreshControls();
1073
    }
1074

    
1075
    /**
1076
     * This method initializes jPanel4
1077
     * 
1078
     * @return JPanel
1079
     */
1080
    private JPanel getProjectsButtonPanel() {
1081
        if (projectButtonsPanel == null) {
1082
            projectButtonsPanel = new JPanel();
1083

    
1084
            projectButtonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
1085
            projectButtonsPanel
1086
                .setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT);
1087
            // TODO: implement export and import functions
1088
            // projectButtonsPanel.add(getBtnImportar(), null);
1089
            // projectButtonsPanel.add(getBtnExportar(), null);
1090
            projectButtonsPanel.add(getBtnEditar(), null);
1091
        }
1092

    
1093
        return projectButtonsPanel;
1094
    }
1095

    
1096
    public Object getWindowProfile() {
1097
        return WindowInfo.PROJECT_PROFILE;
1098
    }
1099

    
1100
    public void update(Observable observable, Object notification) {
1101
        if (observable instanceof ProjectManager) {
1102
            refreshDocuments();
1103
        }
1104
    }
1105

    
1106
    private void refreshDocuments() {
1107
        // Setting it to null will make it recreate in the next
1108
        // getBtnDocuments() call
1109
        this.btnsDocuments = null;
1110

    
1111
        // Clear previous document type buttons
1112
        documentTypesList.removeAll();
1113
        for (Enumeration<AbstractButton> buttons = grupo.getElements(); buttons
1114
            .hasMoreElements();) {
1115
            grupo.remove(buttons.nextElement());
1116
        }
1117

    
1118
        JRadioButton[] btnDocuments = getBtnDocumentTypes();
1119
        for (int i = 0; i < btnDocuments.length; i++) {
1120
            grupo.add(btnDocuments[i]);
1121
        }
1122
        if (btnDocuments.length > 0) {
1123
            btnDocuments[0].setSelected(true);
1124
        }
1125
        fillDocumentTypeButtons();
1126
    }
1127

    
1128
}