KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > model > RemoteFolderElement


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
12 package org.eclipse.team.internal.ccvs.ui.model;
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.jobs.ISchedulingRule;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.osgi.util.NLS;
18 import org.eclipse.team.core.TeamException;
19 import org.eclipse.team.internal.ccvs.core.*;
20 import org.eclipse.team.internal.ccvs.ui.*;
21 import org.eclipse.team.internal.ccvs.ui.Policy;
22 import org.eclipse.team.internal.ccvs.ui.operations.FetchMembersOperation;
23 import org.eclipse.ui.ISharedImages;
24 import org.eclipse.ui.PlatformUI;
25 import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
26 import org.eclipse.ui.progress.IElementCollector;
27
28 public class RemoteFolderElement extends RemoteResourceElement implements IDeferredWorkbenchAdapter {
29
30     /**
31      * Overridden to append the version name to remote folders which
32      * have version tags and are top-level folders.
33      */

34     public String JavaDoc getLabel(Object JavaDoc o) {
35         if (!(o instanceof ICVSRemoteFolder))
36             return null;
37         ICVSRemoteFolder folder = (ICVSRemoteFolder) o;
38         CVSTag tag = folder.getTag();
39         if (tag != null && tag.getType() != CVSTag.HEAD) {
40             if (folder.getRemoteParent() == null) {
41                 return NLS.bind(CVSUIMessages.RemoteFolderElement_nameAndTag, new String JavaDoc[] { folder.getName(), tag.getName() });
42             }
43         }
44         return folder.getName();
45     }
46
47     public ImageDescriptor getImageDescriptor(Object JavaDoc object) {
48         if (!(object instanceof ICVSRemoteFolder))
49             return null;
50         ICVSRemoteFolder folder = (ICVSRemoteFolder) object;
51         if (folder.isDefinedModule()) {
52             return CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_MODULE);
53         }
54         return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER);
55     }
56
57     public Object JavaDoc[] fetchChildren(Object JavaDoc o, IProgressMonitor monitor) throws TeamException {
58         if (!(o instanceof ICVSRemoteFolder))
59             return new Object JavaDoc[0];
60         return ((ICVSRemoteFolder) o).members(monitor);
61     }
62
63     public void fetchDeferredChildren(Object JavaDoc o, IElementCollector collector, IProgressMonitor monitor) {
64         // If it's not a folder, return an empty array
65
if (!(o instanceof ICVSRemoteFolder)) {
66             collector.add(new Object JavaDoc[0], monitor);
67         }
68         try {
69             monitor = Policy.monitorFor(monitor);
70             monitor.beginTask(NLS.bind(CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren, new String JavaDoc[] { getLabel(o) }), 100);
71             FetchMembersOperation operation = new FetchMembersOperation(null, (ICVSRemoteFolder)o, collector);
72             operation.run(Policy.subMonitorFor(monitor, 100));
73         } catch (InvocationTargetException JavaDoc e) {
74             handle(collector, e);
75         } catch (InterruptedException JavaDoc e) {
76             // Cancelled by the user;
77
} finally {
78             monitor.done();
79         }
80     }
81
82     public ISchedulingRule getRule(Object JavaDoc element) {
83         ICVSRepositoryLocation location = getRepositoryLocation(element);
84         return new RepositoryLocationSchedulingRule(location);
85     }
86
87     private ICVSRepositoryLocation getRepositoryLocation(Object JavaDoc o) {
88         if (!(o instanceof ICVSRemoteFolder))
89             return null;
90         return ((ICVSRemoteFolder)o).getRepository();
91     }
92
93     public boolean isContainer() {
94         return true;
95     }
96 }
97
Popular Tags