Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 166595 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttribute.java (-1 / +1 lines)
Lines 100-106 Link Here
100
100
101
	PRIORITY("Priority:", "priority", TaskAttribute.TYPE_SINGLE_SELECT, false, false),
101
	PRIORITY("Priority:", "priority", TaskAttribute.TYPE_SINGLE_SELECT, false, false),
102
102
103
	PRODUCT("Product:", "product", TaskAttribute.TYPE_SHORT_TEXT, false, true),
103
	PRODUCT("Product:", "product", IBugzillaConstants.EDITOR_TYPE_PRODUCT, false, false),
104
104
105
	REP_PLATFORM("Platform:", "rep_platform", TaskAttribute.TYPE_SINGLE_SELECT, false, false),
105
	REP_PLATFORM("Platform:", "rep_platform", TaskAttribute.TYPE_SINGLE_SELECT, false, false),
106
106
(-)src/org/eclipse/mylyn/internal/bugzilla/core/IBugzillaConstants.java (+2 lines)
Lines 276-281 Link Here
276
276
277
	public static final String EDITOR_TYPE_VOTES = "bugzilla.editor.votes";
277
	public static final String EDITOR_TYPE_VOTES = "bugzilla.editor.votes";
278
278
279
	public static final String EDITOR_TYPE_PRODUCT = "bugzilla.editor.product";
280
279
	public static final String ATTRIBUTE_BUGZILLA_QUERY_CUSTOM = "bugzilla.query.custom";
281
	public static final String ATTRIBUTE_BUGZILLA_QUERY_CUSTOM = "bugzilla.query.custom";
280
282
281
	// Old Tags used for migration
283
	// Old Tags used for migration
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorPage.java (+2 lines)
Lines 96-101 Link Here
96
					editor = new BugzillaCcAttributeEditor(getModel(), taskAttribute);
96
					editor = new BugzillaCcAttributeEditor(getModel(), taskAttribute);
97
				} else if (IBugzillaConstants.EDITOR_TYPE_VOTES.equals(type)) {
97
				} else if (IBugzillaConstants.EDITOR_TYPE_VOTES.equals(type)) {
98
					editor = new BugzillaVotesEditor(getModel(), taskAttribute);
98
					editor = new BugzillaVotesEditor(getModel(), taskAttribute);
99
				} else if (IBugzillaConstants.EDITOR_TYPE_PRODUCT.equals(type)) {
100
					editor = new BugzillaProductEditor(getModel(), taskAttribute);
99
				} else {
101
				} else {
100
					editor = super.createEditor(type, taskAttribute);
102
					editor = super.createEditor(type, taskAttribute);
101
					if (TaskAttribute.TYPE_BOOLEAN.equals(type)) {
103
					if (TaskAttribute.TYPE_BOOLEAN.equals(type)) {
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaProductEditor.java (+164 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2008 Tasktop Technologies 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
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.bugzilla.ui.editor;
13
14
import java.util.Collections;
15
import java.util.List;
16
import java.util.Map;
17
18
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.NullProgressMonitor;
21
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute;
22
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin;
23
import org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration;
24
import org.eclipse.mylyn.internal.tasks.ui.editors.EditorUtil;
25
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
26
import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
27
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
28
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.custom.CCombo;
30
import org.eclipse.swt.events.SelectionAdapter;
31
import org.eclipse.swt.events.SelectionEvent;
32
import org.eclipse.swt.widgets.Composite;
33
import org.eclipse.swt.widgets.Text;
34
import org.eclipse.ui.forms.widgets.FormToolkit;
35
36
public class BugzillaProductEditor extends AbstractAttributeEditor {
37
38
	private String[] values;
39
40
	private CCombo combo;
41
42
	public BugzillaProductEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
43
		super(manager, taskAttribute);
44
		// ignore
45
	}
46
47
	@Override
48
	public void createControl(Composite parent, FormToolkit toolkit) {
49
		if (isReadOnly()) {
50
			Text text = new Text(parent, SWT.FLAT | SWT.READ_ONLY);
51
			text.setFont(EditorUtil.TEXT_FONT);
52
			toolkit.adapt(text, false, false);
53
			text.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.FALSE);
54
			String label = getValueLabel();
55
			if ("".equals(label)) {
56
				// if set to the empty string the label will use 64px on GTK 
57
				text.setText(" ");
58
			} else {
59
				text.setText(label);
60
			}
61
			setControl(text);
62
		} else {
63
			combo = new CCombo(parent, SWT.FLAT | SWT.READ_ONLY);
64
			toolkit.adapt(combo, false, false);
65
			combo.setFont(EditorUtil.TEXT_FONT);
66
			combo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
67
68
			Map<String, String> labelByValue = getAttributeMapper().getOptions(getTaskAttribute());
69
			if (labelByValue != null) {
70
				values = labelByValue.keySet().toArray(new String[0]);
71
				for (String value : values) {
72
					combo.add(labelByValue.get(value));
73
				}
74
			}
75
76
			select(getValue(), getValueLabel());
77
78
			if (values != null) {
79
				combo.addSelectionListener(new SelectionAdapter() {
80
					@Override
81
					public void widgetSelected(SelectionEvent event) {
82
						int index = combo.getSelectionIndex();
83
						if (index > -1) {
84
							Assert.isNotNull(values);
85
							Assert.isLegal(index >= 0 && index <= values.length - 1);
86
							setValue(values[index]);
87
							RepositoryConfiguration repositoryConfiguration = null;
88
							try {
89
								repositoryConfiguration = BugzillaCorePlugin.getRepositoryConfiguration(
90
										getModel().getTaskRepository(), false, new NullProgressMonitor());
91
								TaskAttribute attributeComponent = getModel().getTaskData()
92
										.getRoot()
93
										.getMappedAttribute(BugzillaAttribute.COMPONENT.getKey());
94
								TaskAttribute targetComponent = getModel().getTaskData().getRoot().getMappedAttribute(
95
										BugzillaAttribute.TARGET_MILESTONE.getKey());
96
97
								if (attributeComponent != null) {
98
									attributeComponent.setValue("");
99
									List<String> optionValues = repositoryConfiguration.getComponents(values[index]);
100
									Collections.sort(optionValues);
101
									attributeComponent.clearOptions();
102
									for (String option : optionValues) {
103
										attributeComponent.putOption(option, option);
104
									}
105
									if (optionValues.size() == 1) {
106
										attributeComponent.setValue(optionValues.get(0));
107
									}
108
								}
109
								if (targetComponent != null) {
110
									List<String> optionValues = repositoryConfiguration.getTargetMilestones(values[index]);
111
									Collections.sort(optionValues);
112
									targetComponent.clearOptions();
113
									for (String option : optionValues) {
114
										targetComponent.putOption(option, option);
115
									}
116
									if (optionValues.size() == 1) {
117
										targetComponent.setValue(optionValues.get(0));
118
									}
119
								}
120
							} catch (CoreException e1) {
121
								// ignore
122
							}
123
						}
124
					}
125
				});
126
			}
127
			setControl(combo);
128
		}
129
	}
130
131
	public String getValue() {
132
		return getAttributeMapper().getValue(getTaskAttribute());
133
	}
134
135
	public String getValueLabel() {
136
		return getAttributeMapper().getValueLabel(getTaskAttribute());
137
	}
138
139
	private void select(String value, String label) {
140
		if (values != null) {
141
			for (int i = 0; i < values.length; i++) {
142
				if (values[i].equals(value)) {
143
					combo.select(i);
144
					break;
145
				}
146
			}
147
		} else {
148
			combo.setText(label);
149
		}
150
	}
151
152
	public void setValue(String value) {
153
		getAttributeMapper().setValue(getTaskAttribute(), value);
154
		attributeChanged();
155
	}
156
157
	void selectDefaultValue() {
158
		if (combo.getSelectionIndex() == -1 && values.length > 0) {
159
			combo.select(0);
160
			setValue(values[0]);
161
		}
162
	}
163
164
}

Return to bug 166595