OSDN Git Service

SDK Manager: select just new or just updates.
authorRaphael <raphael@google.com>
Fri, 7 Oct 2011 19:54:19 +0000 (12:54 -0700)
committerRaphael <raphael@google.com>
Fri, 7 Oct 2011 19:54:19 +0000 (12:54 -0700)
This splits the "Select New/Updates" link in the
SDK Manager in 2 parts. Behavior is:
- at startup, the sdk manager selects both new and updates.
- one can click on deselect + select new to select
  just new packages.
- one can click on deselect + select updates to select
  just update packages.
- select does not select first, so clicking both new
  then update will produce the previous behavior.

SDK Bug: 20607

Change-Id: Ib861d78b746f4f3c7a8fce421c89ae8094339933

sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogic.java
sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackagesPage.java
sdkmanager/libs/sdkuilib/tests/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogicTest.java

index 3a70294..f3fa261 100755 (executable)
@@ -89,7 +89,7 @@ class PackagesDiffLogic {
      * <li> If some platform is partially installed, selected anything new/update for it.
      * </ul>
      */
-    public void checkNewUpdateItems() {
+    public void checkNewUpdateItems(boolean selectNew, boolean selectUpdates) {
         int maxApi = 0;
         Set<Integer> installedPlatforms = new HashSet<Integer>();
         Map<Integer, List<PkgItem>> platformItems = new HashMap<Integer, List<PkgItem>>();
@@ -123,7 +123,8 @@ class PackagesDiffLogic {
                 items.add(item);
             } else {
                 // not a plaform package...
-                if (item.getState() == PkgState.NEW || item.hasUpdatePkg()) {
+                if ((selectNew && item.getState() == PkgState.NEW) ||
+                        (selectUpdates && item.hasUpdatePkg())) {
                     item.setChecked(true);
                 }
             }
@@ -134,7 +135,8 @@ class PackagesDiffLogic {
             List<PkgItem> items = platformItems.get(api);
             if (items != null) {
                 for (PkgItem item : items) {
-                    if (item.getState() == PkgState.NEW || item.hasUpdatePkg()) {
+                    if ((selectNew && item.getState() == PkgState.NEW) ||
+                            (selectUpdates && item.hasUpdatePkg())) {
                         item.setChecked(true);
                     }
                 }
@@ -146,7 +148,8 @@ class PackagesDiffLogic {
             List<PkgItem> items = platformItems.get(maxApi);
             if (items != null) {
                 for (PkgItem item : items) {
-                    if (item.getState() == PkgState.NEW || item.hasUpdatePkg()) {
+                    if ((selectNew && item.getState() == PkgState.NEW) ||
+                            (selectUpdates && item.hasUpdatePkg())) {
                         item.setChecked(true);
                     }
                 }
index bb72745..d16972f 100755 (executable)
@@ -291,14 +291,20 @@ public class PackagesPage extends UpdaterPage
         mCheckFilterObsolete.setSelection(false);
 
         Link linkSelectNew = new Link(mGroupOptions, SWT.NONE);
-        linkSelectNew.setText("<a>Select New/Updates</a>");
+        // Note for i18n: we need to identify which link is used, and this is done by using the
+        // text itself so for translation purposes we want to keep the <a> link strings separate.
+        final String strLinkNew = "New";
+        final String strLinkUpdates = "Updates";
+        linkSelectNew.setText(
+                String.format("Select <a>%1$s</a> or <a>%2$s</a>", strLinkNew, strLinkUpdates));
         linkSelectNew.setToolTipText("Selects all items that are either new or updates.");
         GridDataBuilder.create(linkSelectNew).hFill().hGrab();
         linkSelectNew.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 super.widgetSelected(e);
-                onSelectNewUpdates();
+                boolean selectNew = e.text == null || e.text.equals(strLinkNew);
+                onSelectNewUpdates(selectNew, !selectNew);
             }
         });
 
@@ -620,7 +626,7 @@ public class PackagesPage extends UpdaterPage
                                 // automatically select all new and update packages.
                                 Object[] checked = mTreeViewer.getCheckedElements();
                                 if (checked == null || checked.length == 0) {
-                                    onSelectNewUpdates();
+                                    onSelectNewUpdates(true, true);
                                 }
                             }
                         }
@@ -869,9 +875,9 @@ public class PackagesPage extends UpdaterPage
     /**
      * Checks all PkgItems that are either new or have updates.
      */
-    private void onSelectNewUpdates() {
+    private void onSelectNewUpdates(boolean selectNew, boolean selectUpdates) {
         // This does not update the tree itself, syncViewerSelection does it below.
-        mDiffLogic.checkNewUpdateItems();
+        mDiffLogic.checkNewUpdateItems(selectNew, selectUpdates);
         syncViewerSelection();
         updateButtonsState();
     }
index eeec341..499421f 100755 (executable)
@@ -807,7 +807,7 @@ public class PackagesDiffLogicTest extends TestCase {
         assertFalse(m.isFirstLoadComplete());
     }
 
-    public void testCheckNewUpdateItems() {
+    public void testCheckNewUpdateItems_NewOnly() {
         // Populate the list with a few items and an update
         SdkSource src1 = new SdkRepoSource("http://example.com/url", "repo1");
         m.updateStart();
@@ -835,24 +835,70 @@ public class PackagesDiffLogicTest extends TestCase {
                 "-- <INSTALLED, pkg:MockEmptyPackage 'no update' rev=4>\n",
                 getTree(m, false /*displaySortByApi*/));
 
-        // Now request to check new and update items
-        m.checkNewUpdateItems();
+        // Now request to check new items only
+        m.checkNewUpdateItems(true, false);
 
         assertEquals(
                 "PkgCategoryApi <API=TOOLS, label=Tools, #items=0>\n" +
                 "PkgCategoryApi <API=EXTRAS, label=Extras, #items=3>\n" +
-                "-- < * INSTALLED, pkg:MockEmptyPackage 'has update' rev=1, updated by:MockEmptyPackage 'has update' rev=2>\n" +
+                "-- <INSTALLED, pkg:MockEmptyPackage 'has update' rev=1, updated by:MockEmptyPackage 'has update' rev=2>\n" +
                 "-- < * NEW, pkg:MockEmptyPackage 'new stuff' rev=3>\n" +
                 "-- <INSTALLED, pkg:MockEmptyPackage 'no update' rev=4>\n",
                 getTree(m, true /*displaySortByApi*/));
         assertEquals(
                 "PkgCategorySource <source=repo1 (example.com), #items=3>\n" +
-                "-- < * INSTALLED, pkg:MockEmptyPackage 'has update' rev=1, updated by:MockEmptyPackage 'has update' rev=2>\n" +
+                "-- <INSTALLED, pkg:MockEmptyPackage 'has update' rev=1, updated by:MockEmptyPackage 'has update' rev=2>\n" +
                 "-- < * NEW, pkg:MockEmptyPackage 'new stuff' rev=3>\n" +
                 "-- <INSTALLED, pkg:MockEmptyPackage 'no update' rev=4>\n",
                 getTree(m, false /*displaySortByApi*/));
     }
 
+    public void testCheckNewUpdateItems_UpdateOnly() {
+        // Populate the list with a few items and an update
+        SdkSource src1 = new SdkRepoSource("http://example.com/url", "repo1");
+        m.updateStart();
+        m.updateSourcePackages(true /*sortByApi*/, null /*locals*/, new Package[] {
+                new MockEmptyPackage(src1, "has update", 1),
+                new MockEmptyPackage(src1, "no update", 4)
+        });
+        m.updateSourcePackages(true /*sortByApi*/, src1, new Package[] {
+                new MockEmptyPackage(src1, "has update", 2),
+                new MockEmptyPackage(src1, "new stuff", 3),
+        });
+        m.updateEnd(true /*sortByApi*/);
+        // Nothing is checked at first
+        assertEquals(
+                "PkgCategoryApi <API=TOOLS, label=Tools, #items=0>\n" +
+                "PkgCategoryApi <API=EXTRAS, label=Extras, #items=3>\n" +
+                "-- <INSTALLED, pkg:MockEmptyPackage 'has update' rev=1, updated by:MockEmptyPackage 'has update' rev=2>\n" +
+                "-- <NEW, pkg:MockEmptyPackage 'new stuff' rev=3>\n" +
+                "-- <INSTALLED, pkg:MockEmptyPackage 'no update' rev=4>\n",
+                getTree(m, true /*displaySortByApi*/));
+        assertEquals(
+                "PkgCategorySource <source=repo1 (example.com), #items=3>\n" +
+                "-- <INSTALLED, pkg:MockEmptyPackage 'has update' rev=1, updated by:MockEmptyPackage 'has update' rev=2>\n" +
+                "-- <NEW, pkg:MockEmptyPackage 'new stuff' rev=3>\n" +
+                "-- <INSTALLED, pkg:MockEmptyPackage 'no update' rev=4>\n",
+                getTree(m, false /*displaySortByApi*/));
+
+        // Now request to check update items only
+        m.checkNewUpdateItems(false, true);
+
+        assertEquals(
+                "PkgCategoryApi <API=TOOLS, label=Tools, #items=0>\n" +
+                "PkgCategoryApi <API=EXTRAS, label=Extras, #items=3>\n" +
+                "-- < * INSTALLED, pkg:MockEmptyPackage 'has update' rev=1, updated by:MockEmptyPackage 'has update' rev=2>\n" +
+                "-- <NEW, pkg:MockEmptyPackage 'new stuff' rev=3>\n" +
+                "-- <INSTALLED, pkg:MockEmptyPackage 'no update' rev=4>\n",
+                getTree(m, true /*displaySortByApi*/));
+        assertEquals(
+                "PkgCategorySource <source=repo1 (example.com), #items=3>\n" +
+                "-- < * INSTALLED, pkg:MockEmptyPackage 'has update' rev=1, updated by:MockEmptyPackage 'has update' rev=2>\n" +
+                "-- <NEW, pkg:MockEmptyPackage 'new stuff' rev=3>\n" +
+                "-- <INSTALLED, pkg:MockEmptyPackage 'no update' rev=4>\n",
+                getTree(m, false /*displaySortByApi*/));
+    }
+
     public void testCheckNewUpdateItems_SelectInitial() {
         // Populate the list with typical items: tools, platforms tools, extras, 2 platforms.
         // With nothing installed, this should pick the tools, extras and the top platform.
@@ -878,7 +924,7 @@ public class PackagesDiffLogicTest extends TestCase {
         });
         m.updateEnd(true /*sortByApi*/);
 
-        m.checkNewUpdateItems();
+        m.checkNewUpdateItems(true, true);
 
         assertEquals(
                 "PkgCategoryApi <API=TOOLS, label=Tools, #items=2>\n" +
@@ -930,7 +976,7 @@ public class PackagesDiffLogicTest extends TestCase {
         });
         m.updateEnd(true /*sortByApi*/);
 
-        m.checkNewUpdateItems();
+        m.checkNewUpdateItems(true, true);
 
         assertEquals(
                 "PkgCategoryApi <API=TOOLS, label=Tools, #items=2>\n" +