aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/libs/sdkuilib
diff options
context:
space:
mode:
authorRaphael <raphael@google.com>2011-11-15 10:05:13 -0800
committerRaphael <raphael@google.com>2011-11-15 10:13:30 -0800
commit6061d45273ed1eca26b42f2297277f3a77a59c2a (patch)
tree398b532f1ba0ea3d1bf30fc77c1a19f4951e2cc7 /sdkmanager/libs/sdkuilib
parente9a704c522ae46b5f2a395d3d4d8d51aba043764 (diff)
downloadsdk-6061d45273ed1eca26b42f2297277f3a77a59c2a.zip
sdk-6061d45273ed1eca26b42f2297277f3a77a59c2a.tar.gz
sdk-6061d45273ed1eca26b42f2297277f3a77a59c2a.tar.bz2
SDK Manager: remove obsolete sdkamn v1 window.
This removes the SDK Manager 1 window implementation. There are still a few odds and ends that require some cleanup for later, e.g. the "update chooser dialog" but it actually needs a revamp rather than just a cleanup. Change-Id: Icb90fd1f5d9d8ca4b1ffeea72b8c20aed12cbe26
Diffstat (limited to 'sdkmanager/libs/sdkuilib')
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java21
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/icons/ImageFactory.java12
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/LocalPackagesPage.java310
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/LocalSdkAdapter.java110
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/RemotePackagesPage.java501
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/RepoSourcesAdapter.java367
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/SdkUpdaterWindowImpl1.java469
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/SdkUpdaterWindow.java9
8 files changed, 9 insertions, 1790 deletions
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
index d6c6f98..6643dca 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java
@@ -48,10 +48,7 @@ import com.android.sdklib.repository.SdkRepoConstants;
import com.android.sdklib.util.LineUtil;
import com.android.sdklib.util.SparseIntArray;
import com.android.sdkuilib.internal.repository.icons.ImageFactory;
-import com.android.sdkuilib.internal.repository.sdkman1.LocalSdkAdapter;
-import com.android.sdkuilib.internal.repository.sdkman1.RemotePackagesPage;
-import com.android.sdkuilib.internal.repository.sdkman1.RepoSourcesAdapter;
-import com.android.sdkuilib.internal.repository.sdkman1.SdkUpdaterWindowImpl1;
+import com.android.sdkuilib.internal.repository.sdkman2.SdkUpdaterWindowImpl2;
import com.android.sdkuilib.repository.ISdkChangeListener;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -71,7 +68,7 @@ import java.util.Map;
import java.util.Set;
/**
- * Data shared between {@link SdkUpdaterWindowImpl1} and its pages.
+ * Data shared between {@link SdkUpdaterWindowImpl2} and its pages.
*/
public class UpdaterData implements IUpdaterData {
@@ -90,9 +87,6 @@ public class UpdaterData implements IUpdaterData {
private final LocalSdkParser mLocalSdkParser = new LocalSdkParser();
private final SdkSources mSources = new SdkSources();
- private final LocalSdkAdapter mLocalSdkAdapter = new LocalSdkAdapter(this);
- private final RepoSourcesAdapter mSourcesAdapter = new RepoSourcesAdapter(this);
-
private ImageFactory mImageFactory;
private final SettingsController mSettingsController;
@@ -144,18 +138,10 @@ public class UpdaterData implements IUpdaterData {
return mSources;
}
- public RepoSourcesAdapter getSourcesAdapter() {
- return mSourcesAdapter;
- }
-
public LocalSdkParser getLocalSdkParser() {
return mLocalSdkParser;
}
- public LocalSdkAdapter getLocalSdkAdapter() {
- return mLocalSdkAdapter;
- }
-
public ISdkLog getSdkLog() {
return mSdkLog;
}
@@ -317,9 +303,6 @@ public class UpdaterData implements IUpdaterData {
* - the user sources from prefs <br/>
* - the extra repo URLs from the environment, <br/>
* - and finally the extra user repo URLs from the environment.
- * <p/>
- * Note that the "remote add-ons" list is not loaded from here. Instead
- * it is fetched the first time the {@link RemotePackagesPage} is displayed.
*/
public void setupDefaultSources() {
SdkSources sources = getSources();
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/icons/ImageFactory.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/icons/ImageFactory.java
index fbd5047..03b5a5b 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/icons/ImageFactory.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/icons/ImageFactory.java
@@ -20,7 +20,6 @@ import com.android.sdklib.internal.repository.Archive;
import com.android.sdklib.internal.repository.Package;
import com.android.sdklib.internal.repository.SdkSource;
import com.android.sdklib.internal.repository.SdkSourceCategory;
-import com.android.sdkuilib.internal.repository.sdkman1.RepoSourcesAdapter;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.graphics.Image;
@@ -113,11 +112,12 @@ public class ImageFactory {
} else if (object instanceof SdkSource) {
return getImageByName("source_icon16.png"); //$NON-NLS-1$
- } else if (object instanceof RepoSourcesAdapter.RepoSourceError) {
- return getImageByName("error_icon16.png"); //$NON-NLS-1$
-
- } else if (object instanceof RepoSourcesAdapter.RepoSourceEmpty) {
- return getImageByName("nopkg_icon16.png"); //$NON-NLS-1$
+ // TODO reintroduce this in SDK Manager 2 in repository view
+ // } else if (object instanceof RepoSourcesAdapter.RepoSourceError) {
+ // return getImageByName("error_icon16.png"); //$NON-NLS-1$
+ //
+ // } else if (object instanceof RepoSourcesAdapter.RepoSourceEmpty) {
+ // return getImageByName("nopkg_icon16.png"); //$NON-NLS-1$
}
if (object instanceof Archive) {
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/LocalPackagesPage.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/LocalPackagesPage.java
deleted file mode 100755
index 4858f9a..0000000
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/LocalPackagesPage.java
+++ /dev/null
@@ -1,310 +0,0 @@
-/*
- * 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.sdkman1;
-
-import com.android.sdklib.internal.repository.Archive;
-import com.android.sdklib.internal.repository.IDescription;
-import com.android.sdklib.internal.repository.Package;
-import com.android.sdkuilib.internal.repository.UpdaterData;
-import com.android.sdkuilib.internal.repository.UpdaterPage;
-import com.android.sdkuilib.repository.ISdkChangeListener;
-
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ControlAdapter;
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Rectangle;
-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.Table;
-import org.eclipse.swt.widgets.TableColumn;
-
-import java.io.File;
-
-/**
- * Page that displays all locally installed packages from the current SDK.
- */
-public class LocalPackagesPage extends UpdaterPage implements ISdkChangeListener {
-
- private final UpdaterData mUpdaterData;
-
- private Label mSdkLocLabel;
- private TableViewer mTableViewerPackages;
- private Table mTablePackages;
- private TableColumn mColumnPackages;
- private Group mDescriptionContainer;
- private Composite mContainerButtons;
- private Button mUpdateButton;
- private Label mPlaceholder1;
- private Button mDeleteButton;
- private Label mPlaceholder2;
- private Button mRefreshButton;
- private Label mDescriptionLabel;
-
-
- /**
- * Create the composite.
- * @param parent The parent of the composite.
- * @param updaterData An instance of {@link UpdaterData}.
- */
- public LocalPackagesPage(Composite parent, int swtStyle, UpdaterData updaterData) {
- super(parent, swtStyle);
-
- mUpdaterData = updaterData;
-
- createContents(this);
- postCreate(); //$hide$
- }
-
- private void createContents(Composite parent) {
- parent.setLayout(new GridLayout(3, false));
-
- mSdkLocLabel = new Label(parent, SWT.NONE);
- mSdkLocLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false, 3, 1));
- mSdkLocLabel.setText("SDK Location: " +
- (mUpdaterData.getOsSdkRoot() != null ? mUpdaterData.getOsSdkRoot()
- : "<unknown>"));
-
- mTableViewerPackages = new TableViewer(parent, SWT.BORDER | SWT.FULL_SELECTION);
- mTablePackages = mTableViewerPackages.getTable();
- mTablePackages.setHeaderVisible(true);
- mTablePackages.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
- mTablePackages.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- onTreeSelected(); //$hide$
- }
- });
-
- mColumnPackages = new TableColumn(mTablePackages, SWT.NONE);
- mColumnPackages.setWidth(377);
- mColumnPackages.setText("Installed packages");
-
- 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");
-
- mContainerButtons = new Composite(parent, SWT.NONE);
- mContainerButtons.setLayout(new GridLayout(5, false));
- mContainerButtons.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
-
- mUpdateButton = new Button(mContainerButtons, SWT.NONE);
- mUpdateButton.setText("Update All...");
- mUpdateButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- onUpdateSelected(); //$hide$ (hide from SWT designer)
- }
- });
-
- mPlaceholder1 = new Label(mContainerButtons, SWT.NONE);
- mPlaceholder1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
-
- mDeleteButton = new Button(mContainerButtons, SWT.NONE);
- mDeleteButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
- mDeleteButton.setText("Delete...");
- mDeleteButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- onDeleteSelected(); //$hide$ (hide from SWT designer)
- }
- });
-
- mPlaceholder2 = new Label(mContainerButtons, SWT.NONE);
- mPlaceholder2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
-
- mRefreshButton = new Button(mContainerButtons, SWT.NONE);
- mRefreshButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- mRefreshButton.setText("Refresh");
- mRefreshButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- onRefreshSelected(); //$hide$ (hide from SWT designer)
- }
- });
- }
-
- @Override
- public void dispose() {
- mUpdaterData.removeListener(this);
- super.dispose();
- }
-
- @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>>$
-
- /**
- * Called by the constructor right after {@link #createContents(Composite)}.
- */
- private void postCreate() {
- mUpdaterData.addListeners(this);
- adjustColumnsWidth();
- updateButtonsState();
- }
-
- /**
- * Adds a listener to adjust the columns width when the parent is resized.
- * <p/>
- * If we need something more fancy, we might want to use this:
- * http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet77.java?view=co
- */
- private void adjustColumnsWidth() {
- // Add a listener to resize the column to the full width of the table
- ControlAdapter resizer = new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent e) {
- Rectangle r = mTablePackages.getClientArea();
- mColumnPackages.setWidth(r.width);
- }
- };
- mTablePackages.addControlListener(resizer);
- resizer.controlResized(null);
- }
-
- /**
- * Enable or disable buttons depending on list content and selection
- */
- private void updateButtonsState() {
- ISelection sel = mTableViewerPackages.getSelection();
- boolean hasSelection = sel != null && !sel.isEmpty();
-
- mUpdateButton.setEnabled(mTablePackages.getItemCount() > 0);
- mDeleteButton.setEnabled(hasSelection);
- mRefreshButton.setEnabled(true);
- }
-
- /**
- * Called when an item in the package table viewer is selected.
- * If the items is an {@link IDescription} (as it should), this will display its long
- * description in the description area. Otherwise when the item is not of the expected
- * type or there is no selection, it empties the description area.
- */
- private void onTreeSelected() {
- updateButtonsState();
-
- ISelection sel = mTableViewerPackages.getSelection();
- if (sel instanceof IStructuredSelection) {
- Object elem = ((IStructuredSelection) sel).getFirstElement();
- if (elem instanceof IDescription) {
- mDescriptionLabel.setText(((IDescription) elem).getLongDescription());
- mDescriptionContainer.layout(true);
- return;
- }
- }
- mDescriptionLabel.setText(""); //$NON-NLS1-$
- }
-
- /** User selected the 'update all' button. */
- private void onUpdateSelected() {
- mUpdaterData.updateOrInstallAll_WithGUI(
- null /*selectedArchives*/,
- false /* includeObsoletes */,
- 0 /* flags */);
- }
-
- private void onDeleteSelected() {
- ISelection sel = mTableViewerPackages.getSelection();
- if (sel instanceof IStructuredSelection) {
- Object elem = ((IStructuredSelection) sel).getFirstElement();
- if (elem instanceof Package) {
-
- String title = "Delete SDK Package";
- String error = null;
-
- Package p = (Package) elem;
- Archive[] archives = p.getArchives();
- if (archives.length == 1 && archives[0] != null && archives[0].isLocal()) {
- Archive archive = archives[0];
- String osPath = archive.getLocalOsPath();
-
- File dir = new File(osPath);
- if (dir.isDirectory()) {
- String msg = String.format("Are you sure you want to delete '%1$s' at '%2$s'? This cannot be undone.",
- p.getShortDescription(), osPath);
-
- if (MessageDialog.openQuestion(getShell(), title, msg)) {
- archive.deleteLocal();
-
- // refresh list
- onRefreshSelected();
- }
- } else {
- error = "Directory not found for this package";
- }
- } else {
- error = "No local archive found for this package";
- }
-
- if (error != null) {
- MessageDialog.openError(getShell(), title, error);
- }
-
- return;
- }
- }
- }
-
- private void onRefreshSelected() {
- mUpdaterData.reloadSdk();
- updateButtonsState();
- }
-
- // --- Implementation of ISdkChangeListener ---
-
- public void onSdkLoaded() {
- onSdkReload();
- }
-
- public void onSdkReload() {
- LocalSdkAdapter localSdkAdapter = mUpdaterData.getLocalSdkAdapter();
- mTableViewerPackages.setLabelProvider( localSdkAdapter.getLabelProvider());
- mTableViewerPackages.setContentProvider(localSdkAdapter.getContentProvider());
- mTableViewerPackages.setInput(localSdkAdapter);
- onTreeSelected();
- }
-
- public void preInstallHook() {
- // nothing to be done for now.
- }
-
- public void postInstallHook() {
- // nothing to be done for now.
- }
-
- // End of hiding from SWT Designer
- //$hide<<$
-}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/LocalSdkAdapter.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/LocalSdkAdapter.java
deleted file mode 100755
index b018918..0000000
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/LocalSdkAdapter.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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.sdkman1;
-
-import com.android.sdklib.internal.repository.IDescription;
-import com.android.sdklib.internal.repository.NullTaskMonitor;
-import com.android.sdklib.internal.repository.Package;
-import com.android.sdklib.internal.repository.SdkSource;
-import com.android.sdkuilib.internal.repository.UpdaterData;
-import com.android.sdkuilib.internal.repository.icons.ImageFactory;
-
-import org.eclipse.jface.viewers.IContentProvider;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * Table adapters to use the local SDK list.
- */
-public class LocalSdkAdapter {
-
- private final UpdaterData mUpdaterData;
-
- public LocalSdkAdapter(UpdaterData updaterData) {
- mUpdaterData = updaterData;
- }
-
- public ILabelProvider getLabelProvider() {
- return new ViewerLabelProvider();
- }
-
-
- public IContentProvider getContentProvider() {
- return new TableContentProvider();
- }
-
- // ------------
-
- public class ViewerLabelProvider extends LabelProvider {
- /** Returns an image appropriate for this element. */
- @Override
- public Image getImage(Object element) {
- ImageFactory imgFactory = mUpdaterData.getImageFactory();
-
- if (imgFactory != null) {
- return imgFactory.getImageForObject(element);
- }
-
- return super.getImage(element);
- }
-
- /** Returns the toString of the element. */
- @Override
- public String getText(Object element) {
- if (element instanceof IDescription) {
- return ((IDescription) element).getShortDescription();
- }
- return super.getText(element);
- }
- }
-
- // ------------
-
- private class TableContentProvider implements IStructuredContentProvider {
-
- // Called when the viewer is disposed
- public void dispose() {
- // pass
- }
-
- // Called when the input is set or changed on the provider
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- /**
- * Called to collect the root elements for the given input.
- * The input here is a {@link LocalSdkAdapter} object, this returns an array
- * of {@link SdkSource}.
- */
- public Object[] getElements(Object inputElement) {
- if (inputElement == LocalSdkAdapter.this) {
- Package[] packages = mUpdaterData.getInstalledPackages(
- new NullTaskMonitor(mUpdaterData.getSdkLog()));
-
- if (packages != null) {
- return packages;
- }
- }
-
- return new Object[0];
- }
- }
-
-}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/RemotePackagesPage.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/RemotePackagesPage.java
deleted file mode 100755
index 9e157cb..0000000
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/RemotePackagesPage.java
+++ /dev/null
@@ -1,501 +0,0 @@
-/*
- * 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.sdkman1;
-
-
-import com.android.sdklib.internal.repository.Archive;
-import com.android.sdklib.internal.repository.IDescription;
-import com.android.sdklib.internal.repository.Package;
-import com.android.sdklib.internal.repository.SdkAddonSource;
-import com.android.sdklib.internal.repository.SdkSource;
-import com.android.sdklib.internal.repository.SdkSourceCategory;
-import com.android.sdkuilib.internal.repository.SettingsController;
-import com.android.sdkuilib.internal.repository.UpdaterData;
-import com.android.sdkuilib.internal.repository.UpdaterPage;
-import com.android.sdkuilib.repository.ISdkChangeListener;
-
-import org.eclipse.jface.dialogs.IInputValidator;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.ITreeSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ControlAdapter;
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Rectangle;
-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;
-
-import java.util.ArrayList;
-
-/**
- * Page that displays remote repository & add-ons sources and let the user
- * select packages for installation.
- */
-public class RemotePackagesPage extends UpdaterPage implements ISdkChangeListener {
-
- private final UpdaterData mUpdaterData;
-
- private CheckboxTreeViewer mTreeViewerSources;
- private Tree mTreeSources;
- private TreeColumn mColumnSource;
- private Button mUpdateOnlyCheckBox;
- private Group mDescriptionContainer;
- private Button mAddSiteButton;
- private Button mDeleteSiteButton;
- private Button mRefreshButton;
- private Button mInstallSelectedButton;
- private Label mDescriptionLabel;
- private Label mSdkLocLabel;
-
-
-
- /**
- * Create the composite.
- * @param parent The parent of the composite.
- * @param updaterData An instance of {@link UpdaterData}.
- */
- RemotePackagesPage(Composite parent, int swtStyle, UpdaterData updaterData) {
- super(parent, swtStyle);
-
- mUpdaterData = updaterData;
-
- createContents(this);
- postCreate(); //$hide$
- }
-
- private void createContents(Composite parent) {
- parent.setLayout(new GridLayout(5, false));
-
- mSdkLocLabel = new Label(parent, SWT.NONE);
- mSdkLocLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false, 5, 1));
- mSdkLocLabel.setText("SDK Location: " +
- (mUpdaterData.getOsSdkRoot() != null ? mUpdaterData.getOsSdkRoot()
- : "<unknown>"));
-
- mTreeViewerSources = new CheckboxTreeViewer(parent, SWT.BORDER);
- mTreeViewerSources.addCheckStateListener(new ICheckStateListener() {
- public void checkStateChanged(CheckStateChangedEvent event) {
- onTreeCheckStateChanged(event); //$hide$
- }
- });
- 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));
-
- mColumnSource = new TreeColumn(mTreeSources, SWT.NONE);
- mColumnSource.setWidth(289);
- mColumnSource.setText("Packages available for download");
-
- 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"); //$NON-NLS-1$
-
- mAddSiteButton = new Button(parent, SWT.NONE);
- mAddSiteButton.setText("Add Add-on Site...");
- mAddSiteButton.setToolTipText("Allows you to enter a new add-on site. " +
- "Such site can only contribute add-ons and extra packages.");
- mAddSiteButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- onAddSiteSelected(); //$hide$
- }
- });
-
- mDeleteSiteButton = new Button(parent, SWT.NONE);
- mDeleteSiteButton.setText("Delete Add-on Site...");
- mDeleteSiteButton.setToolTipText("Allows you to remove an add-on site. " +
- "Built-in default sites cannot be removed.");
- mDeleteSiteButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- onRemoveSiteSelected(); //$hide$
- }
- });
-
- mUpdateOnlyCheckBox = new Button(parent, SWT.CHECK);
- mUpdateOnlyCheckBox.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
- mUpdateOnlyCheckBox.setText("Display updates only");
- mUpdateOnlyCheckBox.setToolTipText("When selected, only compatible non-obsolete update packages are shown in the list above.");
- mUpdateOnlyCheckBox.setSelection(mUpdaterData.getSettingsController().getShowUpdateOnly());
- mUpdateOnlyCheckBox.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent arg0) {
- onShowUpdateOnly(); //$hide$
- }
- });
-
- mRefreshButton = new Button(parent, SWT.NONE);
- mRefreshButton.setText("Refresh");
- mRefreshButton.setToolTipText("Refreshes the list of packages from open sites.");
- mRefreshButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- onRefreshSelected(); //$hide$
- }
- });
-
- mInstallSelectedButton = new Button(parent, SWT.NONE);
- mInstallSelectedButton.setText("Install Selected");
- mInstallSelectedButton.setToolTipText("Allows you to review all selected packages " +
- "and install them.");
- mInstallSelectedButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- onInstallSelectedArchives(); //$hide$
- }
- });
- }
-
- @Override
- public void dispose() {
- mUpdaterData.removeListener(this);
- super.dispose();
- }
-
- @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>>$
-
- /**
- * Called by the constructor right after {@link #createContents(Composite)}.
- */
- private void postCreate() {
- mUpdaterData.addListeners(this);
- adjustColumnsWidth();
- updateButtonsState();
- }
-
- /**
- * Adds a listener to adjust the columns width when the parent is resized.
- * <p/>
- * If we need something more fancy, we might want to use this:
- * http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet77.java?view=co
- */
- private void adjustColumnsWidth() {
- // Add a listener to resize the column to the full width of the table
- ControlAdapter resizer = new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent e) {
- Rectangle r = mTreeSources.getClientArea();
- mColumnSource.setWidth(r.width);
- }
- };
-
- mTreeSources.addControlListener(resizer);
- resizer.controlResized(null);
- }
-
- /**
- * Called when an item in the package table viewer is selected.
- * If the items is an {@link IDescription} (as it should), this will display its long
- * description in the description area. Otherwise when the item is not of the expected
- * type or there is no selection, it empties the description area.
- */
- private void onTreeSelected() {
- updateButtonsState();
-
- 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-$
- }
-
- /**
- * Handle checking and unchecking of the tree items.
- *
- * When unchecking, all sub-tree items checkboxes are cleared too.
- * When checking a source, all of its packages are checked too.
- * When checking a package, only its compatible archives are checked.
- */
- private void onTreeCheckStateChanged(CheckStateChangedEvent event) {
- updateButtonsState();
-
- boolean b = event.getChecked();
- Object elem = event.getElement(); // Will be Archive or Package or RepoSource
-
- assert event.getSource() == mTreeViewerSources;
-
- // when deselecting, we just deselect all children too
- if (b == false) {
- mTreeViewerSources.setSubtreeChecked(elem, b);
- return;
- }
-
- ITreeContentProvider provider =
- (ITreeContentProvider) mTreeViewerSources.getContentProvider();
-
- // When selecting, we want to only select compatible archives
- // and expand the super nodes.
- expandItem(elem, provider);
- }
-
- private void expandItem(Object elem, ITreeContentProvider provider) {
- if (elem instanceof SdkSource || elem instanceof SdkSourceCategory) {
- mTreeViewerSources.setExpandedState(elem, true);
- for (Object pkg : provider.getChildren(elem)) {
- mTreeViewerSources.setChecked(pkg, true);
- expandItem(pkg, provider);
- }
- } else if (elem instanceof Package) {
- selectCompatibleArchives(elem, provider);
- }
- }
-
- private void selectCompatibleArchives(Object pkg, ITreeContentProvider provider) {
- for (Object archive : provider.getChildren(pkg)) {
- if (archive instanceof Archive) {
- mTreeViewerSources.setChecked(archive, ((Archive) archive).isCompatible());
- }
- }
- }
-
- private void onShowUpdateOnly() {
- SettingsController controller = mUpdaterData.getSettingsController();
- controller.setShowUpdateOnly(mUpdateOnlyCheckBox.getSelection());
- controller.saveSettings();
-
- // Get the list of selected archives
- ArrayList<Archive> archives = new ArrayList<Archive>();
- for (Object element : mTreeViewerSources.getCheckedElements()) {
- if (element instanceof Archive) {
- archives.add((Archive) element);
- }
- // Deselect them all
- mTreeViewerSources.setChecked(element, false);
- }
-
- mTreeViewerSources.refresh();
-
- // Now reselect those that still exist in the tree but only if they
- // are compatible archives
- for (Archive a : archives) {
- if (a.isCompatible() && mTreeViewerSources.setChecked(a, true)) {
- // If we managed to select the archive, also select the parent package.
- // Technically we should only select the parent package if *all* the
- // compatible archives children are selected. In practice we'll rarely
- // have more than one compatible archive per package.
- mTreeViewerSources.setChecked(a.getParentPackage(), true);
- }
- }
-
- updateButtonsState();
- }
-
- private void onInstallSelectedArchives() {
- ArrayList<Archive> archives = new ArrayList<Archive>();
- for (Object element : mTreeViewerSources.getCheckedElements()) {
- if (element instanceof Archive) {
- archives.add((Archive) element);
- }
- }
-
- if (mUpdaterData != null) {
- mUpdaterData.updateOrInstallAll_WithGUI(
- archives,
- mUpdateOnlyCheckBox.getSelection() /* includeObsoletes */,
- 0 /* flags */);
- }
- }
-
- private void onAddSiteSelected() {
- final SdkSource[] knowSources = mUpdaterData.getSources().getAllSources();
- String title = "Add Add-on Site URL";
-
- String msg =
- "This dialog lets you add the URL of a new add-on site.\n" +
- "\n" +
- "An add-on site can only provide new add-ons or \"user\" packages.\n" +
- "Add-on sites cannot provide standard Android platforms, docs or samples packages.\n" +
- "Inserting a URL here will not allow you to clone an official Android repository.\n" +
- "\n" +
- "Please enter the URL of the repository.xml for the new add-on site:";
-
- InputDialog dlg = new InputDialog(getShell(), title, msg, null, new IInputValidator() {
- public String isValid(String newText) {
-
- newText = newText == null ? null : newText.trim();
-
- if (newText == null || newText.length() == 0) {
- return "Error: URL field is empty. Please enter a URL.";
- }
-
- // A URL should have one of the following prefixes
- if (!newText.startsWith("file://") && //$NON-NLS-1$
- !newText.startsWith("ftp://") && //$NON-NLS-1$
- !newText.startsWith("http://") && //$NON-NLS-1$
- !newText.startsWith("https://")) { //$NON-NLS-1$
- return "Error: The URL must start by one of file://, ftp://, http:// or https://";
- }
-
- // Reject URLs that are already in the source list.
- // URLs are generally case-insensitive (except for file:// where it all depends
- // on the current OS so we'll ignore this case.)
- for (SdkSource s : knowSources) {
- if (newText.equalsIgnoreCase(s.getUrl())) {
- return "Error : This site is already listed.";
- }
- }
-
- return null;
- }
- });
-
- if (dlg.open() == Window.OK) {
- String url = dlg.getValue().trim();
- mUpdaterData.getSources().add(
- SdkSourceCategory.USER_ADDONS,
- new SdkAddonSource(url, null/*uiName*/));
- onRefreshSelected();
- }
- }
-
- private void onRemoveSiteSelected() {
- boolean changed = false;
-
- ISelection sel = mTreeViewerSources.getSelection();
- if (mUpdaterData != null && sel instanceof ITreeSelection) {
- for (Object c : ((ITreeSelection) sel).toList()) {
- if (c instanceof SdkSource) {
- SdkSource source = (SdkSource) c;
-
- if (mUpdaterData.getSources().hasSourceUrl(
- SdkSourceCategory.USER_ADDONS, source)) {
- String title = "Delete Add-on Site?";
-
- String msg = String.format("Are you sure you want to delete the add-on site '%1$s'?",
- source.getUrl());
-
- if (MessageDialog.openQuestion(getShell(), title, msg)) {
- mUpdaterData.getSources().remove(source);
- changed = true;
- }
- }
- }
- }
- }
-
- if (changed) {
- onRefreshSelected();
- }
- }
-
- private void onRefreshSelected() {
- if (mUpdaterData != null) {
- mUpdaterData.refreshSources(false /*forceFetching*/);
- }
- mTreeViewerSources.refresh();
- updateButtonsState();
- }
-
- private void updateButtonsState() {
- // We install archives, so there should be at least one checked archive.
- // Having sites or packages checked does not count.
- boolean hasCheckedArchive = false;
- Object[] checked = mTreeViewerSources.getCheckedElements();
- if (checked != null) {
- for (Object c : checked) {
- if (c instanceof Archive) {
- hasCheckedArchive = true;
- break;
- }
- }
- }
-
- // Is there a selected site Source?
- boolean hasSelectedUserSource = false;
- ISelection sel = mTreeViewerSources.getSelection();
- if (sel instanceof ITreeSelection) {
- for (Object c : ((ITreeSelection) sel).toList()) {
- if (c instanceof SdkSource &&
- mUpdaterData.getSources().hasSourceUrl(
- SdkSourceCategory.USER_ADDONS, (SdkSource) c)) {
- hasSelectedUserSource = true;
- break;
- }
- }
- }
-
- mAddSiteButton.setEnabled(true);
- mDeleteSiteButton.setEnabled(hasSelectedUserSource);
- mRefreshButton.setEnabled(true);
- mInstallSelectedButton.setEnabled(hasCheckedArchive);
-
- // set value on the show only update checkbox
- mUpdateOnlyCheckBox.setSelection(mUpdaterData.getSettingsController().getShowUpdateOnly());
- }
-
- // --- Implementation of ISdkChangeListener ---
-
- public void onSdkLoaded() {
- onSdkReload();
- }
-
- public void onSdkReload() {
- RepoSourcesAdapter sources = mUpdaterData.getSourcesAdapter();
- mTreeViewerSources.setContentProvider(sources.getContentProvider());
- mTreeViewerSources.setLabelProvider( sources.getLabelProvider());
- mTreeViewerSources.setInput(sources);
- onTreeSelected();
- }
-
- public void preInstallHook() {
- // nothing to be done for now.
- }
-
- public void postInstallHook() {
- // nothing to be done for now.
- }
-
- // End of hiding from SWT Designer
- //$hide<<$
-}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/RepoSourcesAdapter.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/RepoSourcesAdapter.java
deleted file mode 100755
index 586431e..0000000
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/RepoSourcesAdapter.java
+++ /dev/null
@@ -1,367 +0,0 @@
-/*
- * 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.sdkman1;
-
-import com.android.sdklib.internal.repository.Archive;
-import com.android.sdklib.internal.repository.IDescription;
-import com.android.sdklib.internal.repository.ITask;
-import com.android.sdklib.internal.repository.ITaskMonitor;
-import com.android.sdklib.internal.repository.NullTaskMonitor;
-import com.android.sdklib.internal.repository.Package;
-import com.android.sdklib.internal.repository.SdkSource;
-import com.android.sdklib.internal.repository.SdkSourceCategory;
-import com.android.sdklib.internal.repository.Package.UpdateInfo;
-import com.android.sdkuilib.internal.repository.UpdaterData;
-import com.android.sdkuilib.internal.repository.icons.ImageFactory;
-
-import org.eclipse.jface.viewers.IContentProvider;
-import org.eclipse.jface.viewers.ILabelProvider;
-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 java.util.ArrayList;
-
-/**
- * A list of sdk-repository sources.
- *
- * This implementation is UI dependent.
- */
-public class RepoSourcesAdapter {
-
- private final UpdaterData mUpdaterData;
-
- /**
- * A dummy RepoSource entry returned for sources which had load errors.
- * It displays a summary of the error as its short description or
- * it displays the source's long description.
- */
- public static class RepoSourceError implements IDescription {
-
- private final SdkSource mSource;
-
- public RepoSourceError(SdkSource source) {
- mSource = source;
- }
-
- public String getLongDescription() {
- return mSource.getLongDescription();
- }
-
- public String getShortDescription() {
- return mSource.getFetchError();
- }
- }
-
- /**
- * A dummy RepoSource entry returned for sources with no packages.
- * We need that to force the SWT tree to display an open/close triangle
- * even for empty sources.
- */
- public static class RepoSourceEmpty implements IDescription {
-
- private final SdkSource mSource;
- private final boolean mEmptyBecauseOfUpdateOnly;
-
- public RepoSourceEmpty(SdkSource source, boolean emptyBecauseOfUpdateOnly) {
- mSource = source;
- mEmptyBecauseOfUpdateOnly = emptyBecauseOfUpdateOnly;
- }
-
- public String getLongDescription() {
- return mSource.getLongDescription();
- }
-
- public String getShortDescription() {
- if (mEmptyBecauseOfUpdateOnly) {
- return "Some packages were found but are not compatible updates.";
- } else {
- return "No packages found";
- }
- }
- }
-
- public RepoSourcesAdapter(UpdaterData updaterData) {
- mUpdaterData = updaterData;
- }
-
- public ILabelProvider getLabelProvider() {
- return new ViewerLabelProvider();
- }
-
-
- public IContentProvider getContentProvider() {
- return new TreeContentProvider();
- }
-
- // ------------
-
- private class ViewerLabelProvider extends LabelProvider {
-
- /** Returns an image appropriate for this element. */
- @Override
- public Image getImage(Object element) {
-
- ImageFactory imgFactory = mUpdaterData.getImageFactory();
-
- if (imgFactory != null) {
- return imgFactory.getImageForObject(element);
- }
-
- return super.getImage(element);
- }
-
- /** Returns the toString of the element. */
- @Override
- public String getText(Object element) {
- if (element instanceof IDescription) {
- return ((IDescription) element).getShortDescription();
- }
- return super.getText(element);
- }
- }
-
- // ------------
-
- private class TreeContentProvider implements ITreeContentProvider {
-
- // Called when the viewer is disposed
- public void dispose() {
- // pass
- }
-
- // Called when the input is set or changed on the provider
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- // pass
- }
-
- /**
- * Called to collect the root elements for the given input.
- * The input here is a {@link RepoSourcesAdapter} object, this returns an array
- * of {@link SdkSource}.
- */
- public Object[] getElements(Object inputElement) {
- return getChildren(inputElement);
- }
-
- /**
- * Get the children of the given parent. This is requested on-demand as
- * nodes are expanded.
- *
- * For a {@link RepoSourcesAdapter} object, returns an array of {@link SdkSource}s.
- * For a {@link SdkSource}, returns an array of {@link Package}s.
- * For a {@link Package}, returns an array of {@link Archive}s.
- */
- public Object[] getChildren(Object parentElement) {
- if (parentElement == RepoSourcesAdapter.this) {
- return mUpdaterData.getSources().getCategories();
-
- } else if (parentElement instanceof SdkSourceCategory) {
- SdkSourceCategory cat = (SdkSourceCategory) parentElement;
- if (cat == SdkSourceCategory.ADDONS_3RD_PARTY) {
- mUpdaterData.loadRemoteAddonsList(
- new NullTaskMonitor(mUpdaterData.getSdkLog()));
- }
-
- SdkSource[] sources = mUpdaterData.getSources().getSources(cat);
-
- if (sources.length == 1 && sources[0] != null) {
- // If a source has a single element and this element has the same
- // uiName as the category, collapse both.
- // Basically this is a kludge so that we don't end up with
- // Android Repository > Android Repository
- // at the top level.
- if (cat.getUiName().equals(sources[0].getUiName())) {
- return getRepoSourceChildren(sources[0]);
- }
- }
-
- return sources;
-
- } else if (parentElement instanceof SdkSource) {
- return getRepoSourceChildren((SdkSource) parentElement);
-
- } else if (parentElement instanceof Package) {
- return getPackageChildren((Package) parentElement);
- }
-
- return new Object[0];
- }
-
- /**
- * Returns the list of packages for this repo source, eventually filtered to display
- * only update packages. If the list is empty, returns a specific empty node. If there's
- * an error, returns a specific error node.
- */
- private Object[] getRepoSourceChildren(final SdkSource source) {
- Package[] packages = source.getPackages();
-
- if (packages == null && source.getFetchError() == null) {
- final boolean forceHttp = mUpdaterData.getSettingsController().getForceHttp();
-
- mUpdaterData.getTaskFactory().start("Loading Source", new ITask() {
- public void run(ITaskMonitor monitor) {
- source.load(monitor, forceHttp);
- }
- });
-
- packages = source.getPackages();
- }
-
- boolean wasEmptyBeforeFilter = (packages == null || packages.length == 0);
-
- // filter out only the packages that are new/upgrade.
- if (packages != null && mUpdaterData.getSettingsController().getShowUpdateOnly()) {
- packages = filterUpdateOnlyPackages(packages);
- }
- if (packages != null && packages.length == 0) {
- packages = null;
- }
-
- ArrayList<Object> results = new ArrayList<Object>();
-
- if (source.getFetchError() != null) {
- // Insert a dummy entry to display the fetch error
- results.add(new RepoSourceError(source));
- }
-
- // Either return a non-null package list or create a new empty node
- if (packages != null) {
- for (Package p : packages) {
- results.add(p);
- }
- } else {
- results.add(new RepoSourceEmpty(source, !wasEmptyBeforeFilter));
- }
-
- return results.toArray();
- }
-
- /**
- * Returns the list of archives for the given package, eventually filtering it
- * to only show the compatible archives.
- */
- private Object[] getPackageChildren(Package pkg) {
- Archive[] archives = pkg.getArchives();
- if (mUpdaterData.getSettingsController().getShowUpdateOnly()) {
- for (Archive archive : archives) {
-
- // if we only want the compatible archives, then we just take the first
- // one. it's unlikely there are 2 compatible archives for the same
- // package
- if (archive.isCompatible()) {
- return new Object[] { archive };
- }
- }
- }
-
- return archives;
- }
-
- /**
- * Returns the parent of a given element.
- * The input {@link RepoSourcesAdapter} is the parent of all {@link SdkSource} elements.
- */
- public Object getParent(Object element) {
-
- if (element instanceof SdkSourceCategory) {
- return RepoSourcesAdapter.this;
-
- } else if (element instanceof SdkSource) {
- return mUpdaterData.getSources().getCategory((SdkSource) element);
-
- } else if (element instanceof Package) {
- return ((Package) element).getParentSource();
-
- } else if (element instanceof Archive) {
- return ((Archive) element).getParentPackage();
- }
- return null;
- }
-
- /**
- * Returns true if a given element has children, which is used to display a
- * "+/expand" box next to the tree node.
- * All non-terminal elements are expandable, whether they actually have any children
- * or not. This is necessary on windows in order for the tree to display the "triangle"
- * icon so that users can actually expand it, which will fill the node at runtime.
- */
- public boolean hasChildren(Object element) {
- return element instanceof SdkSourceCategory ||
- element instanceof SdkSource ||
- element instanceof Package;
- }
- }
-
- /**
- * Filters out a list of remote packages to only keep the ones that are either new or
- * updates of existing package. This also removes obsolete packages.
- *
- * @param remotePackages the list of packages to filter.
- * @return a non null (but maybe empty) list of new or update packages.
- */
- private Package[] filterUpdateOnlyPackages(Package[] remotePackages) {
- // get the installed packages
- Package[] installedPackages = mUpdaterData.getInstalledPackages(
- new NullTaskMonitor(mUpdaterData.getSdkLog()));
-
- // we'll populate this package list with either upgrades or new packages.
- ArrayList<Package> filteredList = new ArrayList<Package>();
-
- // for each remote packages, we look for an existing version.
- // If no existing version -> add to the list
- // if existing version but with older revision -> add it to the list
- for (Package remotePkg : remotePackages) {
-
- // Obsolete packages are not offered as updates.
- if (remotePkg.isObsolete()) {
- continue;
- }
-
- // For all potential packages, we also make sure that there's an archive for
- // the current platform, or we simply skip them.
- if (remotePkg.hasCompatibleArchive()) {
- boolean keepPkg = true;
-
- nextPkg: for (Package installedPkg : installedPackages) {
- UpdateInfo info = installedPkg.canBeUpdatedBy(remotePkg);
- switch(info) {
- case UPDATE:
- // The remote package is an update to an existing one.
- // We're done looking.
- keepPkg = true;
- break nextPkg;
- case NOT_UPDATE:
- // The remote package is the same as one that is already installed.
- keepPkg = false;
- break;
- case INCOMPATIBLE:
- // We can't compare and decide on incompatible things.
- break;
- }
- }
-
- if (keepPkg) {
- filteredList.add(remotePkg);
- }
- }
- }
-
- return filteredList.toArray(new Package[filteredList.size()]);
- }
-}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/SdkUpdaterWindowImpl1.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/SdkUpdaterWindowImpl1.java
deleted file mode 100755
index 37f849c..0000000
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman1/SdkUpdaterWindowImpl1.java
+++ /dev/null
@@ -1,469 +0,0 @@
-/*
- * 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.sdkman1;
-
-
-import com.android.sdklib.ISdkLog;
-import com.android.sdklib.SdkConstants;
-import com.android.sdkuilib.internal.repository.IPageListener;
-import com.android.sdkuilib.internal.repository.ISdkUpdaterWindow;
-import com.android.sdkuilib.internal.repository.ISettingsPage;
-import com.android.sdkuilib.internal.repository.SettingsController;
-import com.android.sdkuilib.internal.repository.UpdaterData;
-import com.android.sdkuilib.internal.repository.UpdaterPage;
-import com.android.sdkuilib.internal.repository.UpdaterPage.Purpose;
-import com.android.sdkuilib.internal.repository.icons.ImageFactory;
-import com.android.sdkuilib.internal.tasks.ProgressTaskFactory;
-import com.android.sdkuilib.repository.ISdkChangeListener;
-import com.android.sdkuilib.repository.SdkUpdaterWindow.SdkInvocationContext;
-import com.android.util.Pair;
-
-import org.eclipse.swt.SWT;
-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.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-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.util.ArrayList;
-
-/**
- * This is the private implementation of the UpdateWindow for the
- * first version of the SDK Manager.
- * <p/>
- * This window has a sash, with a list of available pages on the left
- * (AVD list, settings, about, installed packages, available packages)
- * and the corresponding page on the right.
- */
-public class SdkUpdaterWindowImpl1 implements ISdkUpdaterWindow {
-
- private final Shell mParentShell;
- /** Internal data shared between the window and its pages. */
- private final UpdaterData mUpdaterData;
- /** The array of pages instances. Only one is visible at a time. */
- private ArrayList<Composite> mPages = new ArrayList<Composite>();
- /** Indicates a page change is due to an internal request. Prevents callbacks from looping. */
- private boolean mInternalPageChange;
- /** A list of extra pages to instantiate. Each entry is an object array with 2 elements:
- * the string title and the Composite class to instantiate to create the page. */
- private ArrayList<Pair<Class<? extends UpdaterPage>, Purpose>> mExtraPages;
- /** A factory to create progress task dialogs. */
- private ProgressTaskFactory mTaskFactory;
- /** The initial page to display. If null or not a know class, the first page will be displayed.
- * Must be set before the first call to {@link #open()}. */
- private Class<? extends Composite> mInitialPage;
- /** Sets whether the auto-update wizard will be shown when opening the window. */
- private boolean mRequestAutoUpdate;
-
- // --- UI members ---
-
- protected Shell mShell;
- private List mPageList;
- private Composite mPagesRootComposite;
- private AvdManagerPage mAvdManagerPage;
- private StackLayout mStackLayout;
- private LocalPackagesPage mLocalPackagePage;
- private RemotePackagesPage mRemotePackagesPage;
-
- /**
- * Creates a new window. Caller must call open(), which will block.
- *
- * @param parentShell Parent shell.
- * @param sdkLog Logger. Cannot be null.
- * @param osSdkRoot The OS path to the SDK root.
- * @param context The {@link SdkInvocationContext} to change the behavior depending on who's
- * opening the SDK Manager. Unused for SdkMan1.
- */
- public SdkUpdaterWindowImpl1(
- Shell parentShell,
- ISdkLog sdkLog,
- String osSdkRoot,
- SdkInvocationContext context/*unused*/) {
- mParentShell = parentShell;
- mUpdaterData = new UpdaterData(osSdkRoot, sdkLog);
- }
-
- /**
- * Opens the window.
- * @wbp.parser.entryPoint
- */
- public void open() {
- if (mParentShell == null) {
- Display.setAppName("Android"); //$hide$ (hide from SWT designer)
- }
-
- createShell();
- preCreateContent();
- createContents();
- mShell.open();
- mShell.layout();
-
- if (postCreateContent()) { //$hide$ (hide from SWT designer)
- Display display = Display.getDefault();
- while (!mShell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
- }
-
- dispose(); //$hide$
- }
-
- private void createShell() {
- mShell = new Shell(mParentShell, SWT.SHELL_TRIM | SWT.APPLICATION_MODAL);
- mShell.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- onAndroidSdkUpdaterDispose(); //$hide$ (hide from SWT designer)
- }
- });
-
- GridLayout glShell = new GridLayout(2, false);
- glShell.verticalSpacing = 0;
- glShell.horizontalSpacing = 0;
- glShell.marginWidth = 0;
- glShell.marginHeight = 0;
- mShell.setLayout(glShell);
-
- mShell.setMinimumSize(new Point(500, 300));
- mShell.setSize(700, 500);
- mShell.setText("Android SDK and AVD Manager");
- }
-
- /**
- * Create contents of the window.
- */
- private void createContents() {
- SashForm sashForm = new SashForm(mShell, SWT.NONE);
- sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
-
- mPageList = new List(sashForm, SWT.BORDER);
- mPageList.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- onPageListSelected(); //$hide$ (hide from SWT designer)
- }
- });
-
- createPagesRoot(sashForm);
-
- sashForm.setWeights(new int[] {150, 576});
- }
-
- private void createPagesRoot(Composite parent) {
- mPagesRootComposite = new Composite(parent, SWT.NONE);
- mStackLayout = new StackLayout();
- mPagesRootComposite.setLayout(mStackLayout);
- }
-
- // -- Start of internal part ----------
- // Hide everything down-below from SWT designer
- //$hide>>$
-
- // --- Public API -----------
-
-
- /**
- * Registers an extra page for the updater window.
- * <p/>
- * Pages must derive from {@link Composite} and implement a constructor that takes
- * a single parent {@link Composite} argument.
- * <p/>
- * All pages must be registered before the call to {@link #open()}.
- *
- * @param pageClass The {@link Composite}-derived class that will implement the page.
- * @param purpose The purpose of this page, e.g. an about box, settings page or generic.
- */
- @SuppressWarnings("unchecked")
- public void registerPage(Class<? extends UpdaterPage> pageClass,
- Purpose purpose) {
- if (mExtraPages == null) {
- mExtraPages = new ArrayList<Pair<Class<? extends UpdaterPage>, Purpose>>();
- }
- Pair<?, Purpose> value = Pair.of(pageClass, purpose);
- mExtraPages.add((Pair<Class<? extends UpdaterPage>, Purpose>) value);
- }
-
- /**
- * Indicate the initial page that should be selected when the window opens.
- * This must be called before the call to {@link #open()}.
- * If null or if the page class is not found, the first page will be selected.
- */
- public void setInitialPage(Class<? extends Composite> pageClass) {
- mInitialPage = pageClass;
- }
-
- /**
- * Sets whether the auto-update wizard will be shown when opening the window.
- * <p/>
- * This must be called before the call to {@link #open()}.
- */
- public void setRequestAutoUpdate(boolean requestAutoUpdate) {
- mRequestAutoUpdate = requestAutoUpdate;
- }
-
- /**
- * Adds a new listener to be notified when a change is made to the content of the SDK.
- */
- public void addListener(ISdkChangeListener listener) {
- mUpdaterData.addListeners(listener);
- }
-
- /**
- * Removes a new listener to be notified anymore when a change is made to the content of
- * the SDK.
- */
- public void removeListener(ISdkChangeListener listener) {
- mUpdaterData.removeListener(listener);
- }
-
- // --- Internals & UI Callbacks -----------
-
- /**
- * Called by {@link #postCreateContent()} to generate the pages that can be
- * displayed in the window.
- */
- protected void createPages() {
- mAvdManagerPage = new AvdManagerPage(mPagesRootComposite, SWT.BORDER, mUpdaterData);
-
- mLocalPackagePage = new LocalPackagesPage(mPagesRootComposite, SWT.BORDER, mUpdaterData);
- mRemotePackagesPage = new RemotePackagesPage(mPagesRootComposite, SWT.BORDER, mUpdaterData);
-
- addPage(mAvdManagerPage, "Virtual devices");
-
- addPage(mLocalPackagePage, "Installed packages");
- addPage(mRemotePackagesPage, "Available packages");
-
- addExtraPages();
- }
-
- /**
- * Callback called when the window shell is disposed.
- */
- private void onAndroidSdkUpdaterDispose() {
- if (mUpdaterData != null) {
- ImageFactory imgFactory = mUpdaterData.getImageFactory();
- if (imgFactory != null) {
- imgFactory.dispose();
- }
- }
- }
-
- /**
- * Creates the icon of the window shell.
- */
- private void setWindowImage(Shell androidSdkUpdater) {
- String imageName = "android_icon_16.png"; //$NON-NLS-1$
- if (SdkConstants.currentPlatform() == SdkConstants.PLATFORM_DARWIN) {
- imageName = "android_icon_128.png";
- }
-
- if (mUpdaterData != null) {
- ImageFactory imgFactory = mUpdaterData.getImageFactory();
- if (imgFactory != null) {
- mShell.setImage(imgFactory.getImageByName(imageName));
- }
- }
- }
-
- /**
- * Called before the UI is created.
- */
- private void preCreateContent() {
- mUpdaterData.setWindowShell(mShell);
- mTaskFactory = new ProgressTaskFactory(mShell);
- mUpdaterData.setTaskFactory(mTaskFactory);
- mUpdaterData.setImageFactory(new ImageFactory(mShell.getDisplay()));
- }
-
- /**
- * Once the UI has been created, initializes the content.
- * This creates the pages, selects the first one, setup sources and scan for local folders.
- *
- * Returns true if we should show the window.
- */
- private boolean postCreateContent() {
- setWindowImage(mShell);
- createPages();
-
- setupSources();
- initializeSettings();
- selectInitialPage();
-
- if (mUpdaterData.checkIfInitFailed()) {
- return false;
- }
-
- mUpdaterData.broadcastOnSdkLoaded();
-
- if (mRequestAutoUpdate) {
- mUpdaterData.updateOrInstallAll_WithGUI(
- null /*selectedArchives*/,
- false /* includeObsoletes */,
- 0 /* flags */);
- }
-
- return true;
- }
-
- /**
- * Called by the main loop when the window has been disposed.
- */
- private void dispose() {
- mUpdaterData.getSources().saveUserAddons(mUpdaterData.getSdkLog());
- }
-
- // --- page switching ---
-
- /**
- * Adds an instance of a page to the page list.
- * <p/>
- * Each page is a {@link Composite}. The title of the page is stored in the
- * {@link Composite#getData()} field.
- */
- protected void addPage(Composite page, String title) {
- assert title != null;
- if (title == null) {
- title = "Unknown";
- }
- page.setData(title);
- mPages.add(page);
- if (mPageList != null) {
- mPageList.add(title);
- }
- }
-
- /**
- * Adds all extra pages. For each page, instantiates an instance of the {@link Composite}
- * using the constructor that takes a single {@link Composite} argument and then adds it
- * to the page list.
- */
- protected void addExtraPages() {
- if (mExtraPages == null) {
- return;
- }
-
- for (Pair<Class<? extends UpdaterPage>, Purpose> extraPage : mExtraPages) {
- Class<? extends UpdaterPage> clazz = extraPage.getFirst();
- UpdaterPage instance = UpdaterPage.newInstance(
- clazz,
- mPagesRootComposite,
- SWT.BORDER,
- mUpdaterData.getSdkLog());
- if (instance != null) {
- addPage(instance, instance.getPageTitle());
- }
- }
- }
-
- /**
- * Callback invoked when an item is selected in the page list.
- * If this is not an internal page change, displays the given page.
- */
- private void onPageListSelected() {
- if (mInternalPageChange == false && mPageList != null) {
- int index = mPageList.getSelectionIndex();
- if (index >= 0) {
- displayPage(index);
- }
- }
- }
-
- /**
- * Displays the page at the given index.
- *
- * @param index An index between 0 and {@link #mPages}'s length - 1.
- */
- private void displayPage(int index) {
- Composite page = mPages.get(index);
- if (page != null) {
- mStackLayout.topControl = page;
- mPagesRootComposite.layout(true);
-
- if (!mInternalPageChange && mPageList != null) {
- mInternalPageChange = true;
- mPageList.setSelection(index);
- mInternalPageChange = false;
- }
-
- if (page instanceof IPageListener) {
- ((IPageListener) page).onPageSelected();
- }
- }
- }
-
- /**
- * Used to initialize the sources.
- */
- private void setupSources() {
- mUpdaterData.setupDefaultSources();
- }
-
- /**
- * Initializes settings.
- * This must be called after addExtraPages(), which created a settings page.
- * Iterate through all the pages to find the first (and supposedly unique) setting page,
- * and use it to load and apply these settings.
- */
- private void initializeSettings() {
- SettingsController c = mUpdaterData.getSettingsController();
- c.loadSettings();
- c.applySettings();
-
- for (Object page : mPages) {
- if (page instanceof ISettingsPage) {
- ISettingsPage settingsPage = (ISettingsPage) page;
-
- c.setSettingsPage(settingsPage);
- break;
- }
- }
- }
-
- /**
- * Select and show the initial page.
- * This will be either the page which class matches {@link #mInitialPage} or the
- * first one in the list.
- */
- private void selectInitialPage() {
- int pageIndex = 0;
- int i = 0;
- for (Composite p : mPages) {
- if (p.getClass().equals(mInitialPage)) {
- pageIndex = i;
- break;
- }
- i++;
- }
-
- displayPage(pageIndex);
- if (mPageList != null) {
- mPageList.setSelection(pageIndex);
- }
- }
-
- // End of hiding from SWT Designer
- //$hide<<$
-}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/SdkUpdaterWindow.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/SdkUpdaterWindow.java
index 6c95c61..59da350 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/SdkUpdaterWindow.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/repository/SdkUpdaterWindow.java
@@ -19,7 +19,6 @@ package com.android.sdkuilib.repository;
import com.android.sdklib.ISdkLog;
import com.android.sdkuilib.internal.repository.ISdkUpdaterWindow;
import com.android.sdkuilib.internal.repository.UpdaterPage;
-import com.android.sdkuilib.internal.repository.sdkman1.SdkUpdaterWindowImpl1;
import com.android.sdkuilib.internal.repository.sdkman2.SdkUpdaterWindowImpl2;
import org.eclipse.swt.widgets.Composite;
@@ -87,13 +86,7 @@ public class SdkUpdaterWindow {
String osSdkRoot,
SdkInvocationContext context) {
- // The new PackagesPage is not activated by default,
- // this offers a way to fallback on the old one
- if (System.getenv("ANDROID_OLD_SDKMAN") == null) { //$NON-NLS-1$
- mWindow = new SdkUpdaterWindowImpl2(parentShell, sdkLog, osSdkRoot, context);
- } else {
- mWindow = new SdkUpdaterWindowImpl1(parentShell, sdkLog, osSdkRoot, context);
- }
+ mWindow = new SdkUpdaterWindowImpl2(parentShell, sdkLog, osSdkRoot, context);
}
/**