Source Code Cross Referenced for ReadmeFilePropertyPage2.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, 2007 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.swt.SWT;
021:        import org.eclipse.swt.layout.GridData;
022:        import org.eclipse.swt.layout.GridLayout;
023:        import org.eclipse.swt.widgets.Canvas;
024:        import org.eclipse.swt.widgets.Composite;
025:        import org.eclipse.swt.widgets.Control;
026:        import org.eclipse.swt.widgets.Label;
027:        import org.eclipse.ui.PlatformUI;
028:        import org.eclipse.ui.dialogs.PropertyPage;
029:
030:        /**
031:         * This page will be added to the property page dialog
032:         * when "Properties..." popup menu item is selected
033:         * for Readme files. 
034:         *
035:         * This page demonstrates conditional property pages which look
036:         * different depending on the state of the element. In this example,
037:         * the arbitrary condition chosen is whether the Readme file is
038:         * greater than 256 bytes in length. If it is smaller than 256 bytes
039:         * in length, this will be a placeholder page containing 
040:         * a simple message. If it is 256 bytes or larger, additional 
041:         * information will be provided. This information is determined at
042:         * runtime.
043:         *
044:         * This class may be reused to implement a conditional property page.
045:         * The getPageIndex() method tests the condition and returns the
046:         * index of the page to create. The createPage*() methods are called
047:         * upon to create the actual pages.
048:         */
049:        public class ReadmeFilePropertyPage2 extends PropertyPage {
050:
051:            /**
052:             * Utility method that creates a new composite and
053:             * sets up its layout data.
054:             *
055:             * @param parent  the parent of the composite
056:             * @param numColumns  the number of columns in the new composite
057:             * @return the newly-created composite
058:             */
059:            protected Composite createComposite(Composite parent, int numColumns) {
060:                Composite composite = new Composite(parent, SWT.NULL);
061:                GridLayout layout = new GridLayout();
062:                layout.numColumns = numColumns;
063:                composite.setLayout(layout);
064:                GridData data = new GridData();
065:                data.verticalAlignment = GridData.FILL;
066:                data.horizontalAlignment = GridData.FILL;
067:                composite.setLayoutData(data);
068:                return composite;
069:            }
070:
071:            /** (non-Javadoc)
072:             * Method declared on PreferencePage
073:             */
074:            public Control createContents(Composite parent) {
075:                // ensure the page has no special buttons
076:                noDefaultAndApplyButton();
077:                Composite panel = createComposite(parent, 2);
078:
079:                PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
080:                        IReadmeConstants.PROPERTY_PAGE2_CONTEXT);
081:
082:                // layout the page
083:                int page = getPageIndex();
084:                switch (page) {
085:                case 1:
086:                    createPageOne(panel);
087:                    break;
088:                case 2:
089:                    createPageTwo(panel);
090:                    break;
091:                default:
092:                }
093:                return new Canvas(panel, 0);
094:            }
095:
096:            /**
097:             * Utility method that creates a new label and sets up
098:             * its layout data.
099:             *
100:             * @param parent  the parent of the label
101:             * @param text  the text of the label
102:             * @return the newly-created label
103:             */
104:            protected Label createLabel(Composite parent, String text) {
105:                Label label = new Label(parent, SWT.LEFT);
106:                label.setText(text);
107:                GridData data = new GridData();
108:                data.horizontalAlignment = GridData.FILL;
109:                label.setLayoutData(data);
110:                return label;
111:            }
112:
113:            /**
114:             * Creates the first version of the page. This is a placeholder page which
115:             * notified the user that the page is not available.
116:             *
117:             * @param panel  the panel in which to create the page
118:             */
119:            protected void createPageOne(Composite panel) {
120:                Label l = createLabel(
121:                        panel,
122:                        MessageUtil
123:                                .getString("Additional_Readme_properties_not_available.")); //$NON-NLS-1$
124:                GridData gd = (GridData) l.getLayoutData();
125:                gd.horizontalSpan = 2;
126:                gd.grabExcessHorizontalSpace = true;
127:                l = createLabel(
128:                        panel,
129:                        MessageUtil
130:                                .getString("This_illustrates_a_property_page_that_is_dynamically_determined")); //$NON-NLS-1$
131:                gd = (GridData) l.getLayoutData();
132:                gd.horizontalSpan = 2;
133:                gd.grabExcessHorizontalSpace = true;
134:                l = createLabel(
135:                        panel,
136:                        MessageUtil
137:                                .getString("not_to_be_available_based_on_the_state_of_the_object.")); //$NON-NLS-1$
138:                gd = (GridData) l.getLayoutData();
139:                gd.horizontalSpan = 2;
140:                gd.grabExcessHorizontalSpace = true;
141:            }
142:
143:            /**
144:             * Creates the second version of the page. This page might contain more information
145:             * about the file or other information.
146:             *
147:             * @param panel  the panel in which to create the page
148:             */
149:            protected void createPageTwo(Composite panel) {
150:                Label l = createLabel(
151:                        panel,
152:                        MessageUtil
153:                                .getString("The_size_of_the_Readme_file_is_at_least_256_bytes.")); //$NON-NLS-1$
154:                GridData gd = (GridData) l.getLayoutData();
155:                gd.horizontalSpan = 2;
156:                gd.grabExcessHorizontalSpace = true;
157:                l = createLabel(
158:                        panel,
159:                        MessageUtil
160:                                .getString("Had_it_been_less_than_256_bytes_this_page_would_be_a_placeholder_page.")); //$NON-NLS-1$
161:                gd = (GridData) l.getLayoutData();
162:                gd.horizontalSpan = 2;
163:                gd.grabExcessHorizontalSpace = true;
164:                l = createLabel(panel, MessageUtil
165:                        .getString("Additional_information")); //$NON-NLS-1$
166:                gd = (GridData) l.getLayoutData();
167:                gd.horizontalSpan = 2;
168:                gd.grabExcessHorizontalSpace = true;
169:                l = createLabel(
170:                        panel,
171:                        MessageUtil
172:                                .getString("This_illustrates_a_property_page_that_is_dynamically_determined")); //$NON-NLS-1$
173:                gd = (GridData) l.getLayoutData();
174:                gd.horizontalSpan = 2;
175:                gd.grabExcessHorizontalSpace = true;
176:                l = createLabel(
177:                        panel,
178:                        MessageUtil
179:                                .getString("to_be_available_based_on_the_state_of_the_object.")); //$NON-NLS-1$
180:                gd = (GridData) l.getLayoutData();
181:                gd.horizontalSpan = 2;
182:                gd.grabExcessHorizontalSpace = true;
183:            }
184:
185:            /**
186:             * Returns which page to display. This implementation
187:             * answers 1 if the size of the Readme file is less than 256 bytes
188:             * and 2 otherwise.
189:             *
190:             * @return the index of the page to display
191:             */
192:            protected int getPageIndex() {
193:                IResource resource = (IResource) getElement();
194:
195:                if (resource.getType() == IResource.FILE) {
196:                    InputStream contentStream = null;
197:                    int length = 0;
198:                    try {
199:                        IFile file = (IFile) resource;
200:                        contentStream = file.getContents();
201:                        Reader in = new InputStreamReader(contentStream);
202:                        int chunkSize = contentStream.available();
203:                        StringBuffer buffer = new StringBuffer(chunkSize);
204:                        char[] readBuffer = new char[chunkSize];
205:                        int n = in.read(readBuffer);
206:
207:                        while (n > 0) {
208:                            buffer.append(readBuffer);
209:                            n = in.read(readBuffer);
210:                        }
211:
212:                        contentStream.close();
213:                        length = buffer.length();
214:                    } catch (CoreException e) {
215:                        length = 0;
216:                    } catch (IOException e) {
217:                        // do nothing
218:                    } finally {
219:                        if (contentStream != null) {
220:                            try {
221:                                contentStream.close();
222:                            } catch (IOException e) {
223:                                // do nothing
224:                            }
225:                        }
226:                    }
227:
228:                    if (length < 256)
229:                        return 1;
230:                    return 2;
231:                }
232:
233:                return 0;
234:            }
235:
236:            /** (non-Javadoc)
237:             * Method declared on PreferencePage
238:             */
239:            public boolean performOk() {
240:                // nothing to do - read-only page
241:                return true;
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.