Revision 10679 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/ProjectExtension.java
ProjectExtension.java | ||
---|---|---|
164 | 164 |
{ |
165 | 165 |
PluginServices.getLogger().debug("Intentando cargar el proyecto " + lastArg); |
166 | 166 |
//File projectFile = new File(lastArg); |
167 |
p = readProject(lastArg);
|
|
167 |
setProject(readProject(lastArg));
|
|
168 | 168 |
PluginServices.getMainFrame().setTitle(p.getName()); |
169 | 169 |
projectPath = lastArg; |
170 | 170 |
} |
171 | 171 |
else |
172 | 172 |
{ |
173 |
p = ProjectFactory.createProject();
|
|
173 |
setProject(ProjectFactory.createProject());
|
|
174 | 174 |
p.setName(PluginServices.getText(this, "untitled")); |
175 | 175 |
p.setModified(false); |
176 | 176 |
PluginServices.getMainFrame().setTitle(PluginServices.getText(this, "sin_titulo")); |
... | ... | |
265 | 265 |
* |
266 | 266 |
* @return True si se ha guardado correctamente. |
267 | 267 |
*/ |
268 |
private boolean modificado() {
|
|
269 |
if (p.isModified()) {
|
|
268 |
private int askSave() {
|
|
269 |
if (p.hasChanged()) {
|
|
270 | 270 |
///if (true) { |
271 | 271 |
//TODO de momento se queda como modificado siempre menos cuando est? totalmente vacio que se tomar? como no modificado, |
272 | 272 |
//para poder controlar perfectamente cuando un proyecto ha sido modificado |
273 | 273 |
//hay que recoger los eventos de cambio de leyenda, cambio de extent, a?adir una capa, etc que se encuentran en FMap. |
274 | 274 |
|
275 |
int res = JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(),
|
|
275 |
return JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(),
|
|
276 | 276 |
PluginServices.getText(this, "guardar_cambios"), |
277 | 277 |
"gvSIG", |
278 | 278 |
JOptionPane.YES_NO_CANCEL_OPTION, |
279 | 279 |
JOptionPane.INFORMATION_MESSAGE); |
280 | 280 |
|
281 |
if (res == JOptionPane.YES_OPTION) { |
|
282 |
guardar(); |
|
283 |
} else if (res == JOptionPane.CANCEL_OPTION) { |
|
284 |
return false; |
|
285 |
} |
|
286 | 281 |
} |
287 | 282 |
|
288 |
return true;
|
|
283 |
return JOptionPane.NO_OPTION;
|
|
289 | 284 |
} |
290 | 285 |
|
291 | 286 |
/** |
... | ... | |
294 | 289 |
public void execute(String actionCommand) { |
295 | 290 |
if (actionCommand.equals("NUEVO")) { |
296 | 291 |
//Si est? modificado se pregunta si se quiere guardar el anterior |
297 |
if (!modificado()) { |
|
292 |
int answer = askSave(); |
|
293 |
if (answer == JOptionPane.CANCEL_OPTION) { |
|
294 |
// then do nothing |
|
298 | 295 |
return; |
296 |
} else if (answer == JOptionPane.YES_OPTION) { |
|
297 |
execute("GUARDAR"); |
|
299 | 298 |
} |
300 | 299 |
ProjectDocument.initializeNUMS(); |
301 | 300 |
PluginServices.getMDIManager().closeAllWindows(); |
302 |
p = ProjectFactory.createProject();
|
|
303 |
p.setName(PluginServices.getText(this, "untitled")); |
|
304 |
p.setModified(true); |
|
301 |
setProject(ProjectFactory.createProject());
|
|
302 |
|
|
303 |
// p.setModified(true);
|
|
305 | 304 |
getProjectFrame().setProject(p); |
306 | 305 |
showProjectWindow(); |
307 | 306 |
PluginServices.getMainFrame().setTitle(PluginServices.getText(this, "sin_titulo")); |
308 | 307 |
} else if (actionCommand.equals("ABRIR")) { |
309 | 308 |
//Si est? modificado se pregunta si se quiere guardar el anterior |
310 |
if (!modificado()) { |
|
309 |
int answer = askSave(); |
|
310 |
|
|
311 |
if (answer == JOptionPane.CANCEL_OPTION) { // ? don't ask me why |
|
311 | 312 |
ProjectDocument.initializeNUMS(); |
312 | 313 |
return; |
313 | 314 |
} |
... | ... | |
330 | 331 |
setPath(projectFile.getAbsolutePath()); |
331 | 332 |
lastPath = getPath(); |
332 | 333 |
if (o != null) { |
333 |
p = o;
|
|
334 |
setProject(o);
|
|
334 | 335 |
} |
335 | 336 |
|
336 | 337 |
getProjectFrame().setProject(p); |
337 | 338 |
PluginServices.getMainFrame().setTitle(p.getName()); |
338 | 339 |
getProjectFrame().refreshControls(); |
339 |
p.setModified(true); |
|
340 |
|
|
341 |
//jaume p.setModified(true); |
|
340 | 342 |
p.restoreWindowProperties(); |
341 | 343 |
} |
342 | 344 |
} else if (actionCommand.equals("GUARDAR")) { |
343 | 345 |
guardar(); |
344 |
p.setModified(false); |
|
346 |
//jaume p.setModified(false);
|
|
345 | 347 |
} else if (actionCommand.equals("GUARDAR_COMO")) { |
346 | 348 |
guardarDialogo(); |
347 |
p.setModified(false); |
|
349 |
//jaume p.setModified(false);
|
|
348 | 350 |
} else if (actionCommand.equals("SALIR")){ |
349 | 351 |
int option = JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(), |
350 | 352 |
Messages.getString("MDIFrame.quiere_salir"), |
... | ... | |
356 | 358 |
} |
357 | 359 |
} else if (actionCommand.compareTo("OPENTEMPLATE")==0){ |
358 | 360 |
openLayout(); |
359 |
p.setModified(true); |
|
361 |
//jaume p.setModified(true);
|
|
360 | 362 |
} |
361 | 363 |
} |
362 | 364 |
public void openLayout() { |
... | ... | |
443 | 445 |
p.setModificationDate(DateFormat.getDateInstance().format(new Date())); |
444 | 446 |
p.setModified(false); |
445 | 447 |
XMLEntity xml = p.getXMLEntity(); |
446 |
xml.putProperty("followHeaderEncoding", true); |
|
448 |
xml.putProperty("followHeaderEncoding", true, false);
|
|
447 | 449 |
m.marshal(xml.getXmlTag()); |
448 | 450 |
PluginServices.getMainFrame().setTitle(file.getName()); |
449 | 451 |
setPath(file.toString()); |
... | ... | |
656 | 658 |
*/ |
657 | 659 |
public void setProject(Project p){ |
658 | 660 |
getProjectFrame().setProject(p); |
661 |
p.setSignature(p.getXMLEntity().hash()); |
|
659 | 662 |
this.p=p; |
660 | 663 |
} |
661 | 664 |
|
665 |
public boolean isReadyToTerminate() { |
|
666 |
int answer = askSave(); |
|
667 |
|
|
668 |
if (answer == JOptionPane.CANCEL_OPTION) { |
|
669 |
// the user doesn't want to close the application |
|
670 |
// so quit will be canceled. |
|
671 |
return false; |
|
672 |
} else if (answer == JOptionPane.YES_OPTION) { |
|
673 |
// the user wants to save the project before exit |
|
674 |
boolean ready = guardar(); |
|
675 |
if (!ready) { |
|
676 |
int sel = JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(), |
|
677 |
PluginServices.getText(this, "the_project_could_not_be_saved.Continue_exiting_anyway"), |
|
678 |
PluginServices.getText(this, "warning"), |
|
679 |
JOptionPane.YES_NO_OPTION); |
|
680 |
ready = (sel == JOptionPane.YES_OPTION); |
|
681 |
} |
|
682 |
|
|
683 |
return ready; |
|
684 |
} else if (answer == JOptionPane.NO_OPTION) { |
|
685 |
// the user doesn't care about the current state of the project |
|
686 |
return true; |
|
687 |
} else { |
|
688 |
NotificationManager.addWarning("Reached what should be unreachable code", new IllegalArgumentException()); |
|
689 |
return false; |
|
690 |
} |
|
691 |
} |
|
692 |
|
|
662 | 693 |
//Finalizar y preguntar si se quiere guardar el proyecto o cancelar. |
663 | 694 |
public void terminate() { |
664 |
long t1,t2; |
|
665 |
t1 = System.currentTimeMillis(); |
|
666 |
//if (getProject().hasChanged()) {
|
|
667 |
int option = JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"guardar_cambios"), |
|
668 |
PluginServices.getText(this,"guardar_proyecto"), |
|
669 |
JOptionPane.YES_NO_OPTION); |
|
670 |
|
|
671 |
if (option == JOptionPane.YES_OPTION) { |
|
672 |
if (!guardar()) |
|
673 |
terminate(); |
|
674 |
} |
|
675 |
//}
|
|
676 |
t2 = System.currentTimeMillis(); |
|
677 |
System.err.println("ProjectExtension.terminate() " + (t2-t1) + "milisecs"); |
|
695 |
// long t1,t2;
|
|
696 |
// t1 = System.currentTimeMillis();
|
|
697 |
// if (askSave()){
|
|
698 |
// int option = JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"guardar_cambios"),
|
|
699 |
// PluginServices.getText(this,"guardar_proyecto"),
|
|
700 |
// JOptionPane.YES_NO_OPTION);
|
|
701 |
// |
|
702 |
// if (option == JOptionPane.YES_OPTION) {
|
|
703 |
// if (!guardar())
|
|
704 |
// terminate();
|
|
705 |
// }
|
|
706 |
// }
|
|
707 |
// t2 = System.currentTimeMillis();
|
|
708 |
// System.err.println("ProjectExtension.terminate() " + (t2-t1) + "milisecs");
|
|
678 | 709 |
} |
679 | 710 |
|
680 | 711 |
private void registerDocuments() { |
... | ... | |
682 | 713 |
ProjectTableFactory.register(); |
683 | 714 |
ProjectMapFactory.register(); |
684 | 715 |
} |
716 |
|
|
685 | 717 |
private void initializeDocumentActionsExtensionPoint() { |
686 | 718 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
687 | 719 |
if (!extensionPoints.containsKey("DocumentActions_View")) { |
Also available in: Unified diff