Example usage for org.eclipse.jgit.lib RefDatabase getAdditionalRefs

List of usage examples for org.eclipse.jgit.lib RefDatabase getAdditionalRefs

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib RefDatabase getAdditionalRefs.

Prototype

@NonNull
public abstract List<Ref> getAdditionalRefs() throws IOException;

Source Link

Document

Get the additional reference-like entities from the repository.

Usage

From source file:org.eclipse.egit.ui.internal.actions.SynchronizeWithMenu.java

License:Open Source License

@Override
public void fill(final Menu menu, int index) {
    if (srv == null)
        return;//  www.  j  a  v a 2  s.com
    final IResource selectedResource = getSelection();
    if (selectedResource == null || selectedResource.isLinked(IResource.CHECK_ANCESTORS))
        return;

    RepositoryMapping mapping = RepositoryMapping.getMapping(selectedResource.getProject());
    if (mapping == null)
        return;

    final Repository repo = mapping.getRepository();
    if (repo == null)
        return;

    List<Ref> refs = new LinkedList<Ref>();
    RefDatabase refDatabase = repo.getRefDatabase();
    try {
        refs.addAll(refDatabase.getAdditionalRefs());
    } catch (IOException e) {
        // do nothing
    }
    try {
        refs.addAll(refDatabase.getRefs(RefDatabase.ALL).values());
    } catch (IOException e) {
        // do nothing
    }
    Collections.sort(refs, CommonUtils.REF_ASCENDING_COMPARATOR);
    String currentBranch;
    try {
        currentBranch = repo.getFullBranch();
    } catch (IOException e) {
        currentBranch = ""; //$NON-NLS-1$
    }

    int count = 0;
    String oldName = null;
    int refsLength = R_REFS.length();
    int tagsLength = R_TAGS.substring(refsLength).length();
    for (Ref ref : refs) {
        final String name = ref.getName();
        if (name.equals(Constants.HEAD) || name.equals(currentBranch) || excludeTag(ref, repo))
            continue;
        if (name.startsWith(R_REFS) && oldName != null
                && !oldName.regionMatches(refsLength, name, refsLength, tagsLength))
            new MenuItem(menu, SWT.SEPARATOR);

        MenuItem item = new MenuItem(menu, SWT.PUSH);
        item.setText(name);
        if (name.startsWith(Constants.R_TAGS))
            item.setImage(tagImage);
        else if (name.startsWith(Constants.R_HEADS) || name.startsWith(Constants.R_REMOTES))
            item.setImage(branchImage);

        item.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent event) {
                GitSynchronizeData data;
                try {
                    data = new GitSynchronizeData(repo, HEAD, name, true);
                    if (!(selectedResource instanceof IProject)) {
                        HashSet<IContainer> containers = new HashSet<IContainer>();
                        containers.add((IContainer) selectedResource);
                        data.setIncludedPaths(containers);
                    }

                    GitModelSynchronize.launch(data, new IResource[] { selectedResource });
                } catch (IOException e) {
                    Activator.logError(e.getMessage(), e);
                }
            }
        });

        if (++count == MAX_NUM_MENU_ENTRIES)
            break;
        oldName = name;
    }

    if (count > 1)
        new MenuItem(menu, SWT.SEPARATOR);

    MenuItem custom = new MenuItem(menu, SWT.PUSH);
    custom.setText(UIText.SynchronizeWithMenu_custom);
    custom.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            GitSynchronizeWizard gitWizard = new GitSynchronizeWizard();
            WizardDialog wizard = new WizardDialog(menu.getShell(), gitWizard);
            wizard.create();
            wizard.open();
        }
    });
}