Have icon for "reset" entry in reflog
[egit/eclipse.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / internal / reflog / ReflogItem.java
blob6229465f931b2fa17034e0c187accba29b140584
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;
24 /**
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) {
37 this.entry = entry;
38 this.input = input;
39 this.commitMessage = commitMessage;
42 @SuppressWarnings("unchecked")
43 @Override
44 public Object getAdapter(Class adapter) {
45 // TODO generify once EGit base version is Eclipse 4.5
46 if (adapter.isInstance(this)) {
47 return this;
48 } else if (Repository.class.equals(adapter)) {
49 return getRepository();
51 return null;
54 @Override
55 public ObjectId getOldId() {
56 return entry.getOldId();
59 @Override
60 public ObjectId getNewId() {
61 return entry.getNewId();
64 @Override
65 public PersonIdent getWho() {
66 return entry.getWho();
69 @Override
70 public String getComment() {
71 return entry.getComment();
74 @Override
75 public CheckoutEntry parseCheckout() {
76 return entry.parseCheckout();
79 /**
80 * @return the (short) commit message of the commit, if any, or {@code null}
81 * otherwise.
83 public String getCommitMessage() {
84 return commitMessage;
87 @Override
88 public boolean equals(Object obj) {
89 if (obj == this) {
90 return true;
92 if (!(obj instanceof ReflogItem)) {
93 return false;
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());
104 @Override
105 public int hashCode() {
106 return Objects.hash(input, commitMessage, getNewId(), getOldId(),
107 getWho(), getComment());
110 @Override
111 public Repository getRepository() {
112 return input.getRepository();
115 @Override
116 public ObjectId getObjectId() {
117 return getNewId();