Skip to main content
summaryrefslogtreecommitdiffstats
blob: 49321427f4c0406fa989a9c8b654f30ba1dd791b (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*******************************************************************************
 * 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.ui.wizard;

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

import javax.security.auth.login.LoginException;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
import org.eclipse.mylar.bugzilla.core.BugzillaPreferences;
import org.eclipse.mylar.bugzilla.core.BugzillaRepository;
import org.eclipse.mylar.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.bugzilla.core.NewBugModel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IWorkbench;


/**
 * @author Shawn Minto
 * 
 * The first page of the new bug wizard where the user chooses the bug's product
 */
public class WizardProductPage extends AbstractWizardListPage {

	/** The list of products to submit a bug report for */
	static List<String> products = null;

	/** Reference to the bug wizard which created this page so we can create the second page */ 
	NewBugWizard bugWizard;

	/** String to hold previous product; determines if attribute option values need to be updated */
	private String prevProduct;

	/**
	 * Constructor for WizardProductPage
	 * 
	 * @param workbench
	 *            The instance of the workbench
	 * @param bugWiz
	 *            The bug wizard which created this page
	 */
	public WizardProductPage(IWorkbench workbench, NewBugWizard bugWiz) {
		super("Page1", "New Bug Report",
				"Pick a product on which to enter a bug.", workbench);
		this.bugWizard = bugWiz;
	}

	protected ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(BugzillaPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell());
	protected IPreferenceStore prefs = BugzillaPlugin.getDefault().getPreferenceStore();
	
	@Override
	public void createAdditionalControls(Composite parent){
		Button updateButton = new Button(parent, SWT.LEFT | SWT.PUSH);
		updateButton.setText("Update");
			
		updateButton.setLayoutData(new GridData());
		
		updateButton.addMouseListener(new MouseAdapter() {
			
			@Override
			public void mouseUp(MouseEvent e) {
				
				monitorDialog.open();
				IProgressMonitor monitor = monitorDialog.getProgressMonitor();
				monitor.beginTask("Updating search options...", 55);

				try {
					BugzillaPreferences.updateQueryOptions(monitor);
					
					products = new ArrayList<String>();
					for(String product : BugzillaPreferences.queryOptionsToArray(prefs.getString(IBugzillaConstants.PRODUCT_VALUES))){
						products.add(product);
					}
					monitor.worked(1);
				}
				catch (LoginException exception) {
					// we had a problem that seems to have been caused from bad login info
					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(exception);
				}
				finally {
					monitor.done();
					monitorDialog.close();
				}
			}
		});
	}
	
	/**
	 * Populates the listBox with all available products.
	 */
	@Override
	protected void populateList() {
		listBox.removeAll();
		Iterator<String> itr = products.iterator();

		while (itr.hasNext()) {
			String prod = itr.next();
			listBox.add(prod);
		}
	}

	@Override
	public void handleEvent(Event event) {
		handleEventHelper(event, "You must select a product");
	}

	@Override
	public IWizardPage getNextPage() {
		// save the product information to the model
		saveDataToModel();
		NewBugWizard wizard = (NewBugWizard) getWizard();
		NewBugModel model = wizard.model;

		// try to get the attributes from the bugzilla server
		try	{
			if (!model.hasParsedAttributes() || !prevProduct.equals(model.getProduct())) {
				if (model.isConnected()) {
					BugzillaRepository.getInstance().getnewBugAttributes(model, false);
				}
	 			else {
	 				BugzillaRepository.getInstance().getProdConfigAttributes(model);
	 			}
				model.setParsedAttributesStatus(true);
				if (prevProduct == null) {
					bugWizard.attributePage = new WizardAttributesPage(workbench);
					bugWizard.addPage(bugWizard.attributePage);
				}
				else {
					// selected product has changed
					bugWizard.attributePage.setControl(null);   // will createControl again with new attributes in model
				}
			}
		} catch (Exception e) {
		    BugzillaPlugin.getDefault().logAndShowExceptionDetailsDialog(e, "occurred.", "Bugzilla Error");
		}
		return super.getNextPage();
	}

	/**
	 * Save the currently selected product to the model when next is clicked
	 */
	private void saveDataToModel() {
		// Gets the model
		NewBugModel model = bugWizard.model;

		prevProduct = model.getProduct();
		model.setProduct((listBox.getSelection())[0]);
	}

	@Override
	public String getTableName() {
		return "Product:";
	}
}

Back to the top