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 |
/* 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.border.TitledBorder; |
55 |
|
56 |
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 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
61 |
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 |
import org.gvsig.app.project.ProjectManager; |
66 |
import org.gvsig.app.project.documents.AbstractDocument; |
67 |
import org.gvsig.app.project.documents.Document; |
68 |
import org.gvsig.app.project.documents.DocumentManager; |
69 |
import org.gvsig.tools.observer.Observable; |
70 |
import org.gvsig.tools.observer.Observer; |
71 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
72 |
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager; |
73 |
import org.gvsig.utils.DefaultListModel; |
74 |
|
75 |
/**
|
76 |
* Clase principal del proyecto donde se puede operar para crear cualquier tipo
|
77 |
* de documento.
|
78 |
*
|
79 |
* @author Vicente Caballero Navarro
|
80 |
* @author gvSIG team
|
81 |
*/
|
82 |
public class ProjectWindow extends JPanel implements PropertyChangeListener, |
83 |
IWindow, SingletonWindow, Observer {
|
84 |
|
85 |
private static final long serialVersionUID = 7315293357719796556L; |
86 |
|
87 |
public static final String PERSISTENCE_DEFINITION_NAME = "ProjectWindow"; |
88 |
|
89 |
private JScrollPane documentTypes = null; |
90 |
private JPanel documentTypesList = null; |
91 |
private JRadioButton[] btnsDocuments = null; |
92 |
private ButtonGroup grupo = new ButtonGroup(); |
93 |
private JPanel documentsPanel = null; |
94 |
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 |
private JPanel propertiesPanel = null; |
102 |
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 |
|
114 |
private Project project;
|
115 |
private UsabilitySwingManager manager = ToolsSwingLocator
|
116 |
.getUsabilitySwingManager(); |
117 |
|
118 |
private JScrollPane documentsScrollPane = null; |
119 |
private JPanel projectButtonsPanel = null; |
120 |
|
121 |
/**
|
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 |
// Observe document factory registration changes
|
133 |
ProjectManager.getInstance().addObserver(this);
|
134 |
} |
135 |
|
136 |
/**
|
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 |
|
148 |
/**
|
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 |
|
171 |
/**
|
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 |
|
181 |
String doctype = getDocumentSelected();
|
182 |
model = new DefaultListModel(project.getDocuments(doctype)); |
183 |
tituloMarco = getDocumentSelectedName(); |
184 |
|
185 |
lstDocs.setModel(model); |
186 |
((TitledBorder) getDocumentsPanel().getBorder())
|
187 |
.setTitle(tituloMarco); |
188 |
getDocumentsPanel().repaint(1);
|
189 |
activarBotones(); |
190 |
} |
191 |
} |
192 |
|
193 |
/**
|
194 |
* Devuelve el nombre del tipo de documento activo (el mismo que
|
195 |
* ProjectDocumentFactory.getRegisterName)
|
196 |
*
|
197 |
*
|
198 |
* @return
|
199 |
*/
|
200 |
|
201 |
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 |
|
210 |
return null; |
211 |
} |
212 |
|
213 |
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 |
|
222 |
return null; |
223 |
} |
224 |
|
225 |
/**
|
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 |
|
242 |
/**
|
243 |
* Refresca todo el di?logo
|
244 |
*/
|
245 |
public void refreshControls() { |
246 |
refreshList(); |
247 |
refreshProperties(); |
248 |
} |
249 |
|
250 |
/**
|
251 |
* This method initializes this
|
252 |
*/
|
253 |
private void initialize() { |
254 |
this.setLayout(new GridBagLayout()); |
255 |
GridBagConstraints c = new GridBagConstraints(); |
256 |
c.insets = new Insets(2, 5, 2, 5); |
257 |
|
258 |
c.fill = GridBagConstraints.HORIZONTAL;
|
259 |
c.weightx = 1.0d;
|
260 |
c.weighty = 0.0d;
|
261 |
c.gridy = 0;
|
262 |
add(getDocumentTypesPanel(), c); |
263 |
|
264 |
c.fill = GridBagConstraints.BOTH;
|
265 |
c.gridy = 1;
|
266 |
c.weightx = 1.0d;
|
267 |
c.weighty = 1.0d;
|
268 |
add(getDocumentsPanel(), c); |
269 |
|
270 |
c.fill = GridBagConstraints.HORIZONTAL;
|
271 |
c.weightx = 1.0d;
|
272 |
c.weighty = 0.0d;
|
273 |
c.gridy = 2;
|
274 |
add(getPropertiesPanel(), c); |
275 |
|
276 |
this.setMinimumSize(this.getPreferredSize()); |
277 |
refreshDocuments(); |
278 |
} |
279 |
|
280 |
private void createDocumentsInProject(String doctype) { |
281 |
Iterator<? extends Document> documents = |
282 |
ProjectManager.getInstance().createDocumentsByUser(doctype); |
283 |
for (; (documents != null) && (documents.hasNext());) { |
284 |
try {
|
285 |
Document document = documents.next();
|
286 |
project.add(document); |
287 |
int index =
|
288 |
((DefaultListModel) lstDocs.getModel()).indexOf(document);
|
289 |
lstDocs.setSelectedIndex(index); |
290 |
lstDocs.requestFocus(); |
291 |
openDocumentWindow(document); |
292 |
} catch (Exception e) { |
293 |
NotificationManager.addError(e); |
294 |
} |
295 |
} |
296 |
} |
297 |
|
298 |
/**
|
299 |
* Crea un nuevo project element
|
300 |
*
|
301 |
* @throws Exception
|
302 |
* DOCUMENT ME!
|
303 |
*/
|
304 |
private void newProjectDocument() throws Exception { |
305 |
String doctype = getDocumentSelected();
|
306 |
createDocumentsInProject(doctype); |
307 |
} |
308 |
|
309 |
/**
|
310 |
* Abre la ventana de un nuevo documento
|
311 |
*/
|
312 |
private void abrir() { |
313 |
int[] indexes = lstDocs.getSelectedIndices(); |
314 |
for (int i = indexes.length - 1; i >= 0; i--) { |
315 |
int index = indexes[i];
|
316 |
if (index == -1) { |
317 |
return;
|
318 |
} |
319 |
String doctype = getDocumentSelected();
|
320 |
List<Document> documents = project.getDocuments(doctype); |
321 |
Document doc = documents.get(index);
|
322 |
openDocumentWindow(doc); |
323 |
} |
324 |
} |
325 |
|
326 |
private void openDocumentWindow(Document doc) { |
327 |
if (doc != null) { |
328 |
IWindow window = doc.getFactory().getMainWindow(doc); |
329 |
if (window == null) { |
330 |
JOptionPane.showMessageDialog(
|
331 |
(Component) PluginServices.getMainFrame(),
|
332 |
PluginServices.getText(this, "error_opening_the_document")); |
333 |
return;
|
334 |
} |
335 |
PluginServices.getMDIManager().addWindow(window, |
336 |
MDIManager.ALIGN_FIRST_LINE_END_CASCADE); |
337 |
project.setModified(true);
|
338 |
} |
339 |
} |
340 |
|
341 |
/**
|
342 |
* Cambia el nombre de un project element
|
343 |
*/
|
344 |
private void renombrar() { |
345 |
int index = lstDocs.getSelectedIndex();
|
346 |
|
347 |
if (index == -1) { |
348 |
return;
|
349 |
} |
350 |
String doctype = getDocumentSelected();
|
351 |
List<Document> documents = project.getDocuments(doctype); |
352 |
Document doc = documents.get(index);
|
353 |
|
354 |
if (doc.isLocked()) {
|
355 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, |
356 |
"locked_element_it_cannot_be_renamed"));
|
357 |
return;
|
358 |
} |
359 |
|
360 |
JOptionPane pane = new JOptionPane(); |
361 |
pane.setMessage(PluginServices.getText(this, "introduce_nombre")); |
362 |
pane.setMessageType(JOptionPane.QUESTION_MESSAGE);
|
363 |
pane.setWantsInput(true);
|
364 |
pane.setInitialSelectionValue(doc.getName()); |
365 |
pane.setInputValue(doc.getName()); |
366 |
JDialog dlg =
|
367 |
pane.createDialog((Component) PluginServices.getMainFrame(),
|
368 |
PluginServices.getText(this, "renombrar")); |
369 |
dlg.setModal(true);
|
370 |
dlg.setVisible(true);
|
371 |
|
372 |
String nuevoNombre = pane.getInputValue().toString().trim();
|
373 |
|
374 |
if (nuevoNombre.length() == 0) { |
375 |
return;
|
376 |
} |
377 |
|
378 |
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 |
JOptionPane.showMessageDialog(
|
385 |
(Component) PluginServices.getMainFrame(),
|
386 |
PluginServices.getText(this, "elemento_ya_existe")); |
387 |
return;
|
388 |
} |
389 |
|
390 |
} |
391 |
doc.setName(nuevoNombre); |
392 |
|
393 |
refreshList(); |
394 |
project.setModified(true);
|
395 |
} |
396 |
|
397 |
/**
|
398 |
* Borra un project element
|
399 |
*/
|
400 |
private void borrar() { |
401 |
int res =
|
402 |
JOptionPane.showConfirmDialog(
|
403 |
(Component) PluginServices.getMainFrame(),
|
404 |
PluginServices.getText(this, "confirmar_borrar"), |
405 |
PluginServices.getText(this, "borrar"), |
406 |
JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE); |
407 |
|
408 |
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 |
Document doc = documents.get(index);
|
416 |
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 |
if (lastremoved >= 0) { |
429 |
lstDocs.setSelectedIndex(lastremoved); |
430 |
} |
431 |
// refreshList();
|
432 |
project.setModified(true);
|
433 |
} |
434 |
} |
435 |
|
436 |
/**
|
437 |
* Muestra el di?logo de propiedades de un project element
|
438 |
*/
|
439 |
private void propiedades() { |
440 |
int index = lstDocs.getSelectedIndex();
|
441 |
|
442 |
if (index == -1) { |
443 |
return;
|
444 |
} |
445 |
|
446 |
IWindow dlg = null;
|
447 |
String doctype = getDocumentSelected();
|
448 |
List<Document> documents = project.getDocuments(doctype); |
449 |
Document doc = documents.get(index);
|
450 |
if (doc.isLocked()) {
|
451 |
JOptionPane.showMessageDialog(this, |
452 |
PluginServices.getText(this, "locked_element")); |
453 |
return;
|
454 |
} |
455 |
dlg = doc.getFactory().getPropertiesWindow(doc); |
456 |
PluginServices.getMDIManager().addWindow(dlg); |
457 |
|
458 |
refreshControls(); |
459 |
lstDocs.setSelectedIndex(index); |
460 |
project.setModified(true);
|
461 |
} |
462 |
|
463 |
/**
|
464 |
* This method initializes jPanel
|
465 |
*
|
466 |
* @return JPanel
|
467 |
*/
|
468 |
private JComponent getDocumentTypesPanel() { |
469 |
if (documentTypes == null) { |
470 |
|
471 |
documentTypesList = |
472 |
new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5)); |
473 |
documentTypesList.setName("tipoDocPanel");
|
474 |
fillDocumentTypeButtons(); |
475 |
|
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 |
PluginServices.getText(this, "tipos_de_documentos"), |
482 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
483 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
484 |
} |
485 |
|
486 |
return documentTypes;
|
487 |
} |
488 |
|
489 |
/**
|
490 |
* Adds a button for each document type
|
491 |
*/
|
492 |
private void fillDocumentTypeButtons() { |
493 |
JRadioButton[] btns = getBtnDocumentTypes(); |
494 |
for (int i = 0; i < btns.length; i++) { |
495 |
documentTypesList.add(btns[i]); |
496 |
} |
497 |
} |
498 |
|
499 |
/**
|
500 |
* This method initializes btnVistas
|
501 |
*
|
502 |
* @return JRadioButton
|
503 |
*/
|
504 |
private JRadioButton[] getBtnDocumentTypes() { |
505 |
if (btnsDocuments == null) { |
506 |
|
507 |
List<JRadioButton> btns = new ArrayList<JRadioButton>(); |
508 |
List<DocumentManager> factories =
|
509 |
ProjectManager.getInstance().getDocumentManagers(); |
510 |
Collections.sort(factories, new Comparator<DocumentManager>() { |
511 |
|
512 |
public int compare(DocumentManager arg0, DocumentManager arg1) { |
513 |
return arg0.getPriority() - arg1.getPriority();
|
514 |
} |
515 |
|
516 |
}); |
517 |
for (DocumentManager documentFactory : factories) {
|
518 |
JRadioButton rb = new JRadioButton(); |
519 |
|
520 |
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 |
|
528 |
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 |
|
539 |
/**
|
540 |
* This method initializes jPanel1
|
541 |
*
|
542 |
* @return JPanel
|
543 |
*/
|
544 |
private JPanel getDocumentsPanel() { |
545 |
if (documentsPanel == null) { |
546 |
documentsPanel = new JPanel(); |
547 |
|
548 |
GridBagLayout layout2 = new GridBagLayout(); |
549 |
GridBagConstraints c = new GridBagConstraints(); |
550 |
|
551 |
documentsPanel.setLayout(layout2); |
552 |
|
553 |
c.insets = new Insets(2, 5, 2, 5); |
554 |
c.anchor = GridBagConstraints.WEST;
|
555 |
c.fill = GridBagConstraints.BOTH;
|
556 |
c.weightx = 1.0;
|
557 |
c.weighty = 1.0;
|
558 |
documentsPanel.add(getDocumentsScrollPane(), c); |
559 |
|
560 |
c.anchor = GridBagConstraints.EAST;
|
561 |
c.fill = GridBagConstraints.NONE;
|
562 |
c.weightx = 0;
|
563 |
c.weighty = 0;
|
564 |
documentsPanel.add(getDocumentButtonsPanel(), c); |
565 |
|
566 |
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 |
} |
573 |
|
574 |
return documentsPanel;
|
575 |
} |
576 |
|
577 |
/**
|
578 |
* This method initializes lstDocs
|
579 |
*
|
580 |
* @return JList
|
581 |
*/
|
582 |
private JList getDocumentsList() { |
583 |
if (lstDocs == null) { |
584 |
lstDocs = new JList(); |
585 |
lstDocs.addMouseListener(new java.awt.event.MouseAdapter() {
|
586 |
|
587 |
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 |
|
599 |
public AbstractDocument getItem(java.awt.event.MouseEvent e) { |
600 |
if (lstDocs.getSelectedIndex() < 0) { |
601 |
return null; |
602 |
} |
603 |
|
604 |
return null; |
605 |
} |
606 |
|
607 |
@Override
|
608 |
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 |
|
617 |
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 |
|
631 |
if (e.getClickCount() == 2) { |
632 |
abrir(); |
633 |
} |
634 |
|
635 |
} |
636 |
}); |
637 |
lstDocs |
638 |
.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
639 |
|
640 |
public void valueChanged( |
641 |
javax.swing.event.ListSelectionEvent e) { |
642 |
activarBotones(); |
643 |
} |
644 |
}); |
645 |
} |
646 |
|
647 |
return lstDocs;
|
648 |
} |
649 |
|
650 |
/**
|
651 |
* This method initializes jPanel2
|
652 |
*
|
653 |
* @return JPanel
|
654 |
*/
|
655 |
private JPanel getDocumentButtonsPanel() { |
656 |
if (jPanel2 == null) { |
657 |
jPanel2 = new JPanel(); |
658 |
|
659 |
// FlowLayout layout = new FlowLayout();
|
660 |
GridLayout layout = new GridLayout(5, 1); |
661 |
layout.setVgap(7);
|
662 |
|
663 |
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 |
|
671 |
return jPanel2;
|
672 |
} |
673 |
|
674 |
/**
|
675 |
* This method initializes btnNuevo
|
676 |
*
|
677 |
* @return JButton
|
678 |
*/
|
679 |
private JButton getBtnNuevo() { |
680 |
if (btnNuevo == null) { |
681 |
btnNuevo = manager.createJButton(); |
682 |
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 |
|
687 |
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 |
|
698 |
return btnNuevo;
|
699 |
} |
700 |
|
701 |
/**
|
702 |
* This method initializes btnPropiedades
|
703 |
*
|
704 |
* @return JButton
|
705 |
*/
|
706 |
private JButton getBtnPropiedades() { |
707 |
if (btnPropiedades == null) { |
708 |
btnPropiedades = manager.createJButton(); |
709 |
; |
710 |
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 |
|
717 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
718 |
propiedades(); |
719 |
} |
720 |
}); |
721 |
} |
722 |
|
723 |
return btnPropiedades;
|
724 |
} |
725 |
|
726 |
/**
|
727 |
* This method initializes btnAbrir
|
728 |
*
|
729 |
* @return JButton
|
730 |
*/
|
731 |
private JButton getBtnAbrir() { |
732 |
if (btnAbrir == null) { |
733 |
btnAbrir = manager.createJButton(); |
734 |
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 |
|
740 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
741 |
abrir(); |
742 |
} |
743 |
}); |
744 |
} |
745 |
|
746 |
return btnAbrir;
|
747 |
} |
748 |
|
749 |
/**
|
750 |
* This method initializes btnBorrar
|
751 |
*
|
752 |
* @return JButton
|
753 |
*/
|
754 |
private JButton getBtnBorrar() { |
755 |
if (btnBorrar == null) { |
756 |
btnBorrar = manager.createJButton(); |
757 |
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 |
|
763 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
764 |
borrar(); |
765 |
} |
766 |
}); |
767 |
} |
768 |
|
769 |
return btnBorrar;
|
770 |
} |
771 |
|
772 |
/**
|
773 |
* This method initializes btnRenombrar
|
774 |
*
|
775 |
* @return JButton
|
776 |
*/
|
777 |
private JButton getBtnRenombrar() { |
778 |
if (btnRenombrar == null) { |
779 |
btnRenombrar = manager.createJButton(); |
780 |
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 |
|
786 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
787 |
renombrar(); |
788 |
} |
789 |
}); |
790 |
} |
791 |
|
792 |
return btnRenombrar;
|
793 |
} |
794 |
|
795 |
/**
|
796 |
* This method initializes jPanel3
|
797 |
*
|
798 |
* @return JPanel
|
799 |
*/
|
800 |
private JPanel getPropertiesPanel() { |
801 |
if (propertiesPanel == null) { |
802 |
propertiesPanel = new JPanel(new GridBagLayout()); |
803 |
GridBagConstraints c = new GridBagConstraints(); |
804 |
|
805 |
c.insets = new Insets(2, 5, 0, 5); |
806 |
c.anchor = GridBagConstraints.WEST;
|
807 |
c.gridx = 0;
|
808 |
c.gridy = 0;
|
809 |
propertiesPanel.add(getJLabel(), c); |
810 |
|
811 |
c.fill = GridBagConstraints.HORIZONTAL;
|
812 |
c.weightx = 1.0;
|
813 |
c.gridx = 1;
|
814 |
propertiesPanel.add(getLblNombreSesion(), c); |
815 |
|
816 |
c.gridx = 0;
|
817 |
c.gridy = 1;
|
818 |
c.fill = GridBagConstraints.NONE;
|
819 |
c.weightx = 0.0;
|
820 |
propertiesPanel.add(getJLabel1(), c); |
821 |
|
822 |
c.fill = GridBagConstraints.HORIZONTAL;
|
823 |
c.weightx = 1.0;
|
824 |
c.gridx = 1;
|
825 |
propertiesPanel.add(getLblGuardado(), c); |
826 |
|
827 |
c.gridx = 0;
|
828 |
c.gridy = 2;
|
829 |
c.fill = GridBagConstraints.NONE;
|
830 |
c.weightx = 0.0;
|
831 |
propertiesPanel.add(getJLabel2(), c); |
832 |
|
833 |
c.fill = GridBagConstraints.HORIZONTAL;
|
834 |
c.weightx = 1.0;
|
835 |
c.gridx = 1;
|
836 |
propertiesPanel.add(getLblFecha(), c); |
837 |
|
838 |
c.gridx = 0;
|
839 |
c.gridwidth = 2;
|
840 |
c.gridy = 4;
|
841 |
c.fill = GridBagConstraints.HORIZONTAL;
|
842 |
c.anchor = GridBagConstraints.EAST;
|
843 |
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 |
} |
852 |
|
853 |
return propertiesPanel;
|
854 |
} |
855 |
|
856 |
/**
|
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 |
|
867 |
return jLabel;
|
868 |
} |
869 |
|
870 |
/**
|
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 |
|
883 |
return lblNombreSesion;
|
884 |
} |
885 |
|
886 |
/**
|
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 |
|
897 |
return jLabel1;
|
898 |
} |
899 |
|
900 |
/**
|
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 |
|
912 |
return lblGuardado;
|
913 |
} |
914 |
|
915 |
/**
|
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 |
|
927 |
return jLabel2;
|
928 |
} |
929 |
|
930 |
/**
|
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 |
|
942 |
return lblFecha;
|
943 |
} |
944 |
|
945 |
/**
|
946 |
* This method initializes btnImportar
|
947 |
*
|
948 |
* @return JButton
|
949 |
*/
|
950 |
private JButton getBtnImportar() { |
951 |
if (btnImportar == null) { |
952 |
btnImportar = manager.createJButton(); |
953 |
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 |
|
959 |
return btnImportar;
|
960 |
} |
961 |
|
962 |
/**
|
963 |
* This method initializes btnExportar
|
964 |
*
|
965 |
* @return JButton
|
966 |
*/
|
967 |
private JButton getBtnExportar() { |
968 |
if (btnExportar == null) { |
969 |
btnExportar = manager.createJButton(); |
970 |
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 |
|
976 |
return btnExportar;
|
977 |
} |
978 |
|
979 |
/**
|
980 |
* This method initializes btnEditar
|
981 |
*
|
982 |
* @return JButton
|
983 |
*/
|
984 |
private JButton getBtnEditar() { |
985 |
if (btnEditar == null) { |
986 |
btnEditar = manager.createJButton(); |
987 |
btnEditar.setPreferredSize(new java.awt.Dimension(80, 23)); |
988 |
btnEditar.setText(PluginServices.getText(this, "propiedades")); |
989 |
|
990 |
btnEditar.setName("btnEditar");
|
991 |
btnEditar.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
992 |
|
993 |
btnEditar.addActionListener(new java.awt.event.ActionListener() {
|
994 |
|
995 |
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 |
|
1003 |
return btnEditar;
|
1004 |
} |
1005 |
|
1006 |
/**
|
1007 |
* This method initializes jScrollPane
|
1008 |
*
|
1009 |
* @return JScrollPane
|
1010 |
*/
|
1011 |
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 |
.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
|
1019 |
} |
1020 |
|
1021 |
return documentsScrollPane;
|
1022 |
} |
1023 |
|
1024 |
/**
|
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 |
m_viewInfo = |
1047 |
new WindowInfo(WindowInfo.MAXIMIZABLE | WindowInfo.RESIZABLE);
|
1048 |
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 |
m_viewInfo.setMinimumSize(getPreferredSize()); |
1053 |
|
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 |
private JPanel getProjectsButtonPanel() { |
1069 |
if (projectButtonsPanel == null) { |
1070 |
projectButtonsPanel = new JPanel(); |
1071 |
|
1072 |
projectButtonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
1073 |
projectButtonsPanel |
1074 |
.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT); |
1075 |
// TODO: implement export and import functions
|
1076 |
// projectButtonsPanel.add(getBtnImportar(), null);
|
1077 |
// projectButtonsPanel.add(getBtnExportar(), null);
|
1078 |
projectButtonsPanel.add(getBtnEditar(), null);
|
1079 |
} |
1080 |
|
1081 |
return projectButtonsPanel;
|
1082 |
} |
1083 |
|
1084 |
public Object getWindowProfile() { |
1085 |
return WindowInfo.PROJECT_PROFILE;
|
1086 |
} |
1087 |
|
1088 |
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 |
documentTypesList.removeAll(); |
1101 |
for (Enumeration<AbstractButton> buttons = grupo.getElements(); buttons |
1102 |
.hasMoreElements();) { |
1103 |
grupo.remove(buttons.nextElement()); |
1104 |
} |
1105 |
|
1106 |
JRadioButton[] btnDocuments = getBtnDocumentTypes(); |
1107 |
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 |
} |