use of org.eclipse.egit.ui.internal.commit.RepositoryCommit in project egit by eclipse.
the class MergeResultDialog method createDialogArea.
@Override
public Control createDialogArea(final Composite parent) {
final Composite composite = (Composite) super.createDialogArea(parent);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
composite.setLayout(gridLayout);
// result
Label resultLabel = new Label(composite, SWT.NONE);
resultLabel.setText(UIText.MergeResultDialog_result);
resultLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
Text resultText = new Text(composite, SWT.READ_ONLY);
MergeStatus status = mergeResult.getMergeStatus();
resultText.setText(status.toString());
resultText.setSelection(resultText.getCaretPosition());
resultText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
if (status == MergeStatus.FAILED) {
resultText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
StringBuilder paths = new StringBuilder();
Label pathsLabel = new Label(composite, SWT.NONE);
pathsLabel.setText(UIText.MergeResultDialog_failed);
pathsLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
Text pathsText = new Text(composite, SWT.READ_ONLY);
pathsText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
Set<Entry<String, MergeFailureReason>> failedPaths = mergeResult.getFailingPaths().entrySet();
int n = 0;
for (Map.Entry<String, MergeFailureReason> e : failedPaths) {
if (n > 0)
paths.append(Text.DELIMITER);
paths.append(e.getValue());
// $NON-NLS-1$
paths.append("\t");
paths.append(e.getKey());
n++;
if (n > 10 && failedPaths.size() > 15)
break;
}
if (n < failedPaths.size()) {
paths.append(Text.DELIMITER);
paths.append(MessageFormat.format(UIText.MergeResultDialog_nMore, Integer.valueOf(n - failedPaths.size())));
}
pathsText.setText(paths.toString());
}
if (status == MergeStatus.FAST_FORWARD || status == MergeStatus.FAST_FORWARD_SQUASHED || status == MergeStatus.MERGED) {
// new head
Label newHeadLabel = new Label(composite, SWT.NONE);
newHeadLabel.setText(UIText.MergeResultDialog_newHead);
newHeadLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
Text newHeadText = new Text(composite, SWT.READ_ONLY);
ObjectId newHead = mergeResult.getNewHead();
if (newHead != null)
newHeadText.setText(getCommitMessage(newHead) + SPACE + abbreviate(mergeResult.getNewHead(), true));
newHeadText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
}
// Merge Input
Label mergeInputLabel = new Label(composite, SWT.NONE);
mergeInputLabel.setText(UIText.MergeResultDialog_mergeInput);
GridDataFactory.fillDefaults().align(SWT.LEAD, SWT.CENTER).span(2, 1).applyTo(mergeInputLabel);
TableViewer viewer = new TableViewer(composite);
viewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void dispose() {
// empty
}
@Override
public void inputChanged(Viewer theViewer, Object oldInput, Object newInput) {
// empty
}
@Override
public Object[] getElements(Object inputElement) {
return getCommits(mergeResult.getMergedCommits());
}
});
final IStyledLabelProvider styleProvider = new IStyledLabelProvider() {
private final WorkbenchLabelProvider wrapped = new WorkbenchLabelProvider();
@Override
public void removeListener(ILabelProviderListener listener) {
// Empty
}
@Override
public boolean isLabelProperty(Object element, String property) {
return false;
}
@Override
public void dispose() {
wrapped.dispose();
}
@Override
public void addListener(ILabelProviderListener listener) {
// Empty
}
@Override
public StyledString getStyledText(Object element) {
// supported
if (element instanceof RepositoryCommit)
return ((RepositoryCommit) element).getStyledText(element);
return new StyledString(wrapped.getText(element));
}
@Override
public Image getImage(Object element) {
return wrapped.getImage(element);
}
};
viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(styleProvider));
applyDialogFont(composite);
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(viewer.getControl());
viewer.setInput(mergeResult);
new OpenAndLinkWithEditorHelper(viewer) {
@Override
protected void linkToEditor(ISelection selection) {
// Not supported
}
@Override
protected void open(ISelection selection, boolean activate) {
handleOpen(selection, OpenStrategy.activateOnOpen());
}
@Override
protected void activate(ISelection selection) {
handleOpen(selection, true);
}
private void handleOpen(ISelection selection, boolean activateOnOpen) {
if (selection instanceof IStructuredSelection)
for (Object element : ((IStructuredSelection) selection).toArray()) if (element instanceof RepositoryCommit)
CommitEditor.openQuiet((RepositoryCommit) element, activateOnOpen);
}
};
return composite;
}
use of org.eclipse.egit.ui.internal.commit.RepositoryCommit in project egit by eclipse.
the class ImportChangedProjectsCommand method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Repository repository = getRepository(event);
Set<File> changedFiles = new HashSet<>();
List<RevCommit> commits = getSelectedCommits(event);
for (RevCommit commit : commits) {
RepositoryCommit repoCommit = new RepositoryCommit(repository, commit);
changedFiles.addAll(determineChangedFilesOfCommit(repoCommit));
}
Set<File> dotProjectFiles = findDotProjectFiles(changedFiles, repository);
importProjects(dotProjectFiles);
return null;
}
use of org.eclipse.egit.ui.internal.commit.RepositoryCommit in project egit by eclipse.
the class OpenInCommitViewerHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Repository repository = getRepository(event);
List<RevCommit> commits = getSelectedCommits(event);
for (RevCommit commit : commits) {
try {
CommitEditor.open(new RepositoryCommit(repository, commit));
} catch (PartInitException e) {
// $NON-NLS-1$
Activator.showError("Error opening commit viewer", e);
}
}
return null;
}
use of org.eclipse.egit.ui.internal.commit.RepositoryCommit in project egit by eclipse.
the class RewordHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Repository repository = getRepository(event);
RevCommit commit = getSelectedCommit(event);
try {
if (!CommitUtil.isCommitInCurrentBranch(commit, repository)) {
MessageDialog.openError(HandlerUtil.getActiveShellChecked(event), UIText.RewordHandler_Error_Title, UIText.RewordHandler_CommitNotOnCurrentBranch);
return null;
}
} catch (IOException e) {
throw new ExecutionException(UIText.RewordHandler_ErrorCheckingIfCommitIsOnCurrentBranch, e);
}
final IStructuredSelection selected = new StructuredSelection(new RepositoryCommit(repository, commit));
CommonUtils.runCommand(org.eclipse.egit.ui.internal.commit.command.RewordHandler.ID, selected);
return null;
}
use of org.eclipse.egit.ui.internal.commit.RepositoryCommit in project egit by eclipse.
the class ReflogView method createPartControl.
@Override
public void createPartControl(Composite parent) {
dateFormatter = PreferenceBasedDateFormatter.create();
GridLayoutFactory.fillDefaults().applyTo(parent);
toolkit = new FormToolkit(parent.getDisplay());
parent.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
toolkit.dispose();
}
});
form = toolkit.createForm(parent);
Image repoImage = UIIcons.REPOSITORY.createImage();
UIUtils.hookDisposal(form, repoImage);
Image commitImage = UIIcons.CHANGESET.createImage();
UIUtils.hookDisposal(form, commitImage);
form.setImage(repoImage);
form.setText(UIText.StagingView_NoSelectionTitle);
GridDataFactory.fillDefaults().grab(true, true).applyTo(form);
toolkit.decorateFormHeading(form);
GridLayoutFactory.fillDefaults().applyTo(form.getBody());
Composite tableComposite = toolkit.createComposite(form.getBody());
tableComposite.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(tableComposite);
final TreeColumnLayout layout = new TreeColumnLayout();
FilteredTree filteredTree = new FilteredTree(tableComposite, SWT.NONE | SWT.BORDER | SWT.FULL_SELECTION, new PatternFilter(), true) {
@Override
protected void createControl(Composite composite, int treeStyle) {
super.createControl(composite, treeStyle);
treeComposite.setLayout(layout);
}
};
toolkit.adapt(filteredTree);
refLogTableTreeViewer = filteredTree.getViewer();
refLogTableTreeViewer.getTree().setLinesVisible(true);
refLogTableTreeViewer.getTree().setHeaderVisible(true);
refLogTableTreeViewer.setContentProvider(new ReflogViewContentProvider());
ColumnViewerToolTipSupport.enableFor(refLogTableTreeViewer);
TreeViewerColumn toColumn = createColumn(layout, UIText.ReflogView_CommitColumnHeader, 10, SWT.LEFT);
toColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ReflogEntry) {
final ReflogEntry entry = (ReflogEntry) element;
return entry.getNewId().abbreviate(7).name();
}
return null;
}
@Override
public String getToolTipText(Object element) {
if (element instanceof ReflogEntry) {
final ReflogEntry entry = (ReflogEntry) element;
return entry.getNewId().name();
}
return null;
}
@Override
public Image getImage(Object element) {
if (element instanceof ReflogEntry) {
return commitImage;
}
return null;
}
});
TreeViewerColumn commitMessageColumn = createColumn(layout, UIText.ReflogView_CommitMessageColumnHeader, 40, SWT.LEFT);
commitMessageColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ReflogEntry) {
final ReflogEntry entry = (ReflogEntry) element;
RevCommit c = getCommit(entry);
// $NON-NLS-1$
return c == null ? "" : c.getShortMessage();
} else if (element instanceof IWorkbenchAdapter) {
return ((IWorkbenchAdapter) element).getLabel(element);
}
return null;
}
private RevCommit getCommit(final ReflogEntry entry) {
try (RevWalk walk = new RevWalk(getRepository())) {
walk.setRetainBody(true);
return walk.parseCommit(entry.getNewId());
} catch (IOException ignored) {
// ignore
return null;
}
}
});
TreeViewerColumn dateColumn = createColumn(layout, UIText.ReflogView_DateColumnHeader, 15, SWT.LEFT);
dateColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ReflogEntry) {
final ReflogEntry entry = (ReflogEntry) element;
final PersonIdent who = entry.getWho();
return dateFormatter.formatDate(who);
}
return null;
}
@Override
public Image getImage(Object element) {
return null;
}
});
TreeViewerColumn messageColumn = createColumn(layout, UIText.ReflogView_MessageColumnHeader, 40, SWT.LEFT);
messageColumn.setLabelProvider(new ColumnLabelProvider() {
private ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources());
@Override
public String getText(Object element) {
if (element instanceof ReflogEntry) {
final ReflogEntry entry = (ReflogEntry) element;
return entry.getComment();
}
return null;
}
@Override
public Image getImage(Object element) {
if (!(element instanceof ReflogEntry)) {
return null;
}
String comment = ((ReflogEntry) element).getComment();
if (// $NON-NLS-1$ //$NON-NLS-2$
comment.startsWith("commit:") || comment.startsWith("commit (initial):"))
return (Image) resourceManager.get(UIIcons.COMMIT);
if (// $NON-NLS-1$
comment.startsWith("commit (amend):"))
return (Image) resourceManager.get(UIIcons.AMEND_COMMIT);
if (// $NON-NLS-1$
comment.startsWith("pull"))
return (Image) resourceManager.get(UIIcons.PULL);
if (// $NON-NLS-1$
comment.startsWith("clone"))
return (Image) resourceManager.get(UIIcons.CLONEGIT);
if (// $NON-NLS-1$
comment.startsWith("rebase"))
return (Image) resourceManager.get(UIIcons.REBASE);
if (// $NON-NLS-1$
comment.startsWith("merge"))
return (Image) resourceManager.get(UIIcons.MERGE);
if (// $NON-NLS-1$
comment.startsWith("fetch"))
return (Image) resourceManager.get(UIIcons.FETCH);
if (// $NON-NLS-1$
comment.startsWith("branch"))
return (Image) resourceManager.get(UIIcons.CREATE_BRANCH);
if (// $NON-NLS-1$
comment.startsWith("checkout"))
return (Image) resourceManager.get(UIIcons.CHECKOUT);
return null;
}
@Override
public void dispose() {
resourceManager.dispose();
super.dispose();
}
});
new OpenAndLinkWithEditorHelper(refLogTableTreeViewer) {
@Override
protected void linkToEditor(ISelection selection) {
// Not supported
}
@Override
protected void open(ISelection sel, boolean activate) {
handleOpen(sel, OpenStrategy.activateOnOpen());
}
@Override
protected void activate(ISelection selection) {
handleOpen(selection, true);
}
private void handleOpen(ISelection selection, boolean activateOnOpen) {
if (selection instanceof IStructuredSelection)
if (selection.isEmpty())
return;
Repository repo = getRepository();
if (repo == null)
return;
try (RevWalk walk = new RevWalk(repo)) {
for (Object element : ((IStructuredSelection) selection).toArray()) {
ReflogEntry entry = (ReflogEntry) element;
ObjectId id = entry.getNewId();
if (id == null || id.equals(ObjectId.zeroId()))
id = entry.getOldId();
if (id != null && !id.equals(ObjectId.zeroId()))
CommitEditor.openQuiet(new RepositoryCommit(repo, walk.parseCommit(id)), activateOnOpen);
}
} catch (IOException e) {
Activator.logError(UIText.ReflogView_ErrorOnOpenCommit, e);
}
}
};
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)) {
dateFormatter = PreferenceBasedDateFormatter.create();
refLogTableTreeViewer.refresh();
}
}
};
Activator.getDefault().getPreferenceStore().addPropertyChangeListener(uiPrefsListener);
selectionChangedListener = new ISelectionListener() {
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (part instanceof IEditorPart) {
IEditorInput input = ((IEditorPart) part).getEditorInput();
if (input instanceof IFileEditorInput)
reactOnSelection(new StructuredSelection(((IFileEditorInput) input).getFile()));
} else
reactOnSelection(selection);
}
};
IWorkbenchPartSite site = getSite();
ISelectionService service = CommonUtils.getService(site, ISelectionService.class);
service.addPostSelectionListener(selectionChangedListener);
// Use current selection to populate reflog view
UIUtils.notifySelectionChangedWithCurrentSelection(selectionChangedListener, site);
site.setSelectionProvider(new RepositorySelectionProvider(refLogTableTreeViewer, () -> getRepository()));
addRefsChangedListener = Repository.getGlobalListenerList().addRefsChangedListener(this);
// Toolbar
IToolBarManager toolbar = getViewSite().getActionBars().getToolBarManager();
switchRepositoriesAction = new RepositoryToolbarAction(false, () -> getRepository(), repo -> reactOnSelection(new StructuredSelection(repo)));
toolbar.add(switchRepositoriesAction);
getViewSite().getActionBars().updateActionBars();
// register context menu
MenuManager menuManager = new MenuManager();
menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
Tree tree = refLogTableTreeViewer.getTree();
tree.setMenu(menuManager.createContextMenu(tree));
MenuManager resetManager = ResetMenu.createMenu(getSite());
menuManager.add(resetManager);
getSite().registerContextMenu(POPUP_MENU_ID, menuManager, refLogTableTreeViewer);
}
Aggregations