KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > options > OptionsDisplayer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.options;
21
22 import java.util.Arrays JavaDoc;
23 import java.util.logging.Logger JavaDoc;
24 import org.netbeans.modules.options.CategoryModel;
25 import org.netbeans.modules.options.OptionsDisplayerImpl;
26 import org.openide.util.Mutex;
27 /**
28  * Permits Options Dialog to open the options dialog with some category pre-selected.
29  * @since 1.5
30  * @author Radek Matous
31  */

32 public final class OptionsDisplayer {
33     private static final OptionsDisplayer INSTANCE = new OptionsDisplayer();
34     private final OptionsDisplayerImpl impl = new OptionsDisplayerImpl(false);
35     private static Logger JavaDoc log = Logger.getLogger(OptionsDisplayer.class.getName());
36         
37     private OptionsDisplayer() {}
38     /**
39      * Get the default <code>OptionsDisplayer</code>
40      * @return the default instance
41      */

42     public static OptionsDisplayer getDefault() {
43         return INSTANCE;
44     }
45     
46     /**
47      * Open the options dialog with no guarantee which category is pre-selected.
48      * @return true if optins dialog was sucesfully opened with some pre-selected
49      * category. If no category is registered at all then false will be returned and
50      * options dialog won't be opened.
51      */

52     public boolean open() {
53         return open(CategoryModel.getInstance().getCurrentCategoryID());
54     }
55     
56     /**
57      * Open the options dialog with some category pre-selected.
58      * @param categoryId ID representing required category which is registration name
59      * (e.g. "FooOptionsPanelID" for following registration:
60      * <pre style="background-color: rgb(255, 255, 153);">
61      * &lt;folder name="OptionsDialog"&gt;
62      * &lt;file name="FooOptionsPanelID.instance"&gt;
63      * &lt;attr name="instanceClass" stringvalue="org.foo.FooOptionsPanel"/&gt;
64      * &lt;/file&gt;
65      * &lt;/folder&gt;</pre>
66      * @return true if optins dialog was sucesfully opened with required category pre-selected.
67      * If this method is called when options dialog is already opened then this method
68      * will return immediately false without affecting currently selected category
69      * in opened options dialog.
70      * If <code>categoryId</code> passed as a parameter does not correspond to any
71      * of registered categories then false is returned and options dialog is not opened
72      * at all (e.g. in case that module providing such category is not installed or enabled).
73      */

74     public boolean open(final String JavaDoc categoryId) {
75         log.fine("Open Options Dialog: " + categoryId); //NOI18N
76
return openImpl(categoryId);
77     }
78     
79     private boolean openImpl(final String JavaDoc categoryId) {
80         Boolean JavaDoc retval = Mutex.EVENT.readAccess(new Mutex.Action<Boolean JavaDoc> () {
81             public Boolean JavaDoc run() {
82                 Boolean JavaDoc r = impl.isOpen();
83                 boolean retvalForRun = !r;
84                 if (retvalForRun) {
85                     retvalForRun = Arrays.asList(CategoryModel.getInstance().getCategoryIDs()).contains(categoryId);
86                     if (!retvalForRun) {
87                         log.warning("Unknown categoryId: " + categoryId); //NOI18N
88
}
89                 } else {
90                     log.warning("Options Dialog is opened"); //NOI18N
91
}
92                 if (retvalForRun) {
93                     impl.showOptionsDialog(categoryId);
94                 }
95                 return Boolean.valueOf(retvalForRun);
96             }
97         });
98         return retval;
99     }
100 }
Popular Tags