KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > history > ShowLocalHistory


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ui.history;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.resources.*;
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.jface.action.IAction;
18 import org.eclipse.jface.dialogs.ErrorDialog;
19 import org.eclipse.jface.dialogs.MessageDialog;
20 import org.eclipse.jface.operation.IRunnableWithProgress;
21 import org.eclipse.jface.viewers.ISelection;
22 import org.eclipse.jface.viewers.IStructuredSelection;
23 import org.eclipse.swt.widgets.Shell;
24 import org.eclipse.team.internal.ui.TeamUIMessages;
25 import org.eclipse.team.internal.ui.TeamUIPlugin;
26 import org.eclipse.team.ui.TeamUI;
27 import org.eclipse.team.ui.history.IHistoryPage;
28 import org.eclipse.team.ui.history.IHistoryView;
29 import org.eclipse.ui.*;
30 import org.eclipse.ui.actions.ActionDelegate;
31
32 public class ShowLocalHistory extends ActionDelegate implements IObjectActionDelegate {
33
34     private IStructuredSelection fSelection;
35     private IWorkbenchPart targetPart;
36     
37     public void run(IAction action) {
38         IFileState states[]= getLocalHistory();
39         if (states == null || states.length == 0)
40             return;
41         try {
42             PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
43                 public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
44                     final IResource resource = (IResource) fSelection.getFirstElement();
45                     Runnable JavaDoc r = new Runnable JavaDoc() {
46                         public void run() {
47                             IHistoryView view = TeamUI.showHistoryFor(TeamUIPlugin.getActivePage(), resource, LocalHistoryPageSource.getInstance());
48                             IHistoryPage page = view.getHistoryPage();
49                             if (page instanceof LocalHistoryPage){
50                                 LocalHistoryPage historyPage = (LocalHistoryPage) page;
51                                 historyPage.setClickAction(isCompare());
52                             }
53                         }
54                     };
55                     TeamUIPlugin.getStandardDisplay().asyncExec(r);
56                 }
57             });
58         } catch (InvocationTargetException JavaDoc exception) {
59             ErrorDialog.openError(getShell(), null, null, new Status(IStatus.ERROR, TeamUIPlugin.PLUGIN_ID, IStatus.ERROR, TeamUIMessages.ShowLocalHistory_1, exception.getTargetException()));
60         } catch (InterruptedException JavaDoc exception) {
61         }
62     }
63     
64     public void selectionChanged(IAction action, ISelection sel) {
65         if (sel instanceof IStructuredSelection) {
66             fSelection= (IStructuredSelection) sel;
67         }
68     }
69     public void setActivePart(IAction action, IWorkbenchPart targetPart) {
70         this.targetPart = targetPart;
71     }
72     
73     protected Shell getShell() {
74         if (targetPart != null)
75             return targetPart.getSite().getShell();
76         return TeamUIPlugin.getActivePage().getActivePart().getSite().getShell();
77     }
78
79     protected boolean isCompare() {
80         return false;
81     }
82
83     public IStructuredSelection getSelection() {
84         return fSelection;
85     }
86     
87     protected IFileState[] getLocalHistory() {
88         final IFile file = (IFile) getSelection().getFirstElement();
89         IFileState states[];
90         try {
91             states= file.getHistory(null);
92         } catch (CoreException ex) {
93             MessageDialog.openError(getShell(), getPromptTitle(), ex.getMessage());
94             return null;
95         }
96         
97         if (states == null || states.length <= 0) {
98             MessageDialog.openInformation(getShell(), getPromptTitle(), TeamUIMessages.ShowLocalHistory_0);
99             return states;
100         }
101         return states;
102     }
103
104     protected String JavaDoc getPromptTitle() {
105         return TeamUIMessages.ShowLocalHistory_2;
106     }
107
108 }
109
Popular Tags