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
|
/*******************************************************************************
* 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.favorites.actions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.mylar.bugzilla.BugzillaPlugin;
import org.eclipse.mylar.bugzilla.IBugzillaConstants;
import org.eclipse.mylar.bugzilla.favorites.Favorite;
import org.eclipse.mylar.bugzilla.search.BugzillaSearchResultView;
import org.eclipse.mylar.bugzilla.ui.FavoritesView;
/**
* Bookmark a returned Bugzilla Search result.
*/
public class AddFavoriteAction extends AbstractFavoritesAction {
/** Selected objects */
private List<Favorite> selected;
/** The view where the Bugzilla search results are displayed */
private BugzillaSearchResultView resultView;
/**
* Constructor
* @param text The label for the context menu item
* @param resultView The view where the Bugzilla search results are displayed
*/
public AddFavoriteAction(String text, BugzillaSearchResultView resultView) {
setText(text);
setIcon("Icons/bugzilla-bookmark.gif");
this.resultView = resultView;
selected = null;
}
/**
* Bookmark the selected items
* @see org.eclipse.ui.actions.ActionDelegate#run(IAction)
*/
@Override
public void run()
{
FavoritesView.checkWindow();
selected = new ArrayList<Favorite>();
buildSelection();
// go through each of the selected items and add its data to the favorites file
for (int i = 0; i < selected.size(); i++)
{
BugzillaPlugin.getDefault().getFavorites().add(selected.get(i));
}
FavoritesView.add();
FavoritesView.updateActionEnablement();
}
/**
* Gets the entire selection and puts each bug report into a list. Only the
* relevent parts of each bug report are put into the list.
*/
@SuppressWarnings("unchecked")
private void buildSelection() {
ISelection s = resultView.getViewer().getSelection();
if (s instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) s;
for (Iterator<IMarker> it = selection.iterator(); it.hasNext();) {
IMarker marker = it.next();
try
{
// try to get the attribute for the marker
Integer attributeId = (Integer) marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_ID);
// add the selected item to the list of items that are selected
String description = (String) marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_DESC);
String query = (String) marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_QUERY);
// create a map to add attributes to so that the favorites file can sort
HashMap<String, Object> attributes = new HashMap<String, Object>();
attributes.put(IBugzillaConstants.HIT_MARKER_ATTR_ID, attributeId);
attributes.put(IBugzillaConstants.HIT_MARKER_ATTR_PRIORITY, marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_PRIORITY));
attributes.put(IBugzillaConstants.HIT_MARKER_ATTR_SEVERITY, marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_SEVERITY));
attributes.put(IBugzillaConstants.HIT_MARKER_ATTR_STATE, marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_STATE));
attributes.put(IBugzillaConstants.HIT_MARKER_ATTR_RESULT, marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_RESULT));
Favorite favorite = new Favorite(BugzillaPlugin.getDefault().getServerName(), attributeId.intValue(), description, query, attributes);
selected.add(favorite);
}
catch (CoreException ignored)
{
// do nothing
}
}
}
}
}
|