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 279334 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/provisional/commons/ui/CheckBoxTreeDialog.java (+170 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 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
package org.eclipse.mylyn.internal.provisional.commons.ui;
12
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.Set;
17
18
import org.eclipse.jface.dialogs.Dialog;
19
import org.eclipse.jface.viewers.CheckStateChangedEvent;
20
import org.eclipse.jface.viewers.CheckboxTreeViewer;
21
import org.eclipse.jface.viewers.ICheckStateListener;
22
import org.eclipse.jface.viewers.ITreeContentProvider;
23
import org.eclipse.jface.viewers.LabelProvider;
24
import org.eclipse.jface.viewers.TreeViewer;
25
import org.eclipse.jface.viewers.Viewer;
26
import org.eclipse.jface.viewers.ViewerSorter;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.layout.GridData;
29
import org.eclipse.swt.layout.GridLayout;
30
import org.eclipse.swt.widgets.Composite;
31
import org.eclipse.swt.widgets.Control;
32
import org.eclipse.swt.widgets.Shell;
33
import org.eclipse.ui.dialogs.PatternFilter;
34
35
/**
36
 * @author Shawn Minto
37
 */
38
public class CheckBoxTreeDialog extends Dialog {
39
40
	private final Map<String, String> validValues;
41
42
	private CheckboxFilteredTree valueTree;
43
44
	private final List<String> selectedValues;
45
46
	private final String dialogLabel;
47
48
	private class CheckboxFilteredTree extends EnhancedFilteredTree {
49
50
		public CheckboxFilteredTree(Composite parent, int treeStyle, PatternFilter filter) {
51
			super(parent, treeStyle, filter);
52
		}
53
54
		@Override
55
		protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
56
			return new CheckboxTreeViewer(parent, style);
57
		}
58
59
		@Override
60
		public CheckboxTreeViewer getViewer() {
61
			return (CheckboxTreeViewer) super.getViewer();
62
		}
63
64
	}
65
66
	public CheckBoxTreeDialog(Shell shell, List<String> values, Map<String, String> validValues,
67
			String dialogLabel) {
68
		super(shell);
69
		setShellStyle(getShellStyle() | SWT.RESIZE);
70
		this.selectedValues = values;
71
		this.validValues = validValues;
72
		this.dialogLabel = dialogLabel;
73
	}
74
75
	@Override
76
	protected Control createDialogArea(Composite parent) {
77
		getShell().setText(dialogLabel);
78
79
		Composite composite = new Composite(parent, SWT.NONE);
80
		composite.setLayout(new GridLayout());
81
		GridData gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
82
		composite.setLayoutData(gd);
83
84
		valueTree = new CheckboxFilteredTree(composite, SWT.CHECK | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL
85
				| SWT.BORDER, new SubstringPatternFilter());
86
		gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
87
		gd.heightHint = 175;
88
		gd.widthHint = 160;
89
		CheckboxTreeViewer viewer = valueTree.getViewer();
90
		viewer.getControl().setLayoutData(gd);
91
92
		if (validValues != null) {
93
94
			viewer.setContentProvider(new ITreeContentProvider() {
95
96
				public Object[] getChildren(Object parentElement) {
97
					if (parentElement instanceof Map<?, ?>) {
98
						return ((Map<?, ?>) parentElement).keySet().toArray();
99
					}
100
					return null;
101
				}
102
103
				public Object getParent(Object element) {
104
					return null;
105
				}
106
107
				public boolean hasChildren(Object element) {
108
					return false;
109
				}
110
111
				public Object[] getElements(Object inputElement) {
112
					return getChildren(inputElement);
113
				}
114
115
				public void dispose() {
116
				}
117
118
				public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
119
				}
120
121
			});
122
123
			viewer.setSorter(new ViewerSorter());
124
			viewer.setLabelProvider(new LabelProvider() {
125
				@Override
126
				public String getText(Object element) {
127
					if (element instanceof String) {
128
						return validValues.get(element);
129
					}
130
					return super.getText(element);
131
				}
132
			});
133
			viewer.setInput(validValues);
134
135
			Set<String> invalidValues = new HashSet<String>();
136
			for (String value : validValues.keySet()) {
137
				if (!viewer.setChecked(value, true)) {
138
					invalidValues.add(value);
139
				}
140
			}
141
142
			selectedValues.removeAll(invalidValues);
143
144
			viewer.setCheckedElements(selectedValues.toArray());
145
146
		}
147
148
		viewer.addCheckStateListener(new ICheckStateListener() {
149
150
			public void checkStateChanged(CheckStateChangedEvent event) {
151
				if (event.getChecked()) {
152
					selectedValues.add((String) event.getElement());
153
				} else {
154
					selectedValues.remove(event.getElement());
155
				}
156
			}
157
158
		});
159
160
		parent.pack();
161
162
		applyDialogFont(composite);
163
164
		return composite;
165
	}
166
167
	public List<String> getSelectedValues() {
168
		return selectedValues;
169
	}
170
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/messages.properties (+2 lines)
Lines 30-35 Link Here
30
CategoryEditor_URL_=URL: 
30
CategoryEditor_URL_=URL: 
31
31
32
CategoryEditorInput_Category_Editor=Category Editor
32
CategoryEditorInput_Category_Editor=Category Editor
33
CheckboxMultiSelectAttributeEditor_Edit=Edit
34
CheckboxMultiSelectAttributeEditor_Select_X=Select {0}
33
35
34
CommentGroupStrategy_Current=Current
36
CommentGroupStrategy_Current=Current
35
CommentGroupStrategy_Older=Older
37
CommentGroupStrategy_Older=Older
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/Messages.java (+4 lines)
Lines 61-66 Link Here
61
61
62
	public static String CategoryEditorInput_Category_Editor;
62
	public static String CategoryEditorInput_Category_Editor;
63
63
64
	public static String CheckboxMultiSelectAttributeEditor_Edit;
65
66
	public static String CheckboxMultiSelectAttributeEditor_Select_X;
67
64
	public static String CommentGroupStrategy_Current;
68
	public static String CommentGroupStrategy_Current;
65
69
66
	public static String CommentGroupStrategy_Older;
70
	public static String CommentGroupStrategy_Older;
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/CheckboxMultiSelectAttributeEditor.java (+137 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 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
package org.eclipse.mylyn.internal.tasks.ui.editors;
12
13
import java.util.Collections;
14
import java.util.List;
15
import java.util.Map;
16
17
import org.eclipse.jface.window.Window;
18
import org.eclipse.mylyn.internal.provisional.commons.ui.CheckBoxTreeDialog;
19
import org.eclipse.mylyn.internal.provisional.commons.ui.WorkbenchUtil;
20
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
21
import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
22
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
23
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint;
24
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.ColumnSpan;
25
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.RowSpan;
26
import org.eclipse.osgi.util.NLS;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.events.SelectionEvent;
29
import org.eclipse.swt.events.SelectionListener;
30
import org.eclipse.swt.graphics.Color;
31
import org.eclipse.swt.layout.GridData;
32
import org.eclipse.swt.layout.GridLayout;
33
import org.eclipse.swt.widgets.Button;
34
import org.eclipse.swt.widgets.Composite;
35
import org.eclipse.swt.widgets.Shell;
36
import org.eclipse.swt.widgets.Text;
37
import org.eclipse.ui.forms.widgets.FormToolkit;
38
39
/**
40
 * @author Shawn Minto
41
 */
42
public class CheckboxMultiSelectAttributeEditor extends AbstractAttributeEditor {
43
44
	private Text valueText;
45
46
	public CheckboxMultiSelectAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
47
		super(manager, taskAttribute);
48
		setLayoutHint(new LayoutHint(RowSpan.SINGLE, ColumnSpan.MULTIPLE));
49
	}
50
51
	@Override
52
	public void createControl(Composite parent, FormToolkit toolkit) {
53
		Composite composite = toolkit.createComposite(parent);
54
		GridLayout layout = new GridLayout(2, false);
55
		layout.marginWidth = 1;
56
		composite.setLayout(layout);
57
58
		valueText = toolkit.createText(composite, "", SWT.FLAT); //$NON-NLS-1$
59
		valueText.setFont(EditorUtil.TEXT_FONT);
60
61
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
62
		valueText.setLayoutData(gd);
63
		valueText.setEditable(false);
64
		Button changeValueButton = toolkit.createButton(composite, Messages.CheckboxMultiSelectAttributeEditor_Edit,
65
				SWT.FLAT);
66
		gd = new GridData();
67
		changeValueButton.setLayoutData(gd);
68
		changeValueButton.addSelectionListener(new SelectionListener() {
69
70
			public void widgetDefaultSelected(SelectionEvent e) {
71
			}
72
73
			public void widgetSelected(SelectionEvent e) {
74
75
				List<String> values = getValues();
76
77
				Map<String, String> validValues = getAttributeMapper().getOptions(getTaskAttribute());
78
79
				Shell shell = WorkbenchUtil.getShell();
80
81
				CheckBoxTreeDialog selectionDialog = new CheckBoxTreeDialog(shell, values, validValues, NLS.bind(
82
						Messages.CheckboxMultiSelectAttributeEditor_Select_X, getLabel()));
83
				int responseCode = selectionDialog.open();
84
85
				List<String> newValues = selectionDialog.getSelectedValues();
86
				if (responseCode == Window.OK && values != null) {
87
					setValues(newValues);
88
					attributeChanged();
89
					updateText();
90
				} else {
91
					return;
92
				}
93
94
			}
95
96
		});
97
		toolkit.adapt(valueText, false, false);
98
		updateText();
99
		setControl(composite);
100
	}
101
102
	private void updateText() {
103
		if (valueText != null && !valueText.isDisposed()) {
104
			StringBuilder valueString = new StringBuilder();
105
			List<String> values = getValuesLabels();
106
			Collections.sort(values);
107
			for (int i = 0; i < values.size(); i++) {
108
				valueString.append(values.get(i));
109
				if (i != values.size() - 1) {
110
					valueString.append(", "); //$NON-NLS-1$
111
				}
112
			}
113
			valueText.setText(valueString.toString());
114
		}
115
	}
116
117
	public List<String> getValues() {
118
		return getAttributeMapper().getValues(getTaskAttribute());
119
	}
120
121
	public List<String> getValuesLabels() {
122
		return getAttributeMapper().getValueLabels(getTaskAttribute());
123
	}
124
125
	public void setValues(List<String> newValues) {
126
		getAttributeMapper().setValues(getTaskAttribute(), newValues);
127
		attributeChanged();
128
	}
129
130
	@Override
131
	protected void decorateIncoming(Color color) {
132
		if (valueText != null && !valueText.isDisposed()) {
133
			valueText.setBackground(color);
134
		}
135
	}
136
137
}
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaKeywordAttributeEditor.java (-79 / +24 lines)
Lines 12-115 Link Here
12
package org.eclipse.mylyn.internal.bugzilla.ui.editor;
12
package org.eclipse.mylyn.internal.bugzilla.ui.editor;
13
13
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Collections;
15
import java.util.List;
16
import java.util.List;
17
import java.util.StringTokenizer;
16
18
17
import org.eclipse.core.runtime.NullProgressMonitor;
19
import org.eclipse.mylyn.internal.tasks.ui.editors.CheckboxMultiSelectAttributeEditor;
18
import org.eclipse.jface.window.Window;
19
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin;
20
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
20
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
21
import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
21
import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
22
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
23
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint;
24
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.ColumnSpan;
25
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.RowSpan;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.events.SelectionEvent;
28
import org.eclipse.swt.events.SelectionListener;
29
import org.eclipse.swt.graphics.Color;
30
import org.eclipse.swt.layout.GridData;
31
import org.eclipse.swt.layout.GridLayout;
32
import org.eclipse.swt.widgets.Button;
33
import org.eclipse.swt.widgets.Composite;
34
import org.eclipse.swt.widgets.Shell;
35
import org.eclipse.swt.widgets.Text;
36
import org.eclipse.ui.PlatformUI;
37
import org.eclipse.ui.forms.widgets.FormToolkit;
38
22
39
/**
23
/**
40
 * @author Rob Elves
24
 * @author Rob Elves
41
 */
25
 */
42
public class BugzillaKeywordAttributeEditor extends AbstractAttributeEditor {
26
public class BugzillaKeywordAttributeEditor extends CheckboxMultiSelectAttributeEditor {
43
44
	private Text keywordsText;
45
27
46
	public BugzillaKeywordAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
28
	public BugzillaKeywordAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) {
47
		super(manager, taskAttribute);
29
		super(manager, taskAttribute);
48
		setLayoutHint(new LayoutHint(RowSpan.SINGLE, ColumnSpan.MULTIPLE));
30
49
	}
31
	}
50
32
51
	@Override
33
	@Override
52
	public void createControl(Composite parent, FormToolkit toolkit) {
34
	public List<String> getValues() {
53
		Composite keywordComposite = toolkit.createComposite(parent);
35
		List<String> values = new ArrayList<String>();
54
		GridLayout layout = new GridLayout(2, false);
36
		String selectedKeywords = getAttributeMapper().getValue(getTaskAttribute());
55
		layout.marginWidth = 1;
37
		StringTokenizer st = new StringTokenizer(selectedKeywords, ",", false); //$NON-NLS-1$
56
		keywordComposite.setLayout(layout);
38
		while (st.hasMoreTokens()) {
57
39
			String s = st.nextToken().trim();
58
		keywordsText = toolkit.createText(keywordComposite, getTaskAttribute().getValue());
40
			values.add(s);
59
		GridData keywordsData = new GridData(GridData.FILL_HORIZONTAL);
41
		}
60
		keywordsText.setLayoutData(keywordsData);
61
		keywordsText.setEditable(false);
62
63
		Button changeKeywordsButton = toolkit.createButton(keywordComposite, Messages.BugzillaKeywordAttributeEditor_Edit_, SWT.FLAT);
64
		GridData keyWordsButtonData = new GridData();
65
		changeKeywordsButton.setLayoutData(keyWordsButtonData);
66
		changeKeywordsButton.addSelectionListener(new SelectionListener() {
67
68
			public void widgetDefaultSelected(SelectionEvent e) {
69
			}
70
71
			public void widgetSelected(SelectionEvent e) {
72
73
				String keywords = getTaskAttribute().getValue();
74
75
				Shell shell = null;
76
				if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
77
					shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
78
				} else {
79
					shell = new Shell(PlatformUI.getWorkbench().getDisplay());
80
				}
81
82
				List<String> validKeywords = new ArrayList<String>();
83
				try {
84
					validKeywords = BugzillaCorePlugin.getRepositoryConfiguration(getModel().getTaskRepository(),
85
							false, new NullProgressMonitor()).getKeywords();
86
				} catch (Exception ex) {
87
					// ignore
88
				}
89
90
				KeywordsDialog keywordsDialog = new KeywordsDialog(shell, keywords, validKeywords);
91
				int responseCode = keywordsDialog.open();
92
93
				String newKeywords = keywordsDialog.getSelectedKeywordsString();
94
				if (responseCode == Window.OK && keywords != null) {
95
					keywordsText.setText(newKeywords);
96
					getAttributeMapper().setValue(getTaskAttribute(), newKeywords);
97
					attributeChanged();
98
				} else {
99
					return;
100
				}
101
102
			}
103
42
104
		});
43
		return values;
105
		setControl(keywordComposite);
106
	}
44
	}
107
45
108
	@Override
46
	@Override
109
	protected void decorateIncoming(Color color) {
47
	public void setValues(List<String> newValues) {
110
		if (keywordsText != null && !keywordsText.isDisposed()) {
48
		StringBuilder valueString = new StringBuilder();
111
			keywordsText.setBackground(color);
49
		Collections.sort(newValues);
50
		for (int i = 0; i < newValues.size(); i++) {
51
			valueString.append(newValues.get(i));
52
			if (i != newValues.size() - 1) {
53
				valueString.append(", "); //$NON-NLS-1$
54
			}
112
		}
55
		}
56
		getAttributeMapper().setValue(getTaskAttribute(), valueString.toString());
57
		attributeChanged();
113
	}
58
	}
114
59
115
}
60
}

Return to bug 279334