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 287899
Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/bugzilla/ui/editor/KeywordsDialog.java (-160 lines)
Removed 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
12
package org.eclipse.mylyn.internal.bugzilla.ui.editor;
13
14
import java.util.ArrayList;
15
import java.util.Collection;
16
import java.util.HashSet;
17
import java.util.List;
18
import java.util.Set;
19
import java.util.StringTokenizer;
20
21
import org.eclipse.jface.dialogs.Dialog;
22
import org.eclipse.jface.viewers.CheckStateChangedEvent;
23
import org.eclipse.jface.viewers.CheckboxTableViewer;
24
import org.eclipse.jface.viewers.ICheckStateListener;
25
import org.eclipse.jface.viewers.ITreeContentProvider;
26
import org.eclipse.jface.viewers.Viewer;
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
34
/**
35
 * @author Shawn Minto
36
 */
37
public class KeywordsDialog extends Dialog {
38
39
	private final List<String> selectedKeywords;
40
41
	private final List<String> validKeywords;
42
43
	private CheckboxTableViewer keyWordsList;
44
45
	public KeywordsDialog(Shell shell, String selectedKeywords, java.util.List<String> validKeywords) {
46
		super(shell);
47
		setShellStyle(getShellStyle() | SWT.RESIZE);
48
		StringTokenizer st = new StringTokenizer(selectedKeywords, ",", false); //$NON-NLS-1$
49
		this.selectedKeywords = new ArrayList<String>();
50
		while (st.hasMoreTokens()) {
51
			String s = st.nextToken().trim();
52
			this.selectedKeywords.add(s);
53
		}
54
55
		this.validKeywords = validKeywords;
56
	}
57
58
	@Override
59
	protected Control createDialogArea(Composite parent) {
60
		getShell().setText(Messages.KeywordsDialog_Select_Keywords);
61
62
		Composite composite = new Composite(parent, SWT.NONE);
63
		composite.setLayout(new GridLayout());
64
		GridData gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
65
		composite.setLayoutData(gd);
66
67
		keyWordsList = CheckboxTableViewer.newCheckList(composite, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
68
		GridData keyWordsTextData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
69
		keyWordsTextData.heightHint = 175;
70
		keyWordsTextData.widthHint = 160;
71
		keyWordsList.getTable().setLayoutData(keyWordsTextData);
72
73
		if (validKeywords != null) {
74
75
			keyWordsList.setContentProvider(new ITreeContentProvider() {
76
77
				public Object[] getChildren(Object parentElement) {
78
					if (parentElement instanceof Collection<?>) {
79
						return ((Collection<?>) parentElement).toArray();
80
					}
81
					return null;
82
				}
83
84
				public Object getParent(Object element) {
85
					return null;
86
				}
87
88
				public boolean hasChildren(Object element) {
89
					return false;
90
				}
91
92
				public Object[] getElements(Object inputElement) {
93
					return getChildren(inputElement);
94
				}
95
96
				public void dispose() {
97
				}
98
99
				public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
100
				}
101
102
			});
103
104
			Set<String> invalidKeywords = new HashSet<String>();
105
106
			keyWordsList.setInput(validKeywords);
107
108
			for (String keyword : selectedKeywords) {
109
				if (!keyWordsList.setChecked(keyword, true)) {
110
					invalidKeywords.add(keyword);
111
				}
112
			}
113
114
			selectedKeywords.removeAll(invalidKeywords);
115
116
		}
117
118
		keyWordsList.addCheckStateListener(new KeywordListener());
119
120
		parent.pack();
121
122
		applyDialogFont(composite);
123
124
		return composite;
125
	}
126
127
	protected class KeywordListener implements ICheckStateListener {
128
129
		public void checkStateChanged(CheckStateChangedEvent event) {
130
			if (event.getChecked()) {
131
				selectedKeywords.add((String) event.getElement());
132
			} else {
133
				selectedKeywords.remove(event.getElement());
134
			}
135
		}
136
137
	}
138
139
	public List<String> getSelectedKeywords() {
140
		return selectedKeywords;
141
	}
142
143
	public String getSelectedKeywordsString() {
144
		StringBuffer keywords = new StringBuffer();
145
146
		for (String sel : selectedKeywords) {
147
			keywords.append(sel);
148
			keywords.append(","); //$NON-NLS-1$
149
		}
150
151
		String keywordsString = keywords.toString();
152
153
		if (keywordsString.endsWith(",")) { //$NON-NLS-1$
154
			keywordsString = keywordsString.substring(0, keywordsString.length() - 1);
155
		}
156
157
		return keywordsString;
158
	}
159
160
}
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/editor/Messages.java (-2 lines)
Lines 54-59 Link Here
54
	public static String BugzillaVotesEditor_Show_votes;
54
	public static String BugzillaVotesEditor_Show_votes;
55
55
56
	public static String BugzillaVotesEditor_Vote;
56
	public static String BugzillaVotesEditor_Vote;
57
58
	public static String KeywordsDialog_Select_Keywords;
59
}
57
}
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/editor/messages.properties (-2 lines)
Lines 26-30 Link Here
26
26
27
BugzillaVotesEditor_Show_votes=Show votes
27
BugzillaVotesEditor_Show_votes=Show votes
28
BugzillaVotesEditor_Vote=Vote
28
BugzillaVotesEditor_Vote=Vote
29
30
KeywordsDialog_Select_Keywords=Select Keywords
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchPage.java (-9 / +45 lines)
Lines 19-24 Link Here
19
import java.text.MessageFormat;
19
import java.text.MessageFormat;
20
import java.util.ArrayList;
20
import java.util.ArrayList;
21
import java.util.Arrays;
21
import java.util.Arrays;
22
import java.util.HashMap;
23
import java.util.HashSet;
24
import java.util.Map;
25
import java.util.Set;
22
26
23
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.IProgressMonitor;
28
import org.eclipse.core.runtime.IProgressMonitor;
Lines 44-50 Link Here
44
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants;
48
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants;
45
import org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration;
49
import org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration;
46
import org.eclipse.mylyn.internal.bugzilla.ui.BugzillaUiPlugin;
50
import org.eclipse.mylyn.internal.bugzilla.ui.BugzillaUiPlugin;
47
import org.eclipse.mylyn.internal.bugzilla.ui.editor.KeywordsDialog;
51
import org.eclipse.mylyn.internal.provisional.commons.ui.WorkbenchUtil;
52
import org.eclipse.mylyn.internal.provisional.commons.ui.dialogs.AbstractInPlaceDialog;
53
import org.eclipse.mylyn.internal.provisional.commons.ui.dialogs.IInPlaceDialogListener;
54
import org.eclipse.mylyn.internal.provisional.commons.ui.dialogs.InPlaceCheckBoxTreeDialog;
55
import org.eclipse.mylyn.internal.provisional.commons.ui.dialogs.InPlaceDialogEvent;
48
import org.eclipse.mylyn.internal.tasks.ui.util.WebBrowserDialog;
56
import org.eclipse.mylyn.internal.tasks.ui.util.WebBrowserDialog;
49
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
57
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
50
import org.eclipse.mylyn.tasks.core.RepositoryStatus;
58
import org.eclipse.mylyn.tasks.core.RepositoryStatus;
Lines 372-378 Link Here
372
				}
380
				}
373
				emailPattern2.setText(""); //$NON-NLS-1$
381
				emailPattern2.setText(""); //$NON-NLS-1$
374
				keywords.setText(""); //$NON-NLS-1$
382
				keywords.setText(""); //$NON-NLS-1$
375
				keywordsOperation.deselectAll();
383
				keywordsOperation.select(0);
376
				daysText.setText(""); //$NON-NLS-1$
384
				daysText.setText(""); //$NON-NLS-1$
377
			}
385
			}
378
		});
386
		});
Lines 742-758 Link Here
742
			}
750
			}
743
		});
751
		});
744
752
745
		Button keywordsSelectButton = new Button(keywordsComposite, SWT.NONE);
753
		final Button keywordsSelectButton = new Button(keywordsComposite, SWT.NONE);
746
		keywordsSelectButton.addSelectionListener(new SelectionAdapter() {
754
		keywordsSelectButton.addSelectionListener(new SelectionAdapter() {
747
			@Override
755
			@Override
748
			public void widgetSelected(SelectionEvent e) {
756
			public void widgetSelected(SelectionEvent e) {
749
				if (repositoryConfiguration != null && getShell() != null) {
757
750
					KeywordsDialog dialog = new KeywordsDialog(getShell(), keywords.getText(), //
758
				final java.util.List<String> values = new ArrayList<String>();
751
							repositoryConfiguration.getKeywords());
759
				for (String string : keywords.getText().split(",")) { //$NON-NLS-1$
752
					if (dialog.open() == Window.OK) {
760
					values.add(string.trim());
753
						keywords.setText(dialog.getSelectedKeywordsString());
761
				}
762
763
				Map<String, String> validValues = new HashMap<String, String>();
764
				for (String string : repositoryConfiguration.getKeywords()) {
765
					validValues.put(string, string);
766
				}
767
				final InPlaceCheckBoxTreeDialog selectionDialog = new InPlaceCheckBoxTreeDialog(
768
						WorkbenchUtil.getShell(), keywordsSelectButton, values, validValues, ""); //$NON-NLS-1$
769
				selectionDialog.addEventListener(new IInPlaceDialogListener() {
770
771
					public void buttonPressed(InPlaceDialogEvent event) {
772
						if (event.getReturnCode() == Window.OK) {
773
							Set<String> newValues = selectionDialog.getSelectedValues();
774
							if (!new HashSet<String>(values).equals(newValues)) {
775
								String erg = ""; //$NON-NLS-1$
776
								for (String string : newValues) {
777
									if (erg.equals("")) { //$NON-NLS-1$
778
										erg = string;
779
									} else {
780
										erg += (", " + string); //$NON-NLS-1$
781
									}
782
								}
783
								keywords.setText(erg);
784
							}
785
						} else if (event.getReturnCode() == AbstractInPlaceDialog.ID_CLEAR) {
786
							keywords.setText(""); //$NON-NLS-1$
787
						}
754
					}
788
					}
755
				}
789
				});
790
				selectionDialog.open();
791
756
			}
792
			}
757
		});
793
		});
758
		keywordsSelectButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
794
		keywordsSelectButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));

Return to bug 287899