|
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 |
} |