aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager
diff options
context:
space:
mode:
authorRaphael <raphael@google.com>2009-05-21 21:43:00 -0700
committerRaphael <raphael@google.com>2009-05-22 11:31:50 -0700
commite2c0e975c244290674db1eb42e27bc03eb8d3b77 (patch)
treeecfdca94e3fe4d8da36e6669bbac9a7cf2585e12 /sdkmanager
parent3a6ffbab173fbfac460a54065f7f0638248b89b4 (diff)
downloadsdk-e2c0e975c244290674db1eb42e27bc03eb8d3b77.zip
sdk-e2c0e975c244290674db1eb42e27bc03eb8d3b77.tar.gz
sdk-e2c0e975c244290674db1eb42e27bc03eb8d3b77.tar.bz2
SDK Updater: some refactoring and some new features.
The refactoring part involves moving as much as possible stuff in SdkLib/internal/repository. The UI has moved in SdkUiLib/internal/repository except a specific public wrapper for calling the Sdk Updater window. There are also a bunch of new classes to handle the internal structures: Package is the base type and to match the XML element names we have PlatformPackage, AddonPackage, DocPackage and ToolPackage. All headers have been fixed.
Diffstat (limited to 'sdkmanager')
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/AddonPackage.java54
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/DocPackage.java29
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/IDescription.java40
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITask.java26
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITaskFactory.java25
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITaskMonitor.java (renamed from sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/ITaskMonitor.java)33
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Package.java92
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/PlatformPackage.java46
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java (renamed from sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/RepoSource.java)51
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ToolPackage.java40
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/repository/SdkRepository.java60
-rw-r--r--sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/AvdSelector.java4
-rw-r--r--sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/SdkTargetSelector.java54
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/AvailablePackagesPage.java177
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/InstalledPackagesPage.java (renamed from sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/InstalledPackagesPage.java)58
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ProgressTask.java (renamed from sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/ProgressTask.java)77
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ProgressTaskFactory.java39
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/RepoSources.java (renamed from sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/RepoSources.java)24
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java51
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterWindowImpl.java223
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/android_icon_16.png (renamed from sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/android_icon_16.png)bin460 -> 460 bytes
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/AvailablePackagesPage.java116
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/UpdaterWindow.java235
23 files changed, 1097 insertions, 457 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/AddonPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/AddonPackage.java
new file mode 100755
index 0000000..eb016cd
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/AddonPackage.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdklib.internal.repository;
+
+import com.android.sdklib.repository.SdkRepository;
+
+import org.w3c.dom.Node;
+
+/**
+ *
+ */
+public class AddonPackage extends Package {
+
+ private final String mVendor;
+ private final String mName;
+ private final String mApiLevel;
+
+ public AddonPackage(Node packageNode) {
+ super(packageNode);
+ mVendor = getXmlString(packageNode, SdkRepository.NODE_VENDOR);
+ mName = getXmlString(packageNode, SdkRepository.NODE_NAME);
+ mApiLevel = getXmlString(packageNode, SdkRepository.NODE_API_LEVEL);
+
+ // TODO libs
+ }
+
+ public String getVendor() {
+ return mVendor;
+ }
+
+ public String getName() {
+ return mName;
+ }
+
+ public String getApiLevel() {
+ return mApiLevel;
+ }
+
+
+}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/DocPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/DocPackage.java
new file mode 100755
index 0000000..fa71d4f
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/DocPackage.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdklib.internal.repository;
+
+import org.w3c.dom.Node;
+
+/**
+ *
+ */
+public class DocPackage extends Package {
+
+ public DocPackage(Node packageNode) {
+ super(packageNode);
+ }
+}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/IDescription.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/IDescription.java
new file mode 100755
index 0000000..7af92e2
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/IDescription.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdklib.internal.repository;
+
+/**
+ * Interface for elements that can provide a description of themselves.
+ */
+public interface IDescription {
+
+ /**
+ * Returns a description of the given element. Cannot be null.
+ * <p/>
+ * A description is a multi-line of text, typically much more
+ * elaborate than what {@link #toString()} would provide.
+ */
+ public abstract String getShortDescription();
+
+ /**
+ * Returns a description of the given element. Cannot be null.
+ * <p/>
+ * A description is a multi-line of text, typically much more
+ * elaborate than what {@link #toString()} would provide.
+ */
+ public abstract String getLongDescription();
+
+}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITask.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITask.java
new file mode 100755
index 0000000..9178460
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITask.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdklib.internal.repository;
+
+
+/**
+ * A task that executes and can update a monitor to display its status.
+ * The task will generally be run in a separate thread.
+ */
+public interface ITask {
+ public abstract void run(ITaskMonitor monitor);
+}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITaskFactory.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITaskFactory.java
new file mode 100755
index 0000000..540825c
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITaskFactory.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdklib.internal.repository;
+
+/**
+ * A factory that can start and run new {@link ITask}s.
+ */
+public interface ITaskFactory {
+
+ public abstract void start(String title, ITask task);
+}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/ITaskMonitor.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITaskMonitor.java
index 72375ab..832d246 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/ITaskMonitor.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITaskMonitor.java
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.eclipse.org/org/documents/epl-v10.php
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,18 +14,25 @@
* limitations under the License.
*/
-package com.android.sdkuilib.repository;
+package com.android.sdklib.internal.repository;
-import org.eclipse.swt.widgets.ProgressBar;
/**
- * A monitor interface for a {@link ProgressTask}
+ * A monitor interface for a {@link ITask}.
+ * <p/>
+ * Depending on the task factory that created the task, there might not be any UI
+ * or it might not implement all the methods, in which case calling them would be
+ * a no-op but is guaranteed not to crash.
+ * <p/>
+ * If the task runs in a non-UI worker thread, the task factory implementation
+ * will take care of the update the UI in the correct thread. The task itself
+ * must not have to deal with it.
*/
-interface ITaskMonitor {
+public interface ITaskMonitor {
/**
* Sets the description in the current task dialog.
- * This method can be invoke from a non-UI thread.
+ * This method can be invoked from a non-UI thread.
*/
public void setDescription(String description);
@@ -37,24 +44,20 @@ interface ITaskMonitor {
/**
* Sets the max value of the progress bar.
- * This method can be invoke from a non-UI thread.
- *
- * @see ProgressBar#setMaximum(int)
+ * This method can be invoked from a non-UI thread.
*/
public void setProgressMax(int max);
/**
* Increments the current value of the progress bar.
- *
* This method can be invoked from a non-UI thread.
*/
public void incProgress(int delta);
/**
- * Returns true if the "Cancel" button was selected.
- * It is up to the task thread to pool this and exit.
+ * Returns true if the user requested to cancel the operation.
+ * It is up to the task thread to pool this and exit as soon
+ * as possible.
*/
public boolean cancelRequested();
-
-
}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Package.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Package.java
new file mode 100755
index 0000000..126694a
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Package.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdklib.internal.repository;
+
+import com.android.sdklib.repository.SdkRepository;
+
+import org.w3c.dom.Node;
+
+/**
+ *
+ */
+public class Package {
+
+ private final int mRevision;
+ private final String mDescription;
+ private final String mDescUrl;
+
+ private Package(int revision, String description, String descUrl) {
+ mRevision = revision;
+ mDescription = description;
+ mDescUrl = descUrl;
+ }
+
+ public Package(Node packageNode) {
+ this(getXmlInt (packageNode, SdkRepository.NODE_REVISION, 0),
+ getXmlString(packageNode, SdkRepository.NODE_DESCRIPTION),
+ getXmlString(packageNode, SdkRepository.NODE_DESC_URL));
+
+ // TODO archives
+ }
+
+ /** The revision, an int > 0, for all packages (platform, add-on, tool, doc). */
+ public int getRevision() {
+ return mRevision;
+ }
+
+ /** The optional description for all packages (platform, add-on, tool, doc) or for a lib. */
+ public String getDescription() {
+ return mDescription;
+ }
+
+ /** The optional description URL for all packages (platform, add-on, tool, doc).
+ * Can be empty but not null. */
+ public String getDescUrl() {
+ return mDescUrl;
+ }
+
+ /**
+ * Retrieves the value of that XML element as a string.
+ * Returns an empty string when the element is missing.
+ */
+ protected static String getXmlString(Node node, String xmlLocalName) {
+ for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
+ if (child.getNodeType() == Node.ELEMENT_NODE &&
+ child.getNamespaceURI().equals(SdkRepository.NS_SDK_REPOSITORY)) {
+ if (xmlLocalName == null || child.getLocalName().equals(xmlLocalName)) {
+ return child.getTextContent();
+ }
+ }
+ }
+
+ return "";
+ }
+
+ /**
+ * Retrieves the value of that XML element as an integer.
+ * Returns the default value when the element is missing or is not an integer.
+ */
+ protected static int getXmlInt(Node node, String xmlLocalName, int defaultValue) {
+ String s = getXmlString(node, xmlLocalName);
+ try {
+ return Integer.parseInt(s);
+ } catch (NumberFormatException e) {
+ return defaultValue;
+ }
+ }
+
+}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/PlatformPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/PlatformPackage.java
new file mode 100755
index 0000000..b798ea8
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/PlatformPackage.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdklib.internal.repository;
+
+import com.android.sdklib.repository.SdkRepository;
+
+import org.w3c.dom.Node;
+
+/**
+ *
+ */
+public class PlatformPackage extends Package {
+
+ private final String mVersion;
+ private final String mApiLevel;
+
+ public PlatformPackage(Node packageNode) {
+ super(packageNode);
+ mVersion = getXmlString(packageNode, SdkRepository.NODE_VERSION);
+ mApiLevel = getXmlString(packageNode, SdkRepository.NODE_API_LEVEL);
+ }
+
+ public String getVersion() {
+ return mVersion;
+ }
+
+ public String getApiLevel() {
+ return mApiLevel;
+ }
+
+
+}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/RepoSource.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java
index d2f65de..fd909ab 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/RepoSource.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.eclipse.org/org/documents/epl-v10.php
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,12 +14,10 @@
* limitations under the License.
*/
-package com.android.sdkuilib.repository;
+package com.android.sdklib.internal.repository;
import com.android.sdklib.repository.SdkRepository;
-import com.android.sdkuilib.repository.ProgressTask.ThreadTask;
-import org.eclipse.swt.widgets.Shell;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
@@ -43,9 +41,9 @@ import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
/**
- *
+ * An sdk-repository source. It may be a full repository or an add-on only repository.
*/
-class RepoSource {
+public class RepoSource implements IDescription {
private final String mUrl;
private final boolean mAddonOnly;
@@ -59,11 +57,7 @@ class RepoSource {
public RepoSource(String url, boolean addonOnly) {
mUrl = url;
mAddonOnly = addonOnly;
- }
-
- @Override
- public String toString() {
- return mUrl;
+ setDefaultDescription();
}
/** Returns the URL of the source repository. */
@@ -78,26 +72,32 @@ class RepoSource {
return mPackages;
}
- public String getDescription() {
+ public String getShortDescription() {
+ return mUrl;
+ }
+
+ public String getLongDescription() {
return mDescription == null ? "" : mDescription; //$NON-NLS-1$
}
/**
* Tries to fetch the repository index for the given URL.
*/
- public void load(Shell shell) {
+ public void load(ITaskFactory taskFactory) {
- ProgressTask.start(shell, "Init SDK Updater", new ThreadTask() {
- public void PerformTask(ITaskMonitor monitor) {
+ taskFactory.start("Init SDK Updater", new ITask() {
+ public void run(ITaskMonitor monitor) {
monitor.setProgressMax(4);
+ setDefaultDescription();
+
monitor.setDescription(String.format("Fetching %1$s", mUrl));
monitor.incProgress(1);
String xml = fetchUrl(mUrl, monitor);
if (xml == null) {
- mDescription = String.format("Failed to fetch URL %1$s", mUrl);
+ mDescription += String.format("\nFailed to fetch URL %1$s", mUrl);
return;
}
@@ -105,13 +105,20 @@ class RepoSource {
monitor.incProgress(1);
if (!validateXml(xml, monitor)) {
- mDescription = String.format("Failed to validate XML at %1$s", mUrl);
+ mDescription += String.format("\nFailed to validate XML at %1$s", mUrl);
return;
}
monitor.setDescription("Parse XML");
monitor.incProgress(1);
parsePackages(xml, monitor);
+ if (mPackages.size() == 0) {
+ mDescription += "\nNo packages found.";
+ } else if (mPackages.size() == 1) {
+ mDescription += "\nOne package found.";
+ } else {
+ mDescription += String.format("\n%1$d packages found.", mPackages.size());
+ }
// done
monitor.incProgress(1);
@@ -119,6 +126,14 @@ class RepoSource {
});
}
+ private void setDefaultDescription() {
+ if (mAddonOnly) {
+ mDescription = String.format("Add-on Source: %1$s", mUrl);
+ } else {
+ mDescription = String.format("SDK Source: %1$s", mUrl);
+ }
+ }
+
/*
* References:
* Java URL Connection: http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ToolPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ToolPackage.java
new file mode 100755
index 0000000..9979ee3
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ToolPackage.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdklib.internal.repository;
+
+import com.android.sdklib.repository.SdkRepository;
+
+import org.w3c.dom.Node;
+
+/**
+ *
+ */
+public class ToolPackage extends Package {
+
+ private final String mApiLevel;
+
+ public ToolPackage(Node packageNode) {
+ super(packageNode);
+ mApiLevel = getXmlString(packageNode, SdkRepository.NODE_API_LEVEL);
+ }
+
+ public String getApiLevel() {
+ return mApiLevel;
+ }
+
+
+}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/SdkRepository.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/SdkRepository.java
index 72cc425..65962c9 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/SdkRepository.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/SdkRepository.java
@@ -19,24 +19,64 @@ package com.android.sdklib.repository;
import java.io.InputStream;
/**
- * Constants for the sdk-repository XML Schema
+ * Public constants for the sdk-repository XML Schema.
*/
public class SdkRepository {
+ /** The XML namespace of the sdk-repository XML. */
public static final String NS_SDK_REPOSITORY =
"http://schemas.android.com/sdk/android/repository/1"; //$NON-NLS-1$
- public static final String NODE_VERSION = "version"; //$NON-NLS-1$
- public static final String NODE_REVISION = "revision"; //$NON-NLS-1$
- public static final String NODE_API_LEVEL = "api-level"; //$NON-NLS-1$
- public static final String NODE_VENDOR = "vendor"; //$NON-NLS-1$
- public static final String NODE_NAME = "name"; //$NON-NLS-1$
- public static final String NODE_TOOL = "tool"; //$NON-NLS-1$
- public static final String NODE_DOC = "doc"; //$NON-NLS-1$
- public static final String NODE_PLATFORM = "platform"; //$NON-NLS-1$
- public static final String NODE_ADD_ON = "add-on"; //$NON-NLS-1$
+ /** The root sdk-repository element */
public static final String NODE_SDK_REPOSITORY = "sdk-repository"; //$NON-NLS-1$
+ /** A platform package. */
+ public static final String NODE_PLATFORM = "platform"; //$NON-NLS-1$
+ /** An add-on package. */
+ public static final String NODE_ADD_ON = "add-on"; //$NON-NLS-1$
+ /** A tool package. */
+ public static final String NODE_TOOL = "tool"; //$NON-NLS-1$
+ /** A doc package. */
+ public static final String NODE_DOC = "doc"; //$NON-NLS-1$
+
+ /** The revision, an int > 0, for all packages (platform, add-on, tool, doc). */
+ public static final String NODE_REVISION = "revision"; //$NON-NLS-1$
+ /** The optional description for all packages (platform, add-on, tool, doc) or for a lib. */
+ public static final String NODE_DESCRIPTION = "description"; //$NON-NLS-1$
+ /** The optional description URL for all packages (platform, add-on, tool, doc). */
+ public static final String NODE_DESC_URL = "desc-url"; //$NON-NLS-1$
+
+ /** The version, a string, for platform packages. */
+ public static final String NODE_VERSION = "version"; //$NON-NLS-1$
+ /** The api-level, an int > 0, for platform, add-on and doc packages. */
+ public static final String NODE_API_LEVEL = "api-level"; //$NON-NLS-1$
+ /** The vendor, a string, for add-on packages. */
+ public static final String NODE_VENDOR = "vendor"; //$NON-NLS-1$
+ /** The name, a string, for add-on packages or for libraries. */
+ public static final String NODE_NAME = "name"; //$NON-NLS-1$
+
+ /** The libs container, optional for an add-on. */
+ public static final String NODE_LIBS = "libs"; //$NON-NLS-1$
+ /** A lib element in a libs container. */
+ public static final String NODE_LIB = "lib"; //$NON-NLS-1$
+
+ /** The archives container, for all packages. */
+ public static final String NODE_ARCHVIES = "archives"; //$NON-NLS-1$
+ /** An archive element, for the archives container. */
+ public static final String NODE_ARCHVIE = "archive"; //$NON-NLS-1$
+
+ /** An archive size, an int > 0. */
+ public static final String NODE_SIZE = "size"; //$NON-NLS-1$
+ /** A sha1 archive checksum, as a 40-char hex. */
+ public static final String NODE_CHECKSUM = "checksum"; //$NON-NLS-1$
+ /** A download archive URL, either absolute or relative to the repository xml. */
+ public static final String NODE_URL = "url"; //$NON-NLS-1$
+
+ /** An archive OS attribute, mandatory. */
+ public static final String NODE_OS = "os"; //$NON-NLS-1$
+ /** An optional archive Architecture attribute. */
+ public static final String NODE_ARCH = "arch"; //$NON-NLS-1$
+
public static InputStream getXsdStream() {
return SdkRepository.class.getResourceAsStream("sdk-repository.xsd"); //$NON-NLS-1$
}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/AvdSelector.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/AvdSelector.java
index 44c7724..0166556 100644
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/AvdSelector.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/AvdSelector.java
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.eclipse.org/org/documents/epl-v10.php
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/SdkTargetSelector.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/SdkTargetSelector.java
index b23c865..b90bd61 100644
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/SdkTargetSelector.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/SdkTargetSelector.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2009 The Android Open Source Project
*
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.eclipse.org/org/documents/epl-v10.php
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -46,17 +46,17 @@ import org.eclipse.swt.widgets.TableItem;
* selection.
*/
public class SdkTargetSelector {
-
+
private IAndroidTarget[] mTargets;
private final boolean mAllowSelection;
private SelectionListener mSelectionListener;
private Table mTable;
private Label mDescription;
private Composite mInnerGroup;
-
+
/**
* Creates a new SDK Target Selector.
- *
+ *
* @param parent The parent composite where the selector will be added.
* @param targets The list of targets. This is <em>not</em> copied, the caller must not modify.
* Targets can be null or an empty array, in which case the table is disabled.
@@ -67,7 +67,7 @@ public class SdkTargetSelector {
/**
* Creates a new SDK Target Selector.
- *
+ *
* @param parent The parent composite where the selector will be added.
* @param targets The list of targets. This is <em>not</em> copied, the caller must not modify.
* Targets can be null or an empty array, in which case the table is disabled.
@@ -79,7 +79,7 @@ public class SdkTargetSelector {
mInnerGroup.setLayout(new GridLayout());
mInnerGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
mInnerGroup.setFont(parent.getFont());
-
+
mAllowSelection = allowSelection;
int style = SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION;
if (allowSelection) {
@@ -137,7 +137,7 @@ public class SdkTargetSelector {
/**
* Changes the targets of the SDK Target Selector.
- *
+ *
* @param targets The list of targets. This is <em>not</em> copied, the caller must not modify.
*/
public void setTargets(IAndroidTarget[] targets) {
@@ -154,19 +154,19 @@ public class SdkTargetSelector {
* The {@link TableItem#getData()} contains an {@link IAndroidTarget}.
* <p/>
* It is recommended that the caller uses the {@link #getSelected()} method instead.
- *
+ *
* @param selectionListener The new listener or null to remove it.
*/
public void setSelectionListener(SelectionListener selectionListener) {
mSelectionListener = selectionListener;
}
-
+
/**
* Sets the current target selection.
* <p/>
* If the selection is actually changed, this will invoke the selection listener
* (if any) with a null event.
- *
+ *
* @param target the target to be selection
* @return true if the target could be selected, false otherwise.
*/
@@ -174,7 +174,7 @@ public class SdkTargetSelector {
if (!mAllowSelection) {
return false;
}
-
+
boolean found = false;
boolean modified = false;
@@ -192,17 +192,17 @@ public class SdkTargetSelector {
}
}
}
-
+
if (modified && mSelectionListener != null) {
mSelectionListener.widgetSelected(null);
}
-
+
return found;
}
/**
* Returns the selected item.
- *
+ *
* @return The selected item or null.
*/
public IAndroidTarget getSelected() {
@@ -234,7 +234,7 @@ public class SdkTargetSelector {
@Override
public void controlResized(ControlEvent e) {
Rectangle r = table.getClientArea();
- column0.setWidth(r.width * 30 / 100); // 30%
+ column0.setWidth(r.width * 30 / 100); // 30%
column1.setWidth(r.width * 45 / 100); // 45%
column2.setWidth(r.width * 15 / 100); // 15%
column3.setWidth(r.width * 10 / 100); // 10%
@@ -267,7 +267,7 @@ public class SdkTargetSelector {
mSelectionListener.widgetDefaultSelected(e);
}
}
-
+
public void widgetSelected(SelectionEvent e) {
if (e.item instanceof TableItem) {
TableItem i = (TableItem) e.item;
@@ -315,7 +315,7 @@ public class SdkTargetSelector {
}
table.removeAll();
-
+
if (mTargets != null && mTargets.length > 0) {
table.setEnabled(true);
for (IAndroidTarget target : mTargets) {
@@ -350,36 +350,36 @@ public class SdkTargetSelector {
}
/*
- * Reference:
+ * Reference:
* http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet125.java?view=markup
*/
-
+
final Listener listener = new Listener() {
public void handleEvent(Event event) {
-
+
switch(event.type) {
case SWT.KeyDown:
case SWT.MouseExit:
case SWT.MouseDown:
return;
-
+
case SWT.MouseHover:
updateDescription(table.getItem(new Point(event.x, event.y)));
break;
-
+
case SWT.Selection:
if (event.item instanceof TableItem) {
updateDescription((TableItem) event.item);
}
break;
-
+
default:
return;
}
}
};
-
+
table.addListener(SWT.Dispose, listener);
table.addListener(SWT.KeyDown, listener);
table.addListener(SWT.MouseMove, listener);
@@ -414,5 +414,5 @@ public class SdkTargetSelector {
enableControl(c2, enabled);
}
}
-
+
}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/AvailablePackagesPage.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/AvailablePackagesPage.java
new file mode 100755
index 0000000..97b8c0d
--- /dev/null
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/AvailablePackagesPage.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdkuilib.internal.repository;
+
+
+import com.android.sdklib.internal.repository.IDescription;
+
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+
+/*
+ * TODO list
+ * - check source => toggle packages: all, none
+ * - check package => set source check to tri-state
+ * - check callback => install enable if has selection
+ * - fill columns (or remove them?)
+ * - select tree item: delete site enable if add-on source
+ * - select tree item: refresh enable if source
+ * - load add-on sites from pref
+ * - delete site callback, update pref
+ * - refresh callback
+ * - install selected callback
+ */
+
+public class AvailablePackagesPage extends Composite {
+
+ private final UpdaterData mUpdaterData;
+
+ private CheckboxTreeViewer mTreeViewerSources;
+ private Tree mTreeSources;
+ private TreeColumn mColumnAvailSummary;
+ private TreeColumn mColumnAvailApiLevel;
+ private TreeColumn mColumnAvailRevision;
+ private TreeColumn mColumnAvailOs;
+ private TreeColumn mColumnAvailInstalled;
+ private Group mDescriptionContainer;
+ private Button mAddSiteButton;
+ private Button mRemoveSiteButton;
+ private Label mPlaceholder3;
+ private Button mRefreshButton;
+ private Button mInstallSelectedButton;
+ private Label mDescriptionLabel;
+
+
+ /**
+ * Create the composite.
+ * @param parent The parent of the composite.
+ * @param updaterData An instance of {@link UpdaterData}. If null, a local
+ * one will be allocated just to help with the SWT Designer.
+ */
+ public AvailablePackagesPage(Composite parent, UpdaterData updaterData) {
+ super(parent, SWT.BORDER);
+
+ mUpdaterData = updaterData != null ? updaterData : new UpdaterData();
+
+ createContents(this);
+ }
+
+ private void createContents(Composite parent) {
+ parent.setLayout(new GridLayout(5, false));
+
+ mTreeViewerSources = new CheckboxTreeViewer(parent, SWT.BORDER);
+ mTreeViewerSources.setContentProvider(mUpdaterData.getSources().getContentProvider());
+ mTreeViewerSources.setLabelProvider(mUpdaterData.getSources().getLabelProvider());
+ mTreeSources = mTreeViewerSources.getTree();
+ mTreeSources.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ onTreeSelected(); //$hide$
+ }
+ });
+ mTreeSources.setHeaderVisible(true);
+ mTreeSources.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
+
+ mColumnAvailSummary = new TreeColumn(mTreeSources, SWT.NONE);
+ mColumnAvailSummary.setWidth(289);
+ mColumnAvailSummary.setText("Summary");
+
+ mColumnAvailApiLevel = new TreeColumn(mTreeSources, SWT.NONE);
+ mColumnAvailApiLevel.setWidth(66);
+ mColumnAvailApiLevel.setText("API Level");
+
+ mColumnAvailRevision = new TreeColumn(mTreeSources, SWT.NONE);
+ mColumnAvailRevision.setWidth(63);
+ mColumnAvailRevision.setText("Revision");
+
+ mColumnAvailOs = new TreeColumn(mTreeSources, SWT.NONE);
+ mColumnAvailOs.setWidth(100);
+ mColumnAvailOs.setText("OS/Arch");
+
+ mColumnAvailInstalled = new TreeColumn(mTreeSources, SWT.NONE);
+ mColumnAvailInstalled.setWidth(59);
+ mColumnAvailInstalled.setText("Installed");
+
+ mDescriptionContainer = new Group(parent, SWT.NONE);
+ mDescriptionContainer.setLayout(new GridLayout(1, false));
+ mDescriptionContainer.setText("Description");
+ mDescriptionContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 5, 1));
+
+ mDescriptionLabel = new Label(mDescriptionContainer, SWT.NONE);
+ mDescriptionLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+ mDescriptionLabel.setText("Line1\nLine2\nLine3");
+
+ mAddSiteButton = new Button(parent, SWT.NONE);
+ mAddSiteButton.setText("Add Site...");
+
+ mRemoveSiteButton = new Button(parent, SWT.NONE);
+ mRemoveSiteButton.setText("Delete Site...");
+
+ mPlaceholder3 = new Label(parent, SWT.NONE);
+ mPlaceholder3.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
+
+ mRefreshButton = new Button(parent, SWT.NONE);
+ mRefreshButton.setText("Refresh");
+
+ mInstallSelectedButton = new Button(parent, SWT.NONE);
+ mInstallSelectedButton.setText("Install Selected");
+ }
+
+ @Override
+ protected void checkSubclass() {
+ // Disable the check that prevents subclassing of SWT components
+ }
+
+ // -- Start of internal part ----------
+ // Hide everything down-below from SWT designer
+ //$hide>>$
+
+ public void setInput(RepoSources sources) {
+ mTreeViewerSources.setInput(sources);
+ onTreeSelected();
+ }
+
+ private void onTreeSelected() {
+ ISelection sel = mTreeViewerSources.getSelection();
+ if (sel instanceof ITreeSelection) {
+ Object elem = ((ITreeSelection) sel).getFirstElement();
+ if (elem instanceof IDescription) {
+ mDescriptionLabel.setText(((IDescription) elem).getLongDescription());
+ mDescriptionContainer.layout(true);
+ return;
+ }
+ }
+ mDescriptionLabel.setText(""); //$NON-NLS1-$
+ }
+
+
+ // End of hiding from SWT Designer
+ //$hide<<$
+
+}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/InstalledPackagesPage.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/InstalledPackagesPage.java
index 95d180d..118760c 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/InstalledPackagesPage.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/InstalledPackagesPage.java
@@ -1,7 +1,23 @@
-package com.android.sdkuilib.repository;
-
-import com.android.sdkuilib.repository.ProgressTask.ThreadTask;
-import com.android.sdkuilib.repository.UpdaterWindow.UpdaterData;
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdkuilib.internal.repository;
+
+import com.android.sdklib.internal.repository.ITask;
+import com.android.sdklib.internal.repository.ITaskMonitor;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
@@ -17,6 +33,17 @@ import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
+/*
+ * TODO list
+ * - parse local repo
+ * - create entries
+ * - select => update desc, enable update + delete, enable home page if url
+ * - home page callback
+ * - update callback
+ * - delete callback
+ * - refresh callback
+ */
+
public class InstalledPackagesPage extends Composite {
private UpdaterData mUpdaterData;
@@ -29,24 +56,25 @@ public class InstalledPackagesPage extends Composite {
private TableColumn mColumnInstSummary;
private TableColumn mColumnInstApiLevel;
private TableColumn mColumnInstRevision;
- private Group mInstDescription;
+ private Group mDescriptionContainer;
private Composite mInstButtons;
private Button mInstUpdate;
private Label mPlaceholder1;
private Button mInstDelete;
private Label mPlaceholder2;
private Button mInstHomePage;
+ private Label mDescriptionLabel;
/**
* Create the composite.
* @param parent The parent of the composite.
- * @param updaterData An instance of {@link UpdaterWindow.UpdaterData}. If null, a local
+ * @param updaterData An instance of {@link UpdaterData}. If null, a local
* one will be allocated just to help with the SWT Designer.
*/
public InstalledPackagesPage(Composite parent, UpdaterData updaterData) {
super(parent, SWT.BORDER);
- mUpdaterData = updaterData != null ? updaterData : new UpdaterWindow.UpdaterData();
+ mUpdaterData = updaterData != null ? updaterData : new UpdaterData();
createContents(this);
}
@@ -77,9 +105,14 @@ public class InstalledPackagesPage extends Composite {
mColumnInstRevision.setWidth(100);
mColumnInstRevision.setText("Revision");
- mInstDescription = new Group(parent, SWT.NONE);
- mInstDescription.setText("Description");
- mInstDescription.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
+ mDescriptionContainer = new Group(parent, SWT.NONE);
+ mDescriptionContainer.setLayout(new GridLayout(1, false));
+ mDescriptionContainer.setText("Description");
+ mDescriptionContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
+
+ mDescriptionLabel = new Label(mDescriptionContainer, SWT.NONE);
+ mDescriptionLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 1, 1));
+ mDescriptionLabel.setText("Line1\nLine2\nLine3");
mInstButtons = new Composite(parent, SWT.NONE);
mInstButtons.setLayout(new GridLayout(5, false));
@@ -143,8 +176,8 @@ public class InstalledPackagesPage extends Composite {
//$hide>>$
protected void onUpdateInstalledPackage() {
- ProgressTask.start(getShell(), "Test", new ThreadTask() {
- public void PerformTask(ITaskMonitor monitor) {
+ ProgressTask.start(getShell(), "Test", new ITask() {
+ public void run(ITaskMonitor monitor) {
monitor.setDescription("Test");
monitor.setProgressMax(100);
int n = 0;
@@ -162,7 +195,6 @@ public class InstalledPackagesPage extends Composite {
});
}
-
// End of hiding from SWT Designer
//$hide<<$
}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/ProgressTask.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ProgressTask.java
index ee768dd..3897096 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/ProgressTask.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ProgressTask.java
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.eclipse.org/org/documents/epl-v10.php
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,10 @@
* limitations under the License.
*/
-package com.android.sdkuilib.repository;
+package com.android.sdkuilib.internal.repository;
+
+import com.android.sdklib.internal.repository.ITask;
+import com.android.sdklib.internal.repository.ITaskMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@@ -30,6 +33,13 @@ import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+/*
+ * TODO:
+ * - trap window.close and treat it as a cancel request
+ * - on cancel as been clicked *and* the task finished,, change it to a "close" button
+ */
+
+
class ProgressTask extends Dialog
implements ITaskMonitor //$hide$ (hide from SWT designer)
{
@@ -72,6 +82,9 @@ class ProgressTask extends Dialog
display.sleep();
}
}
+
+ mCancelRequested = true;
+
if (!mDialogShell.isDisposed()) {
mDialogShell.close();
}
@@ -119,11 +132,7 @@ class ProgressTask extends Dialog
// Hide everything down-below from SWT designer
//$hide>>$
- public interface ThreadTask {
- public abstract void PerformTask(ITaskMonitor monitor);
- }
-
- private ThreadTask mTask;
+ private ITask mTask;
/**
* Creates a new {@link ProgressTask} with the given title.
@@ -131,7 +140,7 @@ class ProgressTask extends Dialog
*
* This blocks till the thread ends.
*/
- public static ProgressTask start(Shell parent, String title, ThreadTask task) {
+ public static ProgressTask start(Shell parent, String title, ITask task) {
ProgressTask t = new ProgressTask(parent);
t.setText(title);
t.setTask(task);
@@ -159,14 +168,16 @@ class ProgressTask extends Dialog
*/
public void setResult(final String result) {
mAutomaticallyCloseOnTaskCompletion = false;
- mDialogShell.getDisplay().asyncExec(new Runnable() {
- public void run() {
- if (!mResultText.isDisposed()) {
- mResultText.setVisible(true);
- mResultText.setText(result);
+ if (!mDialogShell.isDisposed()) {
+ mDialogShell.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ if (!mResultText.isDisposed()) {
+ mResultText.setVisible(true);
+ mResultText.setText(result);
+ }
}
- }
- });
+ });
+ }
}
/**
@@ -176,13 +187,15 @@ class ProgressTask extends Dialog
* @see ProgressBar#setMaximum(int)
*/
public void setProgressMax(final int max) {
- mDialogShell.getDisplay().asyncExec(new Runnable() {
- public void run() {
- if (!mProgressBar.isDisposed()) {
- mProgressBar.setMaximum(max);
+ if (!mDialogShell.isDisposed()) {
+ mDialogShell.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ if (!mProgressBar.isDisposed()) {
+ mProgressBar.setMaximum(max);
+ }
}
- }
- });
+ });
+ }
}
/**
@@ -191,13 +204,15 @@ class ProgressTask extends Dialog
* This method can be invoked from a non-UI thread.
*/
public void incProgress(final int delta) {
- mDialogShell.getDisplay().asyncExec(new Runnable() {
- public void run() {
- if (!mProgressBar.isDisposed()) {
- mProgressBar.setSelection(mProgressBar.getSelection() + delta);
+ if (!mDialogShell.isDisposed()) {
+ mDialogShell.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ if (!mProgressBar.isDisposed()) {
+ mProgressBar.setSelection(mProgressBar.getSelection() + delta);
+ }
}
- }
- });
+ });
+ }
}
/**
@@ -209,12 +224,12 @@ class ProgressTask extends Dialog
}
/** Sets the task that will execute in a separate thread. */
- private void setTask(ThreadTask task) {
+ private void setTask(ITask task) {
mTask = task;
}
/**
- * Starts the task from {@link #setTask(ThreadTask)} in a separate thread.
+ * Starts the task from {@link #setTask(ITask)} in a separate thread.
* When the task completes, set {@link #mCloseRequested} to end the dialog loop.
*/
private void startTask() {
@@ -222,7 +237,7 @@ class ProgressTask extends Dialog
new Thread(getText()) {
@Override
public void run() {
- mTask.PerformTask(ProgressTask.this);
+ mTask.run(ProgressTask.this);
if (mAutomaticallyCloseOnTaskCompletion) {
mCloseRequested = true;
}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ProgressTaskFactory.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ProgressTaskFactory.java
new file mode 100755
index 0000000..ceb701e
--- /dev/null
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/ProgressTaskFactory.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdkuilib.internal.repository;
+
+import com.android.sdklib.internal.repository.ITask;
+import com.android.sdklib.internal.repository.ITaskFactory;
+
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * An {@link ITaskFactory} that creates a new {@link ProgressTask} dialog
+ * for each new task.
+ */
+public class ProgressTaskFactory implements ITaskFactory {
+
+ private final Shell mShell;
+
+ public ProgressTaskFactory(Shell shell) {
+ mShell = shell;
+ }
+
+ public void start(String title, ITask task) {
+ ProgressTask.start(mShell, title, task);
+ }
+}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/RepoSources.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/RepoSources.java
index c06e16d..42ab5b2 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/RepoSources.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/RepoSources.java
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.eclipse.org/org/documents/epl-v10.php
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,7 +14,11 @@
* limitations under the License.
*/
-package com.android.sdkuilib.repository;
+package com.android.sdkuilib.internal.repository;
+
+import com.android.sdklib.internal.repository.IDescription;
+import com.android.sdklib.internal.repository.ITaskFactory;
+import com.android.sdklib.internal.repository.RepoSource;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
@@ -22,23 +26,24 @@ import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Shell;
import java.util.ArrayList;
/**
+ * A list of sdk-repository sources.
*
+ * This implementation is UI dependent.
*/
class RepoSources {
- private Shell mShell;
private ArrayList<RepoSource> mSources = new ArrayList<RepoSource>();
+ private ITaskFactory mTaskFactory;
public RepoSources() {
}
- public void setShell(Shell shell) {
- mShell = shell;
+ public void setTaskFactory(ITaskFactory taskFactory) {
+ mTaskFactory = taskFactory;
}
public void add(RepoSource source) {
@@ -66,6 +71,9 @@ class RepoSources {
/** Returns the toString of the element. */
@Override
public String getText(Object element) {
+ if (element instanceof IDescription) {
+ return ((IDescription) element).getShortDescription();
+ }
return super.getText(element);
}
}
@@ -112,7 +120,7 @@ class RepoSources {
ArrayList<String> pkgs = source.getPackages();
if (pkgs == null) {
- source.load(mShell);
+ source.load(mTaskFactory);
pkgs = source.getPackages();
}
if (pkgs != null) {
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java
new file mode 100755
index 0000000..920769b
--- /dev/null
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdkuilib.internal.repository;
+
+/**
+ * Data shared between {@link UpdaterWindowImpl} and its pages.
+ */
+class UpdaterData {
+ private String mOsSdkRoot;
+ private boolean mUserCanChangeSdkRoot;
+ private RepoSources mSources = new RepoSources();
+
+ public void setOsSdkRoot(String osSdkRoot) {
+ mOsSdkRoot = osSdkRoot;
+ }
+
+ public String getOsSdkRoot() {
+ return mOsSdkRoot;
+ }
+
+ public void setUserCanChangeSdkRoot(boolean userCanChangeSdkRoot) {
+ mUserCanChangeSdkRoot = userCanChangeSdkRoot;
+ }
+
+ public boolean canUserChangeSdkRoot() {
+ return mUserCanChangeSdkRoot;
+ }
+
+ public void setSources(RepoSources sources) {
+ mSources = sources;
+ }
+
+ public RepoSources getSources() {
+ return mSources;
+ }
+
+}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterWindowImpl.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterWindowImpl.java
new file mode 100755
index 0000000..50ebdb6
--- /dev/null
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterWindowImpl.java
@@ -0,0 +1,223 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdkuilib.internal.repository;
+
+
+import com.android.sdklib.internal.repository.RepoSource;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTException;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.custom.StackLayout;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Shell;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+
+/**
+ * This is the private implementation of the UpdateWindow.
+ */
+public class UpdaterWindowImpl {
+
+ private final UpdaterData mUpdaterData = new UpdaterData();
+ private ArrayList<Composite> mPages = new ArrayList<Composite>();
+ private boolean mInternalPageChange;
+
+ // --- UI members ---
+
+ protected Shell mAndroidSdkUpdater;
+ private SashForm mSashForm;
+ private List mPageList;
+ private Composite mPagesRootComposite;
+ private InstalledPackagesPage mInstalledPackagePage;
+ private AvailablePackagesPage mAvailablePackagesPage;
+ private StackLayout mStackLayout;
+ private Image mIconImage;
+
+ public UpdaterWindowImpl(String osSdkRoot, boolean userCanChangeSdkRoot) {
+ mUpdaterData.setOsSdkRoot(osSdkRoot);
+ mUpdaterData.setUserCanChangeSdkRoot(userCanChangeSdkRoot);
+ }
+
+ /**
+ * Open the window.
+ * @wbp.parser.entryPoint
+ */
+ public void open() {
+ Display display = Display.getDefault();
+ createContents();
+ mAndroidSdkUpdater.open();
+ mAndroidSdkUpdater.layout();
+
+ firstInit(); //$hide$ (hide from SWT designer)
+
+ while (!mAndroidSdkUpdater.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ }
+
+ /**
+ * Create contents of the window.
+ */
+ protected void createContents() {
+ mAndroidSdkUpdater = new Shell();
+ setWindowImage(mAndroidSdkUpdater);
+ mAndroidSdkUpdater.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ onAndroidSdkUpdaterDispose(); //$hide$ (hide from SWT designer)
+ }
+ });
+
+ mAndroidSdkUpdater.setLayout(new FillLayout(SWT.HORIZONTAL));
+ mAndroidSdkUpdater.setMinimumSize(new Point(200, 50));
+ mAndroidSdkUpdater.setSize(745, 433);
+ mAndroidSdkUpdater.setText("Android SDK Updater");
+
+ mSashForm = new SashForm(mAndroidSdkUpdater, SWT.NONE);
+
+ mPageList = new List(mSashForm, SWT.BORDER);
+ mPageList.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ onPageListSelected(); //$hide$ (hide from SWT designer)
+ }
+ });
+
+ mPagesRootComposite = new Composite(mSashForm, SWT.NONE);
+ mStackLayout = new StackLayout();
+ mPagesRootComposite.setLayout(mStackLayout);
+
+ mInstalledPackagePage = new InstalledPackagesPage(mPagesRootComposite, mUpdaterData);
+ mAvailablePackagesPage = new AvailablePackagesPage(mPagesRootComposite, mUpdaterData);
+ mSashForm.setWeights(new int[] {150, 576});
+ }
+
+
+ // -- Start of internal part ----------
+ // Hide everything down-below from SWT designer
+ //$hide>>$
+
+ // --- UI Callbacks -----------
+
+ private void onAndroidSdkUpdaterDispose() {
+ if (mIconImage != null) {
+ mIconImage.dispose();
+ mIconImage = null;
+ }
+ }
+
+ private void setWindowImage(Shell androidSdkUpdater) {
+ InputStream stream = getClass().getResourceAsStream("android_icon_16.png"); //$NON-NLS-1$
+ if (stream != null) {
+ try {
+ ImageData imgData = new ImageData(stream);
+ mIconImage = new Image(mAndroidSdkUpdater.getDisplay(),
+ imgData,
+ imgData.getTransparencyMask());
+ mAndroidSdkUpdater.setImage(mIconImage);
+ } catch (SWTException e) {
+ // ignore
+ } catch (IllegalArgumentException e) {
+ // ignore
+ }
+ }
+ }
+
+ private Shell getShell() {
+ return mAndroidSdkUpdater;
+ }
+
+ /**
+ * Once the UI has been created, initialize the content
+ */
+ private void firstInit() {
+ addPage(mInstalledPackagePage, "Installed Packages");
+ addPage(mAvailablePackagesPage, "Available Packages");
+ displayPage(0);
+ mPageList.setSelection(0);
+
+ setupSources();
+ scanLocalSdkFolders();
+ }
+
+ // --- page switching ---
+
+ private void addPage(Composite page, String title) {
+ page.setData(title);
+ mPages.add(page);
+ mPageList.add(title);
+ }
+
+ private void onPageListSelected() {
+ if (mInternalPageChange == false) {
+ int index = mPageList.getSelectionIndex();
+ if (index >= 0) {
+ displayPage(index);
+ }
+ }
+ }
+
+ private void displayPage(int index) {
+ Composite page = mPages.get(index);
+ if (page != null) {
+ mStackLayout.topControl = page;
+ mPagesRootComposite.layout(true);
+
+ if (!mInternalPageChange) {
+ mInternalPageChange = true;
+ mPageList.setSelection(index);
+ mInternalPageChange = false;
+ }
+ }
+ }
+
+ private void setupSources() {
+ mUpdaterData.getSources().setTaskFactory(new ProgressTaskFactory(getShell()));
+
+ mUpdaterData.getSources().add(new RepoSource(
+ "https://dl.google.com/android/eclipse/repository/index.xml", //$NON-NLS-1$
+ false /* addonOnly */));
+
+ String url = System.getenv("TEMP_SDK_URL"); // TODO STOPSHIP temporary remove before shipping
+ if (url != null) {
+ mUpdaterData.getSources().add(new RepoSource(url, false /* addonOnly */));
+ }
+
+ mAvailablePackagesPage.setInput(mUpdaterData.getSources());
+ }
+
+ private void scanLocalSdkFolders() {
+ // TODO Auto-generated method stub
+
+ }
+
+ // End of hiding from SWT Designer
+ //$hide<<$
+}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/android_icon_16.png b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/android_icon_16.png
index 0b0744b..0b0744b 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/android_icon_16.png
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/android_icon_16.png
Binary files differ
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/AvailablePackagesPage.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/AvailablePackagesPage.java
deleted file mode 100755
index 7c4565a..0000000
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/AvailablePackagesPage.java
+++ /dev/null
@@ -1,116 +0,0 @@
-package com.android.sdkuilib.repository;
-
-import com.android.sdkuilib.repository.UpdaterWindow.UpdaterData;
-
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeColumn;
-
-class AvailablePackagesPage extends Composite {
-
- private final UpdaterData mUpdaterData;
-
- private CheckboxTreeViewer mTreeViewAvailPkg;
- private Tree mTreeAvailPkg;
- private TreeColumn mColumnAvailSummary;
- private TreeColumn mColumnAvailApiLevel;
- private TreeColumn mColumnAvailRevision;
- private TreeColumn mColumnAvailOs;
- private TreeColumn mColumnAvailInstalled;
- private Group mAvailDescription;
- private Button mAvailAddSite;
- private Button mAvailRemoveSite;
- private Label mPlaceholder3;
- private Button mAvailRefresh;
- private Button mAvailInstallSelected;
-
-
- /**
- * Create the composite.
- * @param parent The parent of the composite.
- * @param updaterData An instance of {@link UpdaterWindow.UpdaterData}. If null, a local
- * one will be allocated just to help with the SWT Designer.
- */
- public AvailablePackagesPage(Composite parent, UpdaterData updaterData) {
- super(parent, SWT.BORDER);
-
- mUpdaterData = updaterData != null ? updaterData : new UpdaterWindow.UpdaterData();
-
- createContents(this);
- }
-
- private void createContents(Composite parent) {
- parent.setLayout(new GridLayout(5, false));
-
- mTreeViewAvailPkg = new CheckboxTreeViewer(parent, SWT.BORDER);
- mTreeViewAvailPkg.setContentProvider(mUpdaterData.getSources().getContentProvider());
- mTreeViewAvailPkg.setLabelProvider(mUpdaterData.getSources().getLabelProvider());
- mTreeAvailPkg = mTreeViewAvailPkg.getTree();
- mTreeAvailPkg.setHeaderVisible(true);
- mTreeAvailPkg.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
-
- mColumnAvailSummary = new TreeColumn(mTreeAvailPkg, SWT.NONE);
- mColumnAvailSummary.setWidth(289);
- mColumnAvailSummary.setText("Summary");
-
- mColumnAvailApiLevel = new TreeColumn(mTreeAvailPkg, SWT.NONE);
- mColumnAvailApiLevel.setWidth(66);
- mColumnAvailApiLevel.setText("API Level");
-
- mColumnAvailRevision = new TreeColumn(mTreeAvailPkg, SWT.NONE);
- mColumnAvailRevision.setWidth(63);
- mColumnAvailRevision.setText("Revision");
-
- mColumnAvailOs = new TreeColumn(mTreeAvailPkg, SWT.NONE);
- mColumnAvailOs.setWidth(100);
- mColumnAvailOs.setText("OS/Arch");
-
- mColumnAvailInstalled = new TreeColumn(mTreeAvailPkg, SWT.NONE);
- mColumnAvailInstalled.setWidth(59);
- mColumnAvailInstalled.setText("Installed");
-
- mAvailDescription = new Group(parent, SWT.NONE);
- mAvailDescription.setText("Description");
- mAvailDescription.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 5, 1));
-
- mAvailAddSite = new Button(parent, SWT.NONE);
- mAvailAddSite.setText("Add Site...");
-
- mAvailRemoveSite = new Button(parent, SWT.NONE);
- mAvailRemoveSite.setText("Delete Site...");
-
- mPlaceholder3 = new Label(parent, SWT.NONE);
- mPlaceholder3.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
-
- mAvailRefresh = new Button(parent, SWT.NONE);
- mAvailRefresh.setText("Refresh");
-
- mAvailInstallSelected = new Button(parent, SWT.NONE);
- mAvailInstallSelected.setText("Install Selected");
- }
-
- @Override
- protected void checkSubclass() {
- // Disable the check that prevents subclassing of SWT components
- }
-
- // -- Start of internal part ----------
- // Hide everything down-below from SWT designer
- //$hide>>$
-
- public void setInput(RepoSources sources) {
- mTreeViewAvailPkg.setInput(sources);
- }
-
-
- // End of hiding from SWT Designer
- //$hide<<$
-
-}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/UpdaterWindow.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/UpdaterWindow.java
index a9f5cdd..0d067ae 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/UpdaterWindow.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/UpdaterWindow.java
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.eclipse.org/org/documents/epl-v10.php
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,230 +16,31 @@
package com.android.sdkuilib.repository;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.custom.SashForm;
-import org.eclipse.swt.custom.StackLayout;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.List;
-import org.eclipse.swt.widgets.Shell;
-
-import java.io.InputStream;
-import java.util.ArrayList;
+import com.android.sdkuilib.internal.repository.UpdaterWindowImpl;
+/**
+ * Opens an SDK Updater Window.
+ *
+ * This is the public interface for using the window.
+ */
public class UpdaterWindow {
- static class UpdaterData {
- private String mOsSdkRoot;
- private boolean mUserCanChangeSdkRoot;
- private RepoSources mSources = new RepoSources();
-
- public void setOsSdkRoot(String osSdkRoot) {
- mOsSdkRoot = osSdkRoot;
- }
-
- public String getOsSdkRoot() {
- return mOsSdkRoot;
- }
-
- public void setUserCanChangeSdkRoot(boolean userCanChangeSdkRoot) {
- mUserCanChangeSdkRoot = userCanChangeSdkRoot;
- }
-
- public boolean canUserChangeSdkRoot() {
- return mUserCanChangeSdkRoot;
- }
-
- public void setSources(RepoSources sources) {
- mSources = sources;
- }
-
- public RepoSources getSources() {
- return mSources;
- }
- }
-
- private final UpdaterData mUpdaterData = new UpdaterData();
- private ArrayList<Composite> mPages = new ArrayList<Composite>();
- private boolean mInternalPageChange;
-
- // --- UI members ---
-
- protected Shell mAndroidSdkUpdater;
- private SashForm mSashForm;
- private List mPageList;
- private Composite mPagesRootComposite;
- private InstalledPackagesPage mInstalledPackagePage;
- private AvailablePackagesPage mAvailablePackagesPage;
- private StackLayout mStackLayout;
- private Image mIconImage;
-
- public UpdaterWindow(String osSdkRoot, boolean userCanChangeSdkRoot) {
- mUpdaterData.setOsSdkRoot(osSdkRoot);
- mUpdaterData.setUserCanChangeSdkRoot(userCanChangeSdkRoot);
- }
-
- /**
- * Open the window.
- * @wbp.parser.entryPoint
- */
- public void open() {
- Display display = Display.getDefault();
- createContents();
- mAndroidSdkUpdater.open();
- mAndroidSdkUpdater.layout();
-
- firstInit(); //$hide$ (hide from SWT designer)
-
- while (!mAndroidSdkUpdater.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
- }
+ private UpdaterWindowImpl mWindow;
/**
- * Create contents of the window.
+ * Creates a new window. Caller must call open(), which will block.
+ * @param osSdkRoot The OS path to the SDK root.
+ * @param userCanChangeSdkRoot If true, the window lets the user change the SDK path
+ * being browsed.
*/
- protected void createContents() {
- mAndroidSdkUpdater = new Shell();
- setWindowImage(mAndroidSdkUpdater);
- mAndroidSdkUpdater.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- onAndroidSdkUpdaterDispose(); //$hide$ (hide from SWT designer)
- }
- });
-
- mAndroidSdkUpdater.setLayout(new FillLayout(SWT.HORIZONTAL));
- mAndroidSdkUpdater.setMinimumSize(new Point(200, 50));
- mAndroidSdkUpdater.setSize(745, 433);
- mAndroidSdkUpdater.setText("Android SDK Updater");
-
- mSashForm = new SashForm(mAndroidSdkUpdater, SWT.NONE);
-
- mPageList = new List(mSashForm, SWT.BORDER);
- mPageList.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- onPageListSelected(e); //$hide$ (hide from SWT designer)
- }
- });
-
- mPagesRootComposite = new Composite(mSashForm, SWT.NONE);
- mStackLayout = new StackLayout();
- mPagesRootComposite.setLayout(mStackLayout);
-
- mInstalledPackagePage = new InstalledPackagesPage(mPagesRootComposite, mUpdaterData);
- mAvailablePackagesPage = new AvailablePackagesPage(mPagesRootComposite, mUpdaterData);
- mSashForm.setWeights(new int[] {150, 576});
- }
-
-
- // -- Start of internal part ----------
- // Hide everything down-below from SWT designer
- //$hide>>$
-
- // --- UI Callbacks -----------
-
- private void onAndroidSdkUpdaterDispose() {
- if (mIconImage != null) {
- mIconImage.dispose();
- mIconImage = null;
- }
- }
-
- private void setWindowImage(Shell androidSdkUpdater) {
- InputStream stream = getClass().getResourceAsStream("android_icon_16.png"); //$NON-NLS-1$
- if (stream != null) {
- try {
- ImageData imgData = new ImageData(stream);
- mIconImage = new Image(mAndroidSdkUpdater.getDisplay(),
- imgData,
- imgData.getTransparencyMask());
- mAndroidSdkUpdater.setImage(mIconImage);
- } catch (SWTException e) {
- // ignore
- } catch (IllegalArgumentException e) {
- // ignore
- }
- }
- }
-
- private Shell getShell() {
- return mAndroidSdkUpdater;
+ public UpdaterWindow(String osSdkRoot, boolean userCanChangeSdkRoot) {
+ mWindow = new UpdaterWindowImpl(osSdkRoot, userCanChangeSdkRoot);
}
/**
- * Once the UI has been created, initialize the content
+ * Opens the window.
*/
- private void firstInit() {
- addPage(mInstalledPackagePage, "Installed Packages");
- addPage(mAvailablePackagesPage, "Available Packages");
- displayPage(0);
- mPageList.setSelection(0);
-
- setupSources();
- scanLocalSdkFolders();
- }
-
- // --- page switching ---
-
- private void addPage(Composite page, String title) {
- page.setData(title);
- mPages.add(page);
- mPageList.add(title);
- }
-
- private void onPageListSelected(SelectionEvent e) {
- if (mInternalPageChange == false) {
- int index = mPageList.getSelectionIndex();
- if (index >= 0) {
- displayPage(index);
- }
- }
- }
-
- private void displayPage(int index) {
- Composite page = mPages.get(index);
- if (page != null) {
- mStackLayout.topControl = page;
- mPagesRootComposite.layout(true);
-
- if (!mInternalPageChange) {
- mInternalPageChange = true;
- mPageList.setSelection(index);
- mInternalPageChange = false;
- }
- }
- }
-
- private void setupSources() {
- mUpdaterData.getSources().setShell(getShell());
-
- mUpdaterData.getSources().add(new RepoSource(
- "https://dl.google.com/android/eclipse/repository/index.xml", //$NON-NLS-1$
- false /* addonOnly */));
- mUpdaterData.getSources().add(new RepoSource(
- "http://www.corp.google.com/~raphael/android/sdk-repo/repository.xml", //$NON-NLS-1$
- false /* addonOnly */));
-
- mAvailablePackagesPage.setInput(mUpdaterData.getSources());
- }
-
- private void scanLocalSdkFolders() {
- // TODO Auto-generated method stub
-
+ public void open() {
+ mWindow.open();
}
-
- // End of hiding from SWT Designer
- //$hide<<$
}