Add a checkbox to only show packages that are updates or new.
This commit is contained in:
@@ -25,11 +25,13 @@ import java.util.Properties;
|
||||
public interface ISettingsPage {
|
||||
|
||||
/** Java system setting picked up by {@link URL} for http proxy port. Type: String. */
|
||||
public static final String KEY_HTTP_PROXY_PORT = "http.proxyPort"; //$NON-NLS-1$
|
||||
public static final String KEY_HTTP_PROXY_PORT = "http.proxyPort"; //$NON-NLS-1$
|
||||
/** Java system setting picked up by {@link URL} for http proxy host. Type: String. */
|
||||
public static final String KEY_HTTP_PROXY_HOST = "http.proxyHost"; //$NON-NLS-1$
|
||||
public static final String KEY_HTTP_PROXY_HOST = "http.proxyHost"; //$NON-NLS-1$
|
||||
/** Setting to force using http:// instead of https:// connections. Type: Boolean. */
|
||||
public static final String KEY_FORCE_HTTP = "sdkman.force.http"; //$NON-NLS-1$
|
||||
public static final String KEY_FORCE_HTTP = "sdkman.force.http"; //$NON-NLS-1$
|
||||
/** Setting to display only packages that are new or updates. Type: Boolean. */
|
||||
public static final String KEY_SHOW_UPDATE_ONLY = "sdkman.show.update.only"; //$NON-NLS-1$
|
||||
|
||||
/** Loads settings from the given {@link Properties} container and update the page UI. */
|
||||
public abstract void loadSettings(Properties in_settings);
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.android.sdkuilib.internal.repository;
|
||||
|
||||
import com.android.sdklib.internal.repository.IDescription;
|
||||
import com.android.sdklib.internal.repository.LocalSdkParser;
|
||||
import com.android.sdklib.internal.repository.Package;
|
||||
import com.android.sdklib.internal.repository.RepoSource;
|
||||
import com.android.sdkuilib.internal.repository.icons.ImageFactory;
|
||||
@@ -95,17 +94,7 @@ class LocalSdkAdapter {
|
||||
*/
|
||||
public Object[] getElements(Object inputElement) {
|
||||
if (inputElement == LocalSdkAdapter.this) {
|
||||
LocalSdkParser parser = mUpdaterData.getLocalSdkParser();
|
||||
|
||||
Package[] packages = parser.getPackages();
|
||||
|
||||
if (packages == null) {
|
||||
// load on demand the first time
|
||||
packages = parser.parseSdk(
|
||||
mUpdaterData.getOsSdkRoot(),
|
||||
mUpdaterData.getSdkManager(),
|
||||
mUpdaterData.getSdkLog());
|
||||
}
|
||||
Package[] packages = mUpdaterData.getInstalledPackage();
|
||||
|
||||
if (packages != null) {
|
||||
return packages;
|
||||
|
||||
@@ -58,6 +58,7 @@ public class RemotePackagesPage extends Composite implements ISdkListener {
|
||||
private CheckboxTreeViewer mTreeViewerSources;
|
||||
private Tree mTreeSources;
|
||||
private TreeColumn mColumnSource;
|
||||
private Button mUpdateOnlyCheckBox;
|
||||
private Group mDescriptionContainer;
|
||||
private Button mAddSiteButton;
|
||||
private Button mDeleteSiteButton;
|
||||
@@ -67,6 +68,7 @@ public class RemotePackagesPage extends Composite implements ISdkListener {
|
||||
private Label mDescriptionLabel;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create the composite.
|
||||
* @param parent The parent of the composite.
|
||||
@@ -104,6 +106,28 @@ public class RemotePackagesPage extends Composite implements ISdkListener {
|
||||
mColumnSource.setWidth(289);
|
||||
mColumnSource.setText("Sources, Packages and Archives");
|
||||
|
||||
Composite composite = new Composite(parent, SWT.NONE);
|
||||
composite.setLayoutData(
|
||||
new GridData(SWT.FILL, SWT.BEGINNING, false, false, 5, 1));
|
||||
GridLayout gl;
|
||||
composite.setLayout(gl = new GridLayout(2, false));
|
||||
gl.marginHeight = gl.marginWidth = 0;
|
||||
// add an empty composite
|
||||
Composite spacer = new Composite(composite, SWT.NONE);
|
||||
GridData gd;
|
||||
spacer.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
|
||||
gd.heightHint = 0;
|
||||
|
||||
mUpdateOnlyCheckBox = new Button(composite, SWT.CHECK);
|
||||
mUpdateOnlyCheckBox.setText("Display updates only");
|
||||
mUpdateOnlyCheckBox.setSelection(mUpdaterData.getSettingsController().getShowUpdateOnly());
|
||||
mUpdateOnlyCheckBox.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
onShowUpdateOnly(); //$hide$
|
||||
}
|
||||
});
|
||||
|
||||
mDescriptionContainer = new Group(parent, SWT.NONE);
|
||||
mDescriptionContainer.setLayout(new GridLayout(1, false));
|
||||
mDescriptionContainer.setText("Description");
|
||||
@@ -263,6 +287,11 @@ public class RemotePackagesPage extends Composite implements ISdkListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void onShowUpdateOnly() {
|
||||
mUpdaterData.getSettingsController().setShowUpdateOnly(mUpdateOnlyCheckBox.getSelection());
|
||||
mTreeViewerSources.refresh();
|
||||
}
|
||||
|
||||
private void onInstallSelectedArchives() {
|
||||
ArrayList<Archive> archives = new ArrayList<Archive>();
|
||||
for (Object element : mTreeViewerSources.getCheckedElements()) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.android.sdklib.internal.repository.ITask;
|
||||
import com.android.sdklib.internal.repository.ITaskMonitor;
|
||||
import com.android.sdklib.internal.repository.Package;
|
||||
import com.android.sdklib.internal.repository.RepoSource;
|
||||
import com.android.sdklib.internal.repository.Package.UpdateInfo;
|
||||
import com.android.sdkuilib.internal.repository.icons.ImageFactory;
|
||||
|
||||
import org.eclipse.jface.viewers.IContentProvider;
|
||||
@@ -31,6 +32,8 @@ 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.
|
||||
*
|
||||
@@ -149,6 +152,10 @@ public class RepoSourcesAdapter {
|
||||
packages = source.getPackages();
|
||||
}
|
||||
if (packages != null) {
|
||||
// filter out only the packages that are new/upgrade.
|
||||
if (mUpdaterData.getSettingsController().getShowUpdateOnly()) {
|
||||
return filteredPackages(packages);
|
||||
}
|
||||
return packages;
|
||||
} else if (source.getFetchError() != null) {
|
||||
// Return a dummy entry to display the fetch error
|
||||
@@ -188,4 +195,46 @@ public class RepoSourcesAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters out a list of remote packages to only keep the ones that are either new or
|
||||
* updates of existing package.
|
||||
* @param remotePackages the list of packages to filter.
|
||||
* @return a non null (but maybe empty) list of new or update packages.
|
||||
*/
|
||||
private Object[] filteredPackages(Package[] remotePackages) {
|
||||
// get the installed packages
|
||||
Package[] installedPackages = mUpdaterData.getInstalledPackage();
|
||||
|
||||
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) {
|
||||
boolean newPkg = true;
|
||||
|
||||
// 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()) {
|
||||
for (Package installedPkg : installedPackages) {
|
||||
UpdateInfo info = installedPkg.canBeUpdatedBy(remotePkg);
|
||||
if (info == UpdateInfo.UPDATE) {
|
||||
filteredList.add(remotePkg);
|
||||
newPkg = false;
|
||||
break; // there shouldn't be 2 revision of the same package
|
||||
} else if (info != UpdateInfo.INCOMPATIBLE) {
|
||||
newPkg = false;
|
||||
break; // there shouldn't be 2 revision of the same package
|
||||
}
|
||||
}
|
||||
|
||||
// if we have not found the same package, then we add it (it's a new package)
|
||||
if (newPkg) {
|
||||
filteredList.add(remotePkg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filteredList.toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,18 @@ public class SettingsController {
|
||||
return Boolean.parseBoolean(mProperties.getProperty(ISettingsPage.KEY_FORCE_HTTP));
|
||||
}
|
||||
|
||||
public boolean getShowUpdateOnly() {
|
||||
String value = mProperties.getProperty(ISettingsPage.KEY_SHOW_UPDATE_ONLY);
|
||||
if (value == null) {
|
||||
return true;
|
||||
}
|
||||
return Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
public void setShowUpdateOnly(boolean enabled) {
|
||||
mProperties.setProperty(ISettingsPage.KEY_SHOW_UPDATE_ONLY, Boolean.toString(enabled));
|
||||
}
|
||||
|
||||
//--- Controller methods -------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.android.sdklib.internal.repository.Package;
|
||||
import com.android.sdklib.internal.repository.RepoSource;
|
||||
import com.android.sdklib.internal.repository.RepoSources;
|
||||
import com.android.sdklib.internal.repository.ToolPackage;
|
||||
import com.android.sdklib.internal.repository.Package.UpdateInfo;
|
||||
import com.android.sdkuilib.internal.repository.icons.ImageFactory;
|
||||
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
@@ -226,6 +227,22 @@ class UpdaterData {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of installed packages, parsing them if this has not yet been done.
|
||||
*/
|
||||
public Package[] getInstalledPackage() {
|
||||
LocalSdkParser parser = getLocalSdkParser();
|
||||
|
||||
Package[] packages = parser.getPackages();
|
||||
|
||||
if (packages == null) {
|
||||
// load on demand the first time
|
||||
packages = parser.parseSdk(getOsSdkRoot(), getSdkManager(), getSdkLog());
|
||||
}
|
||||
|
||||
return packages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the listeners ({@link ISdkListener}) that the SDK was reloaded.
|
||||
* <p/>This can be called from any thread.
|
||||
@@ -491,7 +508,8 @@ class UpdaterData {
|
||||
// local package?
|
||||
|
||||
for (Archive availArchive : list) {
|
||||
if (localPkg.canBeUpdatedBy(availArchive.getParentPackage())) {
|
||||
UpdateInfo info = localPkg.canBeUpdatedBy(availArchive.getParentPackage());
|
||||
if (info == UpdateInfo.UPDATE) {
|
||||
// Found one!
|
||||
result.put(availArchive, localArchive);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user