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

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditor.java (-99 / +47 lines)
Lines 12-21 Link Here
12
import java.util.ArrayList;
12
import java.util.ArrayList;
13
import java.util.Calendar;
13
import java.util.Calendar;
14
import java.util.Date;
14
import java.util.Date;
15
import java.util.Iterator;
15
import java.util.List;
16
import java.util.Set;
16
import java.util.Set;
17
import java.util.StringTokenizer;
18
17
18
import org.eclipse.jface.dialogs.Dialog;
19
import org.eclipse.jface.dialogs.MessageDialog;
19
import org.eclipse.jface.dialogs.MessageDialog;
20
import org.eclipse.jface.layout.GridDataFactory;
20
import org.eclipse.jface.layout.GridDataFactory;
21
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin;
21
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin;
Lines 48-55 Link Here
48
import org.eclipse.swt.widgets.Button;
48
import org.eclipse.swt.widgets.Button;
49
import org.eclipse.swt.widgets.Composite;
49
import org.eclipse.swt.widgets.Composite;
50
import org.eclipse.swt.widgets.Label;
50
import org.eclipse.swt.widgets.Label;
51
import org.eclipse.swt.widgets.List;
51
import org.eclipse.swt.widgets.Shell;
52
import org.eclipse.swt.widgets.Text;
52
import org.eclipse.swt.widgets.Text;
53
import org.eclipse.ui.PlatformUI;
53
import org.eclipse.ui.forms.IFormColors;
54
import org.eclipse.ui.forms.IFormColors;
54
import org.eclipse.ui.forms.editor.FormEditor;
55
import org.eclipse.ui.forms.editor.FormEditor;
55
import org.eclipse.ui.forms.events.HyperlinkAdapter;
56
import org.eclipse.ui.forms.events.HyperlinkAdapter;
Lines 61-66 Link Here
61
import org.eclipse.ui.forms.widgets.Section;
62
import org.eclipse.ui.forms.widgets.Section;
62
import org.eclipse.ui.themes.IThemeManager;
63
import org.eclipse.ui.themes.IThemeManager;
63
64
65
64
/**
66
/**
65
 * An editor used to view a bug report that exists on a server. It uses a <code>BugReport</code> object to store the
67
 * An editor used to view a bug report that exists on a server. It uses a <code>BugReport</code> object to store the
66
 * data.
68
 * data.
Lines 73-84 Link Here
73
75
74
	private static final String LABEL_TIME_TRACKING = "Bugzilla Time Tracking";
76
	private static final String LABEL_TIME_TRACKING = "Bugzilla Time Tracking";
75
77
76
	// protected BugzillaCompareInput compareInput;
77
78
	// protected Button compareButton;
79
80
	protected List keyWordsList;
81
82
	protected Text keywordsText;
78
	protected Text keywordsText;
83
79
84
	protected Text estimateText;
80
	protected Text estimateText;
Lines 521-530 Link Here
521
517
522
	protected void addKeywordsList(Composite attributesComposite) throws IOException {
518
	protected void addKeywordsList(Composite attributesComposite) throws IOException {
523
		// newLayout(attributesComposite, 1, "Keywords:", PROPERTY);
519
		// newLayout(attributesComposite, 1, "Keywords:", PROPERTY);
524
		RepositoryTaskAttribute attribute = taskData.getAttribute(RepositoryTaskAttribute.KEYWORDS);
520
		final RepositoryTaskAttribute attribute = taskData.getAttribute(RepositoryTaskAttribute.KEYWORDS);
525
		if (attribute == null)
521
		if (attribute == null)
526
			return;
522
			return;
527
		String keywords = attribute.getValue();
528
		Label label = createLabel(attributesComposite, attribute);
523
		Label label = createLabel(attributesComposite, attribute);
529
		GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
524
		GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
530
525
Lines 538-588 Link Here
538
		keywordsData.horizontalSpan = 2;
533
		keywordsData.horizontalSpan = 2;
539
		keywordsData.widthHint = 200;
534
		keywordsData.widthHint = 200;
540
		keywordsText.setLayoutData(keywordsData);
535
		keywordsText.setLayoutData(keywordsData);
541
		// keywordsText.setText(keywords);
536
		
542
		keyWordsList = new List(attributesComposite, SWT.MULTI | SWT.V_SCROLL);
537
		
543
		keyWordsList.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
538
		Button changeKeywordsButton = getManagedForm().getToolkit().createButton(attributesComposite, "Edit...", SWT.FLAT);
544
		keyWordsList.setFont(TEXT_FONT);
539
		GridData keyWordsButtonData = new GridData();
545
		GridData keyWordsTextData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
540
		changeKeywordsButton.setLayoutData(keyWordsButtonData);
546
		keyWordsTextData.horizontalSpan = 1;
541
		changeKeywordsButton.addSelectionListener(new SelectionListener(){
547
		keyWordsTextData.widthHint = 125;
542
548
		keyWordsTextData.heightHint = 40;
543
			public void widgetDefaultSelected(SelectionEvent e) {}
549
		keyWordsList.setLayoutData(keyWordsTextData);
544
550
545
			public void widgetSelected(SelectionEvent e) {
551
		// initialize the keywords list with valid values
546
552
547
				String keywords = attribute.getValue();
553
		java.util.List<String> validKeywords = new ArrayList<String>();
548
554
		try {
549
				Shell shell = null;
555
			validKeywords = BugzillaCorePlugin.getRepositoryConfiguration(repository, false).getKeywords();
550
				if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
556
		} catch (Exception e) {
551
					shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
557
			// ignore
552
				} else {
558
		}
553
					shell = new Shell(PlatformUI.getWorkbench().getDisplay());
559
554
				}
560
		if (validKeywords != null) {
555
				
561
			for (Iterator<String> it = validKeywords.iterator(); it.hasNext();) {
556
				List<String> validKeywords = new ArrayList<String>();
562
				String keyword = it.next();
557
				try {
563
				keyWordsList.add(keyword);
558
					validKeywords = BugzillaCorePlugin.getRepositoryConfiguration(repository, false).getKeywords();
564
			}
559
				} catch (Exception ex) {
565
560
					// ignore
566
			// get the selected keywords for the bug
561
				}
567
			StringTokenizer st = new StringTokenizer(keywords, ",", false);
562
				
568
			ArrayList<Integer> indicies = new ArrayList<Integer>();
563
				KeywordsDialog keywordsDialog = new KeywordsDialog(shell, keywords, validKeywords);
569
			while (st.hasMoreTokens()) {
564
				int responseCode = keywordsDialog.open();
570
				String s = st.nextToken().trim();
565
				
571
				int index = keyWordsList.indexOf(s);
566
				String newKeywords = keywordsDialog.getSelectedKeywordsString();
572
				if (index != -1)
567
				if (responseCode == Dialog.OK && keywords != null) {
573
					indicies.add(new Integer(index));
568
					keywordsText.setText(newKeywords);
574
			}
569
					attribute.setValue(newKeywords);
575
570
					attributeChanged(attribute);
576
			// select the keywords that were selected for the bug
571
				} else {
577
			int length = indicies.size();
572
					return;
578
			int[] sel = new int[length];
573
				}
579
			for (int i = 0; i < length; i++) {
574
				
580
				sel[i] = indicies.get(i).intValue();
581
			}
575
			}
582
			keyWordsList.select(sel);
576
			
583
		}
577
		});
584
585
		keyWordsList.addSelectionListener(new KeywordListener());
586
	}
578
	}
587
579
588
	protected void addVoting(Composite attributesComposite) {
580
	protected void addVoting(Composite attributesComposite) {
Lines 632-681 Link Here
632
		});
624
		});
633
	}
625
	}
634
626
635
	/**
636
	 * Class to handle the selection change of the keywords.
637
	 */
638
	protected class KeywordListener implements SelectionListener {
639
640
		/*
641
		 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
642
		 */
643
		public void widgetSelected(SelectionEvent arg0) {
644
			markDirty(true);
645
646
			// get the selected keywords and create a string to submit
647
			StringBuffer keywords = new StringBuffer();
648
			String[] sel = keyWordsList.getSelection();
649
650
			// allow unselecting 1 keyword when it is the only one selected
651
			if (keyWordsList.getSelectionCount() == 1) {
652
				int index = keyWordsList.getSelectionIndex();
653
				String keyword = keyWordsList.getItem(index);
654
				if (taskData.getAttributeValue(BugzillaReportElement.KEYWORDS.getKeyString()).equals(keyword))
655
					keyWordsList.deselectAll();
656
			}
657
658
			for (int i = 0; i < keyWordsList.getSelectionCount(); i++) {
659
				keywords.append(sel[i]);
660
				if (i != keyWordsList.getSelectionCount() - 1) {
661
					keywords.append(",");
662
				}
663
			}
664
665
			taskData.setAttributeValue(BugzillaReportElement.KEYWORDS.getKeyString(), keywords.toString());
666
667
			// update the keywords text field
668
			keywordsText.setText(keywords.toString());
669
		}
670
671
		/*
672
		 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
673
		 */
674
		public void widgetDefaultSelected(SelectionEvent arg0) {
675
			// no need to listen to this
676
		}
677
678
	}
679
627
680
	@Override
628
	@Override
681
	protected void validateInput() {
629
	protected void validateInput() {
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/editor/KeywordsDialog.java (+152 lines)
Added Link Here
1
package org.eclipse.mylyn.internal.bugzilla.ui.editor;
2
import java.util.ArrayList;
3
import java.util.Collection;
4
import java.util.List;
5
import java.util.StringTokenizer;
6
7
import org.eclipse.jface.dialogs.Dialog;
8
import org.eclipse.jface.viewers.CheckStateChangedEvent;
9
import org.eclipse.jface.viewers.CheckboxTableViewer;
10
import org.eclipse.jface.viewers.ICheckStateListener;
11
import org.eclipse.jface.viewers.ITreeContentProvider;
12
import org.eclipse.jface.viewers.Viewer;
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.layout.GridData;
15
import org.eclipse.swt.layout.GridLayout;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Control;
18
import org.eclipse.swt.widgets.Shell;
19
20
/**
21
 * 
22
 * @author Shawn Minto
23
 */
24
public class KeywordsDialog extends Dialog {
25
26
	private List<String> selectedKeywords;
27
	private List<String> validKeywords;
28
	
29
	private  CheckboxTableViewer keyWordsList;
30
		
31
	public KeywordsDialog(Shell shell, String selectedKeywords, java.util.List<String> validKeywords) {
32
		super(shell);
33
		
34
		StringTokenizer st = new StringTokenizer(selectedKeywords, ",", false);
35
		this.selectedKeywords = new ArrayList<String>();
36
		while (st.hasMoreTokens()) {
37
			String s = st.nextToken().trim();
38
			this.selectedKeywords.add(s);
39
		}
40
		
41
		this.validKeywords = validKeywords;
42
	}
43
44
	@Override
45
	protected Control createDialogArea(Composite parent) {
46
		getShell().setText("Select Keywords");
47
	
48
		Composite composite = new Composite(parent, SWT.NONE);
49
		composite.setLayout(new GridLayout());
50
		GridData gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
51
		composite.setLayoutData(gd);
52
		
53
		
54
		
55
		
56
		keyWordsList = CheckboxTableViewer.newCheckList(composite, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
57
		GridData keyWordsTextData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
58
		keyWordsTextData.heightHint = 175;
59
		keyWordsTextData.widthHint = 160;
60
		keyWordsList.getTable().setLayoutData(keyWordsTextData);
61
62
63
		if (validKeywords != null) {
64
			
65
			keyWordsList.setContentProvider(new ITreeContentProvider(){
66
67
				public Object[] getChildren(Object parentElement) {
68
					if(parentElement instanceof Collection){
69
						return ((Collection<?>)parentElement).toArray();
70
					}
71
					return null;
72
				}
73
74
				public Object getParent(Object element) {
75
					// TODO Auto-generated method stub
76
					return null;
77
				}
78
79
				public boolean hasChildren(Object element) {
80
					// TODO Auto-generated method stub
81
					return false;
82
				}
83
84
				public Object[] getElements(Object inputElement) {
85
					return getChildren(inputElement);
86
				}
87
88
				public void dispose() {
89
					// TODO Auto-generated method stub
90
					
91
				}
92
93
				public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
94
					// TODO Auto-generated method stub
95
					
96
				}
97
				
98
			});
99
			
100
			
101
			keyWordsList.setInput(validKeywords);
102
			
103
						
104
			for(String keyword: selectedKeywords){
105
				keyWordsList.setChecked(keyword, true);
106
			}
107
		}
108
109
		keyWordsList.addCheckStateListener(new KeywordListener());
110
		
111
		super.createDialogArea(parent);
112
		
113
		parent.pack();
114
		
115
		return composite;
116
	}
117
	
118
	
119
	protected class KeywordListener implements ICheckStateListener {
120
		
121
		public void checkStateChanged(CheckStateChangedEvent event) {
122
			if(event.getChecked()){
123
				selectedKeywords.add((String)event.getElement());
124
			} else {
125
				selectedKeywords.remove(event.getElement());
126
			}
127
		}
128
129
	}
130
	
131
	public List<String> getSelectedKeywords(){
132
		return selectedKeywords;
133
	}
134
	
135
	public String getSelectedKeywordsString() {
136
		StringBuffer keywords = new StringBuffer();
137
	
138
		for(String sel: selectedKeywords){
139
			keywords.append(sel);
140
			keywords.append(",");
141
		}
142
		
143
		String keywordsString = keywords.toString(); 
144
		
145
		if(keywordsString.endsWith(",")){
146
			keywordsString = keywordsString.substring(0, keywordsString.length() - 1);
147
		}
148
		
149
		return keywordsString;
150
	}
151
152
}

Return to bug 168895