javamanager/javainstaller/installerui/javasrc/com/nokia/mj/impl/installer/ui/eswt/PermissionConfirmationView.java
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     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.eswt;
       
    20 
       
    21 import com.nokia.mj.impl.installer.ui.InstallInfo;
       
    22 import com.nokia.mj.impl.installer.ui.PermissionInfo;
       
    23 import com.nokia.mj.impl.security.midp.common.SigningCertificate;
       
    24 
       
    25 import java.io.InputStream;
       
    26 
       
    27 import org.eclipse.swt.SWT;
       
    28 import org.eclipse.swt.SWTException;
       
    29 import org.eclipse.swt.events.FocusEvent;
       
    30 import org.eclipse.swt.events.FocusListener;
       
    31 import org.eclipse.swt.events.KeyEvent;
       
    32 import org.eclipse.swt.graphics.Image;
       
    33 import org.eclipse.swt.graphics.Point;
       
    34 import org.eclipse.swt.layout.GridData;
       
    35 import org.eclipse.swt.widgets.Composite;
       
    36 import org.eclipse.swt.widgets.Button;
       
    37 import org.eclipse.swt.widgets.Event;
       
    38 import org.eclipse.swt.widgets.Label;
       
    39 import org.eclipse.swt.widgets.Link;
       
    40 import org.eclipse.swt.widgets.Listener;
       
    41 import org.eclipse.swt.widgets.Shell;
       
    42 
       
    43 /**
       
    44  * PermissionConfirmationView asks permissions confirmation
       
    45  * from the user.
       
    46  */
       
    47 public class PermissionConfirmationView extends ConfirmationViewBase
       
    48 {
       
    49     private PermissionDetailsView iPermissionDetailsView = null;
       
    50     private CertificateDetailsView iCertificateDetailsView = null;
       
    51     private InstallInfo iInstallInfo = null;
       
    52     private PermissionInfo iPermissionInfo = null;
       
    53     /** Application suite icon */
       
    54     private Image iSuiteIcon = null;
       
    55     private Button iAllowButton = null;
       
    56     private Button iDenyButton = null;
       
    57 
       
    58     /** Constructor */
       
    59     protected PermissionConfirmationView()
       
    60     {
       
    61         super();
       
    62     }
       
    63 
       
    64     /** Constructor */
       
    65     protected PermissionConfirmationView(InstallerUiEswt aInstaller, Composite aParent)
       
    66     {
       
    67         super(aInstaller, aParent, 8);
       
    68         setTitle(InstallerUiTexts.get(InstallerUiTexts.INSTALL));
       
    69         setCommands(null, InstallerUiTexts.get(InstallerUiTexts.CANCEL));
       
    70     }
       
    71 
       
    72     /**
       
    73      * Synchoronous method for asking user confirmation.
       
    74      */
       
    75     public boolean confirm(InstallInfo aInstallInfo,
       
    76                            PermissionInfo aPermissionInfo)
       
    77     {
       
    78         iInstallInfo = aInstallInfo;
       
    79         iPermissionInfo = aPermissionInfo;
       
    80         boolean result = confirm();
       
    81         if (result)
       
    82         {
       
    83             log("permissionConfirmationView confirmed");
       
    84         }
       
    85         else
       
    86         {
       
    87             log("permissionConfirmationView cancelled");
       
    88         }
       
    89         return result;
       
    90     }
       
    91 
       
    92     /**
       
    93      * This method is called once before view is opened.
       
    94      */
       
    95     protected void createView()
       
    96     {
       
    97         GridData gridData = null;
       
    98         int horizontalSpan = getColumns() - 1;
       
    99         int labelStyle = SWT.WRAP;
       
   100 
       
   101         // Add suite icon.
       
   102         InputStream iconInputStream = iInstallInfo.getIconInputStream();
       
   103         if (iconInputStream != null)
       
   104         {
       
   105             iSuiteIcon = InstallerUiEswt.loadImage
       
   106                          (getComposite().getDisplay(), iconInputStream,
       
   107                           iInstallInfo.getIconPath());
       
   108             if (iSuiteIcon != null)
       
   109             {
       
   110                 Label iconLabel = createLabel(iSuiteIcon, 2, SWT.NONE);
       
   111                 horizontalSpan = getColumns() - 3;
       
   112             }
       
   113             else
       
   114             {
       
   115                 horizontalSpan = getColumns() - 1;
       
   116             }
       
   117         }
       
   118 
       
   119         // Add title.
       
   120         String title = InstallerUiTexts.get
       
   121                        (InstallerUiTexts.INSTALL_QUERY,
       
   122                         new String[] { iInstallInfo.getName() });
       
   123         if (iInstallInfo.getOldVersion() != null)
       
   124         {
       
   125             title = InstallerUiTexts.get
       
   126                     (InstallerUiTexts.UPDATE_QUERY,
       
   127                      new String[] { iInstallInfo.getName(),
       
   128                                     iInstallInfo.getOldVersion(),
       
   129                                     iInstallInfo.getVersion()
       
   130                                   });
       
   131         }
       
   132         Label titleLabel = createLabel(title, horizontalSpan, labelStyle);
       
   133         titleLabel.setFont(iInstallerUi.getBoldFont());
       
   134 
       
   135         // Add security icon.
       
   136         boolean identified = (iInstallInfo.getCertificates() != null);
       
   137         Label securityIconLabel = createSecurityLabel(identified);
       
   138 
       
   139         horizontalSpan = getColumns();
       
   140 
       
   141         // Add permission query label.
       
   142         Label domainLabel = createLabel(
       
   143                                 InstallerUiTexts.get(InstallerUiTexts.PERM_QUERY),
       
   144                                 horizontalSpan, labelStyle);
       
   145 
       
   146         // Add allow button.
       
   147         iAllowButton = new Button(getComposite(), SWT.NONE);
       
   148         iAllowButton.setText(InstallerUiTexts.get
       
   149                              (InstallerUiTexts.PERM_ALLOW_ALWAYS));
       
   150         iAllowButton.addListener(SWT.Selection, new Listener()
       
   151         {
       
   152             public void handleEvent(Event aEvent)
       
   153             {
       
   154                 iPermissionInfo.setPermissionAllowed(true);
       
   155                 confirmOk();
       
   156             }
       
   157         });
       
   158         iAllowButton.addFocusListener(new FocusListener()
       
   159         {
       
   160             public void focusGained(FocusEvent aEvent)
       
   161             {
       
   162                 if (!userHasAnswered())
       
   163                 {
       
   164                     iPermissionInfo.setPermissionAllowed(true);
       
   165                 }
       
   166             }
       
   167             public void focusLost(FocusEvent aEvent)
       
   168             {
       
   169                 // nop
       
   170             }
       
   171         });
       
   172         gridData = new GridData(GridData.FILL_HORIZONTAL);
       
   173         gridData.horizontalSpan = horizontalSpan;
       
   174         iAllowButton.setLayoutData(gridData);
       
   175         iAllowButton.setFocus();
       
   176         addSoftKeyListenerFor(iAllowButton);
       
   177 
       
   178         // Add deny button.
       
   179         iDenyButton = new Button(getComposite(), SWT.NONE);
       
   180         iDenyButton.setText(InstallerUiTexts.get
       
   181                             (InstallerUiTexts.PERM_ASK_ME_LATER));
       
   182         iDenyButton.addListener(SWT.Selection, new Listener()
       
   183         {
       
   184             public void handleEvent(Event aEvent)
       
   185             {
       
   186                 iPermissionInfo.setPermissionAllowed(false);
       
   187                 confirmOk();
       
   188             }
       
   189         });
       
   190         iDenyButton.addFocusListener(new FocusListener()
       
   191         {
       
   192             public void focusGained(FocusEvent aEvent)
       
   193             {
       
   194                 if (!userHasAnswered())
       
   195                 {
       
   196                     iPermissionInfo.setPermissionAllowed(false);
       
   197                 }
       
   198             }
       
   199             public void focusLost(FocusEvent aEvent)
       
   200             {
       
   201                 // nop
       
   202             }
       
   203         });
       
   204         gridData = new GridData(GridData.FILL_HORIZONTAL);
       
   205         gridData.horizontalSpan = horizontalSpan;
       
   206         iDenyButton.setLayoutData(gridData);
       
   207         addSoftKeyListenerFor(iDenyButton);
       
   208 
       
   209         // Add link for permission details.
       
   210         if (iPermissionInfo != null &&
       
   211                 iPermissionInfo.getPermissionNames() != null &&
       
   212                 iPermissionInfo.getPermissionNames().length > 0)
       
   213         {
       
   214             Link detailsLink = new Link(getComposite(), SWT.NONE);
       
   215             detailsLink.setText("<a>" +
       
   216                                 InstallerUiTexts.get(
       
   217                                     InstallerUiTexts.PERM_VIEW_DETAILS) +
       
   218                                 "</a>");
       
   219             detailsLink.addListener(SWT.Selection, new Listener()
       
   220             {
       
   221                 public void handleEvent(Event aEvent)
       
   222                 {
       
   223                     openDetailsView();
       
   224                 }
       
   225             });
       
   226             gridData = new GridData(GridData.FILL_HORIZONTAL);
       
   227             gridData.horizontalSpan = horizontalSpan;
       
   228             detailsLink.setLayoutData(gridData);
       
   229             addSoftKeyListenerFor(detailsLink);
       
   230         }
       
   231 
       
   232         // Add links for certificate details.
       
   233         SigningCertificate[] certs = iInstallInfo.getCertificates();
       
   234         if (certs != null)
       
   235         {
       
   236             // Add link to the first certificate only, it is the one
       
   237             // that will be used for MIDP2 applications.
       
   238             for (int i = 0; i < 1; i++)
       
   239             {
       
   240                 Link certLink = new Link(getComposite(), SWT.NONE);
       
   241                 certLink.setText("<a>" +
       
   242                                  InstallerUiTexts.get
       
   243                                  (InstallerUiTexts.CERTIFICATE_INFO) +
       
   244                                  "</a>");
       
   245                 final int certIndex = i;
       
   246                 certLink.addListener(SWT.Selection, new Listener()
       
   247                 {
       
   248                     public void handleEvent(Event aEvent)
       
   249                     {
       
   250                         openCertsView(certIndex);
       
   251                     }
       
   252                 });
       
   253                 gridData = new GridData(GridData.FILL_HORIZONTAL);
       
   254                 gridData.horizontalSpan = horizontalSpan;
       
   255                 certLink.setLayoutData(gridData);
       
   256                 addSoftKeyListenerFor(certLink);
       
   257             }
       
   258         }
       
   259 
       
   260     }
       
   261 
       
   262     /**
       
   263      * This method is called after user has answered
       
   264      * to confirmation.
       
   265      */
       
   266     protected void getDataFromView()
       
   267     {
       
   268         // nop
       
   269     }
       
   270 
       
   271     /**
       
   272      * Returns true if the View should have focus after it has been opened.
       
   273      */
       
   274     protected boolean forceFocusToView()
       
   275     {
       
   276         return false;
       
   277     }
       
   278 
       
   279     /**
       
   280      * Returns SWT style for this view.
       
   281      */
       
   282     protected int getStyle()
       
   283     {
       
   284         return SWT.V_SCROLL;
       
   285     }
       
   286 
       
   287     /**
       
   288      * Called after view and commands have been created. Subclasses
       
   289      * can overrride this method to set focus to their own default
       
   290      * commands.
       
   291      */
       
   292     protected void setDefaultCommand()
       
   293     {
       
   294         if (iAllowButton != null)
       
   295         {
       
   296             iAllowButton.setFocus();
       
   297             getShell().setDefaultButton(iAllowButton);
       
   298         }
       
   299     }
       
   300 
       
   301     /**
       
   302      * Called when user presses left soft key.
       
   303      */
       
   304     protected void lskPressed(KeyEvent aEvent)
       
   305     {
       
   306         if (iCancelCommand != null && iCancelCommand.isFocusControl())
       
   307         {
       
   308             confirmCancel();
       
   309         }
       
   310         else
       
   311         {
       
   312             confirmOk();
       
   313         }
       
   314     }
       
   315 
       
   316     /**
       
   317      * Opens installation details view.
       
   318      */
       
   319     private void openDetailsView()
       
   320     {
       
   321         if (iPermissionDetailsView != null)
       
   322         {
       
   323             return;
       
   324         }
       
   325         iPermissionDetailsView = new PermissionDetailsView
       
   326         (iInstallerUi, getShell(),
       
   327          getTitle(), iPermissionInfo);
       
   328         // New dialog must be opened in a new thread,
       
   329         // because we cannot use the main thread (which
       
   330         // is blocked by InstallConfirmationView) and we
       
   331         // cannot block the UI main thread
       
   332         // where this method gets executed.
       
   333         new Thread(new Runnable()
       
   334         {
       
   335             public void run()
       
   336             {
       
   337                 if (iPermissionDetailsView.confirm())
       
   338                 {
       
   339                     log("permissionDetailsView confirmed");
       
   340                     confirmOk();
       
   341                 }
       
   342                 else
       
   343                 {
       
   344                     log("permissionDetailsView cancelled");
       
   345                 }
       
   346                 iPermissionDetailsView.dispose();
       
   347                 iPermissionDetailsView = null;
       
   348                 setVisible(true);
       
   349             }
       
   350         }, "InstallerUiPermDetailsViewThread").start();
       
   351     }
       
   352 
       
   353     /**
       
   354      * Opens certificate information view.
       
   355      */
       
   356     private void openCertsView(int aCertIndex)
       
   357     {
       
   358         iCertificateDetailsView = new CertificateDetailsView
       
   359         (iInstallerUi, getShell(),
       
   360          getTitle(), iInstallInfo, aCertIndex);
       
   361         // New dialog must be opened in a new thread,
       
   362         // because we cannot use the main thread (which
       
   363         // is blocked by InstallDetailsView) and we
       
   364         // cannot block the UI main thread
       
   365         // where this method gets executed.
       
   366         new Thread(new Runnable()
       
   367         {
       
   368             public void run()
       
   369             {
       
   370                 if (iCertificateDetailsView.confirm())
       
   371                 {
       
   372                     log("certificateDetailsView confirmed");
       
   373                     confirmOk();
       
   374                 }
       
   375                 else
       
   376                 {
       
   377                     log("certificateDetailsView cancelled");
       
   378                 }
       
   379                 iCertificateDetailsView.dispose();
       
   380                 iCertificateDetailsView = null;
       
   381                 setVisible(true);
       
   382             }
       
   383         }, "InstallerUiCertViewThread").start();
       
   384     }
       
   385 }