javamanager/javainstaller/installerui/javasrc/com/nokia/mj/impl/installer/ui/eswt2/InstallerUiEswt.java
branchRCL_3
changeset 24 0fd27995241b
parent 19 04becd199f91
child 25 9ac0a0a7da70
equal deleted inserted replaced
20:f9bb0fca356a 24:0fd27995241b
    26 import com.nokia.mj.impl.installer.ui.InstallInfo;
    26 import com.nokia.mj.impl.installer.ui.InstallInfo;
    27 import com.nokia.mj.impl.installer.ui.LaunchAppInfo;
    27 import com.nokia.mj.impl.installer.ui.LaunchAppInfo;
    28 import com.nokia.mj.impl.installer.ui.PermissionInfo;
    28 import com.nokia.mj.impl.installer.ui.PermissionInfo;
    29 import com.nokia.mj.impl.installer.ui.UninstallInfo;
    29 import com.nokia.mj.impl.installer.ui.UninstallInfo;
    30 import com.nokia.mj.impl.installer.ui.eswt.MinimalUi;
    30 import com.nokia.mj.impl.installer.ui.eswt.MinimalUi;
       
    31 import com.nokia.mj.impl.rt.ui.ConfirmData;
    31 import com.nokia.mj.impl.rt.ui.RuntimeUi;
    32 import com.nokia.mj.impl.rt.ui.RuntimeUi;
    32 import com.nokia.mj.impl.rt.ui.RuntimeUiFactory;
    33 import com.nokia.mj.impl.rt.ui.RuntimeUiFactory;
    33 import com.nokia.mj.impl.utils.ResourceUtil;
    34 import com.nokia.mj.impl.utils.ResourceUtil;
    34 import com.nokia.mj.impl.utils.StartUpTrace;
    35 import com.nokia.mj.impl.utils.StartUpTrace;
    35 import com.nokia.mj.impl.utils.exception.InstallerExceptionBase;
    36 import com.nokia.mj.impl.utils.exception.InstallerExceptionBase;
    56 import org.eclipse.swt.widgets.Shell;
    57 import org.eclipse.swt.widgets.Shell;
    57 //import org.eclipse.swt.widgets.MessageBox;
    58 //import org.eclipse.swt.widgets.MessageBox;
    58 
    59 
    59 /**
    60 /**
    60  * JavaInstaller eSWT UI.
    61  * JavaInstaller eSWT UI.
    61  *
       
    62  * @author Nokia Corporation
       
    63  * @version $Rev: 0 $
       
    64  */
    62  */
    65 public class InstallerUiEswt extends InstallerUi
    63 public class InstallerUiEswt extends InstallerUi
    66 {
    64 {
    67     /** Default shell style. */
    65     /** Default shell style. */
    68     private static final int SHELL_STYLE =
    66     private static final int SHELL_STYLE =
    76     private InstallConfirmationView iInstallConfirmationView = null;
    74     private InstallConfirmationView iInstallConfirmationView = null;
    77     private UninstallConfirmationView iUninstallConfirmationView = null;
    75     private UninstallConfirmationView iUninstallConfirmationView = null;
    78     private PermissionConfirmationView iPermissionConfirmationView = null;
    76     private PermissionConfirmationView iPermissionConfirmationView = null;
    79     private UsernamePasswordView iUsernamePasswordView = null;
    77     private UsernamePasswordView iUsernamePasswordView = null;
    80     private LaunchAppQueryView iLaunchAppQueryView = null;
    78     private LaunchAppQueryView iLaunchAppQueryView = null;
       
    79     private ErrorView iErrorView = null;
       
    80     private ErrorDetailsView iErrorDetailsView = null;
       
    81     private RuntimeConfirmationView iRuntimeConfirmationView = null;
    81     /** Synchronization object for waiting for the UI initialization. */
    82     /** Synchronization object for waiting for the UI initialization. */
    82     private Object iInitWaitObject = new Object();
    83     private Object iInitWaitObject = new Object();
    83     /** Synchronization object for waiting for the UI termination. */
    84     /** Synchronization object for waiting for the UI termination. */
    84     private Object iExitWaitObject = new Object();
    85     private Object iExitWaitObject = new Object();
    85     /**
    86     /**
   129      */
   130      */
   130     public void init(int aMode, InstallerUiListener aListener)
   131     public void init(int aMode, InstallerUiListener aListener)
   131     {
   132     {
   132         super.init(aMode, aListener);
   133         super.init(aMode, aListener);
   133         StartUpTrace.doTrace("InstallerUiEswt init");
   134         StartUpTrace.doTrace("InstallerUiEswt init");
       
   135         InstallerRuntimeUi.init(this);
   134         // Create a hashtable for icons.
   136         // Create a hashtable for icons.
   135         iImageTable = new Hashtable();
   137         iImageTable = new Hashtable();
   136         // Create a new thread to be the UI main thread.
   138         // Create a new thread to be the UI main thread.
   137         iUiThreadExists = true;
   139         iUiThreadExists = true;
   138         new Thread(new Runnable()
   140         new Thread(new Runnable()
   269         }
   271         }
   270         if (iLaunchAppQueryView != null)
   272         if (iLaunchAppQueryView != null)
   271         {
   273         {
   272             iLaunchAppQueryView.confirmCancel();
   274             iLaunchAppQueryView.confirmCancel();
   273         }
   275         }
       
   276         if (iErrorView != null)
       
   277         {
       
   278             iErrorView.confirmCancel();
       
   279         }
       
   280         if (iErrorDetailsView != null)
       
   281         {
       
   282             iErrorDetailsView.confirmCancel();
       
   283         }
       
   284         if (iRuntimeConfirmationView != null)
       
   285         {
       
   286             iRuntimeConfirmationView.confirmCancel();
       
   287         }
   274         // Remove download progress bar if it visible.
   288         // Remove download progress bar if it visible.
   275         if (iDlProgressView != null && !iDlProgressView.isDisposed())
   289         if (iDlProgressView != null && !iDlProgressView.isDisposed())
   276         {
   290         {
   277             iDlProgressView.dispose();
   291             iDlProgressView.dispose();
   278             iDlProgressView = null;
   292             iDlProgressView = null;
   684         super.ended(aDownloadInfo);
   698         super.ended(aDownloadInfo);
   685         if (!isUiReady())
   699         if (!isUiReady())
   686         {
   700         {
   687             return;
   701             return;
   688         }
   702         }
   689         if (iDlProgressView != null)
   703         if (iDlProgressView != null && !iDlProgressView.isDisposed())
   690         {
   704         {
   691             iDlProgressView.dispose();
   705             iDlProgressView.dispose();
   692             iDlProgressView = null;
   706             iDlProgressView = null;
   693         }
   707         }
   694         synchronized (iProgressSyncObject)
   708         synchronized (iProgressSyncObject)
   801         }
   815         }
   802     }
   816     }
   803 
   817 
   804     /**
   818     /**
   805      * Notify user that an error has occurred.
   819      * Notify user that an error has occurred.
   806      * This method must return quickly.
       
   807      *
   820      *
   808      * @param aInstallerException exception indicating the error reason
   821      * @param aInstallerException exception indicating the error reason
   809      */
   822      */
   810     public void error(InstallerExceptionBase aInstallerException)
   823     public void error(InstallerExceptionBase aInstallerException)
   811     {
   824     {
   812         super.error(aInstallerException);
   825         super.error(aInstallerException);
   813 
   826 
   814         waitForUi();
   827         waitForUi();
   815         // InstallerUi does not have to be ready as long as
   828         if (!isUiReady()) {
   816         // RuntimeUi is used to display error messages.
   829             showRuntimeUiError(aInstallerException);
   817         //if (!isUiReady()) {
   830             return;
   818         //    return;
   831         }
   819         //}
   832 
   820 
   833         // Use ErrorView to display error message.
       
   834         if (iErrorView == null)
       
   835         {
       
   836             final Display display = iParent.getDisplay();
       
   837             final InstallerUiEswt self = this;
       
   838             display.syncExec(new Runnable()
       
   839             {
       
   840                 public void run()
       
   841                 {
       
   842                     iErrorView = new ErrorView(self, iDialog);
       
   843                 }
       
   844             });
       
   845         }
       
   846         boolean result = iErrorView.error(aInstallerException);
       
   847         iErrorView.dispose();
       
   848         iErrorView = null;
       
   849 
       
   850         if (result)
       
   851         {
       
   852             // Display error details.
       
   853             if (iErrorDetailsView == null)
       
   854             {
       
   855                 final Display display = iParent.getDisplay();
       
   856                 final InstallerUiEswt self = this;
       
   857                 display.syncExec(new Runnable()
       
   858                 {
       
   859                     public void run()
       
   860                     {
       
   861                         iErrorDetailsView = new ErrorDetailsView(self, iDialog);
       
   862                     }
       
   863                 });
       
   864             }
       
   865             result = iErrorDetailsView.error(aInstallerException);
       
   866             iErrorDetailsView.dispose();
       
   867             iErrorDetailsView = null;
       
   868         }
       
   869     }
       
   870 
       
   871     /**
       
   872      * Notify user that an error has occurred using RuntimeUI.
       
   873      *
       
   874      * @param aInstallerException exception indicating the error reason
       
   875      */
       
   876     private void showRuntimeUiError(InstallerExceptionBase aInstallerException)
       
   877     {
   821         boolean identified = false;
   878         boolean identified = false;
   822         //String tmpAppName = null;
       
   823         if (iInstallInfo != null)
   879         if (iInstallInfo != null)
   824         {
   880         {
   825             //tmpAppName = iInstallInfo.getName();
       
   826             if (iInstallInfo.getCertificates() != null)
   881             if (iInstallInfo.getCertificates() != null)
   827             {
   882             {
   828                 identified = true;
   883                 identified = true;
   829             }
   884             }
   830         }
   885         }
   831         else if (iUninstallInfo != null)
   886         else if (iUninstallInfo != null)
   832         {
   887         {
   833             //tmpAppName = iUninstallInfo.getName();
       
   834             if (iUninstallInfo.getCertificates() != null)
   888             if (iUninstallInfo.getCertificates() != null)
   835             {
   889             {
   836                 identified = true;
   890                 identified = true;
   837             }
   891             }
   838         }
   892         }
   851         // Hide progress view before displaying error message.
   905         // Hide progress view before displaying error message.
   852         if (iProgressView != null)
   906         if (iProgressView != null)
   853         {
   907         {
   854             iProgressView.setVisible(false);
   908             iProgressView.setVisible(false);
   855         }
   909         }
   856         // Use RuntimeUi to display error message.
   910         // Use RuntimeUi to display uninstallation error message.
   857         RuntimeUi runtimeUi = RuntimeUiFactory.getRuntimeUi(identified);
   911         RuntimeUi runtimeUi = RuntimeUiFactory.getRuntimeUi(identified);
   858         runtimeUi.error(tmpTitle, aInstallerException);
   912         runtimeUi.error(tmpTitle, aInstallerException);
   859         runtimeUi.destroy();
   913         runtimeUi.destroy();
   860 
   914     }
   861         /*
   915 
   862         // Display error message using eSWT MessageBox.
   916     /**
   863         final String appName = tmpAppName;
   917      * Seeks confirmation from the user.
   864         final String title = tmpTitle;
   918      *
   865         final String shortMsg = aInstallerException.getShortMessage();
   919      * @param aAppName     the name of the application on behalf of which the
   866         final String detailedMsg = aInstallerException.getDetailedMessage();
   920      *                     confirmation is requested
   867         // UI updates must be executed in UI thread.
   921      * @param aConfirmData the data to be confirmed. Unless the user has
   868         iParent.getDisplay().syncExec
   922      *                     canceled the confirmation, this data will be filled
   869             (new Runnable() {
   923      *                     in with user's answer upon return
   870                     public void run() {
   924      * @return             true if the user has answered, false if the user has
   871                         if (detailedMsg == null || detailedMsg.length() == 0) {
   925      *                     canceled the confirmation
   872                             // No detailed msg, display only short msg.
   926      */
   873                             MessageBox messageBox = new MessageBox
   927     public boolean confirm(String aAppName, ConfirmData aConfirmData)
   874                                 (iParent, SWT.ICON_ERROR | SWT.OK);
   928     {
   875                             messageBox.setText(title);
   929         waitForUi();
   876                             messageBox.setMessage
   930         if (!isUiReady()) {
   877                                 (getMessage(title, appName, shortMsg, false));
   931             return true;
   878                             messageBox.open();
   932         }
   879                         } else {
   933 
   880                             // Display both short and detailed msgs.
   934         if (iRuntimeConfirmationView == null)
   881                             MessageBox messageBox = new MessageBox
   935         {
   882                                 (iParent, SWT.ICON_ERROR | SWT.YES | SWT.NO);
   936             final Display display = iParent.getDisplay();
   883                             messageBox.setText(title);
   937             final InstallerUiEswt self = this;
   884                             messageBox.setMessage
   938             final String appName = aAppName;
   885                                 (getMessage(title, appName, shortMsg, true));
   939             final ConfirmData confirmData = aConfirmData;
   886                             int answer = messageBox.open();
   940             display.syncExec(new Runnable()
   887                             if ((answer & SWT.YES) != 0) {
   941             {
   888                                 // User wants to see details, display them.
   942                 public void run()
   889                                 messageBox = new MessageBox
   943                 {
   890                                     (iParent, SWT.ICON_ERROR | SWT.OK);
   944                     iRuntimeConfirmationView = new RuntimeConfirmationView(
   891                                 messageBox.setText(title);
   945                         self, iDialog, appName, confirmData);
   892                                 messageBox.setMessage
   946                 }
   893                                     (getMessage(title, appName, detailedMsg, false));
   947             });
   894                                 messageBox.open();
   948         }
   895                             }
   949         boolean result = iRuntimeConfirmationView.confirm();
   896                         }
   950         iRuntimeConfirmationView.dispose();
   897                     }
   951         iRuntimeConfirmationView = null;
   898                     private String getMessage(String aTitle, String aAppName,
   952         log("Runtime confirmation returns " + result);
   899                                               String aMsg, boolean aDetailsQuery) {
   953         return result;
   900                         //String result = aTitle + "\n\n";
       
   901                         String result = "";
       
   902                         if (aAppName == null) {
       
   903                             result += aMsg;
       
   904                         } else {
       
   905                             result += aAppName + "\n\n" + aMsg;
       
   906                         }
       
   907                         if (aDetailsQuery) {
       
   908                             result += "\n\n";
       
   909                             result += InstallerUiTexts.get
       
   910                                 (InstallerUiTexts.DETAILS_QUERY);
       
   911                         }
       
   912                         return result;
       
   913                     }
       
   914                 });
       
   915 
       
   916         */
       
   917     }
   954     }
   918 
   955 
   919     /**
   956     /**
   920      * Ask username and password for http authentication.
   957      * Ask username and password for http authentication.
   921      * This method blocks until user has answered to the dialog.
   958      * This method blocks until user has answered to the dialog.
  1018     }
  1055     }
  1019 
  1056 
  1020     /**
  1057     /**
  1021      * Hides or unhides InstallerUi.
  1058      * Hides or unhides InstallerUi.
  1022      */
  1059      */
  1023     protected void hide(boolean aHide)
  1060     public void hide(boolean aHide)
  1024     {
  1061     {
  1025         iParent.setMinimized(aHide);
  1062         iParent.setMinimized(aHide);
  1026     }
  1063     }
  1027 
  1064 
  1028     /**
  1065     /**