KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.ILogEntry;
24 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
25
26 public class OpenRemoteFileAction 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 ILogEntry) {
43                     resources.add(((ILogEntry)next).getRemoteFile());
44                     continue;
45                 }
46                 if (next instanceof IAdaptable) {
47                     IAdaptable a = (IAdaptable) next;
48                     Object JavaDoc adapter = a.getAdapter(ICVSRemoteFile.class);
49                     if (adapter instanceof ICVSRemoteFile) {
50                         resources.add(adapter);
51                         continue;
52                     }
53                 }
54             }
55         }
56         if (resources != null && !resources.isEmpty()) {
57             ICVSRemoteFile[] result = new ICVSRemoteFile[resources.size()];
58             resources.toArray(result);
59             return result;
60         }
61         return new ICVSRemoteFile[0];
62     }
63     /*
64      * @see CVSAction#execute(IAction)
65      */

66     public void execute(IAction action) throws InterruptedException JavaDoc, InvocationTargetException JavaDoc {
67         run(new IRunnableWithProgress() {
68             public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc {
69                 ICVSRemoteFile[] files = getSelectedRemoteFiles();
70                 for (int i = 0; i < files.length; i++) {
71                     ICVSRemoteFile file = files[i];
72                     CVSUIPlugin.getPlugin().openEditor(file, monitor);
73                 }
74             }
75         }, false, PROGRESS_BUSYCURSOR);
76     }
77     /*
78      * @see TeamAction#isEnabled()
79      */

80     public boolean isEnabled() {
81         ICVSRemoteFile[] resources = getSelectedRemoteFiles();
82         if (resources.length == 0) return false;
83         return true;
84     }
85 }
86
Popular Tags