AddUntrustedModuleDialog.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 java.io.File;
  14. import javax.swing.JOptionPane;
  15. import org.eclipse.jface.dialogs.Dialog;
  16. import org.eclipse.swt.SWT;
  17. import org.eclipse.swt.events.SelectionEvent;
  18. import org.eclipse.swt.events.SelectionListener;
  19. import org.eclipse.swt.graphics.Point;
  20. import org.eclipse.swt.layout.GridData;
  21. import org.eclipse.swt.layout.GridLayout;
  22. import org.eclipse.swt.widgets.Button;
  23. import org.eclipse.swt.widgets.Composite;
  24. import org.eclipse.swt.widgets.Control;
  25. import org.eclipse.swt.widgets.FileDialog;
  26. import org.eclipse.swt.widgets.Group;
  27. import org.eclipse.swt.widgets.Label;
  28. import org.eclipse.swt.widgets.Shell;
  29. import org.eclipse.swt.widgets.Text;
  30. import com.intel.sgx.handlers.AddUntrustedModule;
  31. public class AddUntrustedModuleDialog extends Dialog {
  32. private Text fileNameField,makeFilePathField;
  33. private Shell shell;
  34. private AddUntrustedModule addHandler;
  35. private boolean generateApp = false;
  36. public AddUntrustedModuleDialog(Shell shell, AddUntrustedModule addHandler) {
  37. super(shell);
  38. this.addHandler = addHandler;
  39. this.shell = shell;
  40. //setShellStyle(SWT.RESIZE | SWT.TITLE);
  41. }
  42. public boolean generateApp()
  43. {
  44. return generateApp;
  45. }
  46. @Override
  47. protected Control createDialogArea(Composite parent) {
  48. Composite composite = (Composite) super.createDialogArea(parent);
  49. final GridLayout gridLayout = new GridLayout(1,false);
  50. composite.setLayout(gridLayout);
  51. final Group container = new Group(composite, SWT.NONE);
  52. container.setLayout(new GridLayout(3,false));
  53. GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL);
  54. innergrid1.horizontalSpan = 3;
  55. container.setLayoutData(innergrid1);
  56. final Label messageLabel = new Label(container, SWT.NONE);
  57. messageLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1));
  58. messageLabel.setText("Enter the path to the Enclave Descriptor file (*.edl) of the enclave to host.");
  59. final Label fileNameLabel = new Label(container, SWT.NONE);
  60. fileNameLabel.setText("Filename:");
  61. fileNameLabel.setLayoutData(new GridData(GridData.BEGINNING,GridData.CENTER, false, false));
  62. fileNameField = new Text(container,SWT.SINGLE | SWT.BORDER);
  63. GridData textGridData1 = new GridData(GridData.FILL_HORIZONTAL);
  64. textGridData1.minimumWidth = 400;
  65. textGridData1.grabExcessHorizontalSpace = true;
  66. fileNameField.setLayoutData(textGridData1);
  67. final Button browseButton = new Button(container, SWT.PUSH);
  68. browseButton.setText("Browse");
  69. GridData buttonGridData1 = new GridData(GridData.END);
  70. buttonGridData1.horizontalAlignment = SWT.RIGHT;
  71. buttonGridData1.horizontalSpan = 1;
  72. buttonGridData1.minimumWidth = 120;
  73. browseButton.setLayoutData(buttonGridData1);
  74. browseButton.addSelectionListener(new SelectionListener() {
  75. @Override
  76. public void widgetSelected(SelectionEvent event) {
  77. String result = null;
  78. shell = new Shell();
  79. FileDialog dialog = new FileDialog(shell, SWT.OPEN);
  80. dialog.setFilterExtensions(new String [] {"*.edl"});
  81. dialog.setFilterPath("");
  82. result = dialog.open();
  83. fileNameField.setText(result);
  84. }
  85. @Override
  86. public void widgetDefaultSelected(SelectionEvent e) {
  87. }
  88. });
  89. return composite;
  90. }
  91. @Override
  92. protected void configureShell(Shell newShell) {
  93. super.configureShell(newShell);
  94. newShell.setText("Add Intel(R) SGX Untrusted Module.");
  95. }
  96. @Override
  97. protected
  98. void okPressed(){
  99. addHandler.edlFilename = fileNameField.getText();
  100. if(!fileNameField.getText().isEmpty())
  101. if((new File(fileNameField.getText())).isFile())
  102. super.okPressed();
  103. else
  104. JOptionPane.showMessageDialog(null, "EDL file does not exist.", "Error",
  105. JOptionPane.ERROR_MESSAGE);
  106. }
  107. @Override
  108. protected Point getInitialSize(){
  109. return new Point(675,200);
  110. }
  111. public String getFileName() {
  112. return fileNameField.getText();
  113. }
  114. }