SDK Updater: logic to load/save user sources and to delete them.
This commit is contained in:
@@ -23,6 +23,7 @@ import com.android.sdklib.internal.repository.Package;
|
||||
import com.android.sdklib.internal.repository.RepoSource;
|
||||
import com.android.sdkuilib.internal.repository.UpdaterData.ISdkListener;
|
||||
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.viewers.CheckStateChangedEvent;
|
||||
import org.eclipse.jface.viewers.CheckboxTreeViewer;
|
||||
import org.eclipse.jface.viewers.ICheckStateListener;
|
||||
@@ -288,7 +289,30 @@ public class RemotePackagesPage extends Composite implements ISdkListener {
|
||||
}
|
||||
|
||||
private void onRemoveSiteSelected() {
|
||||
// TODO prompt for removing addon site URL, store, refresh
|
||||
boolean changed = false;
|
||||
|
||||
ISelection sel = mTreeViewerSources.getSelection();
|
||||
if (sel instanceof ITreeSelection) {
|
||||
for (Object c : ((ITreeSelection) sel).toList()) {
|
||||
if (c instanceof RepoSource && ((RepoSource) c).isUserSource()) {
|
||||
RepoSource source = (RepoSource) c;
|
||||
|
||||
String title = "Delete Site?";
|
||||
|
||||
String msg = String.format("Are you sure you want to delete the site '%1$s'?",
|
||||
source.getUrl());
|
||||
|
||||
if (MessageDialog.openQuestion(getShell(), title, msg)) {
|
||||
mUpdaterData.getSources().remove(source);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
onRefreshSelected();
|
||||
}
|
||||
}
|
||||
|
||||
private void onRefreshSelected() {
|
||||
@@ -321,19 +345,20 @@ public class RemotePackagesPage extends Composite implements ISdkListener {
|
||||
}
|
||||
|
||||
// Is there a selected site Source?
|
||||
boolean hasSelectedSource = false;
|
||||
boolean hasSelectedUserSource = false;
|
||||
ISelection sel = mTreeViewerSources.getSelection();
|
||||
if (sel instanceof ITreeSelection) {
|
||||
for (Object c : ((ITreeSelection) sel).toList()) {
|
||||
if (c instanceof RepoSource) {
|
||||
hasSelectedSource = true;
|
||||
if (c instanceof RepoSource &&
|
||||
((RepoSource) c).isUserSource()) {
|
||||
hasSelectedUserSource = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mAddSiteButton.setEnabled(true);
|
||||
mDeleteSiteButton.setEnabled(hasSelectedSource);
|
||||
mDeleteSiteButton.setEnabled(hasSelectedUserSource);
|
||||
mRefreshButton.setEnabled(true);
|
||||
mInstallSelectedButton.setEnabled(hasCheckedArchive);
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ class RepoSourcesAdapter {
|
||||
*/
|
||||
public Object[] getChildren(Object parentElement) {
|
||||
if (parentElement == RepoSourcesAdapter.this) {
|
||||
return mUpdaterData.getSources().getSources().toArray();
|
||||
return mUpdaterData.getSources().getSources();
|
||||
|
||||
} else if (parentElement instanceof RepoSource) {
|
||||
final RepoSource source = (RepoSource) parentElement;
|
||||
|
||||
@@ -356,8 +356,8 @@ class UpdaterData {
|
||||
|
||||
mTaskFactory.start("Refresh Sources",new ITask() {
|
||||
public void run(ITaskMonitor monitor) {
|
||||
ArrayList<RepoSource> sources = mSources.getSources();
|
||||
monitor.setProgressMax(sources.size());
|
||||
RepoSource[] sources = mSources.getSources();
|
||||
monitor.setProgressMax(sources.length);
|
||||
for (RepoSource source : sources) {
|
||||
if (forceFetching || source.getPackages() != null) {
|
||||
source.load(monitor.createSubMonitor(1), forceHttp);
|
||||
@@ -406,7 +406,7 @@ class UpdaterData {
|
||||
|
||||
} else {
|
||||
// Get all the available archives from all loaded sources
|
||||
ArrayList<RepoSource> remoteSources = getSources().getSources();
|
||||
RepoSource[] remoteSources = getSources().getSources();
|
||||
|
||||
for (RepoSource remoteSrc : remoteSources) {
|
||||
Package[] remotePkgs = remoteSrc.getPackages();
|
||||
|
||||
@@ -20,6 +20,7 @@ package com.android.sdkuilib.internal.repository;
|
||||
import com.android.sdklib.ISdkLog;
|
||||
import com.android.sdklib.SdkConstants;
|
||||
import com.android.sdklib.internal.repository.RepoSource;
|
||||
import com.android.sdklib.internal.repository.RepoSources;
|
||||
import com.android.sdklib.repository.SdkRepository;
|
||||
import com.android.sdkuilib.internal.repository.icons.ImageFactory;
|
||||
|
||||
@@ -93,6 +94,8 @@ public class UpdaterWindowImpl {
|
||||
display.sleep();
|
||||
}
|
||||
}
|
||||
|
||||
dispose(); //$hide$
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,12 +218,18 @@ public class UpdaterWindowImpl {
|
||||
displayPage(0);
|
||||
mPageList.setSelection(0);
|
||||
|
||||
// TODO read add-on sources from some file
|
||||
setupSources();
|
||||
initializeSettings();
|
||||
mUpdaterData.notifyListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the main loop when the window has been disposed.
|
||||
*/
|
||||
private void dispose() {
|
||||
mUpdaterData.getSources().saveUserSources();
|
||||
}
|
||||
|
||||
// --- page switching ---
|
||||
|
||||
/**
|
||||
@@ -304,17 +313,20 @@ public class UpdaterWindowImpl {
|
||||
* Used to initialize the sources.
|
||||
*/
|
||||
private void setupSources() {
|
||||
mUpdaterData.getSources().add(
|
||||
new RepoSource(SdkRepository.URL_GOOGLE_SDK_REPO_SITE, false /* addonOnly */));
|
||||
RepoSources sources = mUpdaterData.getSources();
|
||||
sources.add(new RepoSource(SdkRepository.URL_GOOGLE_SDK_REPO_SITE, false /*userSource*/));
|
||||
|
||||
String str = System.getenv("TEMP_SDK_URL"); // TODO STOPSHIP temporary remove before shipping
|
||||
if (str != null) {
|
||||
String[] urls = str.split(";");
|
||||
for (String url : urls) {
|
||||
mUpdaterData.getSources().add(new RepoSource(url, false /* addonOnly */));
|
||||
sources.add(new RepoSource(url, false /*userSource*/));
|
||||
}
|
||||
}
|
||||
|
||||
// Load user sources
|
||||
sources.loadUserSources();
|
||||
|
||||
mRemotePackagesPage.onSdkChange();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user