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

History | View | Annotate | Download (38.8 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
import java.util.Locale;
43

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

    
60
import org.gvsig.andami.PluginServices;
61
import org.gvsig.andami.help.Help;
62
import org.gvsig.andami.messages.NotificationManager;
63
import org.gvsig.andami.ui.mdiManager.IWindow;
64
import org.gvsig.andami.ui.mdiManager.MDIManager;
65
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
66
import org.gvsig.andami.ui.mdiManager.WindowInfo;
67
import org.gvsig.app.ApplicationLocator;
68
import org.gvsig.app.ApplicationManager;
69
import org.gvsig.app.extension.ProjectExtension;
70
import org.gvsig.app.project.Project;
71
import org.gvsig.app.project.ProjectManager;
72
import org.gvsig.app.project.documents.AbstractDocument;
73
import org.gvsig.app.project.documents.Document;
74
import org.gvsig.app.project.documents.DocumentManager;
75
import org.gvsig.tools.ToolsLocator;
76
import org.gvsig.tools.i18n.I18nManager;
77
import org.gvsig.tools.identitymanagement.SimpleIdentityManager;
78
import org.gvsig.tools.observer.Observable;
79
import org.gvsig.tools.observer.Observer;
80
import org.gvsig.tools.swing.api.ToolsSwingLocator;
81
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
82
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
83
import org.gvsig.utils.DefaultListModel;
84

    
85
/**
86
 * Clase principal del proyecto donde se puede operar para crear cualquier tipo
87
 * de documento.
88
 *
89
 * @author Vicente Caballero Navarro
90
 * @author gvSIG team
91
 */
92
public class ProjectWindow extends JPanel implements PropertyChangeListener,
93
    IWindow, SingletonWindow, Observer {
94

    
95
    private static final long serialVersionUID = 7315293357719796556L;
96

    
97
    public static final String PERSISTENCE_DEFINITION_NAME = "ProjectWindow";
98

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

    
124
    private Project project;
125
    private UsabilitySwingManager manager = ToolsSwingLocator
126
        .getUsabilitySwingManager();
127

    
128
    private JScrollPane documentsScrollPane = null;
129
    private JPanel projectButtonsPanel = null;
130

    
131
    /**
132
     * This is the default constructor
133
     *
134
     * @param project
135
     *            Extension
136
     */
137
    public ProjectWindow() {
138
        super();
139
        initialize();
140
        refreshControls();
141
        Help.getHelp().enableHelp(this, this.getClass().getName());
142
        // Observe document factory registration changes
143
        ProjectManager.getInstance().addObserver(this);
144
    }
145

    
146
    /**
147
     * Asigna el proyecto a la ventana
148
     *
149
     * @param project
150
     *            Proyecto con el que se operar? a trav?s de este di?logo
151
     */
152
    public void setProject(Project project) {
153
        this.project = project;
154
        if(project!=null){
155
            project.addPropertyChangeListener(this);
156
        }
157
        refreshControls();
158
    }
159

    
160
    /**
161
     * Activa los botones de la botonera del medio o los desactiva en funci?n de
162
     * que est? seleccionado o no un elemento de proyecto en la lista del medio
163
     */
164
    private void activarBotones() {
165
        if (lstDocs.getSelectedIndex() != -1) {
166
            btnAbrir.setEnabled(true);
167
            btnBorrar.setEnabled(true);
168
            if (lstDocs.getSelectedIndices().length == 1) {
169
                btnRenombrar.setEnabled(true);
170
                btnPropiedades.setEnabled(true);
171
            } else {
172
                btnRenombrar.setEnabled(false);
173
                btnPropiedades.setEnabled(false);
174
            }
175
        } else {
176
            btnAbrir.setEnabled(false);
177
            btnBorrar.setEnabled(false);
178
            btnRenombrar.setEnabled(false);
179
            btnPropiedades.setEnabled(false);
180
        }
181
    }
182

    
183
    /**
184
     * Refresca la lista de elementos de proyecto con vistas, mapas o tablas,
185
     * seg?n la opci?n activada
186
     */
187
    private void refreshList() {
188
        if (project != null) {
189
            DefaultListModel model = null;
190
            String tituloMarco =
191
                PluginServices.getText(this, "documentos_existentes");
192

    
193
            String doctype = getDocumentSelected();
194
            model = new DefaultListModel(project.getDocuments(doctype));
195
            tituloMarco = getDocumentSelectedName();
196
            Object selectedDoc = lstDocs.getSelectedValue();
197
            lstDocs.setModel(model);
198
            if (selectedDoc!=null) {
199
                    lstDocs.setSelectedValue(selectedDoc, false);
200
            }
201

    
202
            ((TitledBorder) getDocumentsPanel().getBorder())
203
                .setTitle(tituloMarco);
204
            getDocumentsPanel().repaint(1);
205
            activarBotones();
206
        }
207
    }
208

    
209
    /**
210
     * Devuelve el nombre del tipo de documento activo (el mismo que
211
     * ProjectDocumentFactory.getRegisterName)
212
     *
213
     *
214
     * @return
215
     */
216

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

    
226
        return null;
227
    }
228

    
229
    private String getDocumentSelectedName() {
230
        JRadioButton btnSelected = null;
231
        for (int i = 0; i < btnsDocuments.length; i++) {
232
            if (btnsDocuments[i].isSelected()) {
233
                btnSelected = btnsDocuments[i];
234
                return btnSelected.getText();
235
            }
236
        }
237

    
238
        return null;
239
    }
240

    
241
    /**
242
     * Refresca las etiquetas con la informaci?n del proyecto
243
     */
244
    private void refreshProperties() {
245
        if (project != null) {
246
            lblNombreSesion.setText(project.getName());
247
            String path = ProjectExtension.getPath();
248
            if (path != null) {
249
                File f = new File(path);
250
                lblGuardado.setText(f.toString());
251
            } else {
252
                lblGuardado.setText("");
253
            }
254
            lblFecha.setText(project.getCreationDate());
255
        }
256
    }
257

    
258
    /**
259
     * Refresca todo el di?logo
260
     */
261
    public void refreshControls() {
262
        refreshList();
263
        refreshProperties();
264
    }
265

    
266
    /**
267
     * This method initializes this
268
     */
269
    private void initialize() {
270
        this.setLayout(new GridBagLayout());
271
        GridBagConstraints c = new GridBagConstraints();
272
        c.insets = new Insets(2, 5, 2, 5);
273

    
274
        c.fill = GridBagConstraints.HORIZONTAL;
275
        c.weightx = 1.0d;
276
        c.weighty = 0.0d;
277
        c.gridy = 0;
278
        add(getDocumentTypesPanel(), c);
279

    
280
        c.fill = GridBagConstraints.BOTH;
281
        c.gridy = 1;
282
        c.weightx = 1.0d;
283
        c.weighty = 1.0d;
284
        add(getDocumentsPanel(), c);
285

    
286
        c.fill = GridBagConstraints.HORIZONTAL;
287
        c.weightx = 1.0d;
288
        c.weighty = 0.0d;
289
        c.gridy = 2;
290
        add(getPropertiesPanel(), c);
291

    
292
        this.setMinimumSize(this.getPreferredSize());
293
        refreshDocuments();
294
    }
295

    
296
    private void createDocumentsInProject(String doctype) {
297
        Iterator<? extends Document> documents =
298
            ProjectManager.getInstance().createDocumentsByUser(doctype);
299
        for (; (documents != null) && (documents.hasNext());) {
300
            try {
301
                Document document = documents.next();
302
                project.add(document);
303
                int index =
304
                    ((DefaultListModel) lstDocs.getModel()).indexOf(document);
305
                lstDocs.setSelectedIndex(index);
306
                lstDocs.requestFocus();
307
                openDocumentWindow(document);
308
            } catch (Exception e) {
309
                NotificationManager.addError(e);
310
            }
311
        }
312
    }
313

    
314
    /**
315
     * Crea un nuevo project element
316
     *
317
     * @throws Exception
318
     *             DOCUMENT ME!
319
     */
320
    private void newProjectDocument() throws Exception {
321
        String doctype = getDocumentSelected();
322
        createDocumentsInProject(doctype);
323
        lstDocs.setSelectedIndex(lstDocs.getModel().getSize()-1);
324
    }
325

    
326
    /**
327
     * Abre la ventana de un nuevo documento
328
     */
329
    private void abrir() {
330
        int[] indexes = lstDocs.getSelectedIndices();
331
        for (int i = indexes.length - 1; i >= 0; i--) {
332
            int index = indexes[i];
333
            if (index == -1) {
334
                return;
335
            }
336
            String doctype = getDocumentSelected();
337
            List<Document> documents = project.getDocuments(doctype);
338
            Document doc = documents.get(index);
339
            if(!doc.isAvailable()){
340
                I18nManager i18nManager = ToolsLocator.getI18nManager();
341
                JOptionPane.showMessageDialog(
342
                    this,
343
                    i18nManager.getTranslation("document_not_available"),
344
                    i18nManager.getTranslation("abrir"),
345
                    JOptionPane.WARNING_MESSAGE);
346
                return;
347
            }
348
            openDocumentWindow(doc);
349
        }
350
    }
351

    
352
    private void openDocumentWindow(Document doc) {
353
        if (doc != null) {
354
            IWindow window = doc.getFactory().getMainWindow(doc);
355
            if (window == null) {
356
                JOptionPane.showMessageDialog(
357
                    (Component) PluginServices.getMainFrame(),
358
                    PluginServices.getText(this, "error_opening_the_document"));
359
                return;
360
            }
361
            PluginServices.getMDIManager().addWindow(window,
362
                MDIManager.ALIGN_FIRST_LINE_END_CASCADE);
363
            project.setModified(true);
364
        }
365
    }
366

    
367
    /**
368
     * Cambia el nombre de un project element
369
     */
370
    private void renombrar() {
371
        int index = lstDocs.getSelectedIndex();
372

    
373
        if (index == -1) {
374
            return;
375
        }
376
        String doctype = getDocumentSelected();
377
        List<Document> documents = project.getDocuments(doctype);
378
        Document doc = documents.get(index);
379

    
380
        JOptionPane pane = new JOptionPane();
381
        pane.setMessage(PluginServices.getText(this, "introduce_nombre"));
382
        pane.setMessageType(JOptionPane.QUESTION_MESSAGE);
383
        pane.setWantsInput(true);
384
        pane.setInitialSelectionValue(doc.getName());
385
        pane.setInputValue(doc.getName());
386
        JDialog dlg =
387
            pane.createDialog((Component) PluginServices.getMainFrame(),
388
                PluginServices.getText(this, "renombrar"));
389
        dlg.setModal(true);
390
        dlg.setVisible(true);
391

    
392
        String nuevoNombre = pane.getInputValue().toString().trim();
393

    
394
        if (nuevoNombre.length() == 0) {
395
            return;
396
        }
397

    
398
        for (int i = 0; i < lstDocs.getModel().getSize(); i++) {
399
            if (i == index) {
400
                continue;
401
            }
402
            if (((AbstractDocument) lstDocs.getModel().getElementAt(i))
403
                .getName().equals(nuevoNombre)) {
404
                JOptionPane.showMessageDialog(
405
                    (Component) PluginServices.getMainFrame(),
406
                    PluginServices.getText(this, "elemento_ya_existe"));
407
                return;
408
            }
409

    
410
        }
411
        doc.setName(nuevoNombre);
412

    
413
        refreshList();
414
        project.setModified(true);
415
    }
416

    
417
    /**
418
     * Borra un project element
419
     */
420
    private void borrar() {
421
        ApplicationManager application = ApplicationLocator.getManager();
422
        I18nManager i18n = ToolsLocator.getI18nManager();
423
        int res = application.confirmDialog(
424
                i18n.getTranslation("confirmar_borrar"),
425
                i18n.getTranslation("borrar"),
426
                JOptionPane.YES_NO_OPTION,
427
                JOptionPane.INFORMATION_MESSAGE,
428
                "Confirm remove document from project"
429
        );
430
        int lastremoved = 0;
431
        if (res == JOptionPane.YES_OPTION) {
432
            int[] indexes = lstDocs.getSelectedIndices();
433
            for (int i = indexes.length - 1; i >= 0; i--) {
434
                int index = indexes[i];
435
                String s = getDocumentSelected();
436
                List<Document> documents = project.getDocuments(s);
437
                Document doc = documents.get(index);
438
                if (doc.isLocked()) {
439
                    application.messageDialog(
440
                        i18n.getTranslation("locked_element_it_cannot_be_deleted"),
441
                        i18n.getTranslation("Information"),
442
                        JOptionPane.INFORMATION_MESSAGE
443
                    );
444
                    return;
445
                }
446
                PluginServices.getMDIManager().closeSingletonWindow(doc);
447
                project.removeDocument(doc);
448
                lastremoved = index;
449
            }
450
            if (lastremoved > lstDocs.getModel().getSize()) {
451
                lastremoved = lstDocs.getModel().getSize();
452
            }
453
            if (lastremoved >= 0) {
454
                lstDocs.setSelectedIndex(lastremoved);
455
            }
456
            project.setModified(true);
457
        }
458
    }
459

    
460
    /**
461
     * Muestra el di?logo de propiedades de un project element
462
     */
463
    private void propiedades() {
464
        int index = lstDocs.getSelectedIndex();
465

    
466
        if (index == -1) {
467
            return;
468
        }
469

    
470
        IWindow dlg = null;
471
        String doctype = getDocumentSelected();
472
        List<Document> documents = project.getDocuments(doctype);
473
        Document doc = documents.get(index);
474
        if(!doc.isAvailable()){
475
            I18nManager i18nManager = ToolsLocator.getI18nManager();
476
            JOptionPane.showMessageDialog(
477
                this,
478
                i18nManager.getTranslation("document_not_available"),
479
                i18nManager.getTranslation("properties"),
480
                JOptionPane.WARNING_MESSAGE);
481
            return;
482
        }
483
        dlg = doc.getFactory().getPropertiesWindow(doc);
484
        PluginServices.getMDIManager().addWindow(dlg);
485

    
486
        refreshControls();
487
        lstDocs.setSelectedIndex(index);
488
        project.setModified(true);
489
    }
490

    
491
    /**
492
     * This method initializes jPanel
493
     *
494
     * @return JPanel
495
     */
496
    private JComponent getDocumentTypesPanel() {
497
        if (documentTypes == null) {
498

    
499
            documentTypesList =
500
                new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
501
            documentTypesList.setName("tipoDocPanel");
502
            fillDocumentTypeButtons();
503

    
504
            documentTypes = new JScrollPane(documentTypesList);
505
            Dimension dim = documentTypesList.getPreferredSize();
506
            documentTypes.setMinimumSize(new Dimension(dim.width,dim.height + 35));
507
            documentTypes.setBorder(BorderFactory.createTitledBorder(null,
508
                PluginServices.getText(this, "tipos_de_documentos"),
509
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
510
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
511
            documentTypes.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
512
            documentTypes.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
513

    
514
        }
515

    
516
        return documentTypes;
517
    }
518

    
519
    /**
520
     * Adds a button for each document type
521
     */
522
    private void fillDocumentTypeButtons() {
523
        JRadioButton[] btns = getBtnDocumentTypes();
524
        for (int i = 0; i < btns.length; i++) {
525
            documentTypesList.add(btns[i]);
526
        }
527
    }
528

    
529
    /**
530
     * This method initializes btnVistas
531
     *
532
     * @return JRadioButton
533
     */
534
    private JRadioButton[] getBtnDocumentTypes() {
535
        if (btnsDocuments == null) {
536

    
537
            List<JRadioButton> btns = new ArrayList<JRadioButton>();
538
            List<DocumentManager> factories =
539
                ProjectManager.getInstance().getDocumentManagers();
540
            Collections.sort(factories, new Comparator<DocumentManager>() {
541

    
542
                public int compare(DocumentManager arg0, DocumentManager arg1) {
543
                    return arg0.getPriority() - arg1.getPriority();
544
                }
545

    
546
            });
547
            SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager();
548
            for (DocumentManager documentFactory : factories) {
549
                if( ! identityManager.getCurrentIdentity().isAuthorized(Document.ACCESS_DOCUMENT_AUTHORIZATION, documentFactory, documentFactory.getTypeName()) ) {
550
                    // throw new UnauthorizedException(Document.ACCESS_DOCUMENT_AUTHORIZATION, documentFactory, documentFactory.getTypeName());
551
                    continue;
552
                }
553
                JRadioButton rb = new JRadioButton();
554

    
555
                rb.setIcon(documentFactory.getIcon());
556
                rb.setSelectedIcon(documentFactory.getIconSelected());
557
                rb.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
558
                rb.setText(documentFactory.getTitle());
559
                rb.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
560
                rb.setName(documentFactory.getTypeName());
561
                rb.addChangeListener(new javax.swing.event.ChangeListener() {
562

    
563
                    public void stateChanged(javax.swing.event.ChangeEvent e) {
564
                        refreshList();
565
                    }
566
                });
567
                btns.add(rb);
568
            }
569
            btnsDocuments = btns.toArray(new JRadioButton[0]);
570
        }
571
        return btnsDocuments;
572
    }
573

    
574
    /**
575
     * This method initializes jPanel1
576
     *
577
     * @return JPanel
578
     */
579
    private JPanel getDocumentsPanel() {
580
        if (documentsPanel == null) {
581
            documentsPanel = new JPanel();
582

    
583
            GridBagLayout layout2 = new GridBagLayout();
584
            GridBagConstraints c = new GridBagConstraints();
585

    
586
            documentsPanel.setLayout(layout2);
587

    
588
            c.insets = new Insets(2, 5, 2, 5);
589
            c.anchor = GridBagConstraints.WEST;
590
            c.fill = GridBagConstraints.BOTH;
591
            c.weightx = 1.0;
592
            c.weighty = 1.0;
593
            documentsPanel.add(getDocumentsScrollPane(), c);
594

    
595
            c.anchor = GridBagConstraints.EAST;
596
            c.fill = GridBagConstraints.NONE;
597
            c.weightx = 0;
598
            c.weighty = 0;
599
            documentsPanel.add(getDocumentButtonsPanel(), c);
600

    
601
            documentsPanel.setBorder(javax.swing.BorderFactory
602
                .createTitledBorder(null,
603
                    PluginServices.getText(this, "documentos_existentes"),
604
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
605
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
606
                    null));
607
        }
608

    
609
        return documentsPanel;
610
    }
611

    
612
    /**
613
     * This method initializes lstDocs
614
     *
615
     * @return JList
616
     */
617
    private JList getDocumentsList() {
618
        if (lstDocs == null) {
619
            lstDocs = new JList();
620
            lstDocs.addMouseListener(new java.awt.event.MouseAdapter() {
621

    
622
                public AbstractDocument[] getSelecteds() {
623
                    if (lstDocs.getSelectedIndex() < 0) {
624
                        return new AbstractDocument[0];
625
                    }
626
                    Object[] seleteds = lstDocs.getSelectedValues();
627
                    AbstractDocument[] returnValue =
628
                        new AbstractDocument[seleteds.length];
629
                    System.arraycopy(seleteds, 0, returnValue, 0,
630
                        seleteds.length);
631
                    return returnValue;
632
                }
633

    
634
                public AbstractDocument getItem(java.awt.event.MouseEvent e) {
635
                    if (lstDocs.getSelectedIndex() < 0) {
636
                        return null;
637
                    }
638

    
639
                    return null;
640
                }
641

    
642
                @Override
643
                public void mouseClicked(java.awt.event.MouseEvent e) {
644
                    if (e.getButton() == java.awt.event.MouseEvent.BUTTON3) {
645
                        /*
646
                         * getDocumentSelected();//ProjectView
647
                         * getDocumentSelectedName();//Vista
648
                         */
649
                        String docType = getDocumentSelected();
650
                        AbstractDocument[] selecteds = this.getSelecteds();
651

    
652
                        if (selecteds == null) {
653
                            return;
654
                        }
655
                        DocumentContextMenu menu =
656
                            new DocumentContextMenu(docType, this.getItem(e),
657
                                selecteds);
658
                        if (!menu.hasActions()) {
659
                            return;
660
                        }
661
                        lstDocs.add(menu);
662
                        menu.show(e.getComponent(), e.getX(), e.getY());
663
                        return;
664
                    }
665

    
666
                    if (e.getClickCount() == 2) {
667
                        abrir();
668
                    }
669

    
670
                }
671
            });
672
            lstDocs
673
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
674

    
675
                    public void valueChanged(
676
                        javax.swing.event.ListSelectionEvent e) {
677
                        activarBotones();
678
                    }
679
                });
680
        }
681

    
682
        return lstDocs;
683
    }
684

    
685
    /**
686
     * This method initializes jPanel2
687
     *
688
     * @return JPanel
689
     */
690
    private JPanel getDocumentButtonsPanel() {
691
        if (jPanel2 == null) {
692
            jPanel2 = new JPanel();
693

    
694
            // FlowLayout layout = new FlowLayout();
695
            GridLayout layout = new GridLayout(5, 1);
696
            layout.setVgap(7);
697

    
698
            jPanel2.setLayout(layout);
699
            jPanel2.add(getBtnNuevo(), null);
700
            jPanel2.add(getBtnAbrir(), null);
701
            jPanel2.add(getBtnRenombrar(), null);
702
            jPanel2.add(getBtnBorrar(), null);
703
            jPanel2.add(getBtnPropiedades(), null);
704
        }
705

    
706
        return jPanel2;
707
    }
708

    
709
    /**
710
     * This method initializes btnNuevo
711
     *
712
     * @return JButton
713
     */
714
    private JButton getBtnNuevo() {
715
        if (btnNuevo == null) {
716
            btnNuevo = manager.createJButton();
717
            btnNuevo.setName("btnNuevo");
718
            btnNuevo.setText(PluginServices.getText(this, "nuevo"));
719
            btnNuevo.setMargin(new java.awt.Insets(2, 2, 2, 2));
720
            btnNuevo.addActionListener(new java.awt.event.ActionListener() {
721

    
722
                public void actionPerformed(java.awt.event.ActionEvent e) {
723
                    try {
724
                        newProjectDocument();
725
                    } catch (Exception e1) {
726
                        NotificationManager.addError(e1.getLocalizedMessage(),
727
                            e1);
728
                    }
729
                }
730
            });
731
        }
732

    
733
        return btnNuevo;
734
    }
735

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

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

    
758
        return btnPropiedades;
759
    }
760

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

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

    
781
        return btnAbrir;
782
    }
783

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

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

    
804
        return btnBorrar;
805
    }
806

    
807
    /**
808
     * This method initializes btnRenombrar
809
     *
810
     * @return JButton
811
     */
812
    private JButton getBtnRenombrar() {
813
        if (btnRenombrar == null) {
814
            btnRenombrar = manager.createJButton();
815
            btnRenombrar.setName("btnRenombrar");
816
            btnRenombrar.setText(PluginServices.getText(this, "renombrar"));
817
            btnRenombrar.setEnabled(false);
818
            btnRenombrar.setMargin(new java.awt.Insets(2, 2, 2, 2));
819
            btnRenombrar.addActionListener(new java.awt.event.ActionListener() {
820

    
821
                public void actionPerformed(java.awt.event.ActionEvent e) {
822
                    renombrar();
823
                }
824
            });
825
        }
826

    
827
        return btnRenombrar;
828
    }
829

    
830
    /**
831
     * This method initializes jPanel3
832
     *
833
     * @return JPanel
834
     */
835
    private JPanel getPropertiesPanel() {
836
        if (propertiesPanel == null) {
837
            propertiesPanel = new JPanel(new GridBagLayout());
838
            GridBagConstraints c = new GridBagConstraints();
839

    
840
            c.insets = new Insets(2, 5, 0, 5);
841
            c.anchor = GridBagConstraints.WEST;
842
            c.gridx = 0;
843
            c.gridy = 0;
844
            propertiesPanel.add(getJLabel(), c);
845

    
846
            c.fill = GridBagConstraints.HORIZONTAL;
847
            c.weightx = 1.0;
848
            c.gridx = 1;
849
            propertiesPanel.add(getLblNombreSesion(), c);
850

    
851
            c.gridx = 0;
852
            c.gridy = 1;
853
            c.fill = GridBagConstraints.NONE;
854
            c.weightx = 0.0;
855
            propertiesPanel.add(getJLabel1(), c);
856

    
857
            c.fill = GridBagConstraints.HORIZONTAL;
858
            c.weightx = 1.0;
859
            c.gridx = 1;
860
            propertiesPanel.add(getLblGuardado(), c);
861

    
862
            c.gridx = 0;
863
            c.gridy = 2;
864
            c.fill = GridBagConstraints.NONE;
865
            c.weightx = 0.0;
866
            propertiesPanel.add(getJLabel2(), c);
867

    
868
            c.fill = GridBagConstraints.HORIZONTAL;
869
            c.weightx = 1.0;
870
            c.gridx = 1;
871
            propertiesPanel.add(getLblFecha(), c);
872

    
873
            c.gridx = 0;
874
            c.gridwidth = 2;
875
            c.gridy = 4;
876
            c.fill = GridBagConstraints.HORIZONTAL;
877
            c.anchor = GridBagConstraints.EAST;
878
            propertiesPanel.add(getProjectsButtonPanel(), c);
879

    
880
            propertiesPanel.setBorder(javax.swing.BorderFactory
881
                .createTitledBorder(null,
882
                    PluginServices.getText(this, "propiedades_sesion"),
883
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
884
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
885
                    null));
886
        }
887

    
888
        return propertiesPanel;
889
    }
890

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

    
902
        return jLabel;
903
    }
904

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

    
918
        return lblNombreSesion;
919
    }
920

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

    
932
        return jLabel1;
933
    }
934

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

    
947
        return lblGuardado;
948
    }
949

    
950
    /**
951
     * This method initializes jLabel2
952
     *
953
     * @return JLabel
954
     */
955
    private JLabel getJLabel2() {
956
        if (jLabel2 == null) {
957
            jLabel2 = new JLabel();
958
            jLabel2
959
                .setText(PluginServices.getText(this, "creation_date") + ":");
960
        }
961

    
962
        return jLabel2;
963
    }
964

    
965
    /**
966
     * This method initializes lblFecha
967
     *
968
     * @return JLabel
969
     */
970
    private JLabel getLblFecha() {
971
        if (lblFecha == null) {
972
            lblFecha = new JLabel();
973
            lblFecha.setText("");
974
            lblFecha.setAutoscrolls(true);
975
        }
976

    
977
        return lblFecha;
978
    }
979

    
980
    /**
981
     * This method initializes btnImportar
982
     *
983
     * @return JButton
984
     */
985
    private JButton getBtnImportar() {
986
        if (btnImportar == null) {
987
            btnImportar = manager.createJButton();
988
            btnImportar.setPreferredSize(new java.awt.Dimension(80, 23));
989
            btnImportar.setText(PluginServices.getText(this, "importar"));
990
            btnImportar.setName("btnImportar");
991
            btnImportar.setMargin(new java.awt.Insets(2, 2, 2, 2));
992
        }
993

    
994
        return btnImportar;
995
    }
996

    
997
    /**
998
     * This method initializes btnExportar
999
     *
1000
     * @return JButton
1001
     */
1002
    private JButton getBtnExportar() {
1003
        if (btnExportar == null) {
1004
            btnExportar = manager.createJButton();
1005
            btnExportar.setPreferredSize(new java.awt.Dimension(80, 23));
1006
            btnExportar.setText(PluginServices.getText(this, "exportar"));
1007
            btnExportar.setName("btnExportar");
1008
            btnExportar.setMargin(new java.awt.Insets(2, 2, 2, 2));
1009
        }
1010

    
1011
        return btnExportar;
1012
    }
1013

    
1014
    /**
1015
     * This method initializes btnEditar
1016
     *
1017
     * @return JButton
1018
     */
1019
    private JButton getBtnEditar() {
1020
        if (btnEditar == null) {
1021
            btnEditar = manager.createJButton();
1022
            btnEditar.setPreferredSize(new java.awt.Dimension(80, 23));
1023
            btnEditar.setText(PluginServices.getText(this, "propiedades"));
1024

    
1025
            btnEditar.setName("btnEditar");
1026
            btnEditar.setMargin(new java.awt.Insets(2, 2, 2, 2));
1027

    
1028
            btnEditar.addActionListener(new java.awt.event.ActionListener() {
1029

    
1030
                public void actionPerformed(java.awt.event.ActionEvent e) {
1031
                    I18nManager i18nManager = ToolsLocator.getI18nManager();
1032
                    WindowManager winmgr = ToolsSwingLocator.getWindowManager();
1033
                    winmgr.showWindow(
1034
                            new ProjectProperties(project),
1035
                            i18nManager.getTranslation("project_properties"),
1036
                            WindowManager.MODE.WINDOW
1037
                    );
1038
                    refreshProperties();
1039
                }
1040
            });
1041
        }
1042

    
1043
        return btnEditar;
1044
    }
1045

    
1046
    /**
1047
     * This method initializes jScrollPane
1048
     *
1049
     * @return JScrollPane
1050
     */
1051
    private JScrollPane getDocumentsScrollPane() {
1052
        if (documentsScrollPane == null) {
1053
            documentsScrollPane = new JScrollPane();
1054
            documentsScrollPane.setViewportView(getDocumentsList());
1055
            documentsScrollPane.setPreferredSize(new java.awt.Dimension(200,100));
1056
            documentsScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
1057
        }
1058

    
1059
        return documentsScrollPane;
1060
    }
1061

    
1062
    /**
1063
     * @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
1064
     */
1065
    public Object getWindowModel() {
1066
        return project;
1067
    }
1068

    
1069
    public Project getProject() {
1070
        return project;
1071
    }
1072

    
1073
    /**
1074
     * This method is used to get <strong>an initial</strong> ViewInfo object
1075
     * for this Project Manager window. It is not intended to retrieve the
1076
     * ViewInfo object in a later time. <strong>Use
1077
     * PluginServices.getMDIManager().getViewInfo(view) to retrieve the ViewInfo
1078
     * object at any time after the creation of the object.
1079
     *
1080
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
1081
     */
1082
    public WindowInfo getWindowInfo() {
1083
        if (m_viewInfo == null) {
1084
            m_viewInfo =
1085
                new WindowInfo(WindowInfo.MAXIMIZABLE | WindowInfo.RESIZABLE);
1086
            m_viewInfo.setWidth(this.getWidth());
1087
            m_viewInfo.setHeight(this.getHeight());
1088
            int w = this.getPreferredSize().width;
1089
            if( w < 450 ) {
1090
                w = 450;
1091
            }
1092
            m_viewInfo.setNormalWidth(w);
1093
            m_viewInfo.setNormalHeight(this.getPreferredSize().height);
1094
            m_viewInfo.setMinimumSize(getPreferredSize());
1095

    
1096
            m_viewInfo.setTitle(PluginServices.getText(this, "_Project_manager"));
1097
        }
1098
        return m_viewInfo;
1099
    }
1100

    
1101
    public void propertyChange(final PropertyChangeEvent evt) {
1102
                if( !SwingUtilities.isEventDispatchThread() ) {
1103
                        SwingUtilities.invokeLater( new Runnable() {
1104
                                public void run() {
1105
                                        propertyChange(evt);
1106
                                }
1107
                        });
1108
                        return;
1109
                }
1110
        refreshControls();
1111
    }
1112

    
1113
    /**
1114
     * This method initializes jPanel4
1115
     *
1116
     * @return JPanel
1117
     */
1118
    private JPanel getProjectsButtonPanel() {
1119
        if (projectButtonsPanel == null) {
1120
            projectButtonsPanel = new JPanel();
1121

    
1122
            projectButtonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
1123
            projectButtonsPanel
1124
                .setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT);
1125
            // TODO: implement export and import functions
1126
            // projectButtonsPanel.add(getBtnImportar(), null);
1127
            // projectButtonsPanel.add(getBtnExportar(), null);
1128
            projectButtonsPanel.add(getBtnEditar(), null);
1129
        }
1130

    
1131
        return projectButtonsPanel;
1132
    }
1133

    
1134
    public Object getWindowProfile() {
1135
        return WindowInfo.PROJECT_PROFILE;
1136
    }
1137

    
1138
    public void update(Observable observable, Object notification) {
1139
        if (observable instanceof ProjectManager) {
1140
            refreshDocuments();
1141
        }
1142
    }
1143

    
1144
    private void refreshDocuments() {
1145
        // Setting it to null will make it recreate in the next
1146
        // getBtnDocuments() call
1147
        this.btnsDocuments = null;
1148

    
1149
        // Clear previous document type buttons
1150
        documentTypesList.removeAll();
1151
        for (Enumeration<AbstractButton> buttons = grupo.getElements(); buttons
1152
            .hasMoreElements();) {
1153
            grupo.remove(buttons.nextElement());
1154
        }
1155

    
1156
        JRadioButton[] btnDocuments = getBtnDocumentTypes();
1157
        for (int i = 0; i < btnDocuments.length; i++) {
1158
            grupo.add(btnDocuments[i]);
1159
        }
1160
        if (btnDocuments.length > 0) {
1161
            btnDocuments[0].setSelected(true);
1162
        }
1163
        fillDocumentTypeButtons();
1164
    }
1165

    
1166
    @Override
1167
    public void setLocale(Locale locale) {
1168
        super.setLocale(locale);
1169

    
1170
        I18nManager i18nManager = ToolsLocator.getI18nManager();
1171

    
1172
        btnNuevo.setText(i18nManager.getTranslation( "nuevo"));
1173
        btnPropiedades.setText(i18nManager.getTranslation("propiedades"));
1174
        btnAbrir.setText(i18nManager.getTranslation("abrir"));
1175
        btnBorrar.setText(i18nManager.getTranslation("borrar"));
1176
        btnRenombrar.setText(i18nManager.getTranslation("renombrar"));
1177

    
1178
        jLabel.setText(i18nManager.getTranslation("nombre_sesion") + ":");
1179
        jLabel1.setText(i18nManager.getTranslation("guardado") + ":");
1180
        jLabel2.setText(i18nManager.getTranslation("creation_date") + ":");
1181

    
1182
        // btnImportar.setText(i18nManager.getTranslation("importar"));
1183
        // btnExportar.setText(i18nManager.getTranslation("exportar"));
1184
        btnEditar.setText(i18nManager.getTranslation("propiedades"));
1185

    
1186
        m_viewInfo.setTitle(i18nManager.getTranslation("_Project_manager"));
1187

    
1188
        TitledBorder border = null;
1189

    
1190
        border = (TitledBorder) propertiesPanel.getBorder();
1191
        border.setTitle(i18nManager.getTranslation("propiedades_sesion"));
1192

    
1193
        border = (TitledBorder) documentTypes.getBorder();
1194
        border.setTitle(i18nManager.getTranslation("tipos_de_documentos"));
1195

    
1196
        border = (TitledBorder) documentsPanel.getBorder();
1197
        border.setTitle(i18nManager.getTranslation("documentos_existentes"));
1198

    
1199
        refreshList();
1200
    }
1201

    
1202

    
1203
}