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