KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > internal > DialogTaskProperties


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Sebastian Davids <sdavids@gmx.de> - bug 77332 - [Markers] Add task dialog improvements
11  *******************************************************************************/

12
13 package org.eclipse.ui.views.markers.internal;
14
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.core.resources.IMarker;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.events.SelectionAdapter;
20 import org.eclipse.swt.events.SelectionEvent;
21 import org.eclipse.swt.events.TraverseEvent;
22 import org.eclipse.swt.events.TraverseListener;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Button;
26 import org.eclipse.swt.widgets.Combo;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Label;
29 import org.eclipse.swt.widgets.Shell;
30
31 /**
32  * DialogTaskProperties is the properties dialog
33  * for tasks.
34  *
35  */

36 public class DialogTaskProperties extends DialogMarkerProperties {
37
38     private static final String JavaDoc PRIORITY_HIGH =
39         MarkerMessages.propertiesDialog_priorityHigh;
40
41     private static final String JavaDoc PRIORITY_NORMAL =
42         MarkerMessages.propertiesDialog_priorityNormal;
43
44     private static final String JavaDoc PRIORITY_LOW =
45         MarkerMessages.propertiesDialog_priorityLow;
46
47     protected Combo priorityCombo;
48
49     protected Button completedCheckbox;
50
51     /**
52      * @param parentShell
53      */

54     public DialogTaskProperties(Shell parentShell) {
55         super(parentShell);
56         setType(IMarker.TASK);
57     }
58
59     /**
60      * @param parentShell
61      */

62     DialogTaskProperties(Shell parentShell, String JavaDoc title) {
63         super(parentShell, title);
64         setType(IMarker.TASK);
65     }
66
67     /*
68      * (non-Javadoc)
69      * @see org.eclipse.ui.views.markers.internal.DialogMarkerProperties#createAttributesArea(org.eclipse.swt.widgets.Composite)
70      */

71     protected void createAttributesArea(Composite parent) {
72         createSeperator(parent);
73         super.createAttributesArea(parent);
74
75         Label label = new Label(parent, SWT.NONE);
76         label.setText(MarkerMessages.propertiesDialog_priority);
77         
78         Composite composite = new Composite(parent, SWT.NONE);
79         GridLayout layout = new GridLayout();
80         layout.numColumns = 2;
81         layout.marginWidth = 0;
82         layout.marginHeight = 0;
83         composite.setLayout(layout);
84         
85         priorityCombo = new Combo(composite, SWT.READ_ONLY);
86         priorityCombo.setItems(new String JavaDoc[] { PRIORITY_HIGH, PRIORITY_NORMAL,
87                 PRIORITY_LOW });
88         // Prevent Esc and Return from closing the dialog when the combo is active.
89
priorityCombo.addTraverseListener(new TraverseListener() {
90             public void keyTraversed(TraverseEvent e) {
91                 if (e.detail == SWT.TRAVERSE_ESCAPE
92                         || e.detail == SWT.TRAVERSE_RETURN) {
93                     e.doit = false;
94                 }
95             }
96         });
97         priorityCombo.addSelectionListener(new SelectionAdapter() {
98             public void widgetSelected(SelectionEvent e) {
99                 if (getMarker() == null) {
100                     Map JavaDoc initialAttributes = getInitialAttributes();
101                     initialAttributes.put(IMarker.PRIORITY, new Integer JavaDoc(
102                             getPriorityFromDialog()));
103                 }
104                 markDirty();
105             }
106         });
107
108         completedCheckbox = new Button(composite, SWT.CHECK);
109         completedCheckbox.setText(MarkerMessages.propertiesDialog_completed);
110         GridData gridData = new GridData();
111         gridData.horizontalIndent = convertHorizontalDLUsToPixels(20);
112         completedCheckbox.setLayoutData(gridData);
113         completedCheckbox.addSelectionListener(new SelectionAdapter() {
114             public void widgetSelected(SelectionEvent e) {
115                 if (getMarker() == null) {
116                     Map JavaDoc initialAttributes = getInitialAttributes();
117                     initialAttributes.put(IMarker.DONE, completedCheckbox.getSelection() ? Boolean.TRUE : Boolean.FALSE);
118                 }
119                 markDirty();
120             }
121         });
122     }
123
124     protected boolean getCompleted() {
125         IMarker marker = getMarker();
126         if (marker == null) {
127             Map JavaDoc attributes = getInitialAttributes();
128             Object JavaDoc done = attributes.get(IMarker.DONE);
129             return done != null && done instanceof Boolean JavaDoc
130                     && ((Boolean JavaDoc) done).booleanValue();
131         }
132         return marker.getAttribute(IMarker.DONE, false);
133     }
134
135     protected int getPriority() {
136         IMarker marker = getMarker();
137         int priority = IMarker.PRIORITY_NORMAL;
138         if (marker == null) {
139             Map JavaDoc attributes = getInitialAttributes();
140             Object JavaDoc priorityObj = attributes.get(IMarker.PRIORITY);
141             if (priorityObj != null && priorityObj instanceof Integer JavaDoc) {
142                 priority = ((Integer JavaDoc) priorityObj).intValue();
143             }
144         } else {
145             priority = marker.getAttribute(IMarker.PRIORITY,
146                     IMarker.PRIORITY_NORMAL);
147         }
148         return priority;
149     }
150
151     /*
152      * (non-Javadoc)
153      * @see org.eclipse.ui.views.markers.internal.DialogMarkerProperties#updateEnablement()
154      */

155     protected void updateEnablement() {
156         super.updateEnablement();
157         priorityCombo.setEnabled(isEditable());
158         completedCheckbox.setEnabled(isEditable());
159     }
160
161     /*
162      * (non-Javadoc)
163      * @see org.eclipse.ui.views.markers.internal.DialogMarkerProperties#updateDialogForNewMarker()
164      */

165     protected void updateDialogForNewMarker() {
166         Map JavaDoc initialAttributes = getInitialAttributes();
167         int priority = getPriority();
168         initialAttributes.put(IMarker.PRIORITY, new Integer JavaDoc(priority));
169         if (priority == IMarker.PRIORITY_HIGH) {
170             priorityCombo.select(priorityCombo.indexOf(PRIORITY_HIGH));
171         } else if (priority == IMarker.PRIORITY_LOW) {
172             priorityCombo.select(priorityCombo.indexOf(PRIORITY_LOW));
173         } else {
174             priorityCombo.select(priorityCombo.indexOf(PRIORITY_NORMAL));
175         }
176         boolean completed = getCompleted();
177         initialAttributes.put(IMarker.DONE, completed ? Boolean.TRUE : Boolean.FALSE);
178         completedCheckbox.setSelection(completed);
179         super.updateDialogForNewMarker();
180     }
181
182     /*
183      * (non-Javadoc)
184      * @see org.eclipse.ui.views.markers.internal.DialogMarkerProperties#updateDialogFromMarker()
185      */

186     protected void updateDialogFromMarker() {
187         Map JavaDoc initialAttributes = getInitialAttributes();
188         int priority = getPriority();
189         initialAttributes.put(IMarker.PRIORITY, new Integer JavaDoc(priority));
190         if (priority == IMarker.PRIORITY_HIGH) {
191             priorityCombo.select(priorityCombo.indexOf(PRIORITY_HIGH));
192         } else if (priority == IMarker.PRIORITY_LOW) {
193             priorityCombo.select(priorityCombo.indexOf(PRIORITY_LOW));
194         } else {
195             priorityCombo.select(priorityCombo.indexOf(PRIORITY_NORMAL));
196         }
197         boolean completed = getCompleted();
198         initialAttributes.put(IMarker.DONE, completed ? Boolean.TRUE : Boolean.FALSE);
199         completedCheckbox.setSelection(completed);
200         super.updateDialogFromMarker();
201     }
202
203     private int getPriorityFromDialog() {
204         int priority = IMarker.PRIORITY_NORMAL;
205         if (priorityCombo.getSelectionIndex() == priorityCombo
206                 .indexOf(PRIORITY_HIGH)) {
207             priority = IMarker.PRIORITY_HIGH;
208         } else if (priorityCombo.getSelectionIndex() == priorityCombo
209                 .indexOf(PRIORITY_LOW)) {
210             priority = IMarker.PRIORITY_LOW;
211         }
212         return priority;
213     }
214
215     /*
216      * (non-Javadoc)
217      * @see org.eclipse.ui.views.markers.internal.DialogMarkerProperties#getMarkerAttributes()
218      */

219     protected Map JavaDoc getMarkerAttributes() {
220         Map JavaDoc attrs = super.getMarkerAttributes();
221         attrs.put(IMarker.PRIORITY, new Integer JavaDoc(getPriorityFromDialog()));
222         attrs.put(IMarker.DONE, completedCheckbox.getSelection() ? Boolean.TRUE : Boolean.FALSE);
223         Object JavaDoc userEditable = attrs.get(IMarker.USER_EDITABLE);
224         if (userEditable == null || !(userEditable instanceof Boolean JavaDoc)) {
225             attrs.put(IMarker.USER_EDITABLE, Boolean.TRUE);
226         }
227         return attrs;
228     }
229     
230     /* (non-Javadoc)
231      * @see org.eclipse.ui.views.markers.internal.DialogMarkerProperties.getModifyOperationTitle()
232      *
233      * @since 3.3
234      */

235     protected String JavaDoc getModifyOperationTitle() {
236         return MarkerMessages.modifyTask_title;
237     }
238     
239     /* (non-Javadoc)
240      * @see org.eclipse.ui.views.markers.internal.DialogMarkerProperties.getCreateOperationTitle()
241      *
242      * @since 3.3
243      */

244     protected String JavaDoc getCreateOperationTitle() {
245         return MarkerMessages.DialogTaskProperties_CreateTask;
246         
247     }
248
249 }
250
Popular Tags