Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7c363ffee995e3d08838f1479a44f26b94f7074b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
/*******************************************************************************
 * Copyright (c) 2004 - 2005 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/
/*
 * Created on 19-Jan-2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.eclipse.mylar.tasklist.ui;

import java.util.Calendar;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.mylar.core.MylarPlugin;
import org.eclipse.mylar.tasklist.ITask;
import org.eclipse.mylar.tasklist.ITaskActivityListener;
import org.eclipse.mylar.tasklist.MylarTasklistPlugin;
import org.eclipse.mylar.tasklist.contribution.DatePicker;
import org.eclipse.mylar.tasklist.ui.views.TaskListView;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.RetargetAction;
import org.eclipse.ui.forms.FormColors;
import org.eclipse.ui.forms.events.ExpansionEvent;
import org.eclipse.ui.forms.events.IExpansionListener;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
import org.eclipse.ui.internal.WorkbenchImages;
import org.eclipse.ui.internal.WorkbenchMessages;
import org.eclipse.ui.part.EditorPart;

/**
 * For details on forms, go to:
 * 	http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/pde-ui-home/working/EclipseForms/EclipseForms.html
 *
 * @author Mik Kersten
 * @author Ken Sueda (initial prototype)
 */
public class TaskSummaryEditor extends EditorPart {
	
	private static final String DESCRIPTION_OVERVIEW = "Task Summary";

	/**
	 * TODO: use workbench theme
	 */
	public static final Color HYPERLINK  = new Color(Display.getDefault(), 0, 0, 255);
	
	private DatePicker datePicker;
	private ITask task;
	private TaskEditorInput editorInput;
	private Composite editorComposite;
	private TaskEditorCopyAction copyAction;
	private RetargetAction pasteAction;
	private RetargetAction cutAction;
	private static final String cutActionDefId = "org.eclipse.ui.edit.cut";
	private static final String pasteActionDefId = "org.eclipse.ui.edit.paste";
		
	private Button browse;
	private Text pathText;
	private ScrolledForm form;
    private Text description;
    private Text issueReportURL;
    private Text notes;
    private Spinner estimated;
    
    private boolean isDirty = false;
    private MylarTaskEditor parentEditor = null;

    private ITaskActivityListener TASK_LIST_LISTENER = new ITaskActivityListener() {
        public void taskActivated(ITask activeTask) {    
        	if (task != null && !browse.isDisposed() && activeTask.getHandleIdentifier().equals(task.getHandleIdentifier())) {
        		browse.setEnabled(false);
        	}
        }

        public void tasksActivated(List<ITask> tasks) {
            for (ITask t : tasks) {
            	taskActivated(t);
            }
        }

        public void taskDeactivated(ITask deactiveTask) {
        	if (task != null && !browse.isDisposed() && deactiveTask.getHandleIdentifier().equals(task.getHandleIdentifier())) {
        		browse.setEnabled(true);
        	}
        }

		public void taskPropertyChanged(ITask updatedTask, String property) {
			if (task != null && updatedTask.getHandleIdentifier().equals(task.getHandleIdentifier())) {
        		if (property.equals("Description") && !description.isDisposed()) {
        			description.setText(task.getDescription(false));
        		} else if (property.equals("Path") && !pathText.isDisposed()) {
        			pathText.setText("<Mylar_Dir>/" + task.getPath());
        		}
        	}
		}        
    };    

	public TaskSummaryEditor() {
		super();

		cutAction = new RetargetAction(ActionFactory.CUT.getId(),
                WorkbenchMessages.Workbench_cut);
		cutAction.setToolTipText(
                WorkbenchMessages.Workbench_cutToolTip);
		cutAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(
			ISharedImages.IMG_TOOL_CUT));
		cutAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(
			ISharedImages.IMG_TOOL_CUT));
		cutAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(
			ISharedImages.IMG_TOOL_CUT_DISABLED));
		cutAction.setAccelerator(SWT.CTRL | 'x');
		cutAction.setActionDefinitionId(cutActionDefId);

		pasteAction = new RetargetAction(ActionFactory.PASTE.getId(),
                WorkbenchMessages.Workbench_paste);
		pasteAction.setToolTipText(
                WorkbenchMessages.Workbench_pasteToolTip);
		pasteAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(
			ISharedImages.IMG_TOOL_PASTE));
		pasteAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(
			ISharedImages.IMG_TOOL_PASTE));
		pasteAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(
			ISharedImages.IMG_TOOL_PASTE_DISABLED));
		pasteAction.setAccelerator(SWT.CTRL | 'v');
		pasteAction.setActionDefinitionId(pasteActionDefId);

		copyAction = new TaskEditorCopyAction();
		copyAction.setText(
                WorkbenchMessages.Workbench_copy);
		copyAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(
			ISharedImages.IMG_TOOL_COPY));
		copyAction.setHoverImageDescriptor(WorkbenchImages.getImageDescriptor(
			ISharedImages.IMG_TOOL_COPY));
		copyAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(
			ISharedImages.IMG_TOOL_COPY_DISABLED));
		copyAction.setAccelerator(SWT.CTRL | 'c');

		copyAction.setEnabled(false);
		MylarTasklistPlugin.getTaskListManager().addListener(TASK_LIST_LISTENER);
	}
	
	@Override
	public void doSave(IProgressMonitor monitor) {
		String label = description.getText();
		task.setDescription(label);
		task.setIssueReportURL(issueReportURL.getText());
		String note = notes.getText();
		task.setNotes(note);		
		task.setEstimatedTime(estimated.getSelection());
//		links.clear();		
//		TableItem[] items = table.getItems();
//		for (int i = 0; i < items.length; i++) {
//			if (items[i].getData() instanceof String) {
//				links.add((String)items[i].getData());
//			}			
//		}
		//"<MylarDir>/" + res + ".xml"
		String path = pathText.getText();		
		path = path.substring(path.indexOf('/') + 1, path.lastIndexOf('.'));		
		task.setPath(path);
		if (datePicker != null && datePicker.getDate() != null) {
			task.setReminderDate(datePicker.getDate().getTime());
		}
		refreshTaskListView(task);
		markDirty(false);
	}
	
	@Override
	public void doSaveAs() {
		// don't support saving
	}
	
	@SuppressWarnings("deprecation")
	@Override
	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
		if (!(input instanceof TaskEditorInput)) {
			throw new PartInitException("Invalid Input: Must be TaskEditorInput");
		}
		setSite(site);
		setInput(input);
		editorInput = (TaskEditorInput)input;
		setPartName(editorInput.getLabel());
	}
	
	@Override
	public boolean isDirty() {
		return isDirty;
	}
	
	@Override
	public boolean isSaveAsAllowed() {
		return false;
	}
	
	@Override
	public void createPartControl(Composite parent) {
		FormToolkit toolkit = new FormToolkit(parent.getDisplay());
		form = toolkit.createScrolledForm(parent);
		form.getBody().setLayout(new TableWrapLayout());
		editorComposite = form.getBody();
		
		
		TableWrapLayout layout = new TableWrapLayout();
		layout.bottomMargin = 10;
		layout.topMargin = 10;
		layout.leftMargin = 10;
		layout.rightMargin = 10;
		layout.numColumns = 1;
		layout.makeColumnsEqualWidth = true;
		layout.verticalSpacing = 20;
		layout.horizontalSpacing = 10;
		editorComposite.setLayout(layout);
		//editorComposite.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));				
		
		// Put the info onto the editor
		createContent(editorComposite, toolkit);
		form.setFocus();
	}

	@Override
	public void setFocus() {
		form.setFocus();
	}

	public Control getControl() {
		return form;
	}
	
	public void setTask(ITask task) throws Exception {
		if (task == null)
			throw new Exception("ITask object is null.");
		this.task = task;
	}
	
	private Composite createContent(Composite parent, FormToolkit toolkit) {				
		TaskEditorInput taskEditorInput = (TaskEditorInput)getEditorInput();
		
		task = taskEditorInput.getTask();
		if (task == null) {
			MessageDialog.openError(parent.getShell(), "No such task", "No task exists with this id");
			return null;
		}		
        
		try {
			createOverviewSection(parent, toolkit);	
			createPlanningSection(parent, toolkit);
			createDocumentationSection(parent, toolkit);
//	        createRelatedLinksSection(parent, toolkit);
	        createDetailsSection(parent, toolkit);
        } catch (SWTException e) {
        	MylarPlugin.log(e, "content failed");
        }	       
		return null;
	}
	
	private void createOverviewSection(Composite parent, FormToolkit toolkit) {
		Section section = toolkit.createSection(parent, ExpandableComposite.TITLE_BAR);
		section.setText(DESCRIPTION_OVERVIEW);
		section.setLayout(new TableWrapLayout());
		section.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
		section.addExpansionListener(new IExpansionListener() {
			public void expansionStateChanging(ExpansionEvent e) {
				form.reflow(true);
			}
			public void expansionStateChanged(ExpansionEvent e) {
				form.reflow(true);
			}			
		});
		
		Composite container = toolkit.createComposite(section);
		section.setClient(container);		
		TableWrapLayout layout = new TableWrapLayout();
		layout.numColumns = 2;						
		container.setLayout(layout);
		container.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
		
        Label l = toolkit.createLabel(container, "Description:");
        l.setForeground(toolkit.getColors().getColor(FormColors.TITLE));	        
        description = toolkit.createText(container, task.getDescription(true), SWT.BORDER);
        TableWrapData td = new TableWrapData(TableWrapData.FILL_GRAB);
//        td.colspan = 2;
        description.setLayoutData(td);
        if (!task.isDirectlyModifiable()) {
        	description.setEnabled(false);
        } else {
        	description.addModifyListener(new ModifyListener() {
    			public void modifyText(ModifyEvent e) {
    				markDirty(true);
    			}			
    		});
        }
        
        Label urlLabel = toolkit.createLabel(container, "Web Link:");
        urlLabel.setForeground(toolkit.getColors().getColor(FormColors.TITLE));	        
        issueReportURL = toolkit.createText(container, task.getIssueReportURL(), SWT.BORDER);
        issueReportURL.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
//        issueReportURL.setForeground(HYPERLINK);

        if (!task.isDirectlyModifiable()) {
        	issueReportURL.setEnabled(false);
        } else {
        	issueReportURL.addModifyListener(new ModifyListener() {
    			public void modifyText(ModifyEvent e) {
    				markDirty(true);
    			}			
    		});
        }
	}	
	
	private void createDocumentationSection(Composite parent, FormToolkit toolkit) {
		Section section = toolkit.createSection(parent, ExpandableComposite.TITLE_BAR);
		section.setText("Documentation");			
		section.setLayout(new TableWrapLayout());
		section.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
		section.addExpansionListener(new IExpansionListener() {
			public void expansionStateChanging(ExpansionEvent e) {
				form.reflow(true);
			}

			public void expansionStateChanged(ExpansionEvent e) {
				form.reflow(true);
			}			
		});
		Composite container = toolkit.createComposite(section);			
		section.setClient(container);		
		TableWrapLayout layout = new TableWrapLayout();
		layout.numColumns = 1;					
		container.setLayout(layout);
       
		notes = toolkit.createText(container, task.getNotes(), SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
		TableWrapData tablewrap = new TableWrapData(TableWrapData.FILL_GRAB);
		tablewrap.heightHint = 200;
		tablewrap.grabVertical = true;
		notes.setLayoutData(tablewrap);
		notes.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				markDirty(true);
			}			
		});
		
		toolkit.paintBordersFor(container);
	}
	
	private void createPlanningSection(Composite parent, FormToolkit toolkit) {
		Section section = toolkit.createSection(parent, ExpandableComposite.TITLE_BAR);
		section.setText("Planning");			
		section.setLayout(new TableWrapLayout());
		section.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
		section.addExpansionListener(new IExpansionListener() {
			public void expansionStateChanging(ExpansionEvent e) {
				form.reflow(true);
			}

			public void expansionStateChanged(ExpansionEvent e) {
				form.reflow(true);
			}			
		});
		Composite container = toolkit.createComposite(section);			
		section.setClient(container);		
		TableWrapLayout layout = new TableWrapLayout();
		layout.numColumns = 3;					
		container.setLayout(layout);
		
		Label label = toolkit.createLabel(container, "Reminder:");
        label.setForeground(toolkit.getColors().getColor(FormColors.TITLE));	        
        datePicker = new DatePicker(container, SWT.NULL);	
        TableWrapData td = new TableWrapData(TableWrapData.LEFT);
        datePicker.setLayoutData(td);
        Calendar calendar = Calendar.getInstance();
        if (task.getReminderDate() != null) {
        	calendar.setTime(task.getReminderDate());
        	datePicker.setDate(calendar);
        }
		datePicker.setBackground(new Color(Display.getDefault(), 255, 255, 255));
		datePicker.addPickerSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent arg0) {
				TaskSummaryEditor.this.markDirty(true);
			}

			public void widgetDefaultSelected(SelectionEvent arg0) {
				// ignore
			}
		});
        label = toolkit.createLabel(container, " ");
        label.setForeground(toolkit.getColors().getColor(FormColors.TITLE));	
        
		label = toolkit.createLabel(container, "Estimated time:");		
		label.setForeground(toolkit.getColors().getColor(FormColors.TITLE));
		estimated = new Spinner(container, SWT.BORDER);
		estimated.setSelection(task.getEstimateTime());		
		estimated.setDigits(1);
		estimated.setMaximum(100);
		estimated.setMinimum(0);
		estimated.setIncrement(5);
		estimated.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				TaskSummaryEditor.this.markDirty(true);
			}			
		});  
		label = toolkit.createLabel(container, "hours ");		
		label.setForeground(toolkit.getColors().getColor(FormColors.TITLE));
        
		label = toolkit.createLabel(container, "Elapsed time:");		
		label.setForeground(toolkit.getColors().getColor(FormColors.TITLE));
		Text text2 = toolkit.createText(container,task.getElapsedTimeForDisplay(), SWT.BORDER);
		td = new TableWrapData(TableWrapData.FILL_GRAB);
        td.grabHorizontal = true;
        td.colspan = 2;
        text2.setLayoutData(td);
        text2.setEditable(false);
        text2.setEnabled(false);
        
        label = toolkit.createLabel(container, "Creation date:");		
		label.setForeground(toolkit.getColors().getColor(FormColors.TITLE));
		Text creationDate = toolkit.createText(container,task.getCreationDateString(), SWT.BORDER);
		td = new TableWrapData(TableWrapData.FILL_GRAB);
        td.grabHorizontal = true;
        td.colspan = 2;
        creationDate.setLayoutData(td);
        creationDate.setEditable(false);
        creationDate.setEnabled(false);
        
        label = toolkit.createLabel(container, "Completion date:");		
		label.setForeground(toolkit.getColors().getColor(FormColors.TITLE));
		Text endDate = toolkit.createText(container,task.getEndDateString(), SWT.BORDER);
		td = new TableWrapData(TableWrapData.FILL_GRAB);
        td.grabHorizontal = true;
        td.colspan = 2;
        endDate.setLayoutData(td);
        endDate.setEditable(false);
        endDate.setEnabled(false);
	}
	
	private void createDetailsSection(Composite parent, FormToolkit toolkit) {
		Section section = toolkit.createSection(parent, ExpandableComposite.TITLE_BAR | Section.TWISTIE);
		section.setText("Resources");
		section.setLayout(new TableWrapLayout());
		section.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
		section.addExpansionListener(new IExpansionListener() {
			public void expansionStateChanging(ExpansionEvent e) {
				form.reflow(true);
			}
			public void expansionStateChanged(ExpansionEvent e) {
				form.reflow(true);
			}			
		});
		
		Composite container = toolkit.createComposite(section);
		section.setClient(container);
		TableWrapLayout layout = new TableWrapLayout();
		layout.numColumns = 3;						
		container.setLayout(layout);
		
		Label l = toolkit.createLabel(container, "Task Handle:");
        l.setForeground(toolkit.getColors().getColor(FormColors.TITLE));
        Text handle = toolkit.createText(container, task.getHandleIdentifier(), SWT.BORDER);
        TableWrapData td = new TableWrapData(TableWrapData.FILL_GRAB);
        td.colspan = 2;
        handle.setLayoutData(td);
        handle.setEditable(false);
        handle.setEnabled(false);
              		
		
        Label l2 = toolkit.createLabel(container, "Task context file:");
        l2.setForeground(toolkit.getColors().getColor(FormColors.TITLE));
        pathText = toolkit.createText(container, "<Mylar_Dir>/"+task.getPath()+".xml", SWT.BORDER);
        pathText.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
        pathText.setEditable(false);        
        pathText.setEnabled(false);
        
        browse = toolkit.createButton(container, "Change", SWT.PUSH | SWT.CENTER);
        if (task.isActive()) {
        	browse.setEnabled(false);
        } else {
        	browse.setEnabled(true);
        }		
		browse.addSelectionListener(new SelectionAdapter() {			
			@Override
			public void widgetSelected(SelectionEvent e) {
				
				if (task.isActive()) {
					MessageDialog.openInformation(
							Display.getDefault().getActiveShell(),
				            "Task Message",
				            "Task can not be active when changing taskscape");
				} else {
					FileDialog dialog = new FileDialog(Display.getDefault()
							.getActiveShell(), SWT.OPEN);
					String[] ext = { "*.xml" };
					dialog.setFilterExtensions(ext);

					String mylarDir = MylarPlugin.getDefault().getMylarDataDirectory()
							+ "/";
					mylarDir = mylarDir.replaceAll("\\\\", "/");
					dialog.setFilterPath(mylarDir);

					String res = dialog.open();
					if (res != null) {
						res = res.replaceAll("\\\\", "/");
						pathText.setText("<MylarDir>/" + res + ".xml");
						markDirty(true);
					}
				}
			}
		});
		toolkit.createLabel(container, "");
		l = toolkit.createLabel(container, "Go to Mylar Preferences to change <Mylar_Dir>");
        l.setForeground(toolkit.getColors().getColor(FormColors.TITLE));
	}
	
	private void refreshTaskListView(ITask task) {
		if (TaskListView.getDefault() != null) TaskListView.getDefault().notifyTaskDataChanged(task);
	}
	
	private void markDirty(boolean dirty) {
		isDirty = dirty;
		if (parentEditor != null) {
			parentEditor.updatePartName();
		}
		return;
	}

	public void setParentEditor(MylarTaskEditor parentEditor) {
		this.parentEditor = parentEditor;
	}
}

Back to the top