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 219313
Collapse All | Expand All

(-)a/projectuiapi/apichanges.xml (+15 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="ProjectProblemsProviderSupport">
111
            <api name="general"/>
112
            <summary>Added a support class for ProjectProblemsProvider.</summary>
113
            <version major="1" minor="63"/>
114
            <date day="2" month="10" year="2012"/>
115
            <author login="tmysik"/>
116
            <compatibility addition="yes"/>
117
            <description>
118
                <p>
119
                    Added support class for provider of project metadata problems.
120
                </p>
121
            </description>
122
            <class package="org.netbeans.api.project.ui.support" name="ProjectProblemsProviderSupport"/>
123
            <issue number="219313"/>
124
        </change>
110
        <change id="ProjectGroup">
125
        <change id="ProjectGroup">
111
            <api name="general"/>
126
            <api name="general"/>
112
            <summary>API to get current active project group and listen to project groups switching</summary>
127
            <summary>API to get current active project group and listen to project groups switching</summary>
(-)a/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.62.0
45
spec.version.base=1.63.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
(-)a/projectuiapi/src/org/netbeans/spi/project/ui/ProjectProblemsProvider.java (+2 lines)
Lines 75-80 Link Here
75
 * </p>
75
 * </p>
76
 * </div>
76
 * </div>
77
 *
77
 *
78
 * @see org.netbeans.spi.project.ui.support.ProjectProblemsProviderSupport
79
 *
78
 * @author Tomas Zezula
80
 * @author Tomas Zezula
79
 * @since 1.60
81
 * @since 1.60
80
 */
82
 */
(-)a/projectuiapi/src/org/netbeans/spi/project/ui/support/ProjectProblemsProviderSupport.java (+159 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.spi.project.ui.support;
43
44
import java.beans.PropertyChangeListener;
45
import java.beans.PropertyChangeSupport;
46
import java.util.ArrayList;
47
import java.util.Collection;
48
import java.util.Collections;
49
import org.netbeans.api.annotations.common.NonNull;
50
import org.netbeans.spi.project.ui.ProjectProblemsProvider;
51
import org.openide.util.Parameters;
52
53
/**
54
 * Support for {@link ProjectProblemsProvider provider of project metadata problems}.
55
 * <p>
56
 * This class is thread-safe.
57
 * @since 1.63
58
 */
59
public final class ProjectProblemsProviderSupport {
60
61
    private final PropertyChangeSupport propertyChangeSupport;
62
    private final Object problemsLock = new Object();
63
64
    // @GuardedBy("problemsLock")
65
    private Collection<ProjectProblemsProvider.ProjectProblem> problems;
66
    // @GuardedBy("problemsLock")
67
    private long changeId;
68
69
70
    /**
71
     * Create a new {@code ProjectProblemsProviderSupport}.
72
     *
73
     * @param source an instance to be given as the source for events, never {@code null}
74
     */
75
    public ProjectProblemsProviderSupport(Object source) {
76
        Parameters.notNull("source", source);
77
        propertyChangeSupport = new PropertyChangeSupport(source);
78
    }
79
80
    /**
81
     * Add a listener to the listener list.
82
     * @param listener {@link PropertyChangeListener} to be added
83
     * @see PropertyChangeSupport#addPropertyChangeListener(PropertyChangeListener)
84
     */
85
    public void addPropertyChangeListener(PropertyChangeListener listener) {
86
        propertyChangeSupport.addPropertyChangeListener(listener);
87
    }
88
89
    /**
90
     * Remove a listener from the listener list.
91
     * @param listener {@link PropertyChangeListener} to be removed
92
     * @see PropertyChangeSupport#removePropertyChangeListener(PropertyChangeListener)
93
     */
94
    public void removePropertyChangeListener(PropertyChangeListener listener) {
95
        propertyChangeSupport.removePropertyChangeListener(listener);
96
    }
97
98
    /**
99
     * Get project problems using the given {@link ProblemsCollector problems collector}.
100
     * @param problemsCollector {@link ProblemsCollector problems collector} to be used, never {@code null}
101
     * @return collection of project problems, never {@code null}
102
     */
103
    @NonNull
104
    public Collection<? extends ProjectProblemsProvider.ProjectProblem> getProblems(@NonNull ProblemsCollector problemsCollector) {
105
        Parameters.notNull("problemsCollector", problemsCollector);
106
107
        Collection<ProjectProblemsProvider.ProjectProblem> currentProblems;
108
        long currentChangeId;
109
        synchronized (problemsLock) {
110
            currentProblems = problems;
111
            currentChangeId = changeId;
112
        }
113
        if (currentProblems != null) {
114
            return currentProblems;
115
        }
116
        currentProblems = new ArrayList<ProjectProblemsProvider.ProjectProblem>();
117
        currentProblems.addAll(problemsCollector.collectProblems());
118
        if (currentProblems.isEmpty()) {
119
            currentProblems = Collections.<ProjectProblemsProvider.ProjectProblem>emptySet();
120
        }
121
        synchronized (problemsLock) {
122
            if (currentChangeId == changeId) {
123
                problems = currentProblems;
124
            } else if (problems != null) {
125
                currentProblems = problems;
126
            }
127
        }
128
        assert currentProblems != null;
129
        return currentProblems;
130
    }
131
132
    /**
133
     * Fire {@link ProjectProblemsProvider#PROP_PROBLEMS project problems property} change event to all registered listeners.
134
     */
135
    public void fireProblemsChange() {
136
        synchronized (problemsLock) {
137
            problems = null;
138
            changeId++;
139
        }
140
        propertyChangeSupport.firePropertyChange(ProjectProblemsProvider.PROP_PROBLEMS, null, null);
141
    }
142
143
    //~ Inner classes
144
145
    /**
146
     * Collector of current project problems.
147
     */
148
    public interface ProblemsCollector {
149
150
        /**
151
         * Collect current project problems.
152
         * @return list of current project problems, can be empty but never {@code null}
153
         */
154
        @NonNull
155
        Collection<? extends ProjectProblemsProvider.ProjectProblem> collectProblems();
156
157
    }
158
159
}

Return to bug 219313