Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / gui / ProjectWindow.java @ 38608

History | View | Annotate | Download (35 KB)

1 36411 cordinyana
/* gvSIG. Geographic Information System of the Valencian Government
2 7343 caballero
 *
3 36411 cordinyana
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6 7343 caballero
 * 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 36411 cordinyana
 *
11 7343 caballero
 * 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 36411 cordinyana
 *
16 7343 caballero
 * 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 36411 cordinyana
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21 7343 caballero
 */
22 29598 jpiera
package org.gvsig.app.project.documents.gui;
23 7343 caballero
24
import java.awt.Component;
25 37840 cordinyana
import java.awt.Dimension;
26 7343 caballero
import java.awt.FlowLayout;
27
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
29
import java.awt.GridLayout;
30
import java.awt.Insets;
31
import java.beans.PropertyChangeEvent;
32
import java.beans.PropertyChangeListener;
33
import java.io.File;
34
import java.util.ArrayList;
35 31496 jjdelcerro
import java.util.Collections;
36
import java.util.Comparator;
37 36443 cordinyana
import java.util.Enumeration;
38 36631 cordinyana
import java.util.Iterator;
39 31496 jjdelcerro
import java.util.List;
40 7343 caballero
41 36443 cordinyana
import javax.swing.AbstractButton;
42 37840 cordinyana
import javax.swing.BorderFactory;
43 7343 caballero
import javax.swing.ButtonGroup;
44 37413 nfrancisco
import javax.swing.JButton;
45 37840 cordinyana
import javax.swing.JComponent;
46 7343 caballero
import javax.swing.JDialog;
47
import javax.swing.JLabel;
48
import javax.swing.JList;
49
import javax.swing.JOptionPane;
50
import javax.swing.JPanel;
51
import javax.swing.JRadioButton;
52
import javax.swing.JScrollPane;
53 37413 nfrancisco
import javax.swing.ScrollPaneConstants;
54 7343 caballero
import javax.swing.border.TitledBorder;
55
56 29598 jpiera
import org.gvsig.andami.PluginServices;
57
import org.gvsig.andami.help.Help;
58
import org.gvsig.andami.messages.NotificationManager;
59
import org.gvsig.andami.ui.mdiManager.IWindow;
60 38608 jjdelcerro
import org.gvsig.andami.ui.mdiManager.MDIManager;
61 29598 jpiera
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
62
import org.gvsig.andami.ui.mdiManager.WindowInfo;
63
import org.gvsig.app.extension.ProjectExtension;
64
import org.gvsig.app.project.Project;
65 31496 jjdelcerro
import org.gvsig.app.project.ProjectManager;
66 36411 cordinyana
import org.gvsig.app.project.documents.AbstractDocument;
67 31496 jjdelcerro
import org.gvsig.app.project.documents.Document;
68
import org.gvsig.app.project.documents.DocumentManager;
69 36443 cordinyana
import org.gvsig.tools.observer.Observable;
70
import org.gvsig.tools.observer.Observer;
71 37420 nfrancisco
import org.gvsig.tools.swing.api.ToolsSwingLocator;
72
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
73 29598 jpiera
import org.gvsig.utils.DefaultListModel;
74 7343 caballero
75
/**
76 31496 jjdelcerro
 * Clase principal del proyecto donde se puede operar para crear cualquier tipo
77
 * de documento.
78
 *
79 7343 caballero
 * @author Vicente Caballero Navarro
80 37840 cordinyana
 * @author gvSIG team
81 7343 caballero
 */
82
public class ProjectWindow extends JPanel implements PropertyChangeListener,
83 36443 cordinyana
    IWindow, SingletonWindow, Observer {
84 36411 cordinyana
85
    private static final long serialVersionUID = 7315293357719796556L;
86 34833 fdiaz
87 36411 cordinyana
    public static final String PERSISTENCE_DEFINITION_NAME = "ProjectWindow";
88 7343 caballero
89 37840 cordinyana
    private JScrollPane documentTypes = null;
90
    private JPanel documentTypesList = null;
91 36411 cordinyana
    private JRadioButton[] btnsDocuments = null;
92
    private ButtonGroup grupo = new ButtonGroup();
93 37840 cordinyana
    private JPanel documentsPanel = null;
94 36411 cordinyana
    private JList lstDocs = null;
95
    private JPanel jPanel2 = null;
96
    private JButton btnNuevo = null;
97
    private JButton btnPropiedades = null;
98
    private JButton btnAbrir = null;
99
    private JButton btnBorrar = null;
100
    private JButton btnRenombrar = null;
101 37840 cordinyana
    private JPanel propertiesPanel = null;
102 36411 cordinyana
    private JLabel jLabel = null;
103
    private JLabel lblNombreSesion = null;
104
    private JLabel jLabel1 = null;
105
    private JLabel lblGuardado = null;
106
    private JLabel jLabel2 = null;
107
    private JLabel lblFecha = null;
108
    private JButton btnImportar = null;
109
    private JButton btnExportar = null;
110
    private JButton btnEditar = null;
111
    // The properties of the Project Manager window (size, position, etc):
112
    private WindowInfo m_viewInfo = null;
113 7343 caballero
114 36411 cordinyana
    private Project project;
115 37840 cordinyana
    private UsabilitySwingManager manager = ToolsSwingLocator
116
        .getUsabilitySwingManager();
117 7343 caballero
118 37840 cordinyana
    private JScrollPane documentsScrollPane = null;
119
    private JPanel projectButtonsPanel = null;
120 7343 caballero
121 36411 cordinyana
    /**
122
     * This is the default constructor
123
     *
124
     * @param project
125
     *            Extension
126
     */
127
    public ProjectWindow() {
128
        super();
129
        initialize();
130
        refreshControls();
131
        Help.getHelp().enableHelp(this, this.getClass().getName());
132 36443 cordinyana
        // Observe document factory registration changes
133
        ProjectManager.getInstance().addObserver(this);
134 36411 cordinyana
    }
135 7343 caballero
136 36411 cordinyana
    /**
137
     * Asigna el proyecto a la ventana
138
     *
139
     * @param project
140
     *            Proyecto con el que se operar? a trav?s de este di?logo
141
     */
142
    public void setProject(Project project) {
143
        this.project = project;
144
        project.addPropertyChangeListener(this);
145
        refreshControls();
146
    }
147 7343 caballero
148 36411 cordinyana
    /**
149
     * Activa los botones de la botonera del medio o los desactiva en funci?n de
150
     * que est? seleccionado o no un elemento de proyecto en la lista del medio
151
     */
152
    private void activarBotones() {
153
        if (lstDocs.getSelectedIndex() != -1) {
154
            btnAbrir.setEnabled(true);
155
            btnBorrar.setEnabled(true);
156
            if (lstDocs.getSelectedIndices().length == 1) {
157
                btnRenombrar.setEnabled(true);
158
                btnPropiedades.setEnabled(true);
159
            } else {
160
                btnRenombrar.setEnabled(false);
161
                btnPropiedades.setEnabled(false);
162
            }
163
        } else {
164
            btnAbrir.setEnabled(false);
165
            btnBorrar.setEnabled(false);
166
            btnRenombrar.setEnabled(false);
167
            btnPropiedades.setEnabled(false);
168
        }
169
    }
170 7343 caballero
171 36411 cordinyana
    /**
172
     * Refresca la lista de elementos de proyecto con vistas, mapas o tablas,
173
     * seg?n la opci?n activada
174
     */
175
    private void refreshList() {
176
        if (project != null) {
177
            DefaultListModel model = null;
178
            String tituloMarco =
179
                PluginServices.getText(this, "documentos_existentes");
180 7343 caballero
181 36411 cordinyana
            String doctype = getDocumentSelected();
182
            model = new DefaultListModel(project.getDocuments(doctype));
183
            tituloMarco = getDocumentSelectedName();
184 31496 jjdelcerro
185 36411 cordinyana
            lstDocs.setModel(model);
186 37840 cordinyana
            ((TitledBorder) getDocumentsPanel().getBorder())
187
                .setTitle(tituloMarco);
188
            getDocumentsPanel().repaint(1);
189 36411 cordinyana
            activarBotones();
190
        }
191
    }
192 7343 caballero
193 36411 cordinyana
    /**
194
     * Devuelve el nombre del tipo de documento activo (el mismo que
195
     * ProjectDocumentFactory.getRegisterName)
196
     *
197
     *
198
     * @return
199
     */
200 7343 caballero
201 36411 cordinyana
    public String getDocumentSelected() {
202
        JRadioButton btnSelected = null;
203
        for (int i = 0; i < btnsDocuments.length; i++) {
204
            if (btnsDocuments[i].isSelected()) {
205
                btnSelected = btnsDocuments[i];
206
                return btnSelected.getName();
207
            }
208
        }
209 31496 jjdelcerro
210 36411 cordinyana
        return null;
211
    }
212 7343 caballero
213 36411 cordinyana
    private String getDocumentSelectedName() {
214
        JRadioButton btnSelected = null;
215
        for (int i = 0; i < btnsDocuments.length; i++) {
216
            if (btnsDocuments[i].isSelected()) {
217
                btnSelected = btnsDocuments[i];
218
                return btnSelected.getText();
219
            }
220
        }
221 31496 jjdelcerro
222 36411 cordinyana
        return null;
223
    }
224 7343 caballero
225 36411 cordinyana
    /**
226
     * Refresca las etiquetas con la informaci?n del proyecto
227
     */
228
    private void refreshProperties() {
229
        if (project != null) {
230
            lblNombreSesion.setText(project.getName());
231
            String path = ProjectExtension.getPath();
232
            if (path != null) {
233
                File f = new File(path);
234
                lblGuardado.setText(f.toString());
235
            } else {
236
                lblGuardado.setText("");
237
            }
238
            lblFecha.setText(project.getCreationDate());
239
        }
240
    }
241 7343 caballero
242 36411 cordinyana
    /**
243
     * Refresca todo el di?logo
244
     */
245
    public void refreshControls() {
246
        refreshList();
247
        refreshProperties();
248
    }
249 7343 caballero
250 36411 cordinyana
    /**
251
     * This method initializes this
252
     */
253
    private void initialize() {
254 37840 cordinyana
        this.setLayout(new GridBagLayout());
255 36411 cordinyana
        GridBagConstraints c = new GridBagConstraints();
256 37840 cordinyana
        c.insets = new Insets(2, 5, 2, 5);
257
258 36411 cordinyana
        c.fill = GridBagConstraints.HORIZONTAL;
259 37840 cordinyana
        c.weightx = 1.0d;
260
        c.weighty = 0.0d;
261 36411 cordinyana
        c.gridy = 0;
262 37840 cordinyana
        add(getDocumentTypesPanel(), c);
263 9532 caballero
264 36411 cordinyana
        c.fill = GridBagConstraints.BOTH;
265
        c.gridy = 1;
266 37840 cordinyana
        c.weightx = 1.0d;
267
        c.weighty = 1.0d;
268
        add(getDocumentsPanel(), c);
269
270 36411 cordinyana
        c.fill = GridBagConstraints.HORIZONTAL;
271 37840 cordinyana
        c.weightx = 1.0d;
272
        c.weighty = 0.0d;
273 36411 cordinyana
        c.gridy = 2;
274 37840 cordinyana
        add(getPropertiesPanel(), c);
275 7343 caballero
276 37840 cordinyana
        this.setMinimumSize(this.getPreferredSize());
277 36443 cordinyana
        refreshDocuments();
278 36411 cordinyana
    }
279 31496 jjdelcerro
280 36631 cordinyana
    private void createDocumentsInProject(String doctype) {
281
        Iterator<? extends Document> documents =
282
            ProjectManager.getInstance().createDocumentsByUser(doctype);
283 37412 nfrancisco
        for (; (documents != null) && (documents.hasNext());) {
284 36631 cordinyana
            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 36411 cordinyana
            }
295
        }
296
    }
297 7343 caballero
298 36411 cordinyana
    /**
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 36631 cordinyana
        createDocumentsInProject(doctype);
307 36411 cordinyana
    }
308 7343 caballero
309 36411 cordinyana
    /**
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 36483 cordinyana
            openDocumentWindow(doc);
323
        }
324
    }
325
326
    private void openDocumentWindow(Document doc) {
327
        if (doc != null) {
328 36411 cordinyana
            IWindow window = doc.getFactory().getMainWindow(doc);
329
            if (window == null) {
330 37840 cordinyana
                JOptionPane.showMessageDialog(
331
                    (Component) PluginServices.getMainFrame(),
332
                    PluginServices.getText(this, "error_opening_the_document"));
333 36411 cordinyana
                return;
334
            }
335 36483 cordinyana
            PluginServices.getMDIManager().addWindow(window,
336 38608 jjdelcerro
                MDIManager.ALIGN_FIRST_LINE_END_CASCADE);
337 36483 cordinyana
            project.setModified(true);
338 36411 cordinyana
        }
339
    }
340 7343 caballero
341 36411 cordinyana
    /**
342
     * Cambia el nombre de un project element
343
     */
344
    private void renombrar() {
345
        int index = lstDocs.getSelectedIndex();
346 7343 caballero
347 36411 cordinyana
        if (index == -1) {
348
            return;
349
        }
350
        String doctype = getDocumentSelected();
351
        List<Document> documents = project.getDocuments(doctype);
352
        Document doc = documents.get(index);
353 7343 caballero
354 36411 cordinyana
        if (doc.isLocked()) {
355
            JOptionPane.showMessageDialog(this, PluginServices.getText(this,
356
                "locked_element_it_cannot_be_renamed"));
357
            return;
358
        }
359 7343 caballero
360 36411 cordinyana
        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 7343 caballero
372 36411 cordinyana
        String nuevoNombre = pane.getInputValue().toString().trim();
373 7343 caballero
374 36411 cordinyana
        if (nuevoNombre.length() == 0) {
375
            return;
376
        }
377 7343 caballero
378 36411 cordinyana
        for (int i = 0; i < lstDocs.getModel().getSize(); i++) {
379
            if (i == index) {
380
                continue;
381
            }
382
            if (((AbstractDocument) lstDocs.getModel().getElementAt(i))
383
                .getName().equals(nuevoNombre)) {
384 37840 cordinyana
                JOptionPane.showMessageDialog(
385
                    (Component) PluginServices.getMainFrame(),
386
                    PluginServices.getText(this, "elemento_ya_existe"));
387 36411 cordinyana
                return;
388
            }
389 7343 caballero
390 36411 cordinyana
        }
391
        doc.setName(nuevoNombre);
392 7343 caballero
393 36411 cordinyana
        refreshList();
394
        project.setModified(true);
395
    }
396 7343 caballero
397 36411 cordinyana
    /**
398
     * Borra un project element
399
     */
400
    private void borrar() {
401
        int res =
402 37840 cordinyana
            JOptionPane.showConfirmDialog(
403
                (Component) PluginServices.getMainFrame(),
404
                PluginServices.getText(this, "confirmar_borrar"),
405
                PluginServices.getText(this, "borrar"),
406 36411 cordinyana
                JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
407 7343 caballero
408 36411 cordinyana
        int lastremoved = 0;
409
        if (res == JOptionPane.YES_OPTION) {
410
            int[] indexes = lstDocs.getSelectedIndices();
411
            for (int i = indexes.length - 1; i >= 0; i--) {
412
                int index = indexes[i];
413
                String s = getDocumentSelected();
414
                List<Document> documents = project.getDocuments(s);
415 37413 nfrancisco
                Document doc = documents.get(index);
416 36411 cordinyana
                if (doc.isLocked()) {
417
                    JOptionPane.showMessageDialog(this, PluginServices.getText(
418
                        this, "locked_element_it_cannot_be_deleted"));
419
                    return;
420
                }
421
                PluginServices.getMDIManager().closeSingletonWindow(doc);
422
                project.remove(doc);
423
                lastremoved = index;
424
            }
425
            if (lastremoved > lstDocs.getModel().getSize()) {
426
                lastremoved = lstDocs.getModel().getSize();
427
            }
428 38608 jjdelcerro
            if (lastremoved >= 0) {
429 36411 cordinyana
                lstDocs.setSelectedIndex(lastremoved);
430
            }
431 38608 jjdelcerro
            // refreshList();
432 36411 cordinyana
            project.setModified(true);
433
        }
434
    }
435 7343 caballero
436 36411 cordinyana
    /**
437
     * Muestra el di?logo de propiedades de un project element
438
     */
439
    private void propiedades() {
440
        int index = lstDocs.getSelectedIndex();
441 7343 caballero
442 36411 cordinyana
        if (index == -1) {
443
            return;
444
        }
445 7343 caballero
446 36411 cordinyana
        IWindow dlg = null;
447
        String doctype = getDocumentSelected();
448
        List<Document> documents = project.getDocuments(doctype);
449 37413 nfrancisco
        Document doc = documents.get(index);
450 36411 cordinyana
        if (doc.isLocked()) {
451 37840 cordinyana
            JOptionPane.showMessageDialog(this,
452
                PluginServices.getText(this, "locked_element"));
453 36411 cordinyana
            return;
454
        }
455
        dlg = doc.getFactory().getPropertiesWindow(doc);
456
        PluginServices.getMDIManager().addWindow(dlg);
457 7343 caballero
458 36411 cordinyana
        refreshControls();
459
        lstDocs.setSelectedIndex(index);
460
        project.setModified(true);
461
    }
462 7343 caballero
463 36411 cordinyana
    /**
464
     * This method initializes jPanel
465
     *
466
     * @return JPanel
467
     */
468 37840 cordinyana
    private JComponent getDocumentTypesPanel() {
469
        if (documentTypes == null) {
470 7343 caballero
471 37840 cordinyana
            documentTypesList =
472
                new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
473
            documentTypesList.setName("tipoDocPanel");
474 36443 cordinyana
            fillDocumentTypeButtons();
475 37840 cordinyana
476
            documentTypes = new JScrollPane(documentTypesList);
477
            Dimension dim = documentTypesList.getPreferredSize();
478
            documentTypes.setMinimumSize(new Dimension(dim.width,
479
                dim.height + 35));
480
            documentTypes.setBorder(BorderFactory.createTitledBorder(null,
481 36411 cordinyana
                PluginServices.getText(this, "tipos_de_documentos"),
482
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
483
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
484
        }
485 7343 caballero
486 37840 cordinyana
        return documentTypes;
487 36411 cordinyana
    }
488 7343 caballero
489 36411 cordinyana
    /**
490 36443 cordinyana
     * Adds a button for each document type
491
     */
492
    private void fillDocumentTypeButtons() {
493 37840 cordinyana
        JRadioButton[] btns = getBtnDocumentTypes();
494 36443 cordinyana
        for (int i = 0; i < btns.length; i++) {
495 37840 cordinyana
            documentTypesList.add(btns[i]);
496 36443 cordinyana
        }
497
    }
498
499
    /**
500 36411 cordinyana
     * This method initializes btnVistas
501
     *
502
     * @return JRadioButton
503
     */
504 37840 cordinyana
    private JRadioButton[] getBtnDocumentTypes() {
505 36411 cordinyana
        if (btnsDocuments == null) {
506 7343 caballero
507 36411 cordinyana
            List<JRadioButton> btns = new ArrayList<JRadioButton>();
508
            List<DocumentManager> factories =
509 36443 cordinyana
                ProjectManager.getInstance().getDocumentManagers();
510 36411 cordinyana
            Collections.sort(factories, new Comparator<DocumentManager>() {
511 31496 jjdelcerro
512 36411 cordinyana
                public int compare(DocumentManager arg0, DocumentManager arg1) {
513
                    return arg0.getPriority() - arg1.getPriority();
514
                }
515 7343 caballero
516 36411 cordinyana
            });
517
            for (DocumentManager documentFactory : factories) {
518
                JRadioButton rb = new JRadioButton();
519 7343 caballero
520 36411 cordinyana
                rb.setIcon(documentFactory.getIcon());
521
                rb.setSelectedIcon(documentFactory.getIconSelected());
522
                rb.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
523
                rb.setText(documentFactory.getTitle());
524
                rb.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
525
                rb.setName(documentFactory.getTypeName());
526
                rb.addChangeListener(new javax.swing.event.ChangeListener() {
527 7343 caballero
528 36411 cordinyana
                    public void stateChanged(javax.swing.event.ChangeEvent e) {
529
                        refreshList();
530
                    }
531
                });
532
                btns.add(rb);
533
            }
534
            btnsDocuments = btns.toArray(new JRadioButton[0]);
535
        }
536
        return btnsDocuments;
537
    }
538 7343 caballero
539 36411 cordinyana
    /**
540
     * This method initializes jPanel1
541
     *
542
     * @return JPanel
543
     */
544 37840 cordinyana
    private JPanel getDocumentsPanel() {
545
        if (documentsPanel == null) {
546
            documentsPanel = new JPanel();
547 7343 caballero
548 36411 cordinyana
            GridBagLayout layout2 = new GridBagLayout();
549
            GridBagConstraints c = new GridBagConstraints();
550 7343 caballero
551 37840 cordinyana
            documentsPanel.setLayout(layout2);
552
553 36411 cordinyana
            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 37840 cordinyana
            documentsPanel.add(getDocumentsScrollPane(), c);
559 7343 caballero
560 36411 cordinyana
            c.anchor = GridBagConstraints.EAST;
561
            c.fill = GridBagConstraints.NONE;
562
            c.weightx = 0;
563
            c.weighty = 0;
564 37840 cordinyana
            documentsPanel.add(getDocumentButtonsPanel(), c);
565 7343 caballero
566 37840 cordinyana
            documentsPanel.setBorder(javax.swing.BorderFactory
567
                .createTitledBorder(null,
568
                    PluginServices.getText(this, "documentos_existentes"),
569
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
570
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
571
                    null));
572 36411 cordinyana
        }
573 7343 caballero
574 37840 cordinyana
        return documentsPanel;
575 36411 cordinyana
    }
576 7343 caballero
577 36411 cordinyana
    /**
578
     * This method initializes lstDocs
579
     *
580
     * @return JList
581
     */
582 37840 cordinyana
    private JList getDocumentsList() {
583 36411 cordinyana
        if (lstDocs == null) {
584
            lstDocs = new JList();
585
            lstDocs.addMouseListener(new java.awt.event.MouseAdapter() {
586 31496 jjdelcerro
587 36411 cordinyana
                public AbstractDocument[] getSelecteds() {
588
                    if (lstDocs.getSelectedIndex() < 0) {
589
                        return new AbstractDocument[0];
590
                    }
591
                    Object[] seleteds = lstDocs.getSelectedValues();
592
                    AbstractDocument[] returnValue =
593
                        new AbstractDocument[seleteds.length];
594
                    System.arraycopy(seleteds, 0, returnValue, 0,
595
                        seleteds.length);
596
                    return returnValue;
597
                }
598 7379 caballero
599 36411 cordinyana
                public AbstractDocument getItem(java.awt.event.MouseEvent e) {
600
                    if (lstDocs.getSelectedIndex() < 0) {
601
                        return null;
602
                    }
603 31496 jjdelcerro
604 36411 cordinyana
                    return null;
605
                }
606 7343 caballero
607 37413 nfrancisco
                @Override
608 36411 cordinyana
                public void mouseClicked(java.awt.event.MouseEvent e) {
609
                    if (e.getButton() == java.awt.event.MouseEvent.BUTTON3) {
610
                        /*
611
                         * getDocumentSelected();//ProjectView
612
                         * getDocumentSelectedName();//Vista
613
                         */
614
                        String docType = getDocumentSelected();
615
                        AbstractDocument[] selecteds = this.getSelecteds();
616 7343 caballero
617 36411 cordinyana
                        if (selecteds == null) {
618
                            return;
619
                        }
620
                        DocumentContextMenu menu =
621
                            new DocumentContextMenu(docType, this.getItem(e),
622
                                selecteds);
623
                        if (!menu.hasActions()) {
624
                            return;
625
                        }
626
                        lstDocs.add(menu);
627
                        menu.show(e.getComponent(), e.getX(), e.getY());
628
                        return;
629
                    }
630 7343 caballero
631 36411 cordinyana
                    if (e.getClickCount() == 2) {
632
                        abrir();
633
                    }
634 7343 caballero
635 36411 cordinyana
                }
636
            });
637
            lstDocs
638
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
639 7343 caballero
640 36411 cordinyana
                    public void valueChanged(
641
                        javax.swing.event.ListSelectionEvent e) {
642
                        activarBotones();
643
                    }
644
                });
645
        }
646 7343 caballero
647 36411 cordinyana
        return lstDocs;
648
    }
649 7343 caballero
650 36411 cordinyana
    /**
651
     * This method initializes jPanel2
652
     *
653
     * @return JPanel
654
     */
655 37840 cordinyana
    private JPanel getDocumentButtonsPanel() {
656 36411 cordinyana
        if (jPanel2 == null) {
657
            jPanel2 = new JPanel();
658 7343 caballero
659 36411 cordinyana
            // FlowLayout layout = new FlowLayout();
660
            GridLayout layout = new GridLayout(5, 1);
661
            layout.setVgap(7);
662 7343 caballero
663 36411 cordinyana
            jPanel2.setLayout(layout);
664
            jPanel2.add(getBtnNuevo(), null);
665
            jPanel2.add(getBtnAbrir(), null);
666
            jPanel2.add(getBtnRenombrar(), null);
667
            jPanel2.add(getBtnBorrar(), null);
668
            jPanel2.add(getBtnPropiedades(), null);
669
        }
670 7343 caballero
671 36411 cordinyana
        return jPanel2;
672
    }
673 7343 caballero
674 36411 cordinyana
    /**
675
     * This method initializes btnNuevo
676
     *
677
     * @return JButton
678
     */
679
    private JButton getBtnNuevo() {
680
        if (btnNuevo == null) {
681 37420 nfrancisco
            btnNuevo = manager.createJButton();
682 36411 cordinyana
            btnNuevo.setName("btnNuevo");
683
            btnNuevo.setText(PluginServices.getText(this, "nuevo"));
684
            btnNuevo.setMargin(new java.awt.Insets(2, 2, 2, 2));
685
            btnNuevo.addActionListener(new java.awt.event.ActionListener() {
686 7343 caballero
687 36411 cordinyana
                public void actionPerformed(java.awt.event.ActionEvent e) {
688
                    try {
689
                        newProjectDocument();
690
                    } catch (Exception e1) {
691
                        NotificationManager.addError(e1.getLocalizedMessage(),
692
                            e1);
693
                    }
694
                }
695
            });
696
        }
697 7343 caballero
698 36411 cordinyana
        return btnNuevo;
699
    }
700 7343 caballero
701 36411 cordinyana
    /**
702
     * This method initializes btnPropiedades
703
     *
704
     * @return JButton
705
     */
706
    private JButton getBtnPropiedades() {
707
        if (btnPropiedades == null) {
708 37420 nfrancisco
            btnPropiedades = manager.createJButton();
709
            ;
710 36411 cordinyana
            btnPropiedades.setText(PluginServices.getText(this, "propiedades"));
711
            btnPropiedades.setName("btnPropiedades");
712
            btnPropiedades.setEnabled(false);
713
            btnPropiedades.setMargin(new java.awt.Insets(2, 2, 2, 2));
714
            btnPropiedades
715
                .addActionListener(new java.awt.event.ActionListener() {
716 7343 caballero
717 36411 cordinyana
                    public void actionPerformed(java.awt.event.ActionEvent e) {
718
                        propiedades();
719
                    }
720
                });
721
        }
722 7343 caballero
723 36411 cordinyana
        return btnPropiedades;
724
    }
725 7343 caballero
726 36411 cordinyana
    /**
727
     * This method initializes btnAbrir
728
     *
729
     * @return JButton
730
     */
731
    private JButton getBtnAbrir() {
732
        if (btnAbrir == null) {
733 37420 nfrancisco
            btnAbrir = manager.createJButton();
734 36411 cordinyana
            btnAbrir.setName("btnAbrir");
735
            btnAbrir.setText(PluginServices.getText(this, "abrir"));
736
            btnAbrir.setEnabled(false);
737
            btnAbrir.setMargin(new java.awt.Insets(2, 2, 2, 2));
738
            btnAbrir.addActionListener(new java.awt.event.ActionListener() {
739 7343 caballero
740 36411 cordinyana
                public void actionPerformed(java.awt.event.ActionEvent e) {
741
                    abrir();
742
                }
743
            });
744
        }
745 7343 caballero
746 36411 cordinyana
        return btnAbrir;
747
    }
748 7343 caballero
749 36411 cordinyana
    /**
750
     * This method initializes btnBorrar
751
     *
752
     * @return JButton
753
     */
754
    private JButton getBtnBorrar() {
755
        if (btnBorrar == null) {
756 37420 nfrancisco
            btnBorrar = manager.createJButton();
757 36411 cordinyana
            btnBorrar.setText(PluginServices.getText(this, "borrar"));
758
            btnBorrar.setName("btnBorrar");
759
            btnBorrar.setEnabled(false);
760
            btnBorrar.setMargin(new java.awt.Insets(2, 2, 2, 2));
761
            btnBorrar.addActionListener(new java.awt.event.ActionListener() {
762 7343 caballero
763 36411 cordinyana
                public void actionPerformed(java.awt.event.ActionEvent e) {
764
                    borrar();
765
                }
766
            });
767
        }
768 7343 caballero
769 36411 cordinyana
        return btnBorrar;
770
    }
771 7343 caballero
772 36411 cordinyana
    /**
773
     * This method initializes btnRenombrar
774
     *
775
     * @return JButton
776
     */
777
    private JButton getBtnRenombrar() {
778
        if (btnRenombrar == null) {
779 37420 nfrancisco
            btnRenombrar = manager.createJButton();
780 36411 cordinyana
            btnRenombrar.setName("btnRenombrar");
781
            btnRenombrar.setText(PluginServices.getText(this, "renombrar"));
782
            btnRenombrar.setEnabled(false);
783
            btnRenombrar.setMargin(new java.awt.Insets(2, 2, 2, 2));
784
            btnRenombrar.addActionListener(new java.awt.event.ActionListener() {
785 7343 caballero
786 36411 cordinyana
                public void actionPerformed(java.awt.event.ActionEvent e) {
787
                    renombrar();
788
                }
789
            });
790
        }
791 7343 caballero
792 36411 cordinyana
        return btnRenombrar;
793
    }
794 7343 caballero
795 36411 cordinyana
    /**
796
     * This method initializes jPanel3
797
     *
798
     * @return JPanel
799
     */
800 37840 cordinyana
    private JPanel getPropertiesPanel() {
801
        if (propertiesPanel == null) {
802
            propertiesPanel = new JPanel(new GridBagLayout());
803 36411 cordinyana
            GridBagConstraints c = new GridBagConstraints();
804 37840 cordinyana
805 36411 cordinyana
            c.insets = new Insets(2, 5, 0, 5);
806
            c.anchor = GridBagConstraints.WEST;
807
            c.gridx = 0;
808
            c.gridy = 0;
809 37840 cordinyana
            propertiesPanel.add(getJLabel(), c);
810
811 36411 cordinyana
            c.fill = GridBagConstraints.HORIZONTAL;
812
            c.weightx = 1.0;
813
            c.gridx = 1;
814 37840 cordinyana
            propertiesPanel.add(getLblNombreSesion(), c);
815 7343 caballero
816 36411 cordinyana
            c.gridx = 0;
817
            c.gridy = 1;
818
            c.fill = GridBagConstraints.NONE;
819
            c.weightx = 0.0;
820 37840 cordinyana
            propertiesPanel.add(getJLabel1(), c);
821
822 36411 cordinyana
            c.fill = GridBagConstraints.HORIZONTAL;
823
            c.weightx = 1.0;
824
            c.gridx = 1;
825 37840 cordinyana
            propertiesPanel.add(getLblGuardado(), c);
826 7343 caballero
827 36411 cordinyana
            c.gridx = 0;
828
            c.gridy = 2;
829
            c.fill = GridBagConstraints.NONE;
830
            c.weightx = 0.0;
831 37840 cordinyana
            propertiesPanel.add(getJLabel2(), c);
832 7343 caballero
833 36411 cordinyana
            c.fill = GridBagConstraints.HORIZONTAL;
834
            c.weightx = 1.0;
835
            c.gridx = 1;
836 37840 cordinyana
            propertiesPanel.add(getLblFecha(), c);
837
838
            c.gridx = 0;
839
            c.gridwidth = 2;
840 36411 cordinyana
            c.gridy = 4;
841 37840 cordinyana
            c.fill = GridBagConstraints.HORIZONTAL;
842 36411 cordinyana
            c.anchor = GridBagConstraints.EAST;
843 37840 cordinyana
            propertiesPanel.add(getProjectsButtonPanel(), c);
844
845
            propertiesPanel.setBorder(javax.swing.BorderFactory
846
                .createTitledBorder(null,
847
                    PluginServices.getText(this, "propiedades_sesion"),
848
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
849
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
850
                    null));
851 36411 cordinyana
        }
852 7343 caballero
853 37840 cordinyana
        return propertiesPanel;
854 36411 cordinyana
    }
855 7343 caballero
856 36411 cordinyana
    /**
857
     * This method initializes jLabel
858
     *
859
     * @return JLabel
860
     */
861
    private JLabel getJLabel() {
862
        if (jLabel == null) {
863
            jLabel = new JLabel();
864
            jLabel.setText(PluginServices.getText(this, "nombre_sesion") + ":");
865
        }
866 7343 caballero
867 36411 cordinyana
        return jLabel;
868
    }
869 7343 caballero
870 36411 cordinyana
    /**
871
     * This method initializes lblNombreSesion
872
     *
873
     * @return JLabel
874
     */
875
    private JLabel getLblNombreSesion() {
876
        if (lblNombreSesion == null) {
877
            lblNombreSesion = new JLabel();
878
            lblNombreSesion.setText("");
879
            lblNombreSesion.setName("lblNombreSesion");
880
            lblNombreSesion.setAutoscrolls(true);
881
        }
882 7343 caballero
883 36411 cordinyana
        return lblNombreSesion;
884
    }
885 7343 caballero
886 36411 cordinyana
    /**
887
     * This method initializes jLabel1
888
     *
889
     * @return JLabel
890
     */
891
    private JLabel getJLabel1() {
892
        if (jLabel1 == null) {
893
            jLabel1 = new JLabel();
894
            jLabel1.setText(PluginServices.getText(this, "guardado") + ":");
895
        }
896 7343 caballero
897 36411 cordinyana
        return jLabel1;
898
    }
899 7343 caballero
900 36411 cordinyana
    /**
901
     * This method initializes lblGuardado
902
     *
903
     * @return JLabel
904
     */
905
    private JLabel getLblGuardado() {
906
        if (lblGuardado == null) {
907
            lblGuardado = new JLabel();
908
            lblGuardado.setText("");
909
            lblGuardado.setAutoscrolls(true);
910
        }
911 7343 caballero
912 36411 cordinyana
        return lblGuardado;
913
    }
914 7343 caballero
915 36411 cordinyana
    /**
916
     * This method initializes jLabel2
917
     *
918
     * @return JLabel
919
     */
920
    private JLabel getJLabel2() {
921
        if (jLabel2 == null) {
922
            jLabel2 = new JLabel();
923
            jLabel2
924
                .setText(PluginServices.getText(this, "creation_date") + ":");
925
        }
926 7343 caballero
927 36411 cordinyana
        return jLabel2;
928
    }
929 7343 caballero
930 36411 cordinyana
    /**
931
     * This method initializes lblFecha
932
     *
933
     * @return JLabel
934
     */
935
    private JLabel getLblFecha() {
936
        if (lblFecha == null) {
937
            lblFecha = new JLabel();
938
            lblFecha.setText("");
939
            lblFecha.setAutoscrolls(true);
940
        }
941 7343 caballero
942 36411 cordinyana
        return lblFecha;
943
    }
944 7343 caballero
945 36411 cordinyana
    /**
946
     * This method initializes btnImportar
947
     *
948
     * @return JButton
949
     */
950
    private JButton getBtnImportar() {
951
        if (btnImportar == null) {
952 37420 nfrancisco
            btnImportar = manager.createJButton();
953 36411 cordinyana
            btnImportar.setPreferredSize(new java.awt.Dimension(80, 23));
954
            btnImportar.setText(PluginServices.getText(this, "importar"));
955
            btnImportar.setName("btnImportar");
956
            btnImportar.setMargin(new java.awt.Insets(2, 2, 2, 2));
957
        }
958 7343 caballero
959 36411 cordinyana
        return btnImportar;
960
    }
961 31496 jjdelcerro
962 36411 cordinyana
    /**
963
     * This method initializes btnExportar
964
     *
965
     * @return JButton
966
     */
967
    private JButton getBtnExportar() {
968
        if (btnExportar == null) {
969 37420 nfrancisco
            btnExportar = manager.createJButton();
970 36411 cordinyana
            btnExportar.setPreferredSize(new java.awt.Dimension(80, 23));
971
            btnExportar.setText(PluginServices.getText(this, "exportar"));
972
            btnExportar.setName("btnExportar");
973
            btnExportar.setMargin(new java.awt.Insets(2, 2, 2, 2));
974
        }
975 7343 caballero
976 36411 cordinyana
        return btnExportar;
977
    }
978 7343 caballero
979 36411 cordinyana
    /**
980
     * This method initializes btnEditar
981
     *
982
     * @return JButton
983
     */
984
    private JButton getBtnEditar() {
985
        if (btnEditar == null) {
986 37420 nfrancisco
            btnEditar = manager.createJButton();
987 36411 cordinyana
            btnEditar.setPreferredSize(new java.awt.Dimension(80, 23));
988
            btnEditar.setText(PluginServices.getText(this, "propiedades"));
989 7343 caballero
990 36411 cordinyana
            btnEditar.setName("btnEditar");
991
            btnEditar.setMargin(new java.awt.Insets(2, 2, 2, 2));
992 7343 caballero
993 36411 cordinyana
            btnEditar.addActionListener(new java.awt.event.ActionListener() {
994 7343 caballero
995 36411 cordinyana
                public void actionPerformed(java.awt.event.ActionEvent e) {
996
                    ProjectProperties dlg = new ProjectProperties(project);
997
                    PluginServices.getMDIManager().addWindow(dlg);
998
                    refreshProperties();
999
                }
1000
            });
1001
        }
1002 7343 caballero
1003 36411 cordinyana
        return btnEditar;
1004
    }
1005 7343 caballero
1006 36411 cordinyana
    /**
1007
     * This method initializes jScrollPane
1008
     *
1009
     * @return JScrollPane
1010
     */
1011 37840 cordinyana
    private JScrollPane getDocumentsScrollPane() {
1012
        if (documentsScrollPane == null) {
1013
            documentsScrollPane = new JScrollPane();
1014
            documentsScrollPane.setViewportView(getDocumentsList());
1015
            documentsScrollPane.setPreferredSize(new java.awt.Dimension(200,
1016
                100));
1017
            documentsScrollPane
1018 37413 nfrancisco
                .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
1019 36411 cordinyana
        }
1020 26449 jmvivo
1021 37840 cordinyana
        return documentsScrollPane;
1022 36411 cordinyana
    }
1023 26449 jmvivo
1024 36411 cordinyana
    /**
1025
     * @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
1026
     */
1027
    public Object getWindowModel() {
1028
        return project;
1029
    }
1030
1031
    public Project getProject() {
1032
        return project;
1033
    }
1034
1035
    /**
1036
     * This method is used to get <strong>an initial</strong> ViewInfo object
1037
     * for this Project Manager window. It is not intended to retrieve the
1038
     * ViewInfo object in a later time. <strong>Use
1039
     * PluginServices.getMDIManager().getViewInfo(view) to retrieve the ViewInfo
1040
     * object at any time after the creation of the object.
1041
     *
1042
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
1043
     */
1044
    public WindowInfo getWindowInfo() {
1045
        if (m_viewInfo == null) {
1046 37840 cordinyana
            m_viewInfo =
1047
                new WindowInfo(WindowInfo.MAXIMIZABLE | WindowInfo.RESIZABLE);
1048 36411 cordinyana
            m_viewInfo.setWidth(this.getWidth());
1049
            m_viewInfo.setHeight(this.getHeight());
1050
            m_viewInfo.setNormalWidth(this.getPreferredSize().width);
1051
            m_viewInfo.setNormalHeight(this.getPreferredSize().height);
1052 37840 cordinyana
            m_viewInfo.setMinimumSize(getPreferredSize());
1053 36411 cordinyana
1054
            m_viewInfo.setTitle(PluginServices.getText(this, "titulo"));
1055
        }
1056
        return m_viewInfo;
1057
    }
1058
1059
    public void propertyChange(PropertyChangeEvent evt) {
1060
        refreshControls();
1061
    }
1062
1063
    /**
1064
     * This method initializes jPanel4
1065
     *
1066
     * @return JPanel
1067
     */
1068 37840 cordinyana
    private JPanel getProjectsButtonPanel() {
1069
        if (projectButtonsPanel == null) {
1070
            projectButtonsPanel = new JPanel();
1071 36411 cordinyana
1072 37840 cordinyana
            projectButtonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
1073
            projectButtonsPanel
1074 36411 cordinyana
                .setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT);
1075 37840 cordinyana
            // TODO: implement export and import functions
1076
            // projectButtonsPanel.add(getBtnImportar(), null);
1077
            // projectButtonsPanel.add(getBtnExportar(), null);
1078
            projectButtonsPanel.add(getBtnEditar(), null);
1079 36411 cordinyana
        }
1080
1081 37840 cordinyana
        return projectButtonsPanel;
1082 36411 cordinyana
    }
1083
1084
    public Object getWindowProfile() {
1085
        return WindowInfo.PROJECT_PROFILE;
1086
    }
1087
1088 36443 cordinyana
    public void update(Observable observable, Object notification) {
1089
        if (observable instanceof ProjectManager) {
1090
            refreshDocuments();
1091
        }
1092
    }
1093
1094
    private void refreshDocuments() {
1095
        // Setting it to null will make it recreate in the next
1096
        // getBtnDocuments() call
1097
        this.btnsDocuments = null;
1098
1099
        // Clear previous document type buttons
1100 37840 cordinyana
        documentTypesList.removeAll();
1101 36443 cordinyana
        for (Enumeration<AbstractButton> buttons = grupo.getElements(); buttons
1102
            .hasMoreElements();) {
1103
            grupo.remove(buttons.nextElement());
1104
        }
1105
1106 37840 cordinyana
        JRadioButton[] btnDocuments = getBtnDocumentTypes();
1107 36443 cordinyana
        for (int i = 0; i < btnDocuments.length; i++) {
1108
            grupo.add(btnDocuments[i]);
1109
        }
1110
        if (btnDocuments.length > 0) {
1111
            btnDocuments[0].setSelected(true);
1112
        }
1113
        fillDocumentTypeButtons();
1114
    }
1115
1116 31496 jjdelcerro
}