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);
}
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;
}
Aggregations