use of org.eclipse.egit.ui.internal.commit.RepositoryCommit in project egit by eclipse.
the class RebaseInteractiveView method createPartControl.
@Override
public void createPartControl(Composite parent) {
GridLayoutFactory.fillDefaults().applyTo(parent);
final FormToolkit toolkit = new FormToolkit(parent.getDisplay());
parent.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
toolkit.dispose();
}
});
form = createForm(parent, toolkit);
createCommandToolBar(form, toolkit);
planTreeViewer = createPlanTreeViewer(form.getBody(), toolkit);
planLayout = new PlanLayout();
planTreeViewer.getTree().getParent().setLayout(planLayout);
createColumns(planLayout);
createStepActionToolBar(toolkit);
createPopupMenu(planTreeViewer);
setupListeners();
createLocalDragandDrop();
planTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
PlanElement element = (PlanElement) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (element == null)
return;
RepositoryCommit commit = loadCommit(element.getCommit());
if (commit != null)
CommitEditor.openQuiet(commit);
}
private RepositoryCommit loadCommit(AbbreviatedObjectId abbreviatedObjectId) {
if (abbreviatedObjectId != null) {
try (RevWalk walk = new RevWalk(RebaseInteractiveView.this.currentRepository)) {
Collection<ObjectId> resolved = walk.getObjectReader().resolve(abbreviatedObjectId);
if (resolved.size() == 1) {
RevCommit commit = walk.parseCommit(resolved.iterator().next());
return new RepositoryCommit(RebaseInteractiveView.this.currentRepository, commit);
}
} catch (IOException e) {
return null;
}
}
return null;
}
});
prefListener = new IPreferenceChangeListener() {
@Override
public void preferenceChange(PreferenceChangeEvent event) {
if (!RepositoryUtil.PREFS_DIRECTORIES_REL.equals(event.getKey())) {
return;
}
final Repository repo = currentRepository;
if (repo == null)
return;
if (Activator.getDefault().getRepositoryUtil().contains(repo))
return;
// Unselect repository as it has been removed
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
currentRepository = null;
showRepository(null);
}
});
}
};
InstanceScope.INSTANCE.getNode(org.eclipse.egit.core.Activator.getPluginId()).addPreferenceChangeListener(prefListener);
uiPrefsListener = new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
String property = event.getProperty();
if (UIPreferences.DATE_FORMAT.equals(property) || UIPreferences.DATE_FORMAT_CHOICE.equals(property) || UIPreferences.RESOURCEHISTORY_SHOW_RELATIVE_DATE.equals(property)) {
refresh();
}
}
};
Activator.getDefault().getPreferenceStore().addPropertyChangeListener(uiPrefsListener);
IActionBars actionBars = getViewSite().getActionBars();
IToolBarManager toolbar = actionBars.getToolBarManager();
listenOnRepositoryViewSelection = RebaseInteractivePreferences.isReactOnSelection();
// link with selection
Action linkSelectionAction = new BooleanPrefAction((IPersistentPreferenceStore) Activator.getDefault().getPreferenceStore(), UIPreferences.REBASE_INTERACTIVE_SYNC_SELECTION, UIText.InteractiveRebaseView_LinkSelection) {
@Override
public void apply(boolean value) {
listenOnRepositoryViewSelection = value;
}
};
linkSelectionAction.setImageDescriptor(UIIcons.ELCL16_SYNCED);
toolbar.add(linkSelectionAction);
switchRepositoriesAction = new RepositoryToolbarAction(false, () -> currentRepository, repo -> setInput(new StructuredSelection(repo)));
toolbar.add(switchRepositoriesAction);
UIUtils.notifySelectionChangedWithCurrentSelection(selectionChangedListener, getSite());
getSite().setSelectionProvider(new RepositorySelectionProvider(planTreeViewer, () -> currentRepository));
}
use of org.eclipse.egit.ui.internal.commit.RepositoryCommit in project egit by eclipse.
the class RefUpdateElement method getCommits.
private RepositoryCommit[] getCommits(Ref end) {
try (final RevWalk walk = new RevWalk(reader)) {
walk.setRetainBody(true);
walk.markStart(walk.parseCommit(update.getNewObjectId()));
walk.markUninteresting(walk.parseCommit(end.getObjectId()));
List<RepositoryCommit> commits = new ArrayList<>();
for (RevCommit commit : walk) commits.add(new RepositoryCommit(repo, commit));
return commits.toArray(new RepositoryCommit[commits.size()]);
} catch (IOException e) {
// $NON-NLS-1$
Activator.logError("Error parsing commits from push result", e);
return new RepositoryCommit[0];
}
}
use of org.eclipse.egit.ui.internal.commit.RepositoryCommit in project egit by eclipse.
the class GitProjectPropertyPage method createHeadLink.
private void createHeadLink(final Repository repository, Composite composite) throws IOException {
final ObjectId objectId = repository.resolve(repository.getFullBranch());
if (objectId == null) {
Text headLabel = createLabeledReadOnlyText(composite, UIText.GitProjectPropertyPage_LabelId);
if (repository.getAllRefs().size() == 0)
headLabel.setText(UIText.GitProjectPropertyPage_ValueEmptyRepository);
else
headLabel.setText(UIText.GitProjectPropertyPage_ValueUnbornBranch);
} else {
Hyperlink headLink = createHeadHyperLink(composite, UIText.GitProjectPropertyPage_LabelId);
headLink.setText(objectId.name());
headLink.setUnderlined(true);
headLink.setFont(JFaceResources.getDialogFont());
headLink.setForeground(JFaceColors.getHyperlinkText(headLink.getDisplay()));
headLink.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
RepositoryCommit commit = getCommit(repository, objectId);
if (commit != null)
CommitEditor.openQuiet(commit);
}
});
}
}
use of org.eclipse.egit.ui.internal.commit.RepositoryCommit in project egit by eclipse.
the class CommitSearchDialogTest method openCommitTabOnSearchDialog.
@Test
public void openCommitTabOnSearchDialog() throws Exception {
bot.menu("Search").menu("Search...").click();
SWTBotShell shell = bot.shell("Search");
if (!shell.isActive()) {
shell.activate();
}
TestUtil.processUIEvents();
shell.bot().tabItem("Git Search").activate();
shell.bot().comboBox().setText(commit.name());
SWTBotButton search = shell.bot().button("Search");
assertTrue(search.isEnabled());
search.click();
TestUtil.waitForJobs(500, 5000);
TestUtil.joinJobs(InternalSearchUI.FAMILY_SEARCH);
bot.viewById(NewSearchUI.SEARCH_VIEW_ID).show();
TestUtil.processUIEvents();
final SWTBotTreeItem[] repos = bot.activeView().bot().tree().getAllItems();
assertEquals(1, repos.length);
Object repoData = UIThreadRunnable.syncExec(new Result<Object>() {
@Override
public Object run() {
return repos[0].widget.getData();
}
});
assertTrue(repoData instanceof RepositoryMatch);
assertEquals(repository.getDirectory(), ((RepositoryMatch) repoData).getRepository().getDirectory());
final SWTBotTreeItem[] commits = TestUtil.expandAndWait(repos[0]).getItems();
assertEquals(1, commits.length);
Object commitData = UIThreadRunnable.syncExec(new Result<Object>() {
@Override
public Object run() {
return commits[0].widget.getData();
}
});
assertTrue(commitData instanceof RepositoryCommit);
assertEquals(commit, ((RepositoryCommit) commitData).getRevCommit());
}
use of org.eclipse.egit.ui.internal.commit.RepositoryCommit in project egit by eclipse.
the class CommitEditorInputTest method testAdapters.
@Test
public void testAdapters() {
RepositoryCommit repoCommit = new RepositoryCommit(repository, commit);
CommitEditorInput input = new CommitEditorInput(repoCommit);
assertEquals(repoCommit, input.getAdapter(RepositoryCommit.class));
assertEquals(repository, input.getAdapter(Repository.class));
assertEquals(commit, input.getAdapter(RevCommit.class));
}
Aggregations