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