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