1 /*******************************************************************************
2 * Copyright (C) 2017, Thomas Wolf <thomas.wolf@paranor.ch>
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
10 *******************************************************************************/
11 package org
.eclipse
.egit
.ui
.internal
.reflog
;
13 import java
.util
.Objects
;
15 import org
.eclipse
.core
.runtime
.IAdaptable
;
16 import org
.eclipse
.egit
.core
.internal
.IRepositoryObject
;
17 import org
.eclipse
.egit
.ui
.internal
.reflog
.ReflogViewContentProvider
.ReflogInput
;
18 import org
.eclipse
.jgit
.lib
.CheckoutEntry
;
19 import org
.eclipse
.jgit
.lib
.ObjectId
;
20 import org
.eclipse
.jgit
.lib
.PersonIdent
;
21 import org
.eclipse
.jgit
.lib
.ReflogEntry
;
22 import org
.eclipse
.jgit
.lib
.Repository
;
25 * A DTO for {@link ReflogEntry} to use as tree elements in the reflog view.
26 * Also adapts to the repository the item was loaded from.
28 public class ReflogItem
implements ReflogEntry
, IAdaptable
, IRepositoryObject
{
30 private final ReflogEntry entry
;
32 private final ReflogInput input
;
34 private final String commitMessage
;
36 ReflogItem(ReflogInput input
, ReflogEntry entry
, String commitMessage
) {
39 this.commitMessage
= commitMessage
;
42 @SuppressWarnings("unchecked")
44 public Object
getAdapter(Class adapter
) {
45 // TODO generify once EGit base version is Eclipse 4.5
46 if (adapter
.isInstance(this)) {
48 } else if (Repository
.class.equals(adapter
)) {
49 return getRepository();
55 public ObjectId
getOldId() {
56 return entry
.getOldId();
60 public ObjectId
getNewId() {
61 return entry
.getNewId();
65 public PersonIdent
getWho() {
66 return entry
.getWho();
70 public String
getComment() {
71 return entry
.getComment();
75 public CheckoutEntry
parseCheckout() {
76 return entry
.parseCheckout();
80 * @return the (short) commit message of the commit, if any, or {@code null}
83 public String
getCommitMessage() {
88 public boolean equals(Object obj
) {
92 if (!(obj
instanceof ReflogItem
)) {
95 ReflogItem other
= (ReflogItem
) obj
;
96 return input
== other
.input
97 && Objects
.equals(commitMessage
, other
.commitMessage
)
98 && Objects
.equals(getNewId(), other
.getNewId())
99 && Objects
.equals(getOldId(), other
.getOldId())
100 && Objects
.equals(getWho(), other
.getWho())
101 && Objects
.equals(getComment(), other
.getComment());
105 public int hashCode() {
106 return Objects
.hash(input
, commitMessage
, getNewId(), getOldId(),
107 getWho(), getComment());
111 public Repository
getRepository() {
112 return input
.getRepository();
116 public ObjectId
getObjectId() {