# HG changeset patch # Parent 918742ebe348643e6dece1cb7f8642913ab3debc #229161 - Add API to enable closing project customizer dialog programmatically diff --git a/java.api.common/apichanges.xml b/java.api.common/apichanges.xml --- a/java.api.common/apichanges.xml +++ b/java.api.common/apichanges.xml @@ -105,6 +105,23 @@ + + + Enable programmatical closing of project customizer dialog. + + + + + +

+ Addded interface CustomizerProvider3 extending CustomizerProvider2 + that enables to close project's customizer if it is currently open using + method closeCustomizer(). +

+
+ + +
Added UI support for JRE profiles. diff --git a/java.api.common/manifest.mf b/java.api.common/manifest.mf --- a/java.api.common/manifest.mf +++ b/java.api.common/manifest.mf @@ -1,4 +1,4 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.java.api.common/0 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/api/common/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 1.46 +OpenIDE-Module-Specification-Version: 1.47 diff --git a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/customizer/CustomizerProvider3.java b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/customizer/CustomizerProvider3.java new file mode 100644 --- /dev/null +++ b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/customizer/CustomizerProvider3.java @@ -0,0 +1,58 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 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 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.java.api.common.project.ui.customizer; + +/** + * CustomizerProvider enhanced with ability to explicitly close a customizer + * that may be currently opened + * + * @author Petr Somol + * @since + */ +public interface CustomizerProvider3 extends CustomizerProvider2 { + + /** + * Close customizer if it is currently opened as if it was cancelled + */ + void closeCustomizer(); + +} diff --git a/java.api.common/test/unit/src/org/netbeans/modules/java/api/common/project/ui/customizer/CustomizerProvider3Test.java b/java.api.common/test/unit/src/org/netbeans/modules/java/api/common/project/ui/customizer/CustomizerProvider3Test.java new file mode 100644 --- /dev/null +++ b/java.api.common/test/unit/src/org/netbeans/modules/java/api/common/project/ui/customizer/CustomizerProvider3Test.java @@ -0,0 +1,145 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 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 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.java.api.common.project.ui.customizer; + +import java.util.HashMap; +import java.util.Map; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; +import org.netbeans.junit.MockServices; +import org.openide.util.Lookup; + +/** + * Test of SPI class org.netbeans.modules.java.api.common.project.ui.customizer.CustomizerProvider3 + * + * @author Petr Somol + */ +public class CustomizerProvider3Test { + + public CustomizerProvider3Test() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + MockServices.setServices(CustomizerProvider3Test.MockCustomizerProvider.class); + } + + @Test + public void testShowCustomizer() { + CustomizerProvider3 provider = Lookup.getDefault().lookup(CustomizerProvider3.class); + assertNotNull(provider); + MockCustomizerProvider mockProvider = (MockCustomizerProvider)provider; + assertFalse(mockProvider.customizerOpen()); + + provider.showCustomizer(); + + assertTrue(mockProvider.customizerOpen()); + } + + @Test + public void testCloseCancelCustomizer() { + CustomizerProvider3 provider = Lookup.getDefault().lookup(CustomizerProvider3.class); + assertNotNull(provider); + MockCustomizerProvider mockProvider = (MockCustomizerProvider)provider; + assertTrue(mockProvider.customizerOpen()); + + MockCustomizer.invokeProjectModifyingAction(); + + assertFalse(mockProvider.customizerOpen()); + } + + public static final class MockCustomizerProvider implements CustomizerProvider3 { + + private MockCustomizer customizerDialog = null; + private Map props = new HashMap<>(); + + public MockCustomizerProvider() { + } + + @Override + public void closeCustomizer() { + customizerDialog = null; + } + + @Override + public void showCustomizer(String preselectedCategory, String preselectedSubCategory) { + showCustomizer(); + } + + @Override + public void showCustomizer() { + customizerDialog = new MockCustomizer(); + } + + public void loadProperties(Map properties) { + this.props.putAll(properties); + } + + public void saveProperties(Map properties) { + properties.putAll(this.props); + } + + public boolean customizerOpen() { + return customizerDialog != null; + } + + } + + /** + * + */ + public static final class MockCustomizer{ + + // user invokes an action that changes + // project metafiles to such extent that project + // properties dialog needs to be closed + // before making changes to project metafiles + public static void invokeProjectModifyingAction() { + CustomizerProvider3 provider = Lookup.getDefault().lookup(CustomizerProvider3.class); + provider.closeCustomizer(); + // ..do whatever is needed + } + + } + +} diff --git a/java.j2seproject/nbproject/project.properties b/java.j2seproject/nbproject/project.properties --- a/java.j2seproject/nbproject/project.properties +++ b/java.j2seproject/nbproject/project.properties @@ -42,7 +42,7 @@ javac.compilerargs=-Xlint -Xlint:-serial javac.source=1.7 -spec.version.base=1.61.0 +spec.version.base=1.64.0 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml diff --git a/java.j2seproject/nbproject/project.xml b/java.j2seproject/nbproject/project.xml --- a/java.j2seproject/nbproject/project.xml +++ b/java.j2seproject/nbproject/project.xml @@ -142,7 +142,7 @@ 0-1 - 1.45 + 1.47 diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerProviderImpl.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerProviderImpl.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerProviderImpl.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerProviderImpl.java @@ -60,7 +60,7 @@ import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectUtils; import org.netbeans.modules.java.api.common.ant.UpdateHelper; -import org.netbeans.modules.java.api.common.project.ui.customizer.CustomizerProvider2; +import org.netbeans.modules.java.api.common.project.ui.customizer.CustomizerProvider3; import org.netbeans.modules.java.j2seproject.J2SEProject; import org.netbeans.modules.java.api.common.project.ui.customizer.ProjectSharability; import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; @@ -76,9 +76,9 @@ /** Customization of J2SE project * - * @author Petr Hrebejk + * @author Petr Hrebejk, Petr Somol */ -public class CustomizerProviderImpl implements CustomizerProvider2, ProjectSharability { +public class CustomizerProviderImpl implements CustomizerProvider3, ProjectSharability { private final J2SEProject project; private final UpdateHelper updateHelper; @@ -154,6 +156,16 @@ createJ2SEProjectProperties().makeSharable(); } + @Override + public void closeCustomizer() { + Dialog dialog = project2Dialog.get(project); + if ( dialog != null ) { + dialog.setVisible(false); + dialog.dispose(); + project2Dialog.remove( project ); + } + } + private class StoreListener implements ActionListener { private Project project; diff --git a/javafx2.project/nbproject/project.xml b/javafx2.project/nbproject/project.xml --- a/javafx2.project/nbproject/project.xml +++ b/javafx2.project/nbproject/project.xml @@ -73,7 +73,7 @@ 0-1 - 1.24 + 1.47 @@ -82,7 +82,7 @@ 1 - 1.60 + 1.64