javamanager/javainstaller/installerui/javasrc/com/nokia/mj/impl/installer/ui/eswt2/PermissionConfirmationView.java
branchRCL_3
changeset 19 04becd199f91
child 23 98ccebc37403
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.eswt2;
       
    20 
       
    21 import com.nokia.mj.impl.installer.ui.InstallInfo;
       
    22 import com.nokia.mj.impl.installer.ui.PermissionInfo;
       
    23 
       
    24 import java.io.InputStream;
       
    25 
       
    26 import org.eclipse.swt.SWT;
       
    27 import org.eclipse.swt.SWTException;
       
    28 import org.eclipse.swt.events.FocusEvent;
       
    29 import org.eclipse.swt.events.FocusListener;
       
    30 import org.eclipse.swt.events.KeyEvent;
       
    31 import org.eclipse.swt.graphics.Image;
       
    32 import org.eclipse.swt.graphics.Point;
       
    33 import org.eclipse.swt.layout.GridData;
       
    34 import org.eclipse.swt.widgets.Composite;
       
    35 import org.eclipse.swt.widgets.Button;
       
    36 import org.eclipse.swt.widgets.Event;
       
    37 import org.eclipse.swt.widgets.Label;
       
    38 import org.eclipse.swt.widgets.Link;
       
    39 import org.eclipse.swt.widgets.Listener;
       
    40 import org.eclipse.swt.widgets.Shell;
       
    41 
       
    42 /**
       
    43  * PermissionConfirmationView asks permissions confirmation
       
    44  * from the user.
       
    45  */
       
    46 public class PermissionConfirmationView extends ConfirmationViewBase
       
    47 {
       
    48     private PermissionDetailsView iPermissionDetailsView = null;
       
    49     private InstallInfo iInstallInfo = null;
       
    50     private PermissionInfo iPermissionInfo = null;
       
    51     private Button iAllowButton = null;
       
    52     private Button iDenyButton = null;
       
    53     private Button iCancelButton = null;
       
    54 
       
    55     /** Constructor */
       
    56     protected PermissionConfirmationView()
       
    57     {
       
    58         super();
       
    59     }
       
    60 
       
    61     /** Constructor */
       
    62     protected PermissionConfirmationView(InstallerUiEswt aInstaller, Composite aParent)
       
    63     {
       
    64         super(aInstaller, aParent, 8, true);
       
    65         setTitle(InstallerUiTexts.get(InstallerUiTexts.INSTALL));
       
    66         setCommands(null, null);
       
    67     }
       
    68 
       
    69     /**
       
    70      * Synchoronous method for asking user confirmation.
       
    71      */
       
    72     public boolean confirm(InstallInfo aInstallInfo,
       
    73                            PermissionInfo aPermissionInfo)
       
    74     {
       
    75         iInstallInfo = aInstallInfo;
       
    76         iPermissionInfo = aPermissionInfo;
       
    77         boolean result = confirm();
       
    78         if (result)
       
    79         {
       
    80             log("permissionConfirmationView confirmed");
       
    81         }
       
    82         else
       
    83         {
       
    84             log("permissionConfirmationView cancelled");
       
    85         }
       
    86         return result;
       
    87     }
       
    88 
       
    89     /**
       
    90      * This method is called once before view is opened.
       
    91      */
       
    92     protected void createView()
       
    93     {
       
    94         // Add header.
       
    95         String title = "Install?";
       
    96         if (iInstallInfo != null)
       
    97         {
       
    98             if (iInstallInfo.getOldVersion() != null)
       
    99             {
       
   100                 title = "Update?";
       
   101             }
       
   102         }
       
   103         addHeader(title, iInstallInfo, null);
       
   104 
       
   105         GridData gridData = null;
       
   106         int horizontalSpan = getColumns();
       
   107         int labelStyle = SWT.WRAP;
       
   108 
       
   109         // Add permission query label.
       
   110         Label domainLabel = createLabel(
       
   111                                 InstallerUiTexts.get(InstallerUiTexts.PERM_QUERY),
       
   112                                 horizontalSpan, labelStyle);
       
   113 
       
   114         // Add link for permission details.
       
   115         if (iPermissionInfo != null &&
       
   116                 iPermissionInfo.getPermissionNames() != null &&
       
   117                 iPermissionInfo.getPermissionNames().length > 0)
       
   118         {
       
   119             Link detailsLink = new Link(getComposite(), SWT.NONE);
       
   120             detailsLink.setText(
       
   121                 "<a>" +
       
   122                 InstallerUiTexts.get(InstallerUiTexts.PERM_VIEW_DETAILS) +
       
   123                 "</a>");
       
   124             detailsLink.addListener(SWT.Selection, new Listener()
       
   125             {
       
   126                 public void handleEvent(Event aEvent)
       
   127                 {
       
   128                     openDetailsView();
       
   129                 }
       
   130             });
       
   131             gridData = new GridData(GridData.FILL_HORIZONTAL);
       
   132             gridData.horizontalSpan = horizontalSpan;
       
   133             detailsLink.setLayoutData(gridData);
       
   134             addSoftKeyListenerFor(detailsLink);
       
   135         }
       
   136 
       
   137         // Number of pixels on top of the buttons.
       
   138         int verticalIndent = 5;
       
   139 
       
   140         // Add allow button.
       
   141         iAllowButton = new Button(getComposite(), SWT.NONE);
       
   142         iAllowButton.setText(InstallerUiTexts.get(
       
   143                                  InstallerUiTexts.PERM_ALLOW_ALWAYS));
       
   144         iAllowButton.addListener(SWT.Selection, new Listener()
       
   145         {
       
   146             public void handleEvent(Event aEvent)
       
   147             {
       
   148                 iPermissionInfo.setPermissionAllowed(true);
       
   149                 confirmOk();
       
   150             }
       
   151         });
       
   152         iAllowButton.addFocusListener(new FocusListener()
       
   153         {
       
   154             public void focusGained(FocusEvent aEvent)
       
   155             {
       
   156                 if (!userHasAnswered())
       
   157                 {
       
   158                     iPermissionInfo.setPermissionAllowed(true);
       
   159                 }
       
   160             }
       
   161             public void focusLost(FocusEvent aEvent)
       
   162             {
       
   163                 // nop
       
   164             }
       
   165         });
       
   166         gridData = new GridData(GridData.FILL_HORIZONTAL);
       
   167         gridData.horizontalSpan = horizontalSpan;
       
   168         gridData.verticalIndent = verticalIndent;
       
   169         iAllowButton.setLayoutData(gridData);
       
   170         iAllowButton.setFocus();
       
   171         addSoftKeyListenerFor(iAllowButton);
       
   172 
       
   173         // Add deny button.
       
   174         iDenyButton = new Button(getComposite(), SWT.NONE);
       
   175         iDenyButton.setText(InstallerUiTexts.get(
       
   176                                 InstallerUiTexts.PERM_ASK_ME_LATER));
       
   177         iDenyButton.addListener(SWT.Selection, new Listener()
       
   178         {
       
   179             public void handleEvent(Event aEvent)
       
   180             {
       
   181                 iPermissionInfo.setPermissionAllowed(false);
       
   182                 confirmOk();
       
   183             }
       
   184         });
       
   185         iDenyButton.addFocusListener(new FocusListener()
       
   186         {
       
   187             public void focusGained(FocusEvent aEvent)
       
   188             {
       
   189                 if (!userHasAnswered())
       
   190                 {
       
   191                     iPermissionInfo.setPermissionAllowed(false);
       
   192                 }
       
   193             }
       
   194             public void focusLost(FocusEvent aEvent)
       
   195             {
       
   196                 // nop
       
   197             }
       
   198         });
       
   199         gridData = new GridData(GridData.FILL_HORIZONTAL);
       
   200         gridData.horizontalSpan = horizontalSpan;
       
   201         gridData.verticalIndent = verticalIndent;
       
   202         iDenyButton.setLayoutData(gridData);
       
   203         addSoftKeyListenerFor(iDenyButton);
       
   204 
       
   205         // Add cancel button.
       
   206         iCancelButton = new Button(getComposite(), SWT.NONE);
       
   207         iCancelButton.setText(InstallerUiTexts.get(InstallerUiTexts.CANCEL));
       
   208         iCancelButton.addListener(SWT.Selection, new Listener()
       
   209         {
       
   210             public void handleEvent(Event aEvent)
       
   211             {
       
   212                 confirmCancel();
       
   213             }
       
   214         });
       
   215         iCancelButton.addFocusListener(new FocusListener()
       
   216         {
       
   217             public void focusGained(FocusEvent aEvent)
       
   218             {
       
   219                 if (!userHasAnswered())
       
   220                 {
       
   221                     iPermissionInfo.setPermissionAllowed(false);
       
   222                 }
       
   223             }
       
   224             public void focusLost(FocusEvent aEvent)
       
   225             {
       
   226                 // nop
       
   227             }
       
   228         });
       
   229         gridData = new GridData(GridData.FILL_HORIZONTAL);
       
   230         gridData.horizontalSpan = horizontalSpan;
       
   231         gridData.verticalIndent = verticalIndent;
       
   232         iCancelButton.setLayoutData(gridData);
       
   233         addSoftKeyListenerFor(iCancelButton);
       
   234     }
       
   235 
       
   236     /**
       
   237      * This method is called after user has answered
       
   238      * to confirmation.
       
   239      */
       
   240     protected void getDataFromView()
       
   241     {
       
   242         // nop
       
   243     }
       
   244 
       
   245     /**
       
   246      * Returns true if the View should have focus after it has been opened.
       
   247      */
       
   248     protected boolean forceFocusToView()
       
   249     {
       
   250         return false;
       
   251     }
       
   252 
       
   253     /**
       
   254      * Returns SWT style for this view.
       
   255      */
       
   256     protected int getStyle()
       
   257     {
       
   258         return SWT.V_SCROLL;
       
   259     }
       
   260 
       
   261     /**
       
   262      * Called after view and commands have been created. Subclasses
       
   263      * can overrride this method to set focus to their own default
       
   264      * commands.
       
   265      */
       
   266     protected void setDefaultCommand()
       
   267     {
       
   268         if (iAllowButton != null)
       
   269         {
       
   270             iAllowButton.setFocus();
       
   271             getShell().setDefaultButton(iAllowButton);
       
   272         }
       
   273     }
       
   274 
       
   275     /**
       
   276      * Called when user presses left soft key.
       
   277      */
       
   278     protected void lskPressed(KeyEvent aEvent)
       
   279     {
       
   280         if (iCancelButton != null && iCancelButton.isFocusControl())
       
   281         {
       
   282             confirmCancel();
       
   283         }
       
   284         else
       
   285         {
       
   286             confirmOk();
       
   287         }
       
   288     }
       
   289 
       
   290     /**
       
   291      * Opens permission details view.
       
   292      */
       
   293     private void openDetailsView()
       
   294     {
       
   295         if (iPermissionDetailsView != null)
       
   296         {
       
   297             return;
       
   298         }
       
   299         iPermissionDetailsView = new PermissionDetailsView(
       
   300             iInstallerUi, getShell(), getTitle(), iPermissionInfo);
       
   301         // New dialog must be opened in a new thread,
       
   302         // because we cannot use the main thread (which
       
   303         // is blocked by InstallConfirmationView) and we
       
   304         // cannot block the UI main thread
       
   305         // where this method gets executed.
       
   306         new Thread(new Runnable()
       
   307         {
       
   308             public void run()
       
   309             {
       
   310                 if (iPermissionDetailsView.confirm())
       
   311                 {
       
   312                     log("permissionDetailsView confirmed");
       
   313                     confirmOk();
       
   314                 }
       
   315                 else
       
   316                 {
       
   317                     log("permissionDetailsView cancelled");
       
   318                 }
       
   319                 iPermissionDetailsView.dispose();
       
   320                 iPermissionDetailsView = null;
       
   321                 setVisible(true);
       
   322             }
       
   323         }, "InstallerUiPermDetailsViewThread").start();
       
   324     }
       
   325 }