RemoveEnclaveFileDialog.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 org.eclipse.jface.dialogs.Dialog;
  14. import org.eclipse.swt.SWT;
  15. import org.eclipse.swt.events.SelectionEvent;
  16. import org.eclipse.swt.events.SelectionListener;
  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.DirectoryDialog;
  24. //import org.eclipse.swt.widgets.FileDialog;
  25. import org.eclipse.swt.widgets.Group;
  26. import org.eclipse.swt.widgets.Label;
  27. import org.eclipse.swt.widgets.Shell;
  28. import org.eclipse.swt.widgets.Text;
  29. import com.intel.sgx.handlers.RemoveEnclave;
  30. public class RemoveEnclaveFileDialog extends Dialog{
  31. private Text fileNameField;
  32. private Shell shell;
  33. private RemoveEnclave removeHandler;
  34. public RemoveEnclaveFileDialog(Shell shell, RemoveEnclave removeHandler) {
  35. super(shell);
  36. this.removeHandler = removeHandler;
  37. this.shell = shell;
  38. setShellStyle(SWT.RESIZE | SWT.TITLE);
  39. }
  40. @Override
  41. protected Control createDialogArea(Composite parent) {
  42. Composite composite = (Composite) super.createDialogArea(parent);
  43. final GridLayout gridLayout = new GridLayout(1,false);
  44. composite.setLayout(gridLayout);
  45. final Group container = new Group(composite, SWT.None);
  46. container.setLayout(new GridLayout(3,false));
  47. GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL);
  48. innergrid1.horizontalSpan = 3;
  49. container.setLayoutData(innergrid1);
  50. container.setText("Path to Enclave directory:");
  51. final Label messageLabel = new Label(container, SWT.NONE);
  52. messageLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1));
  53. messageLabel.setText("Enter the name of the Enclave Or Navigate to the Enclave folder to be removed from the host.");
  54. final Label fileNameLabel = new Label(container, SWT.NONE);
  55. fileNameLabel.setLayoutData(new GridData(GridData.BEGINNING,GridData.CENTER, false, false));
  56. fileNameLabel.setText("Enclave Name:");
  57. fileNameField = new Text(container, SWT.SINGLE | SWT.BORDER);
  58. GridData textGridData1 = new GridData(GridData.FILL_HORIZONTAL);
  59. textGridData1.minimumWidth = 400;
  60. textGridData1.grabExcessHorizontalSpace = true;
  61. fileNameField.setLayoutData(textGridData1);
  62. final Button browseButton = new Button(container, SWT.PUSH);
  63. browseButton.setText("Browse");
  64. GridData buttonGridData1 = new GridData(GridData.END);
  65. buttonGridData1.horizontalAlignment = SWT.RIGHT;
  66. buttonGridData1.horizontalSpan = 1;
  67. buttonGridData1.minimumWidth = 120;
  68. browseButton.setLayoutData(buttonGridData1);
  69. browseButton.addSelectionListener(new SelectionListener() {
  70. @Override
  71. public void widgetSelected(SelectionEvent event) {
  72. String result = fileNameField.getText();
  73. DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN);
  74. dialog.setMessage("Select the Enclave Directory to remove.");
  75. dialog.setFilterPath("");
  76. result = dialog.open();
  77. fileNameField.setText(result);
  78. }
  79. @Override
  80. public void widgetDefaultSelected(SelectionEvent e) {
  81. }
  82. });
  83. return container;
  84. }
  85. @Override
  86. protected void configureShell(Shell newShell) {
  87. super.configureShell(newShell);
  88. newShell.setText("Remove an Imported Enclave");
  89. }
  90. @Override
  91. protected void okPressed(){
  92. removeHandler.edlFilename = fileNameField.getText();
  93. if(!fileNameField.getText().isEmpty())
  94. super.okPressed();
  95. }
  96. @Override
  97. protected Point getInitialSize(){
  98. return new Point(675,205);
  99. }
  100. public String getFileName() {
  101. return fileNameField.getText();
  102. }
  103. }