KickJava   Java API By Example, From Geeks To Geeks.

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


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.dialogs.MessageDialog;
21 import org.eclipse.jface.operation.IRunnableWithProgress;
22 import org.eclipse.jface.viewers.IStructuredSelection;
23 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile;
24 import org.eclipse.team.internal.ccvs.core.ILogEntry;
25 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
26 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
27
28 public class OpenLogEntryAction extends CVSAction {
29     /**
30      * Returns the selected remote files
31      */

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

64     public void execute(IAction action) throws InterruptedException JavaDoc, InvocationTargetException JavaDoc {
65         run(new IRunnableWithProgress() {
66             public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc {
67                 final ILogEntry[] entries = getSelectedLogEntries();
68                 for (int i = 0; i < entries.length; i++) {
69                     if (entries[i].isDeletion()) {
70                         MessageDialog.openError(getShell(), CVSUIMessages.OpenLogEntryAction_deletedTitle, CVSUIMessages.OpenLogEntryAction_deleted); //
71
} else {
72                         ICVSRemoteFile file = entries[i].getRemoteFile();
73                         CVSUIPlugin.getPlugin().openEditor(file, monitor);
74                     }
75                 }
76             }
77         }, false, PROGRESS_BUSYCURSOR);
78     }
79     /*
80      * @see TeamAction#isEnabled()
81      */

82     public boolean isEnabled() {
83         ILogEntry[] entries = getSelectedLogEntries();
84         if (entries.length == 0) return false;
85         return true;
86     }
87 }
88
Popular Tags