Search in sources :

Example 1 with BranchNameNormalizer

use of org.eclipse.egit.ui.internal.components.BranchNameNormalizer in project egit by eclipse.

the class FetchGerritChangePage method createControl.

@Override
public void createControl(Composite parent) {
    parent.addDisposeListener(event -> {
        for (ChangeList l : changeRefs.values()) {
            l.cancel(ChangeList.CancelMode.INTERRUPT);
        }
        changeRefs.clear();
    });
    Clipboard clipboard = new Clipboard(parent.getDisplay());
    String clipText = (String) clipboard.getContents(TextTransfer.getInstance());
    clipboard.dispose();
    String defaultUri = null;
    String defaultCommand = null;
    String defaultChange = null;
    Change candidateChange = null;
    if (clipText != null) {
        Matcher matcher = GERRIT_FETCH_PATTERN.matcher(clipText);
        if (matcher.matches()) {
            defaultUri = matcher.group(1);
            defaultChange = matcher.group(2);
            defaultCommand = matcher.group(3);
        } else {
            candidateChange = determineChangeFromString(clipText.trim());
        }
    }
    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout(2, false));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(main);
    new Label(main, SWT.NONE).setText(UIText.FetchGerritChangePage_UriLabel);
    uriCombo = new Combo(main, SWT.DROP_DOWN);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(uriCombo);
    uriCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String uriText = uriCombo.getText();
            ChangeList list = changeRefs.get(uriText);
            if (list != null) {
                list.cancel(ChangeList.CancelMode.INTERRUPT);
            }
            list = new ChangeList(repository, uriText);
            changeRefs.put(uriText, list);
            preFetch(list);
        }
    });
    new Label(main, SWT.NONE).setText(UIText.FetchGerritChangePage_ChangeLabel);
    refText = new Text(main, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(refText);
    contentProposer = addRefContentProposalToText(refText);
    refText.addVerifyListener(event -> {
        event.text = event.text.replaceAll("\\v", // $NON-NLS-1$ //$NON-NLS-2$
        " ").trim();
    });
    final Group checkoutGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
    checkoutGroup.setLayout(new GridLayout(3, false));
    GridDataFactory.fillDefaults().span(3, 1).grab(true, false).applyTo(checkoutGroup);
    checkoutGroup.setText(UIText.FetchGerritChangePage_AfterFetchGroup);
    // radio: create local branch
    createBranch = new Button(checkoutGroup, SWT.RADIO);
    GridDataFactory.fillDefaults().span(1, 1).applyTo(createBranch);
    createBranch.setText(UIText.FetchGerritChangePage_LocalBranchRadio);
    createBranch.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            checkPage();
        }
    });
    branchCheckoutButton = new Button(checkoutGroup, SWT.CHECK);
    GridDataFactory.fillDefaults().span(2, 1).align(SWT.END, SWT.CENTER).applyTo(branchCheckoutButton);
    branchCheckoutButton.setFont(JFaceResources.getDialogFont());
    branchCheckoutButton.setText(UIText.FetchGerritChangePage_LocalBranchCheckout);
    branchCheckoutButton.setSelection(true);
    branchTextlabel = new Label(checkoutGroup, SWT.NONE);
    GridDataFactory.defaultsFor(branchTextlabel).exclude(false).applyTo(branchTextlabel);
    branchTextlabel.setText(UIText.FetchGerritChangePage_BranchNameText);
    branchText = new Text(checkoutGroup, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(branchText);
    branchText.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            branchTextEdited = true;
        }
    });
    branchText.addVerifyListener(event -> {
        if (event.text.isEmpty()) {
            branchTextEdited = false;
        }
    });
    branchText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            checkPage();
        }
    });
    BranchNameNormalizer normalizer = new BranchNameNormalizer(branchText);
    normalizer.setVisible(false);
    branchEditButton = new Button(checkoutGroup, SWT.PUSH);
    branchEditButton.setFont(JFaceResources.getDialogFont());
    branchEditButton.setText(UIText.FetchGerritChangePage_BranchEditButton);
    branchEditButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent selectionEvent) {
            String txt = branchText.getText();
            // $NON-NLS-1$
            String refToMark = "".equals(txt) ? null : Constants.R_HEADS + txt;
            AbstractBranchSelectionDialog dlg = new BranchEditDialog(checkoutGroup.getShell(), repository, refToMark);
            if (dlg.open() == Window.OK) {
                branchText.setText(Repository.shortenRefName(dlg.getRefName()));
                branchTextEdited = true;
            } else {
                // force calling branchText's modify listeners
                branchText.setText(branchText.getText());
            }
        }
    });
    GridDataFactory.defaultsFor(branchEditButton).exclude(false).applyTo(branchEditButton);
    // radio: create tag
    createTag = new Button(checkoutGroup, SWT.RADIO);
    GridDataFactory.fillDefaults().span(3, 1).applyTo(createTag);
    createTag.setText(UIText.FetchGerritChangePage_TagRadio);
    createTag.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            checkPage();
        }
    });
    tagTextlabel = new Label(checkoutGroup, SWT.NONE);
    GridDataFactory.defaultsFor(tagTextlabel).exclude(true).applyTo(tagTextlabel);
    tagTextlabel.setText(UIText.FetchGerritChangePage_TagNameText);
    tagText = new Text(checkoutGroup, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().exclude(true).grab(true, false).applyTo(tagText);
    tagText.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            tagTextEdited = true;
        }
    });
    tagText.addVerifyListener(event -> {
        if (event.text.isEmpty()) {
            tagTextEdited = false;
        }
    });
    tagText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            checkPage();
        }
    });
    BranchNameNormalizer tagNormalizer = new BranchNameNormalizer(tagText, UIText.BranchNameNormalizer_TooltipForTag);
    tagNormalizer.setVisible(false);
    // radio: checkout FETCH_HEAD
    checkoutFetchHead = new Button(checkoutGroup, SWT.RADIO);
    GridDataFactory.fillDefaults().span(3, 1).applyTo(checkoutFetchHead);
    checkoutFetchHead.setText(UIText.FetchGerritChangePage_CheckoutRadio);
    checkoutFetchHead.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            checkPage();
        }
    });
    // radio: don't checkout
    updateFetchHead = new Button(checkoutGroup, SWT.RADIO);
    GridDataFactory.fillDefaults().span(3, 1).applyTo(updateFetchHead);
    updateFetchHead.setText(UIText.FetchGerritChangePage_UpdateRadio);
    updateFetchHead.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            checkPage();
        }
    });
    if ("checkout".equals(defaultCommand)) {
        // $NON-NLS-1$
        checkoutFetchHead.setSelection(true);
    } else {
        createBranch.setSelection(true);
    }
    warningAdditionalRefNotActive = new Composite(main, SWT.NONE);
    GridDataFactory.fillDefaults().span(2, 1).grab(true, false).exclude(true).applyTo(warningAdditionalRefNotActive);
    warningAdditionalRefNotActive.setLayout(new GridLayout(2, false));
    warningAdditionalRefNotActive.setVisible(false);
    activateAdditionalRefs = new Button(warningAdditionalRefNotActive, SWT.CHECK);
    activateAdditionalRefs.setText(UIText.FetchGerritChangePage_ActivateAdditionalRefsButton);
    activateAdditionalRefs.setToolTipText(UIText.FetchGerritChangePage_ActivateAdditionalRefsTooltip);
    ActionUtils.setGlobalActions(refText, ActionUtils.createGlobalAction(ActionFactory.PASTE, () -> doPaste(refText)));
    refText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            Change change = determineChangeFromString(refText.getText());
            // $NON-NLS-1$
            String suggestion = "";
            if (change != null) {
                Object ps = change.getPatchSetNumber();
                if (ps == null) {
                    ps = SIMPLE_TIMESTAMP.format(new Date());
                }
                suggestion = NLS.bind(UIText.FetchGerritChangePage_SuggestedRefNamePattern, change.getChangeNumber(), ps);
            }
            if (!branchTextEdited) {
                branchText.setText(suggestion);
            }
            if (!tagTextEdited) {
                tagText.setText(suggestion);
            }
            checkPage();
        }
    });
    if (defaultChange != null) {
        refText.setText(defaultChange);
    } else if (candidateChange != null) {
        String ref = candidateChange.getRefName();
        if (ref != null) {
            refText.setText(ref);
        } else {
            refText.setText(candidateChange.getChangeNumber().toString());
        }
    }
    // get all available Gerrit URIs from the repository
    SortedSet<String> uris = new TreeSet<>();
    try {
        for (RemoteConfig rc : RemoteConfig.getAllRemoteConfigs(repository.getConfig())) {
            if (GerritUtil.isGerritFetch(rc)) {
                if (rc.getURIs().size() > 0) {
                    uris.add(rc.getURIs().get(0).toPrivateString());
                }
                for (URIish u : rc.getPushURIs()) {
                    uris.add(u.toPrivateString());
                }
            }
        }
    } catch (URISyntaxException e) {
        Activator.handleError(e.getMessage(), e, false);
        setErrorMessage(e.getMessage());
    }
    for (String aUri : uris) {
        uriCombo.add(aUri);
        changeRefs.put(aUri, new ChangeList(repository, aUri));
    }
    if (defaultUri != null) {
        uriCombo.setText(defaultUri);
    } else {
        selectLastUsedUri();
    }
    String currentUri = uriCombo.getText();
    ChangeList list = changeRefs.get(currentUri);
    if (list == null) {
        list = new ChangeList(repository, currentUri);
        changeRefs.put(currentUri, list);
    }
    preFetch(list);
    refText.setFocus();
    Dialog.applyDialogFont(main);
    setControl(main);
    if (candidateChange != null) {
        // Launch content assist when the page is displayed
        final IWizardContainer container = getContainer();
        if (container instanceof IPageChangeProvider) {
            ((IPageChangeProvider) container).addPageChangedListener(new IPageChangedListener() {

                @Override
                public void pageChanged(PageChangedEvent event) {
                    if (event.getSelectedPage() == FetchGerritChangePage.this) {
                        // Only the first time: remove myself
                        event.getPageChangeProvider().removePageChangedListener(this);
                        getControl().getDisplay().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                Control control = getControl();
                                if (control != null && !control.isDisposed()) {
                                    contentProposer.openProposalPopup();
                                }
                            }
                        });
                    }
                }
            });
        }
    }
    checkPage();
}
Also used : URIish(org.eclipse.jgit.transport.URIish) Group(org.eclipse.swt.widgets.Group) ModifyListener(org.eclipse.swt.events.ModifyListener) Matcher(java.util.regex.Matcher) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) PageChangedEvent(org.eclipse.jface.dialogs.PageChangedEvent) URISyntaxException(java.net.URISyntaxException) AbstractBranchSelectionDialog(org.eclipse.egit.ui.internal.dialogs.AbstractBranchSelectionDialog) KeyEvent(org.eclipse.swt.events.KeyEvent) IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) BranchNameNormalizer(org.eclipse.egit.ui.internal.components.BranchNameNormalizer) IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) TreeSet(java.util.TreeSet) SelectionEvent(org.eclipse.swt.events.SelectionEvent) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) BranchEditDialog(org.eclipse.egit.ui.internal.dialogs.BranchEditDialog) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IPageChangeProvider(org.eclipse.jface.dialogs.IPageChangeProvider) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) Date(java.util.Date) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 2 with BranchNameNormalizer

use of org.eclipse.egit.ui.internal.components.BranchNameNormalizer in project egit by eclipse.

the class CreateBranchPage method createControl.

@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 StyledText(main, SWT.NONE);
    sourceNameLabel.setBackground(main.getBackground());
    sourceNameLabel.setEditable(false);
    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
    // $NON-NLS-1$ //$NON-NLS-2$
    nameText.setData("org.eclipse.swtbot.widget.key", "BranchName");
    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((newConfig) -> {
        upstreamConfig = newConfig;
        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 listeners just now to avoid unneeded checkPage()
    nameText.addModifyListener(e -> checkPage());
    BranchNameNormalizer normalizer = new BranchNameNormalizer(nameText);
    normalizer.setVisible(false);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) TraverseEvent(org.eclipse.swt.events.TraverseEvent) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) TraverseListener(org.eclipse.swt.events.TraverseListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) BranchNameNormalizer(org.eclipse.egit.ui.internal.components.BranchNameNormalizer) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) UpstreamConfigComponent(org.eclipse.egit.ui.internal.components.UpstreamConfigComponent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 3 with BranchNameNormalizer

use of org.eclipse.egit.ui.internal.components.BranchNameNormalizer in project egit by eclipse.

the class BranchRenameDialog method create.

@Override
public void create() {
    super.create();
    setTitle(UIText.BranchRenameDialog_Title);
    String oldName = branchToRename.getName();
    String prefix;
    if (oldName.startsWith(Constants.R_HEADS))
        prefix = Constants.R_HEADS;
    else if (oldName.startsWith(Constants.R_REMOTES))
        prefix = Constants.R_REMOTES;
    else
        prefix = null;
    String shortName = null;
    if (prefix != null) {
        shortName = Repository.shortenRefName(branchToRename.getName());
        setMessage(NLS.bind(UIText.BranchRenameDialog_Message, shortName));
    } else
        setErrorMessage(NLS.bind(UIText.BranchRenameDialog_WrongPrefixErrorMessage, oldName));
    if (shortName != null) {
        name.setText(shortName);
        name.setSelection(0, shortName.length());
    }
    final IInputValidator inputValidator = ValidationUtils.getRefNameInputValidator(repository, prefix, true);
    name.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            String error = inputValidator.isValid(name.getText());
            setErrorMessage(error);
            getButton(OK).setEnabled(error == null);
        }
    });
    BranchNameNormalizer normalizer = new BranchNameNormalizer(name);
    normalizer.setVisible(false);
    getButton(OK).setEnabled(false);
}
Also used : BranchNameNormalizer(org.eclipse.egit.ui.internal.components.BranchNameNormalizer) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 4 with BranchNameNormalizer

use of org.eclipse.egit.ui.internal.components.BranchNameNormalizer in project egit by eclipse.

the class PushBranchPage method createControl.

@Override
public void createControl(Composite parent) {
    parent.addDisposeListener(event -> {
        for (CancelableFuture<Collection<Ref>> l : refs.values()) {
            l.cancel(CancelableFuture.CancelMode.INTERRUPT);
        }
        refs.clear();
    });
    try {
        this.remoteConfigs = RemoteConfig.getAllRemoteConfigs(repository.getConfig());
        Collections.sort(remoteConfigs, new Comparator<RemoteConfig>() {

            @Override
            public int compare(RemoteConfig first, RemoteConfig second) {
                return String.CASE_INSENSITIVE_ORDER.compare(first.getName(), second.getName());
            }
        });
    } catch (URISyntaxException e) {
        this.remoteConfigs = new ArrayList<>();
        handleError(e);
    }
    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(GridLayoutFactory.swtDefaults().create());
    Composite inputPanel = new Composite(main, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(inputPanel);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(inputPanel);
    Label sourceLabel = new Label(inputPanel, SWT.NONE);
    sourceLabel.setText(UIText.PushBranchPage_Source);
    Composite sourceComposite = new Composite(inputPanel, SWT.NONE);
    sourceComposite.setLayoutData(GridDataFactory.fillDefaults().indent(UIUtils.getControlIndent(), 0).create());
    RowLayout rowLayout = RowLayoutFactory.fillDefaults().create();
    rowLayout.center = true;
    sourceComposite.setLayout(rowLayout);
    if (this.ref != null) {
        Image branchIcon = UIIcons.BRANCH.createImage();
        this.disposables.add(branchIcon);
        Label branchIconLabel = new Label(sourceComposite, SWT.NONE);
        branchIconLabel.setLayoutData(new RowData(branchIcon.getBounds().width, branchIcon.getBounds().height));
        branchIconLabel.setImage(branchIcon);
        Label localBranchLabel = new Label(sourceComposite, SWT.NONE);
        localBranchLabel.setText(Repository.shortenRefName(this.ref.getName()));
        Label spacer = new Label(sourceComposite, SWT.NONE);
        spacer.setLayoutData(new RowData(3, SWT.DEFAULT));
    }
    Image commitIcon = UIIcons.CHANGESET.createImage();
    this.disposables.add(commitIcon);
    Label commitIconLabel = new Label(sourceComposite, SWT.NONE);
    commitIconLabel.setImage(commitIcon);
    commitIconLabel.setLayoutData(new RowData(commitIcon.getBounds().width, commitIcon.getBounds().height));
    Label commit = new Label(sourceComposite, SWT.NONE);
    StringBuilder commitBuilder = new StringBuilder(this.commitToPush.abbreviate(7).name());
    StringBuilder commitTooltipBuilder = new StringBuilder(this.commitToPush.getName());
    try (RevWalk revWalk = new RevWalk(repository)) {
        RevCommit revCommit = revWalk.parseCommit(this.commitToPush);
        // $NON-NLS-1$
        commitBuilder.append("  ");
        commitBuilder.append(Utils.shortenText(revCommit.getShortMessage(), MAX_SHORTCOMMIT_MESSAGE_LENGTH));
        // $NON-NLS-1$
        commitTooltipBuilder.append("\n\n");
        commitTooltipBuilder.append(revCommit.getFullMessage());
    } catch (IOException ex) {
        commitBuilder.append(UIText.PushBranchPage_CannotAccessCommitDescription);
        commitTooltipBuilder.append(ex.getMessage());
        Activator.handleError(ex.getLocalizedMessage(), ex, false);
    }
    commit.setText(commitBuilder.toString());
    commit.setToolTipText(commitTooltipBuilder.toString());
    Label destinationLabel = new Label(inputPanel, SWT.NONE);
    destinationLabel.setText(UIText.PushBranchPage_Destination);
    GridDataFactory.fillDefaults().applyTo(destinationLabel);
    Composite remoteGroup = new Composite(inputPanel, SWT.NONE);
    remoteGroup.setLayoutData(GridDataFactory.fillDefaults().indent(UIUtils.getControlIndent(), 0).create());
    remoteGroup.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).create());
    Label remoteLabel = new Label(remoteGroup, SWT.NONE);
    remoteLabel.setText(UIText.PushBranchPage_RemoteLabel);
    // Use full width in case "New Remote..." button is not shown
    int remoteSelectionSpan = showNewRemoteButton ? 1 : 2;
    remoteSelectionCombo = new RemoteSelectionCombo(remoteGroup, SWT.NONE, SelectionType.PUSH);
    GridDataFactory.fillDefaults().grab(true, false).span(remoteSelectionSpan, 1).applyTo(remoteSelectionCombo);
    setRemoteConfigs();
    remoteSelectionCombo.addRemoteSelectionListener(new IRemoteSelectionListener() {

        @Override
        public void remoteSelected(RemoteConfig rc) {
            remoteConfig = rc;
            setRefAssist(rc);
            checkPage();
        }
    });
    if (showNewRemoteButton) {
        Button newRemoteButton = new Button(remoteGroup, SWT.PUSH);
        newRemoteButton.setText(UIText.PushBranchPage_NewRemoteButton);
        GridDataFactory.fillDefaults().applyTo(newRemoteButton);
        newRemoteButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                showNewRemoteDialog();
            }
        });
    }
    Label branchNameLabel = new Label(remoteGroup, SWT.NONE);
    branchNameLabel.setText(UIText.PushBranchPage_RemoteBranchNameLabel);
    remoteBranchNameText = new Text(remoteGroup, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(remoteBranchNameText);
    remoteBranchNameText.setText(getSuggestedBranchName());
    AsynchronousRefProposalProvider candidateProvider = new AsynchronousRefProposalProvider(getContainer(), remoteBranchNameText, () -> {
        RemoteConfig config = remoteSelectionCombo.getSelectedRemote();
        if (config == null) {
            return null;
        }
        List<URIish> uris = config.getURIs();
        if (uris == null || uris.isEmpty()) {
            return null;
        }
        return uris.get(0).toString();
    }, uri -> {
        FutureRefs list = refs.get(uri);
        if (list == null) {
            list = new FutureRefs(repository, uri, getLocalBranchName());
            refs.put(uri, list);
        }
        return list;
    });
    candidateProvider.setContentProposalAdapter(UIUtils.addRefContentProposalToText(remoteBranchNameText, this.repository, candidateProvider, true));
    if (this.ref != null) {
        upstreamConfigComponent = new UpstreamConfigComponent(inputPanel, SWT.NONE);
        upstreamConfigComponent.getContainer().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(3, 1).indent(SWT.NONE, 20).create());
        upstreamConfigComponent.addUpstreamConfigSelectionListener(new UpstreamConfigSelectionListener() {

            @Override
            public void upstreamConfigSelected(BranchRebaseMode newUpstreamConfig) {
                upstreamConfig = newUpstreamConfig;
                checkPage();
            }
        });
        setDefaultUpstreamConfig();
    }
    final Button forceUpdateButton = new Button(inputPanel, SWT.CHECK);
    forceUpdateButton.setText(UIText.PushBranchPage_ForceUpdateButton);
    forceUpdateButton.setSelection(false);
    forceUpdateButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(3, 1).create());
    forceUpdateButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            forceUpdateSelected = forceUpdateButton.getSelection();
        }
    });
    Link advancedDialogLink = new Link(main, SWT.NONE);
    advancedDialogLink.setText(UIText.PushBranchPage_advancedWizardLink);
    advancedDialogLink.setToolTipText(UIText.PushBranchPage_advancedWizardLinkTooltip);
    advancedDialogLink.setLayoutData(new GridData(SWT.END, SWT.END, false, true));
    advancedDialogLink.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Shell parentShell = getShell().getParent().getShell();
            PushWizard advancedWizard = null;
            try {
                advancedWizard = new PushWizard(repository);
                getShell().close();
                new WizardDialog(parentShell, advancedWizard).open();
            } catch (URISyntaxException ex) {
                Activator.logError(ex.getMessage(), ex);
            }
        }
    });
    setControl(main);
    checkPage();
    // Add listener now to avoid setText above to already trigger it.
    remoteBranchNameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            checkPage();
        }
    });
    // Do not use a tooltip since there is already a content proposal
    // adapter on this field
    BranchNameNormalizer normalizer = new BranchNameNormalizer(remoteBranchNameText, null);
    normalizer.setVisible(false);
}
Also used : URIish(org.eclipse.jgit.transport.URIish) BranchRebaseMode(org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode) ModifyListener(org.eclipse.swt.events.ModifyListener) ArrayList(java.util.ArrayList) Label(org.eclipse.swt.widgets.Label) URISyntaxException(java.net.URISyntaxException) Image(org.eclipse.swt.graphics.Image) BranchNameNormalizer(org.eclipse.egit.ui.internal.components.BranchNameNormalizer) RowData(org.eclipse.swt.layout.RowData) UpstreamConfigComponent(org.eclipse.egit.ui.internal.components.UpstreamConfigComponent) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) IRemoteSelectionListener(org.eclipse.egit.ui.internal.components.RemoteSelectionCombo.IRemoteSelectionListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) RemoteSelectionCombo(org.eclipse.egit.ui.internal.components.RemoteSelectionCombo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) IOException(java.io.IOException) AsynchronousRefProposalProvider(org.eclipse.egit.ui.internal.components.AsynchronousRefProposalProvider) RevWalk(org.eclipse.jgit.revwalk.RevWalk) GridData(org.eclipse.swt.layout.GridData) Collection(java.util.Collection) UpstreamConfigSelectionListener(org.eclipse.egit.ui.internal.components.UpstreamConfigComponent.UpstreamConfigSelectionListener) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Link(org.eclipse.swt.widgets.Link)

Aggregations

BranchNameNormalizer (org.eclipse.egit.ui.internal.components.BranchNameNormalizer)4 ModifyEvent (org.eclipse.swt.events.ModifyEvent)4 ModifyListener (org.eclipse.swt.events.ModifyListener)4 UIText (org.eclipse.egit.ui.internal.UIText)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Button (org.eclipse.swt.widgets.Button)3 Composite (org.eclipse.swt.widgets.Composite)3 Label (org.eclipse.swt.widgets.Label)3 Text (org.eclipse.swt.widgets.Text)3 URISyntaxException (java.net.URISyntaxException)2 UpstreamConfigComponent (org.eclipse.egit.ui.internal.components.UpstreamConfigComponent)2 RemoteConfig (org.eclipse.jgit.transport.RemoteConfig)2 URIish (org.eclipse.jgit.transport.URIish)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 TreeSet (java.util.TreeSet)1