Example #1
0
 /**
  * Returns the parameter documentation (as a {@link FunctionDocumentation} instance) from a given
  * {@link IPHPDocBlock}.
  *
  * @param block - The block to look at when extracting the parameter documetation.
  * @param parameterName
  * @return FunctionDocumentation or null.
  */
 public static FunctionDocumentation getParameterDocumentation(
     IPHPDoc block, String parameterName) {
   if (block == null) {
     return null;
   }
   FunctionDocumentation result = new FunctionDocumentation();
   IPHPDocTag[] tags = block.getTags();
   if (tags != null) {
     for (IPHPDocTag tag : tags) {
       switch (tag.getTagKind()) {
         case PHPDocTag.PARAM:
           String value = tag.getValue();
           if (value == null) {
             continue;
           }
           String[] parsedTag = parseParamTagValue(value);
           // Support two forms of @params docs:
           // @param $param1 this is param 1
           // @param bool $param2 this is param 2
           if (!StringUtil.isEmpty(parsedTag[2]) && parsedTag[2].startsWith(parameterName)
               || !StringUtil.isEmpty(parsedTag[0])
                   && parsedTag[0].startsWith(removeDollar(parameterName))) {
             result.setDescription('\n' + value);
             return result;
           }
       }
     }
   }
   return null;
 }
Example #2
0
  /**
   * writeElement
   *
   * @param index
   * @param element
   */
  public void writeElement(Index index, ElementElement element, URI location) {
    String[] columns =
        new String[] { //
          element.getName(), //
          element.getDisplayName(), //
          StringUtil.join(XMLIndexConstants.SUB_DELIMITER, element.getAttributes()), //
          element.getDescription() //
        };
    String key = StringUtil.join(XMLIndexConstants.DELIMITER, columns);

    index.addEntry(this._keyProvider.getElementKey(), key, location);
  }
 @Override
 protected Object[] filter(IParseNode[] nodes) {
   List<CommonOutlineItem> items = new ArrayList<CommonOutlineItem>();
   HTMLElementNode element;
   for (IParseNode node : nodes) {
     if (node instanceof HTMLCommentNode) {
       // ignores comment nodes in outline
       continue;
     }
     if (node instanceof HTMLTextNode) {
       if (!showTextNode || StringUtil.isEmpty(((HTMLTextNode) node).getText())) {
         continue;
       }
     }
     if (node instanceof HTMLElementNode) {
       // for HTML node, only takes the element node
       element = (HTMLElementNode) node;
       if (element.getName().length() > 0) {
         items.add(getOutlineItem(element));
       }
     } else {
       // includes all non-HTML nodes and let the nested language handle its own filtering
       items.add(getOutlineItem(node));
     }
   }
   return items.toArray(new CommonOutlineItem[items.size()]);
 }
Example #4
0
  /**
   * Convert the specified node to a lisp-like syntax to expose the tree structure of the node and
   * its descendants in a form that is easy test during unit testing
   *
   * @param node
   * @return
   */
  public static String toTreeString(IParseNode node) {
    List<String> parts = new ArrayList<String>();

    toTreeString(parts, node);

    return StringUtil.concat(parts);
  }
  /**
   * toSource
   *
   * @param printer
   */
  public void toSource(SourcePrinter printer) {
    printer.printIndent();

    // print any annotations
    if (!this.isInstanceProperty()) {
      printer.print("static "); // $NON-NLS-1$
    }
    if (this.isInternal()) {
      printer.print("internal "); // $NON-NLS-1$
    }
    if (this.isConstructor()) {
      printer.print("constructor "); // $NON-NLS-1$
    }
    if (this.isMethod()) {
      printer.print("method "); // $NON-NLS-1$
    }

    // print name
    printer.print(this.getName());

    // print parameter types
    printer
        .print('(')
        .print(StringUtil.join(JSTypeConstants.PARAMETER_DELIMITER, this.getParameterTypes()))
        .print(')');

    // print return types
    List<String> returnTypes = this.getReturnTypeNames();

    printer.print(JSTypeConstants.FUNCTION_SIGNATURE_DELIMITER);

    if (!CollectionsUtil.isEmpty(returnTypes)) {
      printer.print(StringUtil.join(JSTypeConstants.RETURN_TYPE_DELIMITER, returnTypes));
    } else {
      printer.print(JSTypeConstants.UNDEFINED_TYPE);
    }

    // print exceptions
    if (this.hasExceptions()) {
      printer
          .print(" throws ")
          .print(StringUtil.join(", ", this.getExceptionTypes())); // $NON-NLS-1$ //$NON-NLS-2$
    }
  }
Example #6
0
  /**
   * writeAttribute
   *
   * @param index
   * @param attribute
   */
  public void writeAttribute(Index index, AttributeElement attribute, URI location) {
    String[] columns =
        new String[] { //
          attribute.getName(), //
          attribute.getElement(), //
          attribute.getDescription(), //
          "" // values //$NON-NLS-1$
        };
    String key = StringUtil.join(XMLIndexConstants.DELIMITER, columns);

    index.addEntry(this._keyProvider.getAttributeKey(), key, location);
  }
  /**
   * SuperTypeName(Simple)/SuperTypeNamespace/SimpleName/EnclosingTypeName/SuperIsClassOrModule(M|C)
   * isClassorModule(M|C)
   *
   * @param typeName
   * @param enclosingTypeNames
   * @param classOrModule
   * @param superTypeName
   * @param superClassOrModule
   * @return
   */
  private String createSuperTypeReferenceKey(
      String typeName,
      String[] enclosingTypeNames,
      char classOrModule,
      String superTypeName,
      char superClassOrModule) {
    if (superTypeName == null) {
      superTypeName = IRubyIndexConstants.OBJECT;
    }
    String superSimpleName = lastSegment(superTypeName, NAMESPACE_DELIMETER);
    char[] superQualification = null;
    if (!superTypeName.equals(superSimpleName)) {
      int length = superTypeName.length() - superSimpleName.length() - 1;
      superQualification = new char[length - 1];
      System.arraycopy(superTypeName.toCharArray(), 0, superQualification, 0, length - 1);
    }

    // if the supertype name contains a $, then split it into: source name and append the $
    // prefix to the qualification
    // e.g. p.A$B ---> p.A$ + B
    String superTypeSourceName = lastSegment(superSimpleName, NAMESPACE_DELIMETER);
    if (superSimpleName != null && !superSimpleName.equals(superTypeSourceName)) {
      int start = superQualification == null ? 0 : superQualification.length + 1;
      int prefixLength = superSimpleName.length() - superTypeSourceName.length();
      char[] mangledQualification = new char[start + prefixLength];
      if (superQualification != null) {
        System.arraycopy(superQualification, 0, mangledQualification, 0, start - 1);
        mangledQualification[start - 1] = '.';
      }
      System.arraycopy(superSimpleName.toCharArray(), 0, mangledQualification, start, prefixLength);
      superQualification = mangledQualification;
      superSimpleName = superTypeSourceName;
    }

    String simpleName = lastSegment(typeName, NAMESPACE_DELIMETER);
    String enclosingTypeName = StringUtil.join(NAMESPACE_DELIMETER, enclosingTypeNames);

    StringBuilder builder = new StringBuilder();
    builder.append(superSimpleName);
    builder.append(IRubyIndexConstants.SEPARATOR);
    if (superQualification != null) {
      builder.append(superQualification);
    }
    builder.append(IRubyIndexConstants.SEPARATOR);
    builder.append(simpleName);
    builder.append(IRubyIndexConstants.SEPARATOR);
    builder.append(enclosingTypeName);
    builder.append(IRubyIndexConstants.SEPARATOR);
    builder.append(superClassOrModule);
    builder.append(classOrModule);

    return builder.toString();
  }
Example #8
0
  private Composite createOwnerGroup(Composite parent, IExtendedFileInfo fileInfo) {
    Group container = new Group(parent, SWT.NONE);
    container.setText(Messages.FileInfoPropertyPage_OwnerAndGroup);
    container.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).create());

    Label label = new Label(container, SWT.NONE);
    label.setText(StringUtil.makeFormLabel(Messages.FileInfoPropertyPage_Owner));
    Text text = new Text(container, SWT.READ_ONLY);
    text.setText(fileInfo.getOwner());
    text.setLayoutData(
        GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create());

    label = new Label(container, SWT.NONE);
    label.setText(StringUtil.makeFormLabel(Messages.FileInfoPropertyPage_Group));
    text = new Text(container, SWT.READ_ONLY);
    text.setText(fileInfo.getGroup());
    text.setLayoutData(
        GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create());

    return container;
  }
Example #9
0
  protected void assertListCrossProducts(List<List<String>> lists, JSTokenType tokenType) {
    ListCrossProduct<String> crossProduct = new ListCrossProduct<String>();

    for (List<String> list : lists) {
      crossProduct.addList(list);
    }

    for (List<String> list : crossProduct) {
      String text = StringUtil.concat(list);

      assertTokenType(text, tokenType);
    }
  }
 /**
  * Generates the payload used for analytics on project creation events.
  *
  * @return
  */
 protected Map<String, String> generatePayload() {
   Map<String, String> payload = new HashMap<String, String>();
   payload.put("name", newProject.getName()); // $NON-NLS-1$
   if (selectedTemplate != null) {
     String id = selectedTemplate.getId();
     if (StringUtil.isEmpty(id)) {
       payload.put(
           "template",
           "custom.template-" + selectedTemplate.getDisplayName()); // $NON-NLS-1$ //$NON-NLS-2$
     } else {
       payload.put("template", id); // $NON-NLS-1$
     }
   }
   return payload;
 }
Example #11
0
  /*
   * (non-Javadoc)
   * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
   */
  public String getText(Object element) {
    List<ILabelProvider> providers = this.getProcessors();
    String result = StringUtil.EMPTY;

    for (ILabelProvider provider : providers) {
      String text = provider.getText(element);

      if (!StringUtil.isEmpty(text)) {
        result = text;
        break;
      }
    }

    return result;
  }
  protected void handleBrowseSelected() {
    DirectoryDialog dialog = new DirectoryDialog(getShell());
    dialog.setMessage(browseDialogMessage);
    String currentWorkingDir = textField.getText();
    if (!StringUtil.isEmpty(currentWorkingDir)) {
      File path = new File(currentWorkingDir);
      if (path.exists()) {
        dialog.setFilterPath(currentWorkingDir);
      }
    }

    String selectedDirectory = dialog.open();
    if (selectedDirectory != null) {
      textField.setText(selectedDirectory);
    }
  }
Example #13
0
    protected List<String> linesFromNotification(String string) {
      // FIXME: throw an error?
      if (string == null) {
        return Collections.emptyList();
      }

      // Strip trailing null
      if (string.endsWith(NULL_DELIMITER)) {
        string = string.substring(0, string.length() - 1);
      }

      if (string.length() == 0) {
        return Collections.emptyList();
      }

      return StringUtil.tokenize(string, NULL_DELIMITER);
    }
Example #14
0
    protected Map<String, List<String>> dictionaryForLines(List<String> lines) {
      Map<String, List<String>> dictionary = new HashMap<String, List<String>>(lines.size() / 2);

      // Fill the dictionary with the new information. These lines are in the form of:
      // :00000 :0644 OTHER INDEX INFORMATION
      // Filename
      Assert.isTrue(
          lines.size() % 2 == 0,
          "Lines must have an even number of lines: " + lines); // $NON-NLS-1$
      Iterator<String> iter = lines.iterator();
      while (iter.hasNext()) {
        String fileStatus = iter.next();
        String fileName = iter.next();
        dictionary.put(fileName, StringUtil.tokenize(fileStatus, " ")); // $NON-NLS-1$
      }

      return dictionary;
    }
  private Composite createLogoutComponents(Composite parent) {
    Composite logoutComp = new Composite(parent, SWT.NONE);
    logoutComp.setLayout(GridLayoutFactory.swtDefaults().numColumns(3).create());

    Label label = new Label(logoutComp, SWT.NONE);
    label.setText(StringUtil.makeFormLabel(Messages.JiraPreferencePageProvider_LBL_User));
    userLabel = new Label(logoutComp, SWT.NONE);
    logoutButton = new Button(logoutComp, SWT.PUSH);
    logoutButton.setText(Messages.JiraPreferencePageProvider_LBL_Logout);
    logoutButton.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {
            logout();
          }
        });
    updateUserText();

    return logoutComp;
  }
  // Initialize the dialog's values.
  private void internalInitializeValues() {
    // TODO: move to preference manager

    originalPort = PHPDebugPreferencesUtil.getInt(XDebugPreferenceMgr.XDEBUG_PREF_PORT, 0);
    if (originalPort == 0) {
      XDebugPreferenceMgr.setDefaults();
      originalPort = PHPDebugPreferencesUtil.getInt(XDebugPreferenceMgr.XDEBUG_PREF_PORT, 0);
    }
    portTextBox.setText(Integer.toString(originalPort));
    showGlobals.setSelection(
        PHPDebugPreferencesUtil.getBoolean(XDebugPreferenceMgr.XDEBUG_PREF_SHOWSUPERGLOBALS, true));
    useMultiSession.setSelection(
        PHPDebugPreferencesUtil.getBoolean(XDebugPreferenceMgr.XDEBUG_PREF_MULTISESSION, true));
    variableDepth.setSelection(
        PHPDebugPreferencesUtil.getInt(XDebugPreferenceMgr.XDEBUG_PREF_ARRAYDEPTH, 0));
    maxChildren.setSelection(
        PHPDebugPreferencesUtil.getInt(XDebugPreferenceMgr.XDEBUG_PREF_CHILDREN, 0));
    acceptRemoteSession.select(
        PHPDebugPreferencesUtil.getInt(XDebugPreferenceMgr.XDEBUG_PREF_REMOTESESSION, 0));

    // capture output
    captureStdout.select(
        PHPDebugPreferencesUtil.getInt(XDebugPreferenceMgr.XDEBUG_PREF_CAPTURESTDOUT, 0));
    captureStderr.select(
        PHPDebugPreferencesUtil.getInt(XDebugPreferenceMgr.XDEBUG_PREF_CAPTURESTDERR, 0));

    // proxy defaults
    boolean useProxyState =
        PHPDebugPreferencesUtil.getBoolean(XDebugPreferenceMgr.XDEBUG_PREF_USEPROXY, false);
    useProxy.setSelection(useProxyState);
    String ideKey = PHPDebugPreferencesUtil.getString(XDebugPreferenceMgr.XDEBUG_PREF_IDEKEY, null);
    if (StringUtil.isEmpty(ideKey)) {
      ideKey = DBGpProxyHandler.instance.generateIDEKey();
    }
    idekeyTextBox.setText(ideKey);
    proxyTextBox.setText(
        PHPDebugPreferencesUtil.getString(XDebugPreferenceMgr.XDEBUG_PREF_PROXY, StringUtil.EMPTY));
    toggleProxyFields(useProxyState);
  }
Example #17
0
  private void readElement(IConfigurationElement element) {
    String elementName = element.getName();

    if (ELEMENT_CATEGORY.equals(elementName)) {
      String id = element.getAttribute(ATTR_ID);
      if (StringUtil.isEmpty(id)) {
        return;
      }
      String name = element.getAttribute(ATTR_NAME);
      if (StringUtil.isEmpty(name)) {
        return;
      }
      SampleCategory category = new SampleCategory(id, name, element);
      categories.put(id, category);

      String iconFile = element.getAttribute(ATTR_ICON);
      if (!StringUtil.isEmpty(iconFile)) {
        Bundle bundle = Platform.getBundle(element.getNamespaceIdentifier());
        URL url = bundle.getEntry(iconFile);
        category.setIconFile(ResourceUtil.resourcePathToString(url));
      }
    } else if (ELEMENT_SAMPLESINFO.equals(elementName)) {
      // either a local path or remote git url needs to be defined
      String path = null;
      boolean isRemote = false;

      Bundle bundle = Platform.getBundle(element.getNamespaceIdentifier());
      IConfigurationElement[] localPaths = element.getChildren(ELEMENT_LOCAL);
      if (localPaths.length > 0) {
        String location = localPaths[0].getAttribute(ATTR_LOCATION);
        URL url = bundle.getEntry(location);
        path = ResourceUtil.resourcePathToString(url);
      } else {
        IConfigurationElement[] remotePaths = element.getChildren(ELEMENT_REMOTE);
        if (remotePaths.length > 0) {
          path = remotePaths[0].getAttribute(ATTR_LOCATION);
          isRemote = true;
        }
      }
      if (path == null) {
        return;
      }

      String id = element.getAttribute(ATTR_ID);
      if (StringUtil.isEmpty(id)) {
        return;
      }
      String name = element.getAttribute(ATTR_NAME);
      if (StringUtil.isEmpty(name)) {
        return;
      }

      String categoryId = element.getAttribute(ATTR_CATEGORY);
      SampleCategory category = categories.get(categoryId);
      if (category == null) {
        categoryId = "default"; // $NON-NLS-1$
        category = categories.get(categoryId);
        if (category == null) {
          category =
              new SampleCategory(categoryId, Messages.SamplesManager_DefaultCategory_Name, element);
        }
      }

      List<SamplesReference> samples = sampleRefsByCategory.get(categoryId);
      if (samples == null) {
        samples = new ArrayList<SamplesReference>();
        sampleRefsByCategory.put(categoryId, samples);
      }

      String description = element.getAttribute(ATTR_DESCRIPTION);

      URL iconUrl = null;
      String iconPath = element.getAttribute(ATTR_ICON);
      if (!StringUtil.isEmpty(iconPath)) {
        URL url = bundle.getEntry(iconPath);
        try {
          iconUrl = FileLocator.toFileURL(url);
        } catch (IOException e) {
          IdeLog.logError(
              SamplesPlugin.getDefault(),
              MessageFormat.format(
                  "Unable to retrieve the icon at {0} for sample {1}",
                  iconPath, name), // $NON-NLS-1$
              e);
        }
      }
      Map<String, URL> iconUrls = new HashMap<String, URL>();
      iconUrls.put(SamplesReference.DEFAULT_ICON_KEY, iconUrl);

      SamplesReference samplesRef =
          new SamplesReference(category, id, name, path, isRemote, description, iconUrls, element);
      samples.add(samplesRef);
      samplesById.put(id, samplesRef);

      String infoFile = element.getAttribute(ATTR_INFOFILE);
      if (!StringUtil.isEmpty(infoFile)) {
        URL url = bundle.getEntry(infoFile);
        samplesRef.setInfoFile(ResourceUtil.resourcePathToString(url));
      }

      IConfigurationElement[] natures = element.getChildren(ELEMENT_NATURE);
      List<String> natureIds = new ArrayList<String>();
      String natureId;
      for (IConfigurationElement nature : natures) {
        natureId = nature.getAttribute(ATTR_ID);
        if (!StringUtil.isEmpty(natureId)) {
          natureIds.add(natureId);
        }
      }
      samplesRef.setNatures(natureIds.toArray(new String[natureIds.size()]));

      IConfigurationElement[] includes = element.getChildren(ELEMENT_INCLUDE);
      List<String> includePaths = new ArrayList<String>();
      String includePath;
      URL url;
      for (IConfigurationElement include : includes) {
        includePath = include.getAttribute(ATTR_PATH);
        if (!StringUtil.isEmpty(includePath)) {
          url = bundle.getEntry(includePath);
          path = ResourceUtil.resourcePathToString(url);
          if (path != null) {
            includePaths.add(path);
          }
        }
      }
      samplesRef.setIncludePaths(includePaths.toArray(new String[includePaths.size()]));
    }
  }
Example #18
0
  /**
   * Returns the function documentation from a given {@link IPHPDocBlock}.
   *
   * @param block - The block to convert to a {@link FunctionDocumentation}.
   * @return FunctionDocumentation or null.
   */
  public static FunctionDocumentation getFunctionDocumentation(IPHPDoc block) {
    if (block == null) {
      return null;
    }
    FunctionDocumentation result = new FunctionDocumentation();

    StringBuilder docBuilder = new StringBuilder();
    docBuilder.append(block.getShortDescription());
    String longDescription = block.getLongDescription();
    if (!StringUtil.isEmpty(longDescription)) {
      docBuilder.append('\n');
      docBuilder.append(longDescription);
    }

    result.setDescription(docBuilder.toString());

    IPHPDocTag[] tags = block.getTags();
    if (tags != null) {
      for (IPHPDocTag tag : tags) {
        switch (tag.getTagKind()) {
          case PHPDocTag.VAR:
            {
              String value = tag.getValue();
              if (value == null) {
                continue;
              }
              TypedDescription typeDescr = new TypedDescription();
              typeDescr.addType(value);
              result.addVar(typeDescr);
              break;
            }
          case PHPDocTag.PARAM:
            String value = tag.getValue();
            if (value == null) {
              continue;
            }
            String[] parsedValue = parseParamTagValue(value);
            TypedDescription typeDescr = new TypedDescription();
            typeDescr.setName(parsedValue[0]);
            if (parsedValue[1] != null) {
              typeDescr.addType(parsedValue[1]);
            }
            if (parsedValue[2] != null) {
              typeDescr.setDescription(parsedValue[2]);
            }
            result.addParam(typeDescr);
            break;
          case PHPDocTag.RETURN:
            String returnTagValue = tag.getValue().trim();
            if (returnTagValue == null) {
              continue;
            }
            String[] returnTypes = returnTagValue.split("\\|"); // $NON-NLS-1$
            for (String returnType : returnTypes) {
              returnTagValue = clean(returnType.trim());
              returnTagValue = firstWord(returnTagValue);
              result.getReturn().addType(returnTagValue);
            }
            break;
        }
      }
    }

    return result;
  }
  /**
   * @param parent
   * @param style
   */
  public SFTPAdvancedOptionsComposite(Composite parent, int style, Listener listener) {
    super(parent, style);
    this.listener = listener;

    setLayout(
        GridLayoutFactory.swtDefaults()
            .numColumns(5)
            .spacing(
                new PixelConverter(this)
                    .convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING),
                new PixelConverter(this)
                    .convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING))
            .create());

    /* row 1 */
    Label label = new Label(this, SWT.NONE);
    label.setLayoutData(
        GridDataFactory.swtDefaults()
            .hint(
                new PixelConverter(this)
                    .convertHorizontalDLUsToPixels(IDialogConstants.LABEL_WIDTH),
                SWT.DEFAULT)
            .create());
    label.setText(StringUtil.makeFormLabel(Messages.SFTPAdvancedOptionsComposite_Compression));

    compressionCombo = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
    compressionCombo.add(ISFTPConstants.COMPRESSION_AUTO);
    compressionCombo.add(ISFTPConstants.COMPRESSION_NONE);
    compressionCombo.add(ISFTPConstants.COMPRESSION_ZLIB);
    compressionCombo.setLayoutData(
        GridDataFactory.swtDefaults()
            .hint(compressionCombo.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x, SWT.DEFAULT)
            .create());

    label = new Label(this, SWT.NONE);
    label.setLayoutData(
        GridDataFactory.swtDefaults()
            .align(SWT.END, SWT.CENTER)
            .hint(
                new PixelConverter(this)
                    .convertHorizontalDLUsToPixels(IDialogConstants.LABEL_WIDTH),
                SWT.DEFAULT)
            .create());

    label = new Label(this, SWT.NONE);
    label.setLayoutData(GridDataFactory.swtDefaults().create());
    label.setText(StringUtil.makeFormLabel(Messages.SFTPAdvancedOptionsComposite_Port));

    portText = new Text(this, SWT.SINGLE | SWT.RIGHT | SWT.BORDER);
    portText.setLayoutData(
        GridDataFactory.swtDefaults()
            .hint(
                Math.max(
                    new PixelConverter(portText).convertWidthInCharsToPixels(5),
                    portText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x),
                SWT.DEFAULT)
            .create());

    /* row 2 */
    label = new Label(this, SWT.NONE);
    label.setLayoutData(
        GridDataFactory.swtDefaults()
            .hint(
                new PixelConverter(this)
                    .convertHorizontalDLUsToPixels(IDialogConstants.LABEL_WIDTH),
                SWT.DEFAULT)
            .create());
    label.setText(StringUtil.makeFormLabel(Messages.SFTPAdvancedOptionsComposite_Encoding));

    encodingCombo = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
    encodingCombo.setItems(Charset.availableCharsets().keySet().toArray(new String[0]));
    encodingCombo.setLayoutData(
        GridDataFactory.swtDefaults()
            .hint(encodingCombo.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x, SWT.DEFAULT)
            .span(4, 1)
            .create());

    /* -- */
    addListeners();
    portText.addVerifyListener(new NumberVerifyListener());
  }
 private void updateButtonStates() {
   testButton.setEnabled(
       !StringUtil.isEmpty(usernameText.getText()) && !StringUtil.isEmpty(passwordText.getText()));
 }
  private boolean login(boolean test) {
    final String username = usernameText.getText();
    final String password = passwordText.getText();
    if (StringUtil.isEmpty(username)) {
      if (test) {
        MessageDialog.openError(
            main.getShell(),
            Messages.JiraPreferencePageProvider_ERR_InvalidInput_Title,
            Messages.JiraPreferencePageProvider_ERR_EmptyUsername);
        return false;
      }
      return true;
    }
    if (StringUtil.isEmpty(password)) {
      if (test) {
        MessageDialog.openError(
            main.getShell(),
            Messages.JiraPreferencePageProvider_ERR_InvalidInput_Title,
            Messages.JiraPreferencePageProvider_ERR_EmptyPassword);
        return false;
      }
      return true;
    }

    setUILocked(true);
    firePreValidationStartEvent();
    try {
      ModalContext.run(
          new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor)
                throws InvocationTargetException, InterruptedException {
              monitor.beginTask(
                  Messages.JiraPreferencePageProvider_ValidateCredentials,
                  IProgressMonitor.UNKNOWN);
              try {
                IStatus status = getJiraManager().login(username, password);
                if (status.isOK()) {
                  // successful; now re-layout to show the logout components
                  UIUtils.getDisplay()
                      .asyncExec(
                          new Runnable() {

                            public void run() {
                              updateUserText();
                              layout();
                            }
                          });
                } else {
                  throw new InvocationTargetException(new CoreException(status));
                }
              } finally {
                if (!monitor.isCanceled()) {
                  monitor.done();
                }
              }
            }
          },
          true,
          getProgressMonitor(),
          UIUtils.getDisplay());
    } catch (InvocationTargetException e) {
      if (main != null && !main.isDisposed()) {
        MessageDialog.openError(
            main.getShell(),
            Messages.JiraPreferencePageProvider_ERR_LoginFailed_Title,
            e.getTargetException().getMessage());
      }
      return false;
    } catch (Exception e) {
      IdeLog.logError(JiraUIPlugin.getDefault(), e);
    } finally {
      setUILocked(false);
      firePostValidationEndEvent();
    }

    return true;
  }
  private Composite createLoginComponents(Composite parent) {
    Composite loginComp = new Composite(parent, SWT.NONE);
    loginComp.setLayout(GridLayoutFactory.swtDefaults().numColumns(3).create());

    Label label = new Label(loginComp, SWT.NONE);
    label.setText(StringUtil.makeFormLabel(Messages.JiraPreferencePageProvider_LBL_Username));
    label.setLayoutData(GridDataFactory.swtDefaults().create());

    ModifyListener modifyListener =
        new ModifyListener() {

          public void modifyText(ModifyEvent e) {
            updateButtonStates();
          }
        };
    usernameText = new Text(loginComp, SWT.BORDER);
    usernameText.setLayoutData(
        GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create());
    usernameText.addModifyListener(modifyListener);

    testButton = new Button(loginComp, SWT.NONE);
    testButton.setText(Messages.JiraPreferencePageProvider_LBL_Validate);
    testButton.setLayoutData(
        GridDataFactory.swtDefaults().hint(getButtonWidthHint(testButton), SWT.DEFAULT).create());
    testButton.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {
            if (login(true)) {
              // shows a success message
              MessageDialog.openInformation(
                  UIUtils.getActiveShell(),
                  Messages.JiraPreferencePageProvider_Success_Title,
                  Messages.JiraPreferencePageProvider_Success_Message);
            }
          }
        });

    label = new Label(loginComp, SWT.NONE);
    label.setText(StringUtil.makeFormLabel(Messages.JiraPreferencePageProvider_LBL_Password));
    label.setLayoutData(GridDataFactory.swtDefaults().create());

    passwordText = new Text(loginComp, SWT.BORDER | SWT.PASSWORD);
    passwordText.setLayoutData(
        GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create());
    passwordText.addModifyListener(modifyListener);

    createAccountButton = new Button(loginComp, SWT.NONE);
    createAccountButton.setText(
        StringUtil.ellipsify(Messages.JiraPreferencePageProvider_LBL_Signup));
    createAccountButton.setLayoutData(
        GridDataFactory.swtDefaults()
            .hint(getButtonWidthHint(createAccountButton), SWT.DEFAULT)
            .create());
    createAccountButton.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {
            WorkbenchBrowserUtil.launchExternalBrowser(SIGNUP_URL);
          }
        });

    KeyListener keyListener =
        new KeyListener() {

          public void keyPressed(KeyEvent e) {
            if (e.character == SWT.CR || e.character == SWT.KEYPAD_CR) {
              if (testButton.isEnabled()) {
                login(true);
              }
            }
          }

          public void keyReleased(KeyEvent e) {}
        };
    usernameText.addKeyListener(keyListener);
    passwordText.addKeyListener(keyListener);

    updateButtonStates();
    adjustWidth();

    return loginComp;
  }