KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > operations > HasProjectMetaFileOperation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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.operations;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.team.core.TeamException;
17 import org.eclipse.team.internal.ccvs.core.CVSException;
18 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder;
19 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
20 import org.eclipse.ui.IWorkbenchPart;
21
22 /**
23  * Operation which checks for the existance of the .project file
24  * in a remote folder. The operation can be run using the <code>hasMetaFile</code>
25  * static method of by executing the operation and then checking <code>metaFileExists</code>
26  */

27 public class HasProjectMetaFileOperation extends CVSOperation {
28
29     private ICVSRemoteFolder remoteFolder;
30     private boolean metaFileExists;
31     
32     public static boolean hasMetaFile(IWorkbenchPart part, ICVSRemoteFolder remoteFolder) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
33         HasProjectMetaFileOperation op = new HasProjectMetaFileOperation(part, remoteFolder);
34         op.run();
35         return op.metaFileExists();
36     }
37     
38     public HasProjectMetaFileOperation(IWorkbenchPart part, ICVSRemoteFolder remoteFolder) {
39         super(part);
40         this.remoteFolder = remoteFolder;
41     }
42     
43     /*
44      * Return true if the provided remote folder contains a valid meta-file
45      * (i.e. .project file).
46      */

47     private boolean hasMetaFile(ICVSRemoteFolder folder, IProgressMonitor monitor) throws CVSException {
48         
49         // make a copy of the folder so that we will not effect the original folder when we refetch the members
50
// TODO: this is a strange thing to need to do. We shold fix this.
51
folder = (ICVSRemoteFolder)folder.forTag(remoteFolder.getTag());
52
53         try {
54             folder.members(monitor);
55         } catch (TeamException e) {
56             throw CVSException.wrapException(e);
57         }
58         // Check for the existance of the .project file
59
try {
60             folder.getFile(".project"); //$NON-NLS-1$
61
return true;
62         } catch (TeamException e) {
63             // We couldn't retrieve the meta file so assume it doesn't exist
64
}
65         return false;
66     }
67
68     /* (non-Javadoc)
69      * @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
70      */

71     public void execute(IProgressMonitor monitor) throws CVSException, InterruptedException JavaDoc {
72         metaFileExists = hasMetaFile(remoteFolder, monitor);
73     }
74     
75     /**
76      * Return true if the meta file exists remotely. This method should only be invoked
77      * after the operation has been executed;
78      * @return
79      */

80     public boolean metaFileExists() {
81         return metaFileExists;
82     }
83
84     protected String JavaDoc getTaskName() {
85         return CVSUIMessages.HasProjectMetaFile_taskName; //$NON-NLS-1$
86
}
87     
88     /* (non-Javadoc)
89      * @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#canRunAsJob()
90      */

91     public boolean canRunAsJob() {
92         // This operation should never be run in the background.
93
return false;
94     }
95
96 }
97
Popular Tags