# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /space/work/all/core/options
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: src/org/netbeans/api/options/OptionsDisplayer.java
*** /space/work/all/core/options/src/org/netbeans/api/options/OptionsDisplayer.java No Base Revision
--- /space/work/all/core/options/src/org/netbeans/api/options/OptionsDisplayer.java Locally New
***************
*** 1,0 ****
--- 1,111 ----
+ /*
+ * 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.api.options;
+
+ import java.lang.reflect.InvocationTargetException;
+ import java.util.Arrays;
+ import java.util.logging.Level;
+ import java.util.logging.Logger;
+ import javax.swing.SwingUtilities;
+ import org.netbeans.modules.options.CategoryModel;
+ import org.netbeans.modules.options.OptionsDisplayerImpl;
+ import org.openide.util.Mutex;
+ /**
+ * Permits Options Dialog to open the options dialog with some category pre-selected.
+ *
+ * @author Radek Matous
+ */
+ public final class OptionsDisplayer {
+ private static final OptionsDisplayer INSTANCE = new OptionsDisplayer();
+ private final OptionsDisplayerImpl impl = new OptionsDisplayerImpl(false);
+ private static Logger log = Logger.getLogger(OptionsDisplayer.class.getName());
+
+
+ private OptionsDisplayer() {}
+
+ /**
+ * Get the default OptionsDisplayer
+ * @return the default instance
+ */
+ public static OptionsDisplayer getDefault() {
+ return INSTANCE;
+ }
+
+ /**
+ * Open the options dialog with no guarantee which category is pre-selected.
+ * @return true if optins dialog was sucesfully opened with some pre-selected
+ * category. If no category is registered at all then false will be returned and
+ * options dialog won't be opened.
+ */
+ public boolean open() {
+ return open(CategoryModel.getInstance().getCurrentCategoryID());
+ }
+
+ /**
+ * Open the options dialog with some category pre-selected.
+ * @param categoryId ID representing required category which is registration name
+ * (e.g. "FooOptionsPanelID" for following registration:
+ *
+ * <folder name="OptionsDialog">
+ * <file name="FooOptionsPanelID.instance">
+ * <attr name="instanceClass" stringvalue="org.foo.FooOptionsPanel"/>
+ * </file>
+ * </folder>
+ * @return true if optins dialog was sucesfully opened with required category pre-selected.
+ * If this method is called when options dialog is already opened then this method
+ * will return immediately false without affecting currently selected category
+ * in opened options dialog.
+ * If categoryId
passed as a parameter does not correspond to any
+ * of registered categories then false is returned and options dialog is not opened
+ * at all (e.g. in case that module providing such category is not installed or enabled).
+ */
+ public boolean open(final String categoryId) {
+ log.fine("Open Options Dialog: " + categoryId); //NOI18N
+ return openImpl(categoryId);
+ }
+
+ private boolean openImpl(final String categoryId) {
+ if (!SwingUtilities.isEventDispatchThread()) {
+ try {
+ SwingUtilities.invokeAndWait(new Runnable(){public void run() {}});
+ } catch (Exception ex) {
+ log.log(Level.SEVERE, null, ex);
+ }
+ }
+ Boolean retval = Mutex.EVENT.readAccess(new Mutex.Action () {
+ public Boolean run() {
+ boolean retvalForRun = !impl.isOpen();
+ if (retvalForRun) {
+ retvalForRun = Arrays.asList(CategoryModel.getInstance().getCategoryIDs()).contains(categoryId);
+ if (!retvalForRun) {
+ log.warning("Unknown categoryId: " + categoryId); //NOI18N
+ }
+ } else {
+ log.warning("Options Dialog is opened"); //NOI18N
+ }
+ if (retvalForRun) {
+ impl.showOptionsDialog(categoryId);
+ }
+ return Boolean.valueOf(retvalForRun);
+ }
+ });
+ return retval;
+ }
+ }
Index: test/unit/src/org/netbeans/api/options/OptionsDisplayerOpenTest.java
*** /space/work/all/core/options/test/unit/src/org/netbeans/api/options/OptionsDisplayerOpenTest.java No Base Revision
--- /space/work/all/core/options/test/unit/src/org/netbeans/api/options/OptionsDisplayerOpenTest.java Locally New
***************
*** 1,0 ****
--- 1,218 ----
+ /*
+ * 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.api.options;
+ /*
+ * OptionsDisplayerTest.java
+ * JUnit based test
+ *
+ * Created on December 12, 2006, 11:13 AM
+ */
+
+ import java.awt.Frame;
+ import java.awt.Dialog;
+ import java.awt.event.ActionEvent;
+ import java.lang.reflect.InvocationTargetException;
+ import java.util.logging.Level;
+ import java.util.logging.Logger;
+ import javax.swing.JButton;
+ import javax.swing.JDialog;
+ import javax.swing.SwingUtilities;
+ import org.netbeans.junit.NbTestCase;
+ import org.openide.DialogDescriptor;
+ import org.openide.DialogDisplayer;
+ import org.openide.NotifyDescriptor;
+
+ /**
+ *
+ * @author Radek Matous
+ */
+ public class OptionsDisplayerOpenTest extends NbTestCase {
+ private static TestDisplayer displayer = new TestDisplayer();
+ Logger log;
+ static {
+ String[] layers = new String[] {"org/netbeans/api/options/mf-layer.xml"};//NOI18N
+ Object[] instances = new Object[] {displayer};
+ IDEInitializer.setup(layers,instances);
+ }
+
+ public OptionsDisplayerOpenTest(String testName) {
+ super(testName);
+ }
+
+ protected void setUp() throws Exception {
+ log = Logger.getLogger("[Test - " + getName() + "]");
+ }
+
+ protected void tearDown() throws Exception {
+ }
+ /**
+ * Test of getDefault method, of class org.netbeans.api.options.OptionsDisplayer.
+ */
+ public void testGetDefault() {
+ assertNotNull(OptionsDisplayer.getDefault());
+ }
+
+ public void testOpenFromWorkerThread() {
+ openOpen(null);
+ openOpen("Registered");
+ openOpen("Unknown");
+ openCloseOpen(null);
+ openCloseOpen("Registered");
+ openCloseOpen("Unknown");
+ }
+
+ public void testOpenFromAWT() throws Exception {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ testOpenFromWorkerThread();
+ }
+ });
+ }
+
+ public void testOpenFromMixedThreads() throws Exception {
+ testOpenFromWorkerThread();
+ testOpenFromAWT();
+ testOpenFromWorkerThread();
+ testOpenFromAWT();
+ }
+
+ public void openOpen(String categoryId) {
+ for (int i = 0; i < 10; i++) {
+ if (categoryId == null) {
+ open(true);
+ open(false);
+ close();
+ //don't call: OptionsDisplayer.getDefault().open(null) but OptionsDisplayer.getDefault().open()
+ open(null, false);
+ close();
+ } else {
+ if ("Registered".equals(categoryId)) {
+ open(categoryId, true);
+ open(categoryId, false);
+ close();
+ } else {
+ open(categoryId, false);
+ open(categoryId, false);
+ close();
+ }
+ }
+ }
+ }
+
+ public void openCloseOpen(String categoryId) {
+ for (int i = 0; i < 10; i++) {
+ if (categoryId == null) {
+ open(true);
+ close();
+ open(true);
+ close();
+ } else {
+ if ("Registered".equals(categoryId)) {
+ open(categoryId, true);
+ close();
+ open(categoryId, true);
+ close();
+ } else {
+ open(categoryId, false);
+ close();
+ open(categoryId, false);
+ close();
+ }
+ }
+ }
+ }
+
+ public void open(boolean expectedResult) {
+ modality(displayer.descriptor);
+ boolean latestResult = OptionsDisplayer.getDefault().open() ;
+ assertEquals(expectedResult, latestResult);
+ }
+
+ public void open(String categoryId, boolean expectedResult) {
+ modality(displayer.descriptor);
+ boolean latestResult = OptionsDisplayer.getDefault().open(categoryId);
+ assertEquals(expectedResult, latestResult);
+ }
+
+ public void modality(DialogDescriptor desc) {
+ if (desc != null) {
+ assertFalse(desc.isModal());
+ }
+ }
+
+ public void close() {
+ modality(displayer.descriptor);
+ displayer.close();
+ }
+
+ protected Level logLevel() {
+ return Level.FINE;
+ }
+
+ private static class TestDisplayer extends DialogDisplayer implements Runnable {
+ DialogDescriptor descriptor;
+ private JDialog dialog;
+ public Object notify(NotifyDescriptor descriptor) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Dialog createDialog(DialogDescriptor descriptor) {
+ this.descriptor = descriptor;
+ return dialog = new TestDialog(descriptor);
+ }
+
+ public void close() {
+ try {
+ if (SwingUtilities.isEventDispatchThread()) {
+ run();
+ } else {
+ SwingUtilities.invokeAndWait(this);
+ }
+ } catch (InterruptedException ex) {
+ } catch (InvocationTargetException ex) {
+ }
+ }
+
+ public void run() {
+ if (descriptor != null) {
+ Object[] oo = descriptor.getClosingOptions();
+ for (int i = 0; i < oo.length; i++) {
+ String command = ((JButton)oo[i]).getActionCommand();
+ if (oo[i] instanceof JButton && "OK".equals(command)) {
+ descriptor.getButtonListener().actionPerformed(new ActionEvent(oo[i], 0, command));
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ private static class TestDialog extends JDialog {
+ TestDialog(DialogDescriptor descriptor) {
+ super((Frame)null, descriptor.getTitle(), descriptor.isModal());
+ }
+
+ public void setVisible(boolean b) {
+ if (isModal()) {
+ super.setVisible(b);
+ }
+ }
+ }
+ }
Index: apichanges.xml
*** /space/work/all/core/options/apichanges.xml Base (1.4)
--- /space/work/all/core/options/apichanges.xml Locally Modified (Based On 1.4)
***************
*** 49,54 ****
--- 49,67 ----
+
+
+ API to open the options dialog with some category pre-selected
+
+
+
+
+
+ Added API to open the options dialog with some category pre-selected.
+
+
+
+
Options Dialog API integrated.