Search in sources :

Example 1 with RepositorySearchWizard

use of org.eclipse.egit.ui.internal.repository.RepositorySearchWizard 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 2 with RepositorySearchWizard

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

the class AddCommand method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    RepositorySearchWizard wizard = new RepositorySearchWizard(util.getConfiguredRepositories(), true);
    WizardDialog dialog = new WizardDialog(getShell(event), wizard) {

        @Override
        protected Button createButton(Composite parent, int id, String label, boolean defaultButton) {
            if (id == IDialogConstants.FINISH_ID) {
                return super.createButton(parent, id, UIText.AddCommand_AddButtonLabel, defaultButton);
            }
            return super.createButton(parent, id, label, defaultButton);
        }
    };
    if (dialog.open() == Window.OK) {
        for (String dir : wizard.getDirectories()) {
            File repositoryDir = FileUtils.canonicalize(new File(dir));
            addRepository(repositoryDir);
        }
    }
    return null;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) RepositorySearchWizard(org.eclipse.egit.ui.internal.repository.RepositorySearchWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) File(java.io.File)

Aggregations

File (java.io.File)2 RepositorySearchWizard (org.eclipse.egit.ui.internal.repository.RepositorySearchWizard)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 Composite (org.eclipse.swt.widgets.Composite)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 IPreferenceChangeListener (org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener)1 PreferenceChangeEvent (org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)1 RepositoriesViewContentProvider (org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider)1 RepositoriesViewLabelProvider (org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider)1 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Button (org.eclipse.swt.widgets.Button)1