Source Code Cross Referenced for ReadmeFilePropertyPage.java in  » IDE-Eclipse » ui-examples » org » eclipse » ui » examples » readmetool » 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 Eclipse » ui examples » org.eclipse.ui.examples.readmetool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.examples.readmetool;
011:
012:        import java.io.IOException;
013:        import java.io.InputStream;
014:        import java.io.InputStreamReader;
015:        import java.io.Reader;
016:
017:        import org.eclipse.core.resources.IFile;
018:        import org.eclipse.core.resources.IResource;
019:        import org.eclipse.core.runtime.CoreException;
020:        import org.eclipse.core.runtime.IAdaptable;
021:        import org.eclipse.core.runtime.IStatus;
022:        import org.eclipse.swt.SWT;
023:        import org.eclipse.swt.layout.GridData;
024:        import org.eclipse.swt.layout.GridLayout;
025:        import org.eclipse.swt.widgets.Canvas;
026:        import org.eclipse.swt.widgets.Composite;
027:        import org.eclipse.swt.widgets.Control;
028:        import org.eclipse.swt.widgets.Label;
029:        import org.eclipse.ui.PlatformUI;
030:        import org.eclipse.ui.dialogs.PropertyPage;
031:
032:        /**
033:         * This page will be added to the property page dialog
034:         * when the "Properties..." popup menu item is selected
035:         * for Readme files. 
036:         */
037:        public class ReadmeFilePropertyPage extends PropertyPage {
038:
039:            /**
040:             * Utility method that creates a new composite and
041:             * sets up its layout data.
042:             *
043:             * @param parent  the parent of the composite
044:             * @param numColumns  the number of columns in the new composite
045:             * @return the newly-created composite
046:             */
047:            protected Composite createComposite(Composite parent, int numColumns) {
048:                Composite composite = new Composite(parent, SWT.NULL);
049:                GridLayout layout = new GridLayout();
050:                layout.numColumns = numColumns;
051:                composite.setLayout(layout);
052:                GridData data = new GridData();
053:                data.verticalAlignment = GridData.FILL;
054:                data.horizontalAlignment = GridData.FILL;
055:                composite.setLayoutData(data);
056:                return composite;
057:            }
058:
059:            /** (non-Javadoc)
060:             * Method declared on PreferencePage
061:             */
062:            public Control createContents(Composite parent) {
063:
064:                // ensure the page has no special buttons
065:                noDefaultAndApplyButton();
066:                Composite panel = createComposite(parent, 2);
067:
068:                PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
069:                        IReadmeConstants.PROPERTY_PAGE_CONTEXT);
070:
071:                // layout the page
072:
073:                IResource resource = (IResource) getElement();
074:                IStatus result = null;
075:                if (resource.getType() == IResource.FILE) {
076:                    Label label = createLabel(panel, MessageUtil
077:                            .getString("File_name")); //$NON-NLS-1$
078:                    label = createLabel(panel, resource.getName());
079:                    grabExcessSpace(label);
080:
081:                    //
082:                    createLabel(panel, MessageUtil.getString("Path")); //$NON-NLS-1$
083:                    label = createLabel(panel, resource.getFullPath()
084:                            .setDevice(null).toString());
085:                    grabExcessSpace(label);
086:
087:                    //
088:                    createLabel(panel, MessageUtil.getString("Size")); //$NON-NLS-1$
089:                    InputStream contentStream = null;
090:                    try {
091:                        IFile file = (IFile) resource;
092:                        contentStream = file.getContents();
093:                        Reader in = new InputStreamReader(contentStream);
094:                        int chunkSize = contentStream.available();
095:                        StringBuffer buffer = new StringBuffer(chunkSize);
096:                        char[] readBuffer = new char[chunkSize];
097:                        int n = in.read(readBuffer);
098:
099:                        while (n > 0) {
100:                            buffer.append(readBuffer);
101:                            n = in.read(readBuffer);
102:                        }
103:
104:                        contentStream.close();
105:                        label = createLabel(panel, Integer.toString(buffer
106:                                .length()));
107:                    } catch (CoreException e) {
108:                        result = e.getStatus();
109:                        String message = result.getMessage();
110:                        if (message == null)
111:                            label = createLabel(panel, MessageUtil
112:                                    .getString("<Unknown>")); //$NON-NLS-1$
113:                        else
114:                            label = createLabel(panel, message);
115:                    } catch (IOException e) {
116:                        label = createLabel(panel, MessageUtil
117:                                .getString("<Unknown>")); //$NON-NLS-1$
118:                    } finally {
119:                        if (contentStream != null) {
120:                            try {
121:                                contentStream.close();
122:                            } catch (IOException e) {
123:                                // do nothing
124:                            }
125:                        }
126:                    }
127:                    grabExcessSpace(label);
128:                    createLabel(panel, MessageUtil
129:                            .getString("Number_of_sections")); //$NON-NLS-1$
130:                    // We will get the sections property and simply
131:                    // report number of elements found.
132:                    IAdaptable sections = getSections(resource);
133:                    if (sections instanceof  AdaptableList) {
134:                        AdaptableList list = (AdaptableList) sections;
135:                        label = createLabel(panel, String.valueOf(list.size()));
136:                        grabExcessSpace(label);
137:                    }
138:                }
139:
140:                //
141:                Label label = createLabel(panel, MessageUtil
142:                        .getString("Additional_information")); //$NON-NLS-1$
143:                grabExcessSpace(label);
144:                GridData gd = (GridData) label.getLayoutData();
145:                gd.horizontalSpan = 2;
146:                return new Canvas(panel, 0);
147:            }
148:
149:            /**
150:             * Utility method that creates a new label and sets up its layout data.
151:             *
152:             * @param parent  the parent of the label
153:             * @param text  the text of the label
154:             * @return the newly-created label
155:             */
156:            protected Label createLabel(Composite parent, String text) {
157:                Label label = new Label(parent, SWT.LEFT);
158:                label.setText(text);
159:                GridData data = new GridData();
160:                data.horizontalAlignment = GridData.FILL;
161:                label.setLayoutData(data);
162:                return label;
163:            }
164:
165:            /**
166:             * Returns the readme sections for this resource, or null
167:             * if not applicable (resource is not a readme file).
168:             */
169:            private AdaptableList getSections(IAdaptable adaptable) {
170:                if (adaptable instanceof  IFile)
171:                    return ReadmeModelFactory.getInstance().getSections(
172:                            (IFile) adaptable);
173:                return null;
174:            }
175:
176:            /**
177:             * Sets this control to grab any excess horizontal space
178:             * left in the window.
179:             *
180:             * @param control  the control for which to grab excess space
181:             */
182:            private void grabExcessSpace(Control control) {
183:                GridData gd = (GridData) control.getLayoutData();
184:                if (gd != null) {
185:                    gd.grabExcessHorizontalSpace = true;
186:                }
187:            }
188:
189:            /** (non-Javadoc)
190:             * Method declared on PreferencePage
191:             */
192:            public boolean performOk() {
193:                // nothing to do - read-only page
194:                return true;
195:            }
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.