Skip to main content
summaryrefslogtreecommitdiffstats
blob: fcb36ccd7ea07d9ea9363d33260af5325a70471a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
/*******************************************************************************
 * Copyright (c) 2003 - 2005 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylar.bugzilla.ui.editor;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.StringTokenizer;

import javax.security.auth.login.LoginException;

import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareUI;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.JFaceColors;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylar.bugzilla.BugzillaPlugin;
import org.eclipse.mylar.bugzilla.IBugzillaConstants;
import org.eclipse.mylar.bugzilla.compare.BugzillaCompareInput;
import org.eclipse.mylar.bugzilla.core.Attribute;
import org.eclipse.mylar.bugzilla.core.BugPost;
import org.eclipse.mylar.bugzilla.core.BugReport;
import org.eclipse.mylar.bugzilla.core.BugzillaException;
import org.eclipse.mylar.bugzilla.core.BugzillaRepository;
import org.eclipse.mylar.bugzilla.core.Comment;
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
import org.eclipse.mylar.bugzilla.core.Operation;
import org.eclipse.mylar.bugzilla.favorites.actions.AddToFavoritesAction;
import org.eclipse.mylar.bugzilla.ui.OfflineView;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaOutlineNode;
import org.eclipse.mylar.bugzilla.ui.outline.BugzillaReportSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.Workbench;


/**
 * An editor used to view a bug report that exists on a server. It uses a
 * <code>BugReport</code> object to store the data.
 */
public class ExistingBugEditor extends AbstractBugEditor
{

	protected BugzillaCompareInput compareInput;
	protected Button compareButton;
	protected Button[] radios;
	protected Combo[] radioOptions;
	protected List keyWordsList;
	protected Text keywordsText;
	protected Text addCommentsText;
	protected BugReport bug;


    public String getNewCommentText(){
        return addCommentsTextBox.getText();
    }
    
	/**
	 * Creates a new <code>ExistingBugEditor</code>.
	 */
	public ExistingBugEditor() {
		super();
		
		// get the workbench page and add a listener so we can detect when it closes
		IWorkbench wb = BugzillaPlugin.getDefault().getWorkbench();
		IWorkbenchWindow aw = wb.getActiveWorkbenchWindow();
		IWorkbenchPage ap = aw.getActivePage();
		BugzillaEditorListener listener = new BugzillaEditorListener();
		ap.addPartListener(listener);
		
		// Set up the input for comparing the bug report to the server
		CompareConfiguration config = new CompareConfiguration();
		config.setLeftEditable(false);
		config.setRightEditable(false);
		config.setLeftLabel("Local Bug Report");
		config.setRightLabel("Remote Bug Report");
		config.setLeftImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT));
		config.setRightImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT));
		compareInput = new BugzillaCompareInput(config);
	}

	@Override
	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
		if (!(input instanceof ExistingBugEditorInput))
			throw new PartInitException("Invalid Input: Must be ExistingBugEditorInput");
		ExistingBugEditorInput ei = (ExistingBugEditorInput) input;
		setSite(site);
		setInput(input);
		bugzillaInput = ei;
		model = BugzillaOutlineNode.parseBugReport(bugzillaInput.getBug());
		bug = ei.getBug();
		restoreBug();
		updateEditorTitle();
	}

	/**
	 * This overrides the existing implementation in order to add
	 * an "add to favorites" option to the context menu.
	 *  
	 * @see org.eclipse.mylar.bugzilla.ui.AbstractBugEditor#createContextMenu()
	 */
	@Override
	protected void createContextMenu() {
		contextMenuManager = new MenuManager("#BugEditor");
		contextMenuManager.setRemoveAllWhenShown(true);
		contextMenuManager.addMenuListener(new IMenuListener() {
			public void menuAboutToShow(IMenuManager manager) {
				manager.add(new AddToFavoritesAction(ExistingBugEditor.this));
				manager.add(new Separator());
				manager.add(cutAction);
				manager.add(copyAction);
				manager.add(pasteAction);
				manager.add(new Separator());
				manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
				if (currentSelectedText == null || 
					currentSelectedText.getSelectionText().length() == 0) {
				
					copyAction.setEnabled(false);
				}
				else {
					copyAction.setEnabled(true);
				}
			}
		});
		getSite().registerContextMenu("#BugEditor", contextMenuManager,
				getSite().getSelectionProvider());
	}

	@Override
	protected void addRadioButtons(Composite buttonComposite) {
		int i = 0;
		radios = new Button[bug.getOperations().size()];
		radioOptions = new Combo[bug.getAttributes().size()];
		for (Iterator<Operation> it = bug.getOperations().iterator(); it.hasNext(); ) {
			Operation o = it.next();
			radios[i] = new Button(buttonComposite, SWT.RADIO);
			GridData radioData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
			if (!o.hasOptions())
				radioData.horizontalSpan = 4;
			else
				radioData.horizontalSpan = 3;
			radioData.heightHint = 20;
			radios[i].setText(o.getOperationName());
			radios[i].setLayoutData(radioData);
			radios[i].setBackground(background);
			radios[i].addSelectionListener(new RadioButtonListener());
			radios[i].addListener(SWT.FocusIn, new GenericListener());
			if (i == 0 || o.isChecked()) {
				radios[i].setSelection(true);
				bug.setSelectedOperation(o);
			}

			if (o.hasOptions()) {
				radioData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
				radioData.horizontalSpan = 1;
				radioData.heightHint = 20;
				radioData.widthHint = 80;
				radioOptions[i] = new Combo(
						buttonComposite,
						SWT.NO_BACKGROUND
							| SWT.MULTI
							| SWT.V_SCROLL
							| SWT.READ_ONLY);
		
				radioOptions[i].setLayoutData(radioData);
				radioOptions[i].setBackground(background);
				
				Object [] a = o.getOptionNames().toArray();
				Arrays.sort(a);
				for (int j = 0; j < a.length; j++) {
					radioOptions[i].add((String) a[j]);
				}
				radioOptions[i].select(0);
				radioOptions[i].addSelectionListener(new RadioButtonListener());
			}
			i++;
		}
	}

	@Override
	protected void addActionButtons(Composite buttonComposite) {
		super.addActionButtons(buttonComposite);

		compareButton = new Button(buttonComposite, SWT.NONE);
		GridData compareButtonData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
		compareButtonData.widthHint = 80;
		compareButtonData.heightHint = 20;
		compareButton.setText("Compare");
		compareButton.setLayoutData(compareButtonData);
		compareButton.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event e) {
				OpenCompareEditorJob compareJob = new OpenCompareEditorJob("Comparing bug with remote server...");
				compareJob.schedule();
			}
		});
		compareButton.addListener(SWT.FocusIn, new GenericListener());
	}

	/**
	 * @return Returns the compareInput.
	 */
	public BugzillaCompareInput getCompareInput() {
		return compareInput;
	}
	
	@Override
	public IBugzillaBug getBug() {
		return bug;
	}

	@Override
	protected String getTitleString() {
		return bug.getLabel() + ": " + checkText(bug.getAttribute("Summary").getNewValue());
	}

	@Override
	protected void submitBug() {
			BugPost form = new BugPost();
			
			// set the url for the bug to be submitted to
			setURL(form, "process_bug.cgi");

			// go through all of the attributes and add them to the bug post
			for (Iterator<Attribute> it = bug.getAttributes().iterator(); it.hasNext(); ) {
				Attribute a = it.next();
				if (a != null && a.getParameterName() != null && a.getParameterName().compareTo("") != 0 && !a.isHidden()) {
					String value = a.getNewValue();
					
					// add the attribute to the bug post
					form.add(a.getParameterName(), checkText(value));
				}
				else if(a != null && a.getParameterName() != null && a.getParameterName().compareTo("") != 0 && a.isHidden()) {
					// we have a hidden attribute and we should send it back.
					form.add(a.getParameterName(), a.getValue());
				}
			}
			
			// make sure that the comment is broken up into 80 character lines
			bug.setNewNewComment(formatText(bug.getNewNewComment()));
					
			// add the summary to the bug post
			form.add("short_desc", bug.getAttribute("Summary").getNewValue());
	
			// add the operation to the bug post
			Operation o = bug.getSelectedOperation();
			if (o == null)
				form.add("knob", "none");
			else {
				form.add("knob", o.getKnobName());
				if(o.hasOptions()) {
					String sel = o.getOptionValue(o.getOptionSelection());
					form.add(o.getOptionName(), sel);
				}
			}
			form.add("form_name", "process_bug");
			
	
			// add the new comment to the bug post if there is some text in it
			if(bug.getNewNewComment().length() != 0) {
				form.add("comment", bug.getNewNewComment());
			}
			
			try {
				form.post();
				
				changeDirtyStatus(false);
				BugzillaPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(this, false);
				OfflineView.removeReport(bug);
			} catch (BugzillaException e) {
			    BugzillaPlugin.getDefault().logAndShowExceptionDetailsDialog(e, "occurred while posting the bug.", "I/O Error");
			}
			catch (LoginException e) {
				MessageDialog.openError(null, "Login Error",
						"Bugzilla could not post your bug since your login name or password is incorrect.\nPlease check your settings in the bugzilla preferences. ");
			}
		}

	@Override
	protected void createDescriptionLayout() {
		// Description Area
		Composite descriptionComposite = new Composite(infoArea, SWT.NONE);
		GridLayout descriptionLayout = new GridLayout();
		descriptionLayout.numColumns = 4;
		descriptionComposite.setLayout(descriptionLayout);
		descriptionComposite.setBackground(background);
		GridData descriptionData = new GridData(GridData.FILL_BOTH);
		descriptionData.horizontalSpan = 1;
		descriptionData.grabExcessVerticalSpace = false;
		descriptionComposite.setLayoutData(descriptionData);
		// End Description Area
		
		StyledText t = newLayout(descriptionComposite, 4, "Description:", HEADER);
		t.addListener(SWT.FocusIn, new DescriptionListener());
		t = newLayout(descriptionComposite, 4, bug.getDescription(), VALUE);
		t.addListener(SWT.FocusIn, new DescriptionListener());
        
        texts.add(textsindex, t);
        textHash.put(bug.getDescription(), t);
        textsindex++; 
        
	}

	@Override
	protected void createCommentLayout() {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			
			// Additional (read-only) Comments Area
			Composite addCommentsComposite = new Composite(infoArea, SWT.NONE);
			GridLayout addCommentsLayout = new GridLayout();
			addCommentsLayout.numColumns = 4;
			addCommentsComposite.setLayout(addCommentsLayout);
			addCommentsComposite.setBackground(background);
			GridData addCommentsData = new GridData(GridData.FILL_BOTH);
			addCommentsData.horizontalSpan = 1;
			addCommentsData.grabExcessVerticalSpace = false;
			addCommentsComposite.setLayoutData(addCommentsData);
			//	End Additional (read-only) Comments Area
			
            StyledText t = null;
			for (Iterator<Comment> it = bug.getComments().iterator(); it.hasNext(); ) {
				Comment comment = it.next();
				String commentHeader = "Additional comment #" + comment.getNumber() + " from "
						+ comment.getAuthorName() + " on "
						+ df.format(comment.getCreated());
				t = newLayout(addCommentsComposite, 4, commentHeader, HEADER);
				t.addListener(SWT.FocusIn, new CommentListener(comment));
				t = newLayout(addCommentsComposite, 4, comment.getText(), VALUE);
				t.addListener(SWT.FocusIn, new CommentListener(comment));
                                
                //code for outline
                texts.add(textsindex, t);
                textHash.put(comment, t);
                textsindex++;
			}
	
			// Additional Comments Text
			Composite addCommentsTitleComposite =
				new Composite(addCommentsComposite, SWT.NONE);
			GridLayout addCommentsTitleLayout = new GridLayout();
			addCommentsTitleLayout.horizontalSpacing = 0;
			addCommentsTitleLayout.marginWidth = 0;
			addCommentsTitleComposite.setLayout(addCommentsTitleLayout);
			addCommentsTitleComposite.setBackground(background);
			GridData addCommentsTitleData =
				new GridData(GridData.HORIZONTAL_ALIGN_FILL);
			addCommentsTitleData.horizontalSpan = 4;
			addCommentsTitleData.grabExcessVerticalSpace = false;
			addCommentsTitleComposite.setLayoutData(addCommentsTitleData);
			newLayout(
				addCommentsTitleComposite,
				4,
				"New Additional Comment:",
				HEADER).addListener(SWT.FocusIn, new NewCommentListener());
			addCommentsText =
				new Text(
					addCommentsComposite,
					SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
			GridData addCommentsTextData =
				new GridData(GridData.HORIZONTAL_ALIGN_FILL);
			addCommentsTextData.horizontalSpan = 4;
			addCommentsTextData.widthHint = 250;
			addCommentsTextData.heightHint = 100;
			addCommentsText.setLayoutData(addCommentsTextData);
			addCommentsText.setText(bug.getNewComment());
			addCommentsText.addListener(SWT.FocusOut, new Listener() {
				public void handleEvent(Event event) {
					String sel = addCommentsText.getText();
					if (!(bug.getNewNewComment().equals(sel))) {
						bug.setNewNewComment(sel);
						changeDirtyStatus(true);
					}
				}
			});
			addCommentsText.addListener(SWT.FocusIn, new NewCommentListener());
			// End Additional Comments Text
	
            addCommentsTextBox = addCommentsText;
            
			this.createSeparatorSpace(addCommentsComposite);
		}

	@Override
	protected void addKeywordsList(String keywords, Composite attributesComposite) {
		newLayout(attributesComposite, 1, "Keywords:", PROPERTY);
		keywordsText = new Text(attributesComposite, SWT.BORDER);
		keywordsText.setEditable(false);
		keywordsText.setForeground(foreground);
		keywordsText.setBackground(JFaceColors.getErrorBackground(display));
		GridData keywordsData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		keywordsData.horizontalSpan = 2;
		keywordsData.widthHint = 200;
		keywordsText.setLayoutData(keywordsData);
		keywordsText.setText(keywords);
		keywordsText.addListener(SWT.FocusIn, new GenericListener());
		keyWordsList = new List(attributesComposite, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
		GridData keyWordsTextData =
			new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		keyWordsTextData.horizontalSpan = 1;
		keyWordsTextData.widthHint = 125;
		keyWordsTextData.heightHint = 40;
		keyWordsList.setLayoutData(keyWordsTextData);
		
		// initialize the keywords list with valid values
		java.util.List<String> keywordList = bug.getKeywords();
		if (keywordList != null) {
			for (Iterator<String> it = keywordList.iterator(); it.hasNext(); ) {
				String keyword = it.next();
				keyWordsList.add(keyword);
			}
			
			// get the selected keywords for the bug
			StringTokenizer st = new StringTokenizer(keywords, ",", false);
			ArrayList<Integer> indicies = new ArrayList<Integer>();
			while (st.hasMoreTokens()) {
				String s = st.nextToken().trim();
				int index = keyWordsList.indexOf(s);
				if (index != -1)
					indicies.add(new Integer(index));
			}
	
			// select the keywords that were selected for the bug
			int length = indicies.size();
			int[] sel = new int[length];
			for (int i = 0; i < length; i++) {
				sel[i] = indicies.get(i).intValue();
			}
			keyWordsList.select(sel);
		}
		
		keyWordsList.addSelectionListener(new KeywordListener());
		keyWordsList.addListener(SWT.FocusIn, new GenericListener());
	}

	@Override
	protected void updateBug() {
			
		// go through all of the attributes and update the main values to the new ones
		for (Iterator<Attribute> it = bug.getAttributes().iterator(); it.hasNext(); ) {
			Attribute a = it.next();
			a.setValue(a.getNewValue());
		}
		
		// Update some other fields as well.
		bug.setNewComment(bug.getNewNewComment());
			
	}

	@Override
	protected void restoreBug() {
		
		// go through all of the attributes and restore the new values to the main ones
		for (Iterator<Attribute> it = bug.getAttributes().iterator(); it.hasNext(); ) {
			Attribute a = it.next();
			a.setNewValue(a.getValue());
		}
		
		// Restore some other fields as well.
		bug.setNewNewComment(bug.getNewComment());
	}

	/**
	 * This job opens a compare editor to compare the current state of the bug
	 * in the editor with the bug on the server.
	 */
	protected class OpenCompareEditorJob extends Job {
		
			public OpenCompareEditorJob(String name) {
				super(name);
			}
		
			@Override
			protected IStatus run(IProgressMonitor monitor) {
				final BugReport serverBug;
				try {
					serverBug = BugzillaRepository.getInstance().getBug(bug.getId());
					// If no bug was found on the server, throw an exception so that the
					// user gets the same message that appears when there is a problem reading the server.
					if (serverBug == null) 
						throw new Exception();
				} catch (Exception e) {
					Workbench.getInstance().getDisplay().asyncExec(new Runnable() {
						public void run() {
							MessageDialog.openInformation(Workbench.getInstance().getActiveWorkbenchWindow().getShell(),
									"Could not open bug.", "Bug #" + bug.getId() + " could not be read from the server.");
						}
					});
					return new Status(IStatus.OK, IBugzillaConstants.PLUGIN_ID, IStatus.OK, "Could not get the bug report from the server.", null);
				}
				Workbench.getInstance().getDisplay().asyncExec(new Runnable() {
					public void run() {
						compareInput.setTitle("Bug #" + bug.getId());
						compareInput.setLeft(bug);
						compareInput.setRight(serverBug);
						CompareUI.openCompareEditor(compareInput);
					}
				});
				return new Status(IStatus.OK, IBugzillaConstants.PLUGIN_ID, IStatus.OK, "", null);
			}
		
		}

	/**
	 * Class to listen for editor events.
	 */
	protected class BugzillaEditorListener implements IPartListener
	{

		/**
		 * @see org.eclipse.ui.IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart)
		 */
		public void partActivated(IWorkbenchPart part) {
			// no need to listen to this
		}

		/**
		 * @see org.eclipse.ui.IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart)
		 */
		public void partBroughtToTop(IWorkbenchPart part) {
			// no need to listen to this
		}

		/**
		 * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
		 */
		public void partClosed(IWorkbenchPart part) {
			
			if (part instanceof ExistingBugEditor) {

				ExistingBugEditor editor = (ExistingBugEditor)part;
				
				// check if the bug editor needs to be saved
				if (editor.isDirty) {
					// ask the user whether they want to save it or not and perform the appropriate action
					editor.changeDirtyStatus(false);
					boolean response = MessageDialog.openQuestion(null, "Save Changes", 
							"You have made some changes to the bug, do you want to save them?");
					if (response) {
						editor.saveBug();
					}
				}
				
				// get the active workbench page
				IWorkbenchPage page = BugzillaPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();

				if (page != null) {
					// Close the compare editor, if there is one
					IEditorPart compareEditor = page.findEditor(getCompareInput());
					if (compareEditor != null) {
						page.closeEditor(compareEditor, false);
					}
				}

			}
		}

		/**
		 * @see org.eclipse.ui.IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart)
		 */
		public void partDeactivated(IWorkbenchPart part) {
			// no need to listen to this
		}

		/**
		 * @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart)
		 */
		public void partOpened(IWorkbenchPart part) {
			// no need to listen to this
		}
	}
	
	/**
	 * Class to handle the selection change of the keywords.
	 */
	protected class KeywordListener implements SelectionListener {
	
		/*
		 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
		 */
		public void widgetSelected(SelectionEvent arg0) {
			changeDirtyStatus(true);
			
			// get the selected keywords and create a string to submit
			StringBuffer keywords = new StringBuffer();
			String [] sel = keyWordsList.getSelection();
			
			// allow unselecting 1 keyword when it is the only one selected
			if(keyWordsList.getSelectionCount() == 1) {
				int index = keyWordsList.getSelectionIndex();
				String keyword = keyWordsList.getItem(index);
				if (bug.getAttribute("Keywords").getNewValue().equals(keyword))
					keyWordsList.deselectAll();
			}
			
			for(int i = 0; i < keyWordsList.getSelectionCount(); i++) {
				keywords.append(sel[i]);
				if (i != keyWordsList.getSelectionCount()-1) {
					keywords.append(",");
				}
			}
			bug.getAttribute("Keywords").setNewValue(keywords.toString());
			
			// update the keywords text field
			keywordsText.setText(keywords.toString());
		}
	
		/* 
		 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
		 */
		public void widgetDefaultSelected(SelectionEvent arg0) {	
			// no need to listen to this
		}
	
	}

	/**
	 * A listener for selection of the description field.
	 */
	protected class DescriptionListener implements Listener {
		public void handleEvent(Event event) {
			fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(new BugzillaReportSelection(bug.getId(), bug.getServer(), "Description", true, bug.getSummary()))));
		}
	}
	
	/**
	 * A listener for selection of a comment.
	 */
	protected class CommentListener implements Listener {
		
		/** The comment that this listener is for. */
		private Comment comment;

		/**
		 * Creates a new <code>CommentListener</code>.
		 * @param comment The comment that this listener is for.
		 */
		public CommentListener(Comment comment) {
			this.comment = comment;
		}
		
		public void handleEvent(Event event) {
			fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(new BugzillaReportSelection(bug.getId(), bug.getServer(), comment.getCreated().toString(), comment, bug.getSummary()))));
		}
	}
	
	/**
	 * A listener for selection of the textbox where a new comment is entered
	 * in.
	 */
	protected class NewCommentListener implements Listener {
		public void handleEvent(Event event) {
			fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(new BugzillaReportSelection(bug.getId(), bug.getServer(), "New Comment", false, bug.getSummary()))));
		}
	}
	
	/**
	 * Class to handle the selection change of the radio buttons.
	 */
	protected class RadioButtonListener implements SelectionListener {

		public void widgetDefaultSelected(SelectionEvent e) {
			widgetSelected(e);
		}

		public void widgetSelected(SelectionEvent e) {
			Button selected = null;
			for (int i = 0; i < radios.length; i++) {
				if (radios[i].getSelection())
					selected = radios[i];
			}
			// determine the operation to do to the bug
			for (int i = 0; i < radios.length; i++) {
				if (radios[i] != e.widget && radios[i] != selected)
					radios[i].setSelection(false);
				if (e.widget == radios[i]) {
					Operation o = bug.getOperation(radios[i].getText());
					bug.setSelectedOperation(o);
				}
				else if(e.widget == radioOptions[i]) {
					Operation o = bug.getOperation(radios[i].getText());
					o.setOptionSelection(radioOptions[i].getItem(radioOptions[i].getSelectionIndex()));
					bug.setSelectedOperation(o);
					radios[i].setSelection(true);
		            if(selected != null && selected != radios[i])
		                selected.setSelection(false);
				}
			}
		}
		
	}
	
	@Override
	public void handleSummaryEvent() {
		String sel = summaryText.getText();
		Attribute a = getBug().getAttribute("Summary");
		if (!(a.getNewValue().equals(sel))) {
			a.setNewValue(sel);
			changeDirtyStatus(true);
		}
	}
}

Back to the top