Fix the commit info tooltip for Windows
[egit.git] / org.spearce.egit.ui / src / org / spearce / egit / ui / GitHistoryPage.java
blob062b93be7e10e1a3c8d0d926f96c00e0b9e19920
1 /*
2 * Copyright (C) 2006 Robin Rosenberg
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License, version 2.1, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 package org.spearce.egit.ui;
19 import java.io.IOException;
20 import java.util.Date;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
25 import org.eclipse.compare.CompareConfiguration;
26 import org.eclipse.compare.structuremergeviewer.ICompareInput;
27 import org.eclipse.core.resources.IContainer;
28 import org.eclipse.core.resources.IProject;
29 import org.eclipse.core.resources.IResource;
30 import org.eclipse.core.resources.IResourceChangeEvent;
31 import org.eclipse.core.resources.IResourceChangeListener;
32 import org.eclipse.core.resources.ResourcesPlugin;
33 import org.eclipse.core.runtime.IAdaptable;
34 import org.eclipse.core.runtime.IProgressMonitor;
35 import org.eclipse.core.runtime.IStatus;
36 import org.eclipse.core.runtime.NullProgressMonitor;
37 import org.eclipse.core.runtime.Status;
38 import org.eclipse.core.runtime.jobs.Job;
39 import org.eclipse.jface.action.Action;
40 import org.eclipse.jface.action.IMenuListener;
41 import org.eclipse.jface.action.IMenuManager;
42 import org.eclipse.jface.action.MenuManager;
43 import org.eclipse.jface.resource.JFaceResources;
44 import org.eclipse.jface.viewers.ColumnWeightData;
45 import org.eclipse.jface.viewers.ILazyContentProvider;
46 import org.eclipse.jface.viewers.StructuredSelection;
47 import org.eclipse.jface.viewers.TableLayout;
48 import org.eclipse.jface.viewers.TableViewer;
49 import org.eclipse.jface.viewers.Viewer;
50 import org.eclipse.swt.SWT;
51 import org.eclipse.swt.events.MouseEvent;
52 import org.eclipse.swt.events.MouseListener;
53 import org.eclipse.swt.events.MouseMoveListener;
54 import org.eclipse.swt.events.SelectionAdapter;
55 import org.eclipse.swt.events.SelectionEvent;
56 import org.eclipse.swt.graphics.Point;
57 import org.eclipse.swt.layout.GridData;
58 import org.eclipse.swt.layout.GridLayout;
59 import org.eclipse.swt.widgets.Composite;
60 import org.eclipse.swt.widgets.Control;
61 import org.eclipse.swt.widgets.Display;
62 import org.eclipse.swt.widgets.Event;
63 import org.eclipse.swt.widgets.Listener;
64 import org.eclipse.swt.widgets.Menu;
65 import org.eclipse.swt.widgets.Table;
66 import org.eclipse.swt.widgets.TableColumn;
67 import org.eclipse.swt.widgets.TableItem;
68 import org.eclipse.team.core.RepositoryProvider;
69 import org.eclipse.team.core.history.IFileHistoryProvider;
70 import org.eclipse.team.core.history.IFileRevision;
71 import org.eclipse.team.internal.ui.TeamUIMessages;
72 import org.eclipse.team.internal.ui.history.DialogHistoryPageSite;
73 import org.eclipse.team.ui.history.HistoryPage;
74 import org.eclipse.team.ui.history.IHistoryCompareAdapter;
75 import org.eclipse.team.ui.history.IHistoryPageSite;
76 import org.spearce.egit.core.GitProvider;
77 import org.spearce.egit.core.internal.mapping.GitFileHistory;
78 import org.spearce.egit.core.internal.mapping.GitFileRevision;
79 import org.spearce.egit.core.project.RepositoryMapping;
80 import org.spearce.egit.ui.internal.actions.GitCompareRevisionAction;
81 import org.spearce.jgit.lib.ObjectId;
82 import org.spearce.jgit.lib.Tag;
83 import org.spearce.jgit.lib.TopologicalSorter;
84 import org.spearce.jgit.lib.Repository.StGitPatch;
85 import org.spearce.jgit.lib.TopologicalSorter.Edge;
86 import org.spearce.jgit.lib.TopologicalSorter.Lane;
88 public class GitHistoryPage extends HistoryPage implements IAdaptable,
89 IHistoryCompareAdapter {
91 private static final String PREF_SHOWALLPROJECTVERSIONS = "org.spearce.egit.ui.githistorypage.showallprojectversions";
92 private static final String PREF_SHOWALLFOLDERVERSIONS = "org.spearce.egit.ui.githistorypage.showallfolderversions";
94 private Composite localComposite;
96 private TableViewer viewer;
98 private Table table;
100 private List<IFileRevision> fileRevisions;
102 protected boolean hintShowDiffNow;
104 private boolean showAllVersions;
106 private boolean showAllFolderVersions;
108 public GitHistoryPage(Object object) {
109 setInput(object);
110 showAllVersions = Activator.getDefault().getPreferenceStore()
111 .getBoolean(PREF_SHOWALLPROJECTVERSIONS);
112 showAllFolderVersions = Activator.getDefault().getPreferenceStore()
113 .getBoolean(PREF_SHOWALLFOLDERVERSIONS);
116 public boolean inputSet() {
117 if (viewer != null)
118 viewer.setInput(getInput());
119 // TODO Auto-generated method stub
120 return true;
123 public void createControl(Composite parent) {
124 localComposite = new Composite(parent, SWT.NONE);
125 GridLayout layout = new GridLayout();
126 layout.marginHeight = 0;
127 layout.marginWidth = 0;
128 localComposite.setLayout(layout);
129 GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
130 data.grabExcessVerticalSpace = true;
131 localComposite.setLayoutData(data);
133 createTable(localComposite);
135 IHistoryPageSite parentSite = getHistoryPageSite();
136 if (parentSite != null && parentSite instanceof DialogHistoryPageSite)
137 parentSite.setSelectionProvider(viewer);
139 final GitCompareRevisionAction compareAction = new GitCompareRevisionAction(
140 "Compare");
141 final GitCompareRevisionAction compareActionPrev = new GitCompareRevisionAction(
142 "Show commit");
143 table.addMouseListener(new MouseListener() {
145 public void mouseUp(MouseEvent e) {
148 public void mouseDown(MouseEvent e) {
149 hintShowDiffNow = e.button==1;
152 public void mouseDoubleClick(MouseEvent e) {
157 table.addMouseMoveListener(new MouseMoveListener() {
158 TableItem lastItem;
159 public void mouseMove(MouseEvent e) {
160 TableItem item = table.getItem(new Point(e.x,e.y));
161 if (item != null && item!=lastItem) {
162 IFileRevision rev = (IFileRevision) item.getData();
163 if (rev == null)
164 return;
165 String commitStr=null;
166 if (appliedPatches!=null) {
167 String id = rev.getContentIdentifier();
168 if (!id.equals("Workspace")) {
169 StGitPatch patch = (StGitPatch) appliedPatches.get(new ObjectId(id));
170 if (patch!=null)
171 commitStr = "Patch: "+patch.getName();
172 } else {
173 commitStr = "Workspace:";
176 if (commitStr == null)
177 commitStr = "Commit: "+rev.getContentIdentifier();
178 table.setToolTipText(commitStr+"\nAuthor: "+rev.getAuthor()+"\nDate: "+new Date(rev.getTimestamp())+"\n\n"+rev.getComment());
180 lastItem = item;
184 table.addSelectionListener(new SelectionAdapter() {
185 public void widgetSelected(SelectionEvent e) {
186 // update the current
187 TableItem[] selection = table.getSelection();
188 IFileRevision[] selection2 = new IFileRevision[selection.length];
189 for (int i = 0; i < selection.length; ++i) {
190 selection2[i] = (IFileRevision) selection[i].getData();
193 compareAction.setCurrentFileRevision(fileRevisions.get(0));
194 compareAction.selectionChanged(new StructuredSelection(
195 selection2));
196 if (selection2.length == 1 && hintShowDiffNow) {
197 ObjectId[] parentIds = ((GitFileRevision)selection2[0]).getCommit().getParentIds();
198 if (parentIds.length > 0) {
199 ObjectId parentId = parentIds[0];
200 IFileRevision previous = new GitFileRevision(parentId,
201 ((GitFileRevision)selection2[0]).getResource(),
202 ((GitFileRevision)selection2[0]).getCount()+1);
203 compareActionPrev.setCurrentFileRevision(null);
204 compareActionPrev.selectionChanged(new StructuredSelection(new IFileRevision[] {selection2[0], previous}));
205 System.out.println("detail="+e.detail);
206 table.getDisplay().asyncExec(new Runnable() {
207 public void run() {
208 if (GitCompareRevisionAction.findReusableCompareEditor(GitHistoryPage.this.getSite().getPage()) != null)
209 compareActionPrev.run();
213 } else {
214 compareActionPrev.setCurrentFileRevision(null);
215 compareActionPrev.selectionChanged(new StructuredSelection(new IFileRevision[0]));
217 hintShowDiffNow = false;
220 compareAction.setPage(this);
221 compareActionPrev.setPage(this);
222 MenuManager menuMgr = new MenuManager();
223 Menu menu = menuMgr.createContextMenu(table);
224 menuMgr.addMenuListener(new IMenuListener() {
225 public void menuAboutToShow(IMenuManager menuMgr) {
226 menuMgr.add(compareAction);
227 menuMgr.add(compareActionPrev);
230 menuMgr.setRemoveAllWhenShown(true);
231 table.setMenu(menu);
233 GitHistoryResourceListener resourceListener = new GitHistoryResourceListener();
234 ResourcesPlugin.getWorkspace().addResourceChangeListener(
235 resourceListener, IResourceChangeEvent.POST_CHANGE);
237 Action showAllVersionsAction = new Action("\u2200" /* unicode: FOR ALL */) {
238 public void run() {
239 setShowAllVersions(isChecked());
240 if (historyRefreshJob.cancel()) {
241 System.out.println("rescheduling");
242 historyRefreshJob.schedule();
243 } else {
244 System.out.println("failed to cancel?");
248 showAllVersionsAction
249 .setToolTipText("Show all versions for the project containing the resource");
250 showAllVersionsAction.setChecked(isShowAllVersions());
251 getSite().getActionBars().getToolBarManager()
252 .add(showAllVersionsAction);
254 Action showAllFolderVersionsAction = new Action("F") {
255 public void run() {
256 setShowAllFolderVersion(isChecked());
257 if (historyRefreshJob.cancel()) {
258 System.out.println("rescheduling");
259 historyRefreshJob.schedule();
260 } else {
261 System.out.println("failed to cancel?");
265 showAllFolderVersionsAction
266 .setToolTipText("Show all versions for the folder containing the resource");
267 showAllFolderVersionsAction.setChecked(isShowAllFolderVersions());
268 getSite().getActionBars().getToolBarManager().add(
269 showAllFolderVersionsAction);
272 private boolean isShowAllVersions() {
273 return showAllVersions;
276 protected void setShowAllVersions(boolean showAllVersions) {
277 this.showAllVersions = showAllVersions;
278 Activator.getDefault().getPreferenceStore().setValue(
279 PREF_SHOWALLPROJECTVERSIONS, showAllVersions);
282 private boolean isShowAllFolderVersions() {
283 return showAllFolderVersions;
286 protected void setShowAllFolderVersion(boolean showAllFolderVersions) {
287 this.showAllFolderVersions = showAllFolderVersions;
288 Activator.getDefault().getPreferenceStore().setValue(
289 PREF_SHOWALLFOLDERVERSIONS, showAllFolderVersions);
292 class GitHistoryResourceListener implements IResourceChangeListener {
294 public void resourceChanged(IResourceChangeEvent event) {
295 System.out.println("resourceChanged(" + event + ")");
300 class GitHistoryLabelProvider {
302 public String getColumnText(int index, int columnIndex) {
303 GitFileRevision element = (GitFileRevision) fileRevisions.get(index);
304 if (columnIndex == 0) {
305 return "";
308 if (columnIndex == 1) {
309 String rss = element.getURI().toString();
310 String rs = rss.substring(rss.length()-10);
311 String id = element.getContentIdentifier();
312 if (appliedPatches!=null) {
313 if (!id.equals("Workspace")) {
314 StGitPatch patch = (StGitPatch) appliedPatches.get(new ObjectId(id));
315 if (patch!=null)
316 return patch.getName();
319 if (id != null)
320 if (id.length() > 9) // make sure "Workspace" is spelled out
321 return id.substring(0, 7) + "..";
322 else
323 return id;
324 else
325 return id + "@.." + rs;
328 if (columnIndex == 2) {
329 String id = element.getContentIdentifier();
330 if (id.equals("Workspace")) {
331 return "";
333 ObjectId oid = new ObjectId(id);
334 StringBuilder b=new StringBuilder();
335 if (tags != null) {
336 Tag[] matching = tags.get(oid);
337 if (matching != null) {
338 for (Tag t : matching) {
339 if (b.length() > 0)
340 b.append(' ');
341 b.append(t.getTag());
345 if (branches != null) {
346 if (b.length() >0)
347 b.append('\n');
348 String[] matching = branches.get(oid);
349 if (matching != null) {
350 for (String t : matching) {
351 if (b.length() > 0)
352 b.append(' ');
353 b.append(t);
357 return b.toString();
360 if (columnIndex == 3) {
361 Date d = new Date(element.getTimestamp());
362 if (d.getTime() == -1)
363 return "";
364 return d.toString();
366 if (columnIndex == 4)
367 return element.getAuthor();
369 if (columnIndex == 5) {
370 String comment = element.getComment();
371 if (comment == null)
372 return null;
373 int p = comment.indexOf('\n');
374 if (p >= 0)
375 return comment.substring(0, p);
376 else
377 return comment;
379 return Integer.toString(columnIndex);
383 private void createTable(Composite composite) {
384 table = new Table(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI
385 | SWT.FULL_SELECTION | SWT.VIRTUAL);
386 table.setHeaderVisible(true);
387 table.setLinesVisible(true);
388 GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
389 table.setLayoutData(data);
390 table.setData("HEAD");
391 table.addListener(SWT.SetData, new Listener() {
392 public void handleEvent(Event event) {
393 try {
394 // System.out.println("handleEvent "+event.type+" "+event.index + "=> "+fileRevisions.get(event.index));
395 TableItem item = (TableItem) event.item;
396 Table parent = item.getParent();
397 if (parent == null) {
398 item.setText(new String[] { "hej", "san" });
399 item.setData("");
400 } else {
401 for (int i = 0; i < 6; ++i) {
402 String text = lp.getColumnText(event.index, i);
403 if (text != null)
404 item.setText(i, text);
405 else
406 item.setText(i, "");
408 item.setData(fileRevisions.get(event.index));
410 item.setFont(0,JFaceResources.getBannerFont());
411 } catch (Throwable b) {
412 b.printStackTrace();
417 table.addListener(SWT.PaintItem, new Listener() {
419 final int[] colors = {
420 SWT.COLOR_BLACK,
421 SWT.COLOR_BLUE,
422 SWT.COLOR_CYAN,
423 SWT.COLOR_DARK_BLUE,
424 SWT.COLOR_DARK_CYAN,
425 SWT.COLOR_DARK_GREEN,
426 SWT.COLOR_DARK_MAGENTA,
427 SWT.COLOR_DARK_RED,
428 SWT.COLOR_DARK_YELLOW,
429 SWT.COLOR_GRAY,
430 SWT.COLOR_GREEN,
431 SWT.COLOR_MAGENTA,
432 SWT.COLOR_RED,
433 // SWT.COLOR_WHITE,
434 SWT.COLOR_YELLOW
436 public void handleEvent(Event event) {
437 TableItem item = (TableItem) event.item;
438 if (event.index == 0) {
439 System.out.println(event);
440 GitFileRevision element = (GitFileRevision)item.getData();
441 ObjectId xx = element.getCommitId();
442 int x = event.x;
443 int y = event.y;
444 int h = event.height;
445 event.gc.setLineWidth(2);
446 // RepositoryMapping rm = RepositoryMapping.getMapping(element.getResource());
447 final int DOTRADIUS = 3;
448 final int INTERLANE = 10;
450 Lane lane = element.getLane();
451 TopologicalSorter<ObjectId> counter = lane.getSorter();
452 Integer io = counter.getInternalPosition(xx);
453 for (TopologicalSorter<ObjectId>.Lane li : counter.currentLanes) {
454 Integer iost = counter.getInternalPosition(li.startsAt);
455 Integer ioen = counter.getInternalPosition(li.endsAt);
456 List<Edge<ObjectId>> lif = counter.getEdgeFrom(li.endsAt);
457 if (lif != null) {
458 for(TopologicalSorter.Edge<ObjectId> ee : lif) {
459 Integer eio = counter.getInternalPosition(ee.getTo());
460 if (eio == null) { // not yet assigned (further down)
461 if (iost != null && io.intValue() > iost.intValue()) {
462 event.gc.setForeground(Display.getCurrent().getSystemColor(colors[li.getNumber()%colors.length]));
463 // event.gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED));
464 event.gc.drawLine(x + li.getNumber()*INTERLANE, y, x + li.getNumber()*INTERLANE, y + h);
466 } else {
467 // System.out.println ("Looking at id "+li.endsAt+" at lane "+li.number+" ending on ="+ioen+" and it's parent "+ee.to+ " ends at "+eio);
468 if (io.intValue() < eio.intValue() && /*ECLIPSEBUG*/ iost!=null && /*ENDBUG*/ io.intValue() > iost.intValue()) {
469 if (io.intValue() >= ioen.intValue()) {
470 event.gc.setForeground(Display.getCurrent().getSystemColor(colors[li.getNumber()%colors.length]));
471 // event.gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_MAGENTA));
472 event.gc.drawLine(x + li.getNumber()*INTERLANE, y, x + li.getNumber()*INTERLANE, y + h);
474 } else {
475 if (io.intValue() == eio.intValue()) {
476 // COPY
477 int fromn = lane.getNumber();
478 int ton = li.getNumber();
479 int x1 = x + fromn * INTERLANE;
480 int x2 = x + ton * INTERLANE;
481 // if (fromn < ton)
482 // x1 += DOTRADIUS;
483 // else
484 // x1 -= DOTRADIUS;
485 event.gc.setForeground(Display.getCurrent().getSystemColor(colors[li.getNumber()%colors.length]));
486 // event.gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GREEN));
487 // _|
488 if (x1 < x2)
489 event.gc.drawArc(x1 - (x2-x1), y-h/2, (x2-x1)*2, h, 270, 90);
490 else
491 event.gc.drawArc(x2, y-h/2, (x1-x2)*2, h, 180, 90);
492 // event.gc.drawLine(x1, y + h/2, x2, y + h/2);
493 // event.gc.drawLine(x2, y, x2, y + h/2);
499 if (li.startsAt == xx) {
500 // COPY
501 int fromn = lane.getNumber();
502 int ton = li.getNumber();
503 int x1 = x + fromn * INTERLANE;
504 int x2 = x + ton * INTERLANE;
505 if (fromn < ton)
506 x1 += DOTRADIUS;
507 else
508 x1 -= DOTRADIUS;
509 // event.gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN));
510 event.gc.setForeground(Display.getCurrent().getSystemColor(colors[li.getNumber()%colors.length]));
511 if (x1 < x2)
512 event.gc.drawArc(x1 - (x2-x1), y+h/2, (x2-x1)*2, h, 0, 90);
513 else
514 event.gc.drawArc(x2, y+h/2, (x1-x2)*2, h, 180, 90);
515 // event.gc.drawLine(x1, y + h/2, x2, y + h/2);
516 // event.gc.drawLine(x2, y + h/2, x2, y + h);
517 // END COPY
519 if (iost!=null && io.intValue() > iost.intValue()) {
520 if (ioen == null || io.intValue() < ioen.intValue()) {
521 // event.gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
522 event.gc.setForeground(Display.getCurrent().getSystemColor(colors[li.getNumber()%colors.length]));
523 event.gc.drawLine(x + li.getNumber()*INTERLANE, y, x + li.getNumber()*INTERLANE, y + h);
525 if (ioen == null || io.intValue() == ioen.intValue()) {
526 // event.gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
527 event.gc.setForeground(Display.getCurrent().getSystemColor(colors[li.getNumber()%colors.length]));
528 event.gc.drawLine(x + li.getNumber()*INTERLANE, y, x + li.getNumber()*INTERLANE, y + h/2);
532 event.gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
533 event.gc.fillOval(x + lane.getNumber() * INTERLANE - DOTRADIUS, y + h/2 - DOTRADIUS, DOTRADIUS*2, DOTRADIUS*2);
537 TableLayout layout = new TableLayout();
538 table.setLayout(layout);
540 viewer = new TableViewer(table, SWT.VIRTUAL | SWT.FULL_SELECTION);
542 viewer.setUseHashlookup(true);
544 createColumns();
546 viewer.setContentProvider(new GitHistoryContentProvider());
548 viewer.setInput(getInput());
551 private Map appliedPatches;
552 private Map<ObjectId,Tag[]> tags;
553 private Map<ObjectId, String[]> branches;
554 GitHistoryLabelProvider lp = new GitHistoryLabelProvider();
556 class HistoryRefreshJob extends Job {
558 public HistoryRefreshJob(String name) {
559 super(name);
562 protected IStatus run(IProgressMonitor monitor) {
563 monitor = new NullProgressMonitor();
564 monitor.beginTask("UpdateHistory", IProgressMonitor.UNKNOWN);
565 IProject project = ((IResource) getInput()).getProject();
566 RepositoryProvider provider = RepositoryProvider
567 .getProvider(project);
568 RepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project);
569 Map newappliedPatches = null;
570 try {
571 newappliedPatches = repositoryMapping.getRepository().getAppliedPatches();
572 } catch (IOException e) {
573 // TODO Auto-generated catch block
574 e.printStackTrace();
576 Map<ObjectId,Tag[]> newtags = new HashMap<ObjectId,Tag[]>();
577 try {
578 for (String name : repositoryMapping.getRepository().getTags()) {
579 Tag t = repositoryMapping.getRepository().mapTag(name);
580 Tag[] samecommit = newtags.get(t.getObjId());
581 if (samecommit==null) {
582 samecommit = new Tag[] { t };
583 } else {
584 Tag[] n=new Tag[samecommit.length+1];
585 for (int j=0; j<samecommit.length; ++j)
586 n[j] = samecommit[j];
587 n[n.length-1] = t;
588 samecommit = n;
590 newtags.put(t.getObjId(), samecommit);
592 } catch (IOException e) {
593 // TODO Auto-generated catch block
594 e.printStackTrace();
596 Map<ObjectId, String[]> newBranches = new HashMap<ObjectId, String[]>();
597 try {
598 for (String branch : repositoryMapping.getRepository().getBranches()) {
599 ObjectId id = repositoryMapping.getRepository().resolve("refs/heads/"+branch);
600 String[] samecommit = newBranches.get(id);
601 if (samecommit == null) {
602 samecommit = new String[] { branch };
603 } else {
604 String[] n=new String[samecommit.length + 1];
605 for (int j=0; j<samecommit.length; ++j)
606 n[j] = samecommit[j];
607 n[n.length-1] = branch;
608 samecommit = n;
610 newBranches.put(id, samecommit);
612 branches = newBranches;
613 } catch (IOException e) {
614 // TODO Auto-generated catch block
615 e.printStackTrace();
618 IFileHistoryProvider fileHistoryProvider = provider
619 .getFileHistoryProvider();
620 IResource startingPoint = (IResource) getInput();
621 if (isShowAllFolderVersions())
622 if (!(startingPoint instanceof IContainer))
623 startingPoint = startingPoint.getParent();
624 if (isShowAllVersions())
625 startingPoint = startingPoint.getProject();
626 GitFileHistory fileHistoryFor = (GitFileHistory)fileHistoryProvider
627 .getFileHistoryFor(startingPoint,
629 monitor);
630 fileRevisions = fileHistoryFor.getFileRevisionsList();
631 final Map fnewappliedPatches = newappliedPatches;
632 final Map<ObjectId,Tag[]> ftags = newtags;
634 table.getDisplay().asyncExec(new Runnable() {
636 public void run() {
637 table.removeAll();
638 table.setItemCount(fileRevisions.size());
639 table.setData("X");
640 table.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
641 System.out.println("inputchanged, invoking refresh");
642 appliedPatches = fnewappliedPatches;
643 tags = ftags;
644 long t0 = System.currentTimeMillis();
645 viewer.refresh();
646 long t1 = System.currentTimeMillis();
647 System.out.println("refresh in "+(t1-t0)/1000.0+"s");
648 done(Status.OK_STATUS);
652 return Status.OK_STATUS;
657 HistoryRefreshJob historyRefreshJob = new HistoryRefreshJob("Git history refresh");
659 class GitHistoryContentProvider implements ILazyContentProvider {
661 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
662 if (newInput == null)
663 return;
664 if (newInput == oldInput)
665 return;
666 IProject project = ((IResource) getInput()).getProject();
667 RepositoryProvider provider = RepositoryProvider.getProvider(project);
668 if (!(provider instanceof GitProvider))
669 return;
671 System.out.println(new Date()+"inputChanged(" + viewer + "," + oldInput + ","
672 + newInput);
673 if (historyRefreshJob.cancel()) {
674 System.out.println("rescheduling");
675 historyRefreshJob.schedule();
676 } else {
677 System.out.println("failed to cancel?");
681 public void dispose() {
684 public void updateElement(int index) {
685 // viewer.update(arg0, arg1)
689 private void createColumns() {
690 // X SelectionListener headerListener = getColumnListener(viewer);
691 // count from head
692 TableColumn col = new TableColumn(table, SWT.NONE);
693 col.setResizable(true);
694 col.setText("^");
695 // X col.addSelectionListener(headerListener);
696 ((TableLayout) table.getLayout()).addColumnData(new ColumnWeightData(15,
697 true));
699 // revision
700 col = new TableColumn(table, SWT.NONE);
701 col.setResizable(true);
702 col.setText(TeamUIMessages.GenericHistoryTableProvider_Revision);
703 // X col.addSelectionListener(headerListener);
704 ((TableLayout) table.getLayout()).addColumnData(new ColumnWeightData(15,
705 true));
707 // tags
708 col = new TableColumn(table, SWT.NONE);
709 col.setResizable(true);
710 col.setText("Tags");
711 // X col.addSelectionListener(headerListener);
712 ((TableLayout) table.getLayout()).addColumnData(new ColumnWeightData(15,
713 true));
714 // creation date
715 col = new TableColumn(table, SWT.NONE);
716 col.setResizable(true);
717 col.setText(TeamUIMessages.GenericHistoryTableProvider_RevisionTime);
718 // X col.addSelectionListener(headerListener);
719 ((TableLayout) table.getLayout()).addColumnData(new ColumnWeightData(30,
720 true));
722 // author
723 col = new TableColumn(table, SWT.NONE);
724 col.setResizable(true);
725 col.setText(TeamUIMessages.GenericHistoryTableProvider_Author);
726 // X col.addSelectionListener(headerListener);
727 ((TableLayout) table.getLayout()).addColumnData(new ColumnWeightData(20,
728 true));
730 // comment
731 col = new TableColumn(table, SWT.NONE);
732 col.setResizable(true);
733 col.setText(TeamUIMessages.GenericHistoryTableProvider_Comment);
734 // X col.addSelectionListener(headerListener);
735 ((TableLayout) table.getLayout()).addColumnData(new ColumnWeightData(35,
736 true));
739 public Control getControl() {
740 return localComposite;
743 public void setFocus() {
744 localComposite.setFocus();
747 public String getDescription() {
748 return "GIT History viewer";
751 public String getName() {
752 return getInput().toString();
755 public boolean isValidInput(Object object) {
756 // TODO Auto-generated method stub
757 return true;
760 public void refresh() {
761 // TODO Auto-generated method stub
765 public Object getAdapter(Class adapter) {
766 if (adapter == IHistoryCompareAdapter.class) {
767 return this;
769 return null;
772 public ICompareInput getCompareInput(Object object) {
773 // TODO Auto-generated method stub
774 return null;
777 public void prepareInput(ICompareInput input,
778 CompareConfiguration configuration, IProgressMonitor monitor) {
779 System.out.println("prepareInput()");
780 // TODO Auto-generated method stub