Search in sources :

Example 36 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project egit by eclipse.

the class CommitResultLabelProvider method getStyledText.

/**
 * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object)
 */
@Override
public StyledString getStyledText(Object element) {
    StyledString styled = new StyledString();
    if (element instanceof RepositoryCommit) {
        RepositoryCommit commit = (RepositoryCommit) element;
        RevCommit revCommit = commit.getRevCommit();
        styled.append(MessageFormat.format(UIText.CommitResultLabelProvider_SectionMessage, commit.abbreviate(), revCommit.getShortMessage()));
        PersonIdent author = revCommit.getAuthorIdent();
        if (author != null)
            styled.append(MessageFormat.format(UIText.CommitResultLabelProvider_SectionAuthor, author.getName(), dateFormatter.formatDate(author)), StyledString.QUALIFIER_STYLER);
        if (layout == AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT)
            styled.append(MessageFormat.format(UIText.CommitResultLabelProvider_SectionRepository, commit.getRepositoryName()), StyledString.DECORATIONS_STYLER);
    } else if (element instanceof RepositoryMatch) {
        RepositoryMatch repository = (RepositoryMatch) element;
        styled.append(repository.getLabel(repository));
        // $NON-NLS-1$
        styled.append(" - ", StyledString.QUALIFIER_STYLER);
        styled.append(repository.getRepository().getDirectory().getAbsolutePath(), StyledString.QUALIFIER_STYLER);
        styled.append(// $NON-NLS-1$
        MessageFormat.format(// $NON-NLS-1$
        " ({0})", Integer.valueOf(repository.getMatchCount())), StyledString.COUNTER_STYLER);
    }
    return styled;
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) StyledString(org.eclipse.jface.viewers.StyledString) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 37 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project egit by eclipse.

the class CommitEditorPage method createUserArea.

private Composite createUserArea(Composite parent, FormToolkit toolkit, PersonIdent person, boolean author) {
    Composite userArea = toolkit.createComposite(parent);
    GridLayoutFactory.fillDefaults().spacing(2, 2).numColumns(3).applyTo(userArea);
    Label userLabel = toolkit.createLabel(userArea, null);
    userLabel.setImage(getImage(author ? UIIcons.ELCL16_AUTHOR : UIIcons.ELCL16_COMMITTER));
    if (author)
        userLabel.setToolTipText(UIText.CommitEditorPage_TooltipAuthor);
    else
        userLabel.setToolTipText(UIText.CommitEditorPage_TooltipCommitter);
    boolean signedOff = isSignedOffBy(person);
    final Text userText = new Text(userArea, SWT.FLAT | SWT.READ_ONLY);
    addToFocusTracking(userText);
    setPerson(userText, person, author);
    toolkit.adapt(userText, false, false);
    userText.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.FALSE);
    IPropertyChangeListener uiPrefsListener = (event) -> {
        String property = event.getProperty();
        if (UIPreferences.DATE_FORMAT.equals(property) || UIPreferences.DATE_FORMAT_CHOICE.equals(property)) {
            setPerson(userText, person, author);
            userArea.layout();
        }
    };
    Activator.getDefault().getPreferenceStore().addPropertyChangeListener(uiPrefsListener);
    userText.addDisposeListener((e) -> {
        Activator.getDefault().getPreferenceStore().removePropertyChangeListener(uiPrefsListener);
    });
    GridDataFactory.fillDefaults().span(signedOff ? 1 : 2, 1).applyTo(userText);
    if (signedOff) {
        Label signedOffLabel = toolkit.createLabel(userArea, null);
        signedOffLabel.setImage(getImage(UIIcons.SIGNED_OFF));
        if (author)
            signedOffLabel.setToolTipText(UIText.CommitEditorPage_TooltipSignedOffByAuthor);
        else
            signedOffLabel.setToolTipText(UIText.CommitEditorPage_TooltipSignedOffByCommitter);
    }
    return userArea;
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) AdapterUtils(org.eclipse.egit.core.AdapterUtils) CLabel(org.eclipse.swt.custom.CLabel) DisposeEvent(org.eclipse.swt.events.DisposeEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) UIPreferences(org.eclipse.egit.ui.UIPreferences) StyledText(org.eclipse.swt.custom.StyledText) FileDiff(org.eclipse.egit.ui.internal.history.FileDiff) DisposeListener(org.eclipse.swt.events.DisposeListener) Hyperlink(org.eclipse.ui.forms.widgets.Hyperlink) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) Point(org.eclipse.swt.graphics.Point) RevWalk(org.eclipse.jgit.revwalk.RevWalk) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) Map(java.util.Map) PreferenceBasedDateFormatter(org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) IAdaptable(org.eclipse.core.runtime.IAdaptable) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) Text(org.eclipse.swt.widgets.Text) PlatformUI(org.eclipse.ui.PlatformUI) GitLabelProvider(org.eclipse.egit.ui.internal.GitLabelProvider) FormEditor(org.eclipse.ui.forms.editor.FormEditor) Status(org.eclipse.core.runtime.Status) Constants(org.eclipse.jgit.lib.Constants) GitDateFormatter(org.eclipse.jgit.util.GitDateFormatter) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) RevWalkUtils(org.eclipse.jgit.revwalk.RevWalkUtils) IManagedForm(org.eclipse.ui.forms.IManagedForm) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PersonIdent(org.eclipse.jgit.lib.PersonIdent) CommitFileDiffViewer(org.eclipse.egit.ui.internal.history.CommitFileDiffViewer) List(java.util.List) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) UIText(org.eclipse.egit.ui.internal.UIText) IFormColors(org.eclipse.ui.forms.IFormColors) Ref(org.eclipse.jgit.lib.Ref) SWT(org.eclipse.swt.SWT) UIIcons(org.eclipse.egit.ui.internal.UIIcons) Label(org.eclipse.swt.widgets.Label) FormPage(org.eclipse.ui.forms.editor.FormPage) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Activator(org.eclipse.egit.ui.Activator) Image(org.eclipse.swt.graphics.Image) HashMap(java.util.HashMap) JFaceResources(org.eclipse.jface.resource.JFaceResources) PlatformObject(org.eclipse.core.runtime.PlatformObject) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) IShowInSource(org.eclipse.ui.part.IShowInSource) ShowInContext(org.eclipse.ui.part.ShowInContext) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) Section(org.eclipse.ui.forms.widgets.Section) SpellcheckableMessageArea(org.eclipse.egit.ui.internal.dialogs.SpellcheckableMessageArea) Job(org.eclipse.core.runtime.jobs.Job) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) IOException(java.io.IOException) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ObjectId(org.eclipse.jgit.lib.ObjectId) AbstractHyperlink(org.eclipse.ui.forms.widgets.AbstractHyperlink) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) UIUtils(org.eclipse.egit.ui.UIUtils) NonNull(org.eclipse.jgit.annotations.NonNull) Platform(org.eclipse.core.runtime.Platform) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) Comparator(java.util.Comparator) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter) Collections(java.util.Collections) Repository(org.eclipse.jgit.lib.Repository) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) CLabel(org.eclipse.swt.custom.CLabel) Label(org.eclipse.swt.widgets.Label) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText)

Example 38 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project egit by eclipse.

the class CommitHelper method getHeadCommitInfo.

/**
 * @param repository
 * @return info related to the HEAD commit
 */
public static CommitInfo getHeadCommitInfo(Repository repository) {
    RevCommit headCommit = getHeadCommit(repository);
    if (headCommit == null)
        return null;
    String commitMessage = headCommit.getFullMessage().replaceAll("\n", // $NON-NLS-1$
    Text.DELIMITER);
    PersonIdent authorIdent = headCommit.getAuthorIdent();
    String author = authorIdent.getName() + " <" + authorIdent.getEmailAddress() + // $NON-NLS-1$ //$NON-NLS-2$
    ">";
    PersonIdent committerIdent = headCommit.getCommitterIdent();
    String committer = committerIdent.getName() + " <" + committerIdent.getEmailAddress() + // $NON-NLS-1$ //$NON-NLS-2$
    ">";
    return new CommitInfo(headCommit, author, committer, commitMessage);
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 39 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project egit by eclipse.

the class BlameInformationControl method setInput.

@Override
public void setInput(Object input) {
    if (input == null) {
        // Make sure we don't hold a reference to this when nothing is
        // shown, it can be big
        this.revision = null;
        if (showAnnotationsLink != null) {
            // parent...)
            if (!showAnnotationsLink.isDisposed())
                showAnnotationsLink.removeSelectionListener(showAnnotationsLinkSelectionAdapter);
            showAnnotationsLink = null;
            showAnnotationsLinkSelectionAdapter = null;
        }
        return;
    }
    this.revision = (BlameRevision) input;
    // Used for showing the diff hunk of this line instead of the full diff.
    if (rulerInfo != null)
        revisionRulerLineNumber = rulerInfo.getLineOfLastMouseButtonActivity();
    RevCommit commit = this.revision.getCommit();
    String linkText = MessageFormat.format(UIText.BlameInformationControl_Commit, commit.abbreviate(7).name());
    commitLabel.setText(linkText);
    PreferenceBasedDateFormatter dateFormatter = PreferenceBasedDateFormatter.create();
    PersonIdent author = commit.getAuthorIdent();
    if (author != null) {
        setControlVisible(authorLabel, true);
        authorLabel.setText(MessageFormat.format(UIText.BlameInformationControl_Author, author.getName(), author.getEmailAddress(), dateFormatter.formatDate(author)));
    } else
        setControlVisible(authorLabel, false);
    PersonIdent committer = commit.getCommitterIdent();
    setControlVisible(authorLabel, author != null);
    if (committer != null && !committer.equals(author)) {
        setControlVisible(committerLabel, true);
        committerLabel.setText(MessageFormat.format(UIText.BlameInformationControl_Committer, committer.getName(), committer.getEmailAddress(), dateFormatter.formatDate(committer)));
    } else
        setControlVisible(committerLabel, false);
    messageText.setText(commit.getFullMessage());
    createDiffs();
    displayArea.layout();
    scrolls.setMinSize(displayArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) PreferenceBasedDateFormatter(org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 40 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project egit by eclipse.

the class RepositoryCommit method getStyledText.

/**
 * @param object
 * @return styled text
 */
@Override
public StyledString getStyledText(Object object) {
    StyledString styled = new StyledString();
    styled.append(abbreviate());
    // $NON-NLS-1$
    styled.append(": ");
    styled.append(commit.getShortMessage());
    PersonIdent author = commit.getAuthorIdent();
    PersonIdent committer = commit.getCommitterIdent();
    if (author != null && committer != null) {
        PreferenceBasedDateFormatter formatter = PreferenceBasedDateFormatter.create();
        if (author.getName().equals(committer.getName())) {
            styled.append(MessageFormat.format(UIText.RepositoryCommit_AuthorDate, author.getName(), formatter.formatDate(author)), StyledString.QUALIFIER_STYLER);
        } else {
            styled.append(MessageFormat.format(UIText.RepositoryCommit_AuthorDateCommitter, author.getName(), formatter.formatDate(author), committer.getName()), StyledString.QUALIFIER_STYLER);
        }
    }
    return styled;
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) StyledString(org.eclipse.jface.viewers.StyledString) PreferenceBasedDateFormatter(org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter)

Aggregations

PersonIdent (org.eclipse.jgit.lib.PersonIdent)221 RevCommit (org.eclipse.jgit.revwalk.RevCommit)78 ObjectId (org.eclipse.jgit.lib.ObjectId)55 Test (org.junit.Test)55 Repository (org.eclipse.jgit.lib.Repository)48 IOException (java.io.IOException)41 CommitBuilder (org.eclipse.jgit.lib.CommitBuilder)41 RevWalk (org.eclipse.jgit.revwalk.RevWalk)38 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)31 Change (com.google.gerrit.entities.Change)28 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)26 Ref (org.eclipse.jgit.lib.Ref)26 Git (org.eclipse.jgit.api.Git)25 Account (com.google.gerrit.entities.Account)22 Instant (java.time.Instant)21 TestRepository (org.eclipse.jgit.junit.TestRepository)20 ArrayList (java.util.ArrayList)18 File (java.io.File)17 Date (java.util.Date)17 RefUpdate (org.eclipse.jgit.lib.RefUpdate)17