private void createPushConfigurationGroup(Composite panel) {
    pushConfigurationGroup =
        SWTUtils.createHFillGroup(
            panel, UIText.GerritConfigurationPage_groupPush, SWTUtils.MARGINS_DEFAULT, 3);
    Label branchLabel = new Label(pushConfigurationGroup, SWT.NULL);
    branchLabel.setText(UIText.GerritConfigurationPage_labelDestinationBranch);
    // we visualize the prefix here
    Text prefix = new Text(pushConfigurationGroup, SWT.READ_ONLY);
    prefix.setText(GerritUtil.REFS_FOR);
    prefix.setEnabled(false);

    branch = SWTUtils.createText(pushConfigurationGroup);
    branch.addModifyListener(
        new ModifyListener() {
          public void modifyText(final ModifyEvent e) {
            checkPage();
          }
        });

    // give focus to the branch if label is activated using the mnemonic
    branchLabel.addTraverseListener(
        new TraverseListener() {
          public void keyTraversed(TraverseEvent e) {
            branch.setFocus();
            branch.selectAll();
          }
        });
    addRefContentProposalToText(branch);
  }
Exemplo n.º 2
0
  @Override
  public void createControl(Composite parent) {
    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout(4, false));

    Label sourceLabel = new Label(main, SWT.NONE);
    sourceLabel.setText(UIText.CreateBranchPage_SourceLabel);
    sourceLabel.setToolTipText(UIText.CreateBranchPage_SourceTooltip);

    sourceIcon = new Label(main, SWT.NONE);
    sourceIcon.setImage(UIIcons.getImage(resourceManager, UIIcons.BRANCH));
    sourceIcon.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    sourceNameLabel = new Label(main, SWT.NONE);
    sourceNameLabel.setLayoutData(
        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create());

    Button selectButton = new Button(main, SWT.NONE);
    selectButton.setText(UIText.CreateBranchPage_SourceSelectButton);
    selectButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            selectSource();
          }
        });
    UIUtils.setButtonLayoutData(selectButton);

    Label nameLabel = new Label(main, SWT.NONE);
    nameLabel.setText(UIText.CreateBranchPage_BranchNameLabel);
    nameLabel.setLayoutData(
        GridDataFactory.fillDefaults().span(1, 1).align(SWT.BEGINNING, SWT.CENTER).create());
    nameLabel.setToolTipText(UIText.CreateBranchPage_BranchNameToolTip);

    nameText = new Text(main, SWT.BORDER);
    // give focus to the nameText if label is activated using the mnemonic
    nameLabel.addTraverseListener(
        new TraverseListener() {
          @Override
          public void keyTraversed(TraverseEvent e) {
            nameText.setFocus();
          }
        });

    nameText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            nameIsSuggestion = false;
          }
        });
    // enable testing with SWTBot
    nameText.setData("org.eclipse.swtbot.widget.key", "BranchName"); // $NON-NLS-1$ //$NON-NLS-2$
    GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(nameText);

    upstreamConfigComponent = new UpstreamConfigComponent(main, SWT.NONE);
    GridDataFactory.fillDefaults()
        .grab(true, false)
        .span(4, 1)
        .applyTo(upstreamConfigComponent.getContainer());

    upstreamConfigComponent.addUpstreamConfigSelectionListener(
        new UpstreamConfigSelectionListener() {
          @Override
          public void upstreamConfigSelected(UpstreamConfig newUpstreamConfig) {
            upstreamConfig = newUpstreamConfig;
            checkPage();
          }
        });

    boolean isBare = myRepository.isBare();
    checkout = new Button(main, SWT.CHECK);
    checkout.setText(UIText.CreateBranchPage_CheckoutButton);
    // most of the time, we probably will check this out
    // unless we have a bare repository which doesn't allow
    // check out at all
    checkout.setSelection(!isBare);
    checkout.setEnabled(!isBare);
    checkout.setVisible(!isBare);
    GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(checkout);
    checkout.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            checkPage();
          }
        });

    Dialog.applyDialogFont(main);
    setControl(main);

    if (this.myBaseCommit != null) setSourceCommit(this.myBaseCommit);
    else if (myBaseRef != null) setSourceRef(myBaseRef);

    nameText.setFocus();
    // add the listener just now to avoid unneeded checkPage()
    nameText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            checkPage();
          }
        });
  }