KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CSC - Intial implementation
10  * IBM Corporation - ongoing maintenance
11  *******************************************************************************/

12 package org.eclipse.team.internal.ccvs.ui.actions;
13
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.jface.operation.IRunnableWithProgress;
20 import org.eclipse.jface.window.Window;
21 import org.eclipse.osgi.util.NLS;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.team.core.Team;
24 import org.eclipse.team.internal.ccvs.core.*;
25 import org.eclipse.team.internal.ccvs.ui.*;
26 import org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction.IProviderAction;
27
28 /**
29  * This Action gets the <code>EditorsInfo[]</code>
30  * It is used by the <code>ShowEditorAction</code>
31  * and <code>ShowEditorAction</code>.
32  *
33  * @author <a HREF="mailto:gregor.kohlwes@csc.com,kohlwes@gmx.net">Gregor
34  * Kohlwes</a>
35  *
36  */

37 public class EditorsAction implements IProviderAction, IRunnableWithProgress {
38     EditorsInfo[] f_editorsInfo = new EditorsInfo[0];
39     CVSTeamProvider f_provider;
40     IResource[] f_resources;
41
42     public EditorsAction() {
43     }
44     
45     public EditorsAction(CVSTeamProvider provider, IResource[] resources) {
46         f_provider = provider;
47         f_resources = resources;
48     }
49     /**
50      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction.IProviderAction#execute(org.eclipse.team.internal.ccvs.core.CVSTeamProvider, org.eclipse.core.resources.IResource, org.eclipse.core.runtime.IProgressMonitor)
51      */

52     public IStatus execute(CVSTeamProvider provider, IResource[] resources, IProgressMonitor monitor) throws CVSException {
53         f_editorsInfo = provider.editors(resources, monitor);
54         return Team.OK_STATUS;
55     }
56     
57     public boolean promptToEdit(Shell shell) {
58         if (!isEmpty()) {
59             final EditorsDialog view = new EditorsDialog(shell, f_editorsInfo);
60             // Open the dialog using a sync exec (there are no guarentees that we
61
// were called from the UI thread
62
CVSUIPlugin.openDialog(shell, new CVSUIPlugin.IOpenableInShell() {
63                 public void open(Shell shell) {
64                     view.open();
65                 }
66             }, CVSUIPlugin.PERFORM_SYNC_EXEC);
67             return (view.getReturnCode() == Window.OK);
68         }
69         return true;
70     }
71
72     /**
73      * Contact the server to determine if there are any editors on the associatd files.
74      *
75      * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
76      */

77     public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
78         if (f_provider == null || f_resources == null) {
79             throw new InvocationTargetException JavaDoc(new RuntimeException JavaDoc(NLS.bind(CVSUIMessages.EditorsAction_classNotInitialized, new String JavaDoc[] { this.getClass().getName() })));
80         }
81         try {
82             execute(f_provider,f_resources,monitor);
83         } catch (CVSException e) {
84             throw new InvocationTargetException JavaDoc(e);
85         }
86     }
87
88     /**
89      * Returns the f_editorsInfo.
90      * @return EditorsInfo[]
91      */

92     public EditorsInfo[] getEditorsInfo() {
93         return f_editorsInfo;
94     }
95
96     /**
97      * Indicates whether there are editors of any of the associated files.
98      * The <code>run(IProgressMonitor)</code> must be invoked first to
99      * fetch any editors from the server.
100      * @return boolean
101      */

102     public boolean isEmpty() {
103         return f_editorsInfo.length == 0;
104     }
105
106 }
107
Popular Tags