javamanager/javainstaller/installerui/javasrc/com/nokia/mj/impl/installer/ui/eswt2/ViewBase.java
branchRCL_3
changeset 60 6c158198356e
parent 59 e5618cc85d74
child 77 7cee158cb8cd
equal deleted inserted replaced
59:e5618cc85d74 60:6c158198356e
    32 import org.eclipse.swt.events.SelectionEvent;
    32 import org.eclipse.swt.events.SelectionEvent;
    33 import org.eclipse.swt.events.SelectionListener;
    33 import org.eclipse.swt.events.SelectionListener;
    34 import org.eclipse.swt.graphics.Image;
    34 import org.eclipse.swt.graphics.Image;
    35 import org.eclipse.swt.graphics.Point;
    35 import org.eclipse.swt.graphics.Point;
    36 import org.eclipse.swt.graphics.Rectangle;
    36 import org.eclipse.swt.graphics.Rectangle;
       
    37 import org.eclipse.swt.internal.qt.WidgetConstant;
    37 import org.eclipse.swt.layout.GridData;
    38 import org.eclipse.swt.layout.GridData;
    38 import org.eclipse.swt.layout.GridLayout;
    39 import org.eclipse.swt.layout.GridLayout;
    39 import org.eclipse.swt.widgets.Button;
    40 import org.eclipse.swt.widgets.Button;
    40 import org.eclipse.swt.widgets.Composite;
    41 import org.eclipse.swt.widgets.Composite;
    41 import org.eclipse.swt.widgets.Control;
    42 import org.eclipse.swt.widgets.Control;
    42 import org.eclipse.swt.widgets.Display;
    43 import org.eclipse.swt.widgets.Display;
    43 import org.eclipse.swt.widgets.Label;
    44 import org.eclipse.swt.widgets.Label;
    44 import org.eclipse.swt.widgets.Shell;
    45 import org.eclipse.swt.widgets.Shell;
       
    46 import org.eclipse.swt.widgets.Widget;
    45 
    47 
    46 /**
    48 /**
    47  * Base class for different InstallerUi views.
    49  * Base class for different InstallerUi views.
    48  */
    50  */
    49 abstract public class ViewBase
    51 abstract public class ViewBase
    50 {
    52 {
    51     /** Maximum view height in percentage from display client area height. */
    53     /** Maximum view height in percentage from display client area height. */
    52     protected static final int MAX_VIEW_HEIGHT = 80;
    54     protected static final int MAX_VIEW_HEIGHT = 80;
       
    55     /** Maximum view width in percentage from display client area width. */
       
    56     protected static final int MAX_VIEW_WIDTH = 90;
    53     /** Parent shell for this view. */
    57     /** Parent shell for this view. */
    54     protected Shell iParent = null;
    58     protected Shell iParent = null;
    55     /** Container for the contents of the view */
    59     /** Container for the contents of the view */
    56     private Composite iContainer = null;
    60     private Composite iContainer = null;
    57     /** ScrolledComposite for iComposite. */
    61     /** ScrolledComposite for iComposite. */
    97 
   101 
    98         // Each view gets a shell to be used as a parameter.
   102         // Each view gets a shell to be used as a parameter.
    99         iParent = (Shell)aParent;
   103         iParent = (Shell)aParent;
   100 
   104 
   101         iContainer = new Composite(iParent, 0);
   105         iContainer = new Composite(iParent, 0);
       
   106         setCssId(iContainer, "dialogArea");
   102         iContainer.setVisible(false);
   107         iContainer.setVisible(false);
   103 
   108 
   104         iColumns = aColumns;
   109         iColumns = aColumns;
   105 
   110 
   106         // Store the default bounds for later height adjustments.
   111         // Store the default bounds for later height adjustments.
   214     }
   219     }
   215 
   220 
   216     /** Set title for this view. */
   221     /** Set title for this view. */
   217     public void setTitle(String aTitle)
   222     public void setTitle(String aTitle)
   218     {
   223     {
   219         // Dialog shells have no title anymore
   224         // Dialog shells have no title.
   220     }
   225     }
   221 
   226 
   222     /** Disposes this view. */
   227     /** Disposes this view. */
   223     public void dispose()
   228     public void dispose()
   224     {
   229     {
   339             getAppInfoComposite().setSize(
   344             getAppInfoComposite().setSize(
   340                 getAppInfoComposite().computeSize(
   345                 getAppInfoComposite().computeSize(
   341                     SWT.DEFAULT, SWT.DEFAULT));
   346                     SWT.DEFAULT, SWT.DEFAULT));
   342         }
   347         }
   343 
   348 
   344         int contentWidth = iDefaultContentSize.x;
   349         int contentWidth = iDefaultContentSize.x * MAX_VIEW_WIDTH / 100;
   345         if (aVerticalScrollBarVisible)
   350         if (aVerticalScrollBarVisible)
   346         {
   351         {
   347             int verticalScrollBarWidth =
   352             int verticalScrollBarWidth =
   348                 getScrolledComposite().getVerticalBar().getSize().x;
   353                 getScrolledComposite().getVerticalBar().getSize().x;
   349             contentWidth = iDefaultContentSize.x - verticalScrollBarWidth;
   354             contentWidth -= verticalScrollBarWidth;
   350         }
   355         }
   351 
   356 
   352         // Recalculate the size of the content.
   357         // Recalculate the size of the content.
   353         Point contentSize = comp.computeSize(contentWidth, SWT.DEFAULT);
   358         Point contentSize = comp.computeSize(contentWidth, SWT.DEFAULT);
   354         comp.setSize(contentSize);
   359         comp.setSize(contentSize);
   355         Point cmdContentSize = cmdComp.computeSize(iDefaultContentSize.x, SWT.DEFAULT);
   360         Point cmdContentSize = cmdComp.computeSize(iDefaultContentSize.x, SWT.DEFAULT);
   356         cmdComp.setSize(cmdContentSize);
   361         cmdComp.setSize(cmdContentSize);
   357 
   362 
   358         // Adjust Shell height. The Shell never changes the x position, nor the width.
   363         // Adjust Shell height and width.
   359         Rectangle dispRect = shell.getDisplay().getClientArea();
   364         Rectangle dispRect = shell.getDisplay().getClientArea();
   360         int offset = iDefaultContentSize.y - contentSize.y - cmdContentSize.y;
   365         int offset = iDefaultContentSize.y - contentSize.y - cmdContentSize.y;
   361 
   366 
   362         Rectangle defShellBounds = iInstallerUi.getDefaultShellBounds();
   367         Rectangle defShellBounds = iInstallerUi.getDefaultShellBounds();
   363         int newHeight = defShellBounds.height - offset;
   368         int newHeight = defShellBounds.height - offset;
   366         if (newHeight > maxHeight)
   371         if (newHeight > maxHeight)
   367         {
   372         {
   368             offset -= maxHeight - newHeight;
   373             offset -= maxHeight - newHeight;
   369             newHeight = maxHeight;
   374             newHeight = maxHeight;
   370         }
   375         }
   371 
   376         int newWidth = defShellBounds.width;
       
   377         int maxWidth = dispRect.width * MAX_VIEW_WIDTH / 100;
       
   378         if (newWidth > maxWidth)
       
   379         {
       
   380             newWidth = maxWidth;
       
   381         }
       
   382 
       
   383         // Always center horizontally and vertically.
   372         Rectangle dispBounds = shell.getDisplay().getBounds();
   384         Rectangle dispBounds = shell.getDisplay().getBounds();
       
   385         int x = dispBounds.width - newWidth;
   373         int y = dispBounds.height - newHeight;
   386         int y = dispBounds.height - newHeight;
   374         // Always center vertically.
   387         x /= 2;
   375         y /= 2;
   388         y /= 2;
   376         // For landscape orientation center vertically
   389         shell.setBounds(x, y, newWidth, newHeight);
   377         //if (dispRect.width > dispRect.height)
       
   378         //{
       
   379         //    y /= 2;
       
   380         //}
       
   381         // Set bounds when command Buttons are in use.
       
   382         shell.setBounds(defShellBounds.x, y, defShellBounds.width, newHeight);
       
   383         Rectangle clientArea = shell.getClientArea();
   390         Rectangle clientArea = shell.getClientArea();
   384         iContainer.setSize(clientArea.width, clientArea.height);
   391         iContainer.setSize(clientArea.width, clientArea.height);
   385         iContainer.layout(true);
   392         iContainer.layout(true);
   386     }
   393     }
   387 
   394 
   432     {
   439     {
   433         return iColumns;
   440         return iColumns;
   434     }
   441     }
   435 
   442 
   436     /**
   443     /**
       
   444      * Sets CSS id for given widget.
       
   445      */
       
   446     protected void setCssId(Widget aWidget, String aCssId)
       
   447     {
       
   448         aWidget.setData(WidgetConstant.CSS_ID, aCssId);
       
   449     }
       
   450 
       
   451     /**
   437      * Adds header used in installation views.
   452      * Adds header used in installation views.
   438      */
   453      */
   439     protected void addHeader(
   454     protected void addHeader(
   440         String aTitle, InstallInfo aInstallInfo, UninstallInfo aUninstallInfo)
   455         String aTitle, InstallInfo aInstallInfo, UninstallInfo aUninstallInfo)
   441     {
   456     {
   448     protected void addHeader(
   463     protected void addHeader(
   449         String aTitle, InstallInfo aInstallInfo, UninstallInfo aUninstallInfo,
   464         String aTitle, InstallInfo aInstallInfo, UninstallInfo aUninstallInfo,
   450         boolean aSecurityButton)
   465         boolean aSecurityButton)
   451     {
   466     {
   452         // Add title.
   467         // Add title.
   453         String title = InstallerUiTexts.get(InstallerUiTexts.INSTALL_QUERY);
   468         if (aTitle == null)
       
   469         {
       
   470             aTitle = InstallerUiTexts.get(InstallerUiTexts.INSTALL_QUERY);
       
   471             if (aInstallInfo != null && aInstallInfo.getOldVersion() != null)
       
   472             {
       
   473                 aTitle = InstallerUiTexts.get(InstallerUiTexts.UPDATE_QUERY);
       
   474             }
       
   475         }
       
   476         Label titleLabel = createLabel(aTitle, getColumns() - 1, SWT.WRAP);
       
   477         setCssId(titleLabel, "heading");
       
   478 
   454         if (aInstallInfo != null)
   479         if (aInstallInfo != null)
   455         {
   480         {
   456             if (aInstallInfo.getOldVersion() != null)
       
   457             {
       
   458                 title = InstallerUiTexts.get(InstallerUiTexts.UPDATE_QUERY);
       
   459             }
       
   460             iCertificates = aInstallInfo.getCertificates();
   481             iCertificates = aInstallInfo.getCertificates();
   461         }
   482         }
   462         if (aUninstallInfo != null)
   483         else if (aUninstallInfo != null)
   463         {
   484         {
   464             title = "Uninstall?";
       
   465             iCertificates = aUninstallInfo.getCertificates();
   485             iCertificates = aUninstallInfo.getCertificates();
   466         }
   486         }
   467         Label titleLabel = createLabel(aTitle, getColumns() - 1, SWT.WRAP);
       
   468         titleLabel.setFont(iInstallerUi.getBoldFont());
       
   469 
       
   470         if (aSecurityButton)
   487         if (aSecurityButton)
   471         {
   488         {
   472             // Add security icon.
   489             // Add security button.
   473             createSecurityButton();
   490             createSecurityButton();
   474         }
   491         }
   475         else
   492         else
   476         {
   493         {
   477             // Add security icon.
   494             // Add security icon.
   499         int iconColumns = 0;
   516         int iconColumns = 0;
   500         if (iSuiteIcon != null)
   517         if (iSuiteIcon != null)
   501         {
   518         {
   502             iconColumns = 2;
   519             iconColumns = 2;
   503             Label iconLabel = createLabel(iSuiteIcon, iconColumns, SWT.NONE);
   520             Label iconLabel = createLabel(iSuiteIcon, iconColumns, SWT.NONE);
       
   521             setCssId(iconLabel, "contentIcon");
   504         }
   522         }
   505 
   523 
   506         // Create a Composite for displaying application info.
   524         // Create a Composite for displaying application info.
   507         iAppInfoScrolledComposite =
   525         iAppInfoScrolledComposite =
   508             new ScrolledComposite(getComposite(), SWT.H_SCROLL | SWT.V_SCROLL);
   526             new ScrolledComposite(getComposite(), SWT.V_SCROLL);
   509         iAppInfoScrolledComposite.setAlwaysShowScrollBars(false);
   527         iAppInfoScrolledComposite.setAlwaysShowScrollBars(false);
   510         iAppInfoScrolledComposite.setExpandHorizontal(true);
   528         iAppInfoScrolledComposite.setExpandHorizontal(true);
   511         GridData gridData = new GridData(GridData.FILL_BOTH);
   529         GridData gridData = new GridData(GridData.FILL_BOTH);
   512         gridData.horizontalSpan = getColumns() - iconColumns;
   530         gridData.horizontalSpan = getColumns() - iconColumns;
   513         iAppInfoScrolledComposite.setLayoutData(gridData);
   531         iAppInfoScrolledComposite.setLayoutData(gridData);
   514         iAppInfoComposite = new Composite(iAppInfoScrolledComposite, SWT.NONE);
   532         iAppInfoComposite = new Composite(iAppInfoScrolledComposite, SWT.NONE);
   515         iAppInfoComposite.setLayout(new GridLayout(1, true));
   533         iAppInfoComposite.setLayout(new GridLayout(1, true));
   516         iAppInfoScrolledComposite.setContent(iAppInfoComposite);
   534         iAppInfoScrolledComposite.setContent(iAppInfoComposite);
       
   535         setCssId(iAppInfoScrolledComposite, "appInfoArea");
   517     }
   536     }
   518 
   537 
   519     /**
   538     /**
   520      * Adds application information to the header.
   539      * Adds application information to the header.
   521      */
   540      */
   528         }
   547         }
   529 
   548 
   530         // Add suite name and version.
   549         // Add suite name and version.
   531         createAppInfoLabel(
   550         createAppInfoLabel(
   532             InstallerUiTexts.get(
   551             InstallerUiTexts.get(
   533                 InstallerUiTexts.SUITE_NAME,
   552                 InstallerUiTexts.SUITE_NAME_VERSION,
   534                 new String[] { aInstallInfo.getName(),
   553                 new String[] { aInstallInfo.getName(),
   535                                aInstallInfo.getVersion() }));
   554                                aInstallInfo.getVersion() }));
   536         if (aFull)
   555         if (aFull)
   537         {
   556         {
   538             // Add vendor.
   557             // Add vendor.
   551         {
   570         {
   552             size += aInstallInfo.getDataSize();
   571             size += aInstallInfo.getDataSize();
   553         }
   572         }
   554         if (size > 0)
   573         if (size > 0)
   555         {
   574         {
   556             createAppInfoLabel(
   575             if (size > 1024*1024)
   557                 InstallerUiTexts.get(
   576             {
   558                     InstallerUiTexts.SIZE_KB,
   577                 createAppInfoLabel(
   559                     new String[] { Long.toString(1 + size/1024) }));
   578                     InstallerUiTexts.get(
       
   579                         InstallerUiTexts.SIZE_MB,
       
   580                         new Object[] { new Integer((int)(1 + size/(1024*1024))) }));
       
   581             }
       
   582             else
       
   583             {
       
   584                 createAppInfoLabel(
       
   585                     InstallerUiTexts.get(
       
   586                         InstallerUiTexts.SIZE_KB,
       
   587                         new Object[] { new Integer((int)(1 + size/1024)) }));
       
   588             }
   560         }
   589         }
   561         if (aFull)
   590         if (aFull)
   562         {
   591         {
   563             // Add application names.
   592             // Add application names.
   564             ApplicationInfo[] apps = aInstallInfo.getApplications();
   593             ApplicationInfo[] apps = aInstallInfo.getApplications();
   637         Label label = new Label(getComposite(), aStyle);
   666         Label label = new Label(getComposite(), aStyle);
   638         label.setImage(aImage);
   667         label.setImage(aImage);
   639         GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
   668         GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
   640         gridData.horizontalSpan = aColumns;
   669         gridData.horizontalSpan = aColumns;
   641         gridData.horizontalAlignment = SWT.CENTER;
   670         gridData.horizontalAlignment = SWT.CENTER;
   642         gridData.verticalAlignment = SWT.CENTER;
   671         gridData.verticalAlignment = SWT.TOP;
   643         label.setLayoutData(gridData);
   672         label.setLayoutData(gridData);
   644         return label;
   673         return label;
   645     }
   674     }
   646 
   675 
   647     /**
   676     /**
   669      * @return label that was added to this view
   698      * @return label that was added to this view
   670      */
   699      */
   671     protected Label createSecurityLabel(boolean aIdentified)
   700     protected Label createSecurityLabel(boolean aIdentified)
   672     {
   701     {
   673         Label label = createLabel((Image)null, 1, SWT.NONE);
   702         Label label = createLabel((Image)null, 1, SWT.NONE);
       
   703         setCssId(label, "securityLabel");
   674         Image securityIcon = null;
   704         Image securityIcon = null;
   675         if (iInstallerUi != null)
   705         if (iInstallerUi != null)
   676         {
   706         {
   677             securityIcon = iInstallerUi.getSecurityIcon(
   707             securityIcon = iInstallerUi.getSecurityIcon(
   678                 getDisplay(), aIdentified);
   708                 getDisplay(), aIdentified);
   689     }
   719     }
   690 
   720 
   691     protected Button createSecurityButton()
   721     protected Button createSecurityButton()
   692     {
   722     {
   693         Button button = new Button(getComposite(), SWT.PUSH);
   723         Button button = new Button(getComposite(), SWT.PUSH);
       
   724         setCssId(button, "securityButton");
   694         GridData gridData = new GridData(
   725         GridData gridData = new GridData(
   695             GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
   726             GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
   696         gridData.horizontalSpan = 1;
   727         gridData.horizontalSpan = 1;
   697         gridData.horizontalAlignment = SWT.CENTER;
   728         gridData.horizontalAlignment = SWT.CENTER;
   698         gridData.verticalAlignment = SWT.CENTER;
   729         gridData.verticalAlignment = SWT.CENTER;