• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.sdkuilib.internal.repository;
18 
19 import com.android.sdklib.AndroidVersion;
20 import com.android.sdklib.SdkConstants;
21 import com.android.sdklib.internal.repository.Archive;
22 import com.android.sdklib.internal.repository.IPackageVersion;
23 import com.android.sdklib.internal.repository.Package;
24 import com.android.sdkuilib.internal.repository.icons.ImageFactory;
25 import com.android.sdkuilib.ui.GridDialog;
26 
27 import org.eclipse.jface.dialogs.IDialogConstants;
28 import org.eclipse.jface.viewers.ISelection;
29 import org.eclipse.jface.viewers.IStructuredContentProvider;
30 import org.eclipse.jface.viewers.IStructuredSelection;
31 import org.eclipse.jface.viewers.LabelProvider;
32 import org.eclipse.jface.viewers.TableViewer;
33 import org.eclipse.jface.viewers.Viewer;
34 import org.eclipse.jface.window.Window;
35 import org.eclipse.swt.SWT;
36 import org.eclipse.swt.custom.SashForm;
37 import org.eclipse.swt.custom.StyleRange;
38 import org.eclipse.swt.custom.StyledText;
39 import org.eclipse.swt.events.ControlAdapter;
40 import org.eclipse.swt.events.ControlEvent;
41 import org.eclipse.swt.events.SelectionAdapter;
42 import org.eclipse.swt.events.SelectionEvent;
43 import org.eclipse.swt.graphics.Image;
44 import org.eclipse.swt.graphics.Point;
45 import org.eclipse.swt.graphics.Rectangle;
46 import org.eclipse.swt.layout.GridData;
47 import org.eclipse.swt.layout.GridLayout;
48 import org.eclipse.swt.widgets.Button;
49 import org.eclipse.swt.widgets.Composite;
50 import org.eclipse.swt.widgets.Control;
51 import org.eclipse.swt.widgets.Group;
52 import org.eclipse.swt.widgets.Label;
53 import org.eclipse.swt.widgets.Shell;
54 import org.eclipse.swt.widgets.Table;
55 import org.eclipse.swt.widgets.TableColumn;
56 
57 import java.util.ArrayList;
58 
59 
60 /**
61  * Implements an {@link UpdateChooserDialog}.
62  */
63 final class UpdateChooserDialog extends GridDialog {
64 
65     /** Last dialog size for this session. */
66     private static Point sLastSize;
67     private boolean mLicenseAcceptAll;
68     private boolean mInternalLicenseRadioUpdate;
69 
70     // UI fields
71     private SashForm mSashForm;
72     private Composite mPackageRootComposite;
73     private TableViewer mTableViewPackage;
74     private Table mTablePackage;
75     private TableColumn mTableColum;
76     private StyledText mPackageText;
77     private Button mLicenseRadioAccept;
78     private Button mLicenseRadioReject;
79     private Button mLicenseRadioAcceptAll;
80     private Group mPackageTextGroup;
81     private final UpdaterData mUpdaterData;
82     private Group mTableGroup;
83     private Label mErrorLabel;
84 
85     /**
86      * List of all archives to be installed with dependency information.
87      *
88      * Note: in a lot of cases, we need to find the archive info for a given archive. This
89      * is currently done using a simple linear search, which is fine since we only have a very
90      * limited number of archives to deal with (e.g. < 10 now). We might want to revisit
91      * this later if it becomes an issue. Right now just do the simple thing.
92      *
93      * Typically we could add a map Archive=>ArchiveInfo later.
94      */
95     private final ArrayList<ArchiveInfo> mArchives;
96 
97 
98 
99     /**
100      * Create the dialog.
101      * @param parentShell The shell to use, typically updaterData.getWindowShell()
102      * @param updaterData The updater data
103      * @param archives The archives to be installed
104      */
UpdateChooserDialog(Shell parentShell, UpdaterData updaterData, ArrayList<ArchiveInfo> archives)105     public UpdateChooserDialog(Shell parentShell,
106             UpdaterData updaterData,
107             ArrayList<ArchiveInfo> archives) {
108         super(parentShell, 3, false/*makeColumnsEqual*/);
109         mUpdaterData = updaterData;
110         mArchives = archives;
111     }
112 
113     @Override
isResizable()114     protected boolean isResizable() {
115         return true;
116     }
117 
118     /**
119      * Returns the results, i.e. the list of selected new archives to install.
120      * This is similar to the {@link ArchiveInfo} list instance given to the constructor
121      * except only accepted archives are present.
122      *
123      * An empty list is returned if cancel was choosen.
124      */
getResult()125     public ArrayList<ArchiveInfo> getResult() {
126         ArrayList<ArchiveInfo> ais = new ArrayList<ArchiveInfo>();
127 
128         if (getReturnCode() == Window.OK) {
129             for (ArchiveInfo ai : mArchives) {
130                 if (ai.isAccepted()) {
131                     ais.add(ai);
132                 }
133             }
134         }
135 
136         return ais;
137     }
138 
139     /**
140      * Create the main content of the dialog.
141      * See also {@link #createButtonBar(Composite)} below.
142      */
143     @Override
createDialogContent(Composite parent)144     public void createDialogContent(Composite parent) {
145         // Sash form
146         mSashForm = new SashForm(parent, SWT.NONE);
147         mSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
148 
149 
150         // Left part of Sash Form
151 
152         mTableGroup = new Group(mSashForm, SWT.NONE);
153         mTableGroup.setText("Packages");
154         mTableGroup.setLayout(new GridLayout(1, false/*makeColumnsEqual*/));
155 
156         mTableViewPackage = new TableViewer(mTableGroup, SWT.BORDER | SWT.V_SCROLL | SWT.SINGLE);
157         mTablePackage = mTableViewPackage.getTable();
158         mTablePackage.setHeaderVisible(false);
159         mTablePackage.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
160 
161         mTablePackage.addSelectionListener(new SelectionAdapter() {
162             @Override
163             public void widgetSelected(SelectionEvent e) {
164                 onPackageSelected();  //$hide$
165             }
166             @Override
167             public void widgetDefaultSelected(SelectionEvent e) {
168                 onPackageDoubleClick();
169             }
170         });
171 
172         mTableColum = new TableColumn(mTablePackage, SWT.NONE);
173         mTableColum.setWidth(100);
174         mTableColum.setText("Packages");
175 
176 
177         // Right part of Sash form
178         mPackageRootComposite = new Composite(mSashForm, SWT.NONE);
179         mPackageRootComposite.setLayout(new GridLayout(4, false/*makeColumnsEqual*/));
180         mPackageRootComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
181 
182         mPackageTextGroup = new Group(mPackageRootComposite, SWT.NONE);
183         mPackageTextGroup.setText("Package Description && License");
184         mPackageTextGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1));
185         mPackageTextGroup.setLayout(new GridLayout(1, false/*makeColumnsEqual*/));
186 
187         mPackageText = new StyledText(mPackageTextGroup,
188                         SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL);
189         mPackageText.setBackground(
190                 getParentShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
191         mPackageText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
192 
193         mLicenseRadioAccept = new Button(mPackageRootComposite, SWT.RADIO);
194         mLicenseRadioAccept.setText("Accept");
195         mLicenseRadioAccept.addSelectionListener(new SelectionAdapter() {
196             @Override
197             public void widgetSelected(SelectionEvent e) {
198                 onLicenseRadioSelected();
199             }
200         });
201 
202         mLicenseRadioReject = new Button(mPackageRootComposite, SWT.RADIO);
203         mLicenseRadioReject.setText("Reject");
204         mLicenseRadioReject.addSelectionListener(new SelectionAdapter() {
205             @Override
206             public void widgetSelected(SelectionEvent e) {
207                 onLicenseRadioSelected();
208             }
209         });
210 
211         Label placeholder = new Label(mPackageRootComposite, SWT.NONE);
212         placeholder.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
213 
214         mLicenseRadioAcceptAll = new Button(mPackageRootComposite, SWT.RADIO);
215         mLicenseRadioAcceptAll.setText("Accept All");
216         mLicenseRadioAcceptAll.addSelectionListener(new SelectionAdapter() {
217             @Override
218             public void widgetSelected(SelectionEvent e) {
219                 onLicenseRadioSelected();
220             }
221         });
222 
223         mSashForm.setWeights(new int[] {200, 300});
224     }
225 
226     /**
227      * Creates and returns the contents of this dialog's button bar.
228      * <p/>
229      * This reimplements most of the code from the base class with a few exceptions:
230      * <ul>
231      * <li>Enforces 3 columns.
232      * <li>Inserts a full-width error label.
233      * <li>Inserts a help label on the left of the first button.
234      * <li>Renames the OK button into "Install"
235      * </ul>
236      */
createButtonBar(Composite parent)237     @Override
238     protected Control createButtonBar(Composite parent) {
239 
240         Composite composite = new Composite(parent, SWT.NONE);
241         GridLayout layout = new GridLayout();
242         layout.numColumns = 0; // this is incremented by createButton
243         layout.makeColumnsEqualWidth = false;
244         layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
245         layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
246         layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
247         layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
248         composite.setLayout(layout);
249         GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
250         composite.setLayoutData(data);
251         composite.setFont(parent.getFont());
252 
253         // Error message area
254         mErrorLabel = new Label(composite, SWT.NONE);
255         mErrorLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
256 
257         // Label at the left of the install/cancel buttons
258         Label label = new Label(composite, SWT.NONE);
259         label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
260         label.setText("[*] Something depends on this package");
261         label.setEnabled(false);
262         layout.numColumns++;
263 
264         // Add the ok/cancel to the button bar.
265         createButtonsForButtonBar(composite);
266 
267         // the ok button should be an "install" button
268         Button button = getButton(IDialogConstants.OK_ID);
269         button.setText("Install");
270 
271         return composite;
272     }
273 
274     // -- End of UI, Start of internal logic ----------
275     // Hide everything down-below from SWT designer
276     //$hide>>$
277 
create()278     @Override
279     public void create() {
280         super.create();
281 
282         // set window title
283         getShell().setText("Choose Packages to Install");
284 
285         setWindowImage();
286 
287         // Automatically accept those with an empty license or no license
288         for (ArchiveInfo ai : mArchives) {
289             Archive a = ai.getNewArchive();
290             assert a != null;
291 
292             String license = a.getParentPackage().getLicense();
293             ai.setAccepted(license == null || license.trim().length() == 0);
294         }
295 
296         // Fill the list with the replacement packages
297         mTableViewPackage.setLabelProvider(new NewArchivesLabelProvider());
298         mTableViewPackage.setContentProvider(new NewArchivesContentProvider());
299         mTableViewPackage.setInput(mArchives);
300 
301         adjustColumnsWidth();
302 
303         // select first item
304         mTablePackage.select(0);
305         onPackageSelected();
306     }
307 
308     /**
309      * Creates the icon of the window shell.
setWindowImage()310      */
311     private void setWindowImage() {
312         String imageName = "android_icon_16.png"; //$NON-NLS-1$
313         if (SdkConstants.currentPlatform() == SdkConstants.PLATFORM_DARWIN) {
314             imageName = "android_icon_128.png"; //$NON-NLS-1$
315         }
316 
317         if (mUpdaterData != null) {
318             ImageFactory imgFactory = mUpdaterData.getImageFactory();
319             if (imgFactory != null) {
320                 getShell().setImage(imgFactory.getImageByName(imageName));
321             }
322         }
323     }
324 
325     /**
326      * Adds a listener to adjust the columns width when the parent is resized.
327      * <p/>
328      * If we need something more fancy, we might want to use this:
329      * http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet77.java?view=co
adjustColumnsWidth()330      */
331     private void adjustColumnsWidth() {
332         // Add a listener to resize the column to the full width of the table
333         ControlAdapter resizer = new ControlAdapter() {
334             @Override
335             public void controlResized(ControlEvent e) {
336                 Rectangle r = mTablePackage.getClientArea();
337                 mTableColum.setWidth(r.width);
338             }
339         };
340         mTablePackage.addControlListener(resizer);
341         resizer.controlResized(null);
342     }
343 
344     /**
345      * Captures the window size before closing this.
346      * @see #getInitialSize()
347      */
close()348     @Override
349     public boolean close() {
350         sLastSize = getShell().getSize();
351         return super.close();
352     }
353 
354     /**
355      * Tries to reuse the last window size during this session.
356      * <p/>
357      * Note: the alternative would be to implement {@link #getDialogBoundsSettings()}
358      * since the default {@link #getDialogBoundsStrategy()} is to persist both location
359      * and size.
360      */
getInitialSize()361     @Override
362     protected Point getInitialSize() {
363         if (sLastSize != null) {
364             return sLastSize;
365         } else {
366             // Arbitrary values that look good on my screen and fit on 800x600
367             return new Point(740, 370);
368         }
369     }
370 
371     /**
372      * Callback invoked when a package item is selected in the list.
onPackageSelected()373      */
374     private void onPackageSelected() {
375         ArchiveInfo ai = getSelectedArchive();
376         displayInformation(ai);
377         displayMissingDependency(ai);
378         updateLicenceRadios(ai);
379     }
380 
getSelectedArchive()381     /** Returns the currently selected {@link ArchiveInfo} or null. */
382     private ArchiveInfo getSelectedArchive() {
383         ISelection sel = mTableViewPackage.getSelection();
384         if (sel instanceof IStructuredSelection) {
385             Object elem = ((IStructuredSelection) sel).getFirstElement();
386             if (elem instanceof ArchiveInfo) {
387                 return (ArchiveInfo) elem;
388             }
389         }
390         return null;
391     }
392 
393     /**
394      * Updates the package description and license text depending on the selected package.
displayInformation(ArchiveInfo ai)395      */
396     private void displayInformation(ArchiveInfo ai) {
397         if (ai == null) {
398             mPackageText.setText("Please select a package.");
399             return;
400         }
401 
402         Archive aNew = ai.getNewArchive();
403         Package pNew = aNew.getParentPackage();
404 
405         mPackageText.setText("");                                                //$NON-NLS-1$
406 
407         addSectionTitle("Package Description\n");
408         addText(pNew.getLongDescription(), "\n\n");          //$NON-NLS-1$
409 
410         Archive aOld = ai.getReplaced();
411         if (aOld != null) {
412             Package pOld = aOld.getParentPackage();
413 
414             int rOld = pOld.getRevision();
415             int rNew = pNew.getRevision();
416 
417             boolean showRev = true;
418 
419             if (pNew instanceof IPackageVersion && pOld instanceof IPackageVersion) {
420                 AndroidVersion vOld = ((IPackageVersion) pOld).getVersion();
421                 AndroidVersion vNew = ((IPackageVersion) pNew).getVersion();
422 
423                 if (!vOld.equals(vNew)) {
424                     // Versions are different, so indicate more than just the revision.
425                     addText(String.format("This update will replace API %1$s revision %2$d with API %3$s revision %4$d.\n\n",
426                             vOld.getApiString(), rOld,
427                             vNew.getApiString(), rNew));
428                     showRev = false;
429                 }
430             }
431 
432             if (showRev) {
433                 addText(String.format("This update will replace revision %1$d with revision %2$d.\n\n",
434                         rOld,
435                         rNew));
436             }
437         }
438 
439         ArchiveInfo aDep = ai.getDependsOn();
440         if (aDep != null || ai.isDependencyFor()) {
441             addSectionTitle("Dependencies\n");
442 
443             if (aDep != null) {
444                 addText(String.format("This package depends on %1$s.\n\n",
445                         aDep.getNewArchive().getParentPackage().getShortDescription()));
446             }
447 
448             if (ai.isDependencyFor()) {
449                 addText("This package is a dependency for:");
450                 for (ArchiveInfo ai2 : ai.getDependenciesFor()) {
451                     addText("\n- " +
452                             ai2.getNewArchive().getParentPackage().getShortDescription());
453                 }
454                 addText("\n\n");
455             }
456         }
457 
458         addSectionTitle("Archive Description\n");
459         addText(aNew.getLongDescription(), "\n\n");                             //$NON-NLS-1$
460 
461         String license = pNew.getLicense();
462         if (license != null) {
463             addSectionTitle("License\n");
464             addText(license.trim(), "\n\n");                                       //$NON-NLS-1$
465         }
466 
467         addSectionTitle("Site\n");
468         addText(pNew.getParentSource().getShortDescription());
469     }
470 
471     /**
472      * Computes and display missing dependency.
473      * If there's a selected package, check the dependency for that one.
474      * Otherwise display the first missing dependency.
displayMissingDependency(ArchiveInfo ai)475      */
476     private void displayMissingDependency(ArchiveInfo ai) {
477         String error = null;
478 
479         try {
480             if (ai != null) {
481 
482                 if (!ai.isAccepted()) {
483                     // Case where this package blocks another one when not accepted
484                     for (ArchiveInfo ai2 : ai.getDependenciesFor()) {
485                         // It only matters if the blocked one is accepted
486                         if (ai2.isAccepted()) {
487                             error = String.format("Package '%1$s' depends on this one.",
488                                     ai2.getNewArchive().getParentPackage().getShortDescription());
489                             return;
490                         }
491                     }
492                 } else {
493                     // Case where this package is accepted but blocked by another non-accepted one
494                     ArchiveInfo adep = ai.getDependsOn();
495                     if (adep != null && !adep.isAccepted()) {
496                         error = String.format("This package depends on '%1$s'.",
497                                 adep.getNewArchive().getParentPackage().getShortDescription());
498                         return;
499                     }
500                 }
501             }
502 
503             // If there's no selection, just find the first missing dependency of any accepted
504             // package.
505             for (ArchiveInfo ai2 : mArchives) {
506                 if (ai2.isAccepted()) {
507                     ArchiveInfo adep = ai2.getDependsOn();
508                     if (adep != null && !adep.isAccepted()) {
509                         error = String.format("Package '%1$s' depends on '%2$s'",
510                                 ai2.getNewArchive().getParentPackage().getShortDescription(),
511                                 adep.getNewArchive().getParentPackage().getShortDescription());
512                         return;
513                     }
514                 }
515             }
516         } finally {
517             mErrorLabel.setText(error == null ? "" : error);        //$NON-NLS-1$
518         }
519     }
addText(String...string)520 
521     private void addText(String...string) {
522         for (String s : string) {
523             mPackageText.append(s);
524         }
525     }
addSectionTitle(String string)526 
527     private void addSectionTitle(String string) {
528         String s = mPackageText.getText();
529         int start = (s == null ? 0 : s.length());
530         mPackageText.append(string);
531 
532         StyleRange sr = new StyleRange();
533         sr.start = start;
534         sr.length = string.length();
535         sr.fontStyle = SWT.BOLD;
536         sr.underline = true;
537         mPackageText.setStyleRange(sr);
538     }
updateLicenceRadios(ArchiveInfo ai)539 
540     private void updateLicenceRadios(ArchiveInfo ai) {
541         if (mInternalLicenseRadioUpdate) {
542             return;
543         }
544         mInternalLicenseRadioUpdate = true;
545 
546         boolean oneAccepted = false;
547 
548         if (mLicenseAcceptAll) {
549             mLicenseRadioAcceptAll.setSelection(true);
550             mLicenseRadioAccept.setEnabled(true);
551             mLicenseRadioReject.setEnabled(true);
552             mLicenseRadioAccept.setSelection(false);
553             mLicenseRadioReject.setSelection(false);
554         } else {
555             mLicenseRadioAcceptAll.setSelection(false);
556             oneAccepted = ai != null && ai.isAccepted();
557             mLicenseRadioAccept.setEnabled(ai != null);
558             mLicenseRadioReject.setEnabled(ai != null);
559             mLicenseRadioAccept.setSelection(oneAccepted);
560             mLicenseRadioReject.setSelection(ai != null && ai.isRejected());
561         }
562 
563         // The install button is enabled if there's at least one package accepted.
564         // If the current one isn't, look for another one.
565         boolean missing = mErrorLabel.getText() != null && mErrorLabel.getText().length() > 0;
566         if (!missing && !oneAccepted) {
567             for(ArchiveInfo ai2 : mArchives) {
568                 if (ai2.isAccepted()) {
569                     oneAccepted = true;
570                     break;
571                 }
572             }
573         }
574 
575         getButton(IDialogConstants.OK_ID).setEnabled(!missing && oneAccepted);
576 
577         mInternalLicenseRadioUpdate = false;
578     }
579 
580     /**
581      * Callback invoked when one of the radio license buttons is selected.
582      *
583      * - accept/refuse: toggle, update item checkbox
584      * - accept all: set accept-all, check all items
onLicenseRadioSelected()585      */
586     private void onLicenseRadioSelected() {
587         if (mInternalLicenseRadioUpdate) {
588             return;
589         }
590         mInternalLicenseRadioUpdate = true;
591 
592         ArchiveInfo ai = getSelectedArchive();
593         boolean needUpdate = true;
594 
595         if (!mLicenseAcceptAll && mLicenseRadioAcceptAll.getSelection()) {
596             // Accept all has been switched on. Mark all packages as accepted
597             mLicenseAcceptAll = true;
598             for(ArchiveInfo ai2 : mArchives) {
599                 ai2.setAccepted(true);
600                 ai2.setRejected(false);
601             }
602 
603         } else if (mLicenseRadioAccept.getSelection()) {
604             // Accept only this one
605             mLicenseAcceptAll = false;
606             ai.setAccepted(true);
607             ai.setRejected(false);
608 
609         } else if (mLicenseRadioReject.getSelection()) {
610             // Reject only this one
611             mLicenseAcceptAll = false;
612             ai.setAccepted(false);
613             ai.setRejected(true);
614 
615         } else {
616             needUpdate = false;
617         }
618 
619         mInternalLicenseRadioUpdate = false;
620 
621         if (needUpdate) {
622             if (mLicenseAcceptAll) {
623                 mTableViewPackage.refresh();
624             } else {
625                mTableViewPackage.refresh(ai);
626             }
627             displayMissingDependency(ai);
628             updateLicenceRadios(ai);
629         }
630     }
631 
632     /**
633      * Callback invoked when a package item is double-clicked in the list.
onPackageDoubleClick()634      */
635     private void onPackageDoubleClick() {
636         ArchiveInfo ai = getSelectedArchive();
637 
638         boolean wasAccepted = ai.isAccepted();
639         ai.setAccepted(!wasAccepted);
640         ai.setRejected(wasAccepted);
641 
642         // update state
643         mLicenseAcceptAll = false;
644         mTableViewPackage.refresh(ai);
645         updateLicenceRadios(ai);
646     }
647 
648     private class NewArchivesLabelProvider extends LabelProvider {
getImage(Object element)649         @Override
650         public Image getImage(Object element) {
651             assert element instanceof ArchiveInfo;
652             ArchiveInfo ai = (ArchiveInfo) element;
653 
654             ImageFactory imgFactory = mUpdaterData.getImageFactory();
655             if (imgFactory != null) {
656                 if (ai.isAccepted()) {
657                     return imgFactory.getImageByName("accept_icon16.png");
658                 } else if (ai.isRejected()) {
659                     return imgFactory.getImageByName("reject_icon16.png");
660                 }
661                 return imgFactory.getImageByName("unknown_icon16.png");
662             }
663             return super.getImage(element);
664         }
665 
getText(Object element)666         @Override
667         public String getText(Object element) {
668             assert element instanceof ArchiveInfo;
669             ArchiveInfo ai = (ArchiveInfo) element;
670 
671             String desc = ai.getNewArchive().getParentPackage().getShortDescription();
672 
673             if (ai.isDependencyFor()) {
674                 desc += " [*]";
675             }
676 
677             return desc;
678         }
679     }
680 
681     private class NewArchivesContentProvider implements IStructuredContentProvider {
dispose()682 
683         public void dispose() {
684             // pass
685         }
inputChanged(Viewer viewer, Object oldInput, Object newInput)686 
687         public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
688             // Ignore. The input is always mArchives
689         }
getElements(Object inputElement)690 
691         public Object[] getElements(Object inputElement) {
692             return mArchives.toArray();
693         }
694     }
695 
696     // End of hiding from SWT Designer
697     //$hide<<$
698 }
699