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 191407
Collapse All | Expand All

(-)a/openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java (-1 / +7 lines)
Lines 277-283 Link Here
277
            if (e.getAnnotation(ActionRegistration.class) != null) {
277
            if (e.getAnnotation(ActionRegistration.class) != null) {
278
                continue;
278
                continue;
279
            }
279
            }
280
            throw new LayerGenerationException("Don't use @ActionReference without @ActionRegistration", e);
280
            ActionID id = e.getAnnotation(ActionID.class);
281
            if (id != null) {
282
                ActionReference ref = e.getAnnotation(ActionReference.class);
283
                processReferences(e, ref, id);
284
                continue;
285
            }
286
            throw new LayerGenerationException("Don't use @ActionReference without @ActionID", e);
281
        }
287
        }
282
        for (Element e : roundEnv.getElementsAnnotatedWith(ActionReferences.class)) {
288
        for (Element e : roundEnv.getElementsAnnotatedWith(ActionReferences.class)) {
283
            if (e.getAnnotation(ActionRegistration.class) != null) {
289
            if (e.getAnnotation(ActionRegistration.class) != null) {
(-)a/openide.windows/nbproject/project.xml (+5 lines)
Lines 58-63 Link Here
58
                    </run-dependency>
58
                    </run-dependency>
59
                </dependency>
59
                </dependency>
60
                <dependency>
60
                <dependency>
61
                    <code-name-base>org.openide.filesystems</code-name-base>
62
                    <build-prerequisite/>
63
                    <compile-dependency/>
64
                </dependency>
65
                <dependency>
61
                    <code-name-base>org.openide.nodes</code-name-base>
66
                    <code-name-base>org.openide.nodes</code-name-base>
62
                    <build-prerequisite/>
67
                    <build-prerequisite/>
63
                    <compile-dependency/>
68
                    <compile-dependency/>
(-)0f6ce06434f3 (+165 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 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 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.openide.windows;
44
45
import java.util.HashSet;
46
import java.util.Set;
47
import javax.annotation.processing.Processor;
48
import javax.annotation.processing.RoundEnvironment;
49
import javax.annotation.processing.SupportedSourceVersion;
50
import javax.lang.model.SourceVersion;
51
import javax.lang.model.element.Element;
52
import javax.lang.model.element.TypeElement;
53
import javax.lang.model.type.DeclaredType;
54
import javax.lang.model.type.ExecutableType;
55
import org.openide.awt.ActionID;
56
import org.openide.filesystems.annotations.LayerBuilder.File;
57
import org.openide.filesystems.annotations.LayerGeneratingProcessor;
58
import org.openide.filesystems.annotations.LayerGenerationException;
59
import org.openide.util.lookup.ServiceProvider;
60
import org.openide.windows.TopComponent;
61
import org.openide.windows.TopComponent.Description;
62
63
@SupportedSourceVersion(SourceVersion.RELEASE_6)
64
@ServiceProvider(service=Processor.class)
65
public final class TopComponentProcessor extends LayerGeneratingProcessor {
66
    public TopComponentProcessor() {
67
    }
68
69
    @Override
70
    public Set<String> getSupportedAnnotationTypes() {
71
        Set<String> hash = new HashSet<String>();
72
        hash.add(TopComponent.Registration.class.getCanonicalName());
73
        hash.add(TopComponent.OpenActionRegistration.class.getCanonicalName());
74
        hash.add(TopComponent.Description.class.getCanonicalName());
75
        return hash;
76
    }
77
    
78
    @Override
79
    protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws LayerGenerationException {
80
        for (Element e : roundEnv.getElementsAnnotatedWith(TopComponent.Registration.class)) {
81
            TopComponent.Registration reg = e.getAnnotation(TopComponent.Registration.class);
82
            assert reg != null;
83
            
84
            Description info = findInfo(e);
85
            String id = info.preferredID().replace('.', '-');
86
            
87
            File settingsFile = layer(e).
88
                file("Windows2/Components/" + id + ".settings").
89
                contents(settingsFile(e));
90
            settingsFile.write();
91
            
92
            File modeFile = layer(e).
93
                file("Windows2/Modes/" + reg.mode() + "/" + id + ".wstcref").
94
                contents(modeFile(info.preferredID(), reg.openAtStartup()));
95
            modeFile.write();
96
        }
97
        
98
        for (Element e : roundEnv.getElementsAnnotatedWith(TopComponent.OpenActionRegistration.class)) {
99
            TopComponent.OpenActionRegistration reg = e.getAnnotation(TopComponent.OpenActionRegistration.class);
100
            assert reg != null;
101
            Description info = findInfo(e);
102
            
103
            ActionID aid = e.getAnnotation(ActionID.class);
104
            if (aid != null) {
105
                File actionFile = layer(e).
106
                    file("Actions/" + aid.category() + "/" + aid.id().replace('.', '-') + ".instance").
107
                    methodvalue("instanceCreate", "org.openide.windows.TopComponent", "openAction");
108
                actionFile.instanceAttribute("component", TopComponent.class);
109
                if (reg.preferredID().length() > 0) {
110
                    actionFile.stringvalue("preferredID", reg.preferredID());
111
                }
112
                actionFile.bundlevalue("displayName", reg.displayName());
113
                if (info != null && info.iconBase().length() > 0) {
114
                    actionFile.stringvalue("iconBase", info.iconBase());
115
                }
116
                actionFile.write();
117
            }
118
        }
119
        return true;
120
    }
121
122
    private Description findInfo(Element e) throws LayerGenerationException {
123
        Element type;
124
        switch (e.asType().getKind()) {
125
            case DECLARED: type = e; break;
126
            case EXECUTABLE: type = ((DeclaredType)((ExecutableType)e.asType()).getReturnType()).asElement(); break;
127
            default: throw new LayerGenerationException("" + e.asType().getKind(), e);    
128
        }
129
        TopComponent.Description info = type.getAnnotation(TopComponent.Description.class);
130
        return info;
131
    }
132
133
    private static String settingsFile(Element e) throws LayerGenerationException {
134
        String clazz, method;
135
        switch (e.getKind()) {
136
            case CLASS: clazz = e.toString(); method = null; break;
137
            case METHOD: clazz = e.getEnclosingElement().toString(); method = e.getSimpleName().toString(); break;
138
            default:
139
                throw new LayerGenerationException("Cannot work on given element", e);
140
        }
141
        StringBuilder sb = new StringBuilder();
142
        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
143
        sb.append("<!DOCTYPE settings PUBLIC \"-//NetBeans//DTD Session settings 1.0//EN\" \"http://www.netbeans.org/dtds/sessionsettings-1_0.dtd\">\n");
144
        sb.append("<settings version=\"1.0\">\n");
145
        sb.append("  <instance class=\"").append(clazz).append("\"");
146
        if (method != null) {
147
            sb.append(" method=\"").append(method).append("\"");
148
        }
149
        sb.append("/>\n");
150
        sb.append("</settings>\n");
151
        return sb.toString();
152
    }
153
    
154
    private static String modeFile(String id, boolean openAtStart) 
155
    throws LayerGenerationException {
156
        StringBuilder sb = new StringBuilder();
157
        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
158
        sb.append("<!DOCTYPE tc-ref PUBLIC \"-//NetBeans//DTD Top Component in Mode Properties 2.0//EN\" \"http://www.netbeans.org/dtds/tc-ref2_0.dtd\">\n");
159
        sb.append("<tc-ref version=\"2.0\">\n");
160
        sb.append("  <tc-id id=\"").append(id).append("\"/>\n");
161
        sb.append("  <state opened=\"").append(openAtStart).append("\"/>\n");
162
        sb.append("</tc-ref>\n");
163
        return sb.toString();
164
    }
165
}
(-)a/openide.windows/src/org/openide/windows/OpenComponentAction.java (-3 / +14 lines)
Lines 47-52 Link Here
47
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionListener;
48
import java.awt.event.ActionListener;
49
import java.util.Map;
49
import java.util.Map;
50
import org.openide.util.Exceptions;
51
import org.openide.util.Lookup;
50
52
51
/** Opens a top component.
53
/** Opens a top component.
52
 *
54
 *
Lines 71-79 Link Here
71
        if (component != null) {
73
        if (component != null) {
72
            return component;
74
            return component;
73
        }
75
        }
74
        component = (TopComponent)map.get("component"); // NOI18N
76
        TopComponent c = null;
75
        assert component != null : "Component cannot be created for " + map;
77
        Object id = map.get("preferredID"); // NOI18N
76
        return component;
78
        if (id instanceof String) {
79
            c = WindowManager.getDefault().findTopComponent((String)id);
80
        }
81
        if (c == null) {
82
            c = (TopComponent)map.get("component");
83
        }
84
        if (id != null) {
85
            component = c;
86
        }
87
        return c;
77
    }
88
    }
78
89
79
    public void actionPerformed(ActionEvent e) {
90
    public void actionPerformed(ActionEvent e) {
(-)a/openide.windows/src/org/openide/windows/TopComponent.java (-1 / +77 lines)
Lines 60-65 Link Here
60
import java.io.ObjectOutputStream;
60
import java.io.ObjectOutputStream;
61
import java.io.ObjectStreamException;
61
import java.io.ObjectStreamException;
62
import java.io.Serializable;
62
import java.io.Serializable;
63
import java.lang.annotation.ElementType;
64
import java.lang.annotation.Retention;
65
import java.lang.annotation.RetentionPolicy;
66
import java.lang.annotation.Target;
63
import java.lang.ref.Reference;
67
import java.lang.ref.Reference;
64
import java.lang.ref.WeakReference;
68
import java.lang.ref.WeakReference;
65
import java.lang.reflect.InvocationTargetException;
69
import java.lang.reflect.InvocationTargetException;
Lines 85-90 Link Here
85
import javax.swing.Timer;
89
import javax.swing.Timer;
86
import javax.swing.plaf.basic.BasicHTML;
90
import javax.swing.plaf.basic.BasicHTML;
87
import javax.swing.text.Keymap;
91
import javax.swing.text.Keymap;
92
import org.openide.awt.ActionID;
88
import org.openide.awt.Actions;
93
import org.openide.awt.Actions;
89
import org.openide.awt.UndoRedo;
94
import org.openide.awt.UndoRedo;
90
import org.openide.nodes.Node;
95
import org.openide.nodes.Node;
Lines 92-97 Link Here
92
import org.openide.nodes.NodeListener;
97
import org.openide.nodes.NodeListener;
93
import org.openide.util.ContextAwareAction;
98
import org.openide.util.ContextAwareAction;
94
import org.openide.util.HelpCtx;
99
import org.openide.util.HelpCtx;
100
import org.openide.util.ImageUtilities;
95
import org.openide.util.Lookup;
101
import org.openide.util.Lookup;
96
import org.openide.util.NbBundle;
102
import org.openide.util.NbBundle;
97
import org.openide.util.NbPreferences;
103
import org.openide.util.NbPreferences;
Lines 429-434 Link Here
429
     * @since 4.20
435
     * @since 4.20
430
     */
436
     */
431
    public int getPersistenceType() {
437
    public int getPersistenceType() {
438
        Description info = getClass().getAnnotation(Description.class); 
439
        if (info != null) {
440
            return info.persistenceType();
441
        }
442
        
432
        //First check for 'PersistenceType' client property for compatibility.
443
        //First check for 'PersistenceType' client property for compatibility.
433
        if (warnedClasses.add(getClass()) && !TopComponent.class.equals(getClass())) {
444
        if (warnedClasses.add(getClass()) && !TopComponent.class.equals(getClass())) {
434
            Logger.getAnonymousLogger().warning(
445
            Logger.getAnonymousLogger().warning(
Lines 704-709 Link Here
704
    }
715
    }
705
716
706
    /**
717
    /**
718
     * Rather than overriding this method, consider using {@link Description}.
707
     * Subclasses are encouraged to override this method to provide preferred value
719
     * Subclasses are encouraged to override this method to provide preferred value
708
     * for unique TopComponent ID returned by {@link org.openide.windows.WindowManager#findTopComponentID}.
720
     * for unique TopComponent ID returned by {@link org.openide.windows.WindowManager#findTopComponentID}.
709
     *
721
     *
Lines 716-722 Link Here
716
     * @since 4.13
728
     * @since 4.13
717
     */
729
     */
718
    protected String preferredID() {
730
    protected String preferredID() {
719
        Class clazz = getClass();
731
        Class<?> clazz = getClass();
732
        Description id = clazz.getAnnotation(Description.class);
733
        if (id != null) {
734
            return id.preferredID();
735
        }
720
736
721
        if (getPersistenceType() != PERSISTENCE_NEVER && warnedTCPIClasses.add(clazz)) {
737
        if (getPersistenceType() != PERSISTENCE_NEVER && warnedTCPIClasses.add(clazz)) {
722
            Logger.getAnonymousLogger().warning(
738
            Logger.getAnonymousLogger().warning(
Lines 1029-1034 Link Here
1029
1045
1030
    /** @return The icon of the top component */
1046
    /** @return The icon of the top component */
1031
    public Image getIcon() {
1047
    public Image getIcon() {
1048
        Description id;
1049
        if (icon == null && (id = getClass().getAnnotation(Description.class)) != null) {
1050
            icon = ImageUtilities.loadImage(id.iconBase(), true);
1051
        }
1032
        return icon;
1052
        return icon;
1033
    }
1053
    }
1034
1054
Lines 1357-1362 Link Here
1357
        */
1377
        */
1358
        public TopComponent cloneComponent();
1378
        public TopComponent cloneComponent();
1359
    }
1379
    }
1380
    
1381
    /** Provides basic information about the persistence of a {@link TopComponent}.
1382
     * Using this annotation is preferred to overriding {@link #preferredID()}
1383
     * or calling {@link #setIcon(java.awt.Image)}.
1384
     * @since 6.36
1385
     */
1386
    @Retention(RetentionPolicy.RUNTIME)
1387
    @Target(ElementType.TYPE)
1388
    public static @interface Description {
1389
        /** The default value for {@link TopComponent#preferredID()}.
1390
         */
1391
        public String preferredID();
1392
        /** The icon to load for {@link TopComponent#getIcon()}.
1393
         */
1394
        public String iconBase() default "";
1395
        /** Default value for {@link TopComponent#getPersistenceType()}. 
1396
         * 
1397
         * @return one of {@link TopComponent#PERSISTENCE_ALWAYS}, 
1398
         * {@link TopComponent#PERSISTENCE_NEVER}, 
1399
         * {@link TopComponent#PERSISTENCE_ONLY_OPENED}
1400
         * 
1401
         */
1402
        public int persistenceType() default PERSISTENCE_ALWAYS;
1403
    }
1404
    
1405
    /** Registers {@link TopComponent} into specified location.
1406
     * @since 6.36
1407
     */
1408
    @Retention(RetentionPolicy.SOURCE)
1409
    @Target({ ElementType.TYPE, ElementType.METHOD })
1410
    public static @interface Registration {
1411
        /** Name of the mode the component shall be opened in */
1412
        String mode();
1413
        /** Shall the component be opened at start */
1414
        boolean openAtStartup();
1415
    }
1416
    
1417
    /** Creates an action that can open the component.
1418
     * The action is generated only
1419
     * if {@link ActionID} annotation is used on the same element, otherwise
1420
     * a compilation error is raised.
1421
     * @since 6.36
1422
     */
1423
    @Retention(RetentionPolicy.SOURCE)
1424
    @Target({ ElementType.TYPE, ElementType.METHOD })
1425
    public static @interface OpenActionRegistration {
1426
        /** Display name of the action, usually can refer to value from a
1427
         * <code>Bundle.properties</code> using <code>#KEY</code>.
1428
         */
1429
        String displayName();
1430
        /** Shall the action first seek for a component with such ID
1431
         * before creating new instance of the component?
1432
         * @return the {@link TopComponent#preferredID()} to seek for
1433
         */
1434
        String preferredID() default "";
1435
    }
1360
1436
1361
    /** Registry of all top components.
1437
    /** Registry of all top components.
1362
    * There is one instance that can be obtained via {@link TopComponent#getRegistry}
1438
    * There is one instance that can be obtained via {@link TopComponent#getRegistry}
(-)0f6ce06434f3 (+44 lines)
Added Link Here
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
4
#
5
# Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
# Other names may be trademarks of their respective owners.
7
#
8
# The contents of this file are subject to the terms of either the GNU
9
# General Public License Version 2 only ("GPL") or the Common
10
# Development and Distribution License("CDDL") (collectively, the
11
# "License"). You may not use this file except in compliance with the
12
# License. You can obtain a copy of the License at
13
# http://www.netbeans.org/cddl-gplv2.html
14
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
15
# specific language governing permissions and limitations under the
16
# License.  When distributing the software, include this License Header
17
# Notice in each file and include the License file at
18
# nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
19
# particular file as subject to the "Classpath" exception as provided
20
# by Oracle in the GPL Version 2 section of the License file that
21
# accompanied this code. If applicable, add the following below the
22
# License Header, with the fields enclosed by brackets [] replaced by
23
# your own identifying information:
24
# "Portions Copyrighted [year] [name of copyright owner]"
25
#
26
# Contributor(s):
27
#
28
# The Original Software is NetBeans. The Initial Developer of the Original
29
# Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
30
# Microsystems, Inc. All Rights Reserved.
31
#
32
# If you wish your version of this file to be governed by only the CDDL
33
# or only the GPL Version 2, indicate your decision by adding
34
# "[Contributor] elects to include this software in this distribution
35
# under the [CDDL or GPL Version 2] license." If you do not indicate a
36
# single choice of license, a recipient has the option to distribute
37
# your version of this file under either the CDDL, the GPL Version 2 or
38
# to extend the choice of license to its licensees as provided above.
39
# However, if you add GPL Version 2 code and therefore, elected the GPL
40
# Version 2 license, then the option applies only if the new code is
41
# made subject to such option by the copyright holder.
42
43
44
TEST_ACTION=Hello TC!
(-)0f6ce06434f3 (+155 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 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 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.openide.windows;
44
45
import java.awt.EventQueue;
46
import java.awt.event.ActionEvent;
47
import java.io.ByteArrayInputStream;
48
import java.util.Arrays;
49
import javax.swing.Action;
50
import javax.xml.parsers.DocumentBuilder;
51
import javax.xml.parsers.DocumentBuilderFactory;
52
import org.netbeans.junit.NbTestCase;
53
import org.openide.awt.ActionID;
54
import org.openide.awt.ActionReference;
55
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileUtil;
57
import org.openide.windows.TopComponent;
58
import org.w3c.dom.Document;
59
60
public class TopComponentProcessorTest extends  NbTestCase {
61
62
    public TopComponentProcessorTest(String n) {
63
        super(n);
64
    }
65
66
    @Override
67
    protected boolean runInEQ() {
68
        return getName().contains("InEQ");
69
    }
70
71
    public void testTCRegisteredFine() throws Exception {
72
        FileObject set = FileUtil.getConfigFile("Windows2/Components/my-tc.settings");
73
        assertNotNull("Settings file found", set);
74
        assertValidate(set.asText());
75
    }
76
77
    public void testModeIsOK() throws Exception {
78
        FileObject set = FileUtil.getConfigFile("Windows2/Modes/output/my-tc.wstcref");
79
        assertNotNull("Mode file found", set);
80
        final String t = set.asText();
81
        assertValidate(t);
82
        assertEquals("not opened, no true in there", -1, t.indexOf("true"));
83
    }
84
    
85
    public void testFactoryRegisteredFine() throws Exception {
86
        FileObject set = FileUtil.getConfigFile("Windows2/Components/factory-tc.settings");
87
        assertNotNull("Settings file found", set);
88
        assertValidate(set.asText());
89
    }
90
91
    public void testFactoryModeIsOK() throws Exception {
92
        FileObject set = FileUtil.getConfigFile("Windows2/Modes/explorer/factory-tc.wstcref");
93
        assertNotNull("Mode file found", set);
94
        final String t = set.asText();
95
        assertValidate(t);
96
        assertTrue("opened, no true in there", t.indexOf("true") > 0);
97
    }
98
99
    public void testFactoryActionIsOKInEQ() throws Exception {
100
        assertTrue("This one needs to run in EQT", EventQueue.isDispatchThread());
101
        FileObject fo = FileUtil.getConfigFile("Actions/Windows/open-factory-tc.instance");
102
        assertNotNull("Action generated", fo);
103
        Action a = (Action)fo.getAttribute("instanceCreate");
104
        assertNotNull("Action found", a);
105
        assertEquals("Not created yet", 0, TC.cnt);
106
        a.actionPerformed(new ActionEvent(this, 0, ""));
107
        assertEquals("Created", 1, TC.cnt);
108
        assertEquals("Hello TC!", a.getValue(Action.NAME));
109
        assertEquals("any/iconbase.png", a.getValue("iconBase"));
110
        assertEquals("preferredID found", "factory.tc", fo.getAttribute("preferredID"));
111
        
112
        FileObject dir = FileUtil.getConfigFile("Kuk/Huk");
113
        assertNotNull("Kuk/Huk found", dir);
114
        FileObject ref = dir.getFileObject("open-factory-tc.shadow");
115
        assertNotNull("Reference found: " + Arrays.toString(dir.getChildren()), ref);
116
        assertEquals(fo.getPath(), ref.getAttribute("originalFile"));
117
    }
118
    
119
    private static void assertValidate(String xml) throws Exception {
120
        DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
121
        f.setValidating(true);
122
        DocumentBuilder b = f.newDocumentBuilder();
123
        Document res = b.parse(new ByteArrayInputStream(xml.getBytes("UTF-8")));
124
        assertNotNull("Parsed OK", res);
125
    }
126
    
127
    @TopComponent.Registration(
128
        mode="output",
129
        openAtStartup=false
130
    )
131
    @TopComponent.Description(
132
        preferredID="my-tc", iconBase="org/openide/windows/Icon.png"
133
    )
134
    public static class TC1 extends TopComponent {
135
    }
136
    
137
    @TopComponent.Registration(
138
        mode="explorer",
139
        openAtStartup=true
140
    )
141
    @TopComponent.Description(
142
        preferredID="factory.tc", iconBase="any/iconbase.png"
143
    )
144
    public static class TC extends TopComponent {
145
        static int cnt;
146
        
147
        @ActionID(category="Windows", id="open.factory.tc")
148
        @TopComponent.OpenActionRegistration(displayName="#TEST_ACTION")
149
        @ActionReference(path="Kuk/Huk")
150
        public static TC create() {
151
            cnt++;
152
            return new TC();
153
        }
154
    }
155
}
(-)a/openide.windows/test/unit/src/org/openide/windows/TopComponentTest.java (+18 lines)
Lines 44-49 Link Here
44
44
45
package org.openide.windows;
45
package org.openide.windows;
46
46
47
import java.awt.Image;
47
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionEvent;
48
import java.awt.event.KeyEvent;
49
import java.awt.event.KeyEvent;
49
import java.beans.PropertyChangeEvent;
50
import java.beans.PropertyChangeEvent;
Lines 66-71 Link Here
66
import org.openide.nodes.Node;
67
import org.openide.nodes.Node;
67
import org.openide.util.ContextAwareAction;
68
import org.openide.util.ContextAwareAction;
68
import org.openide.util.HelpCtx;
69
import org.openide.util.HelpCtx;
70
import org.openide.util.ImageUtilities;
69
import org.openide.util.Lookup;
71
import org.openide.util.Lookup;
70
import org.openide.util.actions.CookieAction;
72
import org.openide.util.actions.CookieAction;
71
import org.openide.util.io.NbMarshalledObject;
73
import org.openide.util.io.NbMarshalledObject;
Lines 83-88 Link Here
83
    public TopComponentTest(String testName) {
85
    public TopComponentTest(String testName) {
84
        super(testName);
86
        super(testName);
85
    }
87
    }
88
    
89
    public void testPreferredIDAndIconTakenFromAnnotation() {
90
        @TopComponent.Description(
91
            preferredID="my.id", iconBase="org/openide/windows/icon.png",
92
            persistenceType=TopComponent.PERSISTENCE_ONLY_OPENED    
93
        )
94
        class MyTC extends TopComponent {
95
        }
96
        TopComponent tc = new MyTC();
97
        
98
        assertEquals("ID is OK", "my.id", tc.preferredID());
99
        Image image = ImageUtilities.loadImage("org/openide/windows/icon.png");
100
        assertEquals("Image is OK", image, tc.getIcon());
101
        
102
        assertEquals("Only opened", TopComponent.PERSISTENCE_ONLY_OPENED, tc.getPersistenceType());
103
    }
86
104
87
    public void testCanTCGarbageCollectWhenActionInMap() {
105
    public void testCanTCGarbageCollectWhenActionInMap() {
88
        TopComponent tc = new TopComponent();
106
        TopComponent tc = new TopComponent();

Return to bug 191407