Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3d5f93dd616f42a2213301f766b3ceff579db627 (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*******************************************************************************
 * Copyright (c) 2003 - 2006 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.mylyn.internal.bugzilla.ui.preferences;

import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaPlugin;
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylyn.internal.bugzilla.ui.BugzillaUiPlugin;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

/**
 * @author Gail Murphy
 * @author Mik Kersten
 */
public class BugzillaPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

	private RadioGroupFieldEditor bugzillaVersionEditor;

//	private static final String bugzillaMaxResultsLabel = "Maximum returned results: ";

//	private IntegerFieldEditor maxResults;

	/**
	 * Constructor for the preferences page
	 */
	public BugzillaPreferencePage() {
		super(GRID);

		// set the preference store for this preference page
		setPreferenceStore(BugzillaUiPlugin.getDefault().getPreferenceStore());
	}

	@Override
	protected Control createContents(Composite parent) {
		return super.createContents(parent);
	}

	@Override
	public void createControl(Composite parent) {
		super.createControl(parent);

		// HACK: there has to be an easier way
		Control[] radios = bugzillaVersionEditor.getRadioBoxControl(getFieldEditorParent()).getChildren();
		String currentVersion = BugzillaPlugin.getDefault().getPreferenceStore().getString(
				IBugzillaConstants.SERVER_VERSION);
		for (int i = 0; i < radios.length; i++) {
			Button button = (Button) radios[i];
			if (button.getText().equals(currentVersion)) {
				button.setSelection(true);
			} else {
				button.setSelection(false);
			}
		}
	}

	@Override
	protected void createFieldEditors() {

//		maxResults = new IntegerFieldEditor(IBugzillaConstants.MAX_RESULTS, bugzillaMaxResultsLabel,
//				getFieldEditorParent());

		// bugzillaVersionEditor.setPreferenceStore(BugzillaPlugin.getDefault().getPreferenceStore());
		bugzillaVersionEditor = new RadioGroupFieldEditor(IBugzillaConstants.SERVER_VERSION, "Bugzilla Version", 3,
				new String[][] { { IBugzillaConstants.SERVER_220, IBugzillaConstants.SERVER_VERSION },
						{ IBugzillaConstants.SERVER_218, IBugzillaConstants.SERVER_VERSION } }, getFieldEditorParent());
//		refreshQueries = new BooleanFieldEditor(IBugzillaConstants.REFRESH_QUERY,
//				"Automatically refresh Bugzilla reports and queries on startup", BooleanFieldEditor.DEFAULT,
//				getFieldEditorParent());

//		addField(maxResults);
		addField(bugzillaVersionEditor);
//		addField(refreshQueries);
	}

	public static void initDefaults(IPreferenceStore store) {
		store.setDefault(IBugzillaConstants.MOST_RECENT_QUERY, "");
		store.setDefault(IBugzillaConstants.SERVER_VERSION, IBugzillaConstants.SERVER_220);
		store.setDefault(IBugzillaConstants.REFRESH_QUERY, false);
		store.setDefault(IBugzillaConstants.MAX_RESULTS, 100);
	}

	@Override
	protected void performDefaults() {
		super.performDefaults();
	}

	@Override
	public boolean performOk() {
		// HACK: there has to be an easier way
		Control[] radios = bugzillaVersionEditor.getRadioBoxControl(getFieldEditorParent()).getChildren();
		for (int i = 0; i < radios.length; i++) {
			Button button = (Button) radios[i];
			if (button.getSelection()) {
				BugzillaPlugin.getDefault().getPreferenceStore().setValue(IBugzillaConstants.SERVER_VERSION,
						button.getText());
			}
		}

//		BugzillaPlugin.getDefault().getPreferenceStore().setValue(IBugzillaConstants.REFRESH_QUERY,
//				refreshQueries.getBooleanValue());

//		try {
//			int numMaxResults = maxResults.getIntValue();
//			BugzillaPlugin.getDefault().getPreferenceStore().setValue(IBugzillaConstants.MAX_RESULTS, numMaxResults);
//		} catch (NumberFormatException nfe) {
//			// ignore and leave as default
//			BugzillaPlugin.getDefault().getPreferenceStore().setValue(IBugzillaConstants.MAX_RESULTS,
//					BugzillaPlugin.getDefault().getPreferenceStore().getDefaultInt(IBugzillaConstants.MAX_RESULTS));
//		}

		// ProductConfiguration configuration = null;
		// String urlString = bugzillaServer.getStringValue();
		// try {
		// URL serverURL = new URL(urlString + "/show_bug.cgi");
		// URLConnection cntx =
		// BugzillaPlugin.getDefault().getUrlConnection(serverURL);
		// if (cntx == null || !(cntx instanceof HttpURLConnection))
		// return false;
		//
		// HttpURLConnection serverConnection = (HttpURLConnection) cntx;
		//
		// serverConnection.connect();
		//
		// int responseCode = serverConnection.getResponseCode();
		//
		// if (responseCode != HttpURLConnection.HTTP_OK)
		// throw new BugzillaException("No Bugzilla server detected at " +
		// bugzillaServer.getStringValue() + ".");
		//
		// try {
		// configuration =
		// ProductConfigurationFactory.getInstance().getConfiguration(
		// bugzillaServer.getStringValue());
		// } catch (IOException ex) {
		// MessageDialog.openInformation(null, "Bugzilla query parameters
		// check",
		// "An error occurred while pre-fetching valid search attributes: \n\n"
		// + ex.getClass().getName()
		// + ": " + ex.getMessage() + "\n\nOffline submission of new bugs will
		// be disabled.");
		// }
		// } catch (Exception e) {
		// if (!MessageDialog.openQuestion(null, "Bugzilla Server Error", "Error
		// validating Bugzilla Server.\n\n"
		// + e.getMessage() + "\n\nKeep specified server location anyway?")) {
		// return false;
		// }
		// }
		// BugzillaPlugin.getDefault().setProductConfiguration(urlString,
		// configuration);
		// IPath configFile =
		// BugzillaPlugin.getDefault().getProductConfigurationCachePath(urlString);
		// if (configuration != null) {
		//
		// try {
		// ProductConfigurationFactory.getInstance().writeConfiguration(configuration,
		// configFile.toFile());
		// } catch (IOException e) {
		// BugzillaPlugin.log(e);
		// configFile.toFile().delete();
		// }
		// } else {
		// configFile.toFile().delete();
		// }

		// save the preferences that were changed
		// BugzillaPlugin.getDefault().savePluginPreferences();

		// bugzillaServer.store();

		// store the username and password from the editor field
		// user = bugzillaUser.getStringValue();
		// password = bugzillaPassword.getStringValue();
		// storeCache(user, password, true);
		return true;
	}

	@Override
	public boolean performCancel() {
		// refreshQueries.setSelection(getPreferenceStore().getBoolean(MylarTasksPlugin.REFRESH_QUERIES));
		return true;
	}

	@Override
	protected void initialize() {
		super.initialize();
	}

	public void init(IWorkbench workbench) {
		// Don't need to do anything here with the workbench
	}

	// /**
	// * Hack private class to make StringFieldEditor.refreshValidState() a
	// * publicly acessible method.
	// *
	// * @see org.eclipse.jface.preference.StringFieldEditor#refreshValidState()
	// */
	// private static class MyStringFieldEditor extends StringFieldEditor {
	// public MyStringFieldEditor(String name, String labelText, int style,
	// Composite parent) {
	// super(name, labelText, style, parent);
	// }
	//
	// @Override
	// public void refreshValidState() {
	// super.refreshValidState();
	// }
	//
	// @Override
	// public Text getTextControl() {
	// return super.getTextControl();
	// }
	// }

	public static final String INFO_PASSWORD = "org.eclipse.team.cvs.core.password"; //$NON-NLS-1$ 

	public static final String INFO_USERNAME = "org.eclipse.team.cvs.core.username"; //$NON-NLS-1$ 

	public static final String AUTH_SCHEME = "";
}

Back to the top