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 @ 40558

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
    }
311

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

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

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

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

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

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

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

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

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

    
393
        }
394
        doc.setName(nuevoNombre);
395

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

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

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

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

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

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

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

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

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

    
479
            documentTypes = new JScrollPane(documentTypesList);
480
            Dimension dim = documentTypesList.getPreferredSize();
481
            documentTypes.setMinimumSize(new Dimension(dim.width,
482
                dim.height + 35));
483
            documentTypes.setBorder(BorderFactory.createTitledBorder(null,
484
                PluginServices.getText(this, "tipos_de_documentos"),
485
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
486
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
487
        }
488

    
489
        return documentTypes;
490
    }
491

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

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

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

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

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

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

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

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

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

    
554
            documentsPanel.setLayout(layout2);
555

    
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
            documentsPanel.add(getDocumentsScrollPane(), c);
562

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

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

    
577
        return documentsPanel;
578
    }
579

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

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

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

    
607
                    return null;
608
                }
609

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

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

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

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

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

    
650
        return lstDocs;
651
    }
652

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

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

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

    
674
        return jPanel2;
675
    }
676

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

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

    
701
        return btnNuevo;
702
    }
703

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

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

    
726
        return btnPropiedades;
727
    }
728

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

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

    
749
        return btnAbrir;
750
    }
751

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

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

    
772
        return btnBorrar;
773
    }
774

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

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

    
795
        return btnRenombrar;
796
    }
797

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

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

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

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

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

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

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

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

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

    
856
        return propertiesPanel;
857
    }
858

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

    
870
        return jLabel;
871
    }
872

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

    
886
        return lblNombreSesion;
887
    }
888

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

    
900
        return jLabel1;
901
    }
902

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

    
915
        return lblGuardado;
916
    }
917

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

    
930
        return jLabel2;
931
    }
932

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

    
945
        return lblFecha;
946
    }
947

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

    
962
        return btnImportar;
963
    }
964

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

    
979
        return btnExportar;
980
    }
981

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

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

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

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

    
1006
        return btnEditar;
1007
    }
1008

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

    
1024
        return documentsScrollPane;
1025
    }
1026

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

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

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

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

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

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

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

    
1092
        return projectButtonsPanel;
1093
    }
1094

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

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

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

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

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

    
1127
}