Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / gui / ProjectWindow.java @ 37413

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.JButton;
43
import javax.swing.JDialog;
44
import javax.swing.JLabel;
45
import javax.swing.JList;
46
import javax.swing.JOptionPane;
47
import javax.swing.JPanel;
48
import javax.swing.JRadioButton;
49
import javax.swing.JScrollPane;
50
import javax.swing.ScrollPaneConstants;
51
import javax.swing.border.TitledBorder;
52

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

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

    
78
    private static final long serialVersionUID = 7315293357719796556L;
79

    
80
    public static final String PERSISTENCE_DEFINITION_NAME = "ProjectWindow";
81

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

    
106
    private Project project;
107

    
108
    private JScrollPane jScrollPane = null;
109
    private JPanel jPanel4 = null;
110
    private JScrollPane jScrollPane1 = null;
111

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

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

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

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

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

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

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

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

    
200
        return null;
201
    }
202

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

    
212
        return null;
213
    }
214

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

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

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

    
257
        layout.setConstraints(getJPanel(), c);
258
        add(getJPanel(), null);
259

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

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

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

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

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

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

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

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

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

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

    
372
        String nuevoNombre = pane.getInputValue().toString().trim();
373

    
374
        if (nuevoNombre.length() == 0) {
375
            return;
376
        }
377

    
378
        if (nuevoNombre == null) {
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((Component) PluginServices
389
                    .getMainFrame(), PluginServices.getText(this,
390
                    "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((Component) PluginServices
407
                .getMainFrame(), PluginServices.getText(this,
408
                "confirmar_borrar"), 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, PluginServices.getText(this,
455
                "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 JPanel getJPanel() {
472
        if (jPanel == null) {
473
            jPanel = new JPanel();
474

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

    
487
        return jPanel;
488
    }
489

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

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

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

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

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

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

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

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

    
549
            GridBagLayout layout2 = new GridBagLayout();
550
            GridBagConstraints c = new GridBagConstraints();
551

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

    
561
            c.anchor = GridBagConstraints.EAST;
562

    
563
            c.fill = GridBagConstraints.NONE;
564
            c.weightx = 0;
565
            c.weighty = 0;
566
            layout2.setConstraints(getJPanel2(), c);
567
            jPanel1.add(getJPanel2());
568

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

    
577
        return jPanel1;
578
    }
579

    
580
    /**
581
     * This method initializes lstDocs
582
     * 
583
     * @return JList
584
     */
585
    private JList getLstDocs() {
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
                    // Component c = lstDocs.getComponentAt(e.getPoint());
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 getJPanel2() {
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
            jPanel2.setPreferredSize(new java.awt.Dimension(100, 150));
674
            jPanel2.setMinimumSize(new java.awt.Dimension(100, 150));
675
            jPanel2.setMaximumSize(new java.awt.Dimension(100, 150));
676
        }
677

    
678
        return jPanel2;
679
    }
680

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

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

    
705
        return btnNuevo;
706
    }
707

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

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

    
729
        return btnPropiedades;
730
    }
731

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

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

    
752
        return btnAbrir;
753
    }
754

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

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

    
775
        return btnBorrar;
776
    }
777

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

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

    
798
        return btnRenombrar;
799
    }
800

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

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

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

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

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

    
861
        return jPanel3;
862
    }
863

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

    
876
        return jLabel;
877
    }
878

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

    
893
        return lblNombreSesion;
894
    }
895

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

    
908
        return jLabel1;
909
    }
910

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

    
924
        return lblGuardado;
925
    }
926

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

    
940
        return jLabel2;
941
    }
942

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

    
956
        return lblFecha;
957
    }
958

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

    
975
        return btnImportar;
976
    }
977

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

    
994
        return btnExportar;
995
    }
996

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

    
1008
            btnEditar.setName("btnEditar");
1009
            btnEditar.setMargin(new java.awt.Insets(2, 2, 2, 2));
1010

    
1011
            btnEditar.addActionListener(new java.awt.event.ActionListener() {
1012

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

    
1021
        return btnEditar;
1022
    }
1023

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

    
1038
        return jScrollPane;
1039
    }
1040

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

    
1048
    public Project getProject() {
1049
        return project;
1050
    }
1051

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

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

    
1076
    public void propertyChange(PropertyChangeEvent evt) {
1077
        refreshControls();
1078
    }
1079

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

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

    
1098
        return jPanel4;
1099
    }
1100

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

    
1117
    public Object getWindowProfile() {
1118
        return WindowInfo.PROJECT_PROFILE;
1119
    }
1120

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

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

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

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

    
1149
}