@Override
  protected Control createDialogArea(Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    composite.setLayout(gridLayout);

    setTitle(UIText.RebaseInteractiveHandler_EditMessageDialogTitle);
    setMessage(UIText.RebaseInteractiveHandler_EditMessageDialogText);

    messageArea = new SpellcheckableMessageArea(composite, commitMessage);
    messageArea.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    Point size = messageArea.getTextWidget().getSize();
    int minHeight = messageArea.getTextWidget().getLineHeight() * 3;
    messageArea.setLayoutData(
        GridDataFactory.fillDefaults()
            .grab(true, true)
            .hint(size)
            .minSize(size.x, minHeight)
            .align(SWT.FILL, SWT.FILL)
            .create());
    messageArea.setFocus();

    return composite;
  }
  private void addListeners() {
    authorHandler = UIUtils.addPreviousValuesContentProposalToText(authorText, AUTHOR_VALUES_PREF);
    committerText.addModifyListener(
        new ModifyListener() {
          String oldCommitter = committerText.getText();

          public void modifyText(ModifyEvent e) {
            if (!listersEnabled) return;
            if (signedOff) {
              // the commit message is signed
              // the signature must be updated
              String newCommitter = committerText.getText();
              String oldSignOff = getSignedOff(oldCommitter);
              String newSignOff = getSignedOff(newCommitter);
              commitText.setText(replaceSignOff(commitText.getText(), oldSignOff, newSignOff));
              oldCommitter = newCommitter;
            }
          }
        });
    committerHandler =
        UIUtils.addPreviousValuesContentProposalToText(committerText, COMMITTER_VALUES_PREF);
    commitText
        .getTextWidget()
        .addModifyListener(
            new ModifyListener() {
              public void modifyText(ModifyEvent e) {
                if (!listersEnabled) return;
                updateSignedOffButton();
                updateChangeIdButton();
              }
            });
  }
Example #3
0
  private Composite createMessageAndPersonArea(Composite container) {

    Composite messageAndPersonArea = toolkit.createComposite(container);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(messageAndPersonArea);
    GridLayoutFactory.swtDefaults().margins(0, 0).spacing(0, 0).applyTo(messageAndPersonArea);

    Section messageSection =
        toolkit.createSection(
            messageAndPersonArea,
            ExpandableComposite.TITLE_BAR | ExpandableComposite.CLIENT_INDENT);
    messageSection.setText(UIText.CommitDialog_CommitMessage);
    Composite messageArea = toolkit.createComposite(messageSection);
    GridLayoutFactory.fillDefaults().spacing(0, 0).extendedMargins(2, 2, 2, 2).applyTo(messageArea);
    toolkit.paintBordersFor(messageArea);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(messageSection);
    GridLayoutFactory.swtDefaults().applyTo(messageSection);

    Composite headerArea = new Composite(messageSection, SWT.NONE);
    GridLayoutFactory.fillDefaults().spacing(0, 0).numColumns(2).applyTo(headerArea);

    ToolBar messageToolbar = new ToolBar(headerArea, SWT.FLAT | SWT.HORIZONTAL);
    GridDataFactory.fillDefaults()
        .align(SWT.END, SWT.FILL)
        .grab(true, false)
        .applyTo(messageToolbar);

    addMessageDropDown(headerArea);

    messageSection.setTextClient(headerArea);

    final CommitProposalProcessor commitProposalProcessor =
        new CommitProposalProcessor() {
          @Override
          protected Collection<String> computeFileNameProposals() {
            return getFileList();
          }

          @Override
          protected Collection<String> computeMessageProposals() {
            return CommitMessageHistory.getCommitHistory();
          }
        };
    commitText =
        new CommitMessageArea(messageArea, commitMessage, SWT.NONE) {
          @Override
          protected CommitProposalProcessor getCommitProposalProcessor() {
            return commitProposalProcessor;
          }
        };
    commitText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    messageSection.setClient(messageArea);
    Point size = commitText.getTextWidget().getSize();
    int minHeight = commitText.getTextWidget().getLineHeight() * 3;
    commitText.setLayoutData(
        GridDataFactory.fillDefaults()
            .grab(true, true)
            .hint(size)
            .minSize(size.x, minHeight)
            .align(SWT.FILL, SWT.FILL)
            .create());

    UIUtils.addBulbDecorator(commitText.getTextWidget(), UIText.CommitDialog_ContentAssist);

    Composite personArea = toolkit.createComposite(messageAndPersonArea);
    toolkit.paintBordersFor(personArea);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(personArea);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(personArea);

    toolkit
        .createLabel(personArea, UIText.CommitDialog_Author)
        .setForeground(toolkit.getColors().getColor(IFormColors.TB_TOGGLE));
    authorText = toolkit.createText(personArea, null);
    authorText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    authorText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    if (repository != null
        && repository.getRepositoryState().equals(RepositoryState.CHERRY_PICKING_RESOLVED))
      authorText.setEnabled(false);

    toolkit
        .createLabel(personArea, UIText.CommitDialog_Committer)
        .setForeground(toolkit.getColors().getColor(IFormColors.TB_TOGGLE));
    committerText = toolkit.createText(personArea, null);
    committerText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    if (committer != null) committerText.setText(committer);

    amendingItem = new ToolItem(messageToolbar, SWT.CHECK);
    amendingItem.setSelection(amending);
    if (amending) amendingItem.setEnabled(false); // if already set, don't allow any
    // changes
    else if (!amendAllowed) amendingItem.setEnabled(false);
    amendingItem.setToolTipText(UIText.CommitDialog_AmendPreviousCommit);
    Image amendImage = UIIcons.AMEND_COMMIT.createImage();
    UIUtils.hookDisposal(amendingItem, amendImage);
    amendingItem.setImage(amendImage);

    signedOffItem = new ToolItem(messageToolbar, SWT.CHECK);

    signedOffItem.setToolTipText(UIText.CommitDialog_AddSOB);
    Image signedOffImage = UIIcons.SIGNED_OFF.createImage();
    UIUtils.hookDisposal(signedOffItem, signedOffImage);
    signedOffItem.setImage(signedOffImage);

    changeIdItem = new ToolItem(messageToolbar, SWT.CHECK);
    Image changeIdImage = UIIcons.GERRIT.createImage();
    UIUtils.hookDisposal(changeIdItem, changeIdImage);
    changeIdItem.setImage(changeIdImage);
    changeIdItem.setToolTipText(UIText.CommitDialog_AddChangeIdLabel);

    final ICommitMessageComponentNotifications listener =
        new ICommitMessageComponentNotifications() {

          public void updateSignedOffToggleSelection(boolean selection) {
            signedOffItem.setSelection(selection);
          }

          public void updateChangeIdToggleSelection(boolean selection) {
            changeIdItem.setSelection(selection);
          }

          public void statusUpdated() {
            updateMessage();
          }
        };

    commitMessageComponent = new CommitMessageComponent(repository, listener);
    commitMessageComponent.enableListeners(false);
    commitMessageComponent.setDefaults();
    commitMessageComponent.attachControls(commitText, authorText, committerText);
    commitMessageComponent.setCommitMessage(commitMessage);
    commitMessageComponent.setAuthor(author);
    commitMessageComponent.setCommitter(committer);
    commitMessageComponent.setAmending(amending);
    commitMessageComponent.setFilesToCommit(getFileList());

    amendingItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            commitMessageComponent.setAmendingButtonSelection(amendingItem.getSelection());
          }
        });

    changeIdItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            commitMessageComponent.setChangeIdButtonSelection(changeIdItem.getSelection());
          }
        });

    signedOffItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            commitMessageComponent.setSignedOffButtonSelection(signedOffItem.getSelection());
          }
        });

    commitMessageComponent.updateUI();
    commitMessageComponent.enableListeners(true);

    return messageAndPersonArea;
  }