/**
  * Returns whether this page's controls currently all contain valid values.
  *
  * @return <code>true</code> if all controls are valid, and <code>false</code> if at least one is
  *     invalid
  */
 protected boolean validatePage() {
   if (outputFolder == null || !outputFolder.exists()) {
     setErrorMessage(
         "No output folder is selected.\n"
             + "Please select a folder before starting the import wizard!");
     return false;
   }
   if (editor.getStringValue().length() == 0) {
     // no error message as this is obvious to the user
     setErrorMessage(null);
     return false;
   }
   File inputFile = new File(editor.getStringValue());
   if (!inputFile.exists()) {
     setErrorMessage("The file '" + inputFile.getName() + "' does not exist!");
     return false;
   }
   if (inputFile.isDirectory()) {
     setErrorMessage("'" + inputFile.getName() + "' is a directory!");
     return false;
   }
   if (getNewFolder().exists()) {
     setErrorMessage("The folder '" + getNewFolder().getFullPath() + "' already exists!");
     return false;
   }
   setErrorMessage(null);
   return true;
 }
  /** (non-Javadoc) Method declared on IDialogPage. */
  public void createControl(Composite parent) {
    initializeDialogUnits(parent);
    Composite fileSelectionArea = new Composite(parent, SWT.NONE);
    GridData fileSelectionData = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
    fileSelectionArea.setLayoutData(fileSelectionData);

    GridLayout fileSelectionLayout = new GridLayout();
    fileSelectionLayout.numColumns = 1;
    fileSelectionLayout.makeColumnsEqualWidth = false;
    fileSelectionLayout.marginWidth = 0;
    fileSelectionLayout.marginHeight = 0;
    fileSelectionArea.setLayout(fileSelectionLayout);

    editor =
        new FileFieldEditor(
            "fileSelect", "Select File: ", fileSelectionArea); // NON-NLS-1 //NON-NLS-2
    String[] extensions = new String[] {"*.xml"}; // NON-NLS-1
    editor.setFileExtensions(extensions);
    editor
        .getTextControl(fileSelectionArea)
        .addModifyListener(
            new ModifyListener() {
              public void modifyText(ModifyEvent e) {
                setPageComplete(validatePage());
              }
            });
    fileSelectionArea.moveAbove(null);

    // Show description on opening
    setErrorMessage(null);
    setMessage(null);
    setControl(parent);
    setPageComplete(validatePage());
  }
 public InputStream getInitialContents() {
   try {
     return new FileInputStream(new File(editor.getStringValue()));
   } catch (FileNotFoundException e) {
     return null;
   }
 }
 @Override
 public void setEnabled(boolean isEnabled) {
   keyStore.setEnabled(isEnabled, this);
   storekeyLabel.setEnabled(isEnabled);
   storekeyDec.setEnabled(isEnabled);
   aliasLabel.setEnabled(isEnabled);
   alias.setEnabled(isEnabled);
   passkeyLabel.setEnabled(isEnabled);
   passkeyDec.setEnabled(isEnabled);
 }
 void updateKeystoreCertInfo() {
   info =
       new KeystoreCertificateInfo(
           keyStore.getStringValue(),
           alias.getText(),
           storekey.getText(),
           passkey.getText(),
           true);
   dirty = false;
 }
 private void initUI() {
   listener.setActive(false);
   String keyStorePath = info == null ? "" : info.getKeystoreLocation();
   keyStore.setStringValue(keyStorePath == null ? "" : keyStorePath);
   String storekeyValue = info == null ? "" : info.getKeystorePassword();
   storekey.setText(storekeyValue == null ? "" : storekeyValue);
   String aliasValue = info == null ? "" : info.getAlias();
   alias.setText(aliasValue == null ? "" : aliasValue);
   String passkeyValue = info == null ? "" : info.getKeyPassword();
   passkey.setText(passkeyValue == null ? "" : passkeyValue);
   listener.setActive(true);
 }
  protected IFolder getNewFolder() {
    if (outputFolder != null && outputFolder.exists()) {
      String[] pathSegments =
          StringHelper.withoutExtension((new File(editor.getStringValue())).getName()).split("-");

      IFolder importFolder = outputFolder;
      for (String pathSegment : pathSegments) {
        importFolder = importFolder.getFolder(convertToJavaCompliantName(pathSegment));
      }
      folderName = importFolder.getName();
      return importFolder;
    }
    return null;
  }
  public KeystoreCertificateInfoEditor(Composite parent, int style) {
    super(parent, style);

    keyStore =
        new FileFieldEditor("dummy.1", "Key&store", this) { // $NON-NLS-1$
          @Override
          protected boolean checkState() {
            clearErrorMessage();
            return true;
          }
        };

    storekeyLabel = new Label(this, SWT.PASSWORD);
    storekeyLabel.setText("&Keystore password");

    storekey = new Text(this, SWT.BORDER | SWT.SINGLE);
    storekeyDec = new PasswordTextFieldDecorator(storekey);
    GridData storekeyData = new GridData(GridData.FILL_HORIZONTAL);
    storekeyData.horizontalSpan = 2;
    storekey.setLayoutData(storekeyData);

    aliasLabel = new Label(this, SWT.NONE);
    aliasLabel.setText("Key &Alias");

    alias = new Text(this, SWT.BORDER | SWT.SINGLE);
    GridData aliasData = new GridData(GridData.FILL_HORIZONTAL);
    aliasData.horizontalSpan = 2;
    alias.setLayoutData(aliasData);

    passkeyLabel = new Label(this, SWT.NONE);
    passkeyLabel.setText("&Private key password");

    passkey = new Text(this, SWT.BORDER | SWT.SINGLE);
    passkeyDec = new PasswordTextFieldDecorator(passkey);
    GridData passkeyData = new GridData(GridData.FILL_HORIZONTAL);
    passkeyData.horizontalSpan = 2;
    passkey.setLayoutData(passkeyData);

    listener = new UpdateListener(this);
    listener.addTo(SWT.Modify, keyStore.getTextControl(this), storekey, alias, passkey);
  }
  public void deleteNewFolder() {
    if (outputFolder != null && outputFolder.exists()) {
      String[] pathSegments =
          StringHelper.withoutExtension((new File(editor.getStringValue())).getName()).split("-");

      IFolder importFolder = outputFolder;
      for (String pathSegment : pathSegments) {
        importFolder = importFolder.getFolder(convertToJavaCompliantName(pathSegment));
      }
      try {
        while (importFolder != outputFolder && importFolder.getParent() instanceof IFolder) {
          if (importFolder.members().length == 0) {
            importFolder.delete(false, null);
          }
          importFolder = (IFolder) importFolder.getParent();
        }
      } catch (CoreException e) {
        OfsCore.getDefault()
            .logWarning("Could not delete empty import folder '" + importFolder + "'", e);
        e.printStackTrace();
      }
    }
  }
Пример #10
0
 public String getSelectedFileName() {
   File file = new File(editor.getStringValue());
   String fileName = file.getName();
   return fileName.substring(0, fileName.lastIndexOf("."));
 }