Skip to main content
summaryrefslogtreecommitdiffstats
blob: 499a39e4e10a4e6dee7b94419ab56f30becdd3d3 (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
/*******************************************************************************
 * 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 6, 2004
 */
package org.eclipse.mylar.tasks.bugzilla.search;

import javax.security.auth.login.LoginException;

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.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.mylar.bugzilla.BugzillaPlugin;
import org.eclipse.mylar.bugzilla.IBugzillaConstants;
import org.eclipse.mylar.tasks.bugzilla.BugzillaMylarBridge;
import org.eclipse.ui.PlatformUI;


/**
 * The bugzilla search job used to search a bugzilla site
 * 
 * @author sminto
 */
public class BugzillaMylarSearchJob extends Job {

    /** The search operation used to perform the query */
    private BugzillaMylarSearchOperation operation;

    /**
     * Constructor
     * 
     * @param name
     *            Job name
     * @param operation
     *            The operation to perform the search query
     */
    public BugzillaMylarSearchJob(String name,
            BugzillaMylarSearchOperation operation) {
        super(name);
        this.operation = operation;
    }

    @Override
    protected IStatus run(IProgressMonitor monitor) {
        // create a new status
        final IStatus[] status = new IStatus[1];

        try {
            // execute the search operation
            operation.execute(monitor);

            // get the status of the search operation
            status[0] = operation.getStatus();

            // determine if there was an error, if it was cancelled, or if it is
            // ok
            if ( status[0].getCode() == IStatus.CANCEL) {
                // it was cancelled, so just return
                status[0] = Status.OK_STATUS;

                // make sure that we know this job is not running anymore
                BugzillaMylarBridge.removeSearchJob(operation.getSearchMember().getHandleIdentifier()+" "+operation.getScope());//runningJobs.remove(operation.getSearchMember());
                return status[0];
            } else if (!status[0].isOK()) {
                // there was an error, so display an error message
                PlatformUI.getWorkbench().getDisplay().asyncExec(
                        new Runnable() {
                            public void run() {
                                ErrorDialog.openError(null,
                                        "Bugzilla Search Error", null,
                                        status[0]);
                            }
                        });
                status[0] = Status.OK_STATUS;

                // make sure we know that this job is not running anymore
                BugzillaMylarBridge.removeSearchJob(operation.getSearchMember().getHandleIdentifier()+" "+operation.getScope());//runningJobs.remove(operation.getSearchMember());
                return status[0];
            }
        } catch (LoginException e) {
            // we had a problem while searching that seems like a login info
            // problem
            // thrown in BugzillaSearchOperation
            MessageDialog
                    .openError(
                            null,
                            "Login Error",
                            "Bugzilla could not log you in to get the information you requested since login name or password is incorrect.\nPlease check your settings in the bugzilla preferences. ");
            BugzillaPlugin.log(new Status(IStatus.ERROR,
                    IBugzillaConstants.PLUGIN_ID, IStatus.OK, "", e));
        } finally {
            // make sure that we know that this job is not running anymore
        	BugzillaMylarBridge.removeSearchJob(operation.getSearchMember().getHandleIdentifier()+" "+operation.getScope());//.runningJobs.remove(operation.getSearchMember());
        }

        return status[0];
    }
}

Back to the top