| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
package com.bonevich.eclipse.cvsgrapher.editors; |
| 59 |
|
|
| 60 |
|
import com.bonevich.eclipse.cvsgrapher.CvsGraphPluginMessages; |
| 61 |
|
import com.bonevich.eclipse.cvsgrapher.CvsGraphPluginResources; |
| 62 |
|
import com.bonevich.eclipse.cvsgrapher.model.CvsGraphModel; |
| 63 |
|
|
| 64 |
|
import org.apache.commons.logging.Log; |
| 65 |
|
import org.apache.commons.logging.LogFactory; |
| 66 |
|
import org.eclipse.core.resources.IFile; |
| 67 |
|
import org.eclipse.core.resources.IMarker; |
| 68 |
|
import org.eclipse.core.resources.IResource; |
| 69 |
|
import org.eclipse.core.runtime.IProgressMonitor; |
| 70 |
|
import org.eclipse.draw2d.FigureCanvas; |
| 71 |
|
import org.eclipse.draw2d.geometry.Dimension; |
| 72 |
|
import org.eclipse.gef.DefaultEditDomain; |
| 73 |
|
import org.eclipse.gef.EditPartViewer; |
| 74 |
|
import org.eclipse.gef.GraphicalViewer; |
| 75 |
|
import org.eclipse.gef.editparts.ScalableFreeformRootEditPart; |
| 76 |
|
import org.eclipse.gef.ui.parts.GraphicalEditor; |
| 77 |
|
import org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler; |
| 78 |
|
import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer; |
| 79 |
|
import org.eclipse.jface.dialogs.ProgressMonitorDialog; |
| 80 |
|
import org.eclipse.jface.operation.IRunnableWithProgress; |
| 81 |
|
import org.eclipse.swt.SWT; |
| 82 |
|
import org.eclipse.swt.events.KeyEvent; |
| 83 |
|
import org.eclipse.swt.graphics.Rectangle; |
| 84 |
|
import org.eclipse.team.core.RepositoryProvider; |
| 85 |
|
import org.eclipse.team.core.TeamException; |
| 86 |
|
import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin; |
| 87 |
|
import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile; |
| 88 |
|
import org.eclipse.team.internal.ccvs.core.ILogEntry; |
| 89 |
|
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; |
| 90 |
|
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; |
| 91 |
|
import org.eclipse.ui.IEditorInput; |
| 92 |
|
import org.eclipse.ui.IEditorSite; |
| 93 |
|
import org.eclipse.ui.PartInitException; |
| 94 |
|
|
| 95 |
|
import java.lang.reflect.InvocationTargetException; |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
public final class CvsGraphEditor |
| 103 |
|
extends GraphicalEditor |
| 104 |
|
implements CvsGraphPluginResources |
| 105 |
|
{ |
| 106 |
|
private static final Log _logger = LogFactory.getLog(CvsGraphEditor.class); |
| 107 |
|
|
| 108 |
|
public static final String EDITOR_ID = "com.bonevich.eclipse.cvsgrapher.editor"; |
| 109 |
|
|
| 110 |
|
private ICVSRemoteFile _remoteFile = null; |
| 111 |
|
private ILogEntry[] _entries = null; |
| 112 |
|
|
| 113 |
|
public CvsGraphEditor() |
| 114 |
|
{ |
| 115 |
|
setEditDomain(new DefaultEditDomain(this)); |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
public void init(IEditorSite iSite, IEditorInput iInput) throws PartInitException |
| 123 |
|
{ |
| 124 |
|
setSite(iSite); |
| 125 |
|
setInput(iInput); |
| 126 |
|
initializeCvsRemoteFile(); |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
|
| 130 |
|
|
| 131 |
|
|
| 132 |
|
protected void initializeGraphicalViewer() |
| 133 |
|
{ |
| 134 |
|
if (_logger.isDebugEnabled()) |
| 135 |
|
{ |
| 136 |
|
_logger.debug("Opening editor for " + _remoteFile.getRepositoryRelativePath()); |
| 137 |
|
_logger.debug("Viewer = " + getGraphicalViewer()); |
| 138 |
|
} |
| 139 |
|
EditPartViewer viewer = getGraphicalViewer(); |
| 140 |
|
viewer.setContents(new CvsGraphModel(_entries)); |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
public boolean isSaveAsAllowed() |
| 147 |
|
{ |
| 148 |
|
return false; |
| 149 |
|
} |
| 150 |
|
|
| 151 |
|
|
| 152 |
|
|
| 153 |
|
|
| 154 |
|
public void doSave(IProgressMonitor iMonitor) |
| 155 |
|
{ |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
|
public void doSaveAs() |
| 162 |
|
{ |
| 163 |
|
} |
| 164 |
|
|
| 165 |
|
|
| 166 |
|
|
| 167 |
|
|
| 168 |
|
public void gotoMarker(IMarker iMarker) |
| 169 |
|
{ |
| 170 |
|
} |
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
| 174 |
|
|
| 175 |
|
public boolean isDirty() |
| 176 |
|
{ |
| 177 |
|
return false; |
| 178 |
|
} |
| 179 |
|
|
| 180 |
|
|
| 181 |
|
|
| 182 |
|
|
| 183 |
|
protected void configureGraphicalViewer() |
| 184 |
|
{ |
| 185 |
|
super.configureGraphicalViewer(); |
| 186 |
|
GraphicalViewer viewer = getGraphicalViewer(); |
| 187 |
|
|
| 188 |
|
ScalableFreeformRootEditPart rootPart = new ScalableFreeformRootEditPart(); |
| 189 |
|
viewer.setRootEditPart(rootPart); |
| 190 |
|
viewer.setEditPartFactory(new CvsGraphEditPartFactory()); |
| 191 |
|
|
| 192 |
|
((FigureCanvas) viewer.getControl()).setScrollBarVisibility(FigureCanvas.ALWAYS); |
| 193 |
|
viewer.setContextMenu(new CvsGraphContextMenu(viewer, rootPart.getZoomManager())); |
| 194 |
|
viewer.setKeyHandler(new CvsGraphViewerKeyHandler(viewer)); |
| 195 |
|
} |
| 196 |
|
|
| 197 |
|
private void initializeCvsRemoteFile() |
| 198 |
|
{ |
| 199 |
|
IResource resource = (IResource) getEditorInput().getAdapter(IResource.class); |
| 200 |
|
if (resource instanceof IFile) |
| 201 |
|
{ |
| 202 |
|
IFile file = (IFile) resource; |
| 203 |
|
|
| 204 |
|
if (_logger.isDebugEnabled()) |
| 205 |
|
{ |
| 206 |
|
_logger.debug("resource = " + file); |
| 207 |
|
} |
| 208 |
|
|
| 209 |
|
RepositoryProvider teamProvider = |
| 210 |
|
RepositoryProvider.getProvider( |
| 211 |
|
file.getProject(), |
| 212 |
|
CVSProviderPlugin.getTypeId() |
| 213 |
|
); |
| 214 |
|
if (teamProvider != null) |
| 215 |
|
{ |
| 216 |
|
try |
| 217 |
|
{ |
| 218 |
|
_remoteFile = (ICVSRemoteFile) CVSWorkspaceRoot.getRemoteResourceFor(file); |
| 219 |
|
setTitle(CvsGraphPluginMessages.bind(CVSGRAPHER_EDITOR_TITLE_WITHARG, _remoteFile.getName())); |
| 220 |
|
initializeLogEntries(); |
| 221 |
|
} |
| 222 |
|
catch (TeamException e) |
| 223 |
|
{ |
| 224 |
|
CVSUIPlugin.openError(getSite().getShell(), null, class="keyword">null, e); |
| 225 |
|
} |
| 226 |
|
} |
| 227 |
|
return; |
| 228 |
|
} |
| 229 |
|
_remoteFile = null; |
| 230 |
|
setTitle(CvsGraphPluginMessages.bind(CVSGRAPHER_EDITOR_TITLE)); |
| 231 |
|
} |
| 232 |
|
|
| 233 |
|
private void initializeLogEntries() |
| 234 |
|
{ |
| 235 |
|
try |
| 236 |
|
{ |
| 237 |
|
new ProgressMonitorDialog( |
| 238 |
|
getSite().getShell() |
| 239 |
|
).run( |
| 240 |
|
true, |
| 241 |
|
true, |
| 242 |
|
new IRunnableWithProgress() |
| 243 |
|
{ |
| 244 |
|
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException |
| 245 |
|
{ |
| 246 |
|
try |
| 247 |
|
{ |
| 248 |
|
_entries = _remoteFile.getLogEntries(monitor); |
| 249 |
|
} |
| 250 |
|
catch (TeamException e) |
| 251 |
|
{ |
| 252 |
|
throw new InvocationTargetException(e); |
| 253 |
|
} |
| 254 |
|
} |
| 255 |
|
} |
| 256 |
|
); |
| 257 |
|
} |
| 258 |
|
catch (InterruptedException ignore) |
| 259 |
|
{ |
| 260 |
|
|
| 261 |
|
} |
| 262 |
|
catch (InvocationTargetException e) |
| 263 |
|
{ |
| 264 |
|
CVSUIPlugin.openError(getSite().getShell(), null, class="keyword">null, e); |
| 265 |
|
} |
| 266 |
|
} |
| 267 |
|
|
| 268 |
|
|
| 269 |
|
|
| 270 |
|
|
| 271 |
|
|
| 272 |
|
|
| 273 |
|
|
| 274 |
|
|
| 275 |
|
|
| 276 |
|
|
| 277 |
|
final class CvsGraphViewerKeyHandler extends GraphicalViewerKeyHandler |
| 278 |
|
{ |
| 279 |
|
public CvsGraphViewerKeyHandler(GraphicalViewer viewer) |
| 280 |
0 |
{ |
| 281 |
0 |
super(viewer); |
| 282 |
0 |
} |
| 283 |
|
|
| 284 |
|
public boolean keyPressed(KeyEvent event) |
| 285 |
|
{ |
| 286 |
0 |
if (event.keyCode == SWT.PAGE_DOWN || event.keyCode == SWT.PAGE_UP || |
| 287 |
|
event.keyCode == SWT.HOME || event.keyCode == SWT.END ) |
| 288 |
|
{ |
| 289 |
0 |
ScrollingGraphicalViewer viewer = (ScrollingGraphicalViewer) getGraphicalViewer(); |
| 290 |
0 |
FigureCanvas canvas = (FigureCanvas) viewer.getControl(); |
| 291 |
|
|
| 292 |
0 |
int x = canvas.getViewport().getViewLocation().x; |
| 293 |
0 |
int y = canvas.getViewport().getViewLocation().y; |
| 294 |
0 |
int dx = 0; |
| 295 |
0 |
int dy = 0; |
| 296 |
|
|
| 297 |
0 |
Dimension viewingArea = canvas.getViewport().getClientArea().getSize(); |
| 298 |
0 |
Rectangle totalArea = canvas.getBounds(); |
| 299 |
|
|
| 300 |
0 |
switch (event.keyCode) |
| 301 |
|
{ |
| 302 |
0 |
case SWT.PAGE_DOWN : dx = x; dy = y + viewingArea.height; break; |
| 303 |
0 |
case SWT.PAGE_UP : dx = x; dy = y - viewingArea.height; break; |
| 304 |
0 |
case SWT.HOME : dx = 0; dy = y; break; |
| 305 |
0 |
case SWT.END : dx = totalArea.width; dy = y; break; |
| 306 |
0 |
default: dx = x; dy = y; break; |
| 307 |
|
} |
| 308 |
|
|
| 309 |
0 |
canvas.scrollSmoothTo(dx, dy); |
| 310 |
0 |
return true; |
| 311 |
|
} |
| 312 |
0 |
return super.keyPressed(event); |
| 313 |
|
} |
| 314 |
|
} |
| 315 |
|
} |