Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-10-11 18:10:34 +0000
committerEike Stepper2012-10-11 18:10:34 +0000
commit22de2b34be15b6ede8f72c193b05d85cb5c5d645 (patch)
tree21e9a6290bf0ebdd794081e9d209088927d06e51
parentdb098f036a3a82c782956bf1836c4db149d7707f (diff)
downloadcdo-22de2b34be15b6ede8f72c193b05d85cb5c5d645.tar.gz
cdo-22de2b34be15b6ede8f72c193b05d85cb5c5d645.tar.xz
cdo-22de2b34be15b6ede8f72c193b05d85cb5c5d645.zip
[391503] [UI] Render a CDOCommitInfo graph into the history page
https://bugs.eclipse.org/bugs/show_bug.cgi?id=391503
-rw-r--r--.gitignore2
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/commit/CDOCommitHistory.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/commit/CDOCommitInfoManager.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/commit/CDOCommitHistoryImpl.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/commit/CDOCommitInfoImpl.java22
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/commit/CDOCommitInfoManagerImpl.java38
-rw-r--r--plugins/org.eclipse.emf.cdo.ui.team/src/org/eclipse/emf/cdo/ui/internal/team/history/CDOHistoryPage.java57
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/Net.pptxbin0 -> 53299 bytes
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Branch.java230
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Commit.java82
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Net.java376
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/NetRenderer.java285
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Segment.java167
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/SegmentList.java106
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Track.java61
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/CommitHistoryComposite.java51
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ManagedLabelProvider.java4
18 files changed, 1464 insertions, 29 deletions
diff --git a/.gitignore b/.gitignore
index f28ec7b09f..bc200c8188 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
bin/
state/
*~
+~*.docx
+~*.pptx
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/commit/CDOCommitHistory.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/commit/CDOCommitHistory.java
index 274c10a60e..2236cd6d3c 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/commit/CDOCommitHistory.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/commit/CDOCommitHistory.java
@@ -22,7 +22,7 @@ import org.eclipse.net4j.util.container.IContainer;
*/
public interface CDOCommitHistory extends IContainer<CDOCommitInfo>, CDOCommitInfoHandler
{
- public static final int DEFAULT_LOAD_COUNT = 25;
+ public static final int DEFAULT_LOAD_COUNT = 100;
public CDOCommitInfoManager getManager();
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/commit/CDOCommitInfoManager.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/commit/CDOCommitInfoManager.java
index 5f3f35101d..d109e30a55 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/commit/CDOCommitInfoManager.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/commit/CDOCommitInfoManager.java
@@ -30,11 +30,16 @@ public interface CDOCommitInfoManager extends CDOCommitInfoProvider,
*/
public CDOCommitInfo getCommitInfo(long timeStamp);
+ /**
+ * @since 4.2
+ */
+ public CDOCommitInfo getCommitInfo(CDOBranch branch, long startTime, boolean up);
+
public void getCommitInfos(CDOBranch branch, long startTime, long endTime, CDOCommitInfoHandler handler);
/**
* @since 4.0
*/
- public void getCommitInfos(CDOBranch branch, long startTime, String userID, String comment, int count,
+ public void getCommitInfos(CDOBranch branch, long startTime, String reserved1, String reserved2, int count,
CDOCommitInfoHandler handler);
}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/commit/CDOCommitHistoryImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/commit/CDOCommitHistoryImpl.java
index 6e8746b048..d93e81535f 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/commit/CDOCommitHistoryImpl.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/commit/CDOCommitHistoryImpl.java
@@ -29,8 +29,6 @@ import java.util.ListIterator;
*/
public class CDOCommitHistoryImpl extends Container<CDOCommitInfo> implements CDOCommitHistory
{
- public static final int DEFAULT_LOAD_COUNT = 25;
-
private final CDOCommitInfoManager manager;
private final CDOBranch branch;
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/commit/CDOCommitInfoImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/commit/CDOCommitInfoImpl.java
index b3c73bf8ac..7ba657a1e6 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/commit/CDOCommitInfoImpl.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/commit/CDOCommitInfoImpl.java
@@ -34,6 +34,8 @@ import java.util.Map;
*/
public class CDOCommitInfoImpl extends CDOBranchPointImpl implements CDOCommitInfo
{
+// private static final CDOCommitInfo[] NO_PARENTS = {};
+
private InternalCDOCommitInfoManager commitInfoManager;
private long previousTimeStamp;
@@ -44,6 +46,8 @@ public class CDOCommitInfoImpl extends CDOBranchPointImpl implements CDOCommitIn
private CDOCommitData commitData;
+// private transient CDOCommitInfo[] parents;
+
public CDOCommitInfoImpl(InternalCDOCommitInfoManager commitInfoManager, CDOBranch branch, long timeStamp,
long previousTimeStamp, String userID, String comment, CDOCommitData commitData)
{
@@ -61,6 +65,24 @@ public class CDOCommitInfoImpl extends CDOBranchPointImpl implements CDOCommitIn
return commitInfoManager;
}
+// public synchronized CDOCommitInfo[] getParents()
+// {
+// if (parents == null)
+// {
+// CDOCommitInfo previousCommitInfo = commitInfoManager.getCommitInfo(previousTimeStamp);
+// if (previousCommitInfo != null)
+// {
+// parents = new CDOCommitInfo[] { previousCommitInfo };
+// }
+// else
+// {
+// parents = NO_PARENTS;
+// }
+// }
+//
+// return parents;
+// }
+
public long getPreviousTimeStamp()
{
return previousTimeStamp;
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/commit/CDOCommitInfoManagerImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/commit/CDOCommitInfoManagerImpl.java
index 9b703b3d5a..70422f030c 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/commit/CDOCommitInfoManagerImpl.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/commit/CDOCommitInfoManagerImpl.java
@@ -119,6 +119,21 @@ public class CDOCommitInfoManagerImpl extends CDOCommitHistoryProviderImpl<CDOBr
public CDOCommitInfo getCommitInfo(long timeStamp)
{
checkActive();
+
+ if (cache != null)
+ {
+ synchronized (cacheLock)
+ {
+ for (CDOCommitInfo commitInfo : cache.keySet())
+ {
+ if (commitInfo.getTimeStamp() == timeStamp)
+ {
+ return commitInfo;
+ }
+ }
+ }
+ }
+
final CDOCommitInfo[] result = { null };
getCommitInfos(null, timeStamp, timeStamp, new CDOCommitInfoHandler()
{
@@ -131,6 +146,23 @@ public class CDOCommitInfoManagerImpl extends CDOCommitHistoryProviderImpl<CDOBr
return result[0];
}
+ public CDOCommitInfo getCommitInfo(CDOBranch branch, long startTime, boolean up)
+ {
+ checkActive();
+ int count = up ? 1 : -1;
+
+ final CDOCommitInfo[] result = { null };
+ getCommitInfos(branch, startTime, null, null, count, new CDOCommitInfoHandler()
+ {
+ public void handleCommitInfo(CDOCommitInfo commitInfo)
+ {
+ result[0] = commitInfo;
+ }
+ });
+
+ return result[0];
+ }
+
public void getCommitInfos(CDOBranch branch, long startTime, long endTime, CDOCommitInfoHandler handler)
{
checkActive();
@@ -149,12 +181,12 @@ public class CDOCommitInfoManagerImpl extends CDOCommitHistoryProviderImpl<CDOBr
loader.loadCommitInfos(branch, startTime, endTime, handler);
}
- public void getCommitInfos(CDOBranch branch, long startTime, String userID, String comment, int count,
+ public void getCommitInfos(CDOBranch branch, long startTime, String reserved1, String reserved2, int count,
CDOCommitInfoHandler handler)
{
- if (userID != null || comment != null)
+ if (reserved1 != null || reserved2 != null)
{
- throw new IllegalArgumentException("The parameters userID and comment are not supported");
+ throw new IllegalArgumentException("The parameters reserved1 and reserved2 are not supported");
}
long endTime = CDOCommitInfoUtil.encodeCount(count);
diff --git a/plugins/org.eclipse.emf.cdo.ui.team/src/org/eclipse/emf/cdo/ui/internal/team/history/CDOHistoryPage.java b/plugins/org.eclipse.emf.cdo.ui.team/src/org/eclipse/emf/cdo/ui/internal/team/history/CDOHistoryPage.java
index 061fe085af..4073804ade 100644
--- a/plugins/org.eclipse.emf.cdo.ui.team/src/org/eclipse/emf/cdo/ui/internal/team/history/CDOHistoryPage.java
+++ b/plugins/org.eclipse.emf.cdo.ui.team/src/org/eclipse/emf/cdo/ui/internal/team/history/CDOHistoryPage.java
@@ -10,14 +10,18 @@
*/
package org.eclipse.emf.cdo.ui.internal.team.history;
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
+import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
+import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler;
+import org.eclipse.emf.cdo.common.commit.CDOCommitInfoManager;
+import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.session.CDOSession;
-import org.eclipse.emf.cdo.spi.common.branch.CDOBranchUtil;
-import org.eclipse.emf.cdo.ui.compare.CDOCompareEditorInput;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.ui.widgets.CommitHistoryComposite;
import org.eclipse.emf.cdo.ui.widgets.CommitHistoryComposite.Input;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+
import org.eclipse.core.runtime.Platform;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
@@ -60,15 +64,54 @@ public class CDOHistoryPage extends HistoryPage
@Override
protected void doubleClicked(CDOCommitInfo commitInfo)
{
- long previousTimeStamp = commitInfo.getPreviousTimeStamp();
- if (previousTimeStamp != CDOBranchPoint.UNSPECIFIED_DATE)
+ CDOTransaction transaction = null;
+
+ try
{
CDOSession session = input.getSession();
- CDOBranchPoint previous = CDOBranchUtil.normalizeBranchPoint(commitInfo.getBranch(), previousTimeStamp);
- CDOCompareEditorInput.openCompareDialog(session, commitInfo, previous);
+ CDOBranch branch = commitInfo.getBranch();
+
+ final long[] lastCommitTime = { 0 };
+ CDOCommitInfoManager commitInfoManager = session.getCommitInfoManager();
+ commitInfoManager.getCommitInfos(branch, Long.MAX_VALUE, null, null, -1, new CDOCommitInfoHandler()
+ {
+ public void handleCommitInfo(CDOCommitInfo commitInfo)
+ {
+ lastCommitTime[0] = commitInfo.getTimeStamp();
+ }
+ });
+
+ long timeStamp = commitInfo.getTimeStamp();
+ if (timeStamp != lastCommitTime[0])
+ {
+ branch = branch
+ .createBranch("branch-" + (timeStamp - session.getRepositoryInfo().getCreationTime()) / 1000);
+ }
+
+ transaction = session.openTransaction(branch);
+ CDOResourceFolder folder = transaction.getOrCreateResourceFolder("/folder");
+ folder.addResource("folder-" + folder.getNodes().size() + 1);
+ transaction.commit();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
}
+ finally
+ {
+ LifecycleUtil.deactivate(transaction);
+ }
+
+ // long previousTimeStamp = commitInfo.getPreviousTimeStamp();
+ // if (previousTimeStamp != CDOBranchPoint.UNSPECIFIED_DATE)
+ // {
+ // CDOSession session = input.getSession();
+ // CDOBranchPoint previous = CDOBranchUtil.normalizeBranchPoint(commitInfo.getBranch(), previousTimeStamp);
+ // CDOCompareEditorInput.openCompareDialog(session, commitInfo, previous);
+ // }
}
};
+
getSite().setSelectionProvider(commitHistoryComposite.getTableViewer());
}
diff --git a/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF
index b14754900b..23d8a1d1a7 100644
--- a/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF
@@ -66,6 +66,7 @@ Export-Package: org.eclipse.emf.cdo.internal.ui;version="4.2.0";
org.eclipse.emf.cdo.tests.ui,
org.eclipse.emf.cdo.dawn.ui,
org.eclipse.emf.cdo.explorer",
+ org.eclipse.emf.cdo.internal.ui.history;version="4.2.0";x-internal:=true,
org.eclipse.emf.cdo.internal.ui.messages;version="4.2.0";x-friends:="org.eclipse.emf.cdo.tests.ui",
org.eclipse.emf.cdo.internal.ui.perspectives;version="4.2.0";
x-friends:="org.eclipse.emf.cdo.ui.defs,
diff --git a/plugins/org.eclipse.emf.cdo.ui/Net.pptx b/plugins/org.eclipse.emf.cdo.ui/Net.pptx
new file mode 100644
index 0000000000..1534f5af94
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/Net.pptx
Binary files differ
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Branch.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Branch.java
new file mode 100644
index 0000000000..5389468e20
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Branch.java
@@ -0,0 +1,230 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.internal.ui.history;
+
+import org.eclipse.emf.cdo.common.branch.CDOBranch;
+import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
+import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
+import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
+import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler;
+import org.eclipse.emf.cdo.common.commit.CDOCommitInfoManager;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.common.revision.CDORevisionManager;
+
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * @author Eike Stepper
+ */
+public class Branch extends SegmentList
+{
+ private final CDOBranch cdoBranch;
+
+ private final Color color;
+
+ private Branch baseCommitBranch;
+
+ private long baseCommitTime;
+
+ private long firstCommitTime;
+
+ private long lastCommitTime;
+
+ public Branch(Net net, CDOBranch cdoBranch)
+ {
+ super(net);
+ this.cdoBranch = cdoBranch;
+ color = net.getNextColor();
+
+ CDOID objectID = net.getObjectID();
+ if (objectID != null)
+ {
+ CDORevisionManager revisionManager = net.getSession().getRevisionManager();
+
+ CDOBranchPoint lastPoint = cdoBranch.getHead();
+ CDORevision lastRevision = revisionManager.getRevision(objectID, lastPoint, CDORevision.UNCHUNKED,
+ CDORevision.DEPTH_NONE, true);
+
+ if (lastRevision != null && lastRevision.getBranch() == cdoBranch)
+ {
+ CDOBranchVersion firstVersion = cdoBranch.getVersion(CDOBranchVersion.FIRST_VERSION);
+ CDORevision firstRevision = revisionManager.getRevisionByVersion(objectID, firstVersion, CDORevision.UNCHUNKED,
+ true);
+
+ firstCommitTime = firstRevision.getTimeStamp();
+ lastCommitTime = lastRevision.getTimeStamp();
+ }
+ }
+ else
+ {
+ firstCommitTime = getCommitTime(1L, true);
+ lastCommitTime = getCommitTime(Long.MAX_VALUE, false);
+ }
+
+ System.out.println("New: " + this);
+ }
+
+ public final CDOBranch getCDOBranch()
+ {
+ return cdoBranch;
+ }
+
+ public final Color getColor()
+ {
+ return color;
+ }
+
+ @Deprecated
+ public final Branch getBaseBranch()
+ {
+ CDOBranchPoint cdoBase = cdoBranch.getBase();
+ CDOBranch cdoBaseBranch = cdoBase.getBranch();
+ if (cdoBaseBranch == null)
+ {
+ return null;
+ }
+
+ Net net = getNet();
+ return net.getBranch(cdoBaseBranch);
+ }
+
+ @Deprecated
+ public final long getBaseTime()
+ {
+ return cdoBranch.getBase().getTimeStamp();
+ }
+
+ public final Branch getBaseCommitBranch()
+ {
+ determineBaseCommitIfNeeded();
+ return baseCommitBranch;
+ }
+
+ public final long getBaseCommitTime()
+ {
+ determineBaseCommitIfNeeded();
+ return baseCommitTime;
+ }
+
+ public final long getFirstCommitTime()
+ {
+ return firstCommitTime;
+ }
+
+ public final long getLastCommitTime()
+ {
+ return lastCommitTime;
+ }
+
+ public final Segment getSegmentFrom(Segment[] segments)
+ {
+ for (int i = 0; i < segments.length; i++)
+ {
+ Segment segment = segments[i];
+ if (segment != null && segment.getBranch() == this)
+ {
+ return segment;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Branch[" + cdoBranch.getPathName() + "]";
+ }
+
+ void adjustCommitTimes(long time)
+ {
+ if (firstCommitTime == 0)
+ {
+ firstCommitTime = time;
+ lastCommitTime = time;
+ }
+ else if (time < firstCommitTime)
+ {
+ throw new RuntimeException("Must not happen because the constructor initializes firstCommitTime");
+ // firstCommitTime = time;
+ }
+ else if (time > lastCommitTime)
+ {
+ lastCommitTime = time;
+ }
+ }
+
+ private long getCommitTime(long startTime, boolean up)
+ {
+ CDOCommitInfoManager commitInfoManager = getNet().getSession().getCommitInfoManager();
+ CDOCommitInfo commitInfo = commitInfoManager.getCommitInfo(cdoBranch, startTime, up);
+ if (commitInfo != null)
+ {
+ return commitInfo.getTimeStamp();
+ }
+
+ return 0;
+ }
+
+ private void determineBaseCommitIfNeeded()
+ {
+ if (cdoBranch.isMainBranch())
+ {
+ return;
+ }
+
+ CDOBranchPoint base = cdoBranch.getBase();
+ while (baseCommitTime == 0)
+ {
+ CDOBranch baseBranch = base.getBranch();
+ long baseTime = base.getTimeStamp();
+
+ final Net net = getNet();
+ CDOCommitInfoManager commitInfoManager = net.getSession().getCommitInfoManager();
+ commitInfoManager.getCommitInfos(baseBranch, baseTime, null, null, -1, new CDOCommitInfoHandler()
+ {
+ public void handleCommitInfo(CDOCommitInfo commitInfo)
+ {
+ CDOBranch cdoBaseBranch = commitInfo.getBranch();
+ baseCommitBranch = net.getBranch(cdoBaseBranch);
+ baseCommitTime = commitInfo.getTimeStamp();
+ }
+ });
+
+ base = baseBranch.getBase();
+ }
+ }
+
+ @Override
+ protected Segment getNextSegment(Segment segment)
+ {
+ return segment.getNextInBranch();
+ }
+
+ @Override
+ protected void setNextSegment(Segment segment, Segment nextSegment)
+ {
+ segment.setNextInBranch(nextSegment);
+ }
+
+ @Override
+ protected Segment getPreviousSegment(Segment segment)
+ {
+ return segment.getPreviousInBranch();
+ }
+
+ @Override
+ protected void setPreviousSegment(Segment segment, Segment previousSegment)
+ {
+ segment.setPreviousInBranch(previousSegment);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Commit.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Commit.java
new file mode 100644
index 0000000000..8584d76305
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Commit.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.internal.ui.history;
+
+import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
+
+/**
+ * @author Eike Stepper
+ */
+public class Commit
+{
+ private final CDOCommitInfo commitInfo;
+
+ private final Segment segment;
+
+ private Segment[] rowSegments;
+
+ public Commit(CDOCommitInfo commitInfo, Segment segment)
+ {
+ this.segment = segment;
+ this.commitInfo = commitInfo;
+ System.out.println("New: " + this);
+ }
+
+ public final CDOCommitInfo getCommitInfo()
+ {
+ return commitInfo;
+ }
+
+ public final Branch getBranch()
+ {
+ return segment.getBranch();
+ }
+
+ public final long getTime()
+ {
+ return commitInfo.getTimeStamp();
+ }
+
+ public final Segment getSegment()
+ {
+ return segment;
+ }
+
+ public final Segment[] getRowSegments()
+ {
+ // if (rowSegments == null) TODO re-enable cache and add cache invalidation (timestamp of last addition)
+ {
+ long time = getTime();
+ Net net = segment.getNet();
+ rowSegments = net.getRowSegments(time);
+ }
+
+ return rowSegments;
+ }
+
+ public final boolean isFirstInBranch()
+ {
+ long firstTime = segment.getBranch().getFirstCommitTime();
+ return getTime() == firstTime;
+ }
+
+ public final boolean isLastInBranch()
+ {
+ long lastTime = segment.getBranch().getLastCommitTime();
+ return getTime() == lastTime;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Commit[" + getTime() + " --> " + segment + "]";
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Net.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Net.java
new file mode 100644
index 0000000000..a566a2a972
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Net.java
@@ -0,0 +1,376 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.internal.ui.history;
+
+import org.eclipse.emf.cdo.common.branch.CDOBranch;
+import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.session.CDOSession;
+
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+/**
+ * @author Eike Stepper
+ */
+public class Net
+{
+ private static final Segment[] NO_SEGMENTS = {};
+
+ private final CDOSession session;
+
+ private final CDOID objectID;
+
+ private final ResourceManager resourceManager;
+
+ private Color[] colors;
+
+ private int nextColorIndex;
+
+ private Track[] tracks = {};
+
+ private Map<CDOBranch, Branch> branches = new HashMap<CDOBranch, Branch>();
+
+ private Map<CDOCommitInfo, Commit> commits = new WeakHashMap<CDOCommitInfo, Commit>();
+
+ private Commit firstCommit;
+
+ private Commit lastCommit;
+
+ public Net(CDOSession session, CDOID objectID, ResourceManager resourceManager)
+ {
+ this.session = session;
+ this.objectID = objectID;
+ this.resourceManager = resourceManager;
+ System.out.println("New: " + this);
+ }
+
+ public final CDOSession getSession()
+ {
+ return session;
+ }
+
+ public final CDOID getObjectID()
+ {
+ return objectID;
+ }
+
+ public final Color getNextColor()
+ {
+ if (colors == null)
+ {
+ final RGB[] rgbs = new RGB[] { new RGB(133, 166, 214), new RGB(221, 205, 93), new RGB(199, 134, 57),
+ new RGB(131, 150, 98), new RGB(197, 123, 127), new RGB(139, 136, 140), new RGB(48, 135, 144),
+ new RGB(190, 93, 66), new RGB(143, 163, 54), new RGB(180, 148, 74), new RGB(101, 101, 217),
+ new RGB(72, 153, 119), new RGB(23, 101, 160), new RGB(132, 164, 118), new RGB(255, 230, 59),
+ new RGB(136, 176, 70), new RGB(255, 138, 1), new RGB(123, 187, 95), new RGB(233, 88, 98),
+ new RGB(93, 158, 254), new RGB(175, 215, 0), new RGB(140, 134, 142), new RGB(232, 168, 21),
+ new RGB(0, 172, 191), new RGB(251, 58, 4), new RGB(63, 64, 255), new RGB(27, 194, 130), new RGB(0, 104, 183) };
+
+ colors = new Color[rgbs.length];
+ for (int i = 0; i < rgbs.length; i++)
+ {
+ RGB rgb = rgbs[i];
+ colors[i] = resourceManager.createColor(rgb);
+ }
+ }
+
+ if (nextColorIndex >= colors.length)
+ {
+ nextColorIndex = 0;
+ }
+
+ return colors[nextColorIndex++];
+ }
+
+ public final Track[] getTracks()
+ {
+ return tracks;
+ }
+
+ public final Segment[] getRowSegments(long time)
+ {
+ Segment[] segments = NO_SEGMENTS;
+ for (int i = tracks.length - 1; i >= 0; --i)
+ {
+ Track track = tracks[i];
+ Segment segment = track.getSegment(time, true);
+
+ if (segments == NO_SEGMENTS)
+ {
+ if (segment == null)
+ {
+ continue;
+ }
+
+ segments = new Segment[i + 1];
+ }
+
+ segments[i] = segment;
+ }
+
+ return segments;
+ }
+
+ public final Commit getFirstCommit()
+ {
+ return firstCommit;
+ }
+
+ public final Commit getLastCommit()
+ {
+ return lastCommit;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Net[" + session + ", " + objectID + "]";
+ }
+
+ public final Branch getBranch(CDOBranch cdoBranch)
+ {
+ Branch branch = branches.get(cdoBranch);
+ if (branch == null)
+ {
+ branch = new Branch(this, cdoBranch);
+ branches.put(cdoBranch, branch);
+ }
+
+ return branch;
+ }
+
+ public final Commit getCommit(CDOCommitInfo commitInfo)
+ {
+ Commit commit = commits.get(commitInfo);
+ if (commit == null)
+ {
+ commit = createCommit(commitInfo);
+ commits.put(commitInfo, commit);
+ }
+
+ return commit;
+ }
+
+ private Commit createCommit(CDOCommitInfo commitInfo)
+ {
+ System.out.println("Enter: Commit[" + commitInfo.getTimeStamp() + "]");
+
+ Segment segment = getSegment(commitInfo);
+ if (segment == null)
+ {
+ throw new IllegalStateException("No segment");
+ }
+
+ Commit commit = new Commit(commitInfo, segment);
+
+ if (firstCommit == null)
+ {
+ firstCommit = commit;
+ lastCommit = commit;
+ }
+ else
+ {
+ long time = commit.getTime();
+ if (time < firstCommit.getTime())
+ {
+ firstCommit = commit;
+ }
+ else if (time > lastCommit.getTime())
+ {
+ lastCommit = commit;
+ }
+ }
+
+ return commit;
+ }
+
+ private final Segment getSegment(CDOCommitInfo commitInfo)
+ {
+ CDOBranch cdoBranch = commitInfo.getBranch();
+ long time = commitInfo.getTimeStamp();
+
+ Branch branch = getBranch(cdoBranch);
+ Segment segment = branch.getSegment(time, false);
+
+ if (segment == null)
+ {
+ // This must be a new commit after the last or before the first
+ boolean afterLast = isAfterLast(time); // false means beforeFirst
+ segment = getOrCreateSegment(branch, time, afterLast);
+ }
+ else
+ {
+ System.out.println("Match: " + segment);
+ }
+
+ branch.adjustCommitTimes(time);
+ segment.adjustCommitTimes(time);
+ return segment;
+ }
+
+ private Segment getOrCreateSegment(Branch branch, long time, boolean afterLast)
+ {
+ if (!afterLast && firstCommit != null)
+ {
+ Segment[] rowSegments = firstCommit.getRowSegments();
+ for (int i = 0; i < rowSegments.length; i++)
+ {
+ Segment rowSegment = rowSegments[i];
+ if (rowSegment != null && !rowSegment.isComplete())
+ {
+ Branch rowBranch = rowSegment.getBranch();
+ boolean complete = rowBranch.getBaseCommitTime() == time;
+
+ System.out.println("Extend: " + rowSegment + " --> " + time + (complete ? " COMPLETE" : ""));
+ rowSegment.adjustVisualTime(time, complete);
+ }
+ }
+ }
+
+ Segment bestSegment = null;
+ for (int i = 0; i < tracks.length; i++)
+ {
+ Track track = tracks[i];
+
+ if (afterLast)
+ {
+ Segment lastSegment = track.getLastSegment();
+ if (lastSegment != null)
+ {
+ if (lastSegment.getBranch() == branch)
+ {
+ // If the last segment of this track has the same branch, then just extend it
+ return lastSegment;
+ }
+
+ if (branch.getBaseCommitBranch() == lastSegment.getBranch())
+ {
+ // Don't block the tracks with the base commit
+ continue;
+ }
+
+ if (lastSegment.getLastCommitTime() == lastCommit.getTime())
+ {
+ // Don't block the track of the last commit
+ continue;
+ }
+
+ if (lastSegment.getLastCommitTime() < branch.getBaseCommitTime())
+ {
+ // If the last segment of this track ends before the branch's last commit there's enough room for a new
+ // segment in this track
+ if (bestSegment == null || lastSegment.getLastCommitTime() < bestSegment.getLastCommitTime())
+ {
+ bestSegment = lastSegment;
+ }
+ }
+ }
+ }
+ else
+ {
+ Segment firstSegment = track.getFirstSegment();
+ if (firstSegment != null)
+ {
+ Branch firstBranch = firstSegment.getBranch();
+ if (firstBranch == branch)
+ {
+ // If the first segment of this track has the same branch, then just extend it
+ return firstSegment;
+ }
+
+ if (!firstSegment.isComplete())
+ {
+ // Don't block the tracks with incomplete segments
+ continue;
+ }
+
+ if (firstBranch.getBaseCommitBranch() == branch)
+ {
+ // Don't block the tracks with the base commit
+ continue;
+ }
+
+ // if (firstSegment.getFirstVisualTime() == firstCommit.getTime())
+ // {
+ // // Don't block the track of the first commit
+ // continue;
+ // }
+
+ if (firstSegment.getFirstVisualTime() > branch.getFirstCommitTime())
+ {
+ // If the first segment of this track starts after the branch's first commit there's enough room for a new
+ // segment in this track
+ if (bestSegment == null || firstSegment.getFirstVisualTime() > bestSegment.getFirstVisualTime())
+ {
+ bestSegment = firstSegment;
+ }
+ }
+ }
+ }
+ }
+
+ Track track;
+ if (bestSegment != null)
+ {
+ track = bestSegment.getTrack();
+ }
+ else
+ {
+ track = createTrack();
+ }
+
+ Segment segment = new Segment(track, branch);
+ track.addSegment(segment, afterLast);
+ branch.addSegment(segment, afterLast);
+ return segment;
+ }
+
+ private Track createTrack()
+ {
+ int length = tracks.length;
+ Track[] newArray = new Track[length + 1];
+ if (length != 0)
+ {
+ System.arraycopy(tracks, 0, newArray, 0, length);
+ }
+
+ Track track = new Track(this, length);
+ newArray[length] = track;
+ tracks = newArray;
+ return track;
+ }
+
+ private boolean isAfterLast(long time)
+ {
+ if (lastCommit == null)
+ {
+ return true;
+ }
+
+ if (time > lastCommit.getTime())
+ {
+ return true;
+ }
+
+ if (time < firstCommit.getTime())
+ {
+ return false;
+ }
+
+ throw new IllegalArgumentException("New commits must not be added between the first and last commits");
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/NetRenderer.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/NetRenderer.java
new file mode 100644
index 0000000000..e8cc3bbca1
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/NetRenderer.java
@@ -0,0 +1,285 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.internal.ui.history;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.ui.widgets.CommitHistoryComposite.Input;
+import org.eclipse.emf.cdo.ui.widgets.CommitHistoryComposite.LabelProvider;
+
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTException;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.TableItem;
+
+/**
+ * @author Eike Stepper
+ */
+public class NetRenderer implements Listener
+{
+ private static final int TRACK_OFFSET = 4;
+
+ private static final int TRACK_WIDTH = 14;
+
+ private static final int LINE_WIDTH = 2;
+
+ private static final int UNKNOWN = -1;
+
+ private final Color colorDotFill;
+
+ private final Color colorDotOutline;
+
+ private Net net;
+
+ private GC gc;
+
+ private boolean antiAliasing = true;
+
+ private int dotSize = UNKNOWN;
+
+ private int dotSizeHalf;
+
+ private int textHeight = UNKNOWN;
+
+ private int cellHeight = UNKNOWN;
+
+ private int cellHeightHalf;
+
+ private int cellX;
+
+ private int cellY;
+
+ private Color cellForeground;
+
+ private Color cellBackground;
+
+ // private TableViewer tableViewer;
+
+ private LabelProvider labelProvider;
+
+ // private CDOCommitHistory history;
+
+ public NetRenderer(TableViewer tableViewer)
+ {
+ // this.tableViewer = tableViewer;
+ labelProvider = (LabelProvider)tableViewer.getLabelProvider();
+
+ ResourceManager resourceManager = labelProvider.getResourceManager();
+ colorDotFill = resourceManager.createColor(new RGB(220, 220, 220));
+ colorDotOutline = resourceManager.createColor(new RGB(110, 110, 110));
+ }
+
+ public void setInput(Input input)
+ {
+ CDOSession session = input.getSession();
+ CDOObject object = input.getObject();
+ CDOID objectID = object == null ? null : object.cdoID();
+
+ // history = (CDOCommitHistory)tableViewer.getInput();
+
+ ResourceManager resourceManager = labelProvider.getResourceManager();
+ net = new Net(session, objectID, resourceManager);
+ }
+
+ public void handleEvent(Event event)
+ {
+ try
+ {
+ gc = event.gc;
+
+ if (antiAliasing)
+ {
+ try
+ {
+ gc.setAntialias(SWT.ON);
+ }
+ catch (SWTException ex)
+ {
+ antiAliasing = false;
+ }
+ }
+
+ if (textHeight == UNKNOWN)
+ {
+ textHeight = gc.stringExtent("/").y; //$NON-NLS-1$
+ cellHeight = event.height;
+ cellHeightHalf = cellHeight / 2;
+
+ dotSize = (int)(Math.min(cellHeight, TRACK_WIDTH) * 0.5f);
+ dotSize += dotSize & 1;
+ dotSizeHalf = dotSize / 2;
+ }
+
+ cellX = event.x;
+ cellY = event.y;
+ cellForeground = gc.getForeground();
+ cellBackground = gc.getBackground();
+
+ CDOCommitInfo commitInfo = (CDOCommitInfo)((TableItem)event.item).getData();
+ drawCell(commitInfo, event.index);
+ }
+ catch (Throwable ex)
+ {
+ ex.printStackTrace(); // TODO Log properly
+ }
+ }
+
+ private void drawCell(CDOCommitInfo commitInfo, int columnIndex)
+ {
+ int textX = TRACK_OFFSET;
+ if (columnIndex == 1)
+ {
+ Commit commit = net.getCommit(commitInfo);
+ Segment commitSegment = commit.getSegment();
+ long commitTime = commit.getTime();
+
+ Segment[] segments = commit.getRowSegments();
+ for (int i = 0; i < segments.length; i++)
+ {
+ Segment segment = segments[i];
+ if (segment != null)
+ {
+ Branch branch = segment.getBranch();
+ Color color = branch.getColor();
+
+ int trackCenter = getTrackCenter(i);
+ if (segment != commitSegment)
+ {
+ if (commitTime == segment.getFirstVisualTime() && segment.isComplete())
+ {
+ Track commitTrack = commitSegment.getTrack();
+ int commitTrackPosition = commitTrack.getPosition();
+ int commitTrackCenter = getTrackCenter(commitTrackPosition);
+ int positionDelta = Math.abs(i - commitTrackPosition);
+
+ int x2 = commitTrackCenter;
+ if (i < commitTrackPosition)
+ {
+ // Horizontal line to left
+ x2 -= (positionDelta - 1) * TRACK_WIDTH + 7;
+ drawLine(color, commitTrackCenter, cellHeightHalf, x2, cellHeightHalf, LINE_WIDTH);
+
+ // Diagonal line to upper left
+ drawLine(color, x2, cellHeightHalf, getTrackCenter(i), 0, LINE_WIDTH);
+ }
+ else
+ {
+ // Horizontal line to right
+ x2 += (positionDelta - 1) * TRACK_WIDTH + 7;
+ drawLine(color, commitTrackCenter, cellHeightHalf, x2, cellHeightHalf, LINE_WIDTH);
+
+ // Diagonal line to upper right
+ drawLine(color, x2, cellHeightHalf, getTrackCenter(i), 0, LINE_WIDTH);
+ }
+ }
+ else
+ {
+ // Full vertical line
+ drawLine(color, trackCenter, 0, trackCenter, cellHeight, LINE_WIDTH);
+ }
+ }
+ }
+
+ Color color = commitSegment.getBranch().getColor();
+ int position = commitSegment.getTrack().getPosition();
+ int trackCenter = getTrackCenter(position);
+
+ if (commitTime < commitSegment.getLastCommitTime())
+ {
+ // Half vertical line to top
+ drawLine(color, trackCenter, 0, trackCenter, cellHeightHalf, LINE_WIDTH);
+ }
+
+ if (commitTime > commitSegment.getFirstVisualTime() || !commitSegment.isComplete())
+ {
+ // Half vertical line to bottom
+ drawLine(color, trackCenter, cellHeightHalf, trackCenter, cellHeight, LINE_WIDTH);
+ }
+
+ int dotX = trackCenter - dotSizeHalf - 1;
+ int dotY = cellHeightHalf - dotSizeHalf;
+ drawCommitDot(dotX, dotY, dotSize, dotSize);
+ }
+
+ textX += getTrackX(segments.length) + TRACK_WIDTH;
+ }
+ else
+ {
+ Image image = labelProvider.getColumnImage(commitInfo, columnIndex);
+ if (image != null)
+ {
+ Rectangle bounds = image.getBounds();
+ gc.drawImage(image, bounds.x, bounds.y, bounds.width, bounds.height, //
+ cellX + textX, cellY + 1, bounds.width, bounds.height);
+
+ textX += bounds.width + TRACK_OFFSET;
+ }
+ }
+
+ String text = labelProvider.getColumnText(commitInfo, columnIndex);
+ drawText(text, textX, cellHeightHalf);
+ }
+
+ private void drawLine(final Color color, final int x1, final int y1, final int x2, final int y2, final int width)
+ {
+ gc.setForeground(color);
+ gc.setLineWidth(width);
+ gc.drawLine(cellX + x1, cellY + y1, cellX + x2, cellY + y2);
+ }
+
+ private void drawDot(final Color outline, final Color fill, final int x, final int y, final int w, final int h)
+ {
+ int dotX = cellX + x + 2;
+ int dotY = cellY + y + 1;
+ int dotW = w - 2;
+ int dotH = h - 2;
+ gc.setBackground(fill);
+ gc.fillOval(dotX, dotY, dotW, dotH);
+ gc.setForeground(outline);
+ gc.setLineWidth(2);
+ gc.drawOval(dotX, dotY, dotW, dotH);
+ }
+
+ private void drawCommitDot(final int x, final int y, final int w, final int h)
+ {
+ drawDot(colorDotOutline, colorDotFill, x, y, w, h);
+ }
+
+ private void drawText(final String msg, final int x, final int y)
+ {
+ final Point textsz = gc.textExtent(msg);
+ final int texty = (y * 2 - textsz.y) / 2;
+ gc.setForeground(cellForeground);
+ gc.setBackground(cellBackground);
+ gc.drawString(msg, cellX + x, cellY + texty, true);
+ }
+
+ private int getTrackX(int position)
+ {
+ return TRACK_OFFSET + TRACK_WIDTH * position;
+ }
+
+ private int getTrackCenter(int position)
+ {
+ return getTrackX(position) + TRACK_WIDTH / 2;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Segment.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Segment.java
new file mode 100644
index 0000000000..8f867ae418
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Segment.java
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.internal.ui.history;
+
+/**
+ * @author Eike Stepper
+ */
+public class Segment
+{
+ private final Track track;
+
+ private final Branch branch;
+
+ private boolean complete;
+
+ private long firstVisualTime;
+
+ private long firstCommitTime;
+
+ private long lastCommitTime;
+
+ private Segment previousInTrack;
+
+ private Segment nextInTrack;
+
+ private Segment previousInBranch;
+
+ private Segment nextInBranch;
+
+ public Segment(Track track, Branch branch)
+ {
+ this.track = track;
+ this.branch = branch;
+ System.out.println("New: " + this);
+ }
+
+ public final Net getNet()
+ {
+ return track.getNet();
+ }
+
+ public final Track getTrack()
+ {
+ return track;
+ }
+
+ public final Branch getBranch()
+ {
+ return branch;
+ }
+
+ public final boolean isComplete()
+ {
+ return complete;
+ }
+
+ public final long getFirstVisualTime()
+ {
+ return firstVisualTime;
+ }
+
+ public final long getFirstCommitTime()
+ {
+ return firstCommitTime;
+ }
+
+ public final long getLastCommitTime()
+ {
+ return lastCommitTime;
+ }
+
+ public final Segment getPreviousInTrack()
+ {
+ return previousInTrack;
+ }
+
+ public final Segment getNextInTrack()
+ {
+ return nextInTrack;
+ }
+
+ public final Segment getPreviousInBranch()
+ {
+ return previousInBranch;
+ }
+
+ public final Segment getNextInBranch()
+ {
+ return nextInBranch;
+ }
+
+ public final boolean containsCommitTime(long time)
+ {
+ return time >= firstCommitTime && time <= lastCommitTime;
+ }
+
+ public final boolean containsVisualTime(long time)
+ {
+ return time >= getFirstVisualTime() && time <= lastCommitTime;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Segment[" + branch + " --> " + track + "]";
+ }
+
+ void adjustVisualTime(long time, boolean complete)
+ {
+ if (firstVisualTime == 0 || time < firstVisualTime)
+ {
+ firstVisualTime = time;
+ }
+
+ this.complete |= complete;
+ }
+
+ void adjustCommitTimes(long time)
+ {
+ if (firstCommitTime == 0)
+ {
+ firstVisualTime = time;
+ firstCommitTime = time;
+ lastCommitTime = time;
+ }
+ else if (time < firstCommitTime)
+ {
+ firstCommitTime = time;
+ if (time < firstVisualTime)
+ {
+ firstVisualTime = time;
+ }
+ }
+ else if (time > lastCommitTime)
+ {
+ lastCommitTime = time;
+ }
+ }
+
+ void setPreviousInTrack(Segment previousInTrack)
+ {
+ this.previousInTrack = previousInTrack;
+ }
+
+ void setNextInTrack(Segment nextInTrack)
+ {
+ this.nextInTrack = nextInTrack;
+ }
+
+ void setPreviousInBranch(Segment previousInBranch)
+ {
+ this.previousInBranch = previousInBranch;
+ }
+
+ void setNextInBranch(Segment nextInBranch)
+ {
+ this.nextInBranch = nextInBranch;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/SegmentList.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/SegmentList.java
new file mode 100644
index 0000000000..a67d3aa186
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/SegmentList.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.internal.ui.history;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class SegmentList
+{
+ private final Net net;
+
+ private Segment firstSegment;
+
+ private Segment lastSegment;
+
+ public SegmentList(Net net)
+ {
+ this.net = net;
+ }
+
+ public final Net getNet()
+ {
+ return net;
+ }
+
+ public final Segment getFirstSegment()
+ {
+ return firstSegment;
+ }
+
+ public final Segment getLastSegment()
+ {
+ return lastSegment;
+ }
+
+ public final Segment getSegment(long time, boolean extendIfPossible)
+ {
+ Segment last = null;
+ Segment segment = lastSegment;
+ while (segment != null)
+ {
+ if (segment.containsVisualTime(time))
+ {
+ return segment;
+ }
+
+ last = segment;
+ segment = getPreviousSegment(segment);
+ }
+
+ if (extendIfPossible)
+ {
+ if (last != null && last.getLastCommitTime() >= time)
+ {
+ if (last.getBranch().getFirstCommitTime() <= time)
+ {
+ Segment previousInTrack = last.getPreviousInTrack();
+ if (previousInTrack == null || previousInTrack.getLastCommitTime() < time)
+ {
+ last.adjustCommitTimes(time);
+ return last;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ void addSegment(Segment segment, boolean afterLast)
+ {
+ if (lastSegment == null)
+ {
+ lastSegment = segment;
+ firstSegment = segment;
+ }
+ else if (afterLast)
+ {
+ setPreviousSegment(segment, lastSegment);
+ setNextSegment(lastSegment, segment);
+ lastSegment = segment;
+ }
+ else
+ {
+ setNextSegment(segment, firstSegment);
+ setPreviousSegment(firstSegment, segment);
+ firstSegment = segment;
+ }
+ }
+
+ protected abstract Segment getNextSegment(Segment segment);
+
+ protected abstract void setNextSegment(Segment segment, Segment nextSegment);
+
+ protected abstract Segment getPreviousSegment(Segment segment);
+
+ protected abstract void setPreviousSegment(Segment segment, Segment previousSegment);
+}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Track.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Track.java
new file mode 100644
index 0000000000..fb061c5cda
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/history/Track.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.internal.ui.history;
+
+/**
+ * @author Eike Stepper
+ */
+public class Track extends SegmentList
+{
+ private final int position;
+
+ public Track(Net net, int position)
+ {
+ super(net);
+ this.position = position;
+ System.out.println("New: " + this);
+ }
+
+ public int getPosition()
+ {
+ return position;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Track[" + position + "]";
+ }
+
+ @Override
+ protected Segment getNextSegment(Segment segment)
+ {
+ return segment.getNextInTrack();
+ }
+
+ @Override
+ protected void setNextSegment(Segment segment, Segment nextSegment)
+ {
+ segment.setNextInTrack(nextSegment);
+ }
+
+ @Override
+ protected Segment getPreviousSegment(Segment segment)
+ {
+ return segment.getPreviousInTrack();
+ }
+
+ @Override
+ protected void setPreviousSegment(Segment segment, Segment previousSegment)
+ {
+ segment.setPreviousInTrack(previousSegment);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/CommitHistoryComposite.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/CommitHistoryComposite.java
index 9977da988b..05fc097189 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/CommitHistoryComposite.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/CommitHistoryComposite.java
@@ -16,12 +16,13 @@ import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.commit.CDOCommitHistory;
import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
import org.eclipse.emf.cdo.common.commit.CDOCommitInfoManager;
-import org.eclipse.emf.cdo.common.util.CDOCommonUtil;
+import org.eclipse.emf.cdo.internal.ui.history.NetRenderer;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.ui.shared.SharedIcons;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.ui.StructuredContentProvider;
import org.eclipse.net4j.util.ui.TableLabelProvider;
@@ -37,6 +38,9 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Table;
/**
* @author Eike Stepper
@@ -50,6 +54,8 @@ public class CommitHistoryComposite extends Composite
private LabelProvider labelProvider;
+ private NetRenderer netRenderer;
+
private Input input;
public CommitHistoryComposite(Composite parent, int style)
@@ -75,11 +81,18 @@ public class CommitHistoryComposite extends Composite
labelProvider = new LabelProvider();
labelProvider.support(tableViewer);
- }
- public final CDOCommitHistory getHistory()
- {
- return history;
+ netRenderer = new NetRenderer(tableViewer);
+
+ Table table = tableViewer.getTable();
+ table.addListener(SWT.PaintItem, netRenderer);
+ table.addListener(SWT.EraseItem, new Listener()
+ {
+ public void handleEvent(Event event)
+ {
+ event.detail &= ~SWT.FOREGROUND;
+ }
+ });
}
public final TableViewer getTableViewer()
@@ -94,16 +107,25 @@ public class CommitHistoryComposite extends Composite
public final void setInput(Input input)
{
- this.input = input;
+ if (!ObjectUtil.equals(this.input, input))
+ {
+ this.input = input;
- CDOSession session = input.getSession();
- CDOBranch branch = input.getBranch();
+ CDOSession session = input.getSession();
+ CDOBranch branch = input.getBranch();
- labelProvider.setLocalUserID(session.getUserID());
- labelProvider.setInputBranch(branch);
+ labelProvider.setLocalUserID(session.getUserID());
+ labelProvider.setInputBranch(branch);
- setHistory(session, branch, input.getObject());
- tableViewer.setInput(history);
+ setHistory(session, branch, input.getObject());
+ netRenderer.setInput(input);
+ tableViewer.setInput(history);
+ }
+ }
+
+ public final CDOCommitHistory getHistory()
+ {
+ return history;
}
protected void setHistory(CDOSession session, CDOBranch branch, CDOObject object)
@@ -135,8 +157,10 @@ public class CommitHistoryComposite extends Composite
@Override
public void dispose()
{
+
input = null;
history = null;
+
super.dispose();
}
@@ -344,7 +368,8 @@ public class CommitHistoryComposite extends Composite
@Override
public String getText(CDOCommitInfo commitInfo)
{
- return CDOCommonUtil.formatTimeStamp(commitInfo.getTimeStamp());
+ // return CDOCommonUtil.formatTimeStamp(commitInfo.getTimeStamp());
+ return "" + commitInfo.getTimeStamp();
}
@Override
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ManagedLabelProvider.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ManagedLabelProvider.java
index 2c4d68292d..467b80cf78 100644
--- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ManagedLabelProvider.java
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/ManagedLabelProvider.java
@@ -40,13 +40,13 @@ public class ManagedLabelProvider extends LabelProvider
super.dispose();
}
- protected Object getResource(DeviceResourceDescriptor descriptor)
+ public Object getResource(DeviceResourceDescriptor descriptor)
{
ResourceManager resourceManager = getResourceManager();
return resourceManager.get(descriptor);
}
- protected final ResourceManager getResourceManager()
+ public final ResourceManager getResourceManager()
{
if (resourceManager == null)
{

Back to the top