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; |
|
38 import org.eclipse.swt.layout.GridData; |
37 import org.eclipse.swt.layout.GridData; |
39 import org.eclipse.swt.layout.GridLayout; |
38 import org.eclipse.swt.layout.GridLayout; |
40 import org.eclipse.swt.widgets.Button; |
39 import org.eclipse.swt.widgets.Button; |
41 import org.eclipse.swt.widgets.Composite; |
40 import org.eclipse.swt.widgets.Composite; |
42 import org.eclipse.swt.widgets.Control; |
41 import org.eclipse.swt.widgets.Control; |
43 import org.eclipse.swt.widgets.Display; |
42 import org.eclipse.swt.widgets.Display; |
44 import org.eclipse.swt.widgets.Label; |
43 import org.eclipse.swt.widgets.Label; |
45 import org.eclipse.swt.widgets.Shell; |
44 import org.eclipse.swt.widgets.Shell; |
46 import org.eclipse.swt.widgets.Widget; |
|
47 |
45 |
48 /** |
46 /** |
49 * Base class for different InstallerUi views. |
47 * Base class for different InstallerUi views. |
50 */ |
48 */ |
51 abstract public class ViewBase |
49 abstract public class ViewBase |
52 { |
50 { |
53 /** Maximum view height in percentage from display client area height. */ |
51 /** Maximum view height in percentage from display client area height. */ |
54 protected static final int MAX_VIEW_HEIGHT = 80; |
52 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; |
|
57 /** Parent shell for this view. */ |
53 /** Parent shell for this view. */ |
58 protected Shell iParent = null; |
54 protected Shell iParent = null; |
59 /** Container for the contents of the view */ |
55 /** Container for the contents of the view */ |
60 private Composite iContainer = null; |
56 private Composite iContainer = null; |
61 /** ScrolledComposite for iComposite. */ |
57 /** ScrolledComposite for iComposite. */ |
76 private boolean iVisible = false; |
72 private boolean iVisible = false; |
77 /** Number of columns for this view's GridLayout. */ |
73 /** Number of columns for this view's GridLayout. */ |
78 private int iColumns = 1; |
74 private int iColumns = 1; |
79 /** Default content size. */ |
75 /** Default content size. */ |
80 private Point iDefaultContentSize = null; |
76 private Point iDefaultContentSize = null; |
81 /** Certificate details view. */ |
77 /** Certificate details view. */ |
82 private CertificateDetailsView iCertificateDetailsView = null; |
78 private CertificateDetailsView iCertificateDetailsView = null; |
83 /** Certificates for this application. */ |
79 /** Certificates for this application. */ |
84 protected SigningCertificate[] iCertificates = null; |
80 protected SigningCertificate[] iCertificates = null; |
85 |
81 |
86 /** Constructor */ |
82 /** Constructor */ |
101 |
97 |
102 // Each view gets a shell to be used as a parameter. |
98 // Each view gets a shell to be used as a parameter. |
103 iParent = (Shell)aParent; |
99 iParent = (Shell)aParent; |
104 |
100 |
105 iContainer = new Composite(iParent, 0); |
101 iContainer = new Composite(iParent, 0); |
106 setCssId(iContainer, "dialogArea"); |
|
107 iContainer.setVisible(false); |
102 iContainer.setVisible(false); |
108 |
103 |
109 iColumns = aColumns; |
104 iColumns = aColumns; |
110 |
105 |
111 // Store the default bounds for later height adjustments. |
106 // Store the default bounds for later height adjustments. |
344 getAppInfoComposite().setSize( |
339 getAppInfoComposite().setSize( |
345 getAppInfoComposite().computeSize( |
340 getAppInfoComposite().computeSize( |
346 SWT.DEFAULT, SWT.DEFAULT)); |
341 SWT.DEFAULT, SWT.DEFAULT)); |
347 } |
342 } |
348 |
343 |
349 int contentWidth = iDefaultContentSize.x * MAX_VIEW_WIDTH / 100; |
344 int contentWidth = iDefaultContentSize.x; |
350 if (aVerticalScrollBarVisible) |
345 if (aVerticalScrollBarVisible) |
351 { |
346 { |
352 int verticalScrollBarWidth = |
347 int verticalScrollBarWidth = |
353 getScrolledComposite().getVerticalBar().getSize().x; |
348 getScrolledComposite().getVerticalBar().getSize().x; |
354 contentWidth -= verticalScrollBarWidth; |
349 contentWidth = iDefaultContentSize.x - verticalScrollBarWidth; |
355 } |
350 } |
356 |
351 |
357 // Recalculate the size of the content. |
352 // Recalculate the size of the content. |
358 Point contentSize = comp.computeSize(contentWidth, SWT.DEFAULT); |
353 Point contentSize = comp.computeSize(contentWidth, SWT.DEFAULT); |
359 comp.setSize(contentSize); |
354 comp.setSize(contentSize); |
360 Point cmdContentSize = cmdComp.computeSize(iDefaultContentSize.x, SWT.DEFAULT); |
355 Point cmdContentSize = cmdComp.computeSize(iDefaultContentSize.x, SWT.DEFAULT); |
361 cmdComp.setSize(cmdContentSize); |
356 cmdComp.setSize(cmdContentSize); |
362 |
357 |
363 // Adjust Shell height and width. |
358 // Adjust Shell height. The Shell never changes the x position, nor the width. |
364 Rectangle dispRect = shell.getDisplay().getClientArea(); |
359 Rectangle dispRect = shell.getDisplay().getClientArea(); |
365 int offset = iDefaultContentSize.y - contentSize.y - cmdContentSize.y; |
360 int offset = iDefaultContentSize.y - contentSize.y - cmdContentSize.y; |
366 |
361 |
367 Rectangle defShellBounds = iInstallerUi.getDefaultShellBounds(); |
362 Rectangle defShellBounds = iInstallerUi.getDefaultShellBounds(); |
368 int newHeight = defShellBounds.height - offset; |
363 int newHeight = defShellBounds.height - offset; |
371 if (newHeight > maxHeight) |
366 if (newHeight > maxHeight) |
372 { |
367 { |
373 offset -= maxHeight - newHeight; |
368 offset -= maxHeight - newHeight; |
374 newHeight = maxHeight; |
369 newHeight = maxHeight; |
375 } |
370 } |
376 int newWidth = defShellBounds.width; |
371 |
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. |
|
384 Rectangle dispBounds = shell.getDisplay().getBounds(); |
372 Rectangle dispBounds = shell.getDisplay().getBounds(); |
385 int x = dispBounds.width - newWidth; |
|
386 int y = dispBounds.height - newHeight; |
373 int y = dispBounds.height - newHeight; |
387 x /= 2; |
374 // Always center vertically. |
388 y /= 2; |
375 y /= 2; |
389 shell.setBounds(x, y, newWidth, newHeight); |
376 // For landscape orientation center vertically |
|
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); |
390 Rectangle clientArea = shell.getClientArea(); |
383 Rectangle clientArea = shell.getClientArea(); |
391 iContainer.setSize(clientArea.width, clientArea.height); |
384 iContainer.setSize(clientArea.width, clientArea.height); |
392 iContainer.layout(true); |
385 iContainer.layout(true); |
393 } |
386 } |
394 |
387 |
439 { |
432 { |
440 return iColumns; |
433 return iColumns; |
441 } |
434 } |
442 |
435 |
443 /** |
436 /** |
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 /** |
|
452 * Adds header used in installation views. |
437 * Adds header used in installation views. |
453 */ |
438 */ |
454 protected void addHeader( |
439 protected void addHeader( |
455 String aTitle, InstallInfo aInstallInfo, UninstallInfo aUninstallInfo) |
440 String aTitle, InstallInfo aInstallInfo, UninstallInfo aUninstallInfo) |
456 { |
441 { |
463 protected void addHeader( |
448 protected void addHeader( |
464 String aTitle, InstallInfo aInstallInfo, UninstallInfo aUninstallInfo, |
449 String aTitle, InstallInfo aInstallInfo, UninstallInfo aUninstallInfo, |
465 boolean aSecurityButton) |
450 boolean aSecurityButton) |
466 { |
451 { |
467 // Add title. |
452 // Add title. |
468 if (aTitle == null) |
453 String title = InstallerUiTexts.get(InstallerUiTexts.INSTALL_QUERY); |
469 { |
454 if (aInstallInfo != null) |
470 aTitle = InstallerUiTexts.get(InstallerUiTexts.INSTALL_QUERY); |
455 { |
471 if (aInstallInfo != null && aInstallInfo.getOldVersion() != null) |
456 if (aInstallInfo.getOldVersion() != null) |
472 { |
457 { |
473 aTitle = InstallerUiTexts.get(InstallerUiTexts.UPDATE_QUERY); |
458 title = InstallerUiTexts.get(InstallerUiTexts.UPDATE_QUERY); |
474 } |
459 } |
|
460 iCertificates = aInstallInfo.getCertificates(); |
|
461 } |
|
462 if (aUninstallInfo != null) |
|
463 { |
|
464 title = "Uninstall?"; |
|
465 iCertificates = aUninstallInfo.getCertificates(); |
475 } |
466 } |
476 Label titleLabel = createLabel(aTitle, getColumns() - 1, SWT.WRAP); |
467 Label titleLabel = createLabel(aTitle, getColumns() - 1, SWT.WRAP); |
477 setCssId(titleLabel, "heading"); |
468 titleLabel.setFont(iInstallerUi.getBoldFont()); |
478 |
469 |
479 if (aInstallInfo != null) |
|
480 { |
|
481 iCertificates = aInstallInfo.getCertificates(); |
|
482 } |
|
483 else if (aUninstallInfo != null) |
|
484 { |
|
485 iCertificates = aUninstallInfo.getCertificates(); |
|
486 } |
|
487 if (aSecurityButton) |
470 if (aSecurityButton) |
488 { |
471 { |
489 // Add security button. |
472 // Add security icon. |
490 createSecurityButton(); |
473 createSecurityButton(); |
491 } |
474 } |
492 else |
475 else |
493 { |
476 { |
494 // Add security icon. |
477 // Add security icon. |
516 int iconColumns = 0; |
499 int iconColumns = 0; |
517 if (iSuiteIcon != null) |
500 if (iSuiteIcon != null) |
518 { |
501 { |
519 iconColumns = 2; |
502 iconColumns = 2; |
520 Label iconLabel = createLabel(iSuiteIcon, iconColumns, SWT.NONE); |
503 Label iconLabel = createLabel(iSuiteIcon, iconColumns, SWT.NONE); |
521 setCssId(iconLabel, "contentIcon"); |
|
522 } |
504 } |
523 |
505 |
524 // Create a Composite for displaying application info. |
506 // Create a Composite for displaying application info. |
525 iAppInfoScrolledComposite = |
507 iAppInfoScrolledComposite = |
526 new ScrolledComposite(getComposite(), SWT.V_SCROLL); |
508 new ScrolledComposite(getComposite(), SWT.H_SCROLL | SWT.V_SCROLL); |
527 iAppInfoScrolledComposite.setAlwaysShowScrollBars(false); |
509 iAppInfoScrolledComposite.setAlwaysShowScrollBars(false); |
528 iAppInfoScrolledComposite.setExpandHorizontal(true); |
510 iAppInfoScrolledComposite.setExpandHorizontal(true); |
529 GridData gridData = new GridData(GridData.FILL_BOTH); |
511 GridData gridData = new GridData(GridData.FILL_BOTH); |
530 gridData.horizontalSpan = getColumns() - iconColumns; |
512 gridData.horizontalSpan = getColumns() - iconColumns; |
531 iAppInfoScrolledComposite.setLayoutData(gridData); |
513 iAppInfoScrolledComposite.setLayoutData(gridData); |
532 iAppInfoComposite = new Composite(iAppInfoScrolledComposite, SWT.NONE); |
514 iAppInfoComposite = new Composite(iAppInfoScrolledComposite, SWT.NONE); |
533 iAppInfoComposite.setLayout(new GridLayout(1, true)); |
515 iAppInfoComposite.setLayout(new GridLayout(1, true)); |
534 iAppInfoScrolledComposite.setContent(iAppInfoComposite); |
516 iAppInfoScrolledComposite.setContent(iAppInfoComposite); |
535 setCssId(iAppInfoScrolledComposite, "appInfoArea"); |
|
536 } |
517 } |
537 |
518 |
538 /** |
519 /** |
539 * Adds application information to the header. |
520 * Adds application information to the header. |
540 */ |
521 */ |
547 } |
528 } |
548 |
529 |
549 // Add suite name and version. |
530 // Add suite name and version. |
550 createAppInfoLabel( |
531 createAppInfoLabel( |
551 InstallerUiTexts.get( |
532 InstallerUiTexts.get( |
552 InstallerUiTexts.SUITE_NAME_VERSION, |
533 InstallerUiTexts.SUITE_NAME, |
553 new String[] { aInstallInfo.getName(), |
534 new String[] { aInstallInfo.getName(), |
554 aInstallInfo.getVersion() })); |
535 aInstallInfo.getVersion() })); |
555 if (aFull) |
536 if (aFull) |
556 { |
537 { |
557 // Add vendor. |
538 // Add vendor. |
570 { |
551 { |
571 size += aInstallInfo.getDataSize(); |
552 size += aInstallInfo.getDataSize(); |
572 } |
553 } |
573 if (size > 0) |
554 if (size > 0) |
574 { |
555 { |
575 if (size > 1024*1024) |
556 createAppInfoLabel( |
576 { |
557 InstallerUiTexts.get( |
577 createAppInfoLabel( |
558 InstallerUiTexts.SIZE_KB, |
578 InstallerUiTexts.get( |
559 new String[] { Long.toString(1 + size/1024) })); |
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 } |
|
589 } |
560 } |
590 if (aFull) |
561 if (aFull) |
591 { |
562 { |
592 // Add application names. |
563 // Add application names. |
593 ApplicationInfo[] apps = aInstallInfo.getApplications(); |
564 ApplicationInfo[] apps = aInstallInfo.getApplications(); |
666 Label label = new Label(getComposite(), aStyle); |
637 Label label = new Label(getComposite(), aStyle); |
667 label.setImage(aImage); |
638 label.setImage(aImage); |
668 GridData gridData = new GridData(GridData.FILL_HORIZONTAL); |
639 GridData gridData = new GridData(GridData.FILL_HORIZONTAL); |
669 gridData.horizontalSpan = aColumns; |
640 gridData.horizontalSpan = aColumns; |
670 gridData.horizontalAlignment = SWT.CENTER; |
641 gridData.horizontalAlignment = SWT.CENTER; |
671 gridData.verticalAlignment = SWT.TOP; |
642 gridData.verticalAlignment = SWT.CENTER; |
672 label.setLayoutData(gridData); |
643 label.setLayoutData(gridData); |
673 return label; |
644 return label; |
674 } |
645 } |
675 |
646 |
676 /** |
647 /** |
698 * @return label that was added to this view |
669 * @return label that was added to this view |
699 */ |
670 */ |
700 protected Label createSecurityLabel(boolean aIdentified) |
671 protected Label createSecurityLabel(boolean aIdentified) |
701 { |
672 { |
702 Label label = createLabel((Image)null, 1, SWT.NONE); |
673 Label label = createLabel((Image)null, 1, SWT.NONE); |
703 setCssId(label, "securityLabel"); |
|
704 Image securityIcon = null; |
674 Image securityIcon = null; |
705 if (iInstallerUi != null) |
675 if (iInstallerUi != null) |
706 { |
676 { |
707 securityIcon = iInstallerUi.getSecurityIcon( |
677 securityIcon = iInstallerUi.getSecurityIcon( |
708 getDisplay(), aIdentified); |
678 getDisplay(), aIdentified); |
719 } |
689 } |
720 |
690 |
721 protected Button createSecurityButton() |
691 protected Button createSecurityButton() |
722 { |
692 { |
723 Button button = new Button(getComposite(), SWT.PUSH); |
693 Button button = new Button(getComposite(), SWT.PUSH); |
724 setCssId(button, "securityButton"); |
|
725 GridData gridData = new GridData( |
694 GridData gridData = new GridData( |
726 GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); |
695 GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); |
727 gridData.horizontalSpan = 1; |
696 gridData.horizontalSpan = 1; |
728 gridData.horizontalAlignment = SWT.CENTER; |
697 gridData.horizontalAlignment = SWT.CENTER; |
729 gridData.verticalAlignment = SWT.CENTER; |
698 gridData.verticalAlignment = SWT.CENTER; |
801 // where this method gets executed. |
770 // where this method gets executed. |
802 new Thread(new Runnable() |
771 new Thread(new Runnable() |
803 { |
772 { |
804 public void run() |
773 public void run() |
805 { |
774 { |
806 iInstallerUi.setCertificateDetailsView(iCertificateDetailsView); |
|
807 if (iCertificateDetailsView.confirm()) |
775 if (iCertificateDetailsView.confirm()) |
808 { |
776 { |
809 log("certificateDetailsView confirmed"); |
777 log("certificateDetailsView confirmed"); |
810 } |
778 } |
811 else |
779 else |
812 { |
780 { |
813 log("certificateDetailsView cancelled"); |
781 log("certificateDetailsView cancelled"); |
814 } |
782 } |
815 iCertificateDetailsView.dispose(); |
783 iCertificateDetailsView.dispose(); |
816 iCertificateDetailsView = null; |
784 iCertificateDetailsView = null; |
817 iInstallerUi.setCertificateDetailsView(null); |
|
818 setVisible(true); |
785 setVisible(true); |
819 } |
786 } |
820 }, "InstallerUiCertViewThread").start(); |
787 }, "InstallerUiCertViewThread").start(); |
821 } |
788 } |
822 } |
789 } |