Source Code Cross Referenced for SmartTypingConfigurationBlock.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » preferences » 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 » jdt » org.eclipse.jdt.internal.ui.preferences 
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.jdt.internal.ui.preferences;
011:
012:        import org.eclipse.core.runtime.Assert;
013:
014:        import org.eclipse.swt.SWT;
015:        import org.eclipse.swt.events.DisposeListener;
016:        import org.eclipse.swt.events.SelectionAdapter;
017:        import org.eclipse.swt.events.SelectionEvent;
018:        import org.eclipse.swt.graphics.Point;
019:        import org.eclipse.swt.layout.GridData;
020:        import org.eclipse.swt.layout.GridLayout;
021:        import org.eclipse.swt.widgets.Button;
022:        import org.eclipse.swt.widgets.Composite;
023:        import org.eclipse.swt.widgets.Control;
024:        import org.eclipse.swt.widgets.Link;
025:
026:        import org.eclipse.jface.dialogs.Dialog;
027:        import org.eclipse.jface.preference.IPreferenceStore;
028:        import org.eclipse.jface.util.IPropertyChangeListener;
029:        import org.eclipse.jface.util.PropertyChangeEvent;
030:
031:        import org.eclipse.ui.dialogs.PreferencesUtil;
032:
033:        import org.eclipse.jdt.core.JavaCore;
034:        import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
035:
036:        import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil;
037:        import org.eclipse.jdt.internal.corext.util.Messages;
038:
039:        import org.eclipse.jdt.ui.PreferenceConstants;
040:
041:        import org.eclipse.jdt.internal.ui.JavaPlugin;
042:
043:        /**
044:         * Configures Java Editor typing preferences.
045:         * 
046:         * @since 3.1
047:         */
048:        class SmartTypingConfigurationBlock extends AbstractConfigurationBlock {
049:
050:            public SmartTypingConfigurationBlock(OverlayPreferenceStore store) {
051:                super (store);
052:
053:                store.addKeys(createOverlayStoreKeys());
054:            }
055:
056:            private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() {
057:
058:                return new OverlayPreferenceStore.OverlayKey[] {
059:                        new OverlayPreferenceStore.OverlayKey(
060:                                OverlayPreferenceStore.BOOLEAN,
061:                                PreferenceConstants.EDITOR_SMART_PASTE),
062:                        new OverlayPreferenceStore.OverlayKey(
063:                                OverlayPreferenceStore.BOOLEAN,
064:                                PreferenceConstants.EDITOR_IMPORTS_ON_PASTE),
065:
066:                        new OverlayPreferenceStore.OverlayKey(
067:                                OverlayPreferenceStore.BOOLEAN,
068:                                PreferenceConstants.EDITOR_CLOSE_STRINGS),
069:                        new OverlayPreferenceStore.OverlayKey(
070:                                OverlayPreferenceStore.BOOLEAN,
071:                                PreferenceConstants.EDITOR_CLOSE_BRACKETS),
072:                        new OverlayPreferenceStore.OverlayKey(
073:                                OverlayPreferenceStore.BOOLEAN,
074:                                PreferenceConstants.EDITOR_CLOSE_BRACES),
075:                        new OverlayPreferenceStore.OverlayKey(
076:                                OverlayPreferenceStore.BOOLEAN,
077:                                PreferenceConstants.EDITOR_CLOSE_JAVADOCS),
078:                        new OverlayPreferenceStore.OverlayKey(
079:                                OverlayPreferenceStore.BOOLEAN,
080:                                PreferenceConstants.EDITOR_WRAP_STRINGS),
081:                        new OverlayPreferenceStore.OverlayKey(
082:                                OverlayPreferenceStore.BOOLEAN,
083:                                PreferenceConstants.EDITOR_ESCAPE_STRINGS),
084:                        new OverlayPreferenceStore.OverlayKey(
085:                                OverlayPreferenceStore.BOOLEAN,
086:                                PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS),
087:
088:                        new OverlayPreferenceStore.OverlayKey(
089:                                OverlayPreferenceStore.BOOLEAN,
090:                                PreferenceConstants.EDITOR_SMART_SEMICOLON),
091:                        new OverlayPreferenceStore.OverlayKey(
092:                                OverlayPreferenceStore.BOOLEAN,
093:                                PreferenceConstants.EDITOR_SMART_TAB),
094:                        new OverlayPreferenceStore.OverlayKey(
095:                                OverlayPreferenceStore.BOOLEAN,
096:                                PreferenceConstants.EDITOR_SMART_OPENING_BRACE), };
097:            }
098:
099:            /**
100:             * Creates page for mark occurrences preferences.
101:             * 
102:             * @param parent the parent composite
103:             * @return the control for the preference page
104:             */
105:            public Control createControl(Composite parent) {
106:                ScrolledPageContent scrolled = new ScrolledPageContent(parent,
107:                        SWT.H_SCROLL | SWT.V_SCROLL);
108:                scrolled.setExpandHorizontal(true);
109:                scrolled.setExpandVertical(true);
110:
111:                Composite control = new Composite(scrolled, SWT.NONE);
112:                GridLayout layout = new GridLayout();
113:                layout.marginWidth = 0;
114:                layout.marginHeight = 0;
115:                control.setLayout(layout);
116:
117:                Composite composite;
118:
119:                composite = createSubsection(
120:                        control,
121:                        null,
122:                        PreferencesMessages.SmartTypingConfigurationBlock_autoclose_title);
123:                addAutoclosingSection(composite);
124:
125:                composite = createSubsection(
126:                        control,
127:                        null,
128:                        PreferencesMessages.SmartTypingConfigurationBlock_automove_title);
129:                addAutopositionSection(composite);
130:
131:                composite = createSubsection(
132:                        control,
133:                        null,
134:                        PreferencesMessages.SmartTypingConfigurationBlock_tabs_title);
135:                addTabSection(composite);
136:
137:                composite = createSubsection(
138:                        control,
139:                        null,
140:                        PreferencesMessages.SmartTypingConfigurationBlock_pasting_title);
141:                addPasteSection(composite);
142:
143:                composite = createSubsection(
144:                        control,
145:                        null,
146:                        PreferencesMessages.SmartTypingConfigurationBlock_strings_title);
147:                addStringsSection(composite);
148:
149:                scrolled.setContent(control);
150:                final Point size = control
151:                        .computeSize(SWT.DEFAULT, SWT.DEFAULT);
152:                scrolled.setMinSize(size.x, size.y);
153:                return scrolled;
154:            }
155:
156:            private void addStringsSection(Composite composite) {
157:                GridLayout layout = new GridLayout();
158:                composite.setLayout(layout);
159:
160:                String label;
161:                Button master, slave;
162:                label = PreferencesMessages.JavaEditorPreferencePage_wrapStrings;
163:                master = addCheckBox(composite, label,
164:                        PreferenceConstants.EDITOR_WRAP_STRINGS, 0);
165:
166:                label = PreferencesMessages.JavaEditorPreferencePage_escapeStrings;
167:                slave = addCheckBox(composite, label,
168:                        PreferenceConstants.EDITOR_ESCAPE_STRINGS, 0);
169:                createDependency(master, slave);
170:            }
171:
172:            private void addPasteSection(Composite composite) {
173:                GridLayout layout = new GridLayout();
174:                composite.setLayout(layout);
175:
176:                String label;
177:                label = PreferencesMessages.JavaEditorPreferencePage_smartPaste;
178:                addCheckBox(composite, label,
179:                        PreferenceConstants.EDITOR_SMART_PASTE, 0);
180:
181:                label = PreferencesMessages.JavaEditorPreferencePage_importsOnPaste;
182:                addCheckBox(composite, label,
183:                        PreferenceConstants.EDITOR_IMPORTS_ON_PASTE, 0);
184:            }
185:
186:            private void addTabSection(Composite composite) {
187:                GridLayout layout = new GridLayout();
188:                composite.setLayout(layout);
189:
190:                String label;
191:                label = PreferencesMessages.JavaEditorPreferencePage_typing_smartTab;
192:                addCheckBox(composite, label,
193:                        PreferenceConstants.EDITOR_SMART_TAB, 0);
194:
195:                createMessage(composite);
196:            }
197:
198:            private void addAutopositionSection(Composite composite) {
199:
200:                GridLayout layout = new GridLayout();
201:                composite.setLayout(layout);
202:
203:                String label;
204:
205:                label = PreferencesMessages.JavaEditorPreferencePage_typing_smartSemicolon;
206:                addCheckBox(composite, label,
207:                        PreferenceConstants.EDITOR_SMART_SEMICOLON, 0);
208:
209:                label = PreferencesMessages.JavaEditorPreferencePage_typing_smartOpeningBrace;
210:                addCheckBox(composite, label,
211:                        PreferenceConstants.EDITOR_SMART_OPENING_BRACE, 0);
212:            }
213:
214:            private void addAutoclosingSection(Composite composite) {
215:
216:                GridLayout layout = new GridLayout();
217:                layout.numColumns = 1;
218:                composite.setLayout(layout);
219:
220:                String label;
221:                Button master, slave;
222:
223:                label = PreferencesMessages.JavaEditorPreferencePage_closeStrings;
224:                addCheckBox(composite, label,
225:                        PreferenceConstants.EDITOR_CLOSE_STRINGS, 0);
226:
227:                label = PreferencesMessages.JavaEditorPreferencePage_closeBrackets;
228:                addCheckBox(composite, label,
229:                        PreferenceConstants.EDITOR_CLOSE_BRACKETS, 0);
230:
231:                label = PreferencesMessages.JavaEditorPreferencePage_closeBraces;
232:                addCheckBox(composite, label,
233:                        PreferenceConstants.EDITOR_CLOSE_BRACES, 0);
234:
235:                label = PreferencesMessages.JavaEditorPreferencePage_closeJavaDocs;
236:                master = addCheckBox(composite, label,
237:                        PreferenceConstants.EDITOR_CLOSE_JAVADOCS, 0);
238:
239:                label = PreferencesMessages.JavaEditorPreferencePage_addJavaDocTags;
240:                slave = addCheckBox(composite, label,
241:                        PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS, 0);
242:                createDependency(master, slave);
243:            }
244:
245:            private void createMessage(final Composite composite) {
246:                // TODO create a link with an argument, so the formatter preference page can open the 
247:                // current profile automatically.
248:                String linkTooltip = PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_tooltip;
249:                String text;
250:                String indentMode = JavaPlugin
251:                        .getDefault()
252:                        .getCombinedPreferenceStore()
253:                        .getString(
254:                                DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR);
255:                if (JavaCore.TAB.equals(indentMode))
256:                    text = Messages
257:                            .format(
258:                                    PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_tab_text,
259:                                    new String[] { Integer
260:                                            .toString(getTabDisplaySize()) });
261:                else
262:                    text = Messages
263:                            .format(
264:                                    PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_others_text,
265:                                    new String[] {
266:                                            Integer
267:                                                    .toString(getTabDisplaySize()),
268:                                            Integer.toString(getIndentSize()),
269:                                            getIndentMode() });
270:
271:                final Link link = new Link(composite, SWT.NONE);
272:                link.setText(text);
273:                link.setToolTipText(linkTooltip);
274:                GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
275:                gd.widthHint = 300; // don't get wider initially
276:                link.setLayoutData(gd);
277:                link.addSelectionListener(new SelectionAdapter() {
278:                    public void widgetSelected(SelectionEvent e) {
279:                        PreferencesUtil
280:                                .createPreferenceDialogOn(
281:                                        link.getShell(),
282:                                        "org.eclipse.jdt.ui.preferences.CodeFormatterPreferencePage", null, null); //$NON-NLS-1$
283:                    }
284:                });
285:
286:                final IPreferenceStore combinedStore = JavaPlugin.getDefault()
287:                        .getCombinedPreferenceStore();
288:                final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() {
289:                    private boolean fHasRun = false;
290:
291:                    public void propertyChange(PropertyChangeEvent event) {
292:                        if (fHasRun)
293:                            return;
294:                        if (composite.isDisposed())
295:                            return;
296:                        String property = event.getProperty();
297:                        if (DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR
298:                                .equals(property)
299:                                || DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE
300:                                        .equals(property)) {
301:                            fHasRun = true;
302:                            link.dispose();
303:                            createMessage(composite);
304:                            Dialog.applyDialogFont(composite);
305:                            composite.redraw();
306:                            composite.layout();
307:                        }
308:                    }
309:                };
310:                combinedStore.addPropertyChangeListener(propertyChangeListener);
311:                link.addDisposeListener(new DisposeListener() {
312:                    public void widgetDisposed(
313:                            org.eclipse.swt.events.DisposeEvent e) {
314:                        combinedStore
315:                                .removePropertyChangeListener(propertyChangeListener);
316:                    }
317:                });
318:            }
319:
320:            private String getIndentMode() {
321:                String indentMode = JavaPlugin
322:                        .getDefault()
323:                        .getCombinedPreferenceStore()
324:                        .getString(
325:                                DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR);
326:
327:                if (JavaCore.SPACE.equals(indentMode))
328:                    return PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_spaces;
329:
330:                if (JavaCore.TAB.equals(indentMode))
331:                    return PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_tabs;
332:
333:                if (DefaultCodeFormatterConstants.MIXED.equals(indentMode))
334:                    return PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_tabsAndSpaces;
335:
336:                Assert.isTrue(false, "Illegal indent mode - must not happen"); //$NON-NLS-1$
337:                return null;
338:            }
339:
340:            private int getIndentSize() {
341:                return CodeFormatterUtil.getIndentWidth(null);
342:            }
343:
344:            private int getTabDisplaySize() {
345:                return CodeFormatterUtil.getTabWidth(null);
346:            }
347:
348:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.