# HG changeset patch # Parent 0b0865f638200cf4bc52034142ae8d8a7e789d92 #219827 add Close listener to ProjectCustomizer.Category diff -r 0b0865f63820 java.j2seproject/src/org/netbeans/modules/java/j2seproject/api/J2SECustomPropertySaver.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/api/J2SECustomPropertySaver.java Thu Nov 01 06:36:43 2012 +0000 +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/api/J2SECustomPropertySaver.java Thu Nov 01 15:57:00 2012 +0100 @@ -46,6 +46,8 @@ * if modified by user in Project Properties dialog. * Implementation of the interface should be registered using {@link org.netbeans.spi.project.ProjectServiceProvider}. * + * Note: alternatively use org.netbeans.spi.project.ui.support.ProjectCustomizer.Category.setStoreListener + * * @author Petr Somol * @since 1.46 */ diff -r 0b0865f63820 javafx2.project/manifest.mf --- a/javafx2.project/manifest.mf Thu Nov 01 06:36:43 2012 +0000 +++ b/javafx2.project/manifest.mf Thu Nov 01 15:57:00 2012 +0100 @@ -3,4 +3,4 @@ OpenIDE-Module: org.netbeans.modules.javafx2.project OpenIDE-Module-Layer: org/netbeans/modules/javafx2/project/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/javafx2/project/Bundle.properties -OpenIDE-Module-Specification-Version: 1.9 +OpenIDE-Module-Specification-Version: 1.10 diff -r 0b0865f63820 javafx2.project/nbproject/project.properties --- a/javafx2.project/nbproject/project.properties Thu Nov 01 06:36:43 2012 +0000 +++ b/javafx2.project/nbproject/project.properties Thu Nov 01 15:57:00 2012 +0100 @@ -1,4 +1,4 @@ javac.source=1.6 javac.compilerargs=-Xlint -Xlint:-serial -test.config.stable.includes=**/NewJavaFX2ProjectTest.class \ No newline at end of file +test.config.stable.includes=**/NewJavaFX2ProjectTest.class diff -r 0b0865f63820 javafx2.project/nbproject/project.xml --- a/javafx2.project/nbproject/project.xml Thu Nov 01 06:36:43 2012 +0000 +++ b/javafx2.project/nbproject/project.xml Thu Nov 01 15:57:00 2012 +0100 @@ -161,7 +161,7 @@ 1 - 1.49.0.8 + 1.64 diff -r 0b0865f63820 javafx2.project/src/org/netbeans/modules/javafx2/project/JFXProjectProperties.java --- a/javafx2.project/src/org/netbeans/modules/javafx2/project/JFXProjectProperties.java Thu Nov 01 06:36:43 2012 +0000 +++ b/javafx2.project/src/org/netbeans/modules/javafx2/project/JFXProjectProperties.java Thu Nov 01 15:57:00 2012 +0100 @@ -491,7 +491,10 @@ * * @param category marker string to indicate which category provider is calling this * @return instance of JFXProjectProperties shared among category panels in the current Project Properties dialog only + * + * @deprecated handle cleanup using ProjectCustomizer.Category.setCloseListener instead */ + @Deprecated public static JFXProjectProperties getInstancePerSession(Lookup context, String category) { Project proj = context.lookup(Project.class); String projDir = proj.getProjectDirectory().getPath(); diff -r 0b0865f63820 javafx2.project/src/org/netbeans/modules/javafx2/project/ui/JFXProjectPropertiesSaver.java --- a/javafx2.project/src/org/netbeans/modules/javafx2/project/ui/JFXProjectPropertiesSaver.java Thu Nov 01 06:36:43 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2011 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development and - * Distribution License("CDDL") (collectively, the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy of - * the License at http://www.netbeans.org/cddl-gplv2.html or - * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language - * governing permissions and limitations under the License. When distributing - * the software, include this License Header Notice in each file and include - * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided by - * Oracle in the GPL Version 2 section of the License file that accompanied - * this code. If applicable, add the following below the License Header, with - * the fields enclosed by brackets [] replaced by your own identifying - * information: "Portions Copyrighted [year] [name of copyright owner]" - * - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you do not indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to its - * licensees as provided above. However, if you add GPL Version 2 code and - * therefore, elected the GPL Version 2 license, then the option applies only - * if the new code is made subject to such option by the copyright holder. - * - * Contributor(s): - * - * Portions Copyrighted 2011 Sun Microsystems, Inc. - */ -package org.netbeans.modules.javafx2.project.ui; - -import java.io.IOException; -import org.netbeans.api.project.Project; -import org.netbeans.modules.java.j2seproject.api.J2SECustomPropertySaver; -import org.netbeans.modules.javafx2.project.JFXProjectProperties; -import org.netbeans.spi.project.ProjectServiceProvider; -import org.openide.util.Exceptions; - -/** - * Provides saver service for JavaFX 2.0 specific project properties - * for use in standard J2SE Project Properties dialog so that all properties - * can be properly saved in project.properties and private.properties when - * OK button is pressed. - * - * @author Petr Somol - */ -@ProjectServiceProvider(service=J2SECustomPropertySaver.class, projectType="org-netbeans-modules-java-j2seproject") -public class JFXProjectPropertiesSaver implements J2SECustomPropertySaver { - - public JFXProjectPropertiesSaver() {} - - @Override - public void save(Project project) { - JFXProjectProperties prop = JFXProjectProperties.getInstanceIfExists(project.getLookup()); - if(prop != null) { - try { - prop.store(); - JFXProjectProperties.cleanup(project.getLookup()); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } - } - } - -} diff -r 0b0865f63820 javafx2.project/src/org/netbeans/modules/javafx2/project/ui/JFXRunCategoryProvider.java --- a/javafx2.project/src/org/netbeans/modules/javafx2/project/ui/JFXRunCategoryProvider.java Thu Nov 01 06:36:43 2012 +0000 +++ b/javafx2.project/src/org/netbeans/modules/javafx2/project/ui/JFXRunCategoryProvider.java Thu Nov 01 15:57:00 2012 +0100 @@ -37,12 +37,18 @@ */ package org.netbeans.modules.javafx2.project.ui; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import javax.swing.JComponent; import org.netbeans.api.project.Project; import org.netbeans.modules.java.j2seproject.api.J2SEPropertyEvaluator; import org.netbeans.modules.javafx2.project.JFXProjectProperties; import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category; +import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.NbBundle; @@ -56,7 +62,7 @@ private static final String CAT_RUN = "Run"; // NOI18N - private static JFXProjectProperties jfxProps = null; + private static final Map projectProperties = new HashMap(); @Override public Category createCategory(Lookup context) { @@ -68,16 +74,51 @@ && !JFXProjectProperties.isTrue(j2sepe.evaluator().getProperty(JFXProjectProperties.JAVAFX_PRELOADER)); //NOI18N } if(fxProjectEnabled) { - jfxProps = JFXProjectProperties.getInstancePerSession(context, CAT_RUN); - return ProjectCustomizer.Category.create(CAT_RUN, + ProjectCustomizer.Category c = ProjectCustomizer.Category.create(CAT_RUN, NbBundle.getMessage(JFXRunCategoryProvider.class, "LBL_Category_Run"), null); //NOI18N + c.setOkButtonListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(project != null) { + JFXProjectProperties prop = JFXProjectProperties.getInstanceIfExists(project.getLookup()); + if(prop != null) { + projectProperties.put(project.getProjectDirectory().getPath(), prop); + } + } + } + }); + c.setStoreListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(project != null) { + JFXProjectProperties prop = projectProperties.get(project.getProjectDirectory().getPath()); + if(prop != null) { + try { + prop.store(); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + projectProperties.remove(project.getProjectDirectory().getPath()); + } + } + }); + c.setCloseListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(project != null) { + JFXProjectProperties.cleanup(project.getLookup()); + } + } + }); + return c; } return null; } @Override public JComponent createComponent(Category category, Lookup context) { - return new JFXRunPanel(jfxProps); + return new JFXRunPanel(JFXProjectProperties.getInstance(context)); } } diff -r 0b0865f63820 javawebstart/manifest.mf --- a/javawebstart/manifest.mf Thu Nov 01 06:36:43 2012 +0000 +++ b/javawebstart/manifest.mf Thu Nov 01 15:57:00 2012 +0100 @@ -2,5 +2,5 @@ OpenIDE-Module: org.netbeans.modules.javawebstart OpenIDE-Module-Layer: org/netbeans/modules/javawebstart/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/javawebstart/Bundle.properties -OpenIDE-Module-Specification-Version: 1.19 +OpenIDE-Module-Specification-Version: 1.20 AutoUpdate-Show-In-Client: false diff -r 0b0865f63820 javawebstart/nbproject/project.xml --- a/javawebstart/nbproject/project.xml Thu Nov 01 06:36:43 2012 +0000 +++ b/javawebstart/nbproject/project.xml Thu Nov 01 15:57:00 2012 +0100 @@ -152,7 +152,7 @@ 1 - 1.37 + 1.64 diff -r 0b0865f63820 javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/Bundle.properties --- a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/Bundle.properties Thu Nov 01 06:36:43 2012 +0000 +++ b/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/Bundle.properties Thu Nov 01 15:57:00 2012 +0100 @@ -261,4 +261,4 @@ ERR_MissingPlatformLocation=Java platform {0} location property missing. Attempting to switch to default WebStart. ERR_MissingPlatformLib=Java platform {0} library {1} could not be located. ERR_LibFileMissing=Library file {0} not found! Switching WebStart off. -ERR_ClassPathProblem=Classpath property {0} decoding problem. Paths to WebStart libraries may be decoded wrong. \ No newline at end of file +ERR_ClassPathProblem=Classpath property {0} decoding problem. Paths to WebStart libraries may be decoded wrong. diff -r 0b0865f63820 javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCompositeCategoryProvider.java --- a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCompositeCategoryProvider.java Thu Nov 01 06:36:43 2012 +0000 +++ b/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCompositeCategoryProvider.java Thu Nov 01 15:57:00 2012 +0100 @@ -44,6 +44,10 @@ package org.netbeans.modules.javawebstart.ui.customizer; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; +import java.util.Map; import javax.swing.JComponent; import org.netbeans.api.project.Project; import org.netbeans.modules.java.j2seproject.api.J2SEPropertyEvaluator; @@ -62,8 +66,8 @@ private static final String CAT_WEBSTART = "WebStart"; // NOI18N - private static JWSProjectProperties jwsProps = null; - + private static final Map projectProperties = new HashMap(); + public JWSCompositeCategoryProvider() {} @Override @@ -74,14 +78,49 @@ final J2SEPropertyEvaluator j2sepe = project.getLookup().lookup(J2SEPropertyEvaluator.class); fxOverride = JWSProjectProperties.isTrue(j2sepe.evaluator().getProperty("javafx.enabled")); //NOI18N } - jwsProps = JWSProjectProperties.getInstancePerSession(context, CAT_WEBSTART); - return fxOverride ? null : ProjectCustomizer.Category.create(CAT_WEBSTART, + if(!fxOverride) { + ProjectCustomizer.Category c = ProjectCustomizer.Category.create(CAT_WEBSTART, NbBundle.getMessage(JWSCompositeCategoryProvider.class, "LBL_Category_WebStart"), null); //NOI18N + c.setOkButtonListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(project != null) { + JWSProjectProperties prop = JWSProjectProperties.getInstanceIfExists(project.getLookup()); + if(prop != null) { + projectProperties.put(project.getProjectDirectory().getPath(), prop); + } + } + } + }); + c.setStoreListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(project != null) { + JWSProjectProperties prop = projectProperties.get(project.getProjectDirectory().getPath()); + if(prop != null) { + JWSProjectPropertiesUtils.updateMasterFiles(prop, project); + JWSProjectPropertiesUtils.savePropsAndUpdateMetaFiles(prop, project); + } + projectProperties.remove(project.getProjectDirectory().getPath()); + } + } + }); + c.setCloseListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(project != null) { + JWSProjectProperties.cleanup(project.getLookup()); + } + } + }); + return c; + } + return null; } @Override public JComponent createComponent(ProjectCustomizer.Category category, Lookup context) { - return new JWSCustomizerPanel(jwsProps); + return new JWSCustomizerPanel(JWSProjectProperties.getInstance(context)); } } diff -r 0b0865f63820 javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSProjectProperties.java --- a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSProjectProperties.java Thu Nov 01 06:36:43 2012 +0000 +++ b/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSProjectProperties.java Thu Nov 01 15:57:00 2012 +0100 @@ -263,16 +263,19 @@ /** Factory method * This is to prevent reuse of the same instance after the properties dialog - * has been cancelled. Called by each FX category provider at the time + * has been cancelled. Called by each WS category provider at the time * when properties dialog is opened, it checks/stores category-specific marker strings. * Previous existence of marker string indicates that properties dialog had been opened * before and ended by Cancel, otherwise this instance would not exist (OK would - * cause properties to be saved and the instance deleted by a call to JFXProjectProperties.cleanup()). + * cause properties to be saved and the instance deleted by a call to JWSProjectProperties.cleanup()). * (Note that this is a workaround to avoid adding listener to properties dialog close event.) * * @param category marker string to indicate which category provider is calling this - * @return instance of JFXProjectProperties shared among category panels in the current Project Properties dialog only + * @return instance of JWSProjectProperties shared among category panels in the current Project Properties dialog only + * + * @deprecated handle cleanup using ProjectCustomizer.Category.setCloseListener instead */ + @Deprecated public static JWSProjectProperties getInstancePerSession(Lookup context, String category) { Project proj = context.lookup(Project.class); String projDir = proj.getProjectDirectory().getPath(); diff -r 0b0865f63820 javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSProjectPropertiesSaver.java --- a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSProjectPropertiesSaver.java Thu Nov 01 06:36:43 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2011 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - * - * Contributor(s): - * - * Portions Copyrighted 2011 Sun Microsystems, Inc. - */ -package org.netbeans.modules.javawebstart.ui.customizer; - -import org.netbeans.api.project.Project; -import org.netbeans.modules.java.j2seproject.api.J2SECustomPropertySaver; -import org.netbeans.spi.project.ProjectServiceProvider; - -/** - * Provides saver service for WebStart specific project properties - * for use in standard J2SE Project Properties dialog so that all properties - * can be properly saved in project.properties and private.properties when - * OK button is pressed. Note that this enables reaction to change of Java Platform. - * - * @author Petr Somol - */ -@ProjectServiceProvider(service=J2SECustomPropertySaver.class, projectType="org-netbeans-modules-java-j2seproject") -public class JWSProjectPropertiesSaver implements J2SECustomPropertySaver { - - public JWSProjectPropertiesSaver() {} - - @Override - public void save(Project project) { - JWSProjectProperties prop = JWSProjectProperties.getInstanceIfExists(project.getLookup()); - if(prop != null) { - JWSProjectPropertiesUtils.updateMasterFiles(prop, project); - JWSProjectPropertiesUtils.savePropsAndUpdateMetaFiles(prop, project); - JWSProjectProperties.cleanup(project.getLookup()); - } - } - -} diff -r 0b0865f63820 projectuiapi/apichanges.xml --- a/projectuiapi/apichanges.xml Thu Nov 01 06:36:43 2012 +0000 +++ b/projectuiapi/apichanges.xml Thu Nov 01 15:57:00 2012 +0100 @@ -107,6 +107,29 @@ + + + Added Close listener to ProjectCustomizer.Category. + + + + + +

+ Added a Close listener to ProjectCustomizer.Category to enable + correct memory management when specific project properties are + to be maintained while Project Properties dialog is displayed, + containing various, possibly extended, categories. This is the case + with JWSProjectProperties and JFXProjectProperties, where cleanup + is needed at the time of dialog closing. The introduction of + a Close listener here actually enables to deprecate J2SECustomPropertySaver + interface and thus make the same mechanism available even outside + J2SE projects. +

+
+ + +
Added a support class for ProjectProblemsProvider. diff -r 0b0865f63820 projectuiapi/nbproject/project.properties --- a/projectuiapi/nbproject/project.properties Thu Nov 01 06:36:43 2012 +0000 +++ b/projectuiapi/nbproject/project.properties Thu Nov 01 15:57:00 2012 +0100 @@ -42,7 +42,7 @@ javac.compilerargs=-Xlint -Xlint:-serial javac.source=1.6 -spec.version.base=1.63.0 +spec.version.base=1.64.0 is.autoload=true javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml diff -r 0b0865f63820 projectuiapi/src/org/netbeans/modules/project/uiapi/CustomizerDialog.java --- a/projectuiapi/src/org/netbeans/modules/project/uiapi/CustomizerDialog.java Thu Nov 01 06:36:43 2012 +0000 +++ b/projectuiapi/src/org/netbeans/modules/project/uiapi/CustomizerDialog.java Thu Nov 01 15:57:00 2012 +0100 @@ -101,6 +101,9 @@ private static final String COMMAND_OK = "OK"; // NOI18N private static final String COMMAND_CANCEL = "CANCEL"; // NOI18N + // Close action + private static final int ACTION_CLOSE = OPTION_CANCEL + 1; + private static final String CUSTOMIZER_DIALOG_X = "CustomizerDialog.dialog.x"; private static final String CUSTOMIZER_DIALOG_Y = "CustomizerDialog.dialog.y"; private static final String CUSTOMIZER_DIALOG_WIDTH = "CustomizerDialog.dialog.width"; @@ -214,6 +217,11 @@ Utilities.removeCategoryChangeSupport(category); + ActionListener listener = category.getCloseListener(); + if (listener != null) { + listener.actionPerformed(new ActionEvent(this, ACTION_CLOSE, e.paramString())); + } + if (category.getSubcategories() != null) { queue.addAll(Arrays.asList(category.getSubcategories())); } diff -r 0b0865f63820 projectuiapi/src/org/netbeans/spi/project/ui/support/ProjectCustomizer.java --- a/projectuiapi/src/org/netbeans/spi/project/ui/support/ProjectCustomizer.java Thu Nov 01 06:36:43 2012 +0000 +++ b/projectuiapi/src/org/netbeans/spi/project/ui/support/ProjectCustomizer.java Thu Nov 01 15:57:00 2012 +0100 @@ -422,6 +422,7 @@ private String errorMessage; private ActionListener okListener; private ActionListener storeListener; + private ActionListener closeListener; /** Private constructor. See the factory method. */ @@ -573,6 +574,26 @@ public ActionListener getStoreListener() { return storeListener; } + + /** + * Set the action listener that will get notified when the customizer is going to be closed + * Listener is executed outside of AWT EventQueue. Usually to be used to do cleanup. + * @param listener ActionListener to notify + * @since org.netbeans.modules.projectuiapi/1 1.64 + */ + public void setCloseListener(ActionListener listener) { + closeListener = listener; + } + + /** + * Returns the action listener that is executed outside of AWT EQ and is associated + * with this category that gets notified when the customizer is going to be closed. + * @return instance of ActionListener or null if not set. + * @since org.netbeans.modules.projectuiapi/1 1.64 + */ + public ActionListener getCloseListener() { + return closeListener; + } } diff -r 0b0865f63820 projectuiapi/test/unit/src/org/netbeans/spi/project/ui/support/ProjectCustomizerListenersTest.java --- a/projectuiapi/test/unit/src/org/netbeans/spi/project/ui/support/ProjectCustomizerListenersTest.java Thu Nov 01 06:36:43 2012 +0000 +++ b/projectuiapi/test/unit/src/org/netbeans/spi/project/ui/support/ProjectCustomizerListenersTest.java Thu Nov 01 15:57:00 2012 +0100 @@ -23,7 +23,9 @@ import java.awt.event.ActionListener; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JDialog; @@ -44,9 +46,9 @@ import org.openide.util.HelpCtx; /** - * Test of OK and Store listeners of ProjectCustomzier dialog + * Test of OK, Store and Close listeners of ProjectCustomzier dialog * - * @author Milan Kubec + * @author Milan Kubec, Petr Somol */ public class ProjectCustomizerListenersTest extends NbTestCase { @@ -55,7 +57,7 @@ } private List events = new ArrayList(); - private enum LType { OK, STORE }; + private enum LType { OK, STORE, CLOSE }; public ProjectCustomizerListenersTest(String name) { super(name); @@ -68,7 +70,7 @@ events.clear(); } - public void testOKAndStoreListeners() { + public void testAllListeners() { Category testCat1 = Category.create("test1", "test1", null); final Category testCat2 = Category.create("test2", "test2", null, testCat1); @@ -76,20 +78,27 @@ testCat1.setOkButtonListener(new Listener(LType.OK, "testCat1", true)); testCat1.setStoreListener(new Listener(LType.STORE, "testCat1", false)); + testCat1.setCloseListener(new Listener(LType.CLOSE, "testCat1", true)); testCat2.setOkButtonListener(new Listener(LType.OK, "testCat2", true)); testCat2.setStoreListener(new Listener(LType.STORE, "testCat2", false)); + testCat2.setCloseListener(new Listener(LType.CLOSE, "testCat2", true)); testCat3.setOkButtonListener(new Listener(LType.OK, "testCat3", true)); testCat3.setStoreListener(new Listener(LType.STORE, "testCat3", false)); + testCat3.setCloseListener(new Listener(LType.CLOSE, "testCat3", true)); final Listener mainOKListener = new Listener(LType.OK, "Properties", true); final Listener mainStoreListener = new Listener(LType.STORE, "Properties", false); try { SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { - ProjectCustomizer.createCustomizerDialog(new Category[]{ testCat2, testCat3 }, + Dialog dialog = ProjectCustomizer.createCustomizerDialog(new Category[]{ testCat2, testCat3 }, new CategoryComponentProviderImpl(), null, mainOKListener, mainStoreListener, HelpCtx.DEFAULT_HELP); + dialog.pack(); + dialog.setVisible(true); + dialog.dispose(); } }); } catch (InterruptedException ex) { @@ -109,16 +118,39 @@ // System.out.println(er); // } - assertEquals(8, events.size()); + assertEquals(14, events.size()); assertEquals(new EventRecord(LType.OK, "Properties", 0), events.get(0)); assertEquals(new EventRecord(LType.OK, "testCat2", 0), events.get(1)); assertEquals(new EventRecord(LType.OK, "testCat1", 0), events.get(2)); assertEquals(new EventRecord(LType.OK, "testCat3", 0), events.get(3)); - assertEquals(new EventRecord(LType.STORE, "Properties", 0), events.get(4)); - assertEquals(new EventRecord(LType.STORE, "testCat2", 0), events.get(5)); - assertEquals(new EventRecord(LType.STORE, "testCat1", 0), events.get(6)); - assertEquals(new EventRecord(LType.STORE, "testCat3", 0), events.get(7)); - + // CLOSE and STORE events can theoretically be intermixed + Map event = new HashMap(); + for(int i = 4; i < 14; i++) { + EventRecord er = events.get(i); + assertNotNull(er); + assertTrue(er.getType() != LType.OK); + Integer count = event.get(er.getTypeAndId()); + if(count == null) { + event.put(er.getTypeAndId(), 1); + } else { + event.put(er.getTypeAndId(), count + 1); + } + } + assertEquals(7, event.size()); + assertNotNull(event.get((new EventRecord(LType.STORE, "Properties", 0)).getTypeAndId())); + assertNotNull(event.get((new EventRecord(LType.STORE, "testCat2", 0)).getTypeAndId())); + assertNotNull(event.get((new EventRecord(LType.STORE, "testCat1", 0)).getTypeAndId())); + assertNotNull(event.get((new EventRecord(LType.STORE, "testCat3", 0)).getTypeAndId())); + assertNotNull(event.get((new EventRecord(LType.CLOSE, "testCat2", 0)).getTypeAndId())); + assertNotNull(event.get((new EventRecord(LType.CLOSE, "testCat1", 0)).getTypeAndId())); + assertNotNull(event.get((new EventRecord(LType.CLOSE, "testCat3", 0)).getTypeAndId())); + assertEquals(1, event.get((new EventRecord(LType.STORE, "Properties", 0)).getTypeAndId()).intValue()); + assertEquals(1, event.get((new EventRecord(LType.STORE, "testCat2", 0)).getTypeAndId()).intValue()); + assertEquals(1, event.get((new EventRecord(LType.STORE, "testCat1", 0)).getTypeAndId()).intValue()); + assertEquals(1, event.get((new EventRecord(LType.STORE, "testCat3", 0)).getTypeAndId()).intValue()); + assertEquals(2, event.get((new EventRecord(LType.CLOSE, "testCat2", 0)).getTypeAndId()).intValue()); + assertEquals(2, event.get((new EventRecord(LType.CLOSE, "testCat1", 0)).getTypeAndId()).intValue()); + assertEquals(2, event.get((new EventRecord(LType.CLOSE, "testCat3", 0)).getTypeAndId()).intValue()); } public void testOKListener() { @@ -135,6 +167,7 @@ try { SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { ProjectCustomizer.createCustomizerDialog(new Category[]{ testCat2, testCat3 }, new CategoryComponentProviderImpl(), null, mainOKListener, @@ -225,6 +258,22 @@ this.when = when; } + public LType getType() { + return type; + } + + public String getId() { + return id; + } + + public long getWhen() { + return when; + } + + public String getTypeAndId() { + return type + ", " + id; + } + @Override public String toString() { return type + ", " + id + ", " + when;