Source Code Cross Referenced for JavaTypeDescription.java in  » IDE-Netbeans » java » org » netbeans » modules » java » source » ui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » java » org.netbeans.modules.java.source.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.java.source.ui;
043:
044:        import java.awt.Toolkit;
045:        import java.io.IOException;
046:        import java.util.logging.Logger;
047:        import javax.lang.model.element.Element;
048:        import javax.lang.model.element.TypeElement;
049:        import javax.swing.Icon;
050:        import org.netbeans.api.java.source.ClasspathInfo;
051:        import org.netbeans.api.java.source.CompilationController;
052:        import org.netbeans.api.java.source.ElementHandle;
053:        import org.netbeans.api.java.source.JavaSource;
054:        import org.netbeans.api.java.source.SourceUtils;
055:        import org.netbeans.api.java.source.Task;
056:        import org.netbeans.api.java.source.ui.ElementOpen;
057:        import org.netbeans.modules.java.ui.Icons;
058:        import org.netbeans.spi.jumpto.type.TypeDescriptor;
059:        import org.openide.awt.StatusDisplayer;
060:        import org.openide.filesystems.FileObject;
061:        import org.openide.util.Exceptions;
062:        import org.openide.util.NbBundle;
063:
064:        /**
065:         * 
066:         * @todo Resolve with TypeDescription
067:         *
068:         * @author Petr Hrebejk
069:         */
070:        public class JavaTypeDescription extends TypeDescriptor {
071:
072:            private static final String EMPTY_STRING = ""; // NOI18N
073:
074:            private Icon icon;
075:
076:            private final JavaTypeProvider.CacheItem cacheItem;
077:
078:            private final ElementHandle<TypeElement> handle;
079:            private String simpleName;
080:            private String outerName;
081:            private String packageName;
082:
083:            public JavaTypeDescription(JavaTypeProvider.CacheItem cacheItem,
084:                    final ElementHandle<TypeElement> handle) {
085:                this .cacheItem = cacheItem;
086:                this .handle = handle;
087:                init();
088:            }
089:
090:            public void open() {
091:                final ClasspathInfo ci = ClasspathInfo.create(cacheItem
092:                        .getRoot());
093:                if (cacheItem.isBinary()) {
094:                    final JavaSource js = JavaSource.create(ci);
095:                    final ElementHandle<TypeElement> eh = handle;
096:                    final Element[] el = new Element[1];
097:                    try {
098:                        js.runUserActionTask(new Task<CompilationController>() {
099:
100:                            public void run(CompilationController info) {
101:                                el[0] = eh.resolve(info);
102:                                if (!ElementOpen.open(ci, el[0])) {
103:                                    final String message = NbBundle.getMessage(
104:                                            JavaTypeDescription.class,
105:                                            "LBL_JavaTypeDescription_nosource",
106:                                            eh.getQualifiedName());
107:                                    StatusDisplayer.getDefault().setStatusText(
108:                                            message);
109:                                    Toolkit.getDefaultToolkit().beep();
110:                                }
111:                            }
112:
113:                        }, true);
114:                    } catch (IOException e) {
115:                        Logger
116:                                .getLogger(JavaTypeDescription.class.getName())
117:                                .info("Source not found: " + eh.getBinaryName());
118:                        Exceptions.printStackTrace(e);
119:                    }
120:                } else {
121:                    final FileObject file = SourceUtils.getFile(handle, ci);
122:                    boolean opened = false;
123:                    if (file != null) {
124:                        opened = ElementOpen.open(file, handle);
125:                    }
126:                    if (!opened) {
127:                        StringBuilder name = new StringBuilder();
128:                        if (packageName != null) {
129:                            name.append(packageName);
130:                            name.append('.'); //NOI18N
131:                        }
132:                        if (outerName != null) {
133:                            name.append(outerName);
134:                        } else {
135:                            name.append(simpleName);
136:                        }
137:                        final String message = NbBundle.getMessage(
138:                                JavaTypeDescription.class,
139:                                "LBL_JavaTypeDescription_nosource", name
140:                                        .toString());
141:                        StatusDisplayer.getDefault().setStatusText(message);
142:                        Toolkit.getDefaultToolkit().beep();
143:                    }
144:                }
145:            }
146:
147:            public String getSimpleName() {
148:                return simpleName;
149:            }
150:
151:            public String getOuterName() {
152:                return outerName;
153:            }
154:
155:            public FileObject getFileObject() {
156:                return cacheItem.getRoot();
157:            }
158:
159:            public String getTypeName() {
160:                StringBuilder sb = new StringBuilder(simpleName);
161:                if (outerName != null) {
162:                    sb.append(" in ").append(outerName);
163:                }
164:                return sb.toString();
165:            }
166:
167:            public String getContextName() {
168:                StringBuilder sb = new StringBuilder();
169:                sb.append(" (").append(
170:                        packageName == null ? "Default Package" : packageName)
171:                        .append(")");
172:                return sb.toString();
173:
174:            }
175:
176:            public String getProjectName() {
177:                String projectName = cacheItem.getProjectName();
178:                return projectName == null ? "" : projectName; // NOI18N        
179:            }
180:
181:            public Icon getProjectIcon() {
182:                return cacheItem.getProjectIcon();
183:            }
184:
185:            public ElementHandle<TypeElement> getHandle() {
186:                return handle;
187:            }
188:
189:            private void init() {
190:                final String typeName = this .handle.getBinaryName();
191:                int lastDot = typeName.lastIndexOf('.'); // NOI18N
192:                int lastDollar = typeName.lastIndexOf('$'); // NOI18N
193:                if (lastDot == -1) {
194:                    if (lastDollar == -1) {
195:                        simpleName = typeName;
196:                    } else {
197:                        simpleName = typeName.substring(lastDollar + 1);
198:                        outerName = typeName.substring(0, lastDollar).replace(
199:                                '$', '.'); //NOI18N;
200:                    }
201:                } else {
202:                    packageName = typeName.substring(0, lastDot);
203:
204:                    if (lastDollar == -1) {
205:                        simpleName = typeName.substring(lastDot + 1).replace(
206:                                '$', '.'); //NOI18N
207:                    } else {
208:                        simpleName = typeName.substring(lastDollar + 1);
209:                        outerName = typeName.substring(lastDot + 1, lastDollar)
210:                                .replace('$', '.'); //NOI18N;
211:                    }
212:
213:                }
214:                icon = Icons.getElementIcon(handle.getKind(), null);
215:            }
216:
217:            public String toString() {
218:
219:                StringBuilder sb = new StringBuilder(simpleName);
220:                if (outerName != null) {
221:                    sb.append(" in ").append(outerName);
222:                }
223:                sb.append(" (").append(
224:                        packageName == null ? "Default Package" : packageName)
225:                        .append(")");
226:                if (cacheItem.getProjectName() != null) {
227:                    sb.append(" [").append(cacheItem.getProjectName()).append(
228:                            "]");
229:                }
230:
231:                return sb.toString();
232:            }
233:
234:            //    
235:            //    //public int compareTo( JavaTypeDescription td ) {
236:            //    public int compareTo( TypeDescriptor descriptor ) {
237:            //        if (descriptor instanceof JavaTypeDescription) {
238:            //            JavaTypeDescription td = (JavaTypeDescription)descriptor;
239:            //           int cmpr = compareStrings( simpleName, td.simpleName );
240:            //           if ( cmpr != 0 ) {
241:            //               return cmpr;
242:            //           }
243:            //           cmpr = compareStrings( outerName, td.outerName );
244:            //           if ( cmpr != 0 ) {
245:            //               return cmpr;
246:            //           }
247:            //           return compareStrings( packageName, td.packageName );
248:            //        } else {
249:            //           int cmpr = compareStrings(simpleName, descriptor.getTypeName());
250:            //           if (cmpr != 0) {
251:            //               return cmpr;
252:            //           }
253:            //           return compareStrings(outerName, descriptor.getPackageName());
254:            //        }
255:            //    }
256:
257:            public synchronized Icon getIcon() {
258:                return icon;
259:            }
260:
261:            //    private int compareStrings(String s1, String s2) {
262:            //        if( s1 == null ) {
263:            //            s1 = EMPTY_STRING;
264:            //        }
265:            //        if ( s2 == null ) {
266:            //            s2 = EMPTY_STRING;
267:            //        }
268:            //        return s1.compareTo( s2 );
269:            //    }
270:
271:            public int getOffset() {
272:                throw new UnsupportedOperationException("Not supported yet.");
273:            }
274:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.