Source Code Cross Referenced for TodoTaskConfigurationBlock.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, 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.jdt.internal.ui.preferences;
011:
012:        import java.util.ArrayList;
013:        import java.util.List;
014:
015:        import org.eclipse.core.runtime.IStatus;
016:
017:        import org.eclipse.core.resources.IProject;
018:
019:        import org.eclipse.swt.SWT;
020:        import org.eclipse.swt.graphics.Font;
021:        import org.eclipse.swt.graphics.Image;
022:        import org.eclipse.swt.layout.GridData;
023:        import org.eclipse.swt.layout.GridLayout;
024:        import org.eclipse.swt.widgets.Composite;
025:        import org.eclipse.swt.widgets.Control;
026:
027:        import org.eclipse.jface.resource.JFaceResources;
028:        import org.eclipse.jface.viewers.IFontProvider;
029:        import org.eclipse.jface.viewers.ITableLabelProvider;
030:        import org.eclipse.jface.viewers.LabelProvider;
031:        import org.eclipse.jface.viewers.Viewer;
032:        import org.eclipse.jface.viewers.ViewerComparator;
033:        import org.eclipse.jface.window.Window;
034:
035:        import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
036:
037:        import org.eclipse.jdt.core.JavaCore;
038:
039:        import org.eclipse.jdt.internal.corext.util.Messages;
040:
041:        import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
042:        import org.eclipse.jdt.internal.ui.util.PixelConverter;
043:        import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
044:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
045:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
046:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter;
047:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField;
048:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
049:
050:        /**
051:         */
052:        public class TodoTaskConfigurationBlock extends
053:                OptionsConfigurationBlock {
054:
055:            private static final Key PREF_COMPILER_TASK_TAGS = getJDTCoreKey(JavaCore.COMPILER_TASK_TAGS);
056:            private static final Key PREF_COMPILER_TASK_PRIORITIES = getJDTCoreKey(JavaCore.COMPILER_TASK_PRIORITIES);
057:
058:            private static final Key PREF_COMPILER_TASK_CASE_SENSITIVE = getJDTCoreKey(JavaCore.COMPILER_TASK_CASE_SENSITIVE);
059:
060:            private static final String PRIORITY_HIGH = JavaCore.COMPILER_TASK_PRIORITY_HIGH;
061:            private static final String PRIORITY_NORMAL = JavaCore.COMPILER_TASK_PRIORITY_NORMAL;
062:            private static final String PRIORITY_LOW = JavaCore.COMPILER_TASK_PRIORITY_LOW;
063:
064:            private static final String ENABLED = JavaCore.ENABLED;
065:            private static final String DISABLED = JavaCore.DISABLED;
066:
067:            public static class TodoTask {
068:                public String name;
069:                public String priority;
070:            }
071:
072:            private class TodoTaskLabelProvider extends LabelProvider implements 
073:                    ITableLabelProvider, IFontProvider {
074:
075:                public TodoTaskLabelProvider() {
076:                }
077:
078:                /* (non-Javadoc)
079:                 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
080:                 */
081:                public Image getImage(Object element) {
082:                    return null; // JavaPluginImages.get(JavaPluginImages.IMG_OBJS_REFACTORING_INFO);
083:                }
084:
085:                /* (non-Javadoc)
086:                 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
087:                 */
088:                public String getText(Object element) {
089:                    return getColumnText(element, 0);
090:                }
091:
092:                /* (non-Javadoc)
093:                 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
094:                 */
095:                public Image getColumnImage(Object element, int columnIndex) {
096:                    return null;
097:                }
098:
099:                /* (non-Javadoc)
100:                 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
101:                 */
102:                public String getColumnText(Object element, int columnIndex) {
103:                    TodoTask task = (TodoTask) element;
104:                    if (columnIndex == 0) {
105:                        String name = task.name;
106:                        if (isDefaultTask(task)) {
107:                            name = Messages
108:                                    .format(
109:                                            PreferencesMessages.TodoTaskConfigurationBlock_tasks_default,
110:                                            name);
111:                        }
112:                        return name;
113:                    } else {
114:                        if (PRIORITY_HIGH.equals(task.priority)) {
115:                            return PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_high_priority;
116:                        } else if (PRIORITY_NORMAL.equals(task.priority)) {
117:                            return PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_normal_priority;
118:                        } else if (PRIORITY_LOW.equals(task.priority)) {
119:                            return PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_low_priority;
120:                        }
121:                        return ""; //$NON-NLS-1$
122:                    }
123:                }
124:
125:                /* (non-Javadoc)
126:                 * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object)
127:                 */
128:                public Font getFont(Object element) {
129:                    if (isDefaultTask((TodoTask) element)) {
130:                        return JFaceResources.getFontRegistry().getBold(
131:                                JFaceResources.DIALOG_FONT);
132:                    }
133:                    return null;
134:                }
135:            }
136:
137:            private static class TodoTaskSorter extends ViewerComparator {
138:                public int compare(Viewer viewer, Object e1, Object e2) {
139:                    return getComparator().compare(((TodoTask) e1).name,
140:                            ((TodoTask) e2).name);
141:                }
142:            }
143:
144:            private static final int IDX_ADD = 0;
145:            private static final int IDX_EDIT = 1;
146:            private static final int IDX_REMOVE = 2;
147:            private static final int IDX_DEFAULT = 4;
148:
149:            private IStatus fTaskTagsStatus;
150:            private ListDialogField fTodoTasksList;
151:            private SelectionButtonDialogField fCaseSensitiveCheckBox;
152:
153:            public TodoTaskConfigurationBlock(IStatusChangeListener context,
154:                    IProject project, IWorkbenchPreferenceContainer container) {
155:                super (context, project, getKeys(), container);
156:
157:                TaskTagAdapter adapter = new TaskTagAdapter();
158:                String[] buttons = new String[] {
159:                        PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_add_button,
160:                        PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_edit_button,
161:                        PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_remove_button,
162:                        null,
163:                        PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_setdefault_button, };
164:                fTodoTasksList = new ListDialogField(adapter, buttons,
165:                        new TodoTaskLabelProvider());
166:                fTodoTasksList.setDialogFieldListener(adapter);
167:                fTodoTasksList.setRemoveButtonIndex(IDX_REMOVE);
168:
169:                String[] columnsHeaders = new String[] {
170:                        PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_name_column,
171:                        PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_priority_column, };
172:
173:                fTodoTasksList
174:                        .setTableColumns(new ListDialogField.ColumnsDescription(
175:                                columnsHeaders, true));
176:                fTodoTasksList.setViewerComparator(new TodoTaskSorter());
177:
178:                fCaseSensitiveCheckBox = new SelectionButtonDialogField(
179:                        SWT.CHECK);
180:                fCaseSensitiveCheckBox
181:                        .setLabelText(PreferencesMessages.TodoTaskConfigurationBlock_casesensitive_label);
182:                fCaseSensitiveCheckBox.setDialogFieldListener(adapter);
183:
184:                unpackTodoTasks();
185:                if (fTodoTasksList.getSize() > 0) {
186:                    fTodoTasksList.selectFirstElement();
187:                } else {
188:                    fTodoTasksList.enableButton(IDX_EDIT, false);
189:                    fTodoTasksList.enableButton(IDX_DEFAULT, false);
190:                }
191:
192:                fTaskTagsStatus = new StatusInfo();
193:            }
194:
195:            public void setEnabled(boolean isEnabled) {
196:                fTodoTasksList.setEnabled(isEnabled);
197:                fCaseSensitiveCheckBox.setEnabled(isEnabled);
198:            }
199:
200:            final boolean isDefaultTask(TodoTask task) {
201:                return fTodoTasksList.getIndexOfElement(task) == 0;
202:            }
203:
204:            private void setToDefaultTask(TodoTask task) {
205:                List elements = fTodoTasksList.getElements();
206:                elements.remove(task);
207:                elements.add(0, task);
208:                fTodoTasksList.setElements(elements);
209:                fTodoTasksList.enableButton(IDX_DEFAULT, false);
210:            }
211:
212:            private static Key[] getKeys() {
213:                return new Key[] { PREF_COMPILER_TASK_TAGS,
214:                        PREF_COMPILER_TASK_PRIORITIES,
215:                        PREF_COMPILER_TASK_CASE_SENSITIVE };
216:            }
217:
218:            public class TaskTagAdapter implements  IListAdapter,
219:                    IDialogFieldListener {
220:
221:                private boolean canEdit(List selectedElements) {
222:                    return selectedElements.size() == 1;
223:                }
224:
225:                private boolean canSetToDefault(List selectedElements) {
226:                    return selectedElements.size() == 1
227:                            && !isDefaultTask((TodoTask) selectedElements
228:                                    .get(0));
229:                }
230:
231:                public void customButtonPressed(ListDialogField field, int index) {
232:                    doTodoButtonPressed(index);
233:                }
234:
235:                public void selectionChanged(ListDialogField field) {
236:                    List selectedElements = field.getSelectedElements();
237:                    field.enableButton(IDX_EDIT, canEdit(selectedElements));
238:                    field.enableButton(IDX_DEFAULT,
239:                            canSetToDefault(selectedElements));
240:                }
241:
242:                public void doubleClicked(ListDialogField field) {
243:                    if (canEdit(field.getSelectedElements())) {
244:                        doTodoButtonPressed(IDX_EDIT);
245:                    }
246:                }
247:
248:                public void dialogFieldChanged(DialogField field) {
249:                    updateModel(field);
250:                }
251:
252:            }
253:
254:            protected Control createContents(Composite parent) {
255:                setShell(parent.getShell());
256:
257:                Composite markersComposite = createMarkersTabContent(parent);
258:
259:                validateSettings(null, null, null);
260:
261:                return markersComposite;
262:            }
263:
264:            private Composite createMarkersTabContent(Composite folder) {
265:                GridLayout layout = new GridLayout();
266:                layout.marginHeight = 0;
267:                layout.marginWidth = 0;
268:                layout.numColumns = 2;
269:
270:                PixelConverter conv = new PixelConverter(folder);
271:
272:                Composite markersComposite = new Composite(folder, SWT.NULL);
273:                markersComposite.setLayout(layout);
274:                markersComposite.setFont(folder.getFont());
275:
276:                GridData data = new GridData(GridData.FILL_BOTH);
277:                data.widthHint = conv.convertWidthInCharsToPixels(50);
278:                Control listControl = fTodoTasksList
279:                        .getListControl(markersComposite);
280:                listControl.setLayoutData(data);
281:
282:                Control buttonsControl = fTodoTasksList
283:                        .getButtonBox(markersComposite);
284:                buttonsControl.setLayoutData(new GridData(
285:                        GridData.HORIZONTAL_ALIGN_FILL
286:                                | GridData.VERTICAL_ALIGN_BEGINNING));
287:
288:                fCaseSensitiveCheckBox.doFillIntoGrid(markersComposite, 2);
289:
290:                return markersComposite;
291:            }
292:
293:            protected void validateSettings(Key changedKey, String oldValue,
294:                    String newValue) {
295:                if (!areSettingsEnabled()) {
296:                    return;
297:                }
298:
299:                if (changedKey != null) {
300:                    if (PREF_COMPILER_TASK_TAGS.equals(changedKey)) {
301:                        fTaskTagsStatus = validateTaskTags();
302:                    } else {
303:                        return;
304:                    }
305:                } else {
306:                    fTaskTagsStatus = validateTaskTags();
307:                }
308:                IStatus status = fTaskTagsStatus; //StatusUtil.getMostSevere(new IStatus[] { fTaskTagsStatus });
309:                fContext.statusChanged(status);
310:            }
311:
312:            private IStatus validateTaskTags() {
313:                return new StatusInfo();
314:            }
315:
316:            protected final void updateModel(DialogField field) {
317:                if (field == fTodoTasksList) {
318:                    StringBuffer tags = new StringBuffer();
319:                    StringBuffer prios = new StringBuffer();
320:                    List list = fTodoTasksList.getElements();
321:                    for (int i = 0; i < list.size(); i++) {
322:                        if (i > 0) {
323:                            tags.append(',');
324:                            prios.append(',');
325:                        }
326:                        TodoTask elem = (TodoTask) list.get(i);
327:                        tags.append(elem.name);
328:                        prios.append(elem.priority);
329:                    }
330:                    setValue(PREF_COMPILER_TASK_TAGS, tags.toString());
331:                    setValue(PREF_COMPILER_TASK_PRIORITIES, prios.toString());
332:                    validateSettings(PREF_COMPILER_TASK_TAGS, null, null);
333:                } else if (field == fCaseSensitiveCheckBox) {
334:                    String state = fCaseSensitiveCheckBox.isSelected() ? ENABLED
335:                            : DISABLED;
336:                    setValue(PREF_COMPILER_TASK_CASE_SENSITIVE, state);
337:                }
338:            }
339:
340:            protected String[] getFullBuildDialogStrings(
341:                    boolean workspaceSettings) {
342:                String title = PreferencesMessages.TodoTaskConfigurationBlock_needsbuild_title;
343:                String message;
344:                if (fProject == null) {
345:                    message = PreferencesMessages.TodoTaskConfigurationBlock_needsfullbuild_message;
346:                } else {
347:                    message = PreferencesMessages.TodoTaskConfigurationBlock_needsprojectbuild_message;
348:                }
349:                return new String[] { title, message };
350:            }
351:
352:            /* (non-Javadoc)
353:             * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#updateControls()
354:             */
355:            protected void updateControls() {
356:                unpackTodoTasks();
357:            }
358:
359:            private void unpackTodoTasks() {
360:                String currTags = getValue(PREF_COMPILER_TASK_TAGS);
361:                String currPrios = getValue(PREF_COMPILER_TASK_PRIORITIES);
362:                String[] tags = getTokens(currTags, ","); //$NON-NLS-1$
363:                String[] prios = getTokens(currPrios, ","); //$NON-NLS-1$
364:                ArrayList elements = new ArrayList(tags.length);
365:                for (int i = 0; i < tags.length; i++) {
366:                    TodoTask task = new TodoTask();
367:                    task.name = tags[i].trim();
368:                    task.priority = (i < prios.length) ? prios[i]
369:                            : PRIORITY_NORMAL;
370:                    elements.add(task);
371:                }
372:                fTodoTasksList.setElements(elements);
373:
374:                boolean isCaseSensitive = checkValue(
375:                        PREF_COMPILER_TASK_CASE_SENSITIVE, ENABLED);
376:                fCaseSensitiveCheckBox.setSelection(isCaseSensitive);
377:            }
378:
379:            private void doTodoButtonPressed(int index) {
380:                TodoTask edited = null;
381:                if (index != IDX_ADD) {
382:                    edited = (TodoTask) fTodoTasksList.getSelectedElements()
383:                            .get(0);
384:                }
385:                if (index == IDX_ADD || index == IDX_EDIT) {
386:                    TodoTaskInputDialog dialog = new TodoTaskInputDialog(
387:                            getShell(), edited, fTodoTasksList.getElements());
388:                    if (dialog.open() == Window.OK) {
389:                        if (edited != null) {
390:                            fTodoTasksList.replaceElement(edited, dialog
391:                                    .getResult());
392:                        } else {
393:                            fTodoTasksList.addElement(dialog.getResult());
394:                        }
395:                    }
396:                } else if (index == IDX_DEFAULT) {
397:                    setToDefaultTask(edited);
398:                }
399:            }
400:
401:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.