# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /Users/mkleint/src/core-main # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: projectuiapi/apichanges.xml --- projectuiapi/apichanges.xml Base (BASE) +++ projectuiapi/apichanges.xml Locally Modified (Based On LOCAL) @@ -107,6 +107,26 @@ + + + API to get current active project group and listen to project groups switching + + + + + +

+ Added methods to + OpenProjects to figure the currently active project group, access preferences related to it + and listen to changes in currently active group. +

+
+ + + + + +
Added an SPI to provide project metadata problems. Index: projectuiapi/nbproject/project.properties --- projectuiapi/nbproject/project.properties Base (BASE) +++ projectuiapi/nbproject/project.properties Locally Modified (Based On LOCAL) @@ -42,7 +42,7 @@ javac.compilerargs=-Xlint -Xlint:-serial javac.source=1.6 -spec.version.base=1.60.0 +spec.version.base=1.61.0 is.autoload=true javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml Index: projectuiapi/src/org/netbeans/api/project/ui/OpenProjects.java --- projectuiapi/src/org/netbeans/api/project/ui/OpenProjects.java Base (BASE) +++ projectuiapi/src/org/netbeans/api/project/ui/OpenProjects.java Locally Modified (Based On LOCAL) @@ -49,6 +49,8 @@ import java.util.concurrent.Future; import java.util.logging.Level; import java.util.logging.Logger; +import org.netbeans.api.annotations.common.CheckForNull; +import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.project.Project; import org.netbeans.modules.project.uiapi.OpenProjectsTrampoline; import org.netbeans.modules.project.uiapi.Utilities; @@ -295,4 +297,31 @@ trampoline.removePropertyChangeListenerAPI( listener ); } + /** + * return the currently action project group + * @return can be null if no group is active + * @since 1.61 + */ + public @CheckForNull ProjectGroup getActiveProjectGroup() { + return trampoline.getActiveProjectGroupAPI(); } + + /** + * add listener to changes in active project group + * @param listener + * @since 1.61 + */ + public void addProjectGroupChangeListener( @NonNull ProjectGroupChangeListener listener) { + trampoline.addProjectGroupChangeListenerAPI(listener); + } + + /** + * remove listener to changes in active project group + * @param listener + * @since 1.61 + */ + public void removeProjectGroupChangeListener( @NonNull ProjectGroupChangeListener listener) { + trampoline.removeProjectGroupChangeListenerAPI(listener); + } + +} Index: projectuiapi/src/org/netbeans/api/project/ui/ProjectGroup.java --- projectuiapi/src/org/netbeans/api/project/ui/ProjectGroup.java Base (BASE) +++ projectuiapi/src/org/netbeans/api/project/ui/ProjectGroup.java Locally New @@ -0,0 +1,122 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.api.project.ui; + +import java.util.prefs.Preferences; +import org.netbeans.modules.project.uiapi.Utilities; + +/** + * Object describing a project group, in most cases the currently active project group. + * @author mkleint + * @since 1.61 + */ +public final class ProjectGroup { + private final Preferences prefs; + private final String name; + + ProjectGroup(String name, Preferences prefs) { + this.name = name; + this.prefs = prefs; + } + + /** + * name of the project group as given by user + * @return + */ + public String getName() { + return name; + } + + /** + * use this method to store and retrieve preferences related to project groups. + * @param clazz + * @return + */ + public Preferences preferencesForPackage(Class clazz) { + return prefs.node(clazz.getPackage().getName().replace(".", "/")); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 11 * hash + (this.name != null ? this.name.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ProjectGroup other = (ProjectGroup) obj; + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { + return false; + } + return true; + } + + static { + AccessorImpl impl = new AccessorImpl(); + impl.assign(); + } + + + static class AccessorImpl extends Utilities.ProjectGroupAccessor { + + + public void assign() { + if (Utilities.ACCESSOR == null) { + Utilities.ACCESSOR = this; + } + } + + @Override + public ProjectGroup createGroup(String name, Preferences prefs) { + return new ProjectGroup(name, prefs); + } + } + + +} Index: projectuiapi/src/org/netbeans/api/project/ui/ProjectGroupChangeEvent.java --- projectuiapi/src/org/netbeans/api/project/ui/ProjectGroupChangeEvent.java Base (BASE) +++ projectuiapi/src/org/netbeans/api/project/ui/ProjectGroupChangeEvent.java Locally New @@ -0,0 +1,80 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.api.project.ui; + +import java.util.EventObject; +import org.netbeans.api.annotations.common.CheckForNull; +import org.netbeans.api.annotations.common.NullAllowed; + + +/** + * event describing the change of active project group by the user. + * @author mkleint + * @since 1.61 + */ +public final class ProjectGroupChangeEvent extends EventObject { + private final ProjectGroup newGroup; + private final ProjectGroup oldGroup; + + public ProjectGroupChangeEvent(@NullAllowed ProjectGroup o, @NullAllowed ProjectGroup n) { + super(OpenProjects.getDefault()); + this.oldGroup = o; + this.newGroup = n; + } + + /** + * the newly current project group, can be null + * @return + */ + public @CheckForNull ProjectGroup getNewGroup() { + return newGroup; + } + + /** + * the previous active project group, can be null + * @return + */ + public @CheckForNull ProjectGroup getOldGroup() { + return oldGroup; + } +} + Index: projectuiapi/src/org/netbeans/api/project/ui/ProjectGroupChangeListener.java --- projectuiapi/src/org/netbeans/api/project/ui/ProjectGroupChangeListener.java Base (BASE) +++ projectuiapi/src/org/netbeans/api/project/ui/ProjectGroupChangeListener.java Locally New @@ -0,0 +1,68 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.api.project.ui; + +import org.netbeans.api.annotations.common.NonNull; + +/** + * listeners that get notified when project group is changed. + * added and removed from OpenProjects + * @author mkleint + * @since 1.61 + */ +public interface ProjectGroupChangeListener { + + /** + * called when the process of changing from old to new project group has started. Will be called before + * the actual projects from old group get closed and the ones from new group get opened. + * @param event + */ + void projectGroupChanging(@NonNull ProjectGroupChangeEvent event); + + /** + * called when the process of changing from old to new project group has been completed. Only projects + * related to current group should be open now, or projects explicitly opened by the user. + * @param event + */ + void projectGroupChanged(@NonNull ProjectGroupChangeEvent event); + +} Index: projectuiapi/src/org/netbeans/modules/project/uiapi/OpenProjectsTrampoline.java --- projectuiapi/src/org/netbeans/modules/project/uiapi/OpenProjectsTrampoline.java Base (BASE) +++ projectuiapi/src/org/netbeans/modules/project/uiapi/OpenProjectsTrampoline.java Locally Modified (Based On LOCAL) @@ -47,6 +47,8 @@ import java.beans.PropertyChangeListener; import java.util.concurrent.Future; import org.netbeans.api.project.Project; +import org.netbeans.api.project.ui.ProjectGroup; +import org.netbeans.api.project.ui.ProjectGroupChangeListener; /** * List of projects open in the GUI. @@ -70,4 +72,10 @@ public void setMainProject(Project project); + public ProjectGroup getActiveProjectGroupAPI(); + + public void addProjectGroupChangeListenerAPI(ProjectGroupChangeListener listener); + + public void removeProjectGroupChangeListenerAPI(ProjectGroupChangeListener listener); + } Index: projectuiapi/src/org/netbeans/modules/project/uiapi/Utilities.java --- projectuiapi/src/org/netbeans/modules/project/uiapi/Utilities.java Base (BASE) +++ projectuiapi/src/org/netbeans/modules/project/uiapi/Utilities.java Locally Modified (Based On LOCAL) @@ -58,6 +58,9 @@ import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.Future; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.prefs.Preferences; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.Icon; @@ -67,6 +70,8 @@ import org.netbeans.api.project.Project; import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.ui.OpenProjects; +import org.netbeans.api.project.ui.ProjectGroup; +import org.netbeans.api.project.ui.ProjectGroupChangeListener; import org.netbeans.spi.project.ui.support.BuildExecutionSupport.Item; import org.netbeans.spi.project.ui.support.FileActionPerformer; import org.netbeans.spi.project.ui.support.ProjectActionPerformer; @@ -84,6 +89,7 @@ */ public class Utilities { + private static final Logger LOG = Logger.getLogger(Utilities.class.getName()); private static final Map CATEGORIES = new HashMap(); private Utilities() {} @@ -253,9 +259,44 @@ @Override public void removePropertyChangeListenerAPI(PropertyChangeListener listener) { pcs.removePropertyChangeListener(listener); } + + @Override + public void addProjectGroupChangeListenerAPI(ProjectGroupChangeListener listener) { + } + + @Override + public void removeProjectGroupChangeListenerAPI(ProjectGroupChangeListener listener) { + } + + @Override + public ProjectGroup getActiveProjectGroupAPI() { + return null; + } }; } + @org.netbeans.api.annotations.common.SuppressWarnings("MS_SHOULD_BE_FINAL") + public static ProjectGroupAccessor ACCESSOR = null; + + static { + // invokes static initializer of ModelHandle.class + // that will assign value to the ACCESSOR field above + Class c = ProjectGroup.class; + try { + Class.forName(c.getName(), true, c.getClassLoader()); + } catch (Exception ex) { + LOG.log(Level.SEVERE, "very wrong, very wrong, yes indeed", ex); + } + } + + public static abstract class ProjectGroupAccessor { + + public abstract ProjectGroup createGroup(String name, Preferences prefs); + + } + + + public static CategoryChangeSupport getCategoryChangeSupport(ProjectCustomizer.Category category) { CategoryChangeSupport cw = Utilities.CATEGORIES.get(category); return cw == null ? CategoryChangeSupport.NULL_INSTANCE : cw;