Search in sources :

Example 46 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig 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)

Example 47 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig in project egit by eclipse.

the class PushToGerritPage method createControl.

@Override
public void createControl(Composite parent) {
    loadKnownRemoteRefs();
    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout(3, false));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(main);
    new Label(main, SWT.NONE).setText(UIText.PushToGerritPage_UriLabel);
    uriCombo = new Combo(main, SWT.DROP_DOWN);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(uriCombo);
    uriCombo.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            checkPage();
        }
    });
    branchTextlabel = new Label(main, SWT.NONE);
    // we visualize the prefix here
    prefixCombo = new Combo(main, SWT.READ_ONLY | SWT.DROP_DOWN);
    prefixCombo.add(GerritUtil.REFS_FOR);
    prefixCombo.add(GerritUtil.REFS_DRAFTS);
    prefixCombo.select(0);
    branchTextlabel.setText(UIText.PushToGerritPage_BranchLabel);
    branchText = new Text(main, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(branchText);
    branchText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            checkPage();
        }
    });
    // give focus to the branchText if label is activated using the mnemonic
    branchTextlabel.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            branchText.setFocus();
            branchText.selectAll();
        }
    });
    addRefContentProposalToText(branchText);
    useTopic = new Button(main, SWT.CHECK | SWT.LEFT);
    useTopic.setText(UIText.PushToGerritPage_TopicUseLabel);
    GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(useTopic);
    topicLabel = new Label(main, SWT.NONE);
    topicLabel.setText(UIText.PushToGerritPage_TopicLabel);
    topicText = new Text(main, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(topicText);
    topicText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            checkPage();
        }
    });
    topicLabel.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            topicText.setFocus();
            topicText.selectAll();
        }
    });
    useTopic.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            topicText.setEnabled(useTopic.getSelection());
            checkPage();
        }
    });
    // get all available Gerrit URIs from the repository
    SortedSet<String> uris = new TreeSet<>();
    try {
        for (RemoteConfig rc : RemoteConfig.getAllRemoteConfigs(repository.getConfig())) {
            if (GerritUtil.isGerritPush(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);
    }
    selectLastUsedUri();
    setLastUsedBranch();
    initializeTopic(branchText.getText());
    addTopicProposal(topicText);
    branchText.setFocus();
    Dialog.applyDialogFont(main);
    setControl(main);
}
Also used : URIish(org.eclipse.jgit.transport.URIish) 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) Combo(org.eclipse.swt.widgets.Combo) 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) TreeSet(java.util.TreeSet) SelectionEvent(org.eclipse.swt.events.SelectionEvent) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 48 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig in project egit by eclipse.

the class PushWizard method saveRefSpecs.

private void saveRefSpecs() {
    final RemoteConfig rc = repoPage.getSelection().getConfig();
    rc.setPushRefSpecs(refSpecPage.getRefSpecs());
    final StoredConfig config = localDb.getConfig();
    rc.update(config);
    try {
        config.save();
    } catch (final IOException e) {
        ErrorDialog.openError(getShell(), UIText.PushWizard_cantSaveTitle, UIText.PushWizard_cantSaveMessage, new Status(IStatus.WARNING, Activator.getPluginId(), e.getMessage(), e));
    // Continue, it's not critical.
    }
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IOException(java.io.IOException) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 49 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig in project egit by eclipse.

the class PullWizard method configureNewRemote.

private void configureNewRemote(URIish uri) throws URISyntaxException, IOException {
    StoredConfig config = repository.getConfig();
    String remoteName = this.page.getRemoteConfig().getName();
    RemoteConfig remoteConfig = new RemoteConfig(config, remoteName);
    remoteConfig.addURI(uri);
    RefSpec defaultFetchSpec = new RefSpec().setForceUpdate(true).setSourceDestination(// $NON-NLS-1$
    Constants.R_HEADS + "*", // $NON-NLS-1$
    Constants.R_REMOTES + remoteName + "/*");
    remoteConfig.addFetchRefSpec(defaultFetchSpec);
    remoteConfig.update(config);
    config.save();
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) RefSpec(org.eclipse.jgit.transport.RefSpec) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 50 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig in project egit by eclipse.

the class PullWizardPage method setRemoteConfigs.

private void setRemoteConfigs() {
    remoteSelectionCombo.setItems(remoteConfigs);
    if (this.head != null) {
        String branchName = Repository.shortenRefName(this.head.getName());
        BranchConfig branchConfig = new BranchConfig(repository.getConfig(), branchName);
        String remoteName = branchConfig.getRemote();
        if (remoteName != null) {
            for (RemoteConfig rc : remoteConfigs) {
                if (remoteName.equals(rc.getName()))
                    remoteSelectionCombo.setSelectedRemote(rc);
            }
        }
    }
    remoteConfig = remoteSelectionCombo.getSelectedRemote();
    setRefAssist(remoteConfig);
}
Also used : BranchConfig(org.eclipse.jgit.lib.BranchConfig) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Aggregations

RemoteConfig (org.eclipse.jgit.transport.RemoteConfig)63 URISyntaxException (java.net.URISyntaxException)23 StoredConfig (org.eclipse.jgit.lib.StoredConfig)21 URIish (org.eclipse.jgit.transport.URIish)21 IOException (java.io.IOException)16 RefSpec (org.eclipse.jgit.transport.RefSpec)14 Repository (org.eclipse.jgit.lib.Repository)13 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)7 Button (org.eclipse.swt.widgets.Button)6 Composite (org.eclipse.swt.widgets.Composite)6 File (java.io.File)5 Git (org.eclipse.jgit.api.Git)5 Ref (org.eclipse.jgit.lib.Ref)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Label (org.eclipse.swt.widgets.Label)5 List (java.util.List)4 CoreException (org.eclipse.core.runtime.CoreException)4 UIText (org.eclipse.egit.ui.internal.UIText)4