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: * Sebastian Davids <sdavids@gmx.de> - bug 77332 - [Markers] Add task dialog improvements
011: *******************************************************************************/package org.eclipse.ui.views.markers.internal;
012:
013: import java.util.Map;
014:
015: import org.eclipse.core.resources.IMarker;
016: import org.eclipse.swt.SWT;
017: import org.eclipse.swt.events.SelectionAdapter;
018: import org.eclipse.swt.events.SelectionEvent;
019: import org.eclipse.swt.events.TraverseEvent;
020: import org.eclipse.swt.events.TraverseListener;
021: import org.eclipse.swt.layout.GridData;
022: import org.eclipse.swt.layout.GridLayout;
023: import org.eclipse.swt.widgets.Button;
024: import org.eclipse.swt.widgets.Combo;
025: import org.eclipse.swt.widgets.Composite;
026: import org.eclipse.swt.widgets.Label;
027: import org.eclipse.swt.widgets.Shell;
028:
029: /**
030: * DialogTaskProperties is the properties dialog
031: * for tasks.
032: *
033: */
034: public class DialogTaskProperties extends DialogMarkerProperties {
035:
036: private static final String PRIORITY_HIGH = MarkerMessages.propertiesDialog_priorityHigh;
037:
038: private static final String PRIORITY_NORMAL = MarkerMessages.propertiesDialog_priorityNormal;
039:
040: private static final String PRIORITY_LOW = MarkerMessages.propertiesDialog_priorityLow;
041:
042: protected Combo priorityCombo;
043:
044: protected Button completedCheckbox;
045:
046: /**
047: * @param parentShell
048: */
049: public DialogTaskProperties(Shell parentShell) {
050: super (parentShell);
051: setType(IMarker.TASK);
052: }
053:
054: /**
055: * @param parentShell
056: */
057: DialogTaskProperties(Shell parentShell, String title) {
058: super (parentShell, title);
059: setType(IMarker.TASK);
060: }
061:
062: /*
063: * (non-Javadoc)
064: * @see org.eclipse.ui.views.markers.internal.DialogMarkerProperties#createAttributesArea(org.eclipse.swt.widgets.Composite)
065: */
066: protected void createAttributesArea(Composite parent) {
067: createSeperator(parent);
068: super .createAttributesArea(parent);
069:
070: Label label = new Label(parent, SWT.NONE);
071: label.setText(MarkerMessages.propertiesDialog_priority);
072:
073: Composite composite = new Composite(parent, SWT.NONE);
074: GridLayout layout = new GridLayout();
075: layout.numColumns = 2;
076: layout.marginWidth = 0;
077: layout.marginHeight = 0;
078: composite.setLayout(layout);
079:
080: priorityCombo = new Combo(composite, SWT.READ_ONLY);
081: priorityCombo.setItems(new String[] { PRIORITY_HIGH,
082: PRIORITY_NORMAL, PRIORITY_LOW });
083: // Prevent Esc and Return from closing the dialog when the combo is active.
084: priorityCombo.addTraverseListener(new TraverseListener() {
085: public void keyTraversed(TraverseEvent e) {
086: if (e.detail == SWT.TRAVERSE_ESCAPE
087: || e.detail == SWT.TRAVERSE_RETURN) {
088: e.doit = false;
089: }
090: }
091: });
092: priorityCombo.addSelectionListener(new SelectionAdapter() {
093: public void widgetSelected(SelectionEvent e) {
094: if (getMarker() == null) {
095: Map initialAttributes = getInitialAttributes();
096: initialAttributes.put(IMarker.PRIORITY,
097: new Integer(getPriorityFromDialog()));
098: }
099: markDirty();
100: }
101: });
102:
103: completedCheckbox = new Button(composite, SWT.CHECK);
104: completedCheckbox
105: .setText(MarkerMessages.propertiesDialog_completed);
106: GridData gridData = new GridData();
107: gridData.horizontalIndent = convertHorizontalDLUsToPixels(20);
108: completedCheckbox.setLayoutData(gridData);
109: completedCheckbox.addSelectionListener(new SelectionAdapter() {
110: public void widgetSelected(SelectionEvent e) {
111: if (getMarker() == null) {
112: Map initialAttributes = getInitialAttributes();
113: initialAttributes
114: .put(IMarker.DONE, completedCheckbox
115: .getSelection() ? Boolean.TRUE
116: : Boolean.FALSE);
117: }
118: markDirty();
119: }
120: });
121: }
122:
123: protected boolean getCompleted() {
124: IMarker marker = getMarker();
125: if (marker == null) {
126: Map attributes = getInitialAttributes();
127: Object done = attributes.get(IMarker.DONE);
128: return done != null && done instanceof Boolean
129: && ((Boolean) done).booleanValue();
130: }
131: return marker.getAttribute(IMarker.DONE, false);
132: }
133:
134: protected int getPriority() {
135: IMarker marker = getMarker();
136: int priority = IMarker.PRIORITY_NORMAL;
137: if (marker == null) {
138: Map attributes = getInitialAttributes();
139: Object priorityObj = attributes.get(IMarker.PRIORITY);
140: if (priorityObj != null && priorityObj instanceof Integer) {
141: priority = ((Integer) priorityObj).intValue();
142: }
143: } else {
144: priority = marker.getAttribute(IMarker.PRIORITY,
145: IMarker.PRIORITY_NORMAL);
146: }
147: return priority;
148: }
149:
150: /*
151: * (non-Javadoc)
152: * @see org.eclipse.ui.views.markers.internal.DialogMarkerProperties#updateEnablement()
153: */
154: protected void updateEnablement() {
155: super .updateEnablement();
156: priorityCombo.setEnabled(isEditable());
157: completedCheckbox.setEnabled(isEditable());
158: }
159:
160: /*
161: * (non-Javadoc)
162: * @see org.eclipse.ui.views.markers.internal.DialogMarkerProperties#updateDialogForNewMarker()
163: */
164: protected void updateDialogForNewMarker() {
165: Map initialAttributes = getInitialAttributes();
166: int priority = getPriority();
167: initialAttributes.put(IMarker.PRIORITY, new Integer(priority));
168: if (priority == IMarker.PRIORITY_HIGH) {
169: priorityCombo.select(priorityCombo.indexOf(PRIORITY_HIGH));
170: } else if (priority == IMarker.PRIORITY_LOW) {
171: priorityCombo.select(priorityCombo.indexOf(PRIORITY_LOW));
172: } else {
173: priorityCombo
174: .select(priorityCombo.indexOf(PRIORITY_NORMAL));
175: }
176: boolean completed = getCompleted();
177: initialAttributes.put(IMarker.DONE, completed ? Boolean.TRUE
178: : Boolean.FALSE);
179: completedCheckbox.setSelection(completed);
180: super .updateDialogForNewMarker();
181: }
182:
183: /*
184: * (non-Javadoc)
185: * @see org.eclipse.ui.views.markers.internal.DialogMarkerProperties#updateDialogFromMarker()
186: */
187: protected void updateDialogFromMarker() {
188: Map initialAttributes = getInitialAttributes();
189: int priority = getPriority();
190: initialAttributes.put(IMarker.PRIORITY, new Integer(priority));
191: if (priority == IMarker.PRIORITY_HIGH) {
192: priorityCombo.select(priorityCombo.indexOf(PRIORITY_HIGH));
193: } else if (priority == IMarker.PRIORITY_LOW) {
194: priorityCombo.select(priorityCombo.indexOf(PRIORITY_LOW));
195: } else {
196: priorityCombo
197: .select(priorityCombo.indexOf(PRIORITY_NORMAL));
198: }
199: boolean completed = getCompleted();
200: initialAttributes.put(IMarker.DONE, completed ? Boolean.TRUE
201: : Boolean.FALSE);
202: completedCheckbox.setSelection(completed);
203: super .updateDialogFromMarker();
204: }
205:
206: private int getPriorityFromDialog() {
207: int priority = IMarker.PRIORITY_NORMAL;
208: if (priorityCombo.getSelectionIndex() == priorityCombo
209: .indexOf(PRIORITY_HIGH)) {
210: priority = IMarker.PRIORITY_HIGH;
211: } else if (priorityCombo.getSelectionIndex() == priorityCombo
212: .indexOf(PRIORITY_LOW)) {
213: priority = IMarker.PRIORITY_LOW;
214: }
215: return priority;
216: }
217:
218: /*
219: * (non-Javadoc)
220: * @see org.eclipse.ui.views.markers.internal.DialogMarkerProperties#getMarkerAttributes()
221: */
222: protected Map getMarkerAttributes() {
223: Map attrs = super .getMarkerAttributes();
224: attrs.put(IMarker.PRIORITY,
225: new Integer(getPriorityFromDialog()));
226: attrs.put(IMarker.DONE,
227: completedCheckbox.getSelection() ? Boolean.TRUE
228: : Boolean.FALSE);
229: Object userEditable = attrs.get(IMarker.USER_EDITABLE);
230: if (userEditable == null || !(userEditable instanceof Boolean)) {
231: attrs.put(IMarker.USER_EDITABLE, Boolean.TRUE);
232: }
233: return attrs;
234: }
235:
236: /* (non-Javadoc)
237: * @see org.eclipse.ui.views.markers.internal.DialogMarkerProperties.getModifyOperationTitle()
238: *
239: * @since 3.3
240: */
241: protected String getModifyOperationTitle() {
242: return MarkerMessages.modifyTask_title;
243: }
244:
245: /* (non-Javadoc)
246: * @see org.eclipse.ui.views.markers.internal.DialogMarkerProperties.getCreateOperationTitle()
247: *
248: * @since 3.3
249: */
250: protected String getCreateOperationTitle() {
251: return MarkerMessages.DialogTaskProperties_CreateTask;
252:
253: }
254:
255: }
|