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