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.

View | Details | Raw Unified | Return to bug 91031
Collapse All | Expand All

(-)projectuiapi/apichanges.xml (+20 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
        <change id="ProjectGroup">
111
            <api name="general"/>
112
            <summary>API to get current active project group and listen to project groups switching</summary>
113
            <version major="1" minor="61"/>
114
            <date day="25" month="8" year="2012"/>
115
            <author login="mkleint"/>
116
            <compatibility addition="yes"/>
117
            <description>
118
                <p>
119
                    Added methods to 
120
                    <code>OpenProjects</code> to figure the currently active project group, access preferences related to it
121
                    and listen to changes in currently active group.
122
                </p>
123
            </description>
124
            <class package="org.netbeans.api.project.ui" name="OpenProjects"/>
125
            <class package="org.netbeans.api.project.ui" name="ProjectGroup"/>
126
            <class package="org.netbeans.spi.project.ui" name="ProjectGroupChangeListener"/>
127
            <class package="org.netbeans.spi.project.ui" name="ProjectGroupChangeEvent"/>
128
            <issue number="91031"/>
129
        </change>
110
        <change id="ProjectProblems">
130
        <change id="ProjectProblems">
111
            <api name="general"/>
131
            <api name="general"/>
112
            <summary>Added an SPI to provide project metadata problems.</summary>
132
            <summary>Added an SPI to provide project metadata problems.</summary>
(-)projectuiapi/nbproject/project.properties (-1 / +1 lines)
Lines 42-48 Link Here
42
42
43
javac.compilerargs=-Xlint -Xlint:-serial
43
javac.compilerargs=-Xlint -Xlint:-serial
44
javac.source=1.6
44
javac.source=1.6
45
spec.version.base=1.60.0
45
spec.version.base=1.61.0
46
is.autoload=true
46
is.autoload=true
47
javadoc.arch=${basedir}/arch.xml
47
javadoc.arch=${basedir}/arch.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
(-)projectuiapi/src/org/netbeans/api/project/ui/OpenProjects.java (+29 lines)
Lines 49-54 Link Here
49
import java.util.concurrent.Future;
49
import java.util.concurrent.Future;
50
import java.util.logging.Level;
50
import java.util.logging.Level;
51
import java.util.logging.Logger;
51
import java.util.logging.Logger;
52
import org.netbeans.api.annotations.common.CheckForNull;
53
import org.netbeans.api.annotations.common.NonNull;
52
import org.netbeans.api.project.Project;
54
import org.netbeans.api.project.Project;
53
import org.netbeans.modules.project.uiapi.OpenProjectsTrampoline;
55
import org.netbeans.modules.project.uiapi.OpenProjectsTrampoline;
54
import org.netbeans.modules.project.uiapi.Utilities;
56
import org.netbeans.modules.project.uiapi.Utilities;
Lines 295-298 Link Here
295
        trampoline.removePropertyChangeListenerAPI( listener );
297
        trampoline.removePropertyChangeListenerAPI( listener );
296
    }
298
    }
297
    
299
    
300
    /**
301
     * return the currently action project group
302
     * @return can be null if no group is active
303
     * @since 1.61
304
     */
305
    public @CheckForNull ProjectGroup getActiveProjectGroup() {
306
        return trampoline.getActiveProjectGroupAPI();
298
}
307
}
308
    
309
    /**
310
     * add listener to changes in active project group
311
     * @param listener 
312
     * @since 1.61
313
     */
314
    public void addProjectGroupChangeListener( @NonNull ProjectGroupChangeListener listener) {
315
        trampoline.addProjectGroupChangeListenerAPI(listener);
316
    }
317
    
318
    /**
319
     * remove listener to changes in active project group
320
     * @param listener 
321
     * @since 1.61
322
     */
323
    public void removeProjectGroupChangeListener( @NonNull ProjectGroupChangeListener listener) {
324
        trampoline.removeProjectGroupChangeListenerAPI(listener);
325
    }
326
    
327
}
(-)projectuiapi/src/org/netbeans/api/project/ui/ProjectGroup.java (+122 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.project.ui;
43
44
import java.util.prefs.Preferences;
45
import org.netbeans.modules.project.uiapi.Utilities;
46
47
/**
48
 * Object describing a project group, in most cases the currently active project group.
49
 * @author mkleint
50
 * @since 1.61
51
 */
52
public final class ProjectGroup {
53
    private final Preferences prefs;
54
    private final String name;
55
56
    ProjectGroup(String name, Preferences prefs) {
57
        this.name = name;
58
        this.prefs = prefs;
59
    }
60
    
61
    /**
62
     * name of the project group as given by user
63
     * @return 
64
     */
65
    public String getName() {
66
        return name;
67
    }
68
    
69
    /**
70
     * use this method to store and retrieve preferences related to project groups.
71
     * @param clazz
72
     * @return 
73
     */
74
    public Preferences preferencesForPackage(Class clazz) {
75
        return prefs.node(clazz.getPackage().getName().replace(".", "/"));
76
    }
77
    
78
    @Override
79
    public int hashCode() {
80
        int hash = 7;
81
        hash = 11 * hash + (this.name != null ? this.name.hashCode() : 0);
82
        return hash;
83
    }
84
85
    @Override
86
    public boolean equals(Object obj) {
87
        if (obj == null) {
88
            return false;
89
        }
90
        if (getClass() != obj.getClass()) {
91
            return false;
92
        }
93
        final ProjectGroup other = (ProjectGroup) obj;
94
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
95
            return false;
96
        }
97
        return true;
98
    }
99
    
100
    static {
101
        AccessorImpl impl = new AccessorImpl();
102
        impl.assign();
103
    }
104
 
105
    
106
    static class AccessorImpl extends Utilities.ProjectGroupAccessor {
107
        
108
        
109
         public void assign() {
110
             if (Utilities.ACCESSOR == null) {
111
                 Utilities.ACCESSOR = this;
112
             }
113
         }
114
    
115
        @Override
116
        public ProjectGroup createGroup(String name, Preferences prefs) {
117
            return new ProjectGroup(name, prefs);
118
        }
119
    }    
120
    
121
    
122
}
(-)projectuiapi/src/org/netbeans/api/project/ui/ProjectGroupChangeEvent.java (+80 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.project.ui;
43
44
import java.util.EventObject;
45
import org.netbeans.api.annotations.common.CheckForNull;
46
import org.netbeans.api.annotations.common.NullAllowed;
47
48
49
/**
50
 * event describing the change of active project group by the user.
51
 * @author mkleint
52
 * @since 1.61
53
 */
54
public final class ProjectGroupChangeEvent extends EventObject {
55
    private final ProjectGroup newGroup;
56
    private final ProjectGroup oldGroup;
57
    
58
    public ProjectGroupChangeEvent(@NullAllowed ProjectGroup o, @NullAllowed ProjectGroup n) {
59
        super(OpenProjects.getDefault());
60
        this.oldGroup = o;
61
        this.newGroup = n;
62
    }
63
64
    /**
65
     * the newly current project group, can be null
66
     * @return 
67
     */
68
    public @CheckForNull ProjectGroup getNewGroup() {
69
        return newGroup;
70
    }
71
72
    /**
73
     * the previous active project group, can be null
74
     * @return 
75
     */
76
    public @CheckForNull ProjectGroup getOldGroup() {
77
        return oldGroup;
78
    }
79
}
80
(-)projectuiapi/src/org/netbeans/api/project/ui/ProjectGroupChangeListener.java (+68 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.project.ui;
43
44
import org.netbeans.api.annotations.common.NonNull;
45
46
/**
47
 * listeners that get notified when project group is changed.
48
 * added and removed from <code>OpenProjects</code>
49
 * @author mkleint
50
 * @since 1.61
51
 */
52
public interface ProjectGroupChangeListener {
53
    
54
    /**
55
     * called when the process of changing from old to new project group has started. Will be called before
56
     * the actual projects from old group get closed and the ones from new group get opened.
57
     * @param event 
58
     */
59
    void projectGroupChanging(@NonNull ProjectGroupChangeEvent event);
60
        
61
    /**
62
     * called when the process of changing from old to new project group has been completed. Only projects 
63
     * related to current group should be open now, or projects explicitly opened by the user.
64
     * @param event 
65
     */
66
    void projectGroupChanged(@NonNull ProjectGroupChangeEvent event);
67
    
68
}
(-)projectuiapi/src/org/netbeans/modules/project/uiapi/OpenProjectsTrampoline.java (+8 lines)
Lines 47-52 Link Here
47
import java.beans.PropertyChangeListener;
47
import java.beans.PropertyChangeListener;
48
import java.util.concurrent.Future;
48
import java.util.concurrent.Future;
49
import org.netbeans.api.project.Project;
49
import org.netbeans.api.project.Project;
50
import org.netbeans.api.project.ui.ProjectGroup;
51
import org.netbeans.api.project.ui.ProjectGroupChangeListener;
50
52
51
/**
53
/**
52
 * List of projects open in the GUI.
54
 * List of projects open in the GUI.
Lines 70-73 Link Here
70
    
72
    
71
    public void setMainProject(Project project);
73
    public void setMainProject(Project project);
72
    
74
    
75
    public ProjectGroup getActiveProjectGroupAPI();
76
77
    public void addProjectGroupChangeListenerAPI(ProjectGroupChangeListener listener);
78
79
    public void removeProjectGroupChangeListenerAPI(ProjectGroupChangeListener listener);
80
 
73
}
81
}
(-)projectuiapi/src/org/netbeans/modules/project/uiapi/Utilities.java (+41 lines)
Lines 58-63 Link Here
58
import java.util.Map;
58
import java.util.Map;
59
import java.util.concurrent.Callable;
59
import java.util.concurrent.Callable;
60
import java.util.concurrent.Future;
60
import java.util.concurrent.Future;
61
import java.util.logging.Level;
62
import java.util.logging.Logger;
63
import java.util.prefs.Preferences;
61
import javax.swing.AbstractAction;
64
import javax.swing.AbstractAction;
62
import javax.swing.Action;
65
import javax.swing.Action;
63
import javax.swing.Icon;
66
import javax.swing.Icon;
Lines 67-72 Link Here
67
import org.netbeans.api.project.Project;
70
import org.netbeans.api.project.Project;
68
import org.netbeans.api.project.SourceGroup;
71
import org.netbeans.api.project.SourceGroup;
69
import org.netbeans.api.project.ui.OpenProjects;
72
import org.netbeans.api.project.ui.OpenProjects;
73
import org.netbeans.api.project.ui.ProjectGroup;
74
import org.netbeans.api.project.ui.ProjectGroupChangeListener;
70
import org.netbeans.spi.project.ui.support.BuildExecutionSupport.Item;
75
import org.netbeans.spi.project.ui.support.BuildExecutionSupport.Item;
71
import org.netbeans.spi.project.ui.support.FileActionPerformer;
76
import org.netbeans.spi.project.ui.support.FileActionPerformer;
72
import org.netbeans.spi.project.ui.support.ProjectActionPerformer;
77
import org.netbeans.spi.project.ui.support.ProjectActionPerformer;
Lines 84-89 Link Here
84
 */
89
 */
85
public class Utilities {
90
public class Utilities {
86
91
92
    private static final Logger LOG = Logger.getLogger(Utilities.class.getName());
87
    private static final Map<ProjectCustomizer.Category,CategoryChangeSupport> CATEGORIES = new HashMap<ProjectCustomizer.Category,CategoryChangeSupport>();
93
    private static final Map<ProjectCustomizer.Category,CategoryChangeSupport> CATEGORIES = new HashMap<ProjectCustomizer.Category,CategoryChangeSupport>();
88
94
89
    private Utilities() {}
95
    private Utilities() {}
Lines 253-261 Link Here
253
            @Override public void removePropertyChangeListenerAPI(PropertyChangeListener listener) {
259
            @Override public void removePropertyChangeListenerAPI(PropertyChangeListener listener) {
254
                pcs.removePropertyChangeListener(listener);
260
                pcs.removePropertyChangeListener(listener);
255
            }
261
            }
262
263
            @Override
264
            public void addProjectGroupChangeListenerAPI(ProjectGroupChangeListener listener) {
265
            }
266
267
            @Override
268
            public void removeProjectGroupChangeListenerAPI(ProjectGroupChangeListener listener) {
269
            }
270
271
            @Override
272
            public ProjectGroup getActiveProjectGroupAPI() {
273
                return null;
274
            }
256
        };
275
        };
257
    }
276
    }
258
    
277
    
278
    @org.netbeans.api.annotations.common.SuppressWarnings("MS_SHOULD_BE_FINAL")
279
    public static ProjectGroupAccessor ACCESSOR = null;
280
281
    static {
282
        // invokes static initializer of ModelHandle.class
283
        // that will assign value to the ACCESSOR field above
284
        Class<?> c = ProjectGroup.class;
285
        try {
286
            Class.forName(c.getName(), true, c.getClassLoader());
287
        } catch (Exception ex) {
288
            LOG.log(Level.SEVERE, "very wrong, very wrong, yes indeed", ex);
289
        }
290
    }
291
292
    public static abstract class ProjectGroupAccessor {
293
294
        public abstract ProjectGroup createGroup(String name, Preferences prefs);
295
296
    }
297
    
298
    
299
    
259
    public static CategoryChangeSupport getCategoryChangeSupport(ProjectCustomizer.Category category) {
300
    public static CategoryChangeSupport getCategoryChangeSupport(ProjectCustomizer.Category category) {
260
        CategoryChangeSupport cw = Utilities.CATEGORIES.get(category);
301
        CategoryChangeSupport cw = Utilities.CATEGORIES.get(category);
261
        return cw == null ? CategoryChangeSupport.NULL_INSTANCE : cw;
302
        return cw == null ? CategoryChangeSupport.NULL_INSTANCE : cw;

Return to bug 91031