This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 57610 - Discard All option in Save dialog in Close Project action works incorrectly
Summary: Discard All option in Save dialog in Close Project action works incorrectly
Status: RESOLVED WONTFIX
Alias: None
Product: projects
Classification: Unclassified
Component: Generic Projects UI (show other bugs)
Version: 4.x
Hardware: PC Windows XP
: P3 blocker with 1 vote (vote)
Assignee: Milan Kubec
URL:
Keywords:
: 84236 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-04-07 13:59 UTC by Pavel Fiala
Modified: 2008-09-29 11:26 UTC (History)
6 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Fiala 2005-04-07 13:59:51 UTC
- Create  Web Application
- Make any modification in web.xml 
- Close te Web Application (Close Project)
- In Save dialog click button Discard All. The Web Application is closed 
- Re-open the Web Application (Open Recent Project)
- The web.xml is still changed but SaveCookie is not set. Consequent chchanges
of web.xml have no influence to on SaveCookie, so it is impossible to save changes
Comment 1 Petr Hrebejk 2005-04-07 14:29:57 UTC
Works fine for any file in J2SE project. A memory leak in web?
Comment 2 Pavel Fiala 2005-04-07 14:45:25 UTC
The problem is that DataObject does not know that modified data has been
discarded. Method theEnd() in ExitDialog calls setModified(false) on each
DataObject belonging to closing projects but nothing else. It is fine for saved
data objects but modified data objects are marked as unmodified without
reloading the original data. 

I think there should be called setValid(false) for each data object.

Following change seems to be helpful:

RCS file:
/cvs/projects/projectui/src/org/netbeans/modules/project/ui/ProjectUtilities.java,v
retrieving revision 1.18
diff -u -r1.18 ProjectUtilities.java
--- org/netbeans/modules/project/ui/ProjectUtilities.java	5 Apr 2005 07:53:57
-0000	1.18
+++ org/netbeans/modules/project/ui/ProjectUtilities.java	7 Apr 2005 13:36:33 -0000
@@ -28,6 +28,7 @@
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
+import java.beans.PropertyVetoException;
 import javax.swing.Action;
 import javax.swing.JFrame;
 import javax.swing.SwingUtilities;
@@ -122,9 +123,13 @@
             
             if (!openFiles.isEmpty () && ExitDialog.showDialog (openFiles)) {
                 // close documents
-                Iterator it = tc2close.iterator ();
-                while (it.hasNext ()) {
-                    ((TopComponent)it.next ()).close ();
+                for (Iterator it = openFiles.iterator(); it.hasNext();) {
+                    DataObject dataObject = (DataObject) it.next();
+                    try {
+                        dataObject.setValid(false);
+                    } catch (PropertyVetoException e) {
+                        ErrorManager.getDefault().notify(e);
+                    }
                 }
             } else {
                 // signal that close was vetoed
Comment 3 Jesse Glick 2005-04-07 16:33:20 UTC
Careful here. Get a second opinion from someone who understands how data object
modification works. Petr N. maybe?
Comment 4 _ rkubacki 2005-04-07 17:31:04 UTC
There was a bug 57483 depending on this that is not fixed. So no action is
needed. Now there is another bug 57626. Please tell us exactly what is wrong and
why it should be fixed in projects and make sure that XmlMultiview support works
correctly before doing this.

Re setValid(): I disagree. It is not a right way how to fix your problem.
Comment 5 _ rkubacki 2005-04-07 17:33:02 UTC
It is not clear what is wrong from the report.
Comment 6 Milan Kuchtiak 2005-04-07 18:17:50 UTC
There was lot of stuff in issue 47483 so I split it into 57483 and 57626.
Now only the issue 57626 depends on this.

I'll try to describe the problem :
In xml/multiview editor we modify the data model (schema2beans model) related to
xml document (web.xml).

Normally when editor is closed and changes are discarded we refresh the data
model back from file. This is because the core/multiview + core/windows
infrastructure informs us that changes were discarded.

On other hand : if the project is closed with web.xml open(Close->Discard All)
only the DataObject.setModified(false) is called. Here we don't have the
possibility to do a "cleanup" (e.g. to refresh model back from file).

Another problem is that after reopening the project (the editor top components
are deserialized that time) the text is changed in editor and Save button
disabled forever.

Do we do something wrong?
Comment 7 Pavel Fiala 2005-04-08 06:27:58 UTC
Re setValid(): From my point of view setValid(false) works fine, but I am not
expert in this area. It does not matter how we would be notified that project
was closed or changes were discarded. Just suggest any other suitable solution.  
Comment 8 Jiri Rechtacek 2005-04-08 09:09:32 UTC
The problem appears only with web.xml file not for others. Is it possible to
handle this on web.xml side? What about listen on setModified(false) and do
necessary 'cleanup' on this? Other file types can get over it and don't ask any
special handling. Isn't this patch an overkill for others files?
Comment 9 Pavel Fiala 2005-04-08 09:40:04 UTC
The solution in dd editors would be a workaround, not solution. The problem is
reproducible also in J2SE.

Scenario:

- Create Java Application 
- Modify Main.java
- Clone document Main.java
- Move cloned Main.java using drag&drop to another part of workspace (for
example to the right).
- Close the Java Application and choose Discard All in Save dialog.

Main.java remains modified but save button is disabled.

Fortunately the cloned Main.java is not closed owing to problem described in
Issue 57621, so the bug is reproducible also in J2SE even though there exists a
workaround partially solving the issue. 




Comment 10 Milan Kuchtiak 2005-04-08 09:55:06 UTC
Listening on setModified(false) don't help us much as setModified(false) is also
called in these cases :
- Data Object is saved
- Data Object is closed with Save Option
- Data Object is saved with Discard option

We probably need something more.

I think, we can live with 57626 for release41 (its quite a corner case when
project is closed, changes are discarded for data object and project is opened
again).
Comment 11 _ rkubacki 2005-04-08 10:24:06 UTC
re pfiala's last comment: this is another problem - during project close only
documents edited in components that reside in editor mode are searched. Please
file it as separate bug so we do not mix the problems here.
Comment 12 _ rkubacki 2005-04-08 10:56:39 UTC
The reason of your problem is that notifyUnmodified() is not called on your
editor when the project is closed and closes all components belonging to
project. This works well for default DOs, Java sources or JSPs. Please
reevaluate to find if it is related to multiview or your implementation of XML
editing support. 
Comment 13 Pavel Fiala 2005-04-08 11:15:48 UTC
I think notifyUnmodified() just notifies that data in EditorSupport has been
synchronized with data in persistent storage and no additional action is
required to synchronize data. Do you think I am not right?
Comment 14 Milan Kuchtiak 2005-04-08 11:17:14 UTC
The same problem has sun-web.xml that has nothing common with core/multiview or
xml/multiview.
What should be done to get notifyUnmodified() called?
Comment 15 Milan Kuchtiak 2005-04-08 11:23:01 UTC
I am sorry.
I didn't want to change the component and subcomponent.
Comment 16 _ rkubacki 2005-04-08 12:45:16 UTC
Right, it is not exactly notifyUnmodified(). It is rather bad closing of component.

How it works for other files during project close 
- DOs that are edited are gathered and user is asked to save them
- if she decides not to save them these DOs are marked as unmodified using
DO.setModified(false), the editor support is not altered yet
- all documents maintained by editor supports are closed and this results in
call to notifyUnmodified() where save cookie is often removed. 

You can look into form how it works there. 

I really don't know anything about sun-web.xml
Comment 17 Pavel Fiala 2005-04-08 13:29:44 UTC
I don't understand how can DO determine whether the changes were saved or
discarded if in both cases the same action is performed (setModified(false)).
Comment 18 Pavel Fiala 2005-04-08 14:06:49 UTC
If I see result of scenario above that reproduces the issue in J2SE, the data in
DO are out of sync until the project is reopen and it is incorrect behavior.
When we close project with discarding changes we need to notify DO that the
modified data is invalid. I am confident it is the only right flow.
Comment 19 Jiri Rechtacek 2005-04-08 14:59:08 UTC
The problem in J2SE will be fixed together with issue 57621. The problem stays
valid only for web.xml, IMHO still fixable in xml/multiview editing support.
Comment 20 Pavel Fiala 2005-04-10 20:31:20 UTC
Fixes of Issue 57626 and Issue 57621 have eliminated impact of this issue, so
the priority is not so high.

Despite there are no known visible consequences of this issue I consider the
solution of this issue pretty important. We need to notify data object or editor
support about discarding changes. I think we must not rely on reset data after
closing the last editor.
Comment 21 Jesse Glick 2005-04-11 20:43:59 UTC
Do we need a new API permitting code to programmatically close a window and save
or discard changes? I think this may be the first time it is required, since the
exit dialog doesn't have to worry about what happens after the VM exits.
Comment 22 Jiri Rechtacek 2005-11-21 15:37:38 UTC
Reassign to new owner.
Comment 23 Milan Kubec 2007-08-13 16:10:39 UTC
*** Issue 84236 has been marked as a duplicate of this issue. ***
Comment 24 Milan Kubec 2008-09-29 11:26:34 UTC
The issue has been partially fixed and from subsequent comments it looks like it's not clear what the problem really is.
Closing as wontfix.