/*
* Jampa
* Copyright (C) 2008-2009 J. Devauchelle and contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
package org.jampa.preferences.pages;
import java.net.Proxy;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.jampa.Activator;
import org.jampa.gui.translations.Messages;
import org.jampa.preferences.PreferenceConstants;
public class InternetPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
private RadioGroupFieldEditor proxyTypeFE;
private StringFieldEditor proxyUrlFE;
private IntegerFieldEditor proxyPortFE;
private StringFieldEditor proxyUsernameFE;
private StringFieldEditor proxyPasswordFE;
public InternetPage() {
super(GRID);
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setDescription(Messages.getString("InternetPage.Title")); //$NON-NLS-1$
}
@Override
protected void createFieldEditors() {
Label horizontalLine;
horizontalLine = new Label(getFieldEditorParent(), SWT.NONE);
horizontalLine.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 3, 1));
proxyTypeFE = new RadioGroupFieldEditor(
PreferenceConstants.PROXY_TYPE,
Messages.getString("InternetPage.ProxyType"), //$NON-NLS-1$
1,
new String[][] { { Messages.getString("InternetPage.NoProxy"), Proxy.Type.DIRECT.toString() }, { //$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("InternetPage.ProxyHttp"), Proxy.Type.HTTP.toString() }, { //$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("InternetPage.ProxySocks"), Proxy.Type.SOCKS.toString() } }, //$NON-NLS-1$ //$NON-NLS-2$
getFieldEditorParent());
addField(proxyTypeFE);
horizontalLine = new Label(getFieldEditorParent(), SWT.NONE);
horizontalLine.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 3, 1));
proxyUrlFE = new StringFieldEditor(PreferenceConstants.PROXY_URL,
Messages.getString("InternetPage.ProxyUrl"),
getFieldEditorParent());
addField(proxyUrlFE);
proxyPortFE = new IntegerFieldEditor(PreferenceConstants.PROXY_PORT,
Messages.getString("InternetPage.ProxyPort"),
getFieldEditorParent());
addField(proxyPortFE);
proxyUsernameFE = new StringFieldEditor(PreferenceConstants.PROXY_USERNAME,
Messages.getString("InternetPage.ProxyUsername"),
getFieldEditorParent());
addField(proxyUsernameFE);
proxyPasswordFE = new StringFieldEditor(PreferenceConstants.PROXY_PASSWORD,
Messages.getString("InternetPage.ProxyPassword"),
getFieldEditorParent());
proxyPasswordFE.getTextControl(getFieldEditorParent()).setEchoChar('*');
addField(proxyPasswordFE);
setEnableField(!getPreferenceStore().getString(PreferenceConstants.PROXY_TYPE).equals(Proxy.Type.DIRECT.toString()));
}
public void propertyChange(PropertyChangeEvent event) {
if (event.getSource().equals(proxyTypeFE)) {
setEnableField(!event.getNewValue().equals(Proxy.Type.DIRECT.toString()));
}
}
private void setEnableField(boolean value) {
proxyUrlFE.setEnabled(value, getFieldEditorParent());
proxyPortFE.setEnabled(value, getFieldEditorParent());
proxyUsernameFE.setEnabled(value, getFieldEditorParent());
proxyPasswordFE.setEnabled(value, getFieldEditorParent());
}
@Override
public void init(IWorkbench workbench) {
super.initialize();
}
}