Index: ant/freeform/apichanges.xml =================================================================== RCS file: /cvs/ant/freeform/apichanges.xml,v retrieving revision 1.5 diff -u -r1.5 apichanges.xml --- ant/freeform/apichanges.xml 16 Oct 2006 14:18:44 -0000 1.5 +++ ant/freeform/apichanges.xml 8 Feb 2007 07:23:24 -0000 @@ -82,12 +82,30 @@ + + Simplify ProjectNature and align with common project extensibility APIs + + + + + +

+ Removed class org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel + and removed methods from org.netbeans.modules.ant.freeform.spi.ProjectNature. + The removed methods were replaced by new project extensibility APIs. +

+
+ + + +
+ Remove LookupMerger - +

Removed class org.netbeans.modules.ant.freeform.spi.LookupMerger Index: ant/freeform/arch.xml =================================================================== RCS file: /cvs/ant/freeform/arch.xml,v retrieving revision 1.9 diff -u -r1.9 arch.xml --- ant/freeform/arch.xml 15 Aug 2006 15:21:07 -0000 1.9 +++ ant/freeform/arch.xml 8 Feb 2007 07:23:24 -0000 @@ -1003,9 +1003,29 @@ --> -

- No. -

+ +

+ "Projects/org-netbeans-modules-ant-freeform/Nodes" folder's content is used to construct the project's child nodes. + It's content is expected to be NodeFactory instances. +

+
+ +

+ "Projects/org-netbeans-modules-ant-freeform/Lookup" folder's content is used to construct the project's additional lookup. + It's content is expected to be LookupProvider instances. Freeform project provides LookupMergers + for ActionProvider, PrivilegedTemplates and RecommendedTemplates. Implementations added by 3rd parties + will be merged into a single instance in the project's lookup. +

+
+ +

+ "Projects/org-netbeans-modules-ant-freeform/Customizer" folder's content is used to construct the project's customizer. + It's content is expected to be ProjectCustomizer.CompositeCategoryProvider instances. + The lookup passed to the panels contains an instance of Project, AuxiliaryConfiguration and ProjectAccessor + Each panel is assumed to save it's own changed content by setting an ActionListener on it's ProjectCutomizer.Category +

+
+ @@ -1081,6 +1101,87 @@

No. +

+
+ + + + + + + + + + + + + +

+ XXX no answer for compat-deprecation +

+
+ + + + + +

+ XXX no answer for exec-ant-tasks +

+
+ + + + + +

+ XXX no answer for resources-preferences

Index: ant/freeform/manifest.mf =================================================================== RCS file: /cvs/ant/freeform/manifest.mf,v retrieving revision 1.15 diff -u -r1.15 manifest.mf --- ant/freeform/manifest.mf 16 Oct 2006 14:18:45 -0000 1.15 +++ ant/freeform/manifest.mf 8 Feb 2007 07:23:24 -0000 @@ -1,5 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.ant.freeform/1 -OpenIDE-Module-Specification-Version: 1.13 +OpenIDE-Module-Specification-Version: 1.14 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/ant/freeform/Bundle.properties +OpenIDE-Module-Layer: org/netbeans/modules/ant/freeform/resources/layer.xml Index: ant/freeform/nbproject/project.xml =================================================================== RCS file: /cvs/ant/freeform/nbproject/project.xml,v retrieving revision 1.25 diff -u -r1.25 project.xml --- ant/freeform/nbproject/project.xml 9 Nov 2006 16:53:54 -0000 1.25 +++ ant/freeform/nbproject/project.xml 8 Feb 2007 07:23:24 -0000 @@ -154,43 +154,73 @@ - - - unit - - org.netbeans.modules.ant.freeform - - - - - org.openide.modules - - - - org.openidex.util - - - org.openide.options - - - org.netbeans.modules.projectui - - - org.netbeans.modules.masterfs - - - org.netbeans.core.startup - - - org.netbeans.bootstrap - - - org.netbeans.libs.xerces - - - - qa-functional - + + + unit + + org.apache.xml.resolver + + + + org.netbeans.bootstrap + + + org.netbeans.core.execution + + + + + org.netbeans.core.startup + + + org.netbeans.core.ui + + + + org.netbeans.libs.xerces + + + org.netbeans.modules.ant.freeform + + + + + org.netbeans.modules.editor.mimelookup.impl + + + + org.netbeans.modules.favorites + + + + org.netbeans.modules.masterfs + + + org.netbeans.modules.projectui + + + org.netbeans.modules.xml.catalog + + + + org.netbeans.modules.xml.core + + + + + org.openide.modules + + + + org.openide.options + + + org.openidex.util + + + + qa-functional + org.netbeans.modules.j2ee.ejbfreeform Index: ant/freeform/src/org/netbeans/modules/ant/freeform/Accessor.java =================================================================== RCS file: ant/freeform/src/org/netbeans/modules/ant/freeform/Accessor.java diff -N ant/freeform/src/org/netbeans/modules/ant/freeform/Accessor.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ant/freeform/src/org/netbeans/modules/ant/freeform/Accessor.java 8 Feb 2007 07:23:25 -0000 @@ -0,0 +1,44 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.ant.freeform; + +import org.netbeans.modules.ant.freeform.spi.ProjectAccessor; + +/** + * + * @author mkleint + */ +public abstract class Accessor { + + protected static Accessor DEFAULT = null; + + static { + // invokes static initializer of Item.class + // that will assign value to the DEFAULT field above + Class c = ProjectAccessor.class; + try { + Class.forName(c.getName(), true, c.getClassLoader()); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public abstract ProjectAccessor createProjectAccessor(FreeformProject desc); +} Index: ant/freeform/src/org/netbeans/modules/ant/freeform/FreeformProject.java =================================================================== RCS file: /cvs/ant/freeform/src/org/netbeans/modules/ant/freeform/FreeformProject.java,v retrieving revision 1.45 diff -u -r1.45 FreeformProject.java --- ant/freeform/src/org/netbeans/modules/ant/freeform/FreeformProject.java 1 Feb 2007 17:27:49 -0000 1.45 +++ ant/freeform/src/org/netbeans/modules/ant/freeform/FreeformProject.java 8 Feb 2007 07:23:25 -0000 @@ -19,13 +19,9 @@ package org.netbeans.modules.ant.freeform; +import org.netbeans.modules.ant.freeform.spi.ProjectAccessor; import java.beans.PropertyChangeListener; import java.io.IOException; -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; import javax.swing.Icon; import javax.swing.ImageIcon; import org.netbeans.api.project.Project; @@ -36,20 +32,16 @@ import org.netbeans.modules.ant.freeform.ui.ProjectCustomizerProvider; import org.netbeans.modules.ant.freeform.ui.View; import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.support.LookupProviderSupport; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.PropertyUtils; import org.netbeans.spi.project.ui.support.UILookupMergerSupport; -import org.openide.ErrorManager; import org.openide.filesystems.FileObject; import org.openide.util.Lookup; -import org.openide.util.LookupEvent; -import org.openide.util.LookupListener; import org.openide.util.Mutex; import org.openide.util.Utilities; -import org.openide.util.WeakListeners; import org.openide.util.lookup.Lookups; -import org.openide.util.lookup.ProxyLookup; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -80,6 +72,7 @@ private Lookup initLookup() throws IOException { aux = helper().createAuxiliaryConfiguration(); // AuxiliaryConfiguration Lookup baseLookup = Lookups.fixed( + this, new Info(), // ProjectInformation new FreeformSources(this), // Sources new Actions(this), // ActionProvider @@ -90,12 +83,13 @@ new Subprojects(this), // SubprojectProvider new ArtifactProvider(this), // AntArtifactProvider new LookupMergerImpl(), // LookupMerger or ActionProvider - UILookupMergerSupport.createPrivilegedTemplatesMerger(), + UILookupMergerSupport.createPrivilegedTemplatesMerger(), + UILookupMergerSupport.createRecommendedTemplatesMerger(), new FreeformProjectOperations(this), new FreeformSharabilityQuery(helper()), //SharabilityQueryImplementation - new ProjectAccessor(this) //Access to AntProjectHelper and PropertyEvaluator + Accessor.DEFAULT.createProjectAccessor(this) //Access to AntProjectHelper and PropertyEvaluator ); - return new FreeformLookup(baseLookup, this, helper, eval, aux); + return LookupProviderSupport.createCompositeLookup(baseLookup, "Projects/org-netbeans-modules-ant-freeform/Lookup"); //NOI18N } public FileObject getProjectDirectory() { @@ -183,86 +177,7 @@ } - private static final class FreeformLookup extends ProxyLookup implements LookupListener { - - private final Lookup baseLookup; - private final AntProjectHelper helper; - private final PropertyEvaluator evaluator; - private final FreeformProject project; - private final AuxiliaryConfiguration aux; - private Lookup.Result mergers2; - private Reference listenerRef2; - - //#68623: the proxy lookup fires changes only if someone listens on a particular template: - private List> results; - - public FreeformLookup(Lookup baseLookup, FreeformProject project, AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux) { - super(); - this.baseLookup = baseLookup; - this.project = project; - this.helper = helper; - this.evaluator = evaluator; - this.aux = aux; - this.results = Collections.emptyList(); - updateLookup(); - PROJECT_NATURES.addLookupListener(WeakListeners.create(LookupListener.class, this, PROJECT_NATURES)); - } - - public void resultChanged (LookupEvent ev) { - updateLookup(); - } - - private void updateLookup() { - //unregister listeners from the old results: - for (Lookup.Result r : results) { - r.removeLookupListener(this); - } - - results = new ArrayList>(); - - List lookups = new ArrayList(); - lookups.add(baseLookup); - for (ProjectNature pn : PROJECT_NATURES.allInstances()) { - lookups.add(pn.getLookup(project, helper, evaluator, aux)); - } - Lookup lkp = new ProxyLookup(lookups.toArray(new Lookup[lookups.size()])); - - //merge: - List> filteredClasses = new ArrayList>(); - List mergedInstances = new ArrayList(); - //first comes the new project API's LookupMerger - //merge: - LookupListener l = listenerRef2 != null ? listenerRef2.get() : null; - if (l != null) { - mergers2.removeLookupListener(l); - } - mergers2 = lkp.lookupResult(org.netbeans.spi.project.LookupMerger.class); - l = WeakListeners.create(LookupListener.class, this, mergers2); - listenerRef2 = new WeakReference(l); - mergers2.addLookupListener(l); - for (org.netbeans.spi.project.LookupMerger lm : mergers2.allInstances()) { - Class c = lm.getMergeableClass(); - if (filteredClasses.contains(c)) { - ErrorManager.getDefault().log(ErrorManager.WARNING, - "Two LookupMerger registered for class " + c + - ". Only first one will be used"); // NOI18N - continue; - } - filteredClasses.add(c); - mergedInstances.add(lm.merge(lkp)); - - Lookup.Result result = lkp.lookupResult(c); - - result.addLookupListener(this); - results.add(result); - } - - lkp = Lookups.exclude(lkp, filteredClasses.toArray(new Class[filteredClasses.size()])); - Lookup fixed = Lookups.fixed(mergedInstances.toArray(new Object[mergedInstances.size()])); - setLookups(fixed, lkp); - } - - } + /** * Utility method to decide if the project actually uses Ant scripting. Index: ant/freeform/src/org/netbeans/modules/ant/freeform/LookupMergerImpl.java =================================================================== RCS file: /cvs/ant/freeform/src/org/netbeans/modules/ant/freeform/LookupMergerImpl.java,v retrieving revision 1.7 diff -u -r1.7 LookupMergerImpl.java --- ant/freeform/src/org/netbeans/modules/ant/freeform/LookupMergerImpl.java 16 Oct 2006 14:18:43 -0000 1.7 +++ ant/freeform/src/org/netbeans/modules/ant/freeform/LookupMergerImpl.java 8 Feb 2007 07:23:25 -0000 @@ -22,11 +22,9 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.Set; import org.netbeans.spi.project.ActionProvider; import org.netbeans.spi.project.LookupMerger; -import org.netbeans.spi.project.ui.PrivilegedTemplates; import org.openide.util.Lookup; /** Index: ant/freeform/src/org/netbeans/modules/ant/freeform/ProjectAccessor.java =================================================================== RCS file: ant/freeform/src/org/netbeans/modules/ant/freeform/ProjectAccessor.java diff -N ant/freeform/src/org/netbeans/modules/ant/freeform/ProjectAccessor.java --- ant/freeform/src/org/netbeans/modules/ant/freeform/ProjectAccessor.java 30 Jun 2006 18:05:39 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,45 +0,0 @@ -/* - * The contents of this file are subject to the terms of the Common Development - * and Distribution License (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.html - * or http://www.netbeans.org/cddl.txt. - * - * When distributing Covered Code, include this CDDL Header Notice in each file - * and include the License file at http://www.netbeans.org/cddl.txt. - * If applicable, add the following below the CDDL Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - */ -package org.netbeans.modules.ant.freeform; - -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; - -/** - * - * @author Jan Lahoda - */ -public final class ProjectAccessor { - - private FreeformProject p; - - /** Creates a new instance of ProjectAccessor */ - public ProjectAccessor(FreeformProject p) { - this.p = p; - } - - public AntProjectHelper getHelper() { - return p.helper(); - } - - public PropertyEvaluator getEvaluator() { - return p.evaluator(); - } - -} Index: ant/freeform/src/org/netbeans/modules/ant/freeform/resources/layer.xml =================================================================== RCS file: ant/freeform/src/org/netbeans/modules/ant/freeform/resources/layer.xml diff -N ant/freeform/src/org/netbeans/modules/ant/freeform/resources/layer.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ant/freeform/src/org/netbeans/modules/ant/freeform/resources/layer.xml 8 Feb 2007 07:23:25 -0000 @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + Index: ant/freeform/src/org/netbeans/modules/ant/freeform/spi/AccessorImpl.java =================================================================== RCS file: ant/freeform/src/org/netbeans/modules/ant/freeform/spi/AccessorImpl.java diff -N ant/freeform/src/org/netbeans/modules/ant/freeform/spi/AccessorImpl.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ant/freeform/src/org/netbeans/modules/ant/freeform/spi/AccessorImpl.java 8 Feb 2007 07:23:25 -0000 @@ -0,0 +1,43 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.ant.freeform.spi; + +import org.netbeans.modules.ant.freeform.Accessor; +import org.netbeans.modules.ant.freeform.FreeformProject; + +/** + * + * @author mkleint + */ +class AccessorImpl extends Accessor { + + /** Creates a new instance of AccessorImpl */ + private AccessorImpl() { + } + + static void createAccesor() { + if (DEFAULT == null) { + DEFAULT = new AccessorImpl(); + } + } + public ProjectAccessor createProjectAccessor(FreeformProject p) { + return new ProjectAccessor(p); + } +} Index: ant/freeform/src/org/netbeans/modules/ant/freeform/spi/ProjectAccessor.java =================================================================== RCS file: ant/freeform/src/org/netbeans/modules/ant/freeform/spi/ProjectAccessor.java diff -N ant/freeform/src/org/netbeans/modules/ant/freeform/spi/ProjectAccessor.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ant/freeform/src/org/netbeans/modules/ant/freeform/spi/ProjectAccessor.java 8 Feb 2007 07:23:25 -0000 @@ -0,0 +1,49 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.modules.ant.freeform.spi; + +import org.netbeans.modules.ant.freeform.*; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; + +/** + * Accessor for AntProjectHelper and PropertyEvaluator, resides in project's lookup. + * @author Jan Lahoda + */ +public final class ProjectAccessor { + + private FreeformProject p; + + static { + AccessorImpl.createAccesor(); + } + /** Creates a new instance of ProjectAccessor */ + ProjectAccessor(FreeformProject p) { + this.p = p; + } + + public AntProjectHelper getHelper() { + return p.helper(); + } + + public PropertyEvaluator getEvaluator() { + return p.evaluator(); + } + +} Index: ant/freeform/src/org/netbeans/modules/ant/freeform/spi/ProjectNature.java =================================================================== RCS file: /cvs/ant/freeform/src/org/netbeans/modules/ant/freeform/spi/ProjectNature.java,v retrieving revision 1.4 diff -u -r1.4 ProjectNature.java --- ant/freeform/src/org/netbeans/modules/ant/freeform/spi/ProjectNature.java 4 Aug 2006 21:36:51 -0000 1.4 +++ ant/freeform/src/org/netbeans/modules/ant/freeform/spi/ProjectNature.java 8 Feb 2007 07:23:25 -0000 @@ -41,20 +41,6 @@ public interface ProjectNature { /** - * Check project and provide additional lookup if it is project of your type. - * @return lookup additional lookup to insert; cannot be null (use {@link Lookup#EMPTY} instead) - */ - Lookup getLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux); - - /** - * Check project and provide additional customizer panels if it is project of your type. - * Order of panels is unimportant because - * {@link ProjectPropertiesPanel#getPreferredPosition} will be used for ordering. - * @return a list of {@link ProjectPropertiesPanel}s (can be empty but not null) - */ - Set getCustomizerPanels(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux); - - /** * Check project and provide additional build targets to be shown in * target mapping customizer panel if it is project of your type. Order * of targets is important. Index: ant/freeform/src/org/netbeans/modules/ant/freeform/spi/ProjectPropertiesPanel.java =================================================================== RCS file: ant/freeform/src/org/netbeans/modules/ant/freeform/spi/ProjectPropertiesPanel.java diff -N ant/freeform/src/org/netbeans/modules/ant/freeform/spi/ProjectPropertiesPanel.java --- ant/freeform/src/org/netbeans/modules/ant/freeform/spi/ProjectPropertiesPanel.java 30 Jun 2006 18:05:40 -0000 1.3 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,59 +0,0 @@ -/* - * The contents of this file are subject to the terms of the Common Development - * and Distribution License (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.html - * or http://www.netbeans.org/cddl.txt. - * - * When distributing Covered Code, include this CDDL Header Notice in each file - * and include the License file at http://www.netbeans.org/cddl.txt. - * If applicable, add the following below the CDDL Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - */ - -package org.netbeans.modules.ant.freeform.spi; - -import javax.swing.JComponent; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; - -/** - * Interface describing one customizer panel. The panels are added to - * the project customizer by {@link ProjectNature#getCustomizerPanels}. - * @author David Konecny - */ -public interface ProjectPropertiesPanel { - - /** - * Returns panel to be shown in UI. - */ - JComponent getComponent(); - - /** - * Returns display name of the panel which is used in the category list. - */ - String getDisplayName(); - - /** - * Persists customizations done in the panel. Called only when user - * pressed OK in customizer. The panel may or may not be retrieved - * by getComponent() method. - */ - void storeValues(); - - /** - * Preferred position in the list of panels at which it should be displayed. - * Check other panels positions to sort it. When multiple panels has the same - * position the order is undefined. - */ - int getPreferredPosition(); - - //Icon getIcon(); - -} Index: ant/freeform/src/org/netbeans/modules/ant/freeform/spi/support/Util.java =================================================================== RCS file: /cvs/ant/freeform/src/org/netbeans/modules/ant/freeform/spi/support/Util.java,v retrieving revision 1.7 diff -u -r1.7 Util.java --- ant/freeform/src/org/netbeans/modules/ant/freeform/spi/support/Util.java 10 Aug 2006 18:41:07 -0000 1.7 +++ ant/freeform/src/org/netbeans/modules/ant/freeform/spi/support/Util.java 8 Feb 2007 07:23:25 -0000 @@ -34,7 +34,7 @@ import org.netbeans.modules.ant.freeform.FreeformProject; import org.netbeans.modules.ant.freeform.FreeformProjectGenerator; import org.netbeans.modules.ant.freeform.FreeformProjectType; -import org.netbeans.modules.ant.freeform.ProjectAccessor; +import org.netbeans.modules.ant.freeform.spi.ProjectAccessor; import org.netbeans.modules.ant.freeform.spi.ProjectConstants; import org.netbeans.spi.project.AuxiliaryConfiguration; import org.netbeans.spi.project.support.ant.AntProjectHelper; Index: ant/freeform/src/org/netbeans/modules/ant/freeform/ui/FolderNodeFactory.java =================================================================== RCS file: ant/freeform/src/org/netbeans/modules/ant/freeform/ui/FolderNodeFactory.java diff -N ant/freeform/src/org/netbeans/modules/ant/freeform/ui/FolderNodeFactory.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ant/freeform/src/org/netbeans/modules/ant/freeform/ui/FolderNodeFactory.java 8 Feb 2007 07:23:25 -0000 @@ -0,0 +1,281 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + +package org.netbeans.modules.ant.freeform.ui; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.EventListenerList; +import org.netbeans.api.project.Project; +import org.netbeans.api.queries.VisibilityQuery; +import org.netbeans.modules.ant.freeform.FreeformProject; +import org.netbeans.modules.ant.freeform.FreeformProjectType; +import org.netbeans.modules.ant.freeform.spi.support.Util; +import org.netbeans.modules.ant.freeform.spi.ProjectNature; +import org.netbeans.spi.project.support.ant.AntProjectEvent; +import org.netbeans.spi.project.support.ant.AntProjectListener; +import org.netbeans.spi.project.ui.support.NodeFactory; +import org.netbeans.spi.project.ui.support.NodeList; +import org.openide.filesystems.FileObject; +import org.openide.loaders.ChangeableDataFilter; +import org.openide.loaders.DataFilter; +import org.openide.loaders.DataFolder; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataObjectNotFoundException; +import org.openide.nodes.FilterNode; +import org.openide.nodes.Node; +import org.openide.util.Lookup; +import org.openide.util.RequestProcessor; +import org.w3c.dom.Element; + + +/** + * + * @author mkleint + */ +public class FolderNodeFactory implements NodeFactory { + + /** Creates a new instance of FolderNodeFactory */ + public FolderNodeFactory() { + } + + public NodeList createNodes(Project p) { + FreeformProject project = p.getLookup().lookup(FreeformProject.class); + assert project != null; + return new RootChildren(project); + } + + + private static final class RootChildren implements NodeList, AntProjectListener { + + private final FreeformProject p; + private List keys = new ArrayList(); + private List listeners = new ArrayList(); + + public RootChildren(FreeformProject p) { + this.p = p; + } + + public void addNotify() { + updateKeys(false); + p.helper().addAntProjectListener(this); + // XXX should probably listen to project.evaluator also? + } + + public void removeNotify() { + keys = null; + p.helper().removeAntProjectListener(this); + } + + private void updateKeys(boolean fromListener) { + Element genldata = p.helper().getPrimaryConfigurationData(true); + Element viewEl = Util.findElement(genldata, "view", FreeformProjectType.NS_GENERAL); // NOI18N + if (viewEl != null) { + Element itemsEl = Util.findElement(viewEl, "items", FreeformProjectType.NS_GENERAL); // NOI18N + keys = Util.findSubElements(itemsEl); + if (fromListener) { + // #50328 - post setKeys to different thread to prevent deadlocks + RequestProcessor.getDefault().post(new Runnable() { + public void run() { + fireChange(); + } + }); + } + } else { + if (fromListener) { + keys = Collections.emptyList(); + // #58491 - post setKeys to different thread to prevent deadlocks + RequestProcessor.getDefault().post(new Runnable() { + public void run() { + fireChange(); + } + }); + } + } + } + + + public void configurationXmlChanged(AntProjectEvent ev) { + updateKeys(true); + } + + public void propertiesChanged(AntProjectEvent ev) { + // ignore + } + + public List keys() { + return keys; + } + + public void addChangeListener(ChangeListener l) { + listeners.add(l); + } + + public void removeChangeListener(ChangeListener l) { + listeners.remove(l); + } + + private void fireChange() { + List list = new ArrayList(); + list.addAll(listeners); + for (ChangeListener ls : listeners) { + ls.stateChanged(new ChangeEvent(this)); + } + } + + public Node node(Element itemEl) { + + Element locationEl = Util.findElement(itemEl, "location", FreeformProjectType.NS_GENERAL); // NOI18N + String location = Util.findText(locationEl); + String locationEval = p.evaluator().evaluate(location); + if (locationEval == null) { + return null; + } + FileObject file = p.helper().resolveFileObject(locationEval); + if (file == null) { + // Not there... skip this node. + return null; + } + String label; + Element labelEl = Util.findElement(itemEl, "label", FreeformProjectType.NS_GENERAL); // NOI18N + if (labelEl != null) { + label = Util.findText(labelEl); + } else { + label = null; + } + if (itemEl.getLocalName().equals("source-folder")) { // NOI18N + if (!file.isFolder()) { + // Just a file. Skip it. + return null; + } + String style = itemEl.getAttribute("style"); // NOI18N + for (ProjectNature nature : Lookup.getDefault().lookupAll(ProjectNature.class)) { + if (nature.getSourceFolderViewStyles().contains(style)) { + return nature.createSourceFolderView(p, file, style, location, label); + } + } + // fall back to tree display + // assert style.equals(STYLE_TREE); + DataObject fileDO; + try { + fileDO = DataObject.find(file); + } catch (DataObjectNotFoundException e) { + throw new AssertionError(e); + } + return new ViewItemNode((DataFolder) fileDO, location, label); + } else { + assert itemEl.getLocalName().equals("source-file") : itemEl; // NOI18N + DataObject fileDO; + try { + fileDO = DataObject.find(file); + } catch (DataObjectNotFoundException e) { + throw new AssertionError(e); + } + return new ViewItemNode(fileDO.getNodeDelegate(), location, label); + } + } + } + + + static final class VisibilityQueryDataFilter implements ChangeListener, ChangeableDataFilter { + + EventListenerList ell = new EventListenerList(); + + public VisibilityQueryDataFilter() { + VisibilityQuery.getDefault().addChangeListener( this ); + } + + public boolean acceptDataObject(DataObject obj) { + FileObject fo = obj.getPrimaryFile(); + return VisibilityQuery.getDefault().isVisible( fo ); + } + + public void stateChanged( ChangeEvent e) { + Object[] listeners = ell.getListenerList(); + ChangeEvent event = null; + for (int i = listeners.length-2; i>=0; i-=2) { + if (listeners[i] == ChangeListener.class) { + if ( event == null) { + event = new ChangeEvent( this ); + } + ((ChangeListener)listeners[i+1]).stateChanged( event ); + } + } + } + + public void addChangeListener( ChangeListener listener ) { + ell.add( ChangeListener.class, listener ); + } + + public void removeChangeListener( ChangeListener listener ) { + ell.remove( ChangeListener.class, listener ); + } + + } + + private static final class ViewItemNode extends FilterNode { + + private final String name; + + private final String displayName; + private static final DataFilter VISIBILITY_QUERY_FILTER = new VisibilityQueryDataFilter(); + + public ViewItemNode(Node orig, String name, String displayName) { + super(orig); + this.name = name; + this.displayName = displayName; + } + + public ViewItemNode(DataFolder folder, String name, String displayName) { + super(folder.getNodeDelegate(), folder.createNodeChildren(VISIBILITY_QUERY_FILTER)); + this.name = name; + this.displayName = displayName; + } + + public String getName() { + return name; + } + + public String getDisplayName() { + if (displayName != null) { + return displayName; + } else { + // #50425: show original name incl. annotations + return super.getDisplayName(); + } + } + + public boolean canRename() { + return false; + } + + public boolean canDestroy() { + return false; + } + + public boolean canCut() { + return false; + } + + } +} \ No newline at end of file Index: ant/freeform/src/org/netbeans/modules/ant/freeform/ui/ProjectCustomizer.form =================================================================== RCS file: ant/freeform/src/org/netbeans/modules/ant/freeform/ui/ProjectCustomizer.form diff -N ant/freeform/src/org/netbeans/modules/ant/freeform/ui/ProjectCustomizer.form --- ant/freeform/src/org/netbeans/modules/ant/freeform/ui/ProjectCustomizer.form 21 Jan 2005 14:31:23 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,88 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Index: ant/freeform/src/org/netbeans/modules/ant/freeform/ui/ProjectCustomizer.java =================================================================== RCS file: ant/freeform/src/org/netbeans/modules/ant/freeform/ui/ProjectCustomizer.java diff -N ant/freeform/src/org/netbeans/modules/ant/freeform/ui/ProjectCustomizer.java --- ant/freeform/src/org/netbeans/modules/ant/freeform/ui/ProjectCustomizer.java 1 Feb 2007 17:27:48 -0000 1.25 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,438 +0,0 @@ -/* - * The contents of this file are subject to the terms of the Common Development - * and Distribution License (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.html - * or http://www.netbeans.org/cddl.txt. - * - * When distributing Covered Code, include this CDDL Header Notice in each file - * and include the License file at http://www.netbeans.org/cddl.txt. - * If applicable, add the following below the CDDL Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - */ - -package org.netbeans.modules.ant.freeform.ui; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.Image; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyVetoException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import javax.swing.JPanel; -import javax.swing.tree.TreeSelectionModel; -import org.netbeans.modules.ant.freeform.FreeformProject; -import org.netbeans.modules.ant.freeform.Util; -import org.netbeans.modules.ant.freeform.spi.ProjectNature; -import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel; -import org.netbeans.modules.ant.freeform.spi.TargetDescriptor; -import org.netbeans.spi.project.AuxiliaryConfiguration; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.DialogDescriptor; -import org.openide.explorer.ExplorerManager; -import org.openide.explorer.view.BeanTreeView; -import org.openide.nodes.AbstractNode; -import org.openide.nodes.Children; -import org.openide.nodes.Node; -import org.openide.util.HelpCtx; -import org.openide.util.Utilities; - -/** - * - * @author Petr Hrebejk, David Konecny - */ -public class ProjectCustomizer extends JPanel implements HelpCtx.Provider { - - private Component currentCustomizer; - private GridBagConstraints fillConstraints; - private List panels; - private FreeformProject project; - - private DialogDescriptor dialogDescriptor; - - private static final String GENERAL_ICON = "general.gif"; // NOI18N - - public ProjectCustomizer(FreeformProject project) { - this.project = project; - initComponents(); - HelpCtx.setHelpIDString( customizerPanel, "org.netbeans.modules.ant.freeform.ui.ProjectCustomizer." + Util.getMergedHelpIDFragments(project)); // NOI18N - - fillConstraints = new GridBagConstraints(); - fillConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - fillConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; - fillConstraints.fill = java.awt.GridBagConstraints.BOTH; - fillConstraints.weightx = 1.0; - fillConstraints.weighty = 1.0; - createProjectCustomizerPanels(); - categoryPanel.add(new CategoryView(createRootNode()), fillConstraints); - } - - void save() { - for (ProjectPropertiesPanel panel : panels) { - panel.storeValues(); - } - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - private void initComponents() {//GEN-BEGIN:initComponents - java.awt.GridBagConstraints gridBagConstraints; - - categoryPanel = new javax.swing.JPanel(); - jPanel1 = new javax.swing.JPanel(); - customizerPanel = new javax.swing.JPanel(); - jLabel1 = new javax.swing.JLabel(); - - setLayout(new java.awt.GridBagLayout()); - - setPreferredSize(new java.awt.Dimension(750, 450)); - getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "ACSD_ProjectCustomizer")); - categoryPanel.setLayout(new java.awt.GridBagLayout()); - - categoryPanel.setBorder(new javax.swing.border.EtchedBorder()); - categoryPanel.setMinimumSize(new java.awt.Dimension(220, 4)); - categoryPanel.setPreferredSize(new java.awt.Dimension(220, 4)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 1; - gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weighty = 1.0; - gridBagConstraints.insets = new java.awt.Insets(4, 8, 8, 8); - add(categoryPanel, gridBagConstraints); - categoryPanel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "ACSN_ProjectCustomizer_categoryPanel")); - categoryPanel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "ACSD_ProjectCustomizer_categoryPanel")); - - jPanel1.setLayout(new java.awt.GridBagLayout()); - - customizerPanel.setLayout(new java.awt.GridBagLayout()); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.weighty = 1.0; - jPanel1.add(customizerPanel, gridBagConstraints); - customizerPanel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "ACSN_ProjectCustomizer_customizerPanel")); - customizerPanel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "ACSD_ProjectCustomizer_customizerPanel")); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridy = 1; - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.weighty = 1.0; - gridBagConstraints.insets = new java.awt.Insets(4, 4, 8, 8); - add(jPanel1, gridBagConstraints); - - jLabel1.setText(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "LBL_Customizer_Categories")); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 0; - gridBagConstraints.gridwidth = 2; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.insets = new java.awt.Insets(8, 8, 0, 0); - add(jLabel1, gridBagConstraints); - - }//GEN-END:initComponents - - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JPanel categoryPanel; - private javax.swing.JPanel customizerPanel; - private javax.swing.JLabel jLabel1; - private javax.swing.JPanel jPanel1; - // End of variables declaration//GEN-END:variables - - public void setDialogDescriptor( DialogDescriptor dialogDescriptor ) { - this.dialogDescriptor = dialogDescriptor; - } - - // HelpCtx.Provider implementation ----------------------------------------- - - public HelpCtx getHelpCtx() { - if ( currentCustomizer != null ) { - HelpCtx customizerCtx = HelpCtx.findHelp( currentCustomizer ); - if (customizerCtx.getHelpID() != null) { - return new HelpCtx(customizerCtx.getHelpID() + "." + Util.getMergedHelpIDFragments(project)); // NOI18N - } else { - return customizerCtx; - } - } else { - return HelpCtx.findHelp( customizerPanel ); - } - } - - // Private innerclasses ---------------------------------------------------- - - private class CategoryView extends JPanel implements ExplorerManager.Provider { - - private ExplorerManager manager; - private BeanTreeView btv; - - CategoryView( Node rootNode ) { - - // See #36315 - manager = new ExplorerManager(); - - setLayout( new BorderLayout() ); - - Dimension size = new Dimension( 220, 4 ); - btv = new BeanTreeView(); // Add the BeanTreeView - btv.setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION ); - btv.setPopupAllowed( false ); - btv.setRootVisible( false ); - btv.setDefaultActionAllowed( false ); - btv.setMinimumSize( size ); - btv.setPreferredSize( size ); - btv.setMaximumSize( size ); - btv.setDragSource (false); - btv.setDragSource (false); - this.add( btv, BorderLayout.CENTER ); - manager.setRootContext( rootNode ); - manager.addPropertyChangeListener( new ManagerChangeListener() ); - selectFirstNode(); - btv.expandAll(); - - } - - public ExplorerManager getExplorerManager() { - return manager; - } - - public void addNotify() { - super.addNotify(); - btv.expandAll(); - } - - private void selectFirstNode() { - - Children ch = manager.getRootContext().getChildren(); - if ( ch != null ) { - Node nodes[] = ch.getNodes(); - - if ( nodes != null && nodes.length > 0 ) { - try { - manager.setSelectedNodes( new Node[] { nodes[0] } ); - } - catch ( PropertyVetoException e ) { - // No node will be selected - } - } - } - - } - - - /** Listens to selection change and shows the customizers as - * panels - */ - - private class ManagerChangeListener implements PropertyChangeListener { - - public void propertyChange(PropertyChangeEvent evt) { - if(evt.getSource() != manager) { - return; - } - - if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { - Node nodes[] = manager.getSelectedNodes(); - if ( nodes == null || nodes.length <= 0 ) { - return; - } - Node node = nodes[0]; - - if ( currentCustomizer != null ) { - customizerPanel.remove( currentCustomizer ); - } - if ( node.hasCustomizer() ) { - currentCustomizer = node.getCustomizer(); - customizerPanel.add( currentCustomizer, fillConstraints ); - customizerPanel.validate(); - customizerPanel.repaint(); - if ( ProjectCustomizer.this.dialogDescriptor != null ) { - ProjectCustomizer.this.dialogDescriptor.setHelpCtx( ProjectCustomizer.this.getHelpCtx() ); - } - - - } - else { - currentCustomizer = null; - } - - return; - } - } - } - } - - // Private methods --------------------------------------------------------- - - private List createProjectCustomizerPanels() { - AuxiliaryConfiguration aux = project.getLookup().lookup(AuxiliaryConfiguration.class); - AntProjectHelper helper = project.helper(); - PropertyEvaluator eval = project.evaluator(); - panels = new ArrayList(); - List extraTargets = new ArrayList(); - for (ProjectNature pn : FreeformProject.PROJECT_NATURES.allInstances()) { - panels.addAll(pn.getCustomizerPanels(project, helper, eval, aux)); - extraTargets.addAll(pn.getExtraTargets(project, helper, eval, aux)); - } - if (project.usesAntScripting()) { - panels.add(new TargetMappingPanel.Panel(extraTargets, eval, helper)); - } - - Collections.sort(panels, new PanelsComparator()); - return panels; - } - - private static class PanelsComparator implements Comparator { - public int compare(ProjectPropertiesPanel p1, ProjectPropertiesPanel p2) { - if (p1.getPreferredPosition() == p2.getPreferredPosition()) { - return 0; - } else { - return p1.getPreferredPosition() - p2.getPreferredPosition(); - } - } - } - - private Node createRootNode() { - - String ICON_FOLDER = "org/netbeans/modules/ant/freeform/resources/"; // NOI18N - - List l = new ArrayList(); - for (ProjectPropertiesPanel panel : panels) { - ConfigurationDescription cd = new ConfigurationDescription( - panel.getDisplayName(), - panel.getDisplayName(), - ICON_FOLDER + GENERAL_ICON, - panel, - null); - l.add(cd); - } - - ConfigurationDescription rootDescription = new ConfigurationDescription( - "InvisibleRoot", "InvisibleRoot", null, null, l.toArray(new ConfigurationDescription[l.size()])); // NOI18N - - return new ConfigurationNode( rootDescription ); - } - - // Private innerclasses ---------------------------------------------------- - - /** Class describing the configuration node. Prototype of the - * configuration node. - */ - private static class ConfigurationDescription { - - - private String name; - private String displayName; - private String iconResource; - private ProjectPropertiesPanel panel; - private ConfigurationDescription[] children; - // XXX Add Node.Properties - - ConfigurationDescription( String name, - String displayName, - String iconResource, - ProjectPropertiesPanel panel, - ConfigurationDescription[] children ) { - - this.name = name; - this.displayName = displayName; - this.iconResource = iconResource; - this.panel = panel; - this.children = children; - } - - } - - - /** Node to be used for configuration - */ - private static class ConfigurationNode extends AbstractNode { - - private ProjectPropertiesPanel panel; - /** resource path to icon, or null */ - private final String iconResource; - - public ConfigurationNode( ConfigurationDescription description ) { - super( description.children == null ? Children.LEAF : new ConfigurationChildren( description.children ) ); - setName( description.name ); - setDisplayName( description.displayName ); - this.iconResource = description.iconResource; - this.panel = description.panel; - } - - public boolean hasCustomizer() { - return true; - } - - public Component getCustomizer() { - if (panel == null) { - return null; - } - return panel.getComponent(); - } - - public Image getIcon(int type) { - if (iconResource != null) { - return Utilities.loadImage(iconResource, true); - } else { - return super.getIcon(type); - } - } - - public Image getOpenedIcon(int type) { - if (iconResource != null) { - return Utilities.loadImage(iconResource, true); - } else { - return super.getOpenedIcon(type); - } - } - - } - - private static class ConfigurationChildren extends Children.Keys { - - private ConfigurationDescription[] descriptions; - - public ConfigurationChildren(ConfigurationDescription[] descriptions) { - this.descriptions = descriptions; - } - - public void addNotify() { - setKeys(descriptions); - } - - public void removeNotify() { - setKeys(new ConfigurationDescription[0]); - } - - protected Node[] createNodes(ConfigurationDescription key) { - return new Node[] {new ConfigurationNode(key)}; - } - } -} Index: ant/freeform/src/org/netbeans/modules/ant/freeform/ui/ProjectCustomizerProvider.java =================================================================== RCS file: /cvs/ant/freeform/src/org/netbeans/modules/ant/freeform/ui/ProjectCustomizerProvider.java,v retrieving revision 1.11 diff -u -r1.11 ProjectCustomizerProvider.java --- ant/freeform/src/org/netbeans/modules/ant/freeform/ui/ProjectCustomizerProvider.java 4 Aug 2006 21:36:52 -0000 1.11 +++ ant/freeform/src/org/netbeans/modules/ant/freeform/ui/ProjectCustomizerProvider.java 8 Feb 2007 07:23:25 -0000 @@ -22,20 +22,23 @@ import java.awt.Dialog; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.io.IOException; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.text.MessageFormat; +import java.util.HashMap; import java.util.Map; -import java.util.WeakHashMap; -import javax.swing.JButton; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectManager; import org.netbeans.api.project.ProjectUtils; import org.netbeans.modules.ant.freeform.FreeformProject; +import org.netbeans.modules.ant.freeform.spi.ProjectAccessor; +import org.netbeans.spi.project.AuxiliaryConfiguration; import org.netbeans.spi.project.ui.CustomizerProvider; -import org.openide.DialogDescriptor; -import org.openide.DialogDisplayer; -import org.openide.ErrorManager; +import org.netbeans.spi.project.ui.support.ProjectCustomizer; +import org.openide.util.Lookup; import org.openide.util.NbBundle; +import org.openide.util.lookup.AbstractLookup; +import org.openide.util.lookup.InstanceContent; /** * @@ -45,103 +48,81 @@ private final FreeformProject project; - // Option indexes - private static final int OPTION_OK = 0; - private static final int OPTION_CANCEL = OPTION_OK + 1; - - // Option command names - private static final String COMMAND_OK = "OK"; // NOI18N - private static final String COMMAND_CANCEL = "CANCEL"; // NOI18N + public static final String CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-ant-freeform/Customizer"; //NO18N - private DialogDescriptor dialogDescriptor; - private Map customizerPerProject = new WeakHashMap(); // Is weak needed here? + private static Map /**/project2Dialog = new HashMap(); public ProjectCustomizerProvider(FreeformProject project) { this.project = project; } public void showCustomizer() { - - if (customizerPerProject.containsKey (project)) { - Dialog dlg = customizerPerProject.get(project); - - // check if the project is being customized - if (dlg.isShowing ()) { - // make it showed - dlg.setVisible(true); - return ; - } + Dialog dialog = (Dialog)project2Dialog.get (project); + if ( dialog != null ) { + dialog.setVisible(true); + return; } + else { + InstanceContent ic = new InstanceContent(); + Lookup context = new AbstractLookup(ic); + ic.add(project); + ic.add(project.getLookup().lookup(ProjectAccessor.class)); + ic.add(project.getLookup().lookup(AuxiliaryConfiguration.class)); + //TODO replace with generic apis.. + ic.add(ic); + + OptionListener listener = new OptionListener( project ); + dialog = ProjectCustomizer.createCustomizerDialog(CUSTOMIZER_FOLDER_PATH, context, null, listener, null ); + dialog.addWindowListener( listener ); + dialog.setTitle( MessageFormat.format( + NbBundle.getMessage( ProjectCustomizerProvider.class, "LBL_Customizer_Title" ), // NOI18N + new Object[] { ProjectUtils.getInformation(project).getDisplayName() } ) ); - // Create options - JButton options[] = new JButton[] { - new JButton( NbBundle.getMessage( ProjectCustomizerProvider.class, "LBL_Customizer_Ok_Option") ), // NOI18N - new JButton( NbBundle.getMessage( ProjectCustomizerProvider.class, "LBL_Customizer_Cancel_Option" ) ) , // NOI18N - }; - - // Set commands - options[ OPTION_OK ].setActionCommand( COMMAND_OK ); - options[ OPTION_CANCEL ].setActionCommand( COMMAND_CANCEL ); - - ProjectCustomizer pc = new ProjectCustomizer(project); - // RegisterListener - ActionListener optionsListener = new OptionListener( project, pc); - options[ OPTION_OK ].addActionListener( optionsListener ); - options[ OPTION_OK ].getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage (ProjectCustomizerProvider.class, "ACSD_Customizer_Ok_Option")); // NOI18N - options[ OPTION_CANCEL ].addActionListener( optionsListener ); - options[ OPTION_CANCEL ].getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage (ProjectCustomizerProvider.class, "ACSD_Customizer_Cancel_Option")); // NOI18N - - dialogDescriptor = new DialogDescriptor( - pc, // innerPane - MessageFormat.format( // displayName - NbBundle.getMessage( ProjectCustomizerProvider.class, "LBL_Customizer_Title" ), // NOI18N - new Object[] { ProjectUtils.getInformation(project).getDisplayName() } ), - false, // modal - options, // options - options[OPTION_OK], // initial value - DialogDescriptor.BOTTOM_ALIGN, // options align - null, // helpCtx - null ); // listener - - pc.setDialogDescriptor( dialogDescriptor ); - dialogDescriptor.setClosingOptions( new Object[] { options[ OPTION_OK ], options[ OPTION_CANCEL ] } ); - - Dialog dialog = DialogDisplayer.getDefault().createDialog( dialogDescriptor ); - - customizerPerProject.put (project, dialog); - - dialog.setVisible(true); - + project2Dialog.put(project, dialog); + dialog.setVisible(true); + } } - /** Listens to the actions on the Customizer's option buttons */ - private static class OptionListener implements ActionListener { + private class OptionListener extends WindowAdapter implements ActionListener { private Project project; - private ProjectCustomizer projectCustomizer; - private OptionListener(Project project, ProjectCustomizer projectCustomizer) { + OptionListener( Project project) { this.project = project; - this.projectCustomizer = projectCustomizer; } + // Listening to OK button ---------------------------------------------- + public void actionPerformed( ActionEvent e ) { - String command = e.getActionCommand(); + // Store the properties into project + assert !ProjectManager.getDefault().isModified(project) : + "Some of the customizer panels has written the changed data before OK Button was pressed. Please file it as bug."; //NOI18N - if ( COMMAND_OK.equals( command ) ) { - projectCustomizer.save(); - - try { - ProjectManager.getDefault().saveProject(project); - } catch ( IOException ex ) { - ErrorManager.getDefault().notify( ex ); - } + // Close & dispose the the dialog + Dialog dialog = (Dialog)project2Dialog.get( project ); + if ( dialog != null ) { + dialog.setVisible(false); + dialog.dispose(); } - } + // Listening to window events ------------------------------------------ + + public void windowClosed( WindowEvent e) { + project2Dialog.remove( project ); + } + + public void windowClosing (WindowEvent e) { + //Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed} + //may not be called + Dialog dialog = (Dialog)project2Dialog.get( project ); + if ( dialog != null ) { + dialog.setVisible(false); + dialog.dispose(); + } + } } } Index: ant/freeform/src/org/netbeans/modules/ant/freeform/ui/TargetMappingCategoryProvider.java =================================================================== RCS file: ant/freeform/src/org/netbeans/modules/ant/freeform/ui/TargetMappingCategoryProvider.java diff -N ant/freeform/src/org/netbeans/modules/ant/freeform/ui/TargetMappingCategoryProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ant/freeform/src/org/netbeans/modules/ant/freeform/ui/TargetMappingCategoryProvider.java 8 Feb 2007 07:23:25 -0000 @@ -0,0 +1,74 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.ant.freeform.ui; + +import java.util.ArrayList; +import java.util.List; +import javax.swing.JComponent; +import org.netbeans.api.project.Project; +import org.netbeans.modules.ant.freeform.FreeformProject; +import org.netbeans.modules.ant.freeform.spi.ProjectAccessor; +import org.netbeans.modules.ant.freeform.spi.ProjectNature; +import org.netbeans.modules.ant.freeform.spi.TargetDescriptor; +import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; + + +/** + * + * @author mkleint + */ +public class TargetMappingCategoryProvider implements org.netbeans.spi.project.ui.support.ProjectCustomizer.CompositeCategoryProvider { + + /** Creates a new instance of TargetMappingCustomizerProvider */ + public TargetMappingCategoryProvider() { + } + + public Category createCategory(Lookup context) { + FreeformProject project = context.lookup(FreeformProject.class); + assert project != null; + if (project.usesAntScripting()) { + return org.netbeans.spi.project.ui.support.ProjectCustomizer.Category.create("targetMapping", + NbBundle.getMessage(TargetMappingPanel.class, "LBL_ProjectCustomizer_Category_Targets"), null, null); + } + return null; + } + + public JComponent createComponent(Category category, Lookup context) { + Project project = context.lookup(Project.class); + ProjectAccessor acc = context.lookup(ProjectAccessor.class); + AuxiliaryConfiguration aux = context.lookup(AuxiliaryConfiguration.class); + assert aux != null; + assert acc != null; + assert project != null; + + List extraTargets = new ArrayList(); + for (ProjectNature pn : FreeformProject.PROJECT_NATURES.allInstances()) { + extraTargets.addAll(pn.getExtraTargets(project, acc.getHelper(), acc.getEvaluator(), aux)); + } + + TargetMappingPanel panel = new TargetMappingPanel(extraTargets, acc.getEvaluator(), acc.getHelper()); + category.setOkButtonListener(panel.getCustomizerOkListener()); + return panel; + } + +} Index: ant/freeform/src/org/netbeans/modules/ant/freeform/ui/TargetMappingPanel.java =================================================================== RCS file: /cvs/ant/freeform/src/org/netbeans/modules/ant/freeform/ui/TargetMappingPanel.java,v retrieving revision 1.38 diff -u -r1.38 TargetMappingPanel.java --- ant/freeform/src/org/netbeans/modules/ant/freeform/ui/TargetMappingPanel.java 10 Aug 2006 18:48:12 -0000 1.38 +++ ant/freeform/src/org/netbeans/modules/ant/freeform/ui/TargetMappingPanel.java 8 Feb 2007 07:23:25 -0000 @@ -20,6 +20,7 @@ package org.netbeans.modules.ant.freeform.ui; import java.awt.Frame; +import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Arrays; @@ -32,7 +33,6 @@ import javax.swing.ComboBoxModel; import javax.swing.DefaultCellEditor; import javax.swing.JComboBox; -import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; @@ -41,7 +41,6 @@ import org.netbeans.modules.ant.freeform.FreeformProjectGenerator; import org.netbeans.modules.ant.freeform.Util; import org.netbeans.modules.ant.freeform.spi.ProjectConstants; -import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel; import org.netbeans.modules.ant.freeform.spi.TargetDescriptor; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; @@ -83,7 +82,8 @@ /** Any change in custom tasks which needs to be persisted? */ private boolean dirtyCustom; - + + private AntProjectHelper helper; public TargetMappingPanel(boolean advancedPart) { this(new ArrayList(), advancedPart); @@ -104,7 +104,7 @@ public TargetMappingPanel(List extraTargets, PropertyEvaluator evaluator, AntProjectHelper helper) { this(extraTargets, true); - + this.helper = helper; FileObject as = FreeformProjectGenerator.getAntScript(helper, evaluator); List l = null; // #50933 - script can be null @@ -621,65 +621,37 @@ remove.setEnabled(custTargets.size() > 0); } - public static class Panel implements ProjectPropertiesPanel { - - private List extraTargets; - private PropertyEvaluator evaluator; - private AntProjectHelper helper; - private TargetMappingPanel panel; - - public Panel(List extraTargets, PropertyEvaluator evaluator, AntProjectHelper helper) { - this.helper = helper; - this.extraTargets = extraTargets; - this.evaluator = evaluator; - } - - /* ProjectCustomizer.Panel save */ - public void storeValues() { - if (panel == null) { - return; - } - List mapping = panel.getMapping(); - if (panel.dirtyRegular) { - FreeformProjectGenerator.putTargetMappings(helper, mapping); - FreeformProjectGenerator.putContextMenuAction(helper, mapping); - } - - if (panel.dirtyCustom) { - List l = new ArrayList(panel.custTargets); - Iterator it = l.iterator(); - while (it.hasNext()) { - FreeformProjectGenerator.CustomTarget ct = it.next(); - // ignore row if target was not set - if (ct.targets == null || ct.targets.size() == 0) { - it.remove(); - continue; - } - if (ct.label == null || ct.label.length() == 0) { - ct.label = ct.targets.get(0); + + ActionListener getCustomizerOkListener() { + return new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + List mapping = getMapping(); + if (dirtyRegular) { + FreeformProjectGenerator.putTargetMappings(helper, mapping); + FreeformProjectGenerator.putContextMenuAction(helper, mapping); + } + + if (dirtyCustom) { + List l = new ArrayList(custTargets); + Iterator it = l.iterator(); + while (it.hasNext()) { + FreeformProjectGenerator.CustomTarget ct = it.next(); + // ignore row if target was not set + if (ct.targets == null || ct.targets.size() == 0) { + it.remove(); + continue; + } + if (ct.label == null || ct.label.length() == 0) { + ct.label = ct.targets.get(0); + } } + FreeformProjectGenerator.putCustomContextMenuActions(helper, l); } - FreeformProjectGenerator.putCustomContextMenuActions(helper, l); } - } - - public String getDisplayName() { - return NbBundle.getMessage(TargetMappingPanel.class, "LBL_ProjectCustomizer_Category_Targets"); - } - - public JComponent getComponent() { - if (panel == null) { - panel = new TargetMappingPanel(extraTargets, evaluator, helper); - } - return panel; - } - - public int getPreferredPosition() { - return 1000; - } - + }; } + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton add; private javax.swing.JLabel additionalTargetsLabel; @@ -791,5 +763,5 @@ dlg.setVisible(true); } } - + } Index: ant/freeform/src/org/netbeans/modules/ant/freeform/ui/View.java =================================================================== RCS file: /cvs/ant/freeform/src/org/netbeans/modules/ant/freeform/ui/View.java,v retrieving revision 1.24 diff -u -r1.24 View.java --- ant/freeform/src/org/netbeans/modules/ant/freeform/ui/View.java 1 Feb 2007 17:27:49 -0000 1.24 +++ ant/freeform/src/org/netbeans/modules/ant/freeform/ui/View.java 8 Feb 2007 07:23:25 -0000 @@ -24,40 +24,25 @@ import java.util.List; import java.util.StringTokenizer; import javax.swing.Action; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import javax.swing.event.EventListenerList; import org.netbeans.api.project.ProjectUtils; -import org.netbeans.api.queries.VisibilityQuery; import org.netbeans.modules.ant.freeform.Actions; import org.netbeans.modules.ant.freeform.FreeformProject; -import org.netbeans.modules.ant.freeform.FreeformProjectType; import org.netbeans.modules.ant.freeform.spi.ProjectNature; -import org.netbeans.modules.ant.freeform.spi.support.Util; -import org.netbeans.spi.project.support.ant.AntProjectEvent; -import org.netbeans.spi.project.support.ant.AntProjectListener; import org.netbeans.spi.project.ui.LogicalViewProvider; import org.netbeans.spi.project.ui.support.DefaultProjectOperations; +import org.netbeans.spi.project.ui.support.NodeFactorySupport; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; -import org.openide.loaders.ChangeableDataFilter; -import org.openide.loaders.DataFilter; -import org.openide.loaders.DataFolder; import org.openide.loaders.DataObject; -import org.openide.loaders.DataObjectNotFoundException; import org.openide.nodes.AbstractNode; -import org.openide.nodes.Children; -import org.openide.nodes.FilterNode; import org.openide.nodes.Node; import org.openide.nodes.NodeNotFoundException; import org.openide.nodes.NodeOp; import org.openide.util.HelpCtx; import org.openide.util.Lookup; import org.openide.util.NbCollections; -import org.openide.util.RequestProcessor; import org.openide.util.Utilities; import org.openide.util.lookup.Lookups; -import org.w3c.dom.Element; /** * Logical view of a freeform project. @@ -113,124 +98,12 @@ return null; } - private static final class RootChildren extends Children.Keys implements AntProjectListener { - - private final FreeformProject p; - - public RootChildren(FreeformProject p) { - this.p = p; - } - - protected void addNotify() { - super.addNotify(); - updateKeys(false); - p.helper().addAntProjectListener(this); - // XXX should probably listen to project.evaluator also? - } - - protected void removeNotify() { - setKeys(Collections.emptySet()); - p.helper().removeAntProjectListener(this); - super.removeNotify(); - } - - private void updateKeys(boolean fromListener) { - Element genldata = p.helper().getPrimaryConfigurationData(true); - Element viewEl = Util.findElement(genldata, "view", FreeformProjectType.NS_GENERAL); // NOI18N - if (viewEl != null) { - Element itemsEl = Util.findElement(viewEl, "items", FreeformProjectType.NS_GENERAL); // NOI18N - final List keys = Util.findSubElements(itemsEl); - if (fromListener) { - // #50328 - post setKeys to different thread to prevent deadlocks - RequestProcessor.getDefault().post(new Runnable() { - public void run() { - setKeys(keys); - } - }); - } else { - setKeys(keys); - } - } else { - if (fromListener) { - // #58491 - post setKeys to different thread to prevent deadlocks - RequestProcessor.getDefault().post(new Runnable() { - public void run() { - setKeys(Collections.emptySet()); - } - }); - } else { - setKeys(Collections.emptySet()); - } - } - } - - protected Node[] createNodes(Element itemEl) { - Element locationEl = Util.findElement(itemEl, "location", FreeformProjectType.NS_GENERAL); // NOI18N - String location = Util.findText(locationEl); - String locationEval = p.evaluator().evaluate(location); - if (locationEval == null) { - return null; - } - FileObject file = p.helper().resolveFileObject(locationEval); - if (file == null) { - // Not there... skip this node. - return null; - } - String label; - Element labelEl = Util.findElement(itemEl, "label", FreeformProjectType.NS_GENERAL); // NOI18N - if (labelEl != null) { - label = Util.findText(labelEl); - } else { - label = null; - } - if (itemEl.getLocalName().equals("source-folder")) { // NOI18N - if (!file.isFolder()) { - // Just a file. Skip it. - return null; - } - String style = itemEl.getAttribute("style"); // NOI18N - for (ProjectNature nature : Lookup.getDefault().lookupAll(ProjectNature.class)) { - if (nature.getSourceFolderViewStyles().contains(style)) { - return new Node[] {nature.createSourceFolderView(p, file, style, location, label)}; - } - } - // fall back to tree display - // assert style.equals(STYLE_TREE); - DataObject fileDO; - try { - fileDO = DataObject.find(file); - } catch (DataObjectNotFoundException e) { - throw new AssertionError(e); - } - return new Node[] {new ViewItemNode((DataFolder) fileDO, location, label)}; - } else { - assert itemEl.getLocalName().equals("source-file") : itemEl; // NOI18N - DataObject fileDO; - try { - fileDO = DataObject.find(file); - } catch (DataObjectNotFoundException e) { - throw new AssertionError(e); - } - return new Node[] {new ViewItemNode(fileDO.getNodeDelegate(), location, label)}; - } - } - - public void configurationXmlChanged(AntProjectEvent ev) { - updateKeys(true); - } - - public void propertiesChanged(AntProjectEvent ev) { - // ignore - } - - } - private static final class RootNode extends AbstractNode { private final FreeformProject p; public RootNode(FreeformProject p) { - super(new RootChildren(p), Lookups.singleton(p)); + super(NodeFactorySupport.createCompositeChildren(p, "Projects/org-netbeans-modules-ant-freeform/Nodes"), Lookups.singleton(p)); this.p = p; } @@ -275,87 +148,6 @@ } } - - static final class VisibilityQueryDataFilter implements ChangeListener, ChangeableDataFilter { - - EventListenerList ell = new EventListenerList(); - - public VisibilityQueryDataFilter() { - VisibilityQuery.getDefault().addChangeListener( this ); - } - - public boolean acceptDataObject(DataObject obj) { - FileObject fo = obj.getPrimaryFile(); - return VisibilityQuery.getDefault().isVisible( fo ); - } - - public void stateChanged( ChangeEvent e) { - Object[] listeners = ell.getListenerList(); - ChangeEvent event = null; - for (int i = listeners.length-2; i>=0; i-=2) { - if (listeners[i] == ChangeListener.class) { - if ( event == null) { - event = new ChangeEvent( this ); - } - ((ChangeListener)listeners[i+1]).stateChanged( event ); - } - } - } - - public void addChangeListener( ChangeListener listener ) { - ell.add( ChangeListener.class, listener ); - } - - public void removeChangeListener( ChangeListener listener ) { - ell.remove( ChangeListener.class, listener ); - } - - } - - private static final class ViewItemNode extends FilterNode { - - private final String name; - - private final String displayName; - private static final DataFilter VISIBILITY_QUERY_FILTER = new VisibilityQueryDataFilter(); - - public ViewItemNode(Node orig, String name, String displayName) { - super(orig); - this.name = name; - this.displayName = displayName; - } - - public ViewItemNode(DataFolder folder, String name, String displayName) { - super(folder.getNodeDelegate(), folder.createNodeChildren(VISIBILITY_QUERY_FILTER)); - this.name = name; - this.displayName = displayName; - } - - public String getName() { - return name; - } - - public String getDisplayName() { - if (displayName != null) { - return displayName; - } else { - // #50425: show original name incl. annotations - return super.getDisplayName(); - } - } - - public boolean canRename() { - return false; - } - - public boolean canDestroy() { - return false; - } - - public boolean canCut() { - return false; - } - - } + } Index: ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/spi/ProjectNatureTest.java =================================================================== RCS file: ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/spi/ProjectNatureTest.java diff -N ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/spi/ProjectNatureTest.java --- ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/spi/ProjectNatureTest.java 16 Oct 2006 14:18:44 -0000 1.9 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,205 +0,0 @@ -/* - * The contents of this file are subject to the terms of the Common Development - * and Distribution License (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.html - * or http://www.netbeans.org/cddl.txt. - * - * When distributing Covered Code, include this CDDL Header Notice in each file - * and include the License file at http://www.netbeans.org/cddl.txt. - * If applicable, add the following below the CDDL Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - */ - -package org.netbeans.modules.ant.freeform.spi; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectManager; -import org.netbeans.junit.NbTestCase; -import org.netbeans.modules.ant.freeform.FreeformProjectGenerator; -import org.netbeans.spi.project.AuxiliaryConfiguration; -import org.netbeans.spi.project.LookupMerger; -import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.openide.filesystems.FileObject; -import org.openide.nodes.Node; -import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; -import org.openide.util.lookup.ProxyLookup; - -// XXX testActionProviderMergeSemantics - -/** - * Tests correct behavior of merging of lookups from project natures - * and merging of instances by LookupMerger. - * - * @author dk125166 - */ -public class ProjectNatureTest extends NbTestCase { - - public ProjectNatureTest(String testName) { - super(testName); - } - - protected void setUp() throws Exception { - clearWorkDir(); - } - - private AntProjectHelper createEmptyProject(String projectFolder, String projectName) throws Exception { - File base = new File(getWorkDir(), projectFolder); - base.mkdir(); - AntProjectHelper helper = FreeformProjectGenerator.createProject(base, base, projectName, null); - return helper; - } - - public void testGetLookup() throws Exception { - AntProjectHelper h = createEmptyProject("mrg", "ee"); - JavaNature javaNature = Lookup.getDefault().lookup(JavaNature.class); - assertNotNull("found java nature", javaNature); - WebNature webNature = Lookup.getDefault().lookup(WebNature.class); - assertNotNull("found web nature", webNature); - - // first test merging of lookups without LookupMerger: - Project p = ProjectManager.getDefault().findProject(h.getProjectDirectory()); - Lookup.Result tqr = p.getLookup().lookupResult(TemplatesQuery.class); - assertEquals("no TemplatesQuery in project yet", 0, tqr.allInstances().size()); - - TemplatesQuery javaTemplates = new BaseTemplates(new String[]{"class", "main", "library"}); - javaNature.setLookups(new Lookup[]{Lookups.fixed(javaTemplates)}); - assertEquals("javaTemplates in project", 1, tqr.allInstances().size()); - - TemplatesQuery webTemplates = new BaseTemplatesAndSomeProvider(new String[]{"class", "dd"}); - webNature.setLookups(new Lookup[]{Lookups.fixed(webTemplates)}); - assertEquals("webTemplates and javaTemplates in project", 2, tqr.allInstances().size()); - assertEquals("one SomeProvider", 1, p.getLookup().lookupAll(SomeProvider.class).size()); - - // test merging: - LookupMerger lm = new TemplatesQueryMerger(); - javaNature.setLookups(new Lookup[]{Lookups.fixed(javaTemplates, lm)}); - assertEquals("only mergedTemplates in project: " + tqr.allInstances(), 1, tqr.allInstances().size()); - TemplatesQuery tq = p.getLookup().lookup(TemplatesQuery.class); - assertEquals("three merged templates", 4, tq.getTemplates().size()); - assertEquals("one SomeProvider", 1, p.getLookup().lookupAll(SomeProvider.class).size()); - - // test nature uninstallation: - webNature.setLookups(new Lookup[]{Lookup.EMPTY}); - assertEquals("only javaTemplates in project", 1, tqr.allInstances().size()); - tq = p.getLookup().lookup(TemplatesQuery.class); - assertEquals("two java templates", 3, tq.getTemplates().size()); - assertEquals("no SomeProvider", 0, p.getLookup().lookupAll(SomeProvider.class).size()); - } - - private static class BaseNature implements ProjectNature { - - private ChangeableLookup lookup = new ChangeableLookup(); - - public BaseNature() {} - - public Lookup getLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { - return lookup; - } - - public void setLookups(Lookup[] lookups) { - lookup.setLookups2(lookups); - } - - public Set getCustomizerPanels(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { - return Collections.emptySet(); - } - - public List getExtraTargets(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { - return Collections.emptyList(); - } - - public Set getSchemas() { - return Collections.emptySet(); - } - - public Set getSourceFolderViewStyles() { - return Collections.emptySet(); - } - - public Node createSourceFolderView(Project project, FileObject folder, String style, String name, String displayName) throws IllegalArgumentException { - return null; - } - - public Node findSourceFolderViewPath(Project project, Node root, Object target) { - return null; - } - - } - - public static class JavaNature extends BaseNature { - public JavaNature() {} - } - - public static class WebNature extends BaseNature { - public WebNature() {} - } - - private static final class ChangeableLookup extends ProxyLookup { - public ChangeableLookup() {} - - public void setLookups2(Lookup[] lookups) { - setLookups(lookups); - } - } - - private interface TemplatesQuery { - List getTemplates(); - } - - private static class BaseTemplates implements TemplatesQuery { - private List list = new ArrayList(); - public BaseTemplates(String arr[]) { - list.addAll(Arrays.asList(arr)); - } - public List getTemplates() { - return list; - } - } - - private static class BaseTemplatesAndSomeProvider extends BaseTemplates implements SomeProvider { - public BaseTemplatesAndSomeProvider(String arr[]) { - super(arr); - } - public Object find() { - return null; - } - } - - private interface SomeProvider { - public Object find(); - } - - private static class TemplatesQueryMerger implements LookupMerger { - public TemplatesQueryMerger() {} - public Class getMergeableClass() { - return TemplatesQuery.class; - } - - public ProjectNatureTest.TemplatesQuery merge(Lookup lookup) { - Set set = new LinkedHashSet(); - for (TemplatesQuery tq : lookup.lookupAll(TemplatesQuery.class)) { - set.addAll(tq.getTemplates()); - } - return new BaseTemplates(set.toArray(new String[set.size()])); - } - } - -} Index: ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/ui/ViewTest.java =================================================================== RCS file: /cvs/ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/ui/ViewTest.java,v retrieving revision 1.9 diff -u -r1.9 ViewTest.java --- ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/ui/ViewTest.java 10 Aug 2006 18:41:08 -0000 1.9 +++ ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/ui/ViewTest.java 8 Feb 2007 07:23:25 -0000 @@ -29,12 +29,14 @@ import org.netbeans.spi.project.ui.LogicalViewProvider; import org.openide.filesystems.FileObject; import org.openide.loaders.DataObject; +import org.openide.modules.ModuleInfo; import org.openide.nodes.Children; import org.openide.nodes.Node; import org.openide.nodes.NodeEvent; import org.openide.nodes.NodeListener; import org.openide.nodes.NodeMemberEvent; import org.openide.nodes.NodeReorderEvent; +import org.openide.util.Lookup; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -54,6 +56,7 @@ protected void setUp() throws Exception { super.setUp(); + ModuleInfo info = Lookup.getDefault().lookup(ModuleInfo.class); lvp = extsrcroot.getLookup().lookup(LogicalViewProvider.class); assertNotNull("found a LogicalViewProvider", lvp); } Index: j2ee/ejbfreeform/nbproject/project.xml =================================================================== RCS file: /cvs/j2ee/ejbfreeform/nbproject/project.xml,v retrieving revision 1.20 diff -u -r1.20 project.xml --- j2ee/ejbfreeform/nbproject/project.xml 30 Nov 2006 12:57:09 -0000 1.20 +++ j2ee/ejbfreeform/nbproject/project.xml 8 Feb 2007 07:23:25 -0000 @@ -38,7 +38,7 @@ 1 - 1.13 + 1.14 Index: j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/EJBProjectNature.java =================================================================== RCS file: /cvs/j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/EJBProjectNature.java,v retrieving revision 1.21 diff -u -r1.21 EJBProjectNature.java --- j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/EJBProjectNature.java 12 Oct 2006 14:51:41 -0000 1.21 +++ j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/EJBProjectNature.java 8 Feb 2007 07:23:25 -0000 @@ -20,33 +20,21 @@ package org.netbeans.modules.j2ee.ejbfreeform; import java.io.IOException; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.WeakHashMap; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.project.Project; -import org.netbeans.modules.ant.freeform.spi.HelpIDFragmentProvider; import org.netbeans.modules.ant.freeform.spi.ProjectNature; -import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel; import org.netbeans.modules.ant.freeform.spi.TargetDescriptor; import org.netbeans.modules.j2ee.api.ejbjar.EjbJar; import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; -import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; -import org.netbeans.modules.j2ee.ejbfreeform.ui.EJBLocationsPanel; import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView; -import org.netbeans.modules.j2ee.spi.ejbjar.support.EjbEnterpriseReferenceContainerSupport; import org.netbeans.spi.project.AuxiliaryConfiguration; -import org.netbeans.spi.project.support.ant.AntProjectEvent; import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.AntProjectListener; import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.spi.project.ui.PrivilegedTemplates; -import org.netbeans.spi.project.ui.ProjectOpenedHook; -import org.netbeans.spi.project.ui.RecommendedTemplates; import org.openide.ErrorManager; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; @@ -55,10 +43,7 @@ import org.openide.nodes.Node; import org.openide.nodes.NodeNotFoundException; import org.openide.nodes.NodeOp; -import org.openide.util.Lookup; import org.openide.util.NbBundle; -import org.openide.util.lookup.Lookups; -import org.openide.util.lookup.ProxyLookup; /** * @author David Konecny @@ -73,32 +58,10 @@ public static final String EL_EJB = "ejb-data"; // NOI18N public static final String STYLE_CONFIG_FILES = "configFiles"; // NOI18N public static final String STYLE_EJBS = "ejbs"; // NOI18N - - private static final String HELP_ID_FRAGMENT = "ejb"; // NOI18N - - private static final WeakHashMap/*>*/ lookupCache = new WeakHashMap(); public EJBProjectNature() {} - public Lookup getLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { - WeakReference wr = (WeakReference)lookupCache.get(project); - Lookup lookup = wr != null ? (Lookup)wr.get() : null; - if (lookup == null) { - lookup = new ProjectLookup(project, projectHelper, projectEvaluator, aux); - lookupCache.put(project, new WeakReference(lookup)); - } - return lookup; - } - - public Set getCustomizerPanels(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { - HashSet l = new HashSet(); - if (!isMyProject(aux)) { - return l; - } - ProjectPropertiesPanel ejb = new EJBLocationsPanel.Panel(project, projectHelper, projectEvaluator, aux); - l.add(ejb); - return l; - } + public List getExtraTargets(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { ArrayList l = new ArrayList(); @@ -175,7 +138,7 @@ } } - private static boolean isMyProject(AuxiliaryConfiguration aux) { + public static boolean isMyProject(AuxiliaryConfiguration aux) { return (aux.getConfigurationFragment(EL_EJB, NS_EJB, true) != null) || (aux.getConfigurationFragment(EL_EJB, NS_EJB_2, true) != null); } @@ -186,123 +149,5 @@ NbBundle.getMessage(EJBProjectNature.class, "ACSD_TargetMappingPanel_Deploy")); // NOI18N } - private static Lookup initLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { - - EJBFreeformProvider ejbFFProvider = new EJBFreeformProvider(project, projectHelper, projectEvaluator); - EJBFreeformModule ejbFFModule = new EJBFreeformModule(project, projectHelper, projectEvaluator); - ejbFFProvider.setJ2eeModule(ejbFFModule); - - return Lookups.fixed(new Object[] { - ejbFFProvider, - ejbFFModule, - new EJBModules(project, projectHelper, projectEvaluator), // EJBModuleProvider, ClassPathProvider - new PrivilegedTemplatesImpl(), // List of templates in New action popup - EjbEnterpriseReferenceContainerSupport.createEnterpriseReferenceContainer(project, projectHelper), - new EjbFreeFormActionProvider(project, projectHelper, aux), - new ProjectOpenedHookImpl(project), - new LookupMergerImpl(), - new HelpIDFragmentProviderImpl(), - }); - } - - private static final class HelpIDFragmentProviderImpl implements HelpIDFragmentProvider { - public String getHelpIDFragment() { - return HELP_ID_FRAGMENT; - } - } - - private static final class ProjectLookup extends ProxyLookup implements AntProjectListener { - - private AntProjectHelper helper; - private PropertyEvaluator evaluator; - private Project project; - private AuxiliaryConfiguration aux; - private boolean isMyProject; - - public ProjectLookup(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux) { - super(new Lookup[0]); - this.project = project; - this.helper = helper; - this.evaluator = evaluator; - this.aux = aux; - this.isMyProject = isMyProject(aux); - updateLookup(); - helper.addAntProjectListener(this); - } - - private void updateLookup() { - Lookup l = Lookup.EMPTY; - if (isMyProject) { - l = initLookup(project, helper, evaluator, aux); - } - setLookups(new Lookup[]{l}); - } - - public void configurationXmlChanged(AntProjectEvent ev) { - if (isMyProject(aux) != isMyProject) { - isMyProject = !isMyProject; - updateLookup(); - } - } - - public void propertiesChanged(AntProjectEvent ev) { - // ignore - } - - } - - private static final class ProjectOpenedHookImpl extends ProjectOpenedHook { - - private Project project; - - public ProjectOpenedHookImpl(Project project) { - this.project = project; - } - - protected void projectOpened() { - // initialize the server configuration - J2eeModuleProvider j2eeModule = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class); - j2eeModule.getConfigSupport().ensureConfigurationReady(); - } - - protected void projectClosed() { - } - } - - private static final class PrivilegedTemplatesImpl implements PrivilegedTemplates, RecommendedTemplates { - - private static final String[] PRIVILEGED_NAMES = new String[] { - "Templates/J2EE/Session", // NOI18N - "Templates/J2EE/Entity", // NOI18N - "Templates/J2EE/ServiceLocator.java", // NOI18N - "Templates/Classes/Class.java" // NOI18N - }; - - private static final String[] RECOMENDED_TYPES = new String[] { - "java-classes", // NOI18N - "ejb-types", // NOI18N - "ejb-types_2_1", // NOI18N - "j2ee-types", // NOI18N - "java-beans", // NOI18N - "oasis-XML-catalogs", // NOI18N - "XML", // NOI18N - "wsdl", // NOI18N - "ant-script", // NOI18N - "ant-task", // NOI18N - "junit", // NOI18N - "simple-files" // NOI18N - }; - - public String[] getPrivilegedTemplates() { - return PRIVILEGED_NAMES; - } - - public String[] getRecommendedTypes() { - return RECOMENDED_TYPES; - } - - - - } } Index: j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/LookupProviderImpl.java =================================================================== RCS file: j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/LookupProviderImpl.java diff -N j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/LookupProviderImpl.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/LookupProviderImpl.java 8 Feb 2007 07:23:25 -0000 @@ -0,0 +1,182 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.j2ee.ejbfreeform; + +import org.netbeans.api.project.Project; +import org.netbeans.modules.ant.freeform.spi.HelpIDFragmentProvider; +import org.netbeans.modules.ant.freeform.spi.ProjectAccessor; +import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; +import org.netbeans.modules.j2ee.spi.ejbjar.support.EjbEnterpriseReferenceContainerSupport; +import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.LookupProvider; +import org.netbeans.spi.project.support.ant.AntProjectEvent; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.AntProjectListener; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.netbeans.spi.project.ui.PrivilegedTemplates; +import org.netbeans.spi.project.ui.ProjectOpenedHook; +import org.netbeans.spi.project.ui.RecommendedTemplates; +import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; + +/** + * + * @author mkleint + */ +public class LookupProviderImpl implements LookupProvider { + + private static final String HELP_ID_FRAGMENT = "ejb"; // NOI18N + + /** Creates a new instance of LookupProviderImpl */ + public LookupProviderImpl() { + } + + public Lookup createAdditionalLookup(Lookup baseContext) { + Project prj = (Project)baseContext.lookup(Project.class); + ProjectAccessor acc = (ProjectAccessor)baseContext.lookup(ProjectAccessor.class); + AuxiliaryConfiguration aux = (AuxiliaryConfiguration)baseContext.lookup(AuxiliaryConfiguration.class); + assert aux != null; + assert prj != null; + assert acc != null; + return new ProjectLookup(prj, acc.getHelper(), acc.getEvaluator(), aux); + } + + private static Lookup initLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { + + EJBFreeformProvider ejbFFProvider = new EJBFreeformProvider(project, projectHelper, projectEvaluator); + EJBFreeformModule ejbFFModule = new EJBFreeformModule(project, projectHelper, projectEvaluator); + ejbFFProvider.setJ2eeModule(ejbFFModule); + + return Lookups.fixed(new Object[] { + ejbFFProvider, + ejbFFModule, + new EJBModules(project, projectHelper, projectEvaluator), // EJBModuleProvider, ClassPathProvider + new PrivilegedTemplatesImpl(), // List of templates in New action popup + EjbEnterpriseReferenceContainerSupport.createEnterpriseReferenceContainer(project, projectHelper), + new EjbFreeFormActionProvider(project, projectHelper, aux), + new ProjectOpenedHookImpl(project), + new LookupMergerImpl(), + new HelpIDFragmentProviderImpl(), + }); + } + + private static final class HelpIDFragmentProviderImpl implements HelpIDFragmentProvider { + public String getHelpIDFragment() { + return HELP_ID_FRAGMENT; + } + } + + private static final class ProjectLookup extends ProxyLookup implements AntProjectListener { + + private AntProjectHelper helper; + private PropertyEvaluator evaluator; + private Project project; + private AuxiliaryConfiguration aux; + private boolean isMyProject; + + public ProjectLookup(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux) { + super(new Lookup[0]); + this.project = project; + this.helper = helper; + this.evaluator = evaluator; + this.aux = aux; + this.isMyProject = EJBProjectNature.isMyProject(aux); + updateLookup(); + helper.addAntProjectListener(this); + } + + private void updateLookup() { + Lookup l = Lookup.EMPTY; + if (isMyProject) { + l = initLookup(project, helper, evaluator, aux); + } + setLookups(new Lookup[]{l}); + } + + public void configurationXmlChanged(AntProjectEvent ev) { + if (EJBProjectNature.isMyProject(aux) != isMyProject) { + isMyProject = !isMyProject; + updateLookup(); + } + } + + public void propertiesChanged(AntProjectEvent ev) { + // ignore + } + + } + + private static final class ProjectOpenedHookImpl extends ProjectOpenedHook { + + private Project project; + + public ProjectOpenedHookImpl(Project project) { + this.project = project; + } + + protected void projectOpened() { + // initialize the server configuration + J2eeModuleProvider j2eeModule = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class); + j2eeModule.getConfigSupport().ensureConfigurationReady(); + } + + protected void projectClosed() { + } + } + + private static final class PrivilegedTemplatesImpl implements PrivilegedTemplates, RecommendedTemplates { + + private static final String[] PRIVILEGED_NAMES = new String[] { + "Templates/J2EE/Session", // NOI18N + "Templates/J2EE/Entity", // NOI18N + "Templates/J2EE/ServiceLocator.java", // NOI18N + "Templates/Classes/Class.java" // NOI18N + }; + + private static final String[] RECOMENDED_TYPES = new String[] { + "java-classes", // NOI18N + "ejb-types", // NOI18N + "ejb-types_2_1", // NOI18N + "j2ee-types", // NOI18N + "java-beans", // NOI18N + "oasis-XML-catalogs", // NOI18N + "XML", // NOI18N + "wsdl", // NOI18N + "ant-script", // NOI18N + "ant-task", // NOI18N + "junit", // NOI18N + "simple-files" // NOI18N + }; + + public String[] getPrivilegedTemplates() { + return PRIVILEGED_NAMES; + } + + public String[] getRecommendedTypes() { + return RECOMENDED_TYPES; + } + + + + } + + +} Index: j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/resources/layer.xml =================================================================== RCS file: /cvs/j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/resources/layer.xml,v retrieving revision 1.4 diff -u -r1.4 layer.xml --- j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/resources/layer.xml 30 Jun 2006 20:38:34 -0000 1.4 +++ j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/resources/layer.xml 8 Feb 2007 07:23:25 -0000 @@ -35,4 +35,16 @@ + + + + + + + + + + + + Index: j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/ui/EJBLocationsPanel.java =================================================================== RCS file: /cvs/j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/ui/EJBLocationsPanel.java,v retrieving revision 1.22 diff -u -r1.22 EJBLocationsPanel.java --- j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/ui/EJBLocationsPanel.java 12 Oct 2006 14:51:41 -0000 1.22 +++ j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/ui/EJBLocationsPanel.java 8 Feb 2007 07:23:25 -0000 @@ -19,6 +19,8 @@ package org.netbeans.modules.j2ee.ejbfreeform.ui; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.File; import java.io.FilenameFilter; import java.io.IOException; @@ -27,14 +29,12 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.swing.JComponent; import javax.swing.JFileChooser; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import org.netbeans.api.project.Project; import org.netbeans.api.queries.CollocationQuery; -import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel; import org.netbeans.modules.ant.freeform.spi.support.Util; import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; @@ -582,64 +582,35 @@ return Util.relativizeLocation(baseFolder, nbProjectFolder, normalizedLocation); } - public static class Panel implements ProjectPropertiesPanel { - - private Project project; - private AntProjectHelper projectHelper; - private PropertyEvaluator projectEvaluator; - private AuxiliaryConfiguration aux; - private EJBLocationsPanel panel; - - public Panel(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { - this.project = project; - this.projectHelper = projectHelper; - this.projectEvaluator = projectEvaluator; - this.aux = aux; - } - - public void storeValues() { - if (panel == null) { - return; - } - AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(projectHelper); - EJBProjectGenerator.putEJBModules(projectHelper, aux, panel.getEJBModules()); - EJBProjectGenerator.putServerID(projectHelper, panel.getSelectedServerID()); - EJBProjectGenerator.putResourceFolder(projectHelper, panel.getResourcesFolder()); - - String j2eeLevel = ((EJBProjectGenerator.EJBModule)panel.getEJBModules().get(0)).j2eeSpecLevel; - EJBProjectGenerator.putJ2EELevel(projectHelper, j2eeLevel); - - // update the DD to 2.1 if it is 2.0 and the user switched to J2EE 1.4 - FileObject ejbJarXml = findEbjJarXml(panel.getConfigFilesLocation()); - try { - if (j2eeLevel.equals("1.4") && !new BigDecimal(EjbJar.VERSION_2_1).equals(getEjbJarXmlVersion(ejbJarXml))) { // NOI18N - EjbJar root = DDProvider.getDefault().getDDRoot(ejbJarXml); - root.setVersion(new BigDecimal(EjbJar.VERSION_2_1)); - root.write(ejbJarXml); + ActionListener getCustomizerOkListener() { + return new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + + AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(projectHelper); + EJBProjectGenerator.putEJBModules(projectHelper, aux, getEJBModules()); + EJBProjectGenerator.putServerID(projectHelper, getSelectedServerID()); + EJBProjectGenerator.putResourceFolder(projectHelper, getResourcesFolder()); + + String j2eeLevel = ((EJBProjectGenerator.EJBModule)getEJBModules().get(0)).j2eeSpecLevel; + EJBProjectGenerator.putJ2EELevel(projectHelper, j2eeLevel); + + // update the DD to 2.1 if it is 2.0 and the user switched to J2EE 1.4 + FileObject ejbJarXml = findEbjJarXml(getConfigFilesLocation()); + try { + if (j2eeLevel.equals("1.4") && !new BigDecimal(EjbJar.VERSION_2_1).equals(getEjbJarXmlVersion(ejbJarXml))) { // NOI18N + EjbJar root = DDProvider.getDefault().getDDRoot(ejbJarXml); + root.setVersion(new BigDecimal(EjbJar.VERSION_2_1)); + root.write(ejbJarXml); + } + } catch (IOException e) { + final ErrorManager errorManager = ErrorManager.getDefault(); + String message = NbBundle.getMessage(EJBLocationsPanel.class, "MSG_EjbJarXmlCorrupted"); + errorManager.notify(errorManager.annotate(e, message)); } } - catch (IOException e) { - final ErrorManager errorManager = ErrorManager.getDefault(); - String message = NbBundle.getMessage(EJBLocationsPanel.class, "MSG_EjbJarXmlCorrupted"); - errorManager.notify(errorManager.annotate(e, message)); - } - } - - public String getDisplayName() { - return NbBundle.getMessage(EJBLocationsPanel.class, "LBL_ProjectCustomizer_Category_EJB"); - } - - public JComponent getComponent() { - if (panel == null) { - panel = new EJBLocationsPanel(null, project, projectHelper, projectEvaluator, aux); - } - return panel; - } - - public int getPreferredPosition() { - return 40; // before Java sources panel - } + }; } + private void initServerInstances() { String[] servInstIDs = Deployment.getDefault().getServerInstanceIDs(); Index: j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/ui/EjbLocationsCategoryProvider.java =================================================================== RCS file: j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/ui/EjbLocationsCategoryProvider.java diff -N j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/ui/EjbLocationsCategoryProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/ui/EjbLocationsCategoryProvider.java 8 Feb 2007 07:23:25 -0000 @@ -0,0 +1,66 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.j2ee.ejbfreeform.ui; + +import javax.swing.JComponent; +import org.netbeans.api.project.Project; +import org.netbeans.modules.ant.freeform.spi.ProjectAccessor; +import org.netbeans.modules.j2ee.ejbfreeform.EJBProjectNature; +import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.ui.support.ProjectCustomizer; +import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; + +/** + * + * @author mkleint + */ +public class EjbLocationsCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider { + + /** Creates a new instance of EjbLocationsCategoryProvider */ + public EjbLocationsCategoryProvider() { + } + + public Category createCategory(Lookup context) { + AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class); + assert aux != null; + if (EJBProjectNature.isMyProject(aux)) { + Category cat = ProjectCustomizer.Category.create("EjbLocations", //NOI18N + NbBundle.getMessage(EJBLocationsPanel.class, "LBL_ProjectCustomizer_Category_EJB"), null, null); + return cat; + } + return null; + } + + public JComponent createComponent(Category category, Lookup context) { + Project project = (Project)context.lookup(Project.class); + ProjectAccessor acc = (ProjectAccessor)context.lookup(ProjectAccessor.class); + AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class); + assert aux != null; + assert acc != null; + assert project != null; + + EJBLocationsPanel panel = new EJBLocationsPanel(null, project, acc.getHelper(), acc.getEvaluator(), aux); + category.setOkButtonListener(panel.getCustomizerOkListener()); + return panel; + } + +} Index: java/freeform/nbproject/project.xml =================================================================== RCS file: /cvs/java/freeform/nbproject/project.xml,v retrieving revision 1.18 diff -u -r1.18 project.xml --- java/freeform/nbproject/project.xml 16 Oct 2006 14:18:46 -0000 1.18 +++ java/freeform/nbproject/project.xml 8 Feb 2007 07:23:25 -0000 @@ -56,7 +56,7 @@ 1 - 1.13 + 1.14 Index: java/freeform/src/org/netbeans/modules/java/freeform/JavaProjectNature.java =================================================================== RCS file: /cvs/java/freeform/src/org/netbeans/modules/java/freeform/JavaProjectNature.java,v retrieving revision 1.14 diff -u -r1.14 JavaProjectNature.java --- java/freeform/src/org/netbeans/modules/java/freeform/JavaProjectNature.java 12 Oct 2006 23:03:30 -0000 1.14 +++ java/freeform/src/org/netbeans/modules/java/freeform/JavaProjectNature.java 8 Feb 2007 07:23:25 -0000 @@ -19,47 +19,21 @@ package org.netbeans.modules.java.freeform; -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; -import java.util.WeakHashMap; import org.netbeans.api.project.Project; -import org.netbeans.modules.ant.freeform.spi.HelpIDFragmentProvider; import org.netbeans.modules.ant.freeform.spi.ProjectNature; -import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel; import org.netbeans.modules.ant.freeform.spi.TargetDescriptor; -import org.netbeans.modules.ant.freeform.spi.support.Util; -import org.netbeans.modules.java.freeform.ui.ClasspathPanel; -import org.netbeans.modules.java.freeform.ui.OutputPanel; -import org.netbeans.modules.java.freeform.ui.ProjectModel; -import org.netbeans.modules.java.freeform.ui.SourceFoldersPanel; import org.netbeans.spi.java.project.support.ui.PackageView; import org.netbeans.spi.project.AuxiliaryConfiguration; import org.netbeans.spi.project.support.GenericSources; -import org.netbeans.spi.project.support.ant.AntProjectEvent; import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.AntProjectListener; import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.spi.project.ui.PrivilegedTemplates; -import org.netbeans.spi.project.ui.ProjectOpenedHook; -import org.netbeans.spi.project.ui.RecommendedTemplates; import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; -import org.openide.util.lookup.ProxyLookup; -import org.w3c.dom.Comment; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; /** * General hook for registration of the Java nature for freeform projects. @@ -74,36 +48,8 @@ private static final String SCHEMA_2 = "nbres:/org/netbeans/modules/java/freeform/resources/freeform-project-java-2.xsd"; // NOI18N public static final String STYLE_PACKAGES = "packages"; // NOI18N - private static final String HELP_ID_FRAGMENT = "java"; // NOI18N - - private static final Map> lookupCache = new WeakHashMap>(); public JavaProjectNature() {} - - public Lookup getLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { - Reference wr = lookupCache.get(project); - Lookup lookup = wr != null ? wr.get() : null; - if (lookup == null) { - lookup = new ProjectLookup(project, projectHelper, projectEvaluator, aux); - lookupCache.put(project, new WeakReference(lookup)); - } - return lookup; - } - - public Set getCustomizerPanels(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { - Set l = new HashSet(); - if (!isMyProject(aux)) { - return l; - } - ProjectModel pm = ProjectModel.createModel(Util.getProjectLocation(projectHelper, projectEvaluator), FileUtil.toFile(project.getProjectDirectory()), projectEvaluator, projectHelper); - ProjectPropertiesPanel sfp = new SourceFoldersPanel.Panel(pm, projectHelper); - l.add(sfp); - ProjectPropertiesPanel cpp = new ClasspathPanel.Panel(project, projectHelper, projectEvaluator, pm); - l.add(cpp); - ProjectPropertiesPanel op = new OutputPanel.Panel(pm); - l.add(op); - return l; - } public List getExtraTargets(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { return new ArrayList(); @@ -133,201 +79,11 @@ return PackageView.findPath(root, target); } - private static Lookup initLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { - Classpaths cp = new Classpaths(projectHelper, projectEvaluator, aux); - return Lookups.fixed( - cp, // ClassPathProvider - new SourceLevelQueryImpl(projectHelper, projectEvaluator, aux), // SourceLevelQueryImplementation - new SourceForBinaryQueryImpl(projectHelper, projectEvaluator, aux), // SourceForBinaryQueryImplementation - new OpenHook(cp), // ProjectOpenedHook - new TestQuery(projectHelper, projectEvaluator, aux), // MultipleRootsUnitTestForSourceQueryImplementation - new JavadocQuery(projectHelper, projectEvaluator, aux), // JavadocForBinaryQueryImplementation - new PrivilegedTemplatesImpl(), // PrivilegedTemplates - new JavaActions(project, projectHelper, projectEvaluator, aux), // ActionProvider - new LookupMergerImpl(), // LookupMerger - new JavaFreeformFileBuiltQuery(project, projectHelper, projectEvaluator, aux), // FileBuiltQueryImplementation - new HelpIDFragmentProviderImpl()); - } - - private static boolean isMyProject(AuxiliaryConfiguration aux) { - return aux.getConfigurationFragment(EL_JAVA, NS_JAVA_1, true) != null || - aux.getConfigurationFragment(EL_JAVA, NS_JAVA_2, true) != null; - } - private static final class HelpIDFragmentProviderImpl implements HelpIDFragmentProvider { - public String getHelpIDFragment() { - return HELP_ID_FRAGMENT; - } - } - - private static class OpenHook extends ProjectOpenedHook { - - private final Classpaths cp; - - public OpenHook(Classpaths cp) { - this.cp = cp; - } - - protected void projectOpened() { - cp.opened(); - } - - protected void projectClosed() { - cp.closed(); - } - - } - - /** - * Transparently handles /1 -> /2 schema upgrade (on read only, not write!). - */ - static final class UpgradingAuxiliaryConfiguration implements AuxiliaryConfiguration { - - private final AuxiliaryConfiguration delegate; - - public UpgradingAuxiliaryConfiguration(AuxiliaryConfiguration delegate) { - this.delegate = delegate; - } - - public Element getConfigurationFragment(String elementName, String namespace, boolean shared) { - if (elementName.equals(EL_JAVA) && namespace.equals(NS_JAVA_2) && shared) { - Element nue = delegate.getConfigurationFragment(EL_JAVA, NS_JAVA_2, true); - if (nue == null) { - Element old = delegate.getConfigurationFragment(EL_JAVA, NS_JAVA_1, true); - if (old != null) { - nue = upgradeSchema(old); - } - } - return nue; - } else { - return delegate.getConfigurationFragment(elementName, namespace, shared); - } - } - public void putConfigurationFragment(Element fragment, boolean shared) throws IllegalArgumentException { - delegate.putConfigurationFragment(fragment, shared); - } - - public boolean removeConfigurationFragment(String elementName, String namespace, boolean shared) throws IllegalArgumentException { - return delegate.removeConfigurationFragment(elementName, namespace, shared); - } - - } - static Element upgradeSchema(Element old) { - Document doc = old.getOwnerDocument(); - Element nue = doc.createElementNS(NS_JAVA_2, EL_JAVA); - copyXMLTree(doc, old, nue, NS_JAVA_2); - return nue; - } - // Copied from org.netbeans.modules.java.j2seproject.UpdateHelper with changes; could be an API eventually: - private static void copyXMLTree(Document doc, Element from, Element to, String newNamespace) { - NodeList nl = from.getChildNodes(); - int length = nl.getLength(); - for (int i = 0; i < length; i++) { - org.w3c.dom.Node node = nl.item(i); - org.w3c.dom.Node newNode; - switch (node.getNodeType()) { - case org.w3c.dom.Node.ELEMENT_NODE: - Element oldElement = (Element) node; - newNode = doc.createElementNS(newNamespace, oldElement.getTagName()); - NamedNodeMap attrs = oldElement.getAttributes(); - int alength = attrs.getLength(); - for (int j = 0; j < alength; j++) { - org.w3c.dom.Attr oldAttr = (org.w3c.dom.Attr) attrs.item(j); - ((Element)newNode).setAttributeNS(oldAttr.getNamespaceURI(), oldAttr.getName(), oldAttr.getValue()); - } - copyXMLTree(doc, oldElement, (Element) newNode, newNamespace); - break; - case org.w3c.dom.Node.TEXT_NODE: - newNode = doc.createTextNode(((Text) node).getData()); - break; - case org.w3c.dom.Node.COMMENT_NODE: - newNode = doc.createComment(((Comment) node).getData()); - break; - default: - // Other types (e.g. CDATA) not yet handled. - throw new AssertionError(node); - } - to.appendChild(newNode); - } - } - private static final class ProjectLookup extends ProxyLookup implements AntProjectListener { - private AntProjectHelper helper; - private PropertyEvaluator evaluator; - private Project project; - private AuxiliaryConfiguration aux; - private boolean isMyProject; - - public ProjectLookup(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux) { - super(new Lookup[0]); - this.project = project; - this.helper = helper; - this.evaluator = evaluator; - this.aux = new UpgradingAuxiliaryConfiguration(aux); - this.isMyProject = isMyProject(aux); - updateLookup(); - helper.addAntProjectListener(this); - } - - private void updateLookup() { - Lookup l = Lookup.EMPTY; - if (isMyProject) { - l = initLookup(project, helper, evaluator, aux); - } - setLookups(new Lookup[]{l}); - } - - public void configurationXmlChanged(AntProjectEvent ev) { - if (isMyProject(aux) != isMyProject) { - isMyProject = !isMyProject; - updateLookup(); - } - } - - public void propertiesChanged(AntProjectEvent ev) { - // ignore - } - - } - - private static final class PrivilegedTemplatesImpl implements PrivilegedTemplates, RecommendedTemplates { - - private static final String[] PRIVILEGED_NAMES = new String[] { - "Templates/Classes/Class.java", // NOI18N - "Templates/Classes/Package", // NOI18N - "Templates/Classes/Interface.java", // NOI18N - }; - - // List of primarily supported templates = J2SEProject.LIBRARY_TYPES + J2SEProject.APPLICATION_TYPES - private static final String[] RECOMENDED_TYPES = new String[] { - "java-classes", // NOI18N - "java-main-class", // NOI18N - "java-forms", // NOI18N - "gui-java-application", // NOI18N - "java-beans", // NOI18N - "oasis-XML-catalogs", // NOI18N - "XML", // NOI18N - "ant-script", // NOI18N - "ant-task", // NOI18N - "servlet-types", // NOI18N - "wsdl", // NOI18N - "junit", // NOI18N - // "MIDP", // NOI18N - "simple-files" // NOI18N - }; - - public String[] getRecommendedTypes() { - return RECOMENDED_TYPES; - } - - public String[] getPrivilegedTemplates() { - return PRIVILEGED_NAMES; - } - - } } Index: java/freeform/src/org/netbeans/modules/java/freeform/LookupProviderImpl.java =================================================================== RCS file: java/freeform/src/org/netbeans/modules/java/freeform/LookupProviderImpl.java diff -N java/freeform/src/org/netbeans/modules/java/freeform/LookupProviderImpl.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ java/freeform/src/org/netbeans/modules/java/freeform/LookupProviderImpl.java 8 Feb 2007 07:23:25 -0000 @@ -0,0 +1,261 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.java.freeform; + +import org.netbeans.api.project.Project; +import org.netbeans.modules.ant.freeform.spi.HelpIDFragmentProvider; +import org.netbeans.modules.ant.freeform.spi.ProjectAccessor; +import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.LookupProvider; +import org.netbeans.spi.project.support.ant.AntProjectEvent; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.AntProjectListener; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.netbeans.spi.project.ui.PrivilegedTemplates; +import org.netbeans.spi.project.ui.ProjectOpenedHook; +import org.netbeans.spi.project.ui.RecommendedTemplates; +import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; +import org.w3c.dom.Comment; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * + * @author mkleint + */ +public class LookupProviderImpl implements LookupProvider { + private static final String HELP_ID_FRAGMENT = "java"; // NOI18N + + /** Creates a new instance of LookupProviderImpl */ + public LookupProviderImpl() { + } + + public Lookup createAdditionalLookup(Lookup baseContext) { + Project prj = baseContext.lookup(Project.class); + ProjectAccessor acc = baseContext.lookup(ProjectAccessor.class); + AuxiliaryConfiguration aux = baseContext.lookup(AuxiliaryConfiguration.class); + assert aux != null; + assert prj != null; + assert acc != null; + return new ProjectLookup(prj, acc.getHelper(), acc.getEvaluator(), aux); + } + + private static Lookup initLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { + Classpaths cp = new Classpaths(projectHelper, projectEvaluator, aux); + return Lookups.fixed( + cp, // ClassPathProvider + new SourceLevelQueryImpl(projectHelper, projectEvaluator, aux), // SourceLevelQueryImplementation + new SourceForBinaryQueryImpl(projectHelper, projectEvaluator, aux), // SourceForBinaryQueryImplementation + new OpenHook(cp), // ProjectOpenedHook + new TestQuery(projectHelper, projectEvaluator, aux), // MultipleRootsUnitTestForSourceQueryImplementation + new JavadocQuery(projectHelper, projectEvaluator, aux), // JavadocForBinaryQueryImplementation + new PrivilegedTemplatesImpl(), // PrivilegedTemplates + new JavaActions(project, projectHelper, projectEvaluator, aux), // ActionProvider + new LookupMergerImpl(), // LookupMerger + new JavaFreeformFileBuiltQuery(project, projectHelper, projectEvaluator, aux), // FileBuiltQueryImplementation + new HelpIDFragmentProviderImpl()); + } + + public static boolean isMyProject(AuxiliaryConfiguration aux) { + return aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true) != null || + aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true) != null; + } + + private static final class HelpIDFragmentProviderImpl implements HelpIDFragmentProvider { + public String getHelpIDFragment() { + return HELP_ID_FRAGMENT; + } + } + + private static class OpenHook extends ProjectOpenedHook { + + private final Classpaths cp; + + public OpenHook(Classpaths cp) { + this.cp = cp; + } + + protected void projectOpened() { + cp.opened(); + } + + protected void projectClosed() { + cp.closed(); + } + + } + + /** + * Transparently handles /1 -> /2 schema upgrade (on read only, not write!). + */ + static final class UpgradingAuxiliaryConfiguration implements AuxiliaryConfiguration { + + private final AuxiliaryConfiguration delegate; + + public UpgradingAuxiliaryConfiguration(AuxiliaryConfiguration delegate) { + this.delegate = delegate; + } + + public Element getConfigurationFragment(String elementName, String namespace, boolean shared) { + if (elementName.equals(JavaProjectNature.EL_JAVA) && namespace.equals(JavaProjectNature.NS_JAVA_2) && shared) { + Element nue = delegate.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); + if (nue == null) { + Element old = delegate.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); + if (old != null) { + nue = upgradeSchema(old); + } + } + return nue; + } else { + return delegate.getConfigurationFragment(elementName, namespace, shared); + } + } + + public void putConfigurationFragment(Element fragment, boolean shared) throws IllegalArgumentException { + delegate.putConfigurationFragment(fragment, shared); + } + + public boolean removeConfigurationFragment(String elementName, String namespace, boolean shared) throws IllegalArgumentException { + return delegate.removeConfigurationFragment(elementName, namespace, shared); + } + + } + + static Element upgradeSchema(Element old) { + Document doc = old.getOwnerDocument(); + Element nue = doc.createElementNS(JavaProjectNature.NS_JAVA_2, JavaProjectNature.EL_JAVA); + copyXMLTree(doc, old, nue, JavaProjectNature.NS_JAVA_2); + return nue; + } + // Copied from org.netbeans.modules.java.j2seproject.UpdateHelper with changes; could be an API eventually: + private static void copyXMLTree(Document doc, Element from, Element to, String newNamespace) { + NodeList nl = from.getChildNodes(); + int length = nl.getLength(); + for (int i = 0; i < length; i++) { + org.w3c.dom.Node node = nl.item(i); + org.w3c.dom.Node newNode; + switch (node.getNodeType()) { + case org.w3c.dom.Node.ELEMENT_NODE: + Element oldElement = (Element) node; + newNode = doc.createElementNS(newNamespace, oldElement.getTagName()); + NamedNodeMap attrs = oldElement.getAttributes(); + int alength = attrs.getLength(); + for (int j = 0; j < alength; j++) { + org.w3c.dom.Attr oldAttr = (org.w3c.dom.Attr) attrs.item(j); + ((Element)newNode).setAttributeNS(oldAttr.getNamespaceURI(), oldAttr.getName(), oldAttr.getValue()); + } + copyXMLTree(doc, oldElement, (Element) newNode, newNamespace); + break; + case org.w3c.dom.Node.TEXT_NODE: + newNode = doc.createTextNode(((Text) node).getData()); + break; + case org.w3c.dom.Node.COMMENT_NODE: + newNode = doc.createComment(((Comment) node).getData()); + break; + default: + // Other types (e.g. CDATA) not yet handled. + throw new AssertionError(node); + } + to.appendChild(newNode); + } + } + + + + private static final class ProjectLookup extends ProxyLookup implements AntProjectListener { + + private AntProjectHelper helper; + private PropertyEvaluator evaluator; + private Project project; + private AuxiliaryConfiguration aux; + private boolean isMyProject; + + public ProjectLookup(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux) { + super(new Lookup[0]); + this.project = project; + this.helper = helper; + this.evaluator = evaluator; + this.aux = new UpgradingAuxiliaryConfiguration(aux); + this.isMyProject = isMyProject(aux); + updateLookup(); + helper.addAntProjectListener(this); + } + + private void updateLookup() { + Lookup l = Lookup.EMPTY; + if (isMyProject) { + l = initLookup(project, helper, evaluator, aux); + } + setLookups(new Lookup[]{l}); + } + + public void configurationXmlChanged(AntProjectEvent ev) { + if (isMyProject(aux) != isMyProject) { + isMyProject = !isMyProject; + updateLookup(); + } + } + + public void propertiesChanged(AntProjectEvent ev) { + // ignore + } + + } + private static final class PrivilegedTemplatesImpl implements PrivilegedTemplates, RecommendedTemplates { + + private static final String[] PRIVILEGED_NAMES = new String[] { + "Templates/Classes/Class.java", // NOI18N + "Templates/Classes/Package", // NOI18N + "Templates/Classes/Interface.java", // NOI18N + }; + + // List of primarily supported templates = J2SEProject.LIBRARY_TYPES + J2SEProject.APPLICATION_TYPES + private static final String[] RECOMENDED_TYPES = new String[] { + "java-classes", // NOI18N + "java-main-class", // NOI18N + "java-forms", // NOI18N + "gui-java-application", // NOI18N + "java-beans", // NOI18N + "oasis-XML-catalogs", // NOI18N + "XML", // NOI18N + "ant-script", // NOI18N + "ant-task", // NOI18N + "servlet-types", // NOI18N + "wsdl", // NOI18N + "junit", // NOI18N + // "MIDP", // NOI18N + "simple-files" // NOI18N + }; + + public String[] getRecommendedTypes() { + return RECOMENDED_TYPES; + } + + public String[] getPrivilegedTemplates() { + return PRIVILEGED_NAMES; + } + + } +} Index: java/freeform/src/org/netbeans/modules/java/freeform/resources/layer.xml =================================================================== RCS file: /cvs/java/freeform/src/org/netbeans/modules/java/freeform/resources/layer.xml,v retrieving revision 1.4 diff -u -r1.4 layer.xml --- java/freeform/src/org/netbeans/modules/java/freeform/resources/layer.xml 30 Jun 2006 20:07:25 -0000 1.4 +++ java/freeform/src/org/netbeans/modules/java/freeform/resources/layer.xml 8 Feb 2007 07:23:26 -0000 @@ -36,4 +36,19 @@ + + + + + + + + + + + + + + + Index: java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathCategoryProvider.java =================================================================== RCS file: java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathCategoryProvider.java diff -N java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathCategoryProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathCategoryProvider.java 8 Feb 2007 07:23:26 -0000 @@ -0,0 +1,97 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.java.freeform.ui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import javax.swing.JComponent; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import org.netbeans.api.java.platform.JavaPlatform; +import org.netbeans.api.project.Project; +import org.netbeans.modules.ant.freeform.spi.ProjectAccessor; +import org.netbeans.modules.java.freeform.LookupProviderImpl; +import org.netbeans.modules.java.freeform.jdkselection.JdkConfiguration; +import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.ui.support.ProjectCustomizer; +import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; +import org.openide.ErrorManager; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; + +/** + * + * @author mkleint + */ +public class ClasspathCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider { + + /** Creates a new instance of ClasspathCategoryProvider */ + public ClasspathCategoryProvider() { + } + + public Category createCategory(Lookup context) { + AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class); + assert aux != null; + if (LookupProviderImpl.isMyProject(aux)) { + Category cat = ProjectCustomizer.Category.create("classpath", //NOI18N + NbBundle.getMessage(ClasspathPanel.class, "LBL_ProjectCustomizer_Category_Classpath"), null, null); + return cat; + } + return null; + } + + public JComponent createComponent(Category category, Lookup context) { + Project project = (Project)context.lookup(Project.class); + ProjectAccessor acc = (ProjectAccessor)context.lookup(ProjectAccessor.class); + AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class); + assert aux != null; + assert acc != null; + assert project != null; + + final JdkConfiguration jdkConf = new JdkConfiguration(project, acc.getHelper(), acc.getEvaluator()); + + final ClasspathPanel panel = new ClasspathPanel(jdkConf); + final JavaPlatform initialPlatform = (JavaPlatform) panel.javaPlatform.getSelectedItem(); + ProjectModel pm = context.lookup(ProjectModel.class); + assert pm != null; + panel.setModel(pm); + pm.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent arg0) { + panel.updateControls(); + } + }); + category.setOkButtonListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + JavaPlatform p = (JavaPlatform) panel.javaPlatform.getSelectedItem(); + if (p != initialPlatform) { + try { + jdkConf.setSelectedPlatform(p); + } catch (IOException x) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, x); + } + } + } + }); + return panel; + + } + +} Index: java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.form =================================================================== RCS file: /cvs/java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.form,v retrieving revision 1.5 diff -u -r1.5 ClasspathPanel.form --- java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.form 12 Oct 2006 23:03:31 -0000 1.5 +++ java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.form 8 Feb 2007 07:23:26 -0000 @@ -287,6 +287,9 @@ + + + Index: java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.java =================================================================== RCS file: /cvs/java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.java,v retrieving revision 1.11 diff -u -r1.11 ClasspathPanel.java --- java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.java 12 Oct 2006 23:03:32 -0000 1.11 +++ java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.java 8 Feb 2007 07:23:26 -0000 @@ -22,7 +22,6 @@ import java.awt.Component; import java.awt.event.ItemEvent; import java.io.File; -import java.io.IOException; import java.net.MalformedURLException; import java.text.Collator; import java.util.ArrayList; @@ -36,21 +35,15 @@ import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListModel; -import javax.swing.JComponent; import javax.swing.JFileChooser; import javax.swing.JList; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; import javax.swing.filechooser.FileFilter; import org.netbeans.api.java.platform.JavaPlatform; import org.netbeans.api.java.platform.JavaPlatformManager; import org.netbeans.api.java.platform.PlatformsCustomizer; -import org.netbeans.api.project.Project; -import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel; import org.netbeans.modules.ant.freeform.spi.support.Util; import org.netbeans.modules.java.freeform.JavaProjectGenerator; import org.netbeans.modules.java.freeform.jdkselection.JdkConfiguration; -import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.PropertyUtils; import org.openide.ErrorManager; @@ -83,7 +76,7 @@ /** * Create new panel in project properties mode. */ - private ClasspathPanel(JdkConfiguration jdkConf) { + ClasspathPanel(JdkConfiguration jdkConf) { this.jdkConf = jdkConf; basicInit(); jTextArea1.setText(NbBundle.getMessage(ClasspathPanel.class, "LBL_ClasspathPanel_Explanation")); @@ -130,7 +123,7 @@ return new HelpCtx( ClasspathPanel.class ); } - private void updateControls() { + void updateControls() { sourceFolder.removeAllItems(); compUnitsKeys = model.createCompilationUnitKeys(); isSeparateClasspath = !ProjectModel.isSingleCompilationUnit(compUnitsKeys); @@ -666,55 +659,6 @@ } } - public static class Panel implements ProjectPropertiesPanel, ChangeListener { - - private ClasspathPanel panel; - private ProjectModel model; - private final JdkConfiguration jdkConf; - private JavaPlatform initialPlatform; - - public Panel(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, ProjectModel model) { - jdkConf = new JdkConfiguration(project, helper, evaluator); - this.model = model; - } - - public void storeValues() { - if (panel != null) { - JavaPlatform p = (JavaPlatform) panel.javaPlatform.getSelectedItem(); - if (p != initialPlatform) { - try { - jdkConf.setSelectedPlatform(p); - } catch (IOException x) { - ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, x); - } - } - } - } - - public String getDisplayName() { - return NbBundle.getMessage(ClasspathPanel.class, "LBL_ProjectCustomizer_Category_Classpath"); - } - - public JComponent getComponent() { - if (panel == null) { - panel = new ClasspathPanel(jdkConf); - panel.setModel(model); - model.addChangeListener(this); - initialPlatform = (JavaPlatform) panel.javaPlatform.getSelectedItem(); - } - return panel; - } - - public void stateChanged(ChangeEvent e) { - panel.updateControls(); - } - - public int getPreferredPosition() { - return 200; - } - - } - public void setModel(ProjectModel model) { this.model = model; updateControls(); @@ -728,7 +672,7 @@ private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea jTextArea1; - private javax.swing.JComboBox javaPlatform; + javax.swing.JComboBox javaPlatform; private javax.swing.JButton javaPlatformButton; private javax.swing.JTextArea javaPlatformIntro; private javax.swing.JLabel javaPlatformLabel; Index: java/freeform/src/org/netbeans/modules/java/freeform/ui/OutputCategoryProvider.java =================================================================== RCS file: java/freeform/src/org/netbeans/modules/java/freeform/ui/OutputCategoryProvider.java diff -N java/freeform/src/org/netbeans/modules/java/freeform/ui/OutputCategoryProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ java/freeform/src/org/netbeans/modules/java/freeform/ui/OutputCategoryProvider.java 8 Feb 2007 07:23:26 -0000 @@ -0,0 +1,59 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.java.freeform.ui; + +import javax.swing.JComponent; +import org.netbeans.modules.java.freeform.LookupProviderImpl; +import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.ui.support.ProjectCustomizer; +import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; + +/** + * + * @author mkleint + */ +public class OutputCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider { + + /** Creates a new instance of OutputCategoryProvider */ + public OutputCategoryProvider() { + } + + public Category createCategory(Lookup context) { + AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class); + assert aux != null; + if (LookupProviderImpl.isMyProject(aux)) { + Category cat = ProjectCustomizer.Category.create("Output", //NOI18N + NbBundle.getMessage(ClasspathPanel.class, "LBL_ProjectCustomizer_Category_Output"), null, null); + return cat; + } + return null; + } + + public JComponent createComponent(Category category, Lookup context) { + ProjectModel pm = context.lookup(ProjectModel.class); + assert pm != null; + OutputPanel panel = new OutputPanel(); + panel.setModel(pm); + return panel; + } + +} Index: java/freeform/src/org/netbeans/modules/java/freeform/ui/OutputPanel.java =================================================================== RCS file: /cvs/java/freeform/src/org/netbeans/modules/java/freeform/ui/OutputPanel.java,v retrieving revision 1.11 diff -u -r1.11 OutputPanel.java --- java/freeform/src/org/netbeans/modules/java/freeform/ui/OutputPanel.java 2 Sep 2006 07:49:00 -0000 1.11 +++ java/freeform/src/org/netbeans/modules/java/freeform/ui/OutputPanel.java 8 Feb 2007 07:23:26 -0000 @@ -19,21 +19,16 @@ package org.netbeans.modules.java.freeform.ui; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; import java.awt.event.ItemEvent; import java.io.File; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import javax.swing.DefaultListModel; -import javax.swing.JComponent; import javax.swing.JFileChooser; import javax.swing.ListSelectionModel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; -import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel; import org.netbeans.modules.ant.freeform.spi.support.Util; import org.netbeans.modules.java.freeform.JavaProjectGenerator; import org.openide.filesystems.FileUtil; @@ -509,44 +504,14 @@ } } - public static class Panel implements ProjectPropertiesPanel, ChangeListener { - - private OutputPanel panel; - private ProjectModel model; - - public Panel(ProjectModel model) { - this.model = model; - } - - public void storeValues() { - } - - public String getDisplayName() { - return NbBundle.getMessage(ClasspathPanel.class, "LBL_ProjectCustomizer_Category_Output"); - } - - public JComponent getComponent() { - if (panel == null) { - panel = new OutputPanel(); - panel.setModel(model); - model.addChangeListener(this); - } - return panel; - } - - public void stateChanged(ChangeEvent e) { - panel.updateControls(); - } - - public int getPreferredPosition() { - return 300; - } - - } - - private void setModel(ProjectModel model) { + void setModel(ProjectModel model) { this.model = model; updateControls(); + model.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent arg0) { + updateControls(); + } + }); } Index: java/freeform/src/org/netbeans/modules/java/freeform/ui/SourceFoldersCategoryProvider.java =================================================================== RCS file: java/freeform/src/org/netbeans/modules/java/freeform/ui/SourceFoldersCategoryProvider.java diff -N java/freeform/src/org/netbeans/modules/java/freeform/ui/SourceFoldersCategoryProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ java/freeform/src/org/netbeans/modules/java/freeform/ui/SourceFoldersCategoryProvider.java 8 Feb 2007 07:23:26 -0000 @@ -0,0 +1,83 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.java.freeform.ui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JComponent; +import org.netbeans.api.project.Project; +import org.netbeans.modules.ant.freeform.spi.ProjectAccessor; +import org.netbeans.modules.ant.freeform.spi.support.Util; +import org.netbeans.modules.java.freeform.LookupProviderImpl; +import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.ui.support.ProjectCustomizer; +import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; +import org.openide.filesystems.FileUtil; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; +import org.openide.util.lookup.InstanceContent; + +/** + * + * @author mkleint + */ +public class SourceFoldersCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider { + + /** Creates a new instance of SouceFoldersCustomizerProvider */ + public SourceFoldersCategoryProvider() { + } + + public Category createCategory(Lookup context) { + AuxiliaryConfiguration aux = context.lookup(AuxiliaryConfiguration.class); + final ProjectAccessor acc = context.lookup(ProjectAccessor.class); + Project project = context.lookup(Project.class); + assert aux != null; + assert acc != null; + assert project != null; + if (LookupProviderImpl.isMyProject(aux)) { + Category cat = ProjectCustomizer.Category.create("SourceFolders", //NOI18N + NbBundle.getMessage(ClasspathPanel.class, "LBL_ProjectCustomizer_Category_Sources"), null, null); + final ProjectModel pm = ProjectModel.createModel(Util.getProjectLocation(acc.getHelper(), acc.getEvaluator()), + FileUtil.toFile(project.getProjectDirectory()), acc.getEvaluator(), acc.getHelper()); + InstanceContent ic = context.lookup(InstanceContent.class); + assert ic != null; + ic.add(pm); + cat.setOkButtonListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + // store changes always because model could be modified in ClasspathPanel or OutputPanel + ProjectModel.saveProject(acc.getHelper(), pm); + } + }); + return cat; + } + return null; + } + + public JComponent createComponent(Category category, Lookup context) { + ProjectModel pm = context.lookup(ProjectModel.class); + ProjectAccessor acc = context.lookup(ProjectAccessor.class); + assert pm != null; + SourceFoldersPanel panel = new SourceFoldersPanel(false); + panel.setModel(pm, acc.getHelper()); + return panel; + + } + +} Index: java/freeform/src/org/netbeans/modules/java/freeform/ui/SourceFoldersPanel.java =================================================================== RCS file: /cvs/java/freeform/src/org/netbeans/modules/java/freeform/ui/SourceFoldersPanel.java,v retrieving revision 1.21 diff -u -r1.21 SourceFoldersPanel.java --- java/freeform/src/org/netbeans/modules/java/freeform/ui/SourceFoldersPanel.java 8 Jan 2007 14:33:58 -0000 1.21 +++ java/freeform/src/org/netbeans/modules/java/freeform/ui/SourceFoldersPanel.java 8 Feb 2007 07:23:26 -0000 @@ -48,7 +48,6 @@ import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.queries.CollocationQuery; import org.netbeans.modules.ant.freeform.spi.ProjectConstants; -import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel; import org.netbeans.modules.ant.freeform.spi.support.Util; import org.netbeans.modules.java.freeform.JavaProjectGenerator; import org.netbeans.modules.java.freeform.JavaProjectNature; @@ -757,41 +756,6 @@ public boolean hasSomeSourceFolder() { return model.getSourceFoldersCount() > 0; - } - - public static class Panel implements ProjectPropertiesPanel { - - private SourceFoldersPanel panel; - private ProjectModel model; - private AntProjectHelper projectHelper; - - public Panel(ProjectModel model, AntProjectHelper projectHelper) { - this.model = model; - this.projectHelper = projectHelper; - } - - /* ProjectCustomizer.Panel save */ - public void storeValues() { - // store changes always because model could be modified in ClasspathPanel or OutputPanel - ProjectModel.saveProject(projectHelper, model); - } - - public String getDisplayName() { - return NbBundle.getMessage(ClasspathPanel.class, "LBL_ProjectCustomizer_Category_Sources"); - } - - public JComponent getComponent() { - if (panel == null) { - panel = new SourceFoldersPanel(false); - panel.setModel(model, projectHelper); - } - return panel; - } - - public int getPreferredPosition() { - return 100; - } - } // Variables declaration - do not modify//GEN-BEGIN:variables Index: web/freeform/nbproject/project.xml =================================================================== RCS file: /cvs/web/freeform/nbproject/project.xml,v retrieving revision 1.14 diff -u -r1.14 project.xml --- web/freeform/nbproject/project.xml 8 Aug 2006 22:46:43 -0000 1.14 +++ web/freeform/nbproject/project.xml 8 Feb 2007 07:23:26 -0000 @@ -24,29 +24,27 @@ org.netbeans.modules.web.freeform - org.netbeans.modules.ant.freeform + org.netbeans.api.java 1 - 1.8 + 1.5 - org.netbeans.api.java + org.netbeans.api.web.webmodule - - 1 - 1.5 - + - org.netbeans.modules.java.project + org.netbeans.modules.ant.freeform 1 + 1.14 @@ -59,7 +57,7 @@ - org.netbeans.modules.project.ant + org.netbeans.modules.java.project @@ -67,7 +65,7 @@ - org.netbeans.modules.queries + org.netbeans.modules.project.ant @@ -83,23 +81,23 @@ - org.openide.filesystems + org.netbeans.modules.projectuiapi - 6.2 + 1 - org.openide.util + org.netbeans.modules.queries - 6.2 + 1 - org.openide.nodes + org.openide.awt @@ -107,7 +105,7 @@ - org.openide.awt + org.openide.dialogs @@ -115,7 +113,7 @@ - org.openide.dialogs + org.openide.filesystems @@ -123,73 +121,75 @@ - org.openide.text + org.openide.loaders - - 6.2 - + - org.netbeans.api.web.webmodule + org.openide.nodes - + + 6.2 + - org.netbeans.modules.projectuiapi + org.openide.text - 1 + 6.2 - org.openide.loaders + org.openide.util - + + 6.2 + - - - unit - - org.netbeans.modules.web.freeform - - - - - org.openidex.util - - - org.apache.tools.ant.module - - - org.openide.io - - - org.openide.compat - - - org.netbeans.core - - - org.netbeans.swing.plaf - - - org.netbeans.modules.projectui - - - org.netbeans.modules.masterfs - - - org.openide.modules - - - - qa-functional - + + + unit + + org.netbeans.modules.web.freeform + + + + + org.openidex.util + + + org.apache.tools.ant.module + + + org.openide.io + + + org.openide.compat + + + org.netbeans.core + + + org.netbeans.swing.plaf + + + org.netbeans.modules.projectui + + + org.netbeans.modules.masterfs + + + org.openide.modules + + + + qa-functional + Index: web/freeform/src/org/netbeans/modules/web/freeform/LookupProviderImpl.java =================================================================== RCS file: web/freeform/src/org/netbeans/modules/web/freeform/LookupProviderImpl.java diff -N web/freeform/src/org/netbeans/modules/web/freeform/LookupProviderImpl.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ web/freeform/src/org/netbeans/modules/web/freeform/LookupProviderImpl.java 8 Feb 2007 07:23:26 -0000 @@ -0,0 +1,281 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + +package org.netbeans.modules.web.freeform; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import org.netbeans.api.java.classpath.ClassPath; +import org.netbeans.api.java.classpath.GlobalPathRegistry; +import org.netbeans.api.project.Project; +import org.netbeans.modules.ant.freeform.spi.HelpIDFragmentProvider; +import org.netbeans.modules.ant.freeform.spi.ProjectAccessor; +import org.netbeans.modules.ant.freeform.spi.support.Util; +import org.netbeans.spi.java.classpath.ClassPathImplementation; +import org.netbeans.spi.java.classpath.support.ClassPathSupport; +import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.LookupProvider; +import org.netbeans.spi.project.support.ant.AntProjectEvent; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.AntProjectListener; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.netbeans.spi.project.ui.PrivilegedTemplates; +import org.netbeans.spi.project.ui.ProjectOpenedHook; +import org.netbeans.spi.project.ui.RecommendedTemplates; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; +import org.w3c.dom.Element; + +/** + * + * @author mkleint + */ +public class LookupProviderImpl implements LookupProvider { + + private static final String HELP_ID_FRAGMENT = "web"; // NOI18N + + /** Creates a new instance of LookupProviderImpl */ + public LookupProviderImpl() { + } + + public Lookup createAdditionalLookup(Lookup baseContext) { + Project prj = (Project)baseContext.lookup(Project.class); + ProjectAccessor acc = (ProjectAccessor)baseContext.lookup(ProjectAccessor.class); + AuxiliaryConfiguration aux = (AuxiliaryConfiguration)baseContext.lookup(AuxiliaryConfiguration.class); + assert aux != null; + assert prj != null; + assert acc != null; + return new ProjectLookup(prj, acc.getHelper(), acc.getEvaluator(), aux); + } + + private static Lookup initLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { + WebClasspath webcp = new WebClasspath(projectHelper, projectEvaluator, aux, project); + return Lookups.fixed(new Object[] { + new ProjectOpenedHookImpl(webcp), // register webroots as source classpath + new PrivilegedTemplatesImpl(), // List of templates in New action popup + new WebModules(project, projectHelper, projectEvaluator), // WebModuleProvider, ClassPathProvider + new WebFreeFormActionProvider(project, projectHelper, aux), //ActionProvider + new HelpIDFragmentProviderImpl(), + }); + } + + public static boolean isMyProject(AuxiliaryConfiguration aux) { + return aux.getConfigurationFragment("web-data", WebProjectNature.NS_WEB, true) != null; // NOI18N + } + + private static final class HelpIDFragmentProviderImpl implements HelpIDFragmentProvider { + public String getHelpIDFragment() { + return HELP_ID_FRAGMENT; + } + } + + private static class ProjectOpenedHookImpl extends ProjectOpenedHook { + private final WebClasspath webcp; + public ProjectOpenedHookImpl(WebClasspath wcp) { + this.webcp = wcp; + } + protected void projectOpened() { + webcp.prjOpened(); + } + protected void projectClosed() { + webcp.prjClosed(); + } + } + + public static final class WebClasspath implements AntProjectListener, PropertyChangeListener { + + private ClassPath registeredCP[] = new ClassPath[0]; + private List/**/ registeredRoots = Collections.EMPTY_LIST; + + private PropertyEvaluator evaluator; + private AuxiliaryConfiguration aux; + private Project project; + + private PropertyChangeSupport pcs; + + private boolean prjClosed = false; + + public WebClasspath(AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux, Project proj) { + this.evaluator = evaluator; + this.aux = aux; + this.project = proj; + helper.addAntProjectListener(this); + evaluator.addPropertyChangeListener(this); + pcs = new PropertyChangeSupport(this); + } + + public void prjOpened() { + registeredRoots = getWebRoots(aux, project, evaluator); + FileObject fos[] = new FileObject[registeredRoots.size()]; + ClassPath cp = ClassPathSupport.createClassPath((FileObject[]) registeredRoots.toArray(fos)); + registeredCP = new ClassPath[] { cp }; + GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, registeredCP); + prjClosed = false; + } + + public void prjClosed() { + if (!registeredRoots.isEmpty()) { + GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, registeredCP); + } + registeredRoots = Collections.EMPTY_LIST; + prjClosed = true; + } + + public void configurationXmlChanged(AntProjectEvent ev) { + updateClasspath(); + } + + public void propertiesChanged(AntProjectEvent ev) { + // ignore + } + + public void propertyChange(PropertyChangeEvent ev) { + updateClasspath(); + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + pcs.addPropertyChangeListener(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + pcs.removePropertyChangeListener(listener); + } + + private synchronized void updateClasspath() { + if (!prjClosed) { + List newRoots = getWebRoots(aux, project, evaluator); + if (!newRoots.equals(registeredRoots)) { + FileObject fos[] = new FileObject[newRoots.size()]; + ClassPath cp = ClassPathSupport.createClassPath((FileObject[]) newRoots.toArray(fos)); + GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, registeredCP); + registeredCP = new ClassPath[] { cp }; + registeredRoots = newRoots; + GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, registeredCP); + pcs.firePropertyChange(ClassPathImplementation.PROP_RESOURCES, null, null); + } + } + } + + private List/**/ getWebRoots(AuxiliaryConfiguration aux, Project proj, PropertyEvaluator evaluator) { + Element web = aux.getConfigurationFragment("web-data", WebProjectNature.NS_WEB, true); // NOI18N + if (web == null) { + return null; + } + List webModules = Util.findSubElements(web); + Iterator it = webModules.iterator(); + List/**/ roots = new ArrayList(); + while (it.hasNext()) { + Element webModulesEl = (Element) it.next(); + assert webModulesEl.getLocalName().equals("web-module") : webModulesEl; // NOI18N + roots.add(FileUtil.toFileObject(getFile(webModulesEl, "doc-root", proj, evaluator))); // NOI18N + } + return roots; + } + + private File getFile(Element parent, String fileElName, Project proj, PropertyEvaluator evaluator) { + Element el = Util.findElement(parent, fileElName, WebProjectNature.NS_WEB); + return Util.resolveFile(evaluator, FileUtil.toFile(proj.getProjectDirectory()), Util.findText(el)); + } + + } + + private static final class ProjectLookup extends ProxyLookup implements AntProjectListener { + + private AntProjectHelper helper; + private PropertyEvaluator evaluator; + private Project project; + private AuxiliaryConfiguration aux; + private boolean isMyProject; + + public ProjectLookup(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux) { + super(new Lookup[0]); + this.project = project; + this.helper = helper; + this.evaluator = evaluator; + this.aux = aux; + this.isMyProject = isMyProject(aux); + updateLookup(); + helper.addAntProjectListener(this); + } + + private void updateLookup() { + Lookup l = Lookup.EMPTY; + if (isMyProject) { + l = initLookup(project, helper, evaluator, aux); + } + setLookups(new Lookup[]{l}); + } + + public void configurationXmlChanged(AntProjectEvent ev) { + if (isMyProject(aux) != isMyProject) { + isMyProject = !isMyProject; + updateLookup(); + } + } + + public void propertiesChanged(AntProjectEvent ev) { + // ignore + } + + } + + private static final class PrivilegedTemplatesImpl implements PrivilegedTemplates, RecommendedTemplates { + + private static final String[] PRIVILEGED_NAMES = new String[] { + "Templates/JSP_Servlet/JSP.jsp", + "Templates/JSP_Servlet/Html.html", + "Templates/JSP_Servlet/Servlet.java", + "Templates/Classes/Class.java", + }; + + private static final String[] RECOMENDED_TYPES = new String[] { + "java-classes", // NOI18N + "java-main-class", // NOI18N + "java-beans", // NOI18N + "oasis-XML-catalogs", // NOI18N + "XML", // NOI18N + "wsdl", // NOI18N + "ant-script", // NOI18N + "ant-task", // NOI18N + "servlet-types", // NOI18N + "web-types", // NOI18N + "j2ee-types", // NOI18N + "junit", // NOI18N + "simple-files" // NOI18N + }; + + public String[] getPrivilegedTemplates() { + return PRIVILEGED_NAMES; + } + + public String[] getRecommendedTypes() { + return RECOMENDED_TYPES; + } + } +} Index: web/freeform/src/org/netbeans/modules/web/freeform/WebProjectNature.java =================================================================== RCS file: /cvs/web/freeform/src/org/netbeans/modules/web/freeform/WebProjectNature.java,v retrieving revision 1.15 diff -u -r1.15 WebProjectNature.java --- web/freeform/src/org/netbeans/modules/web/freeform/WebProjectNature.java 12 Oct 2006 14:31:38 -0000 1.15 +++ web/freeform/src/org/netbeans/modules/web/freeform/WebProjectNature.java 8 Feb 2007 07:23:26 -0000 @@ -18,48 +18,21 @@ */ package org.netbeans.modules.web.freeform; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.File; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; -import java.util.WeakHashMap; -import org.netbeans.api.java.classpath.ClassPath; -import org.netbeans.api.java.classpath.GlobalPathRegistry; import org.netbeans.api.project.Project; -import org.netbeans.modules.ant.freeform.spi.HelpIDFragmentProvider; import org.netbeans.modules.ant.freeform.spi.ProjectNature; -import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel; import org.netbeans.modules.ant.freeform.spi.TargetDescriptor; -import org.netbeans.modules.ant.freeform.spi.support.Util; import org.netbeans.modules.web.api.webmodule.WebProjectConstants; -import org.netbeans.modules.web.freeform.ui.WebClasspathPanel; -import org.netbeans.modules.web.freeform.ui.WebLocationsPanel; -import org.netbeans.spi.java.classpath.ClassPathImplementation; -import org.netbeans.spi.java.classpath.support.ClassPathSupport; import org.netbeans.spi.project.AuxiliaryConfiguration; -import org.netbeans.spi.project.support.ant.AntProjectEvent; import org.netbeans.spi.project.support.ant.AntProjectHelper; -import org.netbeans.spi.project.support.ant.AntProjectListener; import org.netbeans.spi.project.support.ant.PropertyEvaluator; -import org.netbeans.spi.project.ui.PrivilegedTemplates; -import org.netbeans.spi.project.ui.ProjectOpenedHook; -import org.netbeans.spi.project.ui.RecommendedTemplates; import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; import org.openide.nodes.Node; -import org.openide.util.Lookup; import org.openide.util.NbBundle; -import org.openide.util.lookup.Lookups; -import org.openide.util.lookup.ProxyLookup; -import org.w3c.dom.Element; /** * @author David Konecny @@ -69,36 +42,12 @@ public static final String NS_WEB = "http://www.netbeans.org/ns/freeform-project-web/1"; // NOI18N private static final String SCHEMA = "nbres:/org/netbeans/modules/web/freeform/resources/freeform-project-web.xsd"; // NOI18N - private static final String HELP_ID_FRAGMENT = "web"; // NOI18N - - private static final WeakHashMap/*>*/ lookupCache = new WeakHashMap(); - + public WebProjectNature() {} - - public Lookup getLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { - WeakReference wr = (WeakReference)lookupCache.get(project); - Lookup lookup = wr != null ? (Lookup)wr.get() : null; - if (lookup == null) { - lookup = new ProjectLookup(project, projectHelper, projectEvaluator, aux); - lookupCache.put(project, new WeakReference(lookup)); - } - return lookup; - } - - public Set getCustomizerPanels(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { - HashSet l = new HashSet(); - if (!isMyProject(aux)) { - return l; - } - ProjectPropertiesPanel web = new WebLocationsPanel.Panel(projectHelper, projectEvaluator, aux); - l.add(web); - l.add(new WebClasspathPanel.Panel(projectHelper, projectEvaluator, aux)); - return l; - } public List getExtraTargets(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { ArrayList l = new ArrayList(); - if (!isMyProject(aux)) { + if (!LookupProviderImpl.isMyProject(aux)) { return l; } l.add(getExtraTarget()); @@ -121,9 +70,7 @@ return null; } - private static boolean isMyProject(AuxiliaryConfiguration aux) { - return aux.getConfigurationFragment("web-data", NS_WEB, true) != null; // NOI18N - } + public static TargetDescriptor getExtraTarget() { return new TargetDescriptor(WebProjectConstants.COMMAND_REDEPLOY, Arrays.asList(new String[]{"deploy", ".*deploy.*"}), // NOI18N @@ -131,204 +78,5 @@ NbBundle.getMessage(WebProjectNature.class, "ACSD_TargetMappingPanel_Deploy")); // NOI18N } - private static Lookup initLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { - WebClasspath webcp = new WebClasspath(projectHelper, projectEvaluator, aux, project); - return Lookups.fixed(new Object[] { - new ProjectOpenedHookImpl(webcp), // register webroots as source classpath - new PrivilegedTemplatesImpl(), // List of templates in New action popup - new WebModules(project, projectHelper, projectEvaluator), // WebModuleProvider, ClassPathProvider - new WebFreeFormActionProvider(project, projectHelper, aux), //ActionProvider - new HelpIDFragmentProviderImpl(), - }); - } - - private static final class HelpIDFragmentProviderImpl implements HelpIDFragmentProvider { - public String getHelpIDFragment() { - return HELP_ID_FRAGMENT; - } - } - - private static class ProjectOpenedHookImpl extends ProjectOpenedHook { - private final WebClasspath webcp; - public ProjectOpenedHookImpl(WebClasspath wcp) { - this.webcp = wcp; - } - protected void projectOpened() { - webcp.prjOpened(); - } - protected void projectClosed() { - webcp.prjClosed(); - } - } - - public static final class WebClasspath implements AntProjectListener, PropertyChangeListener { - - private ClassPath registeredCP[] = new ClassPath[0]; - private List/**/ registeredRoots = Collections.EMPTY_LIST; - - private PropertyEvaluator evaluator; - private AuxiliaryConfiguration aux; - private Project project; - - private PropertyChangeSupport pcs; - - private boolean prjClosed = false; - - public WebClasspath(AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux, Project proj) { - this.evaluator = evaluator; - this.aux = aux; - this.project = proj; - helper.addAntProjectListener(this); - evaluator.addPropertyChangeListener(this); - pcs = new PropertyChangeSupport(this); - } - - public void prjOpened() { - registeredRoots = getWebRoots(aux, project, evaluator); - FileObject fos[] = new FileObject[registeredRoots.size()]; - ClassPath cp = ClassPathSupport.createClassPath((FileObject[]) registeredRoots.toArray(fos)); - registeredCP = new ClassPath[] { cp }; - GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, registeredCP); - prjClosed = false; - } - - public void prjClosed() { - if (!registeredRoots.isEmpty()) { - GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, registeredCP); - } - registeredRoots = Collections.EMPTY_LIST; - prjClosed = true; - } - - public void configurationXmlChanged(AntProjectEvent ev) { - updateClasspath(); - } - - public void propertiesChanged(AntProjectEvent ev) { - // ignore - } - - public void propertyChange(PropertyChangeEvent ev) { - updateClasspath(); - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - private synchronized void updateClasspath() { - if (!prjClosed) { - List newRoots = getWebRoots(aux, project, evaluator); - if (!newRoots.equals(registeredRoots)) { - FileObject fos[] = new FileObject[newRoots.size()]; - ClassPath cp = ClassPathSupport.createClassPath((FileObject[]) newRoots.toArray(fos)); - GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, registeredCP); - registeredCP = new ClassPath[] { cp }; - registeredRoots = newRoots; - GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, registeredCP); - pcs.firePropertyChange(ClassPathImplementation.PROP_RESOURCES, null, null); - } - } - } - - private List/**/ getWebRoots(AuxiliaryConfiguration aux, Project proj, PropertyEvaluator evaluator) { - Element web = aux.getConfigurationFragment("web-data", WebProjectNature.NS_WEB, true); // NOI18N - if (web == null) { - return null; - } - List webModules = Util.findSubElements(web); - Iterator it = webModules.iterator(); - List/**/ roots = new ArrayList(); - while (it.hasNext()) { - Element webModulesEl = (Element) it.next(); - assert webModulesEl.getLocalName().equals("web-module") : webModulesEl; // NOI18N - roots.add(FileUtil.toFileObject(getFile(webModulesEl, "doc-root", proj, evaluator))); // NOI18N - } - return roots; - } - - private File getFile(Element parent, String fileElName, Project proj, PropertyEvaluator evaluator) { - Element el = Util.findElement(parent, fileElName, WebProjectNature.NS_WEB); - return Util.resolveFile(evaluator, FileUtil.toFile(proj.getProjectDirectory()), Util.findText(el)); - } - - } - - private static final class ProjectLookup extends ProxyLookup implements AntProjectListener { - - private AntProjectHelper helper; - private PropertyEvaluator evaluator; - private Project project; - private AuxiliaryConfiguration aux; - private boolean isMyProject; - - public ProjectLookup(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux) { - super(new Lookup[0]); - this.project = project; - this.helper = helper; - this.evaluator = evaluator; - this.aux = aux; - this.isMyProject = isMyProject(aux); - updateLookup(); - helper.addAntProjectListener(this); - } - - private void updateLookup() { - Lookup l = Lookup.EMPTY; - if (isMyProject) { - l = initLookup(project, helper, evaluator, aux); - } - setLookups(new Lookup[]{l}); - } - - public void configurationXmlChanged(AntProjectEvent ev) { - if (isMyProject(aux) != isMyProject) { - isMyProject = !isMyProject; - updateLookup(); - } - } - - public void propertiesChanged(AntProjectEvent ev) { - // ignore - } - - } - - private static final class PrivilegedTemplatesImpl implements PrivilegedTemplates, RecommendedTemplates { - - private static final String[] PRIVILEGED_NAMES = new String[] { - "Templates/JSP_Servlet/JSP.jsp", - "Templates/JSP_Servlet/Html.html", - "Templates/JSP_Servlet/Servlet.java", - "Templates/Classes/Class.java", - }; - - private static final String[] RECOMENDED_TYPES = new String[] { - "java-classes", // NOI18N - "java-main-class", // NOI18N - "java-beans", // NOI18N - "oasis-XML-catalogs", // NOI18N - "XML", // NOI18N - "wsdl", // NOI18N - "ant-script", // NOI18N - "ant-task", // NOI18N - "servlet-types", // NOI18N - "web-types", // NOI18N - "j2ee-types", // NOI18N - "junit", // NOI18N - "simple-files" // NOI18N - }; - - public String[] getPrivilegedTemplates() { - return PRIVILEGED_NAMES; - } - - public String[] getRecommendedTypes() { - return RECOMENDED_TYPES; - } - } + } Index: web/freeform/src/org/netbeans/modules/web/freeform/resources/layer.xml =================================================================== RCS file: /cvs/web/freeform/src/org/netbeans/modules/web/freeform/resources/layer.xml,v retrieving revision 1.4 diff -u -r1.4 layer.xml --- web/freeform/src/org/netbeans/modules/web/freeform/resources/layer.xml 30 Jun 2006 22:34:21 -0000 1.4 +++ web/freeform/src/org/netbeans/modules/web/freeform/resources/layer.xml 8 Feb 2007 07:23:26 -0000 @@ -35,4 +35,21 @@ + + + + + + + + + + + + + + + + + Index: web/freeform/src/org/netbeans/modules/web/freeform/ui/WebClasspathCategoryProvider.java =================================================================== RCS file: web/freeform/src/org/netbeans/modules/web/freeform/ui/WebClasspathCategoryProvider.java diff -N web/freeform/src/org/netbeans/modules/web/freeform/ui/WebClasspathCategoryProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ web/freeform/src/org/netbeans/modules/web/freeform/ui/WebClasspathCategoryProvider.java 8 Feb 2007 07:23:26 -0000 @@ -0,0 +1,79 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.web.freeform.ui; + +import java.util.List; +import javax.swing.JComponent; +import org.netbeans.api.project.Project; +import org.netbeans.modules.ant.freeform.spi.ProjectAccessor; +import org.netbeans.modules.ant.freeform.spi.support.Util; +import org.netbeans.modules.web.freeform.LookupProviderImpl; +import org.netbeans.modules.web.freeform.WebProjectGenerator; +import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.ui.support.ProjectCustomizer; +import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; +import org.openide.filesystems.FileUtil; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; + +/** + * + * @author mkleint + */ +public class WebClasspathCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider { + + /** Creates a new instance of EjbLocationsCategoryProvider */ + public WebClasspathCategoryProvider() { + } + + public Category createCategory(Lookup context) { + AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class); + assert aux != null; + if (LookupProviderImpl.isMyProject(aux)) { + Category cat = ProjectCustomizer.Category.create("WebClasspath", //NOI18N + NbBundle.getMessage(WebClasspathPanel.class, "LBL_ProjectCustomizer_Category_Classpath"), null, null); + return cat; + } + return null; + } + + public JComponent createComponent(Category category, Lookup context) { + Project project = (Project)context.lookup(Project.class); + ProjectAccessor acc = (ProjectAccessor)context.lookup(ProjectAccessor.class); + AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class); + assert aux != null; + assert acc != null; + assert project != null; + + WebClasspathPanel panel = new WebClasspathPanel(false); + List l = WebProjectGenerator.getWebmodules(acc.getHelper(), aux); + if (l != null){ + WebProjectGenerator.WebModule wm = (WebProjectGenerator.WebModule)l.get(0); + panel.setProjectFolders(Util.getProjectLocation(acc.getHelper(), acc.getEvaluator()), + FileUtil.toFile(acc.getHelper().getProjectDirectory())); + panel.setClasspath(wm.classpath, acc.getEvaluator()); + panel.updateButtons(); + } + + category.setOkButtonListener(panel.getCustomizerOkListener(acc.getHelper())); + return panel; + } + +} Index: web/freeform/src/org/netbeans/modules/web/freeform/ui/WebClasspathPanel.java =================================================================== RCS file: /cvs/web/freeform/src/org/netbeans/modules/web/freeform/ui/WebClasspathPanel.java,v retrieving revision 1.9 diff -u -r1.9 WebClasspathPanel.java --- web/freeform/src/org/netbeans/modules/web/freeform/ui/WebClasspathPanel.java 12 Oct 2006 14:31:38 -0000 1.9 +++ web/freeform/src/org/netbeans/modules/web/freeform/ui/WebClasspathPanel.java 8 Feb 2007 07:23:27 -0000 @@ -19,20 +19,14 @@ package org.netbeans.modules.web.freeform.ui; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.File; import java.net.MalformedURLException; -import java.util.Arrays; -import java.util.Collection; import java.util.List; -import java.util.StringTokenizer; - import javax.swing.DefaultListModel; -import javax.swing.JComponent; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; - -import org.netbeans.api.project.Project; -import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel; import org.netbeans.modules.ant.freeform.spi.support.Util; import org.netbeans.modules.web.freeform.WebProjectGenerator; import org.netbeans.spi.project.AuxiliaryConfiguration; @@ -40,7 +34,6 @@ import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.PropertyUtils; import org.openide.ErrorManager; - import org.openide.filesystems.FileUtil; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; @@ -265,7 +258,7 @@ updateButtons(); }//GEN-LAST:event_moveUpActionPerformed - private void updateButtons() { + void updateButtons() { int indices[] = classpath.getSelectedIndices(); removeClasspath.setEnabled(listModel.getSize() > 0 && indices.length != 0 && indices[0] != 0); moveUp.setEnabled(indices.length > 0 && indices[0] > 1); @@ -340,7 +333,7 @@ return sf.toString(); } - private void setClasspath(String classpath, PropertyEvaluator evaluator){ + void setClasspath(String classpath, PropertyEvaluator evaluator){ if (classpath == null) return; listModel.clear(); @@ -356,57 +349,23 @@ } } - public static class Panel implements ProjectPropertiesPanel{ - - private WebClasspathPanel panel = null; - private AntProjectHelper projectHelper; - private PropertyEvaluator projectEvaluator; - private AuxiliaryConfiguration aux; - - - public Panel(AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { - this.projectHelper = projectHelper; - this.projectEvaluator = projectEvaluator; - this.aux = aux; - } - - public void storeValues() { - if (panel == null) { - return; - } - AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(projectHelper); - List l = WebProjectGenerator.getWebmodules(projectHelper, aux); - if (l != null){ - WebProjectGenerator.WebModule wm = (WebProjectGenerator.WebModule)l.get(0); - wm.classpath = panel.getClasspath(); - WebProjectGenerator.putWebModules(projectHelper, aux, l); - } - panel.updateButtons(); - } - - public String getDisplayName() { - return NbBundle.getMessage(WebClasspathPanel.class, "LBL_ProjectCustomizer_Category_Classpath"); - } - - public JComponent getComponent() { - if (panel == null) { - panel = new WebClasspathPanel(false); + ActionListener getCustomizerOkListener(final AntProjectHelper projectHelper) { + return new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(projectHelper); List l = WebProjectGenerator.getWebmodules(projectHelper, aux); if (l != null){ WebProjectGenerator.WebModule wm = (WebProjectGenerator.WebModule)l.get(0); - panel.setProjectFolders(Util.getProjectLocation(projectHelper, projectEvaluator), - FileUtil.toFile(projectHelper.getProjectDirectory())); - panel.setClasspath(wm.classpath, projectEvaluator); - panel.updateButtons(); + wm.classpath = getClasspath(); + WebProjectGenerator.putWebModules(projectHelper, aux, l); } + //mkleint: why updating buttons on saving?? + updateButtons(); } - return panel; - } - - public int getPreferredPosition() { - return 250; // after Java Sources Classpath, before Output panel - } + }; } + + // Variables declaration - do not modify//GEN-BEGIN:variables Index: web/freeform/src/org/netbeans/modules/web/freeform/ui/WebLocationsCategoryProvider.java =================================================================== RCS file: web/freeform/src/org/netbeans/modules/web/freeform/ui/WebLocationsCategoryProvider.java diff -N web/freeform/src/org/netbeans/modules/web/freeform/ui/WebLocationsCategoryProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ web/freeform/src/org/netbeans/modules/web/freeform/ui/WebLocationsCategoryProvider.java 8 Feb 2007 07:23:27 -0000 @@ -0,0 +1,65 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (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.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.web.freeform.ui; + +import javax.swing.JComponent; +import org.netbeans.api.project.Project; +import org.netbeans.modules.ant.freeform.spi.ProjectAccessor; +import org.netbeans.modules.web.freeform.LookupProviderImpl; +import org.netbeans.spi.project.AuxiliaryConfiguration; +import org.netbeans.spi.project.ui.support.ProjectCustomizer; +import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; + +/** + * + * @author mkleint + */ +public class WebLocationsCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider { + + /** Creates a new instance of EjbLocationsCategoryProvider */ + public WebLocationsCategoryProvider() { + } + + public Category createCategory(Lookup context) { + AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class); + assert aux != null; + if (LookupProviderImpl.isMyProject(aux)) { + Category cat = ProjectCustomizer.Category.create("WebLocations", //NOI18N + NbBundle.getMessage(WebLocationsPanel.class, "LBL_ProjectCustomizer_Category_Web"), null, null); + return cat; + } + return null; + } + + public JComponent createComponent(Category category, Lookup context) { + Project project = (Project)context.lookup(Project.class); + ProjectAccessor acc = (ProjectAccessor)context.lookup(ProjectAccessor.class); + AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class); + assert aux != null; + assert acc != null; + assert project != null; + WebLocationsPanel panel = new WebLocationsPanel(acc.getHelper(), acc.getEvaluator(), aux); + category.setOkButtonListener(panel.getCustomizerOkListener()); + return panel; + } + +} Index: web/freeform/src/org/netbeans/modules/web/freeform/ui/WebLocationsPanel.java =================================================================== RCS file: /cvs/web/freeform/src/org/netbeans/modules/web/freeform/ui/WebLocationsPanel.java,v retrieving revision 1.9 diff -u -r1.9 WebLocationsPanel.java --- web/freeform/src/org/netbeans/modules/web/freeform/ui/WebLocationsPanel.java 12 Oct 2006 14:31:38 -0000 1.9 +++ web/freeform/src/org/netbeans/modules/web/freeform/ui/WebLocationsPanel.java 8 Feb 2007 07:23:27 -0000 @@ -19,14 +19,13 @@ package org.netbeans.modules.web.freeform.ui; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.File; import java.util.ArrayList; import java.util.List; -import javax.swing.JComponent; import javax.swing.JFileChooser; -import org.netbeans.api.project.Project; import org.netbeans.api.queries.CollocationQuery; -import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel; import org.netbeans.modules.ant.freeform.spi.support.Util; import org.netbeans.modules.web.freeform.WebProjectGenerator; import org.openide.filesystems.FileUtil; @@ -361,42 +360,14 @@ return Util.relativizeLocation(baseFolder, nbProjectFolder, normalizedLocation); } - public static class Panel implements ProjectPropertiesPanel { - - private AntProjectHelper projectHelper; - private PropertyEvaluator projectEvaluator; - private AuxiliaryConfiguration aux; - private WebLocationsPanel panel = null; - - public Panel(AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { - this.projectHelper = projectHelper; - this.projectEvaluator = projectEvaluator; - this.aux = aux; - } - - public void storeValues() { - if (panel == null) { - return; - } - AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(projectHelper); - WebProjectGenerator.putWebSourceFolder(projectHelper, panel.getWebSrcFolder()); - WebProjectGenerator.putWebModules(projectHelper, aux, panel.getWebModules()); - } - - public String getDisplayName() { - return NbBundle.getMessage(WebLocationsPanel.class, "LBL_ProjectCustomizer_Category_Web"); - } - - public JComponent getComponent() { - if (panel == null) { - panel = new WebLocationsPanel(projectHelper, projectEvaluator, aux); + ActionListener getCustomizerOkListener() { + return new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(projectHelper); + WebProjectGenerator.putWebSourceFolder(projectHelper, getWebSrcFolder()); + WebProjectGenerator.putWebModules(projectHelper, aux, getWebModules()); } - return panel; - } - - public int getPreferredPosition() { - return 150; // after Java sources panel, befvore Java Sources Classpath panel - } + }; } }