Skip to main content
summaryrefslogtreecommitdiffstats
blob: 32406c23a1088dc6ba2b18dcc70f31b73b820693 (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
/*******************************************************************************
 * 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.core.search;

import java.util.Iterator;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
import org.eclipse.mylar.bugzilla.core.IBugzillaConstants;
import org.eclipse.search.internal.ui.SearchMessages;
import org.eclipse.search.internal.ui.util.ExceptionHandler;


/**
 * This class is used to open a bug report in an editor.
 */
public class OpenBugsAction extends Action {

	/** The view this action works on */
	private BugzillaSearchResultView resultView;

	/**
	 * Constructor
	 * @param text The text for this action
	 * @param resultView The <code>BugzillaSearchResultView</code> this action works on
	 */
	public OpenBugsAction(String text, BugzillaSearchResultView resultView) {
		setText(text);
		this.resultView = resultView;
	}
	
	/**
	 * Open the selected bug reports in their own editors. 
	 */
    @SuppressWarnings("unchecked")
    @Override
	public void run() {
		
		// Get the selected items
		ISelection s = resultView.getViewer().getSelection();
		if (s instanceof IStructuredSelection) {
			IStructuredSelection selection = (IStructuredSelection) s;

			// go through each of the selected items and show it in an editor
			for (Iterator<IMarker> it = selection.iterator(); it.hasNext();) {
				IMarker marker = it.next();
				try {
					Integer id = (Integer) marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_ID);
					BugzillaSearchHit.show(id.intValue());
				}
				catch (CoreException e) {
					// if an error occurs, handle and log it
					ExceptionHandler.handle(e, SearchMessages.Search_Error_search_title, SearchMessages.Search_Error_search_message); //$NON-NLS-2$ //$NON-NLS-1$
					BugzillaPlugin.log(e.getStatus());
				}
			}
			
		}
	}
	
}

Back to the top