Revision 42200 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/ProjectExtension.java
ProjectExtension.java | ||
---|---|---|
36 | 36 |
|
37 | 37 |
import org.slf4j.Logger; |
38 | 38 |
import org.slf4j.LoggerFactory; |
39 |
|
|
39 | 40 |
import org.gvsig.tools.util.ArrayUtils; |
41 |
|
|
40 | 42 |
import org.apache.commons.lang.StringUtils; |
43 |
|
|
41 | 44 |
import org.gvsig.andami.IconThemeHelper; |
42 | 45 |
import org.gvsig.andami.Launcher; |
43 | 46 |
import org.gvsig.andami.Launcher.TerminationProcess; |
... | ... | |
74 | 77 |
* Extension que proporciona controles para crear proyectos nuevos, abrirlos y |
75 | 78 |
* guardarlos. Adem?s los tipos de tabla que soporta el proyecto son a?adidos en |
76 | 79 |
* esta clase. |
77 |
*
|
|
80 |
* |
|
78 | 81 |
* @author Fernando Gonz?lez Cort?s |
79 | 82 |
*/ |
80 | 83 |
public class ProjectExtension extends Extension implements IExtensionStatus { |
... | ... | |
89 | 92 |
public static final String PROJECT_FILE_CHOOSER_ID = "PROJECT_FILECHOOSER_ID"; |
90 | 93 |
/** |
91 | 94 |
* Use UTF-8 for encoding, as it can represent characters from any language. |
92 |
*
|
|
95 |
* |
|
93 | 96 |
* Another sensible option would be encoding = |
94 | 97 |
* System.getProperty("file.encoding"); but this would need some extra |
95 | 98 |
* testing. |
96 |
*
|
|
99 |
* |
|
97 | 100 |
* @deprecated see PersistentManager |
98 | 101 |
*/ |
99 | 102 |
public static String PROJECTENCODING = "UTF-8"; |
... | ... | |
106 | 109 |
initializeDocumentActionsExtensionPoint(); |
107 | 110 |
registerDocuments(); |
108 | 111 |
registerIcons(); |
109 |
|
|
112 |
|
|
110 | 113 |
File projectFile = getProjectFileFromArguments(); |
111 | 114 |
if( projectFile!=null ) { |
112 | 115 |
// Posponemos la apertura del proyecto ya que en este momento |
... | ... | |
133 | 136 |
/** |
134 | 137 |
* Returns the file to be opened or null if no parameter |
135 | 138 |
* or file does not exist |
136 |
*
|
|
139 |
* |
|
137 | 140 |
* @return |
138 | 141 |
*/ |
139 | 142 |
private File getProjectFileFromArguments() { |
... | ... | |
151 | 154 |
return null; |
152 | 155 |
} |
153 | 156 |
if (!lastArg.toLowerCase().endsWith(Project.FILE_EXTENSION.toLowerCase())) { |
154 |
LOG.info("Do not open project file, does not have the expected extension '" +
|
|
157 |
LOG.info("Do not open project file, does not have the expected extension '" + |
|
155 | 158 |
Project.FILE_EXTENSION +"' ("+lastArg+")."); |
156 | 159 |
return null; |
157 | 160 |
} |
... | ... | |
161 | 164 |
return null; |
162 | 165 |
} |
163 | 166 |
return projectFile; |
164 |
}
|
|
167 |
} |
|
165 | 168 |
|
166 | 169 |
private class OpenInitialProjectTask implements Runnable { |
167 | 170 |
private File projectFile; |
... | ... | |
247 | 250 |
prefs.get("ProjectsFolder", null)); |
248 | 251 |
|
249 | 252 |
jfc.setDialogTitle(PluginServices.getText(this, "guardar_proyecto")); |
250 |
|
|
253 |
|
|
251 | 254 |
GenericFileFilter projExtensionFilter = new GenericFileFilter( |
252 | 255 |
Project.FILE_EXTENSION, MessageFormat.format(PluginServices |
253 | 256 |
.getText(this, "tipo_fichero_proyecto"), |
... | ... | |
277 | 280 |
/** |
278 | 281 |
* Checks whether the project and related unsaved data is modified, and |
279 | 282 |
* allows the user to save it. |
280 |
*
|
|
283 |
* |
|
281 | 284 |
* @return true if the data has been correctly saved, false otherwise |
282 | 285 |
*/ |
283 | 286 |
private boolean askSave() { |
... | ... | |
310 | 313 |
public void execute(String command) { |
311 | 314 |
this.execute(command, null); |
312 | 315 |
} |
313 |
|
|
316 |
|
|
314 | 317 |
public void execute(String actionCommand, Object[] args) { |
315 | 318 |
if (actionCommand.equals("application-project-new")) { |
316 | 319 |
if (!askSave()) { |
... | ... | |
342 | 345 |
"gvsig.foldering"); |
343 | 346 |
JFileChooser jfc = new JFileChooser(PROJECT_FILE_CHOOSER_ID, |
344 | 347 |
prefs.get("ProjectsFolder", null)); |
345 |
|
|
348 |
|
|
346 | 349 |
GenericFileFilter projExtensionFilter = new GenericFileFilter( |
347 | 350 |
Project.FILE_EXTENSION, PluginServices.getText(this, |
348 | 351 |
"tipo_fichero_proyecto")); |
... | ... | |
354 | 357 |
return; |
355 | 358 |
} |
356 | 359 |
// ProjectDocument.initializeNUMS(); |
357 |
|
|
358 | 360 |
|
361 |
|
|
359 | 362 |
projectFile = jfc.getSelectedFile(); |
360 | 363 |
} |
361 |
|
|
364 |
|
|
362 | 365 |
PluginServices.getMDIManager().closeAllWindows(); |
363 | 366 |
|
364 | 367 |
Project o = readProject(projectFile); |
... | ... | |
375 | 378 |
// p.restoreWindowProperties(); |
376 | 379 |
|
377 | 380 |
} else if (actionCommand.equals("application-project-save")) { |
378 |
saveProject(); |
|
381 |
// saveProject(); |
|
382 |
try { |
|
383 |
Launcher.manageUnsavedData("there_are_unsaved_resources"); |
|
384 |
} catch (Exception e) { |
|
385 |
LOG.warn("Can't manage unsaved data", e); |
|
386 |
} |
|
379 | 387 |
} else if (actionCommand.equals("application-project-save-as")) { |
380 | 388 |
File file = (File) ArrayUtils.get(args, 0, DataTypes.FILE); |
381 | 389 |
saveAsProject(file); |
... | ... | |
383 | 391 |
|
384 | 392 |
} |
385 | 393 |
|
386 |
|
|
394 |
|
|
387 | 395 |
private void createEmptyProject() { |
388 | 396 |
setProject(ProjectManager.getInstance().createProject()); |
389 | 397 |
p.setName(PluginServices.getText(this, "untitled")); |
... | ... | |
411 | 419 |
} catch (Exception e) { |
412 | 420 |
LOG.warn("Can't load initial project.",e); |
413 | 421 |
} |
414 |
}
|
|
415 |
|
|
416 |
|
|
422 |
} |
|
423 |
|
|
424 |
|
|
417 | 425 |
/** |
418 | 426 |
* Escribe el proyecto en XML. |
419 |
*
|
|
427 |
* |
|
420 | 428 |
* @param file |
421 | 429 |
* Fichero. |
422 | 430 |
* @param p |
... | ... | |
429 | 437 |
/** |
430 | 438 |
* Escribe el proyecto en XML. Pero permite decidir si se pide confirmaci?n |
431 | 439 |
* para sobreescribir |
432 |
*
|
|
440 |
* |
|
433 | 441 |
* @param file |
434 | 442 |
* Fichero. |
435 | 443 |
* @param p |
... | ... | |
488 | 496 |
/** |
489 | 497 |
* Lee del XML el proyecto.<br> |
490 | 498 |
* <br> |
491 |
*
|
|
499 |
* |
|
492 | 500 |
* Reads the XML of the project.<br> |
493 | 501 |
* It returns a project object holding all needed info that is not linked to |
494 | 502 |
* the Project Dialog. <br> |
495 | 503 |
* In case you want the project to be linked to the window you must set this |
496 | 504 |
* object to the extension:<br> |
497 |
*
|
|
505 |
* |
|
498 | 506 |
* <b>Example:</b><br> |
499 |
*
|
|
507 |
* |
|
500 | 508 |
* ...<br> |
501 | 509 |
* ...<br> |
502 | 510 |
* Project p = ProjectExtension.readProject(projectFile);<br> |
503 | 511 |
* ProjectExtension.setProject(p); ...<br> |
504 | 512 |
* ...<br> |
505 |
*
|
|
513 |
* |
|
506 | 514 |
* @param file |
507 | 515 |
* Fichero. |
508 |
*
|
|
516 |
* |
|
509 | 517 |
* @return Project |
510 |
*
|
|
518 |
* |
|
511 | 519 |
*/ |
512 | 520 |
public Project readProject(File file) { |
513 | 521 |
Project project = ProjectManager.getInstance().createProject(); |
... | ... | |
518 | 526 |
|
519 | 527 |
/** |
520 | 528 |
* Devuelve el proyecto. |
521 |
*
|
|
529 |
* |
|
522 | 530 |
* @return Proyecto. |
523 | 531 |
*/ |
524 | 532 |
public Project getProject() { |
... | ... | |
541 | 549 |
|
542 | 550 |
/** |
543 | 551 |
* Sets the project |
544 |
*
|
|
552 |
* |
|
545 | 553 |
* @param p |
546 | 554 |
*/ |
547 | 555 |
public void setProject(Project p) { |
... | ... | |
596 | 604 |
/** |
597 | 605 |
* Implements the IUnsavedData interface to show unsaved projects in the |
598 | 606 |
* Unsavad Data dialog. |
599 |
*
|
|
607 |
* |
|
600 | 608 |
* @author Cesar Martinez Izquierdo <cesar.martinez@iver.es> |
601 | 609 |
*/ |
602 | 610 |
public class UnsavedProject extends UnsavedData { |
... | ... | |
647 | 655 |
* Adds the specified before saving listener to receive |
648 | 656 |
* "before saving file events" from this component. If l is null, no |
649 | 657 |
* exception is thrown and no action is performed. |
650 |
*
|
|
658 |
* |
|
651 | 659 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es> |
652 |
*
|
|
660 |
* |
|
653 | 661 |
* @param l |
654 | 662 |
* the before saving listener. |
655 | 663 |
* @see SaveEvent |
... | ... | |
670 | 678 |
* Adds the specified after saving listener to receive |
671 | 679 |
* "after saving file events" from this component. If l is null, no |
672 | 680 |
* exception is thrown and no action is performed. |
673 |
*
|
|
681 |
* |
|
674 | 682 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es> |
675 |
*
|
|
683 |
* |
|
676 | 684 |
* @param l |
677 | 685 |
* the after saving listener. |
678 | 686 |
* @see SaveEvent |
... | ... | |
694 | 702 |
/** |
695 | 703 |
* Returns an array of all the before saving listeners registered on this |
696 | 704 |
* component. |
697 |
*
|
|
705 |
* |
|
698 | 706 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es> |
699 |
*
|
|
707 |
* |
|
700 | 708 |
* @return all of this component's <code>BeforeSavingListener</code>s or an |
701 | 709 |
* empty array if no key listeners are currently registered |
702 |
*
|
|
710 |
* |
|
703 | 711 |
* @see #addBeforeSavingListener(BeforeSavingListener) |
704 | 712 |
* @see #removeBeforeSavingListener(BeforeSavingListener) |
705 | 713 |
*/ |
... | ... | |
711 | 719 |
/** |
712 | 720 |
* Returns an array of all the after saving listeners registered on this |
713 | 721 |
* component. |
714 |
*
|
|
722 |
* |
|
715 | 723 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es> |
716 |
*
|
|
724 |
* |
|
717 | 725 |
* @return all of this component's <code>AfterSavingListener</code>s or an |
718 | 726 |
* empty array if no key listeners are currently registered |
719 |
*
|
|
727 |
* |
|
720 | 728 |
* @see #addAfterSavingListener(AfterSavingListener) |
721 | 729 |
* @see #removeAfterSavingListener |
722 | 730 |
*/ |
... | ... | |
732 | 740 |
* the argument was not previously added to this component. If listener |
733 | 741 |
* <code>l</code> is <code>null</code>, no exception is thrown and no action |
734 | 742 |
* is performed. |
735 |
*
|
|
743 |
* |
|
736 | 744 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es> |
737 |
*
|
|
745 |
* |
|
738 | 746 |
* @param l |
739 | 747 |
* the before saving listener |
740 | 748 |
* @see SaveEvent |
... | ... | |
756 | 764 |
* nor does it throw an exception, if the listener specified by the argument |
757 | 765 |
* was not previously added to this component. If listener <code>l</code> is |
758 | 766 |
* <code>null</code>, no exception is thrown and no action is performed. |
759 |
*
|
|
767 |
* |
|
760 | 768 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es> |
761 |
*
|
|
769 |
* |
|
762 | 770 |
* @param l |
763 | 771 |
* the after saving listener |
764 | 772 |
* @see SaveEvent |
... | ... | |
776 | 784 |
|
777 | 785 |
/** |
778 | 786 |
* Reports a before saving file event. |
779 |
*
|
|
787 |
* |
|
780 | 788 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es> |
781 |
*
|
|
789 |
* |
|
782 | 790 |
* @param evt |
783 | 791 |
* the before saving file event |
784 | 792 |
*/ |
... | ... | |
797 | 805 |
|
798 | 806 |
/** |
799 | 807 |
* Reports a after saving file event. |
800 |
*
|
|
808 |
* |
|
801 | 809 |
* @author Pablo Piqueras Bartolom? <pablo.piqueras@iver.es> |
802 |
*
|
|
810 |
* |
|
803 | 811 |
* @param evt |
804 | 812 |
* the after saving file event |
805 | 813 |
*/ |
Also available in: Unified diff