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