Monitoring opening and closing of projects in NetBeans IDE

The NetBeans has had an API to find out what projects are open in the IDE. See OpenProjects. Also there is an API to monitor the opening and closing of the projects. Basically, you have to register a PropertyChangeListener and listen for PROPERTY_OPEN_PROJECTS property changes. However due to the issues #98894 and #64397 this was harder. The problem was that the property change event did not populate the old and new value of open projects array. Therefore the client code had to cache the open projects array by calling the OpenProjects.getDefault().getOpenProjects(), and when the property change event was received call the the OpenProjects.getDefault().getOpenProjects()again and compute opened and closed projects by comparing with previously cached array.

Thanks to very recent bug fixes for issues 98894 and #64397 in NetBeans CVS trunk, the task of monitoring the opening and closing of projects has become really simple. Here is the code:

OpenProjects.getDefault().addPropertyChangeListener(
    new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (OpenProjects.PROPERTY_OPEN_PROJECTS.equals(evt.getPropertyName())) {
                List<Project> oldOpenProjectsList = Arrays.asList((Project[])evt.getOldValue());
                List<Project> newOpenProjectsList = Arrays.asList((Project[])evt.getNewValue());
               
                Set<Project> closedProjectsSet = new LinkedHashSet<Project>(oldOpenProjectsList);
                closedProjectsSet.removeAll(newOpenProjectsList);
                for (Project project : closedProjectsSet) {
                    // Process closed projects
                }
               
                Set<Project> openedProjectsSet = new LinkedHashSet<Project>(newOpenProjectsList);
                openedProjectsSet.removeAll(oldOpenProjectsList);
                for (Project project : openedProjectsSet) {
                    // Process opened projects
                }
            }
        }      
    }
);

DISCLAIMER: This code is experimental. So no guarantees. Use it at your own risk.

Comments:

It sure does sound complecated how difficult it must have been earlier to figure out which projects have been opened and which have been closed. But I also must say, api support for being notified upon closed and open Project still seems to be bad. How about a
...new OpenedProjectChangeListener() { 
propertyChanged(OpenProjectChangeEvent evt) {
Set<Project> openedProjects = evt.getOpenProjects()
}
}...

Posted by Thomas Zillinger on March 26, 2007 at 04:30 PM PDT #

Instead of 'bad' I should have said 'not as good as it could be' :) You are doing a great job, there!!

Posted by Thomas Zillinger on March 26, 2007 at 04:43 PM PDT #

Thanks Thomas for your comments.

I had already filed an enhancement to make it simpler. See http://www.netbeans.org/issues/show_bug.cgi?id=98895. This involves an API change though which is slightly more complicated. So in the mean time the above is the solution (not totally satisfactory).

Posted by Sandip on March 27, 2007 at 12:16 AM PDT #

NOTE: Another thing to note is that the client code should not execute long running tasksin the project open/close callbacks thread. That slows down the percieved time it takes to open/close projects.

Posted by Sandip on March 27, 2007 at 12:19 AM PDT #

Sandip, First of all, please go back to the previous color scheme. Reading gray text on black is not at all eye pleasing, unless the font size is really huge. Also, is there a plan, for releasing netbeans fixes as hotfixes/binary patches ? I see no reason in doing so, especially considering that what is affected at most is one or 2 classes. So why should one need to get unstable CVS head branch for fixes ? Shouldn't netbeans have a update support that can update core features for stuff like bug fixes/security updates etc ?

Posted by gumnaam on March 27, 2007 at 12:20 AM PDT #

Gumnaam,

AFAIK there is notion of Hotfixe releases in NetBeans. I think the iussues that qualify as "hotfixes" get released like that. I am not sure if this particualr issue rises to that level. If you think so please add you comments and votes to the bug. ALso raise it on the nbdev mailing list.

I will look into the color scheme issue.

Posted by Sandip on March 27, 2007 at 12:55 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

sandipchitale

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today