Skip to main content
summaryrefslogtreecommitdiffstats
blob: 50ae8226964ee2dc4ee6acbe776d1181c358bcc1 (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
/*******************************************************************************
 * Copyright (c) 2004, 2009 Tasktop Technologies 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:
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.tasks.ui.editors;

import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.ITextListener;
import org.eclipse.jface.text.TextEvent;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonTextSupport;
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.internal.EditorAreaHelper;
import org.eclipse.ui.internal.WorkbenchPage;

/**
 * @author Shawn Minto
 * @author Steffen Pingel
 */
@Deprecated
public class TaskEditorNotesPart extends AbstractTaskEditorPart {

	private String value;

	private AbstractTask task;

	private SourceViewer noteEditor;

	public TaskEditorNotesPart() {
		setPartName(Messages.TaskPlanningEditor_Notes);
	}

	@Override
	public void initialize(AbstractTaskEditorPage taskEditorPage) {
		super.initialize(taskEditorPage);
		task = (AbstractTask) taskEditorPage.getTask();
	}

	private boolean notesEqual() {
		if (task.getNotes() == null && value == null) {
			return true;
		}

		if (task.getNotes() != null && value != null) {
			return task.getNotes().equals(value);
		}
		return false;
	}

	@Override
	public void commit(boolean onSave) {
		Assert.isNotNull(task);

		if (!notesEqual()) {
			task.setNotes(value);
			// XXX REFRESH THE TASLKIST
		}

		super.commit(onSave);
	}

	@Override
	public void createControl(Composite parent, FormToolkit toolkit) {
		this.value = task.getNotes();
		if (this.value == null) {
			this.value = ""; //$NON-NLS-1$
		}

		Section section = createSection(parent, toolkit, this.value != null && this.value.length() > 0);

		Composite composite = toolkit.createComposite(section);
		composite.setLayout(EditorUtil.createSectionClientLayout());

		noteEditor = new SourceViewer(composite, null, SWT.FLAT | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
		noteEditor.configure(new RepositoryTextViewerConfiguration(getModel().getTaskRepository(),
				getModel().getTask(), true));
		CommonTextSupport textSupport = (CommonTextSupport) getTaskEditorPage().getAdapter(CommonTextSupport.class);
		if (textSupport != null) {
			textSupport.configure(noteEditor, new Document(this.value), true);
		}
		noteEditor.addTextListener(new ITextListener() {
			public void textChanged(TextEvent event) {
				TaskEditorNotesPart.this.value = noteEditor.getTextWidget().getText();
				markDirty();
			}
		});

		final GridData gd = new GridData(GridData.FILL_BOTH);
		int widthHint = 0;

		if (getManagedForm() != null && getManagedForm().getForm() != null) {
			widthHint = getManagedForm().getForm().getClientArea().width - 90;
		}
		if (widthHint <= 0 && getTaskEditorPage().getEditor().getEditorSite() != null
				&& getTaskEditorPage().getEditor().getEditorSite().getPage() != null) {
			EditorAreaHelper editorManager = ((WorkbenchPage) getTaskEditorPage().getEditor().getEditorSite().getPage()).getEditorPresentation();
			if (editorManager != null && editorManager.getLayoutPart() != null) {
				widthHint = editorManager.getLayoutPart().getControl().getBounds().width - 90;
			}
		}

		if (widthHint <= 0) {
			widthHint = 100;
		}

		gd.widthHint = widthHint;
		gd.minimumHeight = 100;
		gd.grabExcessHorizontalSpace = true;

		noteEditor.getControl().setLayoutData(gd);
		noteEditor.getControl().setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
		noteEditor.setEditable(true);

		toolkit.paintBordersFor(composite);
		section.setClient(composite);
		setSection(toolkit, section);
	}

}

Back to the top