use of org.eclipse.egit.ui.internal.repository.tree.RepositoryNode in project egit by eclipse.
the class GitRepositoriesViewTestUtils method getRootItem.
public SWTBotTreeItem getRootItem(SWTBotTree tree, File repositoryFile) throws Exception {
Repository repository = lookupRepository(repositoryFile);
RepositoryNode root = new RepositoryNode(null, repository);
String rootText = labelProvider.getStyledText(root).getString();
SWTBotTreeItem rootItem = tree.getTreeItem(rootText);
return rootItem;
}
use of org.eclipse.egit.ui.internal.repository.tree.RepositoryNode in project egit by eclipse.
the class AbstractHistoryCommandHandler method getRefNodes.
/**
* Utility to get a list of Refs from a commit in order to handle ambiguous
* selections when a Ref is preferred over a commit.
*
* @param commit
* @param repo
* @param refPrefixes
* e.g. "refs/heads/" or ""
* @return a list of RefNodes
*/
protected List<RefNode> getRefNodes(ObjectId commit, Repository repo, String... refPrefixes) {
List<Ref> availableBranches = new ArrayList<>();
List<RefNode> nodes = new ArrayList<>();
try {
Map<String, Ref> branches = new HashMap<>();
for (String refPrefix : refPrefixes) {
branches.putAll(repo.getRefDatabase().getRefs(refPrefix));
}
for (Ref branch : branches.values()) {
ObjectId objectId = branch.getLeaf().getObjectId();
if (objectId != null && objectId.equals(commit)) {
availableBranches.add(branch);
}
}
RepositoryNode repoNode = new RepositoryNode(null, repo);
for (Ref ref : availableBranches) {
nodes.add(new RefNode(repoNode, repo, ref));
}
} catch (IOException e) {
// ignore here
}
return nodes;
}
use of org.eclipse.egit.ui.internal.repository.tree.RepositoryNode in project egit by eclipse.
the class CommitSearchPage method handleWidgetSelected.
private void handleWidgetSelected() {
int selectionIndex = patternCombo.getSelectionIndex();
if (selectionIndex < 0 || selectionIndex >= fPreviousSearchPatterns.size()) {
repositoryViewer.setAllChecked(true);
repositoryGroup.setText(getRepositoryText());
return;
}
CommitSearchSettings settings = fPreviousSearchPatterns.get(selectionIndex);
if (!patternCombo.getText().equals(settings.getTextPattern()))
return;
isCaseSensitiveButton.setSelection(settings.isCaseSensitive());
isRegExButton.setSelection(settings.isRegExSearch());
patternCombo.setText(settings.getTextPattern());
patternFieldContentAssist.setEnabled(settings.isRegExSearch());
searchAuthorButton.setSelection(settings.isMatchAuthor());
searchCommitButton.setSelection(settings.isMatchCommit());
searchCommitterButton.setSelection(settings.isMatchCommitter());
searchMessageButton.setSelection(settings.isMatchMessage());
searchParentsButton.setSelection(settings.isMatchParents());
searchTreeButton.setSelection(settings.isMatchTree());
searchAllBranchesButton.setSelection(settings.isAllBranches());
List<RepositoryNode> repositories = new LinkedList<>();
for (String path : settings.getRepositories()) {
File file = new File(path);
if (file.exists())
try {
RepositoryNode node = new RepositoryNode(null, org.eclipse.egit.core.Activator.getDefault().getRepositoryCache().lookupRepository(file));
repositories.add(node);
} catch (IOException ignore) {
// Ignore and don't check
}
}
repositoryViewer.setCheckedElements(repositories.toArray());
repositoryGroup.setText(getRepositoryText());
}
use of org.eclipse.egit.ui.internal.repository.tree.RepositoryNode in project egit by eclipse.
the class SelectionForViewsTest method before.
@Before
public void before() throws Exception {
localRepositoryDir = createProjectAndCommitToRepository();
remoteRepositoryDir = createRemoteRepository(localRepositoryDir);
URIish uri = new URIish("file:///" + remoteRepositoryDir.getPath());
File workdir = new File(getTestDirectory(), "ClonedRepo");
CloneOperation op = new CloneOperation(uri, true, null, workdir, "refs/heads/master", "origin", 0);
op.run(null);
clonedRepositoryDir = new File(workdir, Constants.DOT_GIT);
RepositoryUtil repoUtil = Activator.getDefault().getRepositoryUtil();
repoUtil.addConfiguredRepository(localRepositoryDir);
repoUtil.addConfiguredRepository(clonedRepositoryDir);
// it's bare
repoUtil.addConfiguredRepository(remoteRepositoryDir);
stagingView = TestUtil.showView(StagingView.VIEW_ID);
reflogView = TestUtil.showView(ReflogView.VIEW_ID);
rebaseInteractiveView = TestUtil.showView(RebaseInteractiveView.VIEW_ID);
repoView = TestUtil.showView(RepositoriesView.VIEW_ID);
RepositoriesView repos = (RepositoriesView) repoView.getViewReference().getView(false);
repos.setReactOnSelection(true);
historyView = TestUtil.showHistoryView();
IHistoryView history = (IHistoryView) historyView.getViewReference().getView(false);
((GenericHistoryView) history).setLinkingEnabled(true);
// Ensure that the git history page is active
Exception[] exception = { null };
PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
try {
history.showHistoryFor(new RepositoryNode(null, lookupRepository(localRepositoryDir)), true);
} catch (Exception e) {
exception[0] = e;
}
});
if (exception[0] != null) {
throw exception[0];
}
waitForRefreshes();
}
use of org.eclipse.egit.ui.internal.repository.tree.RepositoryNode in project egit by eclipse.
the class RemoveCommand method removeRepository.
/**
* Remove or delete the repository
*
* @param event
* @param delete
* if <code>true</code>, the repository will be deleted from disk
*/
protected void removeRepository(final ExecutionEvent event, final boolean delete) {
IServiceLocator serviceLocator = HandlerUtil.getActiveSite(event);
IWorkbenchSiteProgressService service = null;
if (serviceLocator != null) {
service = CommonUtils.getService(serviceLocator, IWorkbenchSiteProgressService.class);
}
// get selected nodes
final List<RepositoryNode> selectedNodes;
try {
selectedNodes = getSelectedNodes(event);
} catch (ExecutionException e) {
Activator.handleError(e.getMessage(), e, true);
return;
}
boolean deleteWorkingDir = false;
boolean removeProjects = false;
final List<IProject> projectsToDelete = findProjectsToDelete(selectedNodes);
if (delete) {
if (selectedNodes.size() > 1) {
return;
} else if (selectedNodes.size() == 1) {
Repository repository = selectedNodes.get(0).getObject();
if (repository.isBare()) {
// simple confirm dialog
String title = UIText.RemoveCommand_ConfirmDeleteBareRepositoryTitle;
String message = NLS.bind(UIText.RemoveCommand_ConfirmDeleteBareRepositoryMessage, repository.getDirectory().getPath());
if (!MessageDialog.openConfirm(getShell(event), title, message))
return;
} else {
// confirm dialog with check box
// "delete also working directory"
DeleteRepositoryConfirmDialog dlg = new DeleteRepositoryConfirmDialog(getShell(event), repository, projectsToDelete);
if (dlg.open() != Window.OK)
return;
deleteWorkingDir = dlg.shouldDeleteWorkingDir();
removeProjects = dlg.shouldRemoveProjects();
}
}
} else {
if (!projectsToDelete.isEmpty()) {
final boolean[] confirmedCanceled = new boolean[] { false, false };
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
try {
confirmedCanceled[0] = confirmProjectDeletion(projectsToDelete, event);
} catch (OperationCanceledException e) {
confirmedCanceled[1] = true;
}
}
});
if (confirmedCanceled[1])
return;
removeProjects = confirmedCanceled[0];
}
}
final boolean deleteWorkDir = deleteWorkingDir;
final boolean removeProj = removeProjects;
Job job = new WorkspaceJob(UIText.RemoveCommand_RemoveRepositoriesJob) {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) {
monitor.setTaskName(UIText.RepositoriesView_DeleteRepoDeterminProjectsMessage);
if (removeProj) {
// confirmed deletion
deleteProjects(deleteWorkDir, projectsToDelete, monitor);
}
for (RepositoryNode node : selectedNodes) {
util.removeDir(node.getRepository().getDirectory());
}
if (delete) {
try {
deleteRepositoryContent(selectedNodes, deleteWorkDir);
} catch (IOException e) {
return Activator.createErrorStatus(e.getMessage(), e);
}
}
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
for (RepositoryNode node : selectedNodes) {
node.clear();
}
}
});
return Status.OK_STATUS;
}
@Override
public boolean belongsTo(Object family) {
if (JobFamilies.REPOSITORY_DELETE.equals(family))
return true;
else
return super.belongsTo(family);
}
};
if (service == null) {
job.schedule();
} else {
service.schedule(job);
}
}
Aggregations