Skip to main content
summaryrefslogtreecommitdiffstats
blob: 91d7297d9af5302c9ddd055d79c9384608523b54 (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
/*******************************************************************************
 * 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.offlineReports;

import java.util.Iterator;
import java.util.List;

import org.eclipse.mylar.bugzilla.BugzillaPlugin;
import org.eclipse.mylar.bugzilla.IBugzillaConstants;
import org.eclipse.mylar.bugzilla.core.BugReport;
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
import org.eclipse.mylar.bugzilla.ui.OfflineView;
import org.eclipse.mylar.bugzilla.ui.editor.ExistingBugEditorInput;
import org.eclipse.mylar.bugzilla.ui.editor.NewBugEditorInput;
import org.eclipse.mylar.bugzilla.ui.wizard.NewBugModel;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;


/**
 * View a bug from the offlineReports menu
 */
public class ViewOfflineReportAction extends AbstractOfflineReportsAction 
{
	
	/** The view to get the result to launch a viewer on */
	private OfflineView view;
	
	/**
	 * Constructor
	 * @param resultsView The view to launch a viewer on
	 */
	public ViewOfflineReportAction(OfflineView resultsView ) 
	{
		setToolTipText( "View selected offline reports" );
		setText( "View selected" );
		setIcon( "Icons/openresult.gif" );
		view = resultsView;
	}
	
	/**
	 * View the selected bugs in the editor window
	 * @see org.eclipse.jface.action.IAction#run()
	 */
	@Override
	public void run() 
	{
		OfflineView.checkWindow();
		List<IBugzillaBug> selectedBugs = view.getSelectedBugs();
		
		// if there are some selected bugs view the bugs in the editor window
		if (!selectedBugs.isEmpty()) 
		{
			IWorkbenchPage page = BugzillaPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
			for (Iterator<IBugzillaBug> it = selectedBugs.iterator(); it.hasNext(); ) {
				IBugzillaBug bug = it.next();
				if (bug instanceof BugReport) {
					ExistingBugEditorInput editorInput = new ExistingBugEditorInput((BugReport)bug);
					try {
						page.openEditor(editorInput, IBugzillaConstants.EXISTING_BUG_EDITOR_ID);
					} catch (PartInitException e) {
						BugzillaPlugin.log(e);
					}
					continue;
				}
				if (bug instanceof NewBugModel) {
					NewBugEditorInput editorInput = new NewBugEditorInput((NewBugModel)bug);
					try {
						page.openEditor(editorInput, IBugzillaConstants.NEW_BUG_EDITOR_ID);
					} catch (PartInitException e) {
						BugzillaPlugin.log(e);
					}
					continue;
				}
			}
		}
	}
}

Back to the top