Ejemplo n.º 1
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
   */
  protected Control createDialogArea(Composite parent) {

    getShell().setText("New Regex"); // $NON-NLS-1$

    // getShell().setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));
    Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayout(new FillLayout());

    FormToolkit toolkit = new FormToolkit(Display.getDefault());
    form = toolkit.createForm(composite);
    form.getBody().setLayout(new GridLayout());
    toolkit.decorateFormHeading(form);

    sec = toolkit.createSection(form.getBody(), Section.TITLE_BAR);
    sec.setText("Regular Expression"); // $NON-NLS-1$
    sec.setLayoutData(new GridData(SWT.FILL, SWT.Expand, true, false, 1, 1));
    Composite compo = toolkit.createComposite(sec);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    compo.setLayout(layout);
    sec.setClient(compo);
    createContent(toolkit, compo);

    // Create field for Regex
    toolkit.createLabel(compo, "Regex: "); // $NON-NLS-1$
    String helpText = Messages.PopupRegexDialog_REGEX;
    componentHelpTextField = new ComponentHelpTextField(this, compo, toolkit, SWT.NONE, helpText);
    GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    componentHelpTextField.setLayoutData(data);

    // Add regex viewer component to the dialog
    regex =
        new RegexViewerComposite(
            form.getBody(),
            SWT.NONE,
            RegexViewerComposite.EXPANDABLE
                | RegexViewerComposite.MATCH
                | RegexViewerComposite.DESCRIPTION
                | RegexViewerComposite.GROUP,
            Pattern.MULTILINE | patterns);
    regex.setDescription("Regex Test Area"); // $NON-NLS-1$
    regex.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

    return composite;
  }
Ejemplo n.º 2
0
 /*
  * (non-Javadoc)
  *
  * @see org.topcased.doc2model.requirement.ui.NotifyElement#handleModelChange()
  */
 public void handleModelChange() {
   regexInput = componentHelpTextField.getInput();
   if (!"".equals(regexInput)) // $NON-NLS-1$
   {
     try {
       Pattern.compile(regexInput, Pattern.MULTILINE);
       form.setMessage(null, IMessageProvider.NONE);
       this.getButton(IDialogConstants.OK_ID).setEnabled(true);
     } catch (PatternSyntaxException e) {
       form.setMessage("Regex doesn't compile", IMessageProvider.ERROR); // $NON-NLS-1$
       this.getButton(IDialogConstants.OK_ID).setEnabled(false);
     }
   } else {
     form.setMessage(null, IMessageProvider.NONE);
     this.getButton(IDialogConstants.OK_ID).setEnabled(true);
   }
 }