KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > actions > ShowHistoryAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.ccvs.ui.actions;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.Iterator JavaDoc;
16
17 import org.eclipse.core.runtime.IAdaptable;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.operation.IRunnableWithProgress;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile;
23 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
24 import org.eclipse.team.ui.TeamUI;
25
26 public class ShowHistoryAction extends CVSAction {
27     /**
28      * Returns the selected remote files
29      */

30     protected ICVSRemoteFile[] getSelectedRemoteFiles() {
31         ArrayList JavaDoc resources = null;
32         IStructuredSelection selection = getSelection();
33         if (!selection.isEmpty()) {
34             resources = new ArrayList JavaDoc();
35             Iterator JavaDoc elements = selection.iterator();
36             while (elements.hasNext()) {
37                 Object JavaDoc next = elements.next();
38                 if (next instanceof ICVSRemoteFile) {
39                     resources.add(next);
40                     continue;
41                 }
42                 if (next instanceof IAdaptable) {
43                     IAdaptable a = (IAdaptable)next;
44                     Object JavaDoc adapter = a.getAdapter(ICVSRemoteFile.class);
45                     if (adapter instanceof ICVSRemoteFile) {
46                         resources.add(adapter);
47                         continue;
48                     }
49                 }
50             }
51         }
52         if (resources != null && !resources.isEmpty()) {
53             ICVSRemoteFile[] result = new ICVSRemoteFile[resources.size()];
54             resources.toArray(result);
55             return result;
56         }
57         return new ICVSRemoteFile[0];
58     }
59     /*
60      * @see CVSAction#executeIAction)
61      */

62     public void execute(IAction action) throws InterruptedException JavaDoc, InvocationTargetException JavaDoc {
63         run(new IRunnableWithProgress() {
64             public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc {
65                 ICVSRemoteFile[] files = getSelectedRemoteFiles();
66                 TeamUI.showHistoryFor(getTargetPage(), files[0], null);
67             }
68         }, false /* cancelable */, PROGRESS_BUSYCURSOR);
69     }
70     /*
71      * @see TeamAction#isEnabled()
72      */

73     public boolean isEnabled() {
74         ICVSRemoteFile[] resources = getSelectedRemoteFiles();
75         return resources.length == 1;
76     }
77     /**
78      * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getErrorTitle()
79      */

80     protected String JavaDoc getErrorTitle() {
81         return CVSUIMessages.ShowHistoryAction_showHistory;
82     }
83
84 }
85
Popular Tags