Search in sources :

Example 1 with RemoteSelectionCombo

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

the class PullWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    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());
            }
        });
        setDefaultUpstreamConfig();
    } catch (URISyntaxException e) {
        this.remoteConfigs = new ArrayList<>();
        handleError(e);
    }
    Composite res = new Composite(parent, SWT.NONE);
    res.setLayout(new GridLayout(3, false));
    Label remoteLabel = new Label(res, SWT.NONE);
    remoteLabel.setText(UIText.PushBranchPage_RemoteLabel);
    this.remoteSelectionCombo = new RemoteSelectionCombo(res, SWT.NONE, SelectionType.PUSH);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(remoteSelectionCombo);
    setRemoteConfigs();
    remoteSelectionCombo.addRemoteSelectionListener(new IRemoteSelectionListener() {

        @Override
        public void remoteSelected(RemoteConfig rc) {
            remoteConfig = rc;
            setRefAssist(rc);
            checkPage();
        }
    });
    Button newRemoteButton = new Button(res, 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(res, SWT.NONE);
    branchNameLabel.setText(UIText.PullWizardPage_referenceLabel);
    branchNameLabel.setToolTipText(UIText.PullWizardPage_referenceTooltip);
    remoteBranchNameText = new Text(res, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(remoteBranchNameText);
    UIUtils.addRefContentProposalToText(remoteBranchNameText, this.repository, () -> {
        if (PullWizardPage.this.assist != null) {
            return PullWizardPage.this.assist.getRefsForContentAssist(false, true);
        }
        return Collections.emptyList();
    }, true);
    remoteBranchNameText.setText(getSuggestedBranchName());
    remoteBranchNameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            checkPage();
        }
    });
    this.upstreamConfigComponent = new BranchRebaseModeCombo(res);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).align(SWT.BEGINNING, SWT.CENTER).applyTo(upstreamConfigComponent.getViewer().getCombo());
    this.upstreamConfigComponent.getViewer().addSelectionChangedListener((event) -> upstreamConfig = upstreamConfigComponent.getRebaseMode());
    if (upstreamConfig != null) {
        upstreamConfigComponent.setRebaseMode(upstreamConfig);
    }
    if (this.fullBranch != null && this.fullBranch.startsWith(Constants.R_HEADS)) {
        this.rememberConfigForBranch = new Button(res, SWT.CHECK);
        GridData checkboxLayoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1);
        checkboxLayoutData.verticalIndent = 20;
        this.rememberConfigForBranch.setText(UIText.UpstreamConfigComponent_ConfigureUpstreamCheck);
        this.rememberConfigForBranch.setToolTipText(UIText.UpstreamConfigComponent_ConfigureUpstreamToolTip);
        this.rememberConfigForBranch.setLayoutData(checkboxLayoutData);
        this.rememberConfigForBranch.setSelection(this.configureUpstream);
        this.rememberConfigForBranch.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                configureUpstream = rememberConfigForBranch.getSelection();
                checkPage();
            }
        });
    }
    setPageComplete(isPageComplete());
    setControl(res);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) Label(org.eclipse.swt.widgets.Label) BranchRebaseModeCombo(org.eclipse.egit.ui.internal.components.BranchRebaseModeCombo) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) URISyntaxException(java.net.URISyntaxException) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) IRemoteSelectionListener(org.eclipse.egit.ui.internal.components.RemoteSelectionCombo.IRemoteSelectionListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) RemoteSelectionCombo(org.eclipse.egit.ui.internal.components.RemoteSelectionCombo)

Example 2 with RemoteSelectionCombo

use of org.eclipse.egit.ui.internal.components.RemoteSelectionCombo 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)

Example 3 with RemoteSelectionCombo

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

the class PushTagsPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(GridLayoutFactory.swtDefaults().spacing(LayoutConstants.getSpacing()).numColumns(2).create());
    Label remoteLabel = new Label(main, SWT.NONE);
    remoteLabel.setText(UIText.PushTagsPage_RemoteLabel);
    RemoteSelectionCombo remoteSelectionCombo = new RemoteSelectionCombo(main, SWT.NONE, SelectionType.PUSH);
    remoteSelectionCombo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    selectedRemoteConfig = remoteSelectionCombo.setItems(getRemoteConfigs());
    remoteSelectionCombo.addRemoteSelectionListener(new RemoteSelectionCombo.IRemoteSelectionListener() {

        @Override
        public void remoteSelected(RemoteConfig remoteConfig) {
            selectedRemoteConfig = remoteConfig;
        }
    });
    tagsLabel = new Label(main, SWT.NONE);
    tagsLabel.setText(UIText.PushTagsPage_TagsLabelNoneSelected);
    tagsLabel.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());
    FilteredCheckboxTree tree = new FilteredCheckboxTree(main, null, SWT.BORDER);
    tree.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(2, 1).hint(400, 300).create());
    final Button forceUpdateButton = new Button(main, SWT.CHECK);
    forceUpdateButton.setText(UIText.PushTagsPage_ForceUpdateButton);
    forceUpdateButton.setSelection(false);
    forceUpdateButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());
    forceUpdateButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            forceUpdateSelected = forceUpdateButton.getSelection();
        }
    });
    final CachedCheckboxTreeViewer treeViewer = tree.getCheckboxTreeViewer();
    TagsNode tagsNode = new TagsNode(null, repository);
    ContentProvider contentProvider = new ContentProvider(tagsNode);
    treeViewer.setContentProvider(contentProvider);
    treeViewer.setLabelProvider(new RepositoriesViewStyledCellLabelProvider());
    treeViewer.setComparator(new ViewerComparator(CommonUtils.STRING_ASCENDING_COMPARATOR));
    treeViewer.setInput(tagsNode);
    final Object[] tagNodes = contentProvider.getElements(tagsNode);
    initiallySelectTags(tagNodes, treeViewer);
    treeViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            setSelectedTags(treeViewer.getCheckedElements());
        }
    });
    setControl(main);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) FilteredCheckboxTree(org.eclipse.egit.ui.internal.components.FilteredCheckboxTree) RepositoriesViewContentProvider(org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TagsNode(org.eclipse.egit.ui.internal.repository.tree.TagsNode) Label(org.eclipse.swt.widgets.Label) RepositoriesViewStyledCellLabelProvider(org.eclipse.egit.ui.internal.repository.RepositoriesViewStyledCellLabelProvider) CachedCheckboxTreeViewer(org.eclipse.egit.ui.internal.components.CachedCheckboxTreeViewer) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) RemoteSelectionCombo(org.eclipse.egit.ui.internal.components.RemoteSelectionCombo) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Aggregations

RemoteSelectionCombo (org.eclipse.egit.ui.internal.components.RemoteSelectionCombo)3 RemoteConfig (org.eclipse.jgit.transport.RemoteConfig)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 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 UIText (org.eclipse.egit.ui.internal.UIText)2 IRemoteSelectionListener (org.eclipse.egit.ui.internal.components.RemoteSelectionCombo.IRemoteSelectionListener)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 GridData (org.eclipse.swt.layout.GridData)2 Text (org.eclipse.swt.widgets.Text)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 AsynchronousRefProposalProvider (org.eclipse.egit.ui.internal.components.AsynchronousRefProposalProvider)1 BranchNameNormalizer (org.eclipse.egit.ui.internal.components.BranchNameNormalizer)1 BranchRebaseModeCombo (org.eclipse.egit.ui.internal.components.BranchRebaseModeCombo)1