| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| com.bonevich.eclipse.cvsgrapher.editors.CvsGraphContextMenu |
|
|
| 1 | /* ==================================================================== |
|
| 2 | * The Apache Software License, Version 1.1 |
|
| 3 | * |
|
| 4 | * Copyright (c) 2000 The Apache Software Foundation. All rights |
|
| 5 | * reserved. |
|
| 6 | * |
|
| 7 | * Redistribution and use in source and binary forms, with or without |
|
| 8 | * modification, are permitted provided that the following conditions |
|
| 9 | * are met: |
|
| 10 | * |
|
| 11 | * 1. Redistributions of source code must retain the above copyright |
|
| 12 | * notice, this list of conditions and the following disclaimer. |
|
| 13 | * |
|
| 14 | * 2. Redistributions in binary form must reproduce the above copyright |
|
| 15 | * notice, this list of conditions and the following disclaimer in |
|
| 16 | * the documentation and/or other materials provided with the |
|
| 17 | * distribution. |
|
| 18 | * |
|
| 19 | * 3. The end-user documentation included with the redistribution, |
|
| 20 | * if any, must include the following acknowledgment: |
|
| 21 | * "This product includes software developed by the |
|
| 22 | * Apache Software Foundation (http://www.apache.org/)." |
|
| 23 | * Alternately, this acknowledgment may appear in the software itself, |
|
| 24 | * if and wherever such third-party acknowledgments normally appear. |
|
| 25 | * |
|
| 26 | * 4. The names "Apache" and "Apache Software Foundation" must |
|
| 27 | * not be used to endorse or promote products derived from this |
|
| 28 | * software without prior written permission. For written |
|
| 29 | * permission, please contact apache@apache.org. |
|
| 30 | * |
|
| 31 | * 5. Products derived from this software may not be called "Apache", |
|
| 32 | * nor may "Apache" appear in their name, without prior written |
|
| 33 | * permission of the Apache Software Foundation. |
|
| 34 | * |
|
| 35 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
|
| 36 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
| 37 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
| 38 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR |
|
| 39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
| 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
| 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
| 42 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
| 43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
| 44 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
|
| 45 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
| 46 | * SUCH DAMAGE. |
|
| 47 | * ==================================================================== |
|
| 48 | * |
|
| 49 | * This software consists of voluntary contributions made by many |
|
| 50 | * individuals on behalf of the Apache Software Foundation. For more |
|
| 51 | * information on the Apache Software Foundation, please see |
|
| 52 | * <http://www.apache.org/>. |
|
| 53 | * |
|
| 54 | * Portions of this software are based upon public domain software |
|
| 55 | * originally written at the National Center for Supercomputing Applications, |
|
| 56 | * University of Illinois, Urbana-Champaign. |
|
| 57 | */ |
|
| 58 | package com.bonevich.eclipse.cvsgrapher.editors; |
|
| 59 | ||
| 60 | import com.bonevich.eclipse.cvsgrapher.model.CvsGraphVersionModel; |
|
| 61 | ||
| 62 | import org.eclipse.compare.CompareUI; |
|
| 63 | import org.eclipse.gef.*; |
|
| 64 | import org.eclipse.gef.editparts.ZoomManager; |
|
| 65 | import org.eclipse.gef.ui.actions.ZoomInAction; |
|
| 66 | import org.eclipse.gef.ui.actions.ZoomOutAction; |
|
| 67 | import org.eclipse.jface.action.Action; |
|
| 68 | import org.eclipse.jface.action.IMenuManager; |
|
| 69 | import org.eclipse.jface.action.Separator; |
|
| 70 | import org.eclipse.team.internal.ccvs.core.ILogEntry; |
|
| 71 | import org.eclipse.team.internal.ccvs.ui.CVSCompareEditorInput; |
|
| 72 | import org.eclipse.team.internal.ccvs.ui.ResourceEditionNode; |
|
| 73 | ||
| 74 | import java.util.List; |
|
| 75 | ||
| 76 | /** |
|
| 77 | * The popup context menu for the CVS Graph editor. |
|
| 78 | * |
|
| 79 | * @author jbonevic |
|
| 80 | */ |
|
| 81 | 0 | public final class CvsGraphContextMenu extends ContextMenuProvider |
| 82 | { |
|
| 83 | private ZoomManager _zoomManager; |
|
| 84 | ||
| 85 | public CvsGraphContextMenu(GraphicalViewer viewer, ZoomManager manager) |
|
| 86 | { |
|
| 87 | 0 | super(viewer); |
| 88 | 0 | _zoomManager = manager; |
| 89 | 0 | } |
| 90 | ||
| 91 | public void buildContextMenu(IMenuManager menu) |
|
| 92 | { |
|
| 93 | 0 | menu.add(new ResetAction()); |
| 94 | 0 | menu.add(new CompareAction()); |
| 95 | ||
| 96 | 0 | menu.add(new Separator()); |
| 97 | ||
| 98 | 0 | menu.add(new GraphZoomInAction()); |
| 99 | 0 | menu.add(new GraphZoomOutAction()); |
| 100 | 0 | } |
| 101 | ||
| 102 | private final class GraphZoomInAction extends ZoomInAction |
|
| 103 | { |
|
| 104 | public GraphZoomInAction() |
|
| 105 | { |
|
| 106 | super(_zoomManager); |
|
| 107 | } |
|
| 108 | ||
| 109 | public boolean isEnabled() |
|
| 110 | { |
|
| 111 | return _zoomManager.canZoomIn(); |
|
| 112 | } |
|
| 113 | } |
|
| 114 | ||
| 115 | private final class GraphZoomOutAction extends ZoomOutAction |
|
| 116 | { |
|
| 117 | public GraphZoomOutAction() |
|
| 118 | { |
|
| 119 | super(_zoomManager); |
|
| 120 | } |
|
| 121 | ||
| 122 | public boolean isEnabled() |
|
| 123 | { |
|
| 124 | return _zoomManager.canZoomOut(); |
|
| 125 | } |
|
| 126 | } |
|
| 127 | ||
| 128 | private final class ResetAction extends Action |
|
| 129 | { |
|
| 130 | public String getText() |
|
| 131 | { |
|
| 132 | return "Reset Graph"; |
|
| 133 | } |
|
| 134 | ||
| 135 | public String getToolTipText() |
|
| 136 | { |
|
| 137 | return "Reset the version graph to its original layout"; |
|
| 138 | } |
|
| 139 | ||
| 140 | public void run() |
|
| 141 | { |
|
| 142 | GraphicalEditPart part = (GraphicalEditPart) getViewer().getContents(); |
|
| 143 | CvsGraphLayout layout = (CvsGraphLayout) part.getFigure().getLayoutManager(); |
|
| 144 | layout.reset(); |
|
| 145 | _zoomManager.setZoom(1.0d); |
|
| 146 | } |
|
| 147 | } |
|
| 148 | ||
| 149 | private final class CompareAction extends Action |
|
| 150 | { |
|
| 151 | public String getText() |
|
| 152 | { |
|
| 153 | return "Compare Versions"; |
|
| 154 | } |
|
| 155 | ||
| 156 | public String getToolTipText() |
|
| 157 | { |
|
| 158 | return "Compare the two selected versions"; |
|
| 159 | } |
|
| 160 | ||
| 161 | public void run() |
|
| 162 | { |
|
| 163 | List parts = getViewer().getSelectedEditParts(); |
|
| 164 | EditPart part1 = (EditPart) parts.get(0); |
|
| 165 | EditPart part2 = (EditPart) parts.get(1); |
|
| 166 | ||
| 167 | CvsGraphVersionModel version1 = (CvsGraphVersionModel) part1.getModel(); |
|
| 168 | CvsGraphVersionModel version2 = (CvsGraphVersionModel) part2.getModel(); |
|
| 169 | ||
| 170 | ILogEntry entry1 = version1.getEntry(); |
|
| 171 | ILogEntry entry2 = version2.getEntry(); |
|
| 172 | ||
| 173 | ResourceEditionNode left = new ResourceEditionNode(entry1.getRemoteFile()); |
|
| 174 | ResourceEditionNode right = new ResourceEditionNode(entry2.getRemoteFile()); |
|
| 175 | CompareUI.openCompareEditor( |
|
| 176 | new CVSCompareEditorInput(left, right) |
|
| 177 | ); |
|
| 178 | } |
|
| 179 | ||
| 180 | public boolean isEnabled() |
|
| 181 | { |
|
| 182 | List parts = getViewer().getSelectedEditParts(); |
|
| 183 | if (parts.size() == 2) |
|
| 184 | { |
|
| 185 | EditPart part1 = (EditPart) parts.get(0); |
|
| 186 | EditPart part2 = (EditPart) parts.get(1); |
|
| 187 | if (part1 instanceof CvsGraphVersionEditPart && part2 instanceof CvsGraphVersionEditPart) |
|
| 188 | { |
|
| 189 | return true; |
|
| 190 | } |
|
| 191 | } |
|
| 192 | return false; |
|
| 193 | } |
|
| 194 | ||
| 195 | } |
|
| 196 | ||
| 197 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |