Search in sources :

Example 1 with RepositoriesViewContentProvider

use of org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider in project egit by eclipse.

the class AbstractBranchSelectionDialog method createRefNode.

private RefNode createRefNode(RepositoryTreeNode<?> root, Repository repository, Ref ref) {
    IContentProvider cp = branchTree.getContentProvider();
    if (cp instanceof RepositoriesViewContentProvider && ((RepositoriesViewContentProvider) cp).isHierarchical()) {
        // Create intermediary BranchHierarchyNodes
        String fullName = ref.getName();
        int i = 0;
        if (fullName.startsWith(Constants.R_HEADS)) {
            i = Constants.R_HEADS.length();
        } else if (fullName.startsWith(Constants.R_REMOTES)) {
            i = Constants.R_REMOTES.length();
        }
        RepositoryTreeNode<?> top = root;
        int l = fullName.length();
        while (i < l) {
            int j = fullName.indexOf('/', i);
            if (j > i) {
                top = new BranchHierarchyNode(top, repository, new Path(fullName.substring(0, j)));
                i = j + 1;
            } else {
                break;
            }
        }
        return new RefNode(top, repository, ref);
    } else {
        return new RefNode(root, repository, ref);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IContentProvider(org.eclipse.jface.viewers.IContentProvider) RepositoriesViewContentProvider(org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider) BranchHierarchyNode(org.eclipse.egit.ui.internal.repository.tree.BranchHierarchyNode) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode) AdditionalRefNode(org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode)

Example 2 with RepositoriesViewContentProvider

use of org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider in project egit by eclipse.

the class LinkHelper method findSelection.

/**
 * TODO javadoc missing
 */
@Override
@SuppressWarnings("unchecked")
public IStructuredSelection findSelection(IEditorInput anInput) {
    if (!(anInput instanceof IURIEditorInput)) {
        return null;
    }
    URI uri = ((IURIEditorInput) anInput).getURI();
    if (// $NON-NLS-1$
    !uri.getScheme().equals("file"))
        return null;
    File file = new File(uri.getPath());
    if (!file.exists())
        return null;
    RepositoryUtil config = Activator.getDefault().getRepositoryUtil();
    List<String> repos = config.getConfiguredRepositories();
    for (String repo : repos) {
        Repository repository;
        try {
            repository = FileRepositoryBuilder.create(new File(repo));
        } catch (IOException e) {
            continue;
        }
        if (repository.isBare())
            continue;
        if (file.getPath().startsWith(repository.getWorkTree().getPath())) {
            RepositoriesViewContentProvider cp = new RepositoriesViewContentProvider();
            RepositoryNode repoNode = new RepositoryNode(null, repository);
            RepositoryTreeNode result = null;
            for (Object child : cp.getChildren(repoNode)) {
                if (child instanceof WorkingDirNode) {
                    result = (WorkingDirNode) child;
                    break;
                }
            }
            if (result == null)
                return null;
            IPath remainingPath = new Path(file.getPath().substring(repository.getWorkTree().getPath().length()));
            for (String segment : remainingPath.segments()) {
                for (Object child : cp.getChildren(result)) {
                    RepositoryTreeNode<File> fileNode;
                    try {
                        fileNode = (RepositoryTreeNode<File>) child;
                    } catch (ClassCastException e) {
                        return null;
                    }
                    if (fileNode.getObject().getName().equals(segment)) {
                        result = fileNode;
                        break;
                    }
                }
            }
            return new StructuredSelection(result);
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IURIEditorInput(org.eclipse.ui.IURIEditorInput) IPath(org.eclipse.core.runtime.IPath) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) RepositoriesViewContentProvider(org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider) URI(java.net.URI) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) Repository(org.eclipse.jgit.lib.Repository) File(java.io.File) IFile(org.eclipse.core.resources.IFile)

Example 3 with RepositoriesViewContentProvider

use of org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider in project egit by eclipse.

the class GitSelectRepositoryPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite main = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).applyTo(main);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(main);
    // use a filtered tree
    FilteredTree tree = new FilteredTree(main, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, new PatternFilter(), true);
    tv = tree.getViewer();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(tree);
    tv.setContentProvider(new RepositoriesViewContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            Object[] elements = super.getElements(inputElement);
            if (allowBare) {
                return elements;
            }
            List<Object> result = new ArrayList<>();
            for (Object element : elements) {
                if (element instanceof RepositoryTreeNode) {
                    RepositoryTreeNode node = (RepositoryTreeNode) element;
                    if (node.getRepository() != null && !node.getRepository().isBare()) {
                        result.add(element);
                    }
                }
            }
            bareMsg.setVisible(result.size() != elements.length);
            return result.toArray();
        }

        // we never show children, only the Repository nodes
        @Override
        public Object[] getChildren(Object parentElement) {
            return null;
        }

        @Override
        public boolean hasChildren(Object element) {
            return false;
        }
    });
    tv.setLabelProvider(new RepositoriesViewLabelProvider());
    Composite tb = new Composite(main, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(tb);
    GridDataFactory.fillDefaults().grab(false, true).applyTo(tb);
    addRepo = new Button(tb, SWT.PUSH);
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING).applyTo(addRepo);
    addRepo.setText(UIText.GitSelectRepositoryPage_AddButton);
    addRepo.setToolTipText(UIText.GitSelectRepositoryPage_AddTooltip);
    addRepo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            List<String> configuredDirs = util.getConfiguredRepositories();
            RepositorySearchWizard wizard = new RepositorySearchWizard(configuredDirs, allowBare);
            WizardDialog dlg = new WizardDialog(getShell(), wizard);
            if (dlg.open() == Window.OK && !wizard.getDirectories().isEmpty()) {
                Set<String> dirs = wizard.getDirectories();
                for (String dir : dirs) {
                    File gitDir = FileUtils.canonicalize(new File(dir));
                    GerritUtil.tryToAutoConfigureForGerrit(gitDir);
                    util.addConfiguredRepository(gitDir);
                }
                checkPage();
            }
        }
    });
    if (!allowBare) {
        bareMsg = new Composite(main, SWT.NONE);
        bareMsg.setLayout(new RowLayout());
        bareMsg.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
        Label imageLabel = new Label(bareMsg, SWT.NONE);
        imageLabel.setImage(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO));
        Label textLabel = new Label(bareMsg, SWT.WRAP);
        textLabel.setText(UIText.GitSelectRepositoryPage_BareRepositoriesHidden);
        bareMsg.setVisible(false);
    }
    tv.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            checkPage();
        }
    });
    tv.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            checkPage();
            if (isPageComplete())
                getContainer().showPage(getNextPage());
        }
    });
    tv.setInput(util.getConfiguredRepositories());
    configChangeListener = new IPreferenceChangeListener() {

        @Override
        public void preferenceChange(PreferenceChangeEvent event) {
            if (RepositoryUtil.PREFS_DIRECTORIES_REL.equals(event.getKey())) {
                Display display = tv.getControl().getDisplay();
                display.asyncExec(() -> {
                    if (!tv.getControl().isDisposed()) {
                        refreshRepositoryList();
                        checkPage();
                    }
                });
            }
        }
    };
    util.getPreferences().addPreferenceChangeListener(configChangeListener);
    // we need to select at least a repository to become complete
    setPageComplete(false);
    Dialog.applyDialogFont(main);
    setControl(main);
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Set(java.util.Set) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) RepositoriesViewLabelProvider(org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider) RepositoriesViewContentProvider(org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider) RepositorySearchWizard(org.eclipse.egit.ui.internal.repository.RepositorySearchWizard) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) PreferenceChangeEvent(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent) IPreferenceChangeListener(org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) WizardDialog(org.eclipse.jface.wizard.WizardDialog) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Example 4 with RepositoriesViewContentProvider

use of org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider in project egit by eclipse.

the class GitSelectWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite main = new Composite(parent, SWT.NO_RADIO_GROUP);
    main.setLayout(new GridLayout(1, false));
    SelectionListener sl = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            tv.getTree().setEnabled(!newProjectWizard.getSelection());
            if (importExisting.getSelection())
                wizardSelection = EXISTING_PROJECTS_WIZARD;
            else if (newProjectWizard.getSelection())
                wizardSelection = NEW_WIZARD;
            else if (generalWizard.getSelection())
                wizardSelection = GENERAL_WIZARD;
            else
                wizardSelection = EXISTING_PROJECTS_WIZARD;
            checkPage();
        }
    };
    Group wizardType = new Group(main, SWT.SHADOW_ETCHED_IN);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(wizardType);
    wizardType.setText(UIText.GitSelectWizardPage_ProjectCreationHeader);
    wizardType.setLayout(new GridLayout(1, false));
    importExisting = new Button(wizardType, SWT.RADIO);
    importExisting.setText(UIText.GitSelectWizardPage_ImportExistingButton);
    importExisting.addSelectionListener(sl);
    decorateWithFilterCount(importExisting);
    newProjectWizard = new Button(wizardType, SWT.RADIO);
    newProjectWizard.setText(UIText.GitSelectWizardPage_UseNewProjectsWizardButton);
    newProjectWizard.addSelectionListener(sl);
    generalWizard = new Button(wizardType, SWT.RADIO);
    generalWizard.setText(UIText.GitSelectWizardPage_ImportAsGeneralButton);
    generalWizard.addSelectionListener(sl);
    IDialogSettings settings = Activator.getDefault().getDialogSettings();
    try {
        wizardSelection = settings.getInt(PREF_WIZ);
    } catch (NumberFormatException e) {
        wizardSelection = EXISTING_PROJECTS_WIZARD;
    }
    switch(wizardSelection) {
        default:
        case EXISTING_PROJECTS_WIZARD:
            importExisting.setSelection(true);
            break;
        case GENERAL_WIZARD:
            generalWizard.setSelection(true);
            break;
        case NEW_WIZARD:
            newProjectWizard.setSelection(true);
            break;
    }
    tv = new TreeViewer(main, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    RepositoriesViewContentProvider cp = new RepositoriesViewContentProvider();
    tv.setContentProvider(cp);
    GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 200).applyTo(tv.getTree());
    tv.setLabelProvider(new RepositoriesViewLabelProvider());
    tv.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            checkPage();
        }
    });
    if (initialRepository != null) {
        List<WorkingDirNode> input = new ArrayList<>();
        WorkingDirNode node = new WorkingDirNode(null, initialRepository);
        input.add(node);
        tv.setInput(input);
        // expand root node
        tv.expandToLevel(2);
        // select the working directory as default
        if (initialPath == null)
            tv.setSelection(new StructuredSelection(input.get(0)));
        else {
            RepositoryTreeNode parentNode = node;
            IPath fullPath = new Path(initialPath);
            IPath workdirPath = new Path(initialRepository.getWorkTree().getPath());
            if (workdirPath.isPrefixOf(fullPath)) {
                IPath relPath = fullPath.removeFirstSegments(workdirPath.segmentCount());
                for (String segment : relPath.segments()) {
                    for (Object child : cp.getChildren(parentNode)) {
                        if (child instanceof FolderNode) {
                            FolderNode childFolder = (FolderNode) child;
                            if (childFolder.getObject().getName().equals(segment)) {
                                parentNode = childFolder;
                                break;
                            }
                        }
                    }
                }
                tv.setSelection(new StructuredSelection(parentNode));
            }
        }
    }
    tv.getTree().setEnabled(!newProjectWizard.getSelection());
    Dialog.applyDialogFont(main);
    setControl(main);
}
Also used : Group(org.eclipse.swt.widgets.Group) FolderNode(org.eclipse.egit.ui.internal.repository.tree.FolderNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) RepositoriesViewLabelProvider(org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider) RepositoriesViewContentProvider(org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) WorkingDirNode(org.eclipse.egit.ui.internal.repository.tree.WorkingDirNode) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Composite(org.eclipse.swt.widgets.Composite) IPath(org.eclipse.core.runtime.IPath) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 5 with RepositoriesViewContentProvider

use of org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider in project egit by eclipse.

the class AbstractBranchSelectionDialog method createDialogArea.

@Override
protected final Composite createDialogArea(Composite base) {
    Composite parent = (Composite) super.createDialogArea(base);
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    composite.setLayout(layout);
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    int selectionModel = -1;
    if ((settings & ALLOW_MULTISELECTION) != 0)
        selectionModel = SWT.MULTI;
    else
        selectionModel = SWT.SINGLE;
    FilteredTree tree = new FilteredTree(composite, selectionModel | SWT.BORDER, new PatternFilter(), true);
    branchTree = tree.getViewer();
    branchTree.setUseHashlookup(true);
    branchTree.setLabelProvider(new RepositoriesViewStyledCellLabelProvider());
    branchTree.setContentProvider(new RepositoriesViewContentProvider());
    ColumnViewerToolTipSupport.enableFor(branchTree);
    GridDataFactory.fillDefaults().grab(true, true).hint(500, 300).applyTo(tree);
    branchTree.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            String refName = refNameFromDialog();
            refNameSelected(refName);
        }
    });
    // double-click support
    branchTree.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            RepositoryTreeNode node = (RepositoryTreeNode) ((IStructuredSelection) branchTree.getSelection()).getFirstElement();
            if (node == null)
                return;
            final RepositoryTreeNodeType type = node.getType();
            if (type != RepositoryTreeNodeType.REF && type != RepositoryTreeNodeType.TAG && type != RepositoryTreeNodeType.ADDITIONALREF)
                branchTree.setExpandedState(node, !branchTree.getExpandedState(node));
            else if (isOkButtonEnabled())
                buttonPressed(OK);
        }
    });
    branchTree.setComparator(new ViewerComparator(STRING_ASCENDING_COMPARATOR));
    createCustomArea(composite);
    setTitle(getTitle());
    setMessage(getMessageText());
    getShell().setText(getWindowTitle());
    applyDialogFont(composite);
    return composite;
}
Also used : RepositoryTreeNodeType(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNodeType) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoriesViewContentProvider(org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider) RepositoriesViewStyledCellLabelProvider(org.eclipse.egit.ui.internal.repository.RepositoriesViewStyledCellLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener)

Aggregations

RepositoriesViewContentProvider (org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider)6 Path (org.eclipse.core.runtime.Path)3 RepositoriesViewLabelProvider (org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider)3 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)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 File (java.io.File)2 ArrayList (java.util.ArrayList)2 IPath (org.eclipse.core.runtime.IPath)2 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 IOException (java.io.IOException)1 URI (java.net.URI)1