KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > ui > nodes > SourceNodes


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.modules.java.ui.nodes;
21
22 import org.netbeans.modules.java.JavaDataObject;
23 import org.netbeans.modules.java.ui.nodes.elements.ElementFormat;
24
25 import java.text.Format JavaDoc;
26
27 /**
28  * Helper class that simplifies work with source nodes.
29  */

30 public final class SourceNodes {
31
32     private static SourceNodeFactory BROWSER_FACTORY;
33     private static SourceNodeFactory EXPLORER_FACTORY;
34
35     public static SourceNodeFactory getExplorerFactory() {
36         if (EXPLORER_FACTORY == null) {
37             EXPLORER_FACTORY = createSourceNodeFactory(
38                     (ExElementNodeFactory) JavaDataObject.getExplorerFactory());
39         }
40         return EXPLORER_FACTORY;
41     }
42     
43     public static SourceNodeFactory getBrowserFactory() {
44         if (BROWSER_FACTORY == null) {
45             JavaSourceNodeFactory f = new JavaSourceNodeFactory();
46             f.setGenerateForTree(true);
47             BROWSER_FACTORY = f;
48         }
49         return BROWSER_FACTORY;
50     }
51     
52     /**
53      * helper that allows to use {@link SourceNodeFactory} as {@link org.openide.src.nodes.ElementNodeFactory}
54      * @param factory jmi nodes factory
55      * @return srcmodel nodes factory
56      */

57     public static ExElementNodeFactory createElementNodeFactory(SourceNodeFactory factory) {
58         return new BridgeSource2Element(factory);
59     }
60     
61     /**
62      * helper that allows to use {@link org.openide.src.nodes.ElementNodeFactory} as {@link SourceNodeFactory}
63      * @param factory srcmodel nodes factory
64      * @return jmi nodes factory
65      */

66     public static SourceNodeFactory createSourceNodeFactory(ExElementNodeFactory factory) {
67         return new BridgeElement2Source(factory);
68     }
69
70     /**
71      * creates format for jmi elements
72      * @param pattern pattern
73      * @return the format
74      */

75     public static Format createElementFormat(String JavaDoc pattern) {
76         return new ElementFormat(pattern);
77     }
78
79 }
80
Popular Tags