AddEnclaveFileDialog.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ///////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) 2018 Intel Corporation. //
  3. // //
  4. // All rights reserved. This program and the accompanying materials //
  5. // are made available under the terms of the Eclipse Public License v1.0 //
  6. // which accompanies this distribution, and is available at //
  7. // http://www.eclipse.org/legal/epl-v10.html //
  8. // //
  9. // Contributors: //
  10. // Intel Corporation - initial implementation and documentation //
  11. ///////////////////////////////////////////////////////////////////////////
  12. package com.intel.sgx.dialogs;
  13. import javax.swing.JOptionPane;
  14. import org.eclipse.swt.SWT;
  15. import org.eclipse.swt.events.SelectionAdapter;
  16. import org.eclipse.swt.events.SelectionEvent;
  17. import org.eclipse.swt.graphics.Point;
  18. import org.eclipse.swt.layout.GridData;
  19. import org.eclipse.swt.layout.GridLayout;
  20. import org.eclipse.swt.widgets.Button;
  21. import org.eclipse.swt.widgets.Composite;
  22. import org.eclipse.swt.widgets.Control;
  23. import org.eclipse.swt.widgets.Group;
  24. import org.eclipse.swt.widgets.Label;
  25. import org.eclipse.swt.widgets.Shell;
  26. import org.eclipse.swt.widgets.Text;
  27. import com.intel.sgx.handlers.AddEnclave;
  28. public class AddEnclaveFileDialog extends SGXDialogBase {
  29. private Text fileNameField;
  30. private AddEnclave addHandler;
  31. private boolean generateApp = true;
  32. public AddEnclaveFileDialog(Shell shell, AddEnclave addHandler) {
  33. super(shell);
  34. this.addHandler = addHandler;
  35. this.shell = shell;
  36. // setShellStyle(SWT.RESIZE | SWT.TITLE);
  37. }
  38. public boolean generateApp()
  39. {
  40. return generateApp;
  41. }
  42. @Override
  43. protected Control createDialogArea(Composite parent) {
  44. Composite composite = (Composite) super.createDialogArea(parent);
  45. final GridLayout gridLayout = new GridLayout(1,false);
  46. composite.setLayout(gridLayout);
  47. final Group container = new Group(composite, SWT.NONE);
  48. container.setLayout(new GridLayout(3,false));
  49. GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL);
  50. innergrid1.horizontalSpan = 3;
  51. container.setLayoutData(innergrid1);
  52. addLabel(container, "Enter the name of the Enclave. Make sure the name is unique within the hosting application.");
  53. final Label fileNameLabel = new Label(container, SWT.NONE);
  54. fileNameLabel.setText("Enclave name:");
  55. fileNameLabel.setLayoutData(new GridData(GridData.BEGINNING,GridData.CENTER, false, false));
  56. fileNameField = new Text(container,SWT.SINGLE | SWT.BORDER);
  57. GridData textGridData1 = new GridData(GridData.FILL_HORIZONTAL);
  58. textGridData1.minimumWidth = 400;
  59. textGridData1.grabExcessHorizontalSpace = true;
  60. fileNameField.setLayoutData(textGridData1);
  61. Button generateUntrustedApp = new Button(container, SWT.CHECK);
  62. generateUntrustedApp.setText("Generate sample untrusted application?");
  63. generateUntrustedApp.setLayoutData(new GridData(GridData.BEGINNING, GridData.END, false, false, 3, 1));
  64. generateUntrustedApp.setSelection(true);
  65. generateUntrustedApp.addSelectionListener(new SelectionAdapter() {
  66. @Override
  67. public void widgetSelected(SelectionEvent event) {
  68. Button btn = (Button) event.getSource();
  69. generateApp = btn.getSelection();
  70. }
  71. });
  72. container.layout();
  73. composite.layout();
  74. return composite;
  75. }
  76. @Override
  77. protected void configureShell(Shell newShell) {
  78. super.configureShell(newShell);
  79. newShell.setText("Add New Intel(R) SGX Enclave Dialog");
  80. newShell.layout();
  81. }
  82. @Override
  83. protected
  84. void okPressed() {
  85. addHandler.edlFilename = fileNameField.getText();
  86. if(!fileNameField.getText().isEmpty()
  87. ){
  88. if(Character.isDigit(fileNameField.getText().charAt(0)))
  89. {
  90. JOptionPane.showMessageDialog(null, "Enclave names starting with digits are not allowed.", "Error",
  91. JOptionPane.ERROR_MESSAGE);
  92. }
  93. else
  94. super.okPressed();
  95. }
  96. }
  97. @Override
  98. protected Point getInitialSize(){
  99. return new Point(675,200);
  100. }
  101. public String getFileName() {
  102. return fileNameField.getText();
  103. }
  104. }