This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 227690
Collapse All | Expand All

(-)a/openide.awt/apichanges.xml (+13 lines)
Lines 52-57 Link Here
52
<changes>
52
<changes>
53
    <change id="Actions.checkbox.default">
53
    <change id="Actions.checkbox.default">
54
        <api name="awt"/>
54
        <api name="awt"/>
55
        <summary>Add notification category to the NotificationDisplayer API</summary>
56
        <version major="7" minor="57"/>
57
        <date day="20" month="3" year="2013"/>
58
        <author login="jpeska"/>
59
        <compatibility addition="yes" binary="compatible" semantic="compatible" deprecation="no" deletion="no" modification="no"/>
60
        <description>
61
            Clients can specify notification category. There are 3 default categories (Info, Warning, Error) but clients can also create a custom category using layer.xml
62
        </description>
63
        <class package="org.openide.awt" name="NotificationDisplayer"/>
64
        <issue number="227690"/>
65
    </change>
66
    <change id="Actions.checkbox.default">
67
        <api name="awt"/>
55
        <summary>The value in Preferences for Actions.checkbox can have a default</summary>
68
        <summary>The value in Preferences for Actions.checkbox can have a default</summary>
56
        <version major="7" minor="53"/>
69
        <version major="7" minor="53"/>
57
        <date day="18" month="9" year="2012"/>
70
        <date day="18" month="9" year="2012"/>
(-)a/openide.awt/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.awt
2
OpenIDE-Module: org.openide.awt
3
OpenIDE-Module-Localizing-Bundle: org/openide/awt/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/awt/Bundle.properties
4
AutoUpdate-Essential-Module: true
4
AutoUpdate-Essential-Module: true
5
OpenIDE-Module-Specification-Version: 7.56
5
OpenIDE-Module-Specification-Version: 7.57
6
6
(-)a/openide.awt/src/org/openide/awt/Bundle.properties (+7 lines)
Lines 143-145 Link Here
143
Yellow=Yellow
143
Yellow=Yellow
144
144
145
SelectColor=Select Color
145
SelectColor=Select Color
146
147
INFO_CATEGORY=Info
148
INFO_CATEGORY_DESCRIPTION=Informational notifications
149
WARNING_CATEGORY=Warning
150
WARNING_CATEGORY_DESCRIPTION=Warning notifications
151
ERROR_CATEGORY=Error
152
ERROR_CATEGORY_DESCRIPTION=Error notifications
(-)a/openide.awt/src/org/openide/awt/NotificationCategoryFactory.java (+148 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.openide.awt;
43
44
import java.util.ArrayList;
45
import java.util.HashMap;
46
import java.util.List;
47
import java.util.Map;
48
import java.util.ResourceBundle;
49
import org.openide.awt.NotificationDisplayer.Category;
50
import org.openide.util.Lookup;
51
import org.openide.util.LookupEvent;
52
import org.openide.util.LookupListener;
53
import org.openide.util.NbBundle;
54
import org.openide.util.lookup.Lookups;
55
56
/**
57
 *
58
 * @author jpeska
59
 */
60
class NotificationCategoryFactory {
61
62
    static final String ATTR_CATEGORY_NAME = "categoryName"; //NOI18N
63
    static final String ATTR_BUNDLE_NAME = "localizingBundle"; //NOI18N
64
    static final String ATTR_DISPLAY_NAME_KEY = "diplayNameKey"; //NOI18N
65
    static final String ATTR_DESCRIPTION_KEY = "descriptionKey"; //NOI18N
66
    private static final String CATEGORY_LIST_PATH = "Notification/Category"; //NOI18N
67
    private static NotificationCategoryFactory theInstance;
68
    private Lookup.Result<Category> lookupRes;
69
    private Map<String, Category> name2category;
70
    private List<Category> categories;
71
72
    private NotificationCategoryFactory() {
73
    }
74
75
    static Category create(Map<String, String> attrs) {
76
        String categoryName = attrs.get(ATTR_CATEGORY_NAME);
77
        String bundleName = attrs.get(ATTR_BUNDLE_NAME);
78
        String displayNameKey = attrs.get(ATTR_DISPLAY_NAME_KEY);
79
        String descriptionKey = attrs.get(ATTR_DESCRIPTION_KEY);
80
        return create(categoryName, bundleName, displayNameKey, descriptionKey);
81
    }
82
83
    static Category create(String categoryName, String bundleName, String displayNameKey, String descriptionKey) {
84
        ResourceBundle bundle = NbBundle.getBundle(bundleName);
85
        String displayName = bundle.getString(displayNameKey);
86
        String description = bundle.getString(descriptionKey);
87
        return new Category(categoryName, displayName, description);
88
    }
89
90
    /**
91
     * @return The one and only instance of this class.
92
     */
93
    public static NotificationCategoryFactory getInstance() {
94
        if (null == theInstance) {
95
            theInstance = new NotificationCategoryFactory();
96
        }
97
        return theInstance;
98
    }
99
100
    Category getCategory(String categoryName) {
101
        assert null != categoryName;
102
        synchronized (this) {
103
            initCategories();
104
            return name2category.get(categoryName);
105
        }
106
    }
107
108
    List<Category> getCategories() {
109
        synchronized (this) {
110
            initCategories();
111
            return categories;
112
        }
113
    }
114
115
    private void initCategories() {
116
        synchronized (this) {
117
            if (null == name2category) {
118
                if (null == lookupRes) {
119
                    lookupRes = initLookup();
120
                    lookupRes.addLookupListener(new LookupListener() {
121
                        @Override
122
                        public void resultChanged(LookupEvent ev) {
123
                            synchronized (NotificationCategoryFactory.this) {
124
                                name2category = null;
125
                                categories = null;
126
                            }
127
                        }
128
                    });
129
                }
130
                int index = 0;
131
                categories = new ArrayList<Category>(Category.getDefaultCategories());
132
                categories.addAll(lookupRes.allInstances());
133
                name2category = new HashMap<String, Category>(categories.size());
134
                for (Category c : categories) {
135
                    name2category.put(c.getName(), c);
136
                    c.setIndex(index++);
137
                }
138
            }
139
        }
140
    }
141
142
    private Lookup.Result<Category> initLookup() {
143
        Lookup lkp = Lookups.forPath(CATEGORY_LIST_PATH);
144
        Lookup.Template<Category> template = new Lookup.Template<Category>(Category.class);
145
        Lookup.Result<Category> res = lkp.lookup(template);
146
        return res;
147
    }
148
}
(-)a/openide.awt/src/org/openide/awt/NotificationDisplayer.java (-5 / +203 lines)
Lines 43-54 Link Here
43
package org.openide.awt;
43
package org.openide.awt;
44
44
45
import java.awt.event.ActionListener;
45
import java.awt.event.ActionListener;
46
import java.util.ArrayList;
47
import java.util.List;
48
import java.util.Map;
46
import java.util.logging.Level;
49
import java.util.logging.Level;
47
import java.util.logging.Logger;
50
import java.util.logging.Logger;
48
import javax.swing.Icon;
51
import javax.swing.Icon;
52
import javax.swing.ImageIcon;
49
import javax.swing.JComponent;
53
import javax.swing.JComponent;
50
import org.openide.awt.StatusDisplayer.Message;
54
import org.openide.awt.StatusDisplayer.Message;
55
import org.openide.util.ImageUtilities;
51
import org.openide.util.Lookup;
56
import org.openide.util.Lookup;
57
import org.openide.util.NbBundle;
52
58
53
/**
59
/**
54
 * Creates and shows clickable notifications in the main status line.
60
 * Creates and shows clickable notifications in the main status line.
Lines 63-76 Link Here
63
     * Priority of Notification
69
     * Priority of Notification
64
     */
70
     */
65
    public static enum Priority {
71
    public static enum Priority {
66
        HIGH,
72
        HIGH(new ImageIcon(ImageUtilities.loadImage("org/openide/awt/resources/priority_high.png"))), //NOI18N
67
        NORMAL,
73
        NORMAL(new ImageIcon(ImageUtilities.loadImage("org/openide/awt/resources/priority_normal.png"))), //NOI18N
68
        LOW,
74
        LOW(new ImageIcon(ImageUtilities.loadImage("org/openide/awt/resources/priority_low.png"))), //NOI18N
69
        /** Priority that shows the notification without details.
75
        /** Priority that shows the notification without details.
70
         * Details shall be shown only later, per user request.
76
         * Details shall be shown only later, per user request.
71
         * @since 7.18
77
         * @since 7.18
72
         */
78
         */
73
        SILENT
79
        SILENT(new ImageIcon(ImageUtilities.loadImage("org/openide/awt/resources/priority_silent.png"))); //NOI18N
80
81
        private final Icon icon;
82
83
        private Priority(Icon icon) {
84
            this.icon = icon;
85
        }
86
87
        /**
88
         * Returns priority icon
89
         *
90
         * @since 7.57
91
         */
92
        public Icon getIcon() {
93
            return icon;
94
        }
95
    }
96
97
    /**
98
     * Category of Notification, displayed in Notifications TC. Use one of the defaults categories (INFO, WARNING, ERROR) or create a custom category.
99
     *
100
     * To create a custom add following code to your <code>layer.xml</code>:
101
     * <pre>
102
     * {@code
103
     * <folder name="Notification">
104
     *      <folder name="Category">
105
     *          <file name="categoryA.instance">
106
     *              <attr name="instanceCreate" methodvalue="org.openide.awt.NotificationDisplayer.createCategory"/>
107
     *
108
     *              <attr name="localizingBundle" stringvalue="org.modules.mymodule.Bundle"/> <!-- Bundle file with used keys-->
109
     *              <attr name="categoryName" stringvalue="categoryA_name/> <!-- Actual category name-->
110
     *              <attr name="diplayNameKey" stringvalue="categoryA_displayName_key"/> <!-- Key to the Bundle file-->
111
     *              <attr name="descriptionKey" stringvalue="categoryA_description_key"/> <!-- Key to the Bundle file-->
112
     *          </file>
113
     *      </folder>
114
     * </folder>
115
     * }
116
     * </pre>
117
     *
118
     * @since 7.57
119
     */
120
    public static final class Category implements Comparable<Category>{
121
122
        public static final Category INFO = new Category("default_category_info", NbBundle.getMessage(NotificationDisplayer.class, "INFO_CATEGORY"), //NOI18N
123
                NbBundle.getMessage(NotificationDisplayer.class, "INFO_CATEGORY_DESCRIPTION")); //NOI18N
124
        public static final Category WARNING = new Category("default_category_warning", NbBundle.getMessage(NotificationDisplayer.class, "WARNING_CATEGORY"), //NOI18N
125
                NbBundle.getMessage(NotificationDisplayer.class, "WARNING_CATEGORY_DESCRIPTION")); //NOI18N
126
        public static final Category ERROR = new Category("default_category_error", NbBundle.getMessage(NotificationDisplayer.class, "ERROR_CATEGORY"), //NOI18N
127
                NbBundle.getMessage(NotificationDisplayer.class, "ERROR_CATEGORY_DESCRIPTION")); //NOI18N
128
129
        private final String name;
130
        private final String displayName;
131
        private final String description;
132
        private int index;
133
134
        Category(String name, String displayName, String description) {
135
            this.name = name;
136
            this.displayName = displayName;
137
            this.description = description;
138
        }
139
140
        /**
141
         * Returns category name - unique id
142
         *
143
         * @since 7.57
144
         */
145
        public String getName() {
146
            return name;
147
        }
148
149
         /**
150
         * Returns category display name
151
         *
152
         * @since 7.57
153
         */
154
        public String getDisplayName() {
155
            return displayName;
156
        }
157
158
        void setIndex(int index) {
159
            this.index = index;
160
        }
161
162
        /**
163
         * Returns category description
164
         *
165
         * @since 7.57
166
         */
167
        public String getDescription() {
168
            return description;
169
        }
170
171
        @Override
172
        public int compareTo(Category other) {
173
            return index - other.index;
174
        }
175
176
        /**
177
         * Returns all available categories
178
         *
179
         * @since 7.57
180
         */
181
        public static List<Category> getCategories() {
182
            return NotificationCategoryFactory.getInstance().getCategories();
183
        }
184
185
        static List<Category> getDefaultCategories() {
186
            List<Category> defaultCategories = new ArrayList<Category>();
187
            defaultCategories.add(ERROR);
188
            defaultCategories.add(WARNING);
189
            defaultCategories.add(INFO);
190
            return defaultCategories;
191
        }
74
    }
192
    }
75
193
76
    /**
194
    /**
Lines 120-125 Link Here
120
            String detailsText, ActionListener detailsAction, Priority priority);
238
            String detailsText, ActionListener detailsAction, Priority priority);
121
239
122
    /**
240
    /**
241
     * Create and show new notification.
242
     * @param title Notification title. Html is not supported, any html tags will
243
     * be escaped.
244
     * @param icon Notification icon
245
     * @param detailsText Detailed description of the notification. If detailsAction
246
     * is non-null then this text will be presented as a clickable link. Html is
247
     * not supported, any html tags will be escaped.
248
     * @param detailsAction Action to invoke when user click details text or null.
249
     * @param priority Notification priority
250
     * @param category Notification category.
251
     * @return New notification.
252
     * @since 7.57
253
     */
254
    public Notification notify(String title, Icon icon,
255
            String detailsText, ActionListener detailsAction, Priority priority, Category category) {
256
        return notify(title, icon, detailsText, detailsAction, priority);
257
    }
258
259
    /**
260
     * Create and show new notification.
261
     *
262
     * @param title Notification title. Html is not supported, any html tags will be escaped.
263
     * @param icon Notification icon
264
     * @param detailsText Detailed description of the notification. If detailsAction
265
     * is non-null then this text will be presented as a clickable link. Html is
266
     * not supported, any html tags will be escaped.
267
     * @param detailsAction Action to invoke when user click details text or null.
268
     * @param priority Notification priority
269
     * @param categoryName Notification category name, refers to a custom category created in e.g. layer.xml.
270
     * @return New notification.
271
     * @since 7.57
272
     */
273
    public Notification notify(String title, Icon icon,
274
            String detailsText, ActionListener detailsAction, Priority priority, String categoryName) {
275
        return notify(title, icon, detailsText, detailsAction, priority, NotificationCategoryFactory.getInstance().getCategory(categoryName));
276
    }
277
278
    /**
123
     * Create and show new notification with customized content.
279
     * Create and show new notification with customized content.
124
     * @param title Notification title. Html is not supported, any html tags will
280
     * @param title Notification title. Html is not supported, any html tags will
125
     * be escaped.
281
     * be escaped.
Lines 127-133 Link Here
127
     * @param balloonDetails Component that will show below notification title 
283
     * @param balloonDetails Component that will show below notification title 
128
     * in a balloon.
284
     * in a balloon.
129
     * @param popupDetails Component that will show below notification title
285
     * @param popupDetails Component that will show below notification title
130
     * in notifications popup list. 
286
     * in notifications list. 
131
     * @param priority Notification priority.
287
     * @param priority Notification priority.
132
     * @return New notification.
288
     * @return New notification.
133
     */
289
     */
Lines 135-140 Link Here
135
            JComponent balloonDetails, JComponent popupDetails, Priority priority);
291
            JComponent balloonDetails, JComponent popupDetails, Priority priority);
136
292
137
    /**
293
    /**
294
     * Create and show new notification with customized content.
295
     * @param title Notification title. Html is not supported, any html tags will
296
     * be escaped.
297
     * @param icon Notification icon
298
     * @param balloonDetails Component that will show below notification title
299
     * in a balloon.
300
     * @param popupDetails Component that will show below notification title
301
     * in notifications list.
302
     * @param priority Notification priority.
303
     * @param category Notification category.
304
     * @return New notification.
305
     * @since 7.57
306
     */
307
    public Notification notify(String title, Icon icon,
308
            JComponent balloonDetails, JComponent popupDetails, Priority priority, Category category) {
309
        return notify(title, icon, balloonDetails, popupDetails, priority);
310
    }
311
312
    /**
313
     Create and show new notification with customized content.
314
     * @param title Notification title. Html is not supported, any html tags will
315
     * be escaped.
316
     * @param icon Notification icon
317
     * @param balloonDetails Component that will show below notification title
318
     * in a balloon.
319
     * @param popupDetails Component that will show below notification title
320
     * in notifications list.
321
     * @param priority Notification priority.
322
     * @param categoryName Notification category name, refers to a custom category created in e.g. layer.xml.
323
     * @return New notification.
324
     * @since 7.57
325
     */
326
    public Notification notify(String title, Icon icon,
327
            JComponent balloonDetails, JComponent popupDetails, Priority priority, String categoryName) {
328
        return notify(title, icon, balloonDetails, popupDetails, priority, NotificationCategoryFactory.getInstance().getCategory(categoryName));
329
    }
330
331
    static Category createCategory(Map<String, String> attrs) {
332
        return NotificationCategoryFactory.create(attrs);
333
    }
334
335
    /**
138
     * Simple implementation of NotificationDisplayer which shows the notifications
336
     * Simple implementation of NotificationDisplayer which shows the notifications
139
     * on the main status line.
337
     * on the main status line.
140
     */
338
     */
(-)a/openide.awt/test/unit/src/org/openide/awt/NotificationCategoryFactoryTest.java (+235 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.openide.awt;
43
44
import java.beans.PropertyVetoException;
45
import java.io.File;
46
import java.io.IOException;
47
import java.net.URL;
48
import java.net.URLStreamHandler;
49
import java.net.URLStreamHandlerFactory;
50
import java.util.Enumeration;
51
import java.util.List;
52
import junit.framework.Assert;
53
import static junit.framework.Assert.assertEquals;
54
import static junit.framework.Assert.assertFalse;
55
import static junit.framework.Assert.assertNotNull;
56
import static junit.framework.Assert.assertNull;
57
import static junit.framework.Assert.fail;
58
import org.netbeans.junit.Manager;
59
import org.netbeans.junit.NbTestCase;
60
import org.openide.awt.NotificationDisplayer.Category;
61
import org.openide.filesystems.FileObject;
62
import org.openide.filesystems.FileSystem;
63
import org.openide.filesystems.FileUtil;
64
import org.openide.filesystems.MultiFileSystem;
65
import org.openide.filesystems.Repository;
66
import org.openide.filesystems.XMLFileSystem;
67
import org.openide.util.Lookup;
68
import org.openide.util.lookup.Lookups;
69
import org.openide.util.lookup.ProxyLookup;
70
71
/**
72
 *
73
 * @author jpeska
74
 */
75
public class NotificationCategoryFactoryTest extends NbTestCase {
76
77
    public static final String CATEGORY_NAME_A = "nb-notification-unittestA";
78
    public static final String CATEGORY_DISPLAY_NAME_A = "unitTestCategoryLabelA";
79
    public static final String CATEGORY_DESCRIPTION_A = "unitTestCategoryDescriptionA";
80
    public static final String CATEGORY_NAME_B = "nb-notification-unittestB";
81
    public static final String CATEGORY_DISPLAY_NAME_B = "unitTestCategoryLabelB";
82
    public static final String CATEGORY_DESCRIPTION_B = "unitTestCategoryDescriptionB";
83
    public static final String CATEGORY_NAME_C = "nb-notification-unittestC";
84
    public static final String CATEGORY_DISPLAY_NAME_C = "unitTestCategoryLabelC";
85
    public static final String CATEGORY_DESCRIPTION_C = "unitTestCategoryDescriptionC";
86
87
    static {
88
        String[] layers = new String[]{"org/openide/awt/mf-layer.xml"};//NOI18N
89
        IDEInitializer.setup(layers, new Object[0]);
90
    }
91
92
    public NotificationCategoryFactoryTest(String name) {
93
        super(name);
94
    }
95
96
    public void testGetCategory() {
97
        NotificationCategoryFactory factory = NotificationCategoryFactory.getInstance();
98
99
        List<? extends Category> categories = factory.getCategories();
100
        categories.removeAll(Category.getDefaultCategories());
101
        assertEquals(2, categories.size());
102
103
        Category cA = categories.get(0);
104
        assertEquals(CATEGORY_NAME_A, cA.getName());
105
        assertEquals(CATEGORY_DISPLAY_NAME_A, cA.getDisplayName());
106
        assertEquals(CATEGORY_DESCRIPTION_A, cA.getDescription());
107
108
        Category cB = categories.get(1);
109
        assertEquals(CATEGORY_NAME_B, cB.getName());
110
        assertEquals(CATEGORY_DISPLAY_NAME_B, cB.getDisplayName());
111
        assertEquals(CATEGORY_DESCRIPTION_B, cB.getDescription());
112
113
        assertFalse(cA.equals(cB));
114
115
        Category category = factory.getCategory(CATEGORY_NAME_A);
116
        assertNotNull(category);
117
        assertEquals(CATEGORY_NAME_A, category.getName());
118
119
        category = factory.getCategory(CATEGORY_NAME_B);
120
        assertNotNull(category);
121
122
        category = factory.getCategory("unknown category name");
123
        assertNull(category);
124
125
        try {
126
            factory.getCategory(null);
127
            fail("null category name is not acceptable");
128
        } catch (AssertionError e) {
129
            //expected
130
        }
131
    }
132
133
    public void testCreate() {
134
        Category category = NotificationCategoryFactory.create(CATEGORY_NAME_C,
135
                "org.openide.awt.TestBundle",
136
                "LBL_unittest_categoryC",
137
                "HINT_unittest_categoryC");
138
139
        assertNotNull(category);
140
        assertEquals(CATEGORY_NAME_C, category.getName());
141
        assertEquals(CATEGORY_DISPLAY_NAME_C, category.getDisplayName());
142
        assertEquals(CATEGORY_DESCRIPTION_C, category.getDescription());
143
    }
144
145
    public static class IDEInitializer extends ProxyLookup {
146
147
        public static IDEInitializer DEFAULT_LOOKUP = null;
148
        private static FileSystem lfs;
149
150
        static {
151
            IDEInitializer.class.getClassLoader().setDefaultAssertionStatus(true);
152
            System.setProperty("org.openide.util.Lookup", IDEInitializer.class.getName());
153
            Assert.assertEquals(IDEInitializer.class, Lookup.getDefault().getClass());
154
        }
155
156
        public IDEInitializer() {
157
            Assert.assertNull(DEFAULT_LOOKUP);
158
            DEFAULT_LOOKUP = this;
159
            URL.setURLStreamHandlerFactory(new MyURLHandlerFactory());
160
        }
161
162
        /**
163
         * Set the global default lookup with the specified content.
164
         *
165
         * @param layers xml-layer URLs to be present in the system filesystem.
166
         * @param instances object instances to be present in the default lookup.
167
         */
168
        public static void setup(
169
                String[] layers,
170
                Object[] instances) {
171
            ClassLoader classLoader = IDEInitializer.class.getClassLoader();
172
            File workDir = new File(Manager.getWorkDirPath());
173
            URL[] urls = new URL[layers.length];
174
            int i, k = urls.length;
175
            for (i = 0; i < k; i++) {
176
                urls[i] = classLoader.getResource(layers[i]);
177
            }
178
179
            // 1) create repository
180
            XMLFileSystem systemFS = new XMLFileSystem();
181
            lfs = FileUtil.createMemoryFileSystem();
182
            try {
183
                systemFS.setXmlUrls(urls);
184
            } catch (Exception ex) {
185
                ex.printStackTrace();
186
            }
187
            MyFileSystem myFileSystem = new MyFileSystem(
188
                    new FileSystem[]{lfs, systemFS});
189
            Repository repository = new Repository(myFileSystem);
190
191
            Object[] lookupContent = new Object[instances.length + 1];
192
            lookupContent[0] = repository;
193
            System.arraycopy(instances, 0, lookupContent, 1, instances.length);
194
195
            DEFAULT_LOOKUP.setLookups(new Lookup[]{
196
                Lookups.fixed(lookupContent),
197
                Lookups.metaInfServices(classLoader),
198
                Lookups.singleton(classLoader),});
199
            Assert.assertTrue(myFileSystem.isDefault());
200
        }
201
202
        public static void cleanWorkDir() {
203
            try {
204
                Enumeration en = lfs.getRoot().getChildren(false);
205
                while (en.hasMoreElements()) {
206
                    ((FileObject) en.nextElement()).delete();
207
                }
208
            } catch (IOException ex) {
209
                ex.printStackTrace();
210
            }
211
        }
212
213
        private static class MyFileSystem extends MultiFileSystem {
214
215
            public MyFileSystem(FileSystem[] fileSystems) {
216
                super(fileSystems);
217
                try {
218
                    setSystemName("TestFS");
219
                } catch (PropertyVetoException ex) {
220
                    ex.printStackTrace();
221
                }
222
            }
223
        }
224
225
        private static class MyURLHandlerFactory implements URLStreamHandlerFactory {
226
227
            public URLStreamHandler createURLStreamHandler(String protocol) {
228
                if (protocol.equals("nbfs")) {
229
                    return FileUtil.nbfsURLStreamHandler();
230
                }
231
                return null;
232
            }
233
        }
234
    }
235
}
(-)a/openide.awt/test/unit/src/org/openide/awt/TestBundle.properties (+8 lines)
Lines 46-48 Link Here
46
Callback=Close
46
Callback=Close
47
NumberLover=Number lover!
47
NumberLover=Number lover!
48
48
49
LBL_unittest_categoryA=unitTestCategoryLabelA
50
HINT_unittest_categoryA=unitTestCategoryDescriptionA
51
52
LBL_unittest_categoryB=unitTestCategoryLabelB
53
HINT_unittest_categoryB=unitTestCategoryDescriptionB
54
55
LBL_unittest_categoryC=unitTestCategoryLabelC
56
HINT_unittest_categoryC=unitTestCategoryDescriptionC
(-)a/openide.awt/test/unit/src/org/openide/awt/mf-layer.xml (+72 lines)
Line 0 Link Here
1
<?xml version="1.0"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
6
7
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8
Other names may be trademarks of their respective owners.
9
10
11
The contents of this file are subject to the terms of either the GNU
12
General Public License Version 2 only ("GPL") or the Common
13
Development and Distribution License("CDDL") (collectively, the
14
"License"). You may not use this file except in compliance with the
15
License. You can obtain a copy of the License at
16
http://www.netbeans.org/cddl-gplv2.html
17
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
18
specific language governing permissions and limitations under the
19
License.  When distributing the software, include this License Header
20
Notice in each file and include the License file at
21
nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
22
particular file as subject to the "Classpath" exception as provided
23
by Oracle in the GPL Version 2 section of the License file that
24
accompanied this code. If applicable, add the following below the
25
License Header, with the fields enclosed by brackets [] replaced by
26
your own identifying information:
27
"Portions Copyrighted [year] [name of copyright owner]"
28
29
Contributor(s):
30
31
The Original Software is NetBeans. The Initial Developer of the Original
32
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
33
Microsystems, Inc. All Rights Reserved.
34
35
If you wish your version of this file to be governed by only the CDDL
36
or only the GPL Version 2, indicate your decision by adding
37
"[Contributor] elects to include this software in this distribution
38
under the [CDDL or GPL Version 2] license." If you do not indicate a
39
single choice of license, a recipient has the option to distribute
40
your version of this file under either the CDDL, the GPL Version 2 or
41
to extend the choice of license to its licensees as provided above.
42
However, if you add GPL Version 2 code and therefore, elected the GPL
43
Version 2 license, then the option applies only if the new code is
44
made subject to such option by the copyright holder.
45
-->
46
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.0//EN" "http://www.netbeans.org/dtds/filesystem-1_0.dtd">
47
48
<filesystem>
49
    <folder name="Notification">
50
        <folder name="Category">
51
            <file name="unittestA.instance">
52
                <attr name="instanceCreate" methodvalue="org.openide.awt.NotificationDisplayer.createCategory"/>
53
                
54
                <attr name="localizingBundle" stringvalue="org.openide.awt.TestBundle"/>
55
                <attr name="categoryName" stringvalue="nb-notification-unittestA"/>
56
                <attr name="diplayNameKey" stringvalue="LBL_unittest_categoryA"/>
57
                <attr name="descriptionKey" stringvalue="HINT_unittest_categoryA"/>
58
            </file>
59
60
            <file name="unittestB.instance">
61
                <attr name="instanceCreate" methodvalue="org.openide.awt.NotificationDisplayer.createCategory"/>
62
                
63
                <attr name="localizingBundle" stringvalue="org.openide.awt.TestBundle"/>
64
                <attr name="categoryName" stringvalue="nb-notification-unittestB"/>
65
                <attr name="diplayNameKey" stringvalue="LBL_unittest_categoryB"/>
66
                <attr name="descriptionKey" stringvalue="HINT_unittest_categoryB"/>
67
            </file>
68
            
69
            <attr name="unittestA.instance/unittestB.instance" boolvalue="true"/>
70
        </folder>
71
    </folder>
72
</filesystem>

Return to bug 227690