javamanager/javainstaller/installerui/javasrc/com/nokia/mj/impl/installer/ui/eswt2/ViewBase.java
changeset 21 2a9601315dfc
child 23 98ccebc37403
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 package com.nokia.mj.impl.installer.ui.eswt2;
       
    20 
       
    21 import com.nokia.mj.impl.installer.ui.ApplicationInfo;
       
    22 import com.nokia.mj.impl.installer.ui.InstallInfo;
       
    23 import com.nokia.mj.impl.installer.ui.UninstallInfo;
       
    24 import com.nokia.mj.impl.security.midp.common.SigningCertificate;
       
    25 
       
    26 import java.io.InputStream;
       
    27 
       
    28 import org.eclipse.swt.SWT;
       
    29 import org.eclipse.swt.custom.ScrolledComposite;
       
    30 import org.eclipse.swt.events.SelectionEvent;
       
    31 import org.eclipse.swt.events.SelectionListener;
       
    32 import org.eclipse.swt.graphics.Image;
       
    33 import org.eclipse.swt.graphics.Point;
       
    34 import org.eclipse.swt.graphics.Rectangle;
       
    35 import org.eclipse.swt.layout.GridData;
       
    36 import org.eclipse.swt.layout.GridLayout;
       
    37 import org.eclipse.swt.widgets.Button;
       
    38 import org.eclipse.swt.widgets.Composite;
       
    39 import org.eclipse.swt.widgets.Control;
       
    40 import org.eclipse.swt.widgets.Display;
       
    41 import org.eclipse.swt.widgets.Label;
       
    42 import org.eclipse.swt.widgets.Shell;
       
    43 
       
    44 /**
       
    45  * Base class for different InstallerUi views.
       
    46  */
       
    47 abstract public class ViewBase
       
    48 {
       
    49     /** Maximum view height in percentage from display client area height. */
       
    50     protected static final int MAX_VIEW_HEIGHT = 80;
       
    51     /** Parent shell for this view. */
       
    52     protected Shell iParent = null;
       
    53     /** Container for the contents of the view */
       
    54     private Composite iContainer = null;
       
    55     /** ScrolledComposite for iComposite. */
       
    56     private ScrolledComposite iScrolledComposite = null;
       
    57     /** Composite to which subclasses add their widgets. */
       
    58     private Composite iComposite = null;
       
    59     /** ScrolledComposite for iAppInfoComposite. */
       
    60     private ScrolledComposite iAppInfoScrolledComposite = null;
       
    61     /** Composite to which application info is added. */
       
    62     private Composite iAppInfoComposite = null;
       
    63     /** Composite to which command buttons are added. */
       
    64     private Composite iCommandComposite = null;
       
    65     /** Application suite icon */
       
    66     protected Image iSuiteIcon = null;
       
    67     /** InstallerUi owning this view. */
       
    68     protected InstallerUiEswt iInstallerUi = null;
       
    69     /** True if this view is visible. */
       
    70     private boolean iVisible = false;
       
    71     /** Number of columns for this view's GridLayout. */
       
    72     private int iColumns = 1;
       
    73     /** Default content size. */
       
    74     private Point iDefaultContentSize = null;
       
    75     /** Certificate details view.  */
       
    76     private CertificateDetailsView iCertificateDetailsView = null;
       
    77     /** Certificates for this application. */
       
    78     private SigningCertificate[] iCertificates = null;
       
    79 
       
    80     /** Constructor */
       
    81     protected ViewBase()
       
    82     {
       
    83     }
       
    84 
       
    85     /** Constructor */
       
    86     protected ViewBase(InstallerUiEswt aInstaller, Composite aParent, int aColumns)
       
    87     {
       
    88         this(aInstaller, aParent, aColumns, false);
       
    89     }
       
    90 
       
    91     /** Constructor */
       
    92     protected ViewBase(InstallerUiEswt aInstaller, Composite aParent, int aColumns, boolean aScrollable)
       
    93     {
       
    94         iInstallerUi = aInstaller;
       
    95 
       
    96         // Each view gets a shell to be used as a parameter.
       
    97         iParent = (Shell)aParent;
       
    98 
       
    99         iContainer = new Composite(iParent, 0);
       
   100         iContainer.setVisible(false);
       
   101 
       
   102         iColumns = aColumns;
       
   103 
       
   104         // Store the default bounds for later height adjustments.
       
   105         Rectangle defShellBounds = iInstallerUi.getDefaultShellBounds();
       
   106         Rectangle defShellClientBounds = iInstallerUi.getDefaultShellClientBounds();
       
   107         iContainer.setSize(defShellClientBounds.width, defShellClientBounds.height);
       
   108 
       
   109         // Let the contents fill the Shell.
       
   110         iContainer.setLayout(setZeroMargins(new GridLayout()));
       
   111 
       
   112         if (aScrollable)
       
   113         {
       
   114             // Create a ScrolledComposite for views which need ScrollBars.
       
   115             iScrolledComposite = new ScrolledComposite(iContainer, getStyle());
       
   116             iScrolledComposite.setAlwaysShowScrollBars(false);
       
   117             iScrolledComposite.setExpandHorizontal(true);
       
   118             iScrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
       
   119             // Create the content composite for the ScrolledComposite.
       
   120             iComposite = new Composite(iScrolledComposite, SWT.NONE);
       
   121             iComposite.setLayout(setZeroMargins(new GridLayout(getColumns(), true)));
       
   122             iScrolledComposite.setContent(iComposite);
       
   123         }
       
   124         else
       
   125         {
       
   126             // Create the composite without ScrollBars.
       
   127             iComposite = new Composite(iContainer, SWT.NONE);
       
   128             GridLayout compLayout =
       
   129                 setZeroMargins(new GridLayout(getColumns(), true));
       
   130             iComposite.setLayout(compLayout);
       
   131             iComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
       
   132         }
       
   133 
       
   134         // Create a composite for command buttons.
       
   135         iCommandComposite = new Composite(iContainer, SWT.NONE);
       
   136         GridLayout cmdLayout = setZeroMargins(new GridLayout(2, true));
       
   137         cmdLayout.marginTop = 5;
       
   138         iCommandComposite.setLayout(cmdLayout);
       
   139         iCommandComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
       
   140 
       
   141         // Layout now and get the default size of the content area.
       
   142         iContainer.layout(true);
       
   143         Rectangle rect = null;
       
   144         if (aScrollable)
       
   145         {
       
   146             rect = iScrolledComposite.getClientArea();
       
   147         }
       
   148         else
       
   149         {
       
   150             rect = iComposite.getClientArea();
       
   151         }
       
   152         iDefaultContentSize = new Point(rect.width, rect.height);
       
   153     }
       
   154 
       
   155     /**
       
   156      * Returns composite which holds the contents of this view.
       
   157      */
       
   158     public Composite getContainer()
       
   159     {
       
   160         return iContainer;
       
   161     }
       
   162 
       
   163     /** Returns composite to which subclasses can add their widgets. */
       
   164     public Composite getComposite()
       
   165     {
       
   166         return iComposite;
       
   167     }
       
   168 
       
   169     /** Returns ScrolledComposite for Composite. */
       
   170     public ScrolledComposite getScrolledComposite()
       
   171     {
       
   172         return iScrolledComposite;
       
   173     }
       
   174 
       
   175     /** Returns composite for application info widgets. */
       
   176     public Composite getAppInfoComposite()
       
   177     {
       
   178         return iAppInfoComposite;
       
   179     }
       
   180 
       
   181     /** Returns ScrolledComposite for AppInfoComposite. */
       
   182     public ScrolledComposite getAppInfoScrolledComposite()
       
   183     {
       
   184         return iAppInfoScrolledComposite;
       
   185     }
       
   186 
       
   187     /** Returns composite to which command buttons are added. */
       
   188     public Composite getCommandComposite()
       
   189     {
       
   190         return iCommandComposite;
       
   191     }
       
   192 
       
   193     /** Returns a shell for this view. */
       
   194     public Shell getShell()
       
   195     {
       
   196         return iParent;
       
   197     }
       
   198 
       
   199     /** Returns display for this view. */
       
   200     public Display getDisplay()
       
   201     {
       
   202         return getShell().getDisplay();
       
   203     }
       
   204 
       
   205     /**
       
   206      * Returns title for this view. If the title has not been
       
   207      * set, returns an empty string.
       
   208      */
       
   209     public String getTitle()
       
   210     {
       
   211         return iParent.getText();
       
   212     }
       
   213 
       
   214     /** Set title for this view. */
       
   215     public void setTitle(String aTitle)
       
   216     {
       
   217         // Dialog shells have no title anymore
       
   218     }
       
   219 
       
   220     /** Disposes this view. */
       
   221     public void dispose()
       
   222     {
       
   223         // This must be final because it is used from inner class.
       
   224         final String className = this.toString();
       
   225         log(className + ": disposing");
       
   226         // UI updates must be executed in UI thread.
       
   227         iParent.getDisplay().syncExec
       
   228         (new Runnable()
       
   229         {
       
   230             public void run()
       
   231             {
       
   232                 log(className + ": disposing view container");
       
   233                 iContainer.dispose();
       
   234             }
       
   235         });
       
   236     }
       
   237 
       
   238     /** Returns true this view has been disposed, false otherwise. */
       
   239     public boolean isDisposed()
       
   240     {
       
   241         if (iContainer.isDisposed())
       
   242         {
       
   243             return true;
       
   244         }
       
   245         return false;
       
   246     }
       
   247 
       
   248     /** Set this view visible. Any previously visible view will be hidden.
       
   249      *  The size of the dialog Shell host will be changed to fit this view.*/
       
   250     public void setVisible(boolean aVisible)
       
   251     {
       
   252         if (iVisible == aVisible)
       
   253         {
       
   254             return;
       
   255         }
       
   256         log(this.toString() + ": setVisible " + aVisible);
       
   257         iVisible = aVisible;
       
   258         if (iVisible)
       
   259         {
       
   260             iInstallerUi.setActiveView(this);
       
   261         }
       
   262         else
       
   263         {
       
   264             if (iInstallerUi.getActiveView() == this)
       
   265             {
       
   266                 iInstallerUi.setActiveView(null);
       
   267             }
       
   268         }
       
   269         // UI updates must be executed in UI thread.
       
   270         iParent.getDisplay().syncExec
       
   271         (new Runnable()
       
   272         {
       
   273             public void run()
       
   274             {
       
   275                 if (iVisible)
       
   276                 {
       
   277                     updateSize();
       
   278                 }
       
   279                 iContainer.setVisible(iVisible);
       
   280                 if (iVisible)
       
   281                 {
       
   282                     if (iParent.getDisplay().getActiveShell() != iParent)
       
   283                     {
       
   284                         iParent.open();
       
   285                     }
       
   286                     if (!iParent.isVisible())
       
   287                     {
       
   288                         iParent.setVisible(true);
       
   289                     }
       
   290                     if (forceFocusToView())
       
   291                     {
       
   292                         iContainer.forceFocus();
       
   293                     }
       
   294                 }
       
   295             }
       
   296         });
       
   297     }
       
   298 
       
   299     /** Returns true if this view is visible, false otherwise. */
       
   300     public boolean isVisible()
       
   301     {
       
   302         return iVisible;
       
   303     }
       
   304 
       
   305     /** Sets the view size according to display size. */
       
   306     protected void updateSize()
       
   307     {
       
   308         getShell().setRedraw(false);
       
   309         // First calculate size without vertical scrollbar.
       
   310         doUpdateSize(false);
       
   311         if (getScrolledComposite() != null &&
       
   312                 getScrolledComposite().getVerticalBar() != null &&
       
   313                 getScrolledComposite().getVerticalBar().getVisible())
       
   314         {
       
   315             // If scrollbar is visible recalculate size with scrollbar.
       
   316             doUpdateSize(true);
       
   317         }
       
   318         getShell().setRedraw(true);
       
   319     }
       
   320 
       
   321     /** Sets the view size according to display size. */
       
   322     private void doUpdateSize(boolean aVerticalScrollBarVisible)
       
   323     {
       
   324         Shell shell = getShell();
       
   325         Composite comp = getComposite();
       
   326         Composite cmdComp = getCommandComposite();
       
   327 
       
   328         if (getAppInfoComposite() != null)
       
   329         {
       
   330             // Recalculate the size of the app info composite.
       
   331             getAppInfoComposite().setSize(
       
   332                 getAppInfoComposite().computeSize(
       
   333                     SWT.DEFAULT, SWT.DEFAULT));
       
   334         }
       
   335 
       
   336         int contentWidth = iDefaultContentSize.x;
       
   337         if (aVerticalScrollBarVisible)
       
   338         {
       
   339             int verticalScrollBarWidth =
       
   340                 getScrolledComposite().getVerticalBar().getSize().x;
       
   341             contentWidth = iDefaultContentSize.x - verticalScrollBarWidth;
       
   342         }
       
   343 
       
   344         // Recalculate the size of the content.
       
   345         Point contentSize = comp.computeSize(contentWidth, SWT.DEFAULT);
       
   346         comp.setSize(contentSize);
       
   347         Point cmdContentSize = cmdComp.computeSize(iDefaultContentSize.x, SWT.DEFAULT);
       
   348         cmdComp.setSize(cmdContentSize);
       
   349 
       
   350         // Adjust Shell height. The Shell never changes the x position, nor the width.
       
   351         Rectangle dispRect = shell.getDisplay().getClientArea();
       
   352         int offset = iDefaultContentSize.y - contentSize.y - cmdContentSize.y;
       
   353 
       
   354         Rectangle defShellBounds = iInstallerUi.getDefaultShellBounds();
       
   355         int newHeight = defShellBounds.height - offset;
       
   356         int maxHeight = dispRect.height * MAX_VIEW_HEIGHT / 100;
       
   357 
       
   358         if (newHeight > maxHeight)
       
   359         {
       
   360             offset -= maxHeight - newHeight;
       
   361             newHeight = maxHeight;
       
   362         }
       
   363 
       
   364         Rectangle dispBounds = shell.getDisplay().getBounds();
       
   365         int y = dispBounds.height - newHeight;
       
   366         // Always center vertically.
       
   367         y /= 2;
       
   368         // For landscape orientation center vertically
       
   369         //if (dispRect.width > dispRect.height)
       
   370         //{
       
   371         //    y /= 2;
       
   372         //}
       
   373         // Set bounds when command Buttons are in use.
       
   374         shell.setBounds(defShellBounds.x, y, defShellBounds.width, newHeight);
       
   375         Rectangle clientArea = shell.getClientArea();
       
   376         iContainer.setSize(clientArea.width, clientArea.height);
       
   377         iContainer.layout(true);
       
   378     }
       
   379 
       
   380     /**
       
   381      * Called when screen orientation changes.
       
   382      */
       
   383     protected void screenOrientationChanged()
       
   384     {
       
   385         updateSize();
       
   386     }
       
   387 
       
   388     /**
       
   389      * Returns true if the View should have focus after it has been opened.
       
   390      */
       
   391     protected boolean forceFocusToView()
       
   392     {
       
   393         return true;
       
   394     }
       
   395 
       
   396     /**
       
   397      * Returns SWT style for this view. Subclasses should override
       
   398      * this method to return style with SWT.H_SCROLL and/or SWT.V_SCROLL
       
   399      * if they need scrollbars.
       
   400      */
       
   401     protected int getStyle()
       
   402     {
       
   403         return SWT.NONE;
       
   404     }
       
   405 
       
   406     /**
       
   407      * Returns number of columns for this view.
       
   408      */
       
   409     protected int getColumns()
       
   410     {
       
   411         return iColumns;
       
   412     }
       
   413 
       
   414     /**
       
   415      * Adds header used in installation and uninstallation views.
       
   416      */
       
   417     protected void addHeader(
       
   418         String aTitle, InstallInfo aInstallInfo, UninstallInfo aUninstallInfo)
       
   419     {
       
   420         // Add title.
       
   421         String title = "Install?";
       
   422         if (aInstallInfo != null)
       
   423         {
       
   424             if (aInstallInfo.getOldVersion() != null)
       
   425             {
       
   426                 title = "Update?";
       
   427             }
       
   428             iCertificates = aInstallInfo.getCertificates();
       
   429         }
       
   430         if (aUninstallInfo != null)
       
   431         {
       
   432             title = "Uninstall?";
       
   433             iCertificates = aUninstallInfo.getCertificates();
       
   434         }
       
   435         Label titleLabel = createLabel(aTitle, getColumns() - 1, SWT.WRAP);
       
   436         titleLabel.setFont(iInstallerUi.getBoldFont());
       
   437 
       
   438         // Add security icon.
       
   439         createSecurityButton();
       
   440 
       
   441         // Add suite icon.
       
   442         InputStream iconInputStream = null;
       
   443         String iconPath = null;
       
   444         if (aInstallInfo != null)
       
   445         {
       
   446             iconInputStream = aInstallInfo.getIconInputStream();
       
   447             iconPath = aInstallInfo.getIconPath();
       
   448         }
       
   449         if (aUninstallInfo != null)
       
   450         {
       
   451             iconInputStream = aUninstallInfo.getIconInputStream();
       
   452             iconPath = aUninstallInfo.getIconPath();
       
   453         }
       
   454         if (iSuiteIcon == null && iconInputStream != null)
       
   455         {
       
   456             iSuiteIcon = InstallerUiEswt.loadImage(
       
   457                              getComposite().getDisplay(), iconInputStream, iconPath);
       
   458         }
       
   459         int iconColumns = 0;
       
   460         if (iSuiteIcon != null)
       
   461         {
       
   462             iconColumns = 2;
       
   463             Label iconLabel = createLabel(iSuiteIcon, iconColumns, SWT.NONE);
       
   464         }
       
   465 
       
   466         // Create a Composite for displaying application info.
       
   467         iAppInfoScrolledComposite =
       
   468             new ScrolledComposite(getComposite(), SWT.H_SCROLL | SWT.V_SCROLL);
       
   469         iAppInfoScrolledComposite.setAlwaysShowScrollBars(false);
       
   470         iAppInfoScrolledComposite.setExpandHorizontal(true);
       
   471         GridData gridData = new GridData(GridData.FILL_BOTH);
       
   472         gridData.horizontalSpan = getColumns() - iconColumns;
       
   473         iAppInfoScrolledComposite.setLayoutData(gridData);
       
   474         iAppInfoComposite = new Composite(iAppInfoScrolledComposite, SWT.NONE);
       
   475         iAppInfoComposite.setLayout(new GridLayout(1, true));
       
   476         iAppInfoScrolledComposite.setContent(iAppInfoComposite);
       
   477     }
       
   478 
       
   479     /**
       
   480      * Adds application information to the header.
       
   481      */
       
   482     protected void addAppInfo(InstallInfo aInstallInfo, boolean aFull)
       
   483     {
       
   484         if (aInstallInfo == null)
       
   485         {
       
   486             // Nothing to add.
       
   487             return;
       
   488         }
       
   489 
       
   490         // Add suite name.
       
   491         createAppInfoLabel(
       
   492             aInstallInfo.getName() + " " + aInstallInfo.getVersion());
       
   493         // Add size.
       
   494         long size = 0;
       
   495         if (aInstallInfo.getJarSize() > 0)
       
   496         {
       
   497             size += aInstallInfo.getJarSize();
       
   498         }
       
   499         if (aInstallInfo.getDataSize() > 0)
       
   500         {
       
   501             size += aInstallInfo.getDataSize();
       
   502         }
       
   503         if (size > 0)
       
   504         {
       
   505             createAppInfoLabel(
       
   506                 InstallerUiTexts.get(
       
   507                     InstallerUiTexts.SIZE,
       
   508                     new String[] { Long.toString(1 + size/1024) }));
       
   509         }
       
   510         if (aFull)
       
   511         {
       
   512             // Add vendor.
       
   513             if (aInstallInfo.getCertificates() != null)
       
   514             {
       
   515                 // Vendor information must be displayed only for
       
   516                 // identified applications.
       
   517                 createAppInfoLabel(
       
   518                     InstallerUiTexts.get(
       
   519                         InstallerUiTexts.VENDOR,
       
   520                         new String[] { aInstallInfo.getVendor() }));
       
   521             }
       
   522             // Add application names.
       
   523             ApplicationInfo[] apps = aInstallInfo.getApplications();
       
   524             if (apps != null && apps.length > 0)
       
   525             {
       
   526                 if (apps.length > 1 ||
       
   527                         !aInstallInfo.getName().equals(apps[0].getName()))
       
   528                 {
       
   529                     for (int i = 0; i < apps.length; i++)
       
   530                     {
       
   531                         createAppInfoLabel(apps[i].getName());
       
   532                     }
       
   533                 }
       
   534             }
       
   535         }
       
   536     }
       
   537 
       
   538     /**
       
   539      * Creates a new label with given text and adds it to this view.
       
   540      * The created label takes one column from this view's GridLayout.
       
   541      *
       
   542      * @param aText text for the label
       
   543      * @param aStyle SWT style for the label
       
   544      * @return label that was added to this view
       
   545      */
       
   546     protected Label createLabel(String aText, int aStyle)
       
   547     {
       
   548         return createLabel(aText, getColumns(), aStyle);
       
   549     }
       
   550 
       
   551     /**
       
   552      * Creates a new label with given text and adds it to this view.
       
   553      *
       
   554      * @param aText text for the label
       
   555      * @param aColumns number of columns the label takes
       
   556      * @param aStyle SWT style for the label
       
   557      * @return label that was added to this view
       
   558      */
       
   559     protected Label createLabel(String aText, int aColumns, int aStyle)
       
   560     {
       
   561         Label label = new Label(getComposite(), aStyle);
       
   562         label.setText(aText);
       
   563         GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
       
   564         gridData.horizontalSpan = aColumns;
       
   565         label.setLayoutData(gridData);
       
   566         return label;
       
   567     }
       
   568 
       
   569     /**
       
   570      * Creates a new label with given image and adds it to this view.
       
   571      * The created label takes one column from this view's GridLayout.
       
   572      *
       
   573      * @param aImage image for the label
       
   574      * @param aStyle SWT style for the label
       
   575      * @return label that was added to this view
       
   576      */
       
   577     protected Label createLabel(Image aImage, int aStyle)
       
   578     {
       
   579         return createLabel(aImage, getColumns(), aStyle);
       
   580     }
       
   581 
       
   582     /**
       
   583      * Creates a new label with given image and adds it to this view.
       
   584      * The created label takes one column from this view's GridLayout.
       
   585      *
       
   586      * @param aImage image for the label
       
   587      * @param aColumns number of columns the label takes
       
   588      * @param aStyle SWT style for the label
       
   589      * @return label that was added to this view
       
   590      */
       
   591     protected Label createLabel(Image aImage, int aColumns, int aStyle)
       
   592     {
       
   593         Label label = new Label(getComposite(), aStyle);
       
   594         label.setImage(aImage);
       
   595         GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
       
   596         gridData.horizontalSpan = aColumns;
       
   597         gridData.horizontalAlignment = SWT.CENTER;
       
   598         gridData.verticalAlignment = SWT.CENTER;
       
   599         label.setLayoutData(gridData);
       
   600         return label;
       
   601     }
       
   602 
       
   603     /**
       
   604      * Creates a new label with given text and adds it
       
   605      * to application info composite for this view.
       
   606      *
       
   607      * @param aText text for the label
       
   608      * @return label that was added to this view
       
   609      */
       
   610     protected Label createAppInfoLabel(String aText)
       
   611     {
       
   612         Label label = new Label(getAppInfoComposite(), SWT.WRAP);
       
   613         label.setText(aText);
       
   614         GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
       
   615         gridData.horizontalSpan = 1;
       
   616         label.setLayoutData(gridData);
       
   617         return label;
       
   618     }
       
   619 
       
   620     /**
       
   621      * Creates a new label with security icon.
       
   622      *
       
   623      * @param aIdentified true if security icon is for an
       
   624      * identified application, false otherwise
       
   625      * @return label that was added to this view
       
   626      */
       
   627     protected Label createSecurityLabel(boolean aIdentified)
       
   628     {
       
   629         Label label = createLabel((Image)null, 1, SWT.NONE);
       
   630         Image securityIcon = null;
       
   631         if (iInstallerUi instanceof InstallerUiEswt)
       
   632         {
       
   633             securityIcon = ((InstallerUiEswt)iInstallerUi).getSecurityIcon
       
   634                            (getDisplay(), aIdentified);
       
   635         }
       
   636         if (securityIcon != null)
       
   637         {
       
   638             label.setImage(securityIcon);
       
   639         }
       
   640         else
       
   641         {
       
   642             label.setText(aIdentified? "I": "U");
       
   643         }
       
   644         return label;
       
   645     }
       
   646 
       
   647     protected Button createSecurityButton()
       
   648     {
       
   649         Button button = new Button(getComposite(), SWT.PUSH);
       
   650         GridData gridData = new GridData(
       
   651             GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
       
   652         gridData.horizontalSpan = 1;
       
   653         gridData.horizontalAlignment = SWT.CENTER;
       
   654         gridData.verticalAlignment = SWT.CENTER;
       
   655         button.setLayoutData(gridData);
       
   656         Image securityIcon = null;
       
   657         if (iInstallerUi instanceof InstallerUiEswt)
       
   658         {
       
   659             securityIcon =
       
   660                 ((InstallerUiEswt)iInstallerUi).getSecurityIcon(
       
   661                     getDisplay(), iCertificates != null);
       
   662         }
       
   663         if (securityIcon != null)
       
   664         {
       
   665             button.setImage(securityIcon);
       
   666         }
       
   667         else
       
   668         {
       
   669             button.setText(iCertificates != null? "I": "U");
       
   670         }
       
   671         button.addSelectionListener(new SelectionListener()
       
   672         {
       
   673             public void widgetDefaultSelected(SelectionEvent aEvent)
       
   674             {
       
   675                 widgetSelected(aEvent);
       
   676             }
       
   677             public void widgetSelected(SelectionEvent aEvent)
       
   678             {
       
   679                 openCertsView(iCertificates, (iCertificates != null? 0: -1));
       
   680             }
       
   681         });
       
   682         return button;
       
   683     }
       
   684 
       
   685     /**
       
   686      * Sets margins and spacing for the given layout to zero.
       
   687      */
       
   688     protected GridLayout setZeroMargins(GridLayout aLayout)
       
   689     {
       
   690         aLayout.horizontalSpacing = 0;
       
   691         aLayout.verticalSpacing = 0;
       
   692         aLayout.marginBottom = 0;
       
   693         aLayout.marginTop = 0;
       
   694         aLayout.marginHeight = 0;
       
   695         aLayout.marginWidth = 0;
       
   696         aLayout.marginLeft = 0;
       
   697         aLayout.marginRight = 0;
       
   698         return aLayout;
       
   699     }
       
   700 
       
   701     protected void log(String aMsg)
       
   702     {
       
   703         if (iInstallerUi != null)
       
   704         {
       
   705             iInstallerUi.log(aMsg);
       
   706         }
       
   707     }
       
   708 
       
   709     protected void logError(String aMsg, Throwable aThrowable)
       
   710     {
       
   711         if (iInstallerUi != null)
       
   712         {
       
   713             iInstallerUi.logError(aMsg, aThrowable);
       
   714         }
       
   715     }
       
   716 
       
   717     /**
       
   718      * Opens certificate information view.
       
   719      */
       
   720     protected void openCertsView(SigningCertificate[] aCerts, int aCertIndex)
       
   721     {
       
   722         iCertificateDetailsView = new CertificateDetailsView(
       
   723             iInstallerUi, getShell(), getTitle(), aCerts, aCertIndex);
       
   724         // New dialog must be opened in a new thread,
       
   725         // because we cannot use the main thread and we
       
   726         // cannot block the UI main thread
       
   727         // where this method gets executed.
       
   728         new Thread(new Runnable()
       
   729         {
       
   730             public void run()
       
   731             {
       
   732                 if (iCertificateDetailsView.confirm())
       
   733                 {
       
   734                     log("certificateDetailsView confirmed");
       
   735                 }
       
   736                 else
       
   737                 {
       
   738                     log("certificateDetailsView cancelled");
       
   739                 }
       
   740                 iCertificateDetailsView.dispose();
       
   741                 iCertificateDetailsView = null;
       
   742                 setVisible(true);
       
   743             }
       
   744         }, "InstallerUiCertViewThread").start();
       
   745     }
       
   746 }