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.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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<<$
|
||||
|
||||
}
|
||||
@@ -1,7 +1,23 @@
|
||||
package com.android.sdkuilib.repository;
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import com.android.sdkuilib.repository.ProgressTask.ThreadTask;
|
||||
import com.android.sdkuilib.repository.UpdaterWindow.UpdaterData;
|
||||
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<<$
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<<$
|
||||
}
|
||||
|
Before Width: | Height: | Size: 460 B After Width: | Height: | Size: 460 B |
@@ -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<<$
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.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
|
||||
*
|
||||
* 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.repository;
|
||||
|
||||
import org.eclipse.swt.widgets.ProgressBar;
|
||||
|
||||
/**
|
||||
* A monitor interface for a {@link ProgressTask}
|
||||
*/
|
||||
interface ITaskMonitor {
|
||||
|
||||
/**
|
||||
* Sets the description in the current task dialog.
|
||||
* This method can be invoke from a non-UI thread.
|
||||
*/
|
||||
public void setDescription(String description);
|
||||
|
||||
/**
|
||||
* Sets the result text in the current task dialog.
|
||||
* This method can be invoked from a non-UI thread.
|
||||
*/
|
||||
public void setResult(String result);
|
||||
|
||||
/**
|
||||
* Sets the max value of the progress bar.
|
||||
* This method can be invoke from a non-UI thread.
|
||||
*
|
||||
* @see ProgressBar#setMaximum(int)
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
public boolean cancelRequested();
|
||||
|
||||
|
||||
}
|
||||
@@ -1,316 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Eclipse Public License, Version 1.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
|
||||
*
|
||||
* 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.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;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
import javax.xml.validation.Validator;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class RepoSource {
|
||||
|
||||
private final String mUrl;
|
||||
private final boolean mAddonOnly;
|
||||
|
||||
private ArrayList<String> mPackages;
|
||||
private String mDescription;
|
||||
|
||||
/**
|
||||
* Constructs a new source for the given repository URL.
|
||||
*/
|
||||
public RepoSource(String url, boolean addonOnly) {
|
||||
mUrl = url;
|
||||
mAddonOnly = addonOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mUrl;
|
||||
}
|
||||
|
||||
/** Returns the URL of the source repository. */
|
||||
public String getUrl() {
|
||||
return mUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of known packages. This is null when the source hasn't been loaded yet.
|
||||
*/
|
||||
public ArrayList<String> getPackages() {
|
||||
return mPackages;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return mDescription == null ? "" : mDescription; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to fetch the repository index for the given URL.
|
||||
*/
|
||||
public void load(Shell shell) {
|
||||
|
||||
ProgressTask.start(shell, "Init SDK Updater", new ThreadTask() {
|
||||
public void PerformTask(ITaskMonitor monitor) {
|
||||
monitor.setProgressMax(4);
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
monitor.setDescription("Validate XML");
|
||||
monitor.incProgress(1);
|
||||
|
||||
if (!validateXml(xml, monitor)) {
|
||||
mDescription = String.format("Failed to validate XML at %1$s", mUrl);
|
||||
return;
|
||||
}
|
||||
|
||||
monitor.setDescription("Parse XML");
|
||||
monitor.incProgress(1);
|
||||
parsePackages(xml, monitor);
|
||||
|
||||
// done
|
||||
monitor.incProgress(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* References:
|
||||
* Java URL Connection: http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html
|
||||
* Java URL Reader: http://java.sun.com/docs/books/tutorial/networking/urls/readingURL.html
|
||||
* Java set Proxy: http://java.sun.com/docs/books/tutorial/networking/urls/_setProxy.html
|
||||
*/
|
||||
private String fetchUrl(String urlString, ITaskMonitor monitor) {
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(urlString);
|
||||
|
||||
StringBuilder xml = new StringBuilder();
|
||||
InputStream is = null;
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
is = url.openStream();
|
||||
br = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
xml.append(line);
|
||||
}
|
||||
|
||||
return xml.toString();
|
||||
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
monitor.setResult(e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean validateXml(String xml, ITaskMonitor monitor) {
|
||||
|
||||
try {
|
||||
Validator validator = getValidator();
|
||||
validator.validate(new StreamSource(new StringReader(xml)));
|
||||
return true;
|
||||
|
||||
} catch (SAXException e) {
|
||||
monitor.setResult(e.getMessage());
|
||||
|
||||
} catch (IOException e) {
|
||||
monitor.setResult(e.getMessage());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Helper method that returns a validator for our XSD */
|
||||
private Validator getValidator() throws SAXException {
|
||||
InputStream xsdStream = SdkRepository.getXsdStream();
|
||||
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
|
||||
// This may throw a SAX Exception if the schema itself is not a valid XSD
|
||||
Schema schema = factory.newSchema(new StreamSource(xsdStream));
|
||||
|
||||
Validator validator = schema.newValidator();
|
||||
|
||||
return validator;
|
||||
}
|
||||
|
||||
|
||||
private boolean parsePackages(String xml, ITaskMonitor monitor) {
|
||||
|
||||
try {
|
||||
Document doc = getDocument(xml);
|
||||
|
||||
Node root = getFirstChild(doc, SdkRepository.NODE_SDK_REPOSITORY);
|
||||
if (root != null) {
|
||||
|
||||
mPackages = new ArrayList<String>();
|
||||
|
||||
for (Node child = root.getFirstChild();
|
||||
child != null;
|
||||
child = child.getNextSibling()) {
|
||||
if (child.getNodeType() == Node.ELEMENT_NODE &&
|
||||
child.getNamespaceURI().equals(SdkRepository.NS_SDK_REPOSITORY)) {
|
||||
String name = child.getLocalName();
|
||||
if (SdkRepository.NODE_ADD_ON.equals(name)) {
|
||||
parseAddon(child, mPackages, monitor);
|
||||
|
||||
} else if (!mAddonOnly) {
|
||||
if (SdkRepository.NODE_PLATFORM.equals(name)) {
|
||||
parsePlatform(child, mPackages, monitor);
|
||||
|
||||
} else if (SdkRepository.NODE_DOC.equals(name)) {
|
||||
parseDoc(child, mPackages, monitor);
|
||||
|
||||
} else if (SdkRepository.NODE_TOOL.equals(name)) {
|
||||
parseTool(child, mPackages, monitor);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} catch (ParserConfigurationException e) {
|
||||
monitor.setResult("Failed to create XML document builder for %1$s");
|
||||
|
||||
} catch (SAXException e) {
|
||||
monitor.setResult("Failed to parse XML document %1$s");
|
||||
|
||||
} catch (IOException e) {
|
||||
monitor.setResult("Failed to read XML document");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Node getFirstChild(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Document getDocument(String xml)
|
||||
throws ParserConfigurationException, SAXException, IOException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setIgnoringComments(true);
|
||||
factory.setNamespaceAware(true);
|
||||
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document doc = builder.parse(new InputSource(new StringReader(xml)));
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
private void parseAddon(Node addon, ArrayList<String> packages, ITaskMonitor monitor) {
|
||||
// TODO Auto-generated method stub
|
||||
String s = String.format("addon %1$s by %2$s, api %3$s, rev %4$s",
|
||||
getFirstChild(addon, SdkRepository.NODE_NAME).getTextContent(),
|
||||
getFirstChild(addon, SdkRepository.NODE_VENDOR).getTextContent(),
|
||||
getFirstChild(addon, SdkRepository.NODE_API_LEVEL).getTextContent(),
|
||||
getFirstChild(addon, SdkRepository.NODE_REVISION).getTextContent()
|
||||
);
|
||||
packages.add(s);
|
||||
}
|
||||
|
||||
private void parsePlatform(Node platform, ArrayList<String> packages, ITaskMonitor monitor) {
|
||||
// TODO Auto-generated method stub
|
||||
String s = String.format("platform %1$s, api %2$s, rev %3$s",
|
||||
getFirstChild(platform, SdkRepository.NODE_VERSION).getTextContent(),
|
||||
getFirstChild(platform, SdkRepository.NODE_API_LEVEL).getTextContent(),
|
||||
getFirstChild(platform, SdkRepository.NODE_REVISION).getTextContent()
|
||||
);
|
||||
packages.add(s);
|
||||
}
|
||||
|
||||
private void parseDoc(Node doc, ArrayList<String> packages, ITaskMonitor monitor) {
|
||||
// TODO Auto-generated method stub
|
||||
String s = String.format("doc for api %1$s, rev %2$s",
|
||||
getFirstChild(doc, SdkRepository.NODE_API_LEVEL).getTextContent(),
|
||||
getFirstChild(doc, SdkRepository.NODE_REVISION).getTextContent()
|
||||
);
|
||||
packages.add(s);
|
||||
}
|
||||
|
||||
private void parseTool(Node tool, ArrayList<String> packages, ITaskMonitor monitor) {
|
||||
// TODO Auto-generated method stub
|
||||
String s = String.format("tool, rev %1$s",
|
||||
getFirstChild(tool, SdkRepository.NODE_REVISION).getTextContent()
|
||||
);
|
||||
packages.add(s);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
private UpdaterWindowImpl mWindow;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public UpdaterWindow(String osSdkRoot, boolean userCanChangeSdkRoot) {
|
||||
mUpdaterData.setOsSdkRoot(osSdkRoot);
|
||||
mUpdaterData.setUserCanChangeSdkRoot(userCanChangeSdkRoot);
|
||||
mWindow = new UpdaterWindowImpl(osSdkRoot, userCanChangeSdkRoot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the window.
|
||||
* @wbp.parser.entryPoint
|
||||
* Opens the window.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
mWindow.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(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
|
||||
|
||||
}
|
||||
|
||||
// End of hiding from SWT Designer
|
||||
//$hide<<$
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user