2 * Copyright (C) 2009 The Android Open Source Project
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package com.android.sdkmanager.internal.repository;
\r
19 import com.android.sdkuilib.internal.repository.ISettingsPage;
\r
21 import org.eclipse.swt.SWT;
\r
22 import org.eclipse.swt.events.ModifyEvent;
\r
23 import org.eclipse.swt.events.ModifyListener;
\r
24 import org.eclipse.swt.events.SelectionAdapter;
\r
25 import org.eclipse.swt.events.SelectionEvent;
\r
26 import org.eclipse.swt.layout.GridData;
\r
27 import org.eclipse.swt.layout.GridLayout;
\r
28 import org.eclipse.swt.widgets.Button;
\r
29 import org.eclipse.swt.widgets.Composite;
\r
30 import org.eclipse.swt.widgets.Group;
\r
31 import org.eclipse.swt.widgets.Label;
\r
32 import org.eclipse.swt.widgets.Text;
\r
34 import java.util.Properties;
\r
37 public class SettingsPage extends Composite implements ISettingsPage {
\r
40 private SettingsChangedCallback mSettingsChangedCallback;
\r
43 private Group mProxySettingsGroup;
\r
44 private Group mMiscGroup;
\r
45 private Button mApplyButton;
\r
46 private Label mProxyServerLabel;
\r
47 private Label mProxyPortLabel;
\r
48 private Text mProxyServerText;
\r
49 private Text mProxyPortText;
\r
50 private Button mForceHttpCheck;
\r
51 private Button mAskAdbRestartCheck;
\r
53 private ModifyListener mSetApplyDirty = new ModifyListener() {
\r
54 public void modifyText(ModifyEvent e) {
\r
55 mApplyButton.setEnabled(true);
\r
61 * Create the composite.
\r
62 * @param parent The parent of the composite.
\r
64 public SettingsPage(Composite parent) {
\r
65 super(parent, SWT.BORDER);
\r
67 createContents(this);
\r
69 mProxySettingsGroup = new Group(this, SWT.NONE);
\r
70 mProxySettingsGroup.setText("Proxy Settings");
\r
71 mProxySettingsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
\r
72 mProxySettingsGroup.setLayout(new GridLayout(2, false));
\r
74 mProxyServerLabel = new Label(mProxySettingsGroup, SWT.NONE);
\r
75 mProxyServerLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
\r
76 mProxyServerLabel.setText("HTTP Proxy Server");
\r
77 String tooltip = "The DNS name or IP of the HTTP proxy server to use. " +
\r
78 "When empty, no HTTP proxy is used.";
\r
79 mProxyServerLabel.setToolTipText(tooltip);
\r
81 mProxyServerText = new Text(mProxySettingsGroup, SWT.BORDER);
\r
82 mProxyServerText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
\r
83 mProxyServerText.addModifyListener(mSetApplyDirty);
\r
84 mProxyServerText.setToolTipText(tooltip);
\r
86 mProxyPortLabel = new Label(mProxySettingsGroup, SWT.NONE);
\r
87 mProxyPortLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
\r
88 mProxyPortLabel.setText("HTTP Proxy Port");
\r
89 tooltip = "The port of the HTTP proxy server to use. " +
\r
90 "When empty, the default for HTTP or HTTPS is used.";
\r
91 mProxyPortLabel.setToolTipText(tooltip);
\r
93 mProxyPortText = new Text(mProxySettingsGroup, SWT.BORDER);
\r
94 mProxyPortText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
\r
95 mProxyPortText.addModifyListener(mSetApplyDirty);
\r
96 mProxyPortText.setToolTipText(tooltip);
\r
98 mMiscGroup = new Group(this, SWT.NONE);
\r
99 mMiscGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
\r
100 mMiscGroup.setText("Misc");
\r
101 mMiscGroup.setLayout(new GridLayout(2, false));
\r
103 mForceHttpCheck = new Button(mMiscGroup, SWT.CHECK);
\r
104 mForceHttpCheck.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
\r
105 mForceHttpCheck.setText("Force https://... sources to be fetched using http://...");
\r
106 mForceHttpCheck.setToolTipText("If you are not able to connect to the official Android repository " +
\r
107 "using HTTPS, enable this setting to force accessing it via HTTP.");
\r
108 mForceHttpCheck.addSelectionListener(new SelectionAdapter() {
\r
110 public void widgetSelected(SelectionEvent e) {
\r
111 onForceHttpSelected(); //$hide$
\r
115 mAskAdbRestartCheck = new Button(mMiscGroup, SWT.CHECK);
\r
116 mAskAdbRestartCheck.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
\r
117 mAskAdbRestartCheck.setText("Ask before restarting ADB");
\r
118 mAskAdbRestartCheck.setToolTipText("When checked, the user will be asked for permission " +
\r
119 "to restart ADB after updating an addon-on package or a tool package.");
\r
120 mAskAdbRestartCheck.addSelectionListener(new SelectionAdapter() {
\r
122 public void widgetSelected(SelectionEvent e) {
\r
123 onForceHttpSelected(); //$hide$
\r
127 mApplyButton = new Button(this, SWT.NONE);
\r
128 mApplyButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
\r
129 mApplyButton.setText("Save && Apply");
\r
130 mApplyButton.addSelectionListener(new SelectionAdapter() {
\r
132 public void widgetSelected(SelectionEvent e) {
\r
133 onApplySelected(); //$hide$
\r
137 postCreate(); //$hide$
\r
140 private void createContents(Composite parent) {
\r
141 parent.setLayout(new GridLayout(1, false));
\r
145 protected void checkSubclass() {
\r
146 // Disable the check that prevents subclassing of SWT components
\r
151 // -- Start of internal part ----------
\r
152 // Hide everything down-below from SWT designer
\r
156 * Called by the constructor right after {@link #createContents(Composite)}.
\r
158 private void postCreate() {
\r
161 /** Loads settings from the given {@link Properties} container and update the page UI. */
\r
162 public void loadSettings(Properties in_settings) {
\r
163 mProxyServerText.setText(in_settings.getProperty(KEY_HTTP_PROXY_HOST, "")); //$NON-NLS-1$
\r
164 mProxyPortText.setText( in_settings.getProperty(KEY_HTTP_PROXY_PORT, "")); //$NON-NLS-1$
\r
165 mForceHttpCheck.setSelection(Boolean.parseBoolean(in_settings.getProperty(KEY_FORCE_HTTP)));
\r
166 mAskAdbRestartCheck.setSelection(Boolean.parseBoolean(in_settings.getProperty(KEY_ASK_ADB_RESTART)));
\r
168 // We loaded fresh settings so there's nothing dirty to apply
\r
169 mApplyButton.setEnabled(false);
\r
172 /** Called by the application to retrieve settings from the UI and store them in
\r
173 * the given {@link Properties} container. */
\r
174 public void retrieveSettings(Properties out_settings) {
\r
175 out_settings.setProperty(KEY_HTTP_PROXY_HOST, mProxyServerText.getText());
\r
176 out_settings.setProperty(KEY_HTTP_PROXY_PORT, mProxyPortText.getText());
\r
177 out_settings.setProperty(KEY_FORCE_HTTP,
\r
178 Boolean.toString(mForceHttpCheck.getSelection()));
\r
179 out_settings.setProperty(KEY_ASK_ADB_RESTART,
\r
180 Boolean.toString(mAskAdbRestartCheck.getSelection()));
\r
184 * Called by the application to give a callback that the page should invoke when
\r
185 * settings must be applied. The page does not apply the settings itself, instead
\r
186 * it notifies the application.
\r
188 public void setOnSettingsChanged(SettingsChangedCallback settingsChangedCallback) {
\r
189 mSettingsChangedCallback = settingsChangedCallback;
\r
193 * Callback invoked when user presses the "Save and Apply" button.
\r
194 * Notify the application that settings have changed.
\r
196 private void onApplySelected() {
\r
197 if (mSettingsChangedCallback != null) {
\r
198 mSettingsChangedCallback.onSettingsChanged(this);
\r
199 mApplyButton.setEnabled(false);
\r
204 * Callback invoked when the users presses the Force HTTPS checkbox.
\r
206 private void onForceHttpSelected() {
\r
207 mSetApplyDirty.modifyText(null);
\r
210 // End of hiding from SWT Designer
\r