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


001:        /*******************************************************************************
002:         * Copyright (c) 2004, 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.internal.dialogs;
011:
012:        import org.eclipse.jface.dialogs.IDialogConstants;
013:        import org.eclipse.jface.preference.IPreferenceNode;
014:        import org.eclipse.jface.preference.IPreferencePageContainer;
015:        import org.eclipse.jface.preference.IPreferenceStore;
016:        import org.eclipse.jface.resource.JFaceResources;
017:        import org.eclipse.swt.SWT;
018:        import org.eclipse.swt.custom.ScrolledComposite;
019:        import org.eclipse.swt.events.MouseAdapter;
020:        import org.eclipse.swt.events.MouseEvent;
021:        import org.eclipse.swt.graphics.Color;
022:        import org.eclipse.swt.graphics.Font;
023:        import org.eclipse.swt.graphics.Point;
024:        import org.eclipse.swt.graphics.Rectangle;
025:        import org.eclipse.swt.layout.FormAttachment;
026:        import org.eclipse.swt.layout.FormData;
027:        import org.eclipse.swt.layout.FormLayout;
028:        import org.eclipse.swt.layout.GridData;
029:        import org.eclipse.swt.layout.GridLayout;
030:        import org.eclipse.swt.widgets.Composite;
031:        import org.eclipse.swt.widgets.Control;
032:        import org.eclipse.swt.widgets.Label;
033:
034:        /**
035:         * The PreferencesPageContainer is the container object for the preference pages
036:         * in a node.
037:         */
038:        public class PreferencesPageContainer implements 
039:                IPreferencePageContainer {
040:
041:            private Composite control;
042:
043:            private ScrolledComposite scrolled;
044:
045:            private class PreferenceEntry {
046:
047:                Composite composite;
048:
049:                IPreferenceNode node;
050:
051:                String title;
052:
053:                int offset;
054:
055:                Label expandImage;
056:
057:                Label titleLabel;
058:
059:                Composite pageContainer;
060:
061:                /**
062:                 * Create a new instance of the receiver.
063:                 * 
064:                 * @param displayedNode
065:                 * @param pageTitle
066:                 */
067:                PreferenceEntry(IPreferenceNode displayedNode, String pageTitle) {
068:                    node = displayedNode;
069:                    title = pageTitle;
070:                }
071:
072:                /**
073:                 * Add the subnodes of the receiver.
074:                 */
075:                private void addSubNodes() {
076:                    IPreferenceNode[] subnodes = node.getSubNodes();
077:                    PreferenceEntry previous = null;
078:                    for (int i = 0; i < subnodes.length; i++) {
079:                        PreferenceEntry entry = createEntry(subnodes[i],
080:                                subnodes[i].getLabelText(), offset + 1);
081:                        if (previous == null) {
082:                            entry.composite.moveBelow(this .composite);
083:                        } else {
084:                            entry.composite.moveBelow(previous.composite);
085:                        }
086:                        previous = entry;
087:                    }
088:                }
089:
090:                /**
091:                 * Create the contents of the entry in parent. When laying this out
092:                 * indent the composite ident units.
093:                 * 
094:                 * @param indent
095:                 */
096:                void createContents(int indent) {
097:
098:                    composite = new Composite(control, SWT.NULL);
099:
100:                    // Create the title area which will contain
101:                    // a title, message, and image.
102:
103:                    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
104:                    gridData.horizontalIndent = IDialogConstants.SMALL_INDENT
105:                            * indent;
106:                    composite.setLayoutData(gridData);
107:
108:                    FormLayout layout = new FormLayout();
109:                    layout.marginHeight = 0;
110:                    layout.marginWidth = 0;
111:                    composite.setLayout(layout);
112:
113:                    Font titleFont = JFaceResources.getBannerFont();
114:
115:                    expandImage = new Label(composite, SWT.RIGHT);
116:                    expandImage.setText("+");//$NON-NLS-1$
117:                    expandImage.setFont(titleFont);
118:
119:                    FormData imageData = new FormData();
120:                    imageData.top = new FormAttachment(0);
121:                    imageData.left = new FormAttachment(0,
122:                            IDialogConstants.HORIZONTAL_SPACING);
123:                    expandImage.setLayoutData(imageData);
124:
125:                    // Title image
126:                    titleLabel = new Label(composite, SWT.LEFT);
127:                    titleLabel.setText(title);
128:                    titleLabel.setFont(titleFont);
129:
130:                    FormData titleData = new FormData();
131:                    titleData.right = new FormAttachment(100);
132:                    titleData.top = new FormAttachment(0);
133:                    titleData.left = new FormAttachment(expandImage,
134:                            IDialogConstants.HORIZONTAL_SPACING);
135:                    titleLabel.setLayoutData(titleData);
136:
137:                    titleLabel.addMouseListener(new MouseAdapter() {
138:                        /*
139:                         * (non-Javadoc)
140:                         * 
141:                         * @see org.eclipse.swt.events.MouseAdapter#mouseDown(org.eclipse.swt.events.MouseEvent)
142:                         */
143:                        public void mouseDown(MouseEvent e) {
144:
145:                            if (pageContainer == null) {
146:                                boolean adjustScrollbars = false;
147:
148:                                pageContainer = new Composite(composite,
149:                                        SWT.BORDER);
150:
151:                                FormData containerData = new FormData();
152:                                containerData.top = new FormAttachment(
153:                                        titleLabel, 0);
154:                                containerData.left = new FormAttachment(0);
155:                                containerData.right = new FormAttachment(100);
156:                                pageContainer.setLayoutData(containerData);
157:
158:                                pageContainer.setLayout(new GridLayout());
159:
160:                                node.createPage();
161:                                node.getPage().createControl(pageContainer);
162:                                node.getPage().setContainer(
163:                                        PreferencesPageContainer.this );
164:                                node.getPage().getControl().setLayoutData(
165:                                        new GridData(GridData.FILL_BOTH));
166:                                adjustScrollbars = true;
167:
168:                                Point contentSize = node.getPage()
169:                                        .computeSize();
170:                                Rectangle totalArea = composite.getClientArea();
171:
172:                                if (contentSize.x < totalArea.width) {
173:                                    contentSize.x = totalArea.width;
174:                                }
175:
176:                                node.getPage().setSize(contentSize);
177:                                if (adjustScrollbars) {
178:                                    adjustScrollbars(contentSize);
179:                                }
180:
181:                                expandImage.setText("-");//$NON-NLS-1$
182:
183:                                addSubNodes();
184:
185:                                setSelectionColors(composite.getDisplay()
186:                                        .getSystemColor(
187:                                                SWT.COLOR_INFO_BACKGROUND));
188:                            } else {
189:                                setSelectionColors(null);
190:                                pageContainer.dispose();
191:                                pageContainer = null;
192:                                expandImage.setText("+");//$NON-NLS-1$
193:                            }
194:
195:                            control.layout(true);
196:                        }
197:                    });
198:                    offset = indent;
199:                }
200:
201:                /**
202:                 * Set the background colors and the labels due to selection.
203:                 * 
204:                 * @param highlight
205:                 *            The highlight to set
206:                 */
207:                private void setSelectionColors(Color highlight) {
208:                    composite.setBackground(highlight);
209:                    titleLabel.setBackground(highlight);
210:                    expandImage.setBackground(highlight);
211:                }
212:
213:            }
214:
215:            /**
216:             * Create a new instance of the receiver.
217:             */
218:            public PreferencesPageContainer() {
219:                super ();
220:            }
221:
222:            /**
223:             * Create the contents area of the composite.
224:             * 
225:             * @param parent
226:             * @param style
227:             */
228:            void createContents(Composite parent, int style) {
229:                scrolled = new ScrolledComposite(parent, SWT.V_SCROLL
230:                        | SWT.H_SCROLL);
231:
232:                GridData newPageData = new GridData(GridData.FILL_BOTH);
233:                scrolled.setLayoutData(newPageData);
234:
235:                control = new Composite(scrolled, style);
236:
237:                scrolled.setContent(control);
238:                scrolled.setExpandVertical(true);
239:                scrolled.setExpandHorizontal(true);
240:                GridData controlData = new GridData(GridData.FILL_BOTH);
241:                control.setLayoutData(controlData);
242:
243:                GridLayout layout = new GridLayout();
244:                layout.marginHeight = 0;
245:                layout.marginWidth = 0;
246:                layout.verticalSpacing = 1;
247:                control.setLayout(layout);
248:
249:            }
250:
251:            /**
252:             * Return the top level control
253:             * 
254:             * @return Control
255:             */
256:            Control getControl() {
257:                return control;
258:            }
259:
260:            /**
261:             * Show the selected node. Return whether or not this succeeded.
262:             * 
263:             * @param node
264:             * @return <code>true</code> if the page selection was sucessful
265:             *         <code>false</code> is unsuccessful
266:             */
267:            boolean show(IPreferenceNode node) {
268:                createGeneralEntry(node);
269:                control.layout(true);
270:                return true;
271:            }
272:
273:            /**
274:             * Create an entry for the receiver with the general tag. Do not recurse
275:             * through the children as this is the implied top node.
276:             * 
277:             * @param node
278:             */
279:            private void createGeneralEntry(IPreferenceNode node) {
280:                PreferenceEntry entry = createEntry(node, "General", 0); //$NON-NLS-1$
281:                entry.addSubNodes();
282:
283:            }
284:
285:            /**
286:             * Create an entry with the given title for the IPreferenceNode with an
287:             * indent i.
288:             * 
289:             * @param node
290:             * @param name
291:             * @param indent
292:             * @return the entry
293:             */
294:            private PreferenceEntry createEntry(IPreferenceNode node,
295:                    String name, int indent) {
296:                PreferenceEntry entry = new PreferenceEntry(node, name);
297:                entry.createContents(indent);
298:                return entry;
299:            }
300:
301:            /*
302:             * (non-Javadoc)
303:             * 
304:             * @see org.eclipse.jface.preference.IPreferencePageContainer#getPreferenceStore()
305:             */
306:            public IPreferenceStore getPreferenceStore() {
307:                // TODO Auto-generated method stub
308:                return null;
309:            }
310:
311:            /*
312:             * (non-Javadoc)
313:             * 
314:             * @see org.eclipse.jface.preference.IPreferencePageContainer#updateButtons()
315:             */
316:            public void updateButtons() {
317:                // TODO Auto-generated method stub
318:
319:            }
320:
321:            /*
322:             * (non-Javadoc)
323:             * 
324:             * @see org.eclipse.jface.preference.IPreferencePageContainer#updateMessage()
325:             */
326:            public void updateMessage() {
327:                // TODO Auto-generated method stub
328:
329:            }
330:
331:            /*
332:             * (non-Javadoc)
333:             * 
334:             * @see org.eclipse.jface.preference.IPreferencePageContainer#updateTitle()
335:             */
336:            public void updateTitle() {
337:                // TODO Auto-generated method stub
338:
339:            }
340:
341:            /**
342:             * Adjust the scrollbars for the content that just got added.
343:             * 
344:             * @param contentSize
345:             */
346:            private void adjustScrollbars(Point contentSize) {
347:
348:                Point size = control.getSize();
349:                scrolled.setMinHeight(size.y + contentSize.y);
350:                scrolled.setMinWidth(Math.max(size.x, contentSize.x));
351:            }
352:
353:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.