javamanager/javainstaller/installerui/javasrc/com/nokia/mj/impl/installer/ui/eswt2/ViewBase.java
changeset 87 1627c337e51e
parent 80 d6dafc5d983f
equal deleted inserted replaced
80:d6dafc5d983f 87:1627c337e51e
    48 /**
    48 /**
    49  * Base class for different InstallerUi views.
    49  * Base class for different InstallerUi views.
    50  */
    50  */
    51 abstract public class ViewBase
    51 abstract public class ViewBase
    52 {
    52 {
       
    53     /** Is command composite present in this view. */
       
    54     protected static final int COMMAND_COMPOSITE = 1;
       
    55     /** Is title composite present in this view. */
       
    56     protected static final int TITLE_COMPOSITE = 2;
       
    57     /** Which composites are present in this view. */
       
    58     private int iComposites = COMMAND_COMPOSITE | TITLE_COMPOSITE;
       
    59 
    53     /** Maximum view height in percentage from display client area height. */
    60     /** Maximum view height in percentage from display client area height. */
    54     protected static final int MAX_VIEW_HEIGHT = 80;
    61     protected static final int MAX_VIEW_HEIGHT = 80;
    55     /** Maximum view width in percentage from display client area width. */
    62     /** Maximum view width in percentage from display client area width. */
    56     protected static final int MAX_VIEW_WIDTH = 90;
    63     protected static final int MAX_VIEW_WIDTH = 90;
    57     /** Parent shell for this view. */
    64     /** Parent shell for this view. */
    58     protected Shell iParent = null;
    65     protected Shell iParent = null;
    59     /** Container for the contents of the view */
    66     /** Container for the contents of the view */
    60     private Composite iContainer = null;
    67     private Composite iContainer = null;
       
    68     /** Composite for heading. */
       
    69     private Composite iHeadingComposite = null;
    61     /** ScrolledComposite for iComposite. */
    70     /** ScrolledComposite for iComposite. */
    62     private ScrolledComposite iScrolledComposite = null;
    71     private ScrolledComposite iScrolledComposite = null;
    63     /** Composite to which subclasses add their widgets. */
    72     /** Composite to which subclasses add their widgets. */
    64     private Composite iComposite = null;
    73     private Composite iComposite = null;
    65     /** ScrolledComposite for iAppInfoComposite. */
    74     /** ScrolledComposite for iAppInfoComposite. */
   102     }
   111     }
   103 
   112 
   104     /** Constructor */
   113     /** Constructor */
   105     protected ViewBase(InstallerUiEswt aInstallerUi, Composite aParent, int aColumns, boolean aScrollable)
   114     protected ViewBase(InstallerUiEswt aInstallerUi, Composite aParent, int aColumns, boolean aScrollable)
   106     {
   115     {
       
   116         this(aInstallerUi, aParent, aColumns, aScrollable, COMMAND_COMPOSITE | TITLE_COMPOSITE);
       
   117     }
       
   118 
       
   119     /** Constructor */
       
   120     protected ViewBase(InstallerUiEswt aInstallerUi, Composite aParent, int aColumns, boolean aScrollable, int aComposites)
       
   121     {
   107         iInstallerUi = aInstallerUi;
   122         iInstallerUi = aInstallerUi;
       
   123         iComposites = aComposites;
   108 
   124 
   109         // Each view gets a shell to be used as a parameter.
   125         // Each view gets a shell to be used as a parameter.
   110         iParent = (Shell)aParent;
   126         iParent = (Shell)aParent;
   111 
   127 
   112         iContainer = new Composite(iParent, 0);
   128         iContainer = new Composite(iParent, 0);
   121         iContainer.setSize(defShellClientBounds.width, defShellClientBounds.height);
   137         iContainer.setSize(defShellClientBounds.width, defShellClientBounds.height);
   122 
   138 
   123         // Let the contents fill the Shell.
   139         // Let the contents fill the Shell.
   124         iContainer.setLayout(setZeroMargins(new GridLayout()));
   140         iContainer.setLayout(setZeroMargins(new GridLayout()));
   125 
   141 
       
   142         if (isCompositePresent(TITLE_COMPOSITE))
       
   143         {
       
   144             // Create a composite for heading.
       
   145             iHeadingComposite = new Composite(iContainer, SWT.NONE);
       
   146             setCssId(iHeadingComposite, "headingArea");
       
   147             GridLayout headingLayout = setZeroMargins(
       
   148                 new GridLayout(getHeadingColumns(), true));
       
   149             iHeadingComposite.setLayout(headingLayout);
       
   150             iHeadingComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
       
   151         }
       
   152 
   126         if (aScrollable)
   153         if (aScrollable)
   127         {
   154         {
   128             // Create a ScrolledComposite for views which need ScrollBars.
   155             // Create a ScrolledComposite for views which need ScrollBars.
   129             iScrolledComposite = new ScrolledComposite(iContainer, getStyle());
   156             iScrolledComposite = new ScrolledComposite(iContainer, getStyle());
       
   157             setCssId(iScrolledComposite, "contentArea");
   130             iScrolledComposite.setAlwaysShowScrollBars(false);
   158             iScrolledComposite.setAlwaysShowScrollBars(false);
   131             iScrolledComposite.setExpandHorizontal(true);
   159             iScrolledComposite.setExpandHorizontal(true);
   132             iScrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
   160             iScrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
   133             // Create the content composite for the ScrolledComposite.
   161             // Create the content composite for the ScrolledComposite.
   134             iComposite = new Composite(iScrolledComposite, SWT.NONE);
   162             iComposite = new Composite(iScrolledComposite, SWT.NONE);
   137         }
   165         }
   138         else
   166         else
   139         {
   167         {
   140             // Create the composite without ScrollBars.
   168             // Create the composite without ScrollBars.
   141             iComposite = new Composite(iContainer, SWT.NONE);
   169             iComposite = new Composite(iContainer, SWT.NONE);
       
   170             setCssId(iComposite, "contentArea");
   142             GridLayout compLayout =
   171             GridLayout compLayout =
   143                 setZeroMargins(new GridLayout(getColumns(), true));
   172                 setZeroMargins(new GridLayout(getColumns(), true));
   144             iComposite.setLayout(compLayout);
   173             iComposite.setLayout(compLayout);
   145             iComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
   174             iComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
   146         }
   175         }
   147 
   176 
   148         // Create a composite for command buttons.
   177         if (isCompositePresent(COMMAND_COMPOSITE))
   149         iCommandComposite = new Composite(iContainer, SWT.NONE);
   178         {
   150         GridLayout cmdLayout = setZeroMargins(new GridLayout(2, true));
   179             // Create a composite for command buttons.
   151         cmdLayout.marginTop = 5;
   180             iCommandComposite = new Composite(iContainer, SWT.NONE);
   152         iCommandComposite.setLayout(cmdLayout);
   181             setCssId(iCommandComposite, "commandButtonArea");
   153         iCommandComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
   182             GridLayout cmdLayout = setZeroMargins(new GridLayout(2, true));
       
   183             iCommandComposite.setLayout(cmdLayout);
       
   184             iCommandComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
       
   185         }
   154 
   186 
   155         // Layout now and get the default size of the content area.
   187         // Layout now and get the default size of the content area.
   156         iContainer.layout(true);
   188         iContainer.layout(true);
   157         Rectangle rect = null;
   189         Rectangle rect = iContainer.getClientArea();
   158         if (aScrollable)
       
   159         {
       
   160             rect = iScrolledComposite.getClientArea();
       
   161         }
       
   162         else
       
   163         {
       
   164             rect = iComposite.getClientArea();
       
   165         }
       
   166         iDefaultContentSize = new Point(rect.width, rect.height);
   190         iDefaultContentSize = new Point(rect.width, rect.height);
   167     }
   191     }
   168 
   192 
   169     /**
   193     /**
   170      * Returns composite which holds the contents of this view.
   194      * Returns composite which holds the contents of this view.
   171      */
   195      */
   172     public Composite getContainer()
   196     public Composite getContainer()
   173     {
   197     {
   174         return iContainer;
   198         return iContainer;
       
   199     }
       
   200 
       
   201     /** Returns composite for heading. */
       
   202     public Composite getHeadingComposite()
       
   203     {
       
   204         return iHeadingComposite;
   175     }
   205     }
   176 
   206 
   177     /** Returns composite to which subclasses can add their widgets. */
   207     /** Returns composite to which subclasses can add their widgets. */
   178     public Composite getComposite()
   208     public Composite getComposite()
   179     {
   209     {
   352     }
   382     }
   353 
   383 
   354     /** Sets the view size according to display size. */
   384     /** Sets the view size according to display size. */
   355     private void doUpdateSize(boolean aVerticalScrollBarVisible)
   385     private void doUpdateSize(boolean aVerticalScrollBarVisible)
   356     {
   386     {
   357         Shell shell = getShell();
       
   358         Composite comp = getComposite();
       
   359         Composite cmdComp = getCommandComposite();
       
   360 
       
   361         if (getAppInfoComposite() != null)
   387         if (getAppInfoComposite() != null)
   362         {
   388         {
   363             // Recalculate the size of the app info composite.
   389             // Recalculate the size of the app info composite.
   364             if (aVerticalScrollBarVisible)
   390             if (aVerticalScrollBarVisible)
   365             {
   391             {
   375                     getAppInfoComposite().computeSize(
   401                     getAppInfoComposite().computeSize(
   376                         SWT.DEFAULT, SWT.DEFAULT));
   402                         SWT.DEFAULT, SWT.DEFAULT));
   377             }
   403             }
   378         }
   404         }
   379 
   405 
   380         int contentWidth = iDefaultContentSize.x * MAX_VIEW_WIDTH / 100;
   406         int contentWidth = iDefaultContentSize.x;
   381         if (aVerticalScrollBarVisible)
   407         if (aVerticalScrollBarVisible)
   382         {
   408         {
   383             int verticalScrollBarWidth =
   409             contentWidth = getComposite().getSize().x -
   384                 getScrolledComposite().getVerticalBar().getSize().x;
   410                 getScrolledComposite().getVerticalBar().getSize().x;
   385             contentWidth -= verticalScrollBarWidth;
       
   386         }
   411         }
   387 
   412 
   388         // Recalculate the size of the content.
   413         // Recalculate the size of the content.
   389         Point contentSize = comp.computeSize(contentWidth, SWT.DEFAULT);
   414         Point headingContentSize = new Point(0, 0);
   390         comp.setSize(contentSize);
   415         if (isCompositePresent(TITLE_COMPOSITE))
   391         Point cmdContentSize = cmdComp.computeSize(iDefaultContentSize.x, SWT.DEFAULT);
   416         {
   392         cmdComp.setSize(cmdContentSize);
   417             headingContentSize =
       
   418                 getHeadingComposite().computeSize(
       
   419                     iDefaultContentSize.x, SWT.DEFAULT);
       
   420             getHeadingComposite().setSize(headingContentSize);
       
   421         }
       
   422         Point contentSize =
       
   423             getComposite().computeSize(contentWidth, SWT.DEFAULT);
       
   424         getComposite().setSize(contentSize);
       
   425         Point cmdContentSize = new Point(0, 0);
       
   426         if (isCompositePresent(COMMAND_COMPOSITE))
       
   427         {
       
   428             cmdContentSize =
       
   429                 getCommandComposite().computeSize(
       
   430                     iDefaultContentSize.x, SWT.DEFAULT);
       
   431             getCommandComposite().setSize(cmdContentSize);
       
   432         }
   393 
   433 
   394         // Adjust Shell height and width.
   434         // Adjust Shell height and width.
   395         Rectangle dispRect = shell.getDisplay().getClientArea();
   435         Rectangle dispClientArea = getShell().getDisplay().getClientArea();
   396         int offset = iDefaultContentSize.y - contentSize.y - cmdContentSize.y;
       
   397 
       
   398         Rectangle defShellBounds = iInstallerUi.getDefaultShellBounds();
   436         Rectangle defShellBounds = iInstallerUi.getDefaultShellBounds();
       
   437         int offset = iDefaultContentSize.y - headingContentSize.y
       
   438             - contentSize.y - cmdContentSize.y;
   399         int newHeight = defShellBounds.height - offset;
   439         int newHeight = defShellBounds.height - offset;
   400         int maxHeight = dispRect.height * MAX_VIEW_HEIGHT / 100;
   440         int maxHeight = dispClientArea.height * MAX_VIEW_HEIGHT / 100;
   401 
       
   402         if (newHeight > maxHeight)
   441         if (newHeight > maxHeight)
   403         {
   442         {
   404             offset -= maxHeight - newHeight;
       
   405             newHeight = maxHeight;
   443             newHeight = maxHeight;
   406         }
   444         }
   407         int newWidth = defShellBounds.width;
   445         int newWidth = defShellBounds.width;
   408         int maxWidth = dispRect.width * MAX_VIEW_WIDTH / 100;
   446         int maxWidth = dispClientArea.width * MAX_VIEW_WIDTH / 100;
   409         if (newWidth > maxWidth)
   447         if (newWidth > maxWidth)
   410         {
   448         {
   411             newWidth = maxWidth;
   449             newWidth = maxWidth;
   412         }
   450         }
   413 
   451 
   414         // Always center horizontally and vertically.
   452         // Always center horizontally and vertically.
   415         Rectangle dispBounds = shell.getDisplay().getBounds();
   453         Rectangle dispBounds = getShell().getDisplay().getBounds();
   416         int x = dispBounds.width - newWidth;
   454         int x = dispBounds.width - newWidth;
   417         int y = dispBounds.height - newHeight;
   455         int y = dispBounds.height - newHeight;
   418         x /= 2;
   456         x /= 2;
   419         y /= 2;
   457         y /= 2;
   420         shell.setBounds(x, y, newWidth, newHeight);
   458         getShell().setBounds(x, y, newWidth, newHeight);
   421         Rectangle clientArea = shell.getClientArea();
   459         Rectangle clientArea = getShell().getClientArea();
   422         iContainer.setSize(clientArea.width, clientArea.height);
   460         iContainer.setSize(clientArea.width, clientArea.height);
   423         iContainer.layout(true);
   461         iContainer.layout(true);
   424     }
   462     }
   425 
   463 
   426     /**
   464     /**
   462     {
   500     {
   463         return SWT.NONE;
   501         return SWT.NONE;
   464     }
   502     }
   465 
   503 
   466     /**
   504     /**
       
   505      * Returns true if specified composite is present in this view.
       
   506      *
       
   507      * @param aComposite COMMAND_COMPOSITE or TITLE_COMPOSITE.
       
   508      */
       
   509     protected boolean isCompositePresent(int aComposites)
       
   510     {
       
   511         return ((iComposites & aComposites) != 0);
       
   512     }
       
   513 
       
   514     /**
       
   515      * Returns number of columns for heading of view.
       
   516      */
       
   517     protected int getHeadingColumns()
       
   518     {
       
   519         return 8;
       
   520     }
       
   521 
       
   522     /**
   467      * Returns number of columns for this view.
   523      * Returns number of columns for this view.
   468      */
   524      */
   469     protected int getColumns()
   525     protected int getColumns()
   470     {
   526     {
   471         return iColumns;
   527         return iColumns;
   479         aWidget.setData(WidgetConstant.CSS_ID, aCssId);
   535         aWidget.setData(WidgetConstant.CSS_ID, aCssId);
   480     }
   536     }
   481 
   537 
   482     /**
   538     /**
   483      * Adds header used in installation views.
   539      * Adds header used in installation views.
       
   540      * Note that this method can be called only for views which
       
   541      * have TITLE_COMPOSITE defined.
   484      */
   542      */
   485     protected void addHeader(
   543     protected void addHeader(
   486         String aTitle, InstallInfo aInstallInfo, UninstallInfo aUninstallInfo)
   544         String aTitle, InstallInfo aInstallInfo, UninstallInfo aUninstallInfo)
   487     {
   545     {
   488         addHeader(aTitle, aInstallInfo, aUninstallInfo, true);
       
   489     }
       
   490 
       
   491     /**
       
   492      * Adds header used in installation views.
       
   493      */
       
   494     protected void addHeader(
       
   495         String aTitle, InstallInfo aInstallInfo, UninstallInfo aUninstallInfo,
       
   496         boolean aSecurityButton)
       
   497     {
       
   498         // Add title.
   546         // Add title.
   499         if (aTitle == null)
   547         if (aTitle == null)
   500         {
   548         {
   501             aTitle = InstallerUiTexts.get(InstallerUiTexts.INSTALL_QUERY);
   549             aTitle = InstallerUiTexts.get(InstallerUiTexts.INSTALL_QUERY);
   502             if (aInstallInfo != null && aInstallInfo.getOldVersion() != null)
   550             if (aInstallInfo != null && aInstallInfo.getOldVersion() != null)
   503             {
   551             {
   504                 aTitle = InstallerUiTexts.get(InstallerUiTexts.UPDATE_QUERY);
   552                 aTitle = InstallerUiTexts.get(InstallerUiTexts.UPDATE_QUERY);
   505             }
   553             }
   506         }
   554         }
   507         Label titleLabel = createLabel(aTitle, getColumns() - 1, SWT.WRAP);
   555         Label titleLabel = createLabel(
       
   556             getHeadingComposite(), aTitle, getHeadingColumns() - 1, SWT.WRAP);
   508         setCssId(titleLabel, "heading");
   557         setCssId(titleLabel, "heading");
   509 
   558 
   510         if (aInstallInfo != null)
   559         if (aInstallInfo != null)
   511         {
   560         {
   512             iCertificates = aInstallInfo.getCertificates();
   561             iCertificates = aInstallInfo.getCertificates();
   513         }
   562         }
   514         else if (aUninstallInfo != null)
   563         else if (aUninstallInfo != null)
   515         {
   564         {
   516             iCertificates = aUninstallInfo.getCertificates();
   565             iCertificates = aUninstallInfo.getCertificates();
   517         }
   566         }
   518         if (aSecurityButton)
   567         // Add security button.
   519         {
   568         createSecurityButton(getHeadingComposite());
   520             // Add security button.
       
   521             createSecurityButton();
       
   522         }
       
   523         else
       
   524         {
       
   525             // Add security icon.
       
   526             createSecurityLabel(iCertificates != null);
       
   527         }
       
   528 
   569 
   529         // Init suite icon data.
   570         // Init suite icon data.
   530         if (aInstallInfo != null)
   571         if (aInstallInfo != null)
   531         {
   572         {
   532             iSuiteIconInputStream = aInstallInfo.getIconInputStream();
   573             iSuiteIconInputStream = aInstallInfo.getIconInputStream();
   667      * @param aStyle SWT style for the label
   708      * @param aStyle SWT style for the label
   668      * @return label that was added to this view
   709      * @return label that was added to this view
   669      */
   710      */
   670     protected Label createLabel(String aText, int aColumns, int aStyle)
   711     protected Label createLabel(String aText, int aColumns, int aStyle)
   671     {
   712     {
   672         Label label = new Label(getComposite(), aStyle);
   713         return createLabel(getComposite(), aText, aColumns, aStyle);
       
   714     }
       
   715 
       
   716     /**
       
   717      * Creates a new label with given text and adds it to given
       
   718      * composite in this view.
       
   719      *
       
   720      * @param aComposite composite to which the label is added
       
   721      * @param aText text for the label
       
   722      * @param aColumns number of columns the label takes
       
   723      * @param aStyle SWT style for the label
       
   724      * @return label that was added to this view
       
   725      */
       
   726     protected Label createLabel(
       
   727         Composite aComposite, String aText, int aColumns, int aStyle)
       
   728     {
       
   729         Label label = new Label(aComposite, aStyle);
   673         label.setText(aText);
   730         label.setText(aText);
   674         GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
   731         GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
   675         gridData.horizontalSpan = aColumns;
   732         gridData.horizontalSpan = aColumns;
   676         label.setLayoutData(gridData);
   733         label.setLayoutData(gridData);
   677         return label;
   734         return label;
   727         gridData.horizontalSpan = 1;
   784         gridData.horizontalSpan = 1;
   728         label.setLayoutData(gridData);
   785         label.setLayoutData(gridData);
   729         return label;
   786         return label;
   730     }
   787     }
   731 
   788 
   732     /**
   789     protected Button createSecurityButton(Composite aComposite)
   733      * Creates a new label with security icon.
   790     {
   734      *
   791         Button button = new Button(aComposite, SWT.PUSH);
   735      * @param aIdentified true if security icon is for an
       
   736      * identified application, false otherwise
       
   737      * @return label that was added to this view
       
   738      */
       
   739     protected Label createSecurityLabel(boolean aIdentified)
       
   740     {
       
   741         Label label = createLabel((Image)null, 1, SWT.NONE);
       
   742         setCssId(label, "securityLabel");
       
   743         Image securityIcon = null;
       
   744         if (iInstallerUi != null)
       
   745         {
       
   746             securityIcon = iInstallerUi.getSecurityIcon(
       
   747                 getDisplay(), aIdentified);
       
   748         }
       
   749         if (securityIcon != null)
       
   750         {
       
   751             label.setImage(securityIcon);
       
   752         }
       
   753         else
       
   754         {
       
   755             label.setText(aIdentified? "I": "U");
       
   756         }
       
   757         return label;
       
   758     }
       
   759 
       
   760     protected Button createSecurityButton()
       
   761     {
       
   762         Button button = new Button(getComposite(), SWT.PUSH);
       
   763         setCssId(button, "securityButton");
   792         setCssId(button, "securityButton");
   764         GridData gridData = new GridData(
   793         GridData gridData = new GridData(
   765             GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
   794             GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
   766         gridData.horizontalSpan = 1;
   795         gridData.horizontalSpan = 1;
   767         gridData.horizontalAlignment = SWT.CENTER;
   796         gridData.horizontalAlignment = SWT.CENTER;