Skip to main content
summaryrefslogtreecommitdiffstats
blob: 40d3c79b045bff7f7e610be501be9f0feafccac8 (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
/*******************************************************************************
 * Copyright (c) 2009, 2013 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 java.text.MessageFormat;

import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.ITaskMapping;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
import org.eclipse.mylyn.tasks.ui.TasksUi;
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.FormToolkit;

/**
 * @author Steffen Pingel
 */
public class PriorityAttributeEditor extends AbstractAttributeEditor {

	private PriorityEditor editor;

	private ITaskMapping mapping;

	public PriorityAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
		super(manager, taskAttribute);
		boolean noOptions = getAttributeMapper().getOptions(getTaskAttribute()).size() == 0;
		setReadOnly(isReadOnly() || noOptions);
	}

	@Override
	public void createControl(final Composite parent, FormToolkit toolkit) {
		AbstractRepositoryConnector connector = TasksUi.getRepositoryConnector(getModel().getTaskRepository()
				.getConnectorKind());
		mapping = connector.getTaskMapping(getModel().getTaskData());
		editor = new PriorityEditor() {
			@Override
			protected void valueChanged(String value) {
				setValue(value);
			};
		};
		editor.setReadOnly(isReadOnly());
		editor.createControl(parent, toolkit);
		setControl(editor.getControl());
		refresh();
	}

	public String getValue() {
		return getAttributeMapper().getValue(getTaskAttribute());
	}

	public String getValueLabel() {
		return getAttributeMapper().getValueLabel(getTaskAttribute());
	}

	@Override
	public void refresh() {
		if (editor.getControl() != null && !editor.getControl().isDisposed()) {
			editor.setLabelByValue(getAttributeMapper().getOptions(getTaskAttribute()));
			updateEditor();
		}
	}

	@Override
	public boolean shouldAutoRefresh() {
		return true;
	}

	public void setValue(String value) {
		String oldValue = getAttributeMapper().getValue(getTaskAttribute());
		if (!oldValue.equals(value)) {
			getAttributeMapper().setValue(getTaskAttribute(), value);
			attributeChanged();
		}
	}

	private void updateEditor() {
		editor.select(getValue(), mapping.getPriorityLevel());
		editor.setToolTipText(MessageFormat.format(Messages.PriorityAttributeEditor_Priority_Tooltip, getValueLabel()));
	}

}

Back to the top