SDK Updater: SettingsController that handles the settings.

There is not any longer any logic in the SettingsPage,
it is handled now by a "SettingsControllers" which is
available via UpdaterData. The page only takes care of
notifying the controller via a callback when settings
have changed in the UI.
This commit is contained in:
Raphael
2009-06-11 18:10:08 -07:00
parent 38ea6d2afe
commit f3eed7385c
6 changed files with 220 additions and 103 deletions

View File

@@ -16,8 +16,6 @@
package com.android.sdkmanager.internal.repository;
import com.android.prefs.AndroidLocation;
import com.android.prefs.AndroidLocation.AndroidLocationException;
import com.android.sdkuilib.internal.repository.ISettingsPage;
import org.eclipse.swt.SWT;
@@ -31,28 +29,15 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
/*
* TODO list
* - The window should probably set a callback to be notified when settings are changed.
* - Actually use the settings.
*/
public class SettingsPage extends Composite implements ISettingsPage {
private static final String SETTINGS_FILENAME = "androidtool.cfg"; //$NON-NLS-1$
/** Java system setting picked up by {@link URL} for http proxy port */
private static final String JAVA_HTTP_PROXY_PORT = "http.proxyPort"; //$NON-NLS-1$
/** Java system setting picked up by {@link URL} for http proxy host */
private static final String JAVA_HTTP_PROXY_HOST = "http.proxyHost"; //$NON-NLS-1$
// data members
private SettingsChangedCallback mSettingsChangedCallback;
// UI widgets
private Group mProxySettingsGroup;
private Group mPlaceholderGroup;
private Button mApplyButton;
@@ -130,85 +115,37 @@ public class SettingsPage extends Composite implements ISettingsPage {
private void postCreate() {
}
/** Loads settings from the given {@link Properties} container and update the page UI. */
public void loadSettings(Properties in_settings) {
mProxyServerText.setText(in_settings.getProperty(JAVA_HTTP_PROXY_HOST, "")); //$NON-NLS-1$
mProxyPortText.setText(in_settings.getProperty(JAVA_HTTP_PROXY_PORT, "")); //$NON-NLS-1$
}
/** Called by the application to retrieve settings from the UI and store them in
* the given {@link Properties} container. */
public void retrieveSettings(Properties out_settings) {
out_settings.put(JAVA_HTTP_PROXY_HOST, mProxyServerText.getText());
out_settings.put(JAVA_HTTP_PROXY_PORT, mProxyPortText.getText());
}
/**
* Called by the application to give a callback that the page should invoke when
* settings must be applied. The page does not apply the settings itself, instead
* it notifies the application.
*/
public void setOnSettingsChanged(SettingsChangedCallback settingsChangedCallback) {
mSettingsChangedCallback = settingsChangedCallback;
}
/**
* Notify the application that settings have changed.
*/
private void onApplySelected() {
applySettings();
saveSettings();
}
/**
* Update Java system properties for the HTTP proxy.
*/
public void applySettings() {
Properties props = System.getProperties();
props.put(JAVA_HTTP_PROXY_HOST, mProxyServerText.getText());
props.put(JAVA_HTTP_PROXY_PORT, mProxyPortText.getText());
}
/**
* Saves settings.
*/
private void saveSettings() {
Properties props = new Properties();
props.put(JAVA_HTTP_PROXY_HOST, mProxyServerText.getText());
props.put(JAVA_HTTP_PROXY_PORT, mProxyPortText.getText());
FileOutputStream fos = null;
try {
String folder = AndroidLocation.getFolder();
File f = new File(folder, SETTINGS_FILENAME);
fos = new FileOutputStream(f);
props.store( fos, "## Settings for Android Tool"); //$NON-NLS-1$
} catch (AndroidLocationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
if (mSettingsChangedCallback != null) {
mSettingsChangedCallback.onSettingsChanged(this);
}
}
/**
* Load settings and puts them in the UI.
*/
public void loadSettings() {
FileInputStream fis = null;
try {
String folder = AndroidLocation.getFolder();
File f = new File(folder, SETTINGS_FILENAME);
if (f.exists()) {
fis = new FileInputStream(f);
Properties props = new Properties();
props.load(fis);
mProxyServerText.setText(props.getProperty(JAVA_HTTP_PROXY_HOST, "")); //$NON-NLS-1$
mProxyPortText.setText(props.getProperty(JAVA_HTTP_PROXY_PORT, "")); //$NON-NLS-1$
}
} catch (AndroidLocationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
}
}
}
}
// End of hiding from SWT Designer
//$hide<<$
}