Statistics
| Revision:

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

History | View | Annotate | Download (36.8 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.tools.swing.api.ToolsSwingLocator;
68
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
69
import org.gvsig.utils.DefaultListModel;
70

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

    
80
    private static final long serialVersionUID = 7315293357719796556L;
81

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

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

    
108
    private Project project;
109
    private UsabilitySwingManager manager =
110
        ToolsSwingLocator.getUsabilitySwingManager();
111

    
112
    private JScrollPane jScrollPane = null;
113
    private JPanel jPanel4 = null;
114
    private JScrollPane jScrollPane1 = null;
115

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

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

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

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

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

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

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

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

    
204
        return null;
205
    }
206

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

    
216
        return null;
217
    }
218

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

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

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

    
261
        layout.setConstraints(getJPanel(), c);
262
        add(getJPanel(), null);
263

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

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

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

    
302
    /**
303
     * Crea un nuevo project element
304
     * 
305
     * @throws Exception
306
     *             DOCUMENT ME!
307
     */
308
    private void newProjectDocument() throws Exception {
309
        String doctype = getDocumentSelected();
310
        createDocumentsInProject(doctype);
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((Component) PluginServices
335
                    .getMainFrame(), PluginServices.getText(this,
336
                    "error_opening_the_document"));
337
                return;
338
            }
339
            PluginServices.getMDIManager().addWindow(window,
340
                GridBagConstraints.FIRST_LINE_END);
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
        if (nuevoNombre == null) {
383
            return;
384
        }
385

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

    
398
        }
399
        doc.setName(nuevoNombre);
400

    
401
        refreshList();
402
        project.setModified(true);
403
    }
404

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

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

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

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

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

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

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

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

    
491
        return jPanel;
492
    }
493

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

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

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

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

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

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

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

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

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

    
556
            jPanel1.setLayout(layout2);
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
            layout2.setConstraints(getJScrollPane(), c);
563
            jPanel1.add(getJScrollPane());
564

    
565
            c.anchor = GridBagConstraints.EAST;
566

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

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

    
581
        return jPanel1;
582
    }
583

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

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

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

    
612
                    return null;
613
                }
614

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

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

    
639
                    if (e.getClickCount() == 2) {
640
                        abrir();
641
                    }
642

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

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

    
655
        return lstDocs;
656
    }
657

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

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

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

    
682
        return jPanel2;
683
    }
684

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

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

    
709
        return btnNuevo;
710
    }
711

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

    
728
                    public void actionPerformed(java.awt.event.ActionEvent e) {
729
                        propiedades();
730
                    }
731
                });
732
        }
733

    
734
        return btnPropiedades;
735
    }
736

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

    
751
                public void actionPerformed(java.awt.event.ActionEvent e) {
752
                    abrir();
753
                }
754
            });
755
        }
756

    
757
        return btnAbrir;
758
    }
759

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

    
774
                public void actionPerformed(java.awt.event.ActionEvent e) {
775
                    borrar();
776
                }
777
            });
778
        }
779

    
780
        return btnBorrar;
781
    }
782

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

    
797
                public void actionPerformed(java.awt.event.ActionEvent e) {
798
                    renombrar();
799
                }
800
            });
801
        }
802

    
803
        return btnRenombrar;
804
    }
805

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

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

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

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

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

    
866
        return jPanel3;
867
    }
868

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

    
881
        return jLabel;
882
    }
883

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

    
898
        return lblNombreSesion;
899
    }
900

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

    
913
        return jLabel1;
914
    }
915

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

    
929
        return lblGuardado;
930
    }
931

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

    
945
        return jLabel2;
946
    }
947

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

    
961
        return lblFecha;
962
    }
963

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

    
980
        return btnImportar;
981
    }
982

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

    
999
        return btnExportar;
1000
    }
1001

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

    
1013
            btnEditar.setName("btnEditar");
1014
            btnEditar.setMargin(new java.awt.Insets(2, 2, 2, 2));
1015

    
1016
            btnEditar.addActionListener(new java.awt.event.ActionListener() {
1017

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

    
1026
        return btnEditar;
1027
    }
1028

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

    
1043
        return jScrollPane;
1044
    }
1045

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

    
1053
    public Project getProject() {
1054
        return project;
1055
    }
1056

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

    
1076
            m_viewInfo.setTitle(PluginServices.getText(this, "titulo"));
1077
        }
1078
        return m_viewInfo;
1079
    }
1080

    
1081
    public void propertyChange(PropertyChangeEvent evt) {
1082
        refreshControls();
1083
    }
1084

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

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

    
1103
        return jPanel4;
1104
    }
1105

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

    
1122
    public Object getWindowProfile() {
1123
        return WindowInfo.PROJECT_PROFILE;
1124
    }
1125

    
1126
    public void update(Observable observable, Object notification) {
1127
        if (observable instanceof ProjectManager) {
1128
            refreshDocuments();
1129
        }
1130
    }
1131

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

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

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

    
1154
}