diff options
author | Andre Dietisheim | 2010-03-13 23:18:13 +0000 |
---|---|---|
committer | Andre Dietisheim | 2010-03-13 23:18:13 +0000 |
commit | a833d09493a342bfed5c4cee2083a6634392d1d7 (patch) | |
tree | b3eb658d23fff7c3776c631233848b7afd940d49 /plugins/org.eclipse.emf.cdo.ui.branch | |
parent | ce2d68a33938e65a5db13e3ab0e710188854ccd6 (diff) | |
download | cdo-a833d09493a342bfed5c4cee2083a6634392d1d7.tar.gz cdo-a833d09493a342bfed5c4cee2083a6634392d1d7.tar.xz cdo-a833d09493a342bfed5c4cee2083a6634392d1d7.zip |
[256624] [UI] Create a Commit History ViewPart
https://bugs.eclipse.org/bugs/show_bug.cgi?id=256624
refactored and fixed bugs (sub branch view translation)
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.ui.branch')
6 files changed, 86 insertions, 147 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/BranchViewPart.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/BranchViewPart.java index d76b033871..b6914e8400 100644 --- a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/BranchViewPart.java +++ b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/BranchViewPart.java @@ -27,6 +27,7 @@ import org.eclipse.net4j.connector.IConnector; import org.eclipse.net4j.tcp.TCPUtil; import org.eclipse.net4j.util.container.ContainerUtil; import org.eclipse.net4j.util.container.IManagedContainer; +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; import org.eclipse.net4j.util.om.OMPlatform; import org.eclipse.net4j.util.om.log.PrintLogHandler; import org.eclipse.net4j.util.om.trace.PrintTraceHandler; @@ -39,7 +40,6 @@ import org.eclipse.ui.IWorkbenchPartReference; import org.eclipse.ui.PartInitException; import org.eclipse.ui.part.ViewPart; import org.eclipse.zest.core.widgets.Graph; -import org.eclipse.zest.core.widgets.ZestStyles; import org.eclipse.zest.layouts.LayoutAlgorithm; import org.eclipse.zest.layouts.LayoutStyles; @@ -62,96 +62,10 @@ public class BranchViewPart extends ViewPart public void createPartControl(Composite parent) { Graph graph = new Graph(parent, SWT.NONE); - graph.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); + // graph.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); createTestTree(graph); - // RootNode rootNode = new RootNode(graph, SWT.NONE, new BranchRootFigure()); - // - // BranchPointNode branchNode1 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure("branch point 1"), 100); - // BranchPointNode branchNode1_1 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure("branch point 1-1"), - // 300); - // BranchPointNode branchNode1_1_1 = new BranchPointNode(graph, SWT.NONE, new - // BranchPointFigure("branch point 1-1-1"), - // 600); - // BranchPointNode branchNode1_1_1_1 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure( - // "branch point 1-1-1-1"), 1102); - // BranchPointNode branchNode1_1_1_1_1 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure( - // "branch point 1-1-1-1-1"), 1302); - // BranchPointNode branchNode1_1_1_2 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure( - // "branch point 1-1-1-2"), 1402); - // BranchPointNode branchNode1_1_1_2_1 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure( - // "branch point 1-1-1-2-1"), 1602); - // BranchPointNode branchNode1_1_2 = new BranchPointNode(graph, SWT.NONE, new - // BranchPointFigure("branch point 1-1-2"), - // 802); - // BranchPointNode branchNode1_1_2_1 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure( - // "branch point 1-1-2-1"), 902); - // - // BranchPointNode branchNode1_2 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure("branch point 1-2"), - // 500); - // BranchPointNode branchNode1_2_1 = new BranchPointNode(graph, SWT.NONE, new - // BranchPointFigure("branch point 1-2-1"), - // 800); - // BranchPointNode branchNode2 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure("branch point 2"), 301); - // BranchPointNode branchNode2_1 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure("branch point 2-1"), - // 401); - // BranchPointNode branchNode2_1_1 = new BranchPointNode(graph, SWT.NONE, new - // BranchPointFigure("branch point 2-1-1"), - // 600); - // BranchPointNode branchNode2_1_2 = new BranchPointNode(graph, SWT.NONE, new - // BranchPointFigure("branch point 2-1-2"), - // 1001); - // BranchPointNode branchNode2_1_2_1 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure( - // "branch point 2-1-2-1"), 1200); - // BranchPointNode branchNode2_1_1_1 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure( - // "branch point 2-1-1-1"), 900); - // BranchPointNode branchNode2_2 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure("branch point 2-2"), - // 700); - // BranchPointNode branchNode2_2_1 = new BranchPointNode(graph, SWT.NONE, new - // BranchPointFigure("branch point 2-2-1"), - // 1401); - // - // BranchPointNode branchNode3 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure("branch point 3"), 701); - // BranchPointNode branchNode3_1 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure("branch point 3-1"), - // 900); - // - // BranchPointNode branchNode4 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure("branch point 4"), - // 1004); - // BranchPointNode branchNode4_1 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure("branch point 4-1"), - // 1300); - // - // BranchPointNode branchNode5 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure("branch point 5"), - // 1400); - // BranchPointNode branchNode5_1 = new BranchPointNode(graph, SWT.NONE, new BranchPointFigure("branch point 5-1"), - // 1600); - // - // new SameBranchConnection(graph, SWT.NONE, rootNode, branchNode1); - // new NewBranchConnection(graph, SWT.NONE, branchNode1, branchNode1_1); - // new NewBranchConnection(graph, SWT.NONE, branchNode1_1, branchNode1_1_1); - // new NewBranchConnection(graph, SWT.NONE, branchNode1_1_1, branchNode1_1_1_1); - // new NewBranchConnection(graph, SWT.NONE, branchNode1_1_1_1, branchNode1_1_1_1_1); - // new SameBranchConnection(graph, SWT.NONE, branchNode1_1_1_1, branchNode1_1_1_2); - // new NewBranchConnection(graph, SWT.NONE, branchNode1_1_1_2, branchNode1_1_1_2_1); - // new SameBranchConnection(graph, SWT.NONE, branchNode1_1_1, branchNode1_1_2); - // new NewBranchConnection(graph, SWT.NONE, branchNode1_1_2, branchNode1_1_2_1); - // new SameBranchConnection(graph, SWT.NONE, branchNode1_1, branchNode1_2); - // new NewBranchConnection(graph, SWT.NONE, branchNode1_2, branchNode1_2_1); - // new SameBranchConnection(graph, SWT.NONE, branchNode1, branchNode2); - // new NewBranchConnection(graph, SWT.NONE, branchNode2, branchNode2_1); - // new SameBranchConnection(graph, SWT.NONE, branchNode2_1, branchNode2_2); - // new NewBranchConnection(graph, SWT.NONE, branchNode2_1, branchNode2_1_1); - // new NewBranchConnection(graph, SWT.NONE, branchNode2_1_1, branchNode2_1_1_1); - // new SameBranchConnection(graph, SWT.NONE, branchNode2_1_1, branchNode2_1_2); - // new NewBranchConnection(graph, SWT.NONE, branchNode2_1_2, branchNode2_1_2_1); - // new NewBranchConnection(graph, SWT.NONE, branchNode2_2, branchNode2_2_1); - // new SameBranchConnection(graph, SWT.NONE, branchNode2, branchNode3); - // new NewBranchConnection(graph, SWT.NONE, branchNode3, branchNode3_1); - // new SameBranchConnection(graph, SWT.NONE, branchNode3, branchNode4); - // new NewBranchConnection(graph, SWT.NONE, branchNode4, branchNode4_1); - // new SameBranchConnection(graph, SWT.NONE, branchNode4, branchNode5); - // new NewBranchConnection(graph, SWT.NONE, branchNode5, branchNode5_1); - LayoutAlgorithm layout = new BranchTreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING); graph.setLayoutAlgorithm(layout, true); } @@ -160,15 +74,7 @@ public class BranchViewPart extends ViewPart public void init(IViewSite site) throws PartInitException { super.init(site); - OMPlatform.INSTANCE.setDebugging(true); - OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE); - OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE); - init(); - cleanupOnPartClosed(site); - } - - private void cleanupOnPartClosed(IViewSite site) - { + initCDO(); site.getPage().addPartListener(new IPartListener2() { public void partVisible(IWorkbenchPartReference partRef) @@ -193,7 +99,7 @@ public class BranchViewPart extends ViewPart public void partClosed(IWorkbenchPartReference partRef) { - cleanup(); + cleanupCDO(); } public void partBroughtToTop(IWorkbenchPartReference partRef) @@ -204,7 +110,6 @@ public class BranchViewPart extends ViewPart { } }); - } @Override @@ -214,17 +119,6 @@ public class BranchViewPart extends ViewPart private void createTestTree(Graph graph) { - // // Open transaction - // CDOTransaction transaction = session.openTransaction(); - // - // // Get or create resource - // CDOResource resource = transaction.getOrCreateResource(RES_NAME); - - // Work with the resource and commit the transaction - // EObject object = CompanyFactory.eINSTANCE.createCompany(); - // resource.getContents().add(object); - // transaction.commit(); - CDOBranch mainBranch = session.getBranchManager().getMainBranch(); CDOBranch subBranch1 = mainBranch.createBranch("1"); CDOBranch subBranch1_1 = subBranch1.createBranch("1-1", subBranch1.getBase().getTimeStamp() + 30000000); @@ -252,29 +146,30 @@ public class BranchViewPart extends ViewPart } - private void init() + private void initCDO() { - // Prepare container + + OMPlatform.INSTANCE.setDebugging(true); + OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE); + OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE); + container = ContainerUtil.createContainer(); Net4jUtil.prepareContainer(container); // Register Net4j factories TCPUtil.prepareContainer(container); // Register TCP factories CDONet4jUtil.prepareContainer(container); // Register CDO factories - container.activate(); + LifecycleUtil.activate(container); - // Create connector connector = TCPUtil.getConnector(container, "localhost:2036"); //$NON-NLS-1$ - // Create configuration org.eclipse.emf.cdo.net4j.CDOSessionConfiguration configuration = CDONet4jUtil.createSessionConfiguration(); configuration.setConnector(connector); configuration.setRepositoryName("repo1"); //$NON-NLS-1$ - // Open session session = configuration.openSession(); session.getPackageRegistry().putEPackage(CompanyPackage.eINSTANCE); } - private void cleanup() + private void cleanupCDO() { // Cleanup session.close(); diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/geometry/GeometryUtils.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/geometry/GeometryUtils.java index cfc9bd677d..cdbfca19bd 100644 --- a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/geometry/GeometryUtils.java +++ b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/geometry/GeometryUtils.java @@ -109,4 +109,18 @@ public class GeometryUtils { return union(thisRectangle, thatRectangle.x, thatRectangle.y, thatRectangle.width, thatRectangle.height); } + + /** + * Gets the translation necessar to translate the source coordinate to the target coordinate. + * + * @param sourceCoordinate + * the source x + * @param targetCoordinate + * the target x + * @return the translation + */ + public static double getTranslation(double sourceCoordinate, double targetCoordinate) + { + return targetCoordinate - sourceCoordinate; + } } diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/item/BranchTreeUtils.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/item/BranchTreeUtils.java index 9df9fa460e..865178ed76 100644 --- a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/item/BranchTreeUtils.java +++ b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/item/BranchTreeUtils.java @@ -60,7 +60,9 @@ public class BranchTreeUtils } /** - * Centers the x coordinate of the given target node compared to the given source node + * Centers the x coordinate of the given target node compared to the given source node. If source node is + * <tt>null</tt>, the target node is translated to the right by the half of its own width (centered on its own + * location) * * @param targetNode * the target node @@ -68,11 +70,29 @@ public class BranchTreeUtils * the source node * @return the centered x */ - public static double getCenteredX(AbstractBranchPointNode targetNode, AbstractBranchPointNode sourceNode) + private static double getCenteredX(InternalNode targetInternalNode, InternalNode sourceInternalNode) { - InternalNode sourceInternalNode = getInternalNode(sourceNode); - return sourceInternalNode.getInternalX() - + (sourceInternalNode.getInternalWidth() - getInternalNode(targetNode).getInternalWidth()) / 2; + if (sourceInternalNode == null) + { + return targetInternalNode.getInternalX() - targetInternalNode.getInternalWidth() / 2; + } + else + { + return sourceInternalNode.getInternalX() + + (sourceInternalNode.getInternalWidth() - targetInternalNode.getInternalWidth()) / 2; + } + } + + /** + * Centers the x coordinate of the given target node. + * + * @param sourceNode + * the source node + * @return the centered x + */ + private static double getCenteredX(InternalNode sourceInternalNode) + { + return getCenteredX(sourceInternalNode, null); } /** @@ -132,16 +152,33 @@ public class BranchTreeUtils * * @param nodeToBeCentered * the node to be centered - * @param sourceNode + * @param sourcePositionNode * the source node * @param y * the y coordinate to apply */ - public static void centerHorizontally(AbstractBranchPointNode nodeToBeCentered, AbstractBranchPointNode sourceNode, - double y) + public static void centerHorizontally(AbstractBranchPointNode nodeToBeCentered, + AbstractBranchPointNode sourcePositionNode, double y) + { + + InternalNode internalNode = getInternalNode(nodeToBeCentered); + double x = getCenteredX(internalNode, getInternalNode(sourcePositionNode)); + internalNode.setInternalLocation(x, y); + } + + /** + * Centers the internal node (which displays the given branch tree node) horizontally. It gets shifted to the right by + * the half of its own width. + * + * @param nodeToBeCentered + * the node to be centered + * @param y + * the y coordinate to apply + */ + public static void centerHorizontally(AbstractBranchPointNode nodeToBeCentered, double y) { - double x = getCenteredX(nodeToBeCentered, sourceNode); InternalNode internalNode = getInternalNode(nodeToBeCentered); + double x = getCenteredX(internalNode); internalNode.setInternalLocation(x, y); } } diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/AbstractBranchViewLayoutStrategy.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/AbstractBranchViewLayoutStrategy.java index cfadd2244c..4a29906e3c 100644 --- a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/AbstractBranchViewLayoutStrategy.java +++ b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/AbstractBranchViewLayoutStrategy.java @@ -70,8 +70,7 @@ public abstract class AbstractBranchViewLayoutStrategy implements BranchViewLayo protected void setBaselineNodeLocation(AbstractBranchPointNode node) { double y = node.getTimeStamp(); - double x = 0; - BranchTreeUtils.setInternalLocation(node, x, y); + BranchTreeUtils.centerHorizontally(node, y); } /** diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchView.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchView.java index 5720d7a1ff..33caabd2a6 100644 --- a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchView.java +++ b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/BranchView.java @@ -104,8 +104,8 @@ public class BranchView if (node instanceof BranchPointNode) { // add a branch to this node - BranchPointNode branchpointNode = (BranchPointNode)node; - addBranchView(branchpointNode.getNextOnNewBranch(), branchpointNode); + BranchPointNode branchPointNode = (BranchPointNode)node; + addBranchView(branchPointNode.getNextOnNewBranch(), branchPointNode); } } } diff --git a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/VerticallyDistributedSubBranches.java b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/VerticallyDistributedSubBranches.java index 48280db335..5af064f1b2 100644 --- a/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/VerticallyDistributedSubBranches.java +++ b/plugins/org.eclipse.emf.cdo.ui.branch/src/org/eclipse/emf/cdo/ui/internal/branch/layout/VerticallyDistributedSubBranches.java @@ -32,16 +32,13 @@ public class VerticallyDistributedSubBranches extends AbstractBranchViewLayoutSt private static final VerticallyDistributedSubBranches RIGHT = new VerticallyDistributedSubBranches() { @Override - protected DisplayIndependentDimension getTranslationToBranchPoint(BranchView subBranch, + protected DisplayIndependentDimension getTranslationToBranchPoint(BranchView subBranchView, BranchPointNode branchPointNode) { InternalNode branchPointInternalNode = BranchTreeUtils.getInternalNode(branchPointNode); return new DisplayIndependentDimension( // - // translate branch completely to visible area - Math.abs(subBranch.getBounds().x) - // add branch point position and its width - + branchPointInternalNode.getInternalX() + branchPointInternalNode.getInternalWidth() // - // add padding + GeometryUtils.getTranslation(subBranchView.getBounds().x, branchPointInternalNode.getInternalX()) // + + branchPointInternalNode.getInternalWidth() // + getBranchPadding(), 0); } @@ -50,7 +47,7 @@ public class VerticallyDistributedSubBranches extends AbstractBranchViewLayoutSt { DisplayIndependentRectangle latterBranchBounds = latterBranch.getBounds(); return new DisplayIndependentDimension(// - latterBranchBounds.x + latterBranchBounds.width, 0); + latterBranchBounds.x + latterBranchBounds.width + getBranchPadding(), 0); } }; @@ -62,13 +59,10 @@ public class VerticallyDistributedSubBranches extends AbstractBranchViewLayoutSt { InternalNode branchPointInternalNode = BranchTreeUtils.getInternalNode(branchPointNode); DisplayIndependentRectangle subBranchBounds = subBranch.getBounds(); - return new DisplayIndependentDimension(-( // - // translate completely to invisible area - subBranchBounds.width + subBranchBounds.x - // add branch point position - + branchPointInternalNode.getInternalX() - // add branch padding - + getBranchPadding()), 0); + return new DisplayIndependentDimension( // + GeometryUtils.getTranslation(subBranchBounds.x, branchPointInternalNode.getInternalX()) // + - subBranchBounds.width // + - getBranchPadding(), 0); } @Override @@ -100,7 +94,7 @@ public class VerticallyDistributedSubBranches extends AbstractBranchViewLayoutSt { return RIGHT; } - + return LEFT; } @@ -117,7 +111,7 @@ public class VerticallyDistributedSubBranches extends AbstractBranchViewLayoutSt * @param branchView * the branch view */ - public void setSubBranchLocation(BranchView subBranchView, BranchView branchView, BranchPointNode branchPointNode) + public void setSubBranchLocation(BranchView branchView, BranchView subBranchView, BranchPointNode branchPointNode) { // translate branch off the branchPointNode (to the right or to the left) DisplayIndependentDimension translation = getTranslationToBranchPoint(subBranchView, branchPointNode); @@ -161,7 +155,7 @@ public class VerticallyDistributedSubBranches extends AbstractBranchViewLayoutSt } /** - * Returns the branch padding that shall be applied betweend branches. + * Returns the horizontal padding between branch views. * * @return the branch padding */ |