Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fce52463f28105dc39ff0edad768dd8359f6f2fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.model;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.ccvs.core.*;
import org.eclipse.team.internal.ccvs.ui.*;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
import org.eclipse.ui.progress.IElementCollector;

public class VersionCategory extends CVSModelElement implements IAdaptable,
        IDeferredWorkbenchAdapter {
    private ICVSRepositoryLocation repository;

    /**
     * ProjectVersionsCategory constructor.
     */
    public VersionCategory(ICVSRepositoryLocation repo) {
        super();
        this.repository = repo;
    }

    /**
     * Returns an object which is an instance of the given class associated with
     * this object. Returns <code>null</code> if no such object can be found.
     */
    public Object getAdapter(Class adapter) {
        if (adapter == IWorkbenchAdapter.class)
            return this;
        if (adapter == IDeferredWorkbenchAdapter.class)
            return this;
        return null;
    }

    /**
     * Returns the children of this object. When this object is displayed in a
     * tree, the returned objects will be this element's children. Returns an
     * empty enumeration if this object has no children.
     */
    public Object[] fetchChildren(Object o, IProgressMonitor monitor)
            throws TeamException {
        if (CVSUIPlugin.getPlugin().getRepositoryManager()
                .isDisplayingProjectVersions(repository)) {
            return getProjectVersionChildren(o, monitor);
        } else {
            return getVersionTagChildren(o, monitor);
        }
    }

    /*
     * Return the children as a list of versions whose children are projects
     */
    private Object[] getVersionTagChildren(Object o, IProgressMonitor monitor)
            throws CVSException {
        CVSTag[] tags = CVSUIPlugin.getPlugin().getRepositoryManager()
                .getKnownTags(repository, getWorkingSet(), CVSTag.VERSION, monitor);
        CVSTagElement[] versionElements = new CVSTagElement[tags.length];
        for (int i = 0; i < tags.length; i++) {
            versionElements[i] = new CVSTagElement(tags[i], repository);
        }
        return versionElements;
    }

    /*
     * Return the children as a list of projects whose children ar project
     * versions
     */
    private Object[] getProjectVersionChildren(Object o,
            IProgressMonitor monitor) throws TeamException {

        ICVSRemoteResource[] resources = CVSUIPlugin.getPlugin()
                .getRepositoryManager().getFoldersForTag(repository,
                        CVSTag.DEFAULT, monitor);
        if (getWorkingSet() != null)
            resources = CVSUIPlugin.getPlugin().getRepositoryManager()
                    .filterResources(getWorkingSet(), resources);
        Object[] modules = new Object[resources.length];
        for (int i = 0; i < resources.length; i++) {
            modules[i] = new RemoteModule((ICVSRemoteFolder) resources[i],
                    VersionCategory.this);
        }
        return modules;
    }

    /**
     * Returns an image descriptor to be used for displaying an object in the
     * workbench. Returns null if there is no appropriate image.
     * 
     * @param object The object to get an image descriptor for.
     */
    public ImageDescriptor getImageDescriptor(Object object) {
        return CVSUIPlugin.getPlugin().getImageDescriptor(
                ICVSUIConstants.IMG_VERSIONS_CATEGORY);
    }

    /**
     * Returns the name of this element. This will typically be used to assign a
     * label to this object when displayed in the UI. Returns an empty string if
     * there is no appropriate name for this object.
     * 
     * @param object The object to get a label for.
     */
    public String getLabel(Object o) {
        return CVSUIMessages.VersionCategory_Versions_1; 
    }

    /**
     * Returns the logical parent of the given object in its tree. Returns null
     * if there is no parent, or if this object doesn't belong to a tree.
     * 
     * @param object The object to get the parent for.
     */
    public Object getParent(Object o) {
        return repository;
    }

    /**
     * Return the repository the given element belongs to.
     */
    public ICVSRepositoryLocation getRepository(Object o) {
        return repository;
    }

    public void fetchDeferredChildren(Object o, IElementCollector collector,
            IProgressMonitor monitor) {
        try {
            collector.add(fetchChildren(o, monitor), monitor);
        } catch (TeamException e) {
            handle(collector, e);
        }
    }

    public boolean isContainer() {
        return true;
    }

    public ISchedulingRule getRule(Object element) {
        return new RepositoryLocationSchedulingRule(repository); 
    }
}

Back to the top