Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5515686f1bd28c2e8cd96ab11ecfd0049813a226 (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
/*******************************************************************************
 * Copyright (c) 2004, 2008 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.bugzilla.ui.editor;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.window.Window;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint;
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.ColumnSpan;
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.RowSpan;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.widgets.FormToolkit;

/**
 * @author Rob Elves
 */
public class BugzillaKeywordAttributeEditor extends AbstractAttributeEditor {

	private Text keywordsText;

	public BugzillaKeywordAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
		super(manager, taskAttribute);
		setLayoutHint(new LayoutHint(RowSpan.SINGLE, ColumnSpan.MULTIPLE));
	}

	@Override
	public void createControl(Composite parent, FormToolkit toolkit) {
		Composite keywordComposite = toolkit.createComposite(parent);
		GridLayout layout = new GridLayout(2, false);
		layout.marginWidth = 1;
		keywordComposite.setLayout(layout);

		keywordsText = toolkit.createText(keywordComposite, getTaskAttribute().getValue());
		GridData keywordsData = new GridData(GridData.FILL_HORIZONTAL);
		keywordsText.setLayoutData(keywordsData);
		keywordsText.setEditable(false);

		Button changeKeywordsButton = toolkit.createButton(keywordComposite, "Edit...", SWT.FLAT);
		GridData keyWordsButtonData = new GridData();
		changeKeywordsButton.setLayoutData(keyWordsButtonData);
		changeKeywordsButton.addSelectionListener(new SelectionListener() {

			public void widgetDefaultSelected(SelectionEvent e) {
			}

			public void widgetSelected(SelectionEvent e) {

				String keywords = getTaskAttribute().getValue();

				Shell shell = null;
				if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
					shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
				} else {
					shell = new Shell(PlatformUI.getWorkbench().getDisplay());
				}

				List<String> validKeywords = new ArrayList<String>();
				try {
					validKeywords = BugzillaCorePlugin.getRepositoryConfiguration(getModel().getTaskRepository(),
							false, new NullProgressMonitor()).getKeywords();
				} catch (Exception ex) {
					// ignore
				}

				KeywordsDialog keywordsDialog = new KeywordsDialog(shell, keywords, validKeywords);
				int responseCode = keywordsDialog.open();

				String newKeywords = keywordsDialog.getSelectedKeywordsString();
				if (responseCode == Window.OK && keywords != null) {
					keywordsText.setText(newKeywords);
					getAttributeMapper().setValue(getTaskAttribute(), newKeywords);
					attributeChanged();
				} else {
					return;
				}

			}

		});
		setControl(keywordComposite);
	}

	@Override
	protected void decorateIncoming(Color color) {
		if (keywordsText != null && !keywordsText.isDisposed()) {
			keywordsText.setBackground(color);
		}
	}

}

Back to the top