Index: apichanges.xml =================================================================== RCS file: /cvs/ant/project/apichanges.xml,v retrieving revision 1.14 diff -c -r1.14 apichanges.xml *** apichanges.xml 11 Sep 2006 21:51:17 -0000 1.14 --- apichanges.xml 3 Oct 2006 08:42:19 -0000 *************** *** 82,87 **** --- 82,107 ---- + + + Added utility class for reuse in CustomizerProvider implementations + + + + + +

+ Added a new class AntProjectProperties to + make it easier to write and share a common data model for Customizers that allow to + additional panels from 3rd party modules. The CustomizerProvider implementation created using the + ProjectCustomizer.createCustomizerDialog(String, Lookup, String, ActionListener, HelpCtx) method, can use a subclass of this class to allow project properties updates + without exposing an API on it's own. +

+
+ + +
+ Added utilities for constructing richer property evaluators Index: manifest.mf =================================================================== RCS file: /cvs/ant/project/manifest.mf,v retrieving revision 1.18 diff -c -r1.18 manifest.mf *** manifest.mf 8 Sep 2006 18:33:46 -0000 1.18 --- manifest.mf 3 Oct 2006 08:42:19 -0000 *************** *** 1,6 **** Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.project.ant/1 ! OpenIDE-Module-Specification-Version: 1.14 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bundle.properties OpenIDE-Module-Install: org/netbeans/modules/project/ant/AntProjectModule.class --- 1,6 ---- Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.project.ant/1 ! OpenIDE-Module-Specification-Version: 1.15 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bundle.properties OpenIDE-Module-Install: org/netbeans/modules/project/ant/AntProjectModule.class Index: src/org/netbeans/spi/project/support/ant/ui/AntProjectProperties.java =================================================================== RCS file: src/org/netbeans/spi/project/support/ant/ui/AntProjectProperties.java diff -N src/org/netbeans/spi/project/support/ant/ui/AntProjectProperties.java *** /dev/null 1 Jan 1970 00:00:00 -0000 --- src/org/netbeans/spi/project/support/ant/ui/AntProjectProperties.java 3 Oct 2006 08:42:19 -0000 *************** *** 0 **** --- 1,150 ---- + /* + * 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.spi.project.support.ant.ui; + + import java.awt.event.ActionEvent; + import java.awt.event.ActionListener; + import java.io.IOException; + import java.util.ArrayList; + import java.util.HashSet; + import java.util.Iterator; + import java.util.Properties; + import java.util.Set; + import org.netbeans.spi.project.support.ant.EditableProperties; + + /** + * A baseclass for Project Properties model in project customizers. Meant to be subclassed + * by the CustomizerProvider implementation of a project type. Manages public and private properties model + * updates and provides utility methods to save them. + * + * Allows to add/update properties from 3rd party panels that originate in + * {@link org.netbeans.spi.project.ui.support.ProjectCustomizer.CompositeCategoryProvider} implementations. + * In typical usecase, the CompositeCategoryProvider is passed instance of this class in the Lookup context. + * The UI of 3rd party panel can update properties, create component model or register callback to be + * notified when the changes are to be applied. + * + * @since org.netbeans.modules.project.ant/1 1.15 + * + * @author mkleint + */ + public abstract class AntProjectProperties { + private StoreGroup privateGroup; + private StoreGroup projectGroup; + + private Properties additionalProperties; + private Properties additionalPrivateProperties; + private Set listeners; + + protected AntProjectProperties() { + privateGroup = new StoreGroup(); + projectGroup = new StoreGroup(); + additionalProperties = new Properties(); + additionalPrivateProperties = new Properties(); + listeners = new HashSet(); + } + + /** + * StoreGroup for nbproject/project.properties content. + */ + public final StoreGroup getPublicStoreGroup() { + return projectGroup; + + } + + /** + * StoreGroup for nbproject/private/private.properties content. + */ + public final StoreGroup getPrivateStoreGroup() { + return privateGroup; + + } + + /** + * Add listener to be notified of storing the project properties. Typically happens + * on user applying the changes done in the customizer. + */ + public final void addStoreActionListener(ActionListener listener) { + listeners.add(listener); + } + /** + * Remove a previously registered listener + */ + public final void removeStoreActionListener(ActionListener listener) { + listeners.remove(listener); + } + /** + * Notifies all registered listeners interested in performing tasks after the + * project properties were stored. + * To be called from storeProperties() method code. + */ + protected final void notifyStoreActionListeners() { + ArrayList list = new ArrayList(); + list.addAll(listeners); + for (ActionListener l : list) { + l.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "APPLY_CHANGES")); + } + } + + /** + * aditional content for nbproject/project.properties, not backed by the + * StoreGroup model + */ + public final void putAdditionalProperty(String propertyName, String propertyValue) { + additionalProperties.setProperty(propertyName, propertyValue); + + } + + /** + * aditional content for nbproject/private/private.properties, not backed by the + * StoreGroup model + */ + public final void putAdditionalPrivateProperty(String propertyName, String propertyValue) { + additionalPrivateProperties.setProperty(propertyName, propertyValue); + } + + /** + * Properties saving logic, to be implemented by subclasses. To fullfill the general contract the subclasses + * ought to call storeProperties(EditableProperties, EditableProperties) and notifyStoreActionListeners() methods. + * + */ + protected abstract void storeProperties() throws IOException; + + /** + * Stores the data contained in the private and public StoreGroup instances and any additional properties. + * To be called from storeProperties() method code. + */ + protected final void storeProperties(EditableProperties projectProperties, EditableProperties privateProperties) { + // Standard store of the properties + projectGroup.store( projectProperties ); + privateGroup.store( privateProperties ); + + storeAdditionalProperties(additionalProperties, projectProperties); + storeAdditionalProperties(additionalPrivateProperties, privateProperties); + + } + + private void storeAdditionalProperties(Properties props, EditableProperties projectProperties) { + for (Iterator i = props.keySet().iterator(); i.hasNext();) { + String key = (String) i.next(); + projectProperties.put(key, (String) props.get(key)); + } + } + + } Index: src/org/netbeans/spi/project/support/ant/ui/StoreGroup.java =================================================================== RCS file: /cvs/ant/project/src/org/netbeans/spi/project/support/ant/ui/StoreGroup.java,v retrieving revision 1.4 diff -c -r1.4 StoreGroup.java *** src/org/netbeans/spi/project/support/ant/ui/StoreGroup.java 3 Aug 2006 19:21:08 -0000 1.4 --- src/org/netbeans/spi/project/support/ant/ui/StoreGroup.java 3 Oct 2006 08:42:19 -0000 *************** *** 50,63 **** * will create the swing models for you. *
  • Use the models in your Swing controls by calling setModel() or setDocument()
  • * ! * For storing the models back to the proprties of project. *
      *
    1. Get the EditableProperties you want to store the model in e.g. private or project * properties
    2. *
    3. Call the store method on given SourceGroup with the {@link EditableProperties} as parameter
    4. *
    5. Manually store models which need some special handling.
    6. *
    ! * * @author Petr Hrebejk */ public class StoreGroup { --- 50,64 ---- * will create the swing models for you. *
  • Use the models in your Swing controls by calling setModel() or setDocument()
  • * ! * For storing the models back to the properties of project. *
      *
    1. Get the EditableProperties you want to store the model in e.g. private or project * properties
    2. *
    3. Call the store method on given SourceGroup with the {@link EditableProperties} as parameter
    4. *
    5. Manually store models which need some special handling.
    6. *
    ! * As a convenience you can use the {@link org.netbeans.spi.project.support.ant.ui.AntProjectProperties} class ! * that encapsulates the default StoreGroup instances for ant based projects. * @author Petr Hrebejk */ public class StoreGroup {