Skip to main content
summaryrefslogtreecommitdiffstats
blob: 38325ab31c2ebf019ac662dd46bef2c95b15c6f8 (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
/*******************************************************************************
 * Copyright (c) 2004 - 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
 *******************************************************************************/
/*
 * Created on Oct 1, 2004
 */
package org.eclipse.mylar.bugzilla;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
import org.eclipse.mylar.bugzilla.ui.tasks.BugzillaReportNode;


/**
 * Class to handle the bridge between mylar and bugzilla
 * 
 * @author Shawn Minto
 */
public class BugzillaMylarBridge { 

    /** The hash of all of the landmarks and their related search hits */
    private HashMap<String, Map<Integer, List<BugzillaReportNode>>> landmarksHash;
	/**
	 * The currently running search jobs so that we can cancel it if necessary <br> KEY: IMember VALUE: Job
	 */
	public static HashMap<String, Job> runningJobs = new HashMap<String, Job>();

    /**
     * Constructor
     */
    public BugzillaMylarBridge() {
        landmarksHash = new HashMap<String, Map<Integer, List<BugzillaReportNode>>>();
    }

    
    /**
     * Remove a landmark from the hash
     * 
     * @param removed
     *            This landmark to remove (IJavaElement)
     */
    public void removeFromLandmarksHash(IJavaElement removed) {
        landmarksHash.remove(removed.getHandleIdentifier());
    }

    /**
     * Remove all of the landmarks from the hash that are in the list
     * 
     * @param removed
     *            This list of landmarks to remove (IJavaElements)
     */
    public void removeFromLandmarksHash(List<IJavaElement> removed) {

        for(IJavaElement je : removed) {
            landmarksHash.remove(je.getHandleIdentifier());
        }
    }

    /**
     * Add data to the landmarks hash
     * 
     * @param doiList
     *            The list of BugzillaSearchHitDoiInfo
     * @param m
     *            The member that this list is for
     */
    public void addToLandmarksHash(List<BugzillaReportNode> doiList, IMember m, int scope) {
    	Map<Integer, List<BugzillaReportNode>> searches = landmarksHash.get(m.getHandleIdentifier());
    	
    	if(searches == null){
    		searches = new HashMap<Integer, List<BugzillaReportNode>>();
    	}
    	searches.put(scope, doiList);
        landmarksHash.put(m.getHandleIdentifier(), searches);
    }

    /**
     * Get the doiList for the given IMember from the landmarks hash
     * 
     * @param m
     *            The member to get the doiList for
     * @return The doiList or null if it doesn't exist
     */
    public List<BugzillaReportNode> getFromLandmarksHash(IMember m, int scope) {
    	Map<Integer, List<BugzillaReportNode>> scopes = landmarksHash.get(m.getHandleIdentifier());
    	if(scopes == null)
    		return null;
    	else
    		return scopes.get(scope);
    }

	/**
	 * Determine whether the current element has a search job running for it
	 * 
	 * @param e
	 *            The element that we want to know whether there is a search job
	 *            or not
	 * @return <code>true</code> if it does else <code>false</code>
	 */
	public static boolean doesJobExist(String handle) {
	    return runningJobs.containsKey(handle);
	}

	/**
	 * Remove search job for the given element
	 * 
	 * @param m
	 *            The element that we want to make sure that the search is
	 *            canceled for
	 */
	public static void removeSearchJob(String handle) {
		
	    // make sure that there wasn't a previous search job that we know
	    // of. If there was, cancel it
	    if (doesJobExist(handle)) {
	        // get the search job and wait until it is cancelled
	        Job prevJob = runningJobs.get(handle);
	        prevJob.cancel();
            runningJobs.remove(handle);
	    }
	}

	/**
	 * Add a search job to our list
	 * @param handle The handle of the element that we are searching for
	 * @param searchJob The job that represents the search
	 */
	public static void addJob(String handle, Job searchJob) {
		runningJobs.put(handle, searchJob);
	}
}

Back to the top