Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0ea73a7abfbc20d9055a85b72104ee3d8d8963d0 (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
/*******************************************************************************
 * Copyright (c) 2000, 2018 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.tags;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.team.internal.ccvs.core.*;
import org.eclipse.ui.model.IWorkbenchAdapter;

/**
 * A workbench adapter that can be used to view the resources that make up 
 * a tag source. It is used by the TagConfigurationDialog.
 */
public class TagSourceResourceAdapter implements IAdaptable, IWorkbenchAdapter {

    public static Object getViewerInput(TagSource tagSource) {
        return new TagSourceResourceAdapter(tagSource);
    }
    
    TagSource tagSource;

    private TagSourceResourceAdapter(TagSource tagSource) {
        this.tagSource = tagSource;
    }
  
    public Object[] getChildren(Object o) {
        ICVSResource[] children = tagSource.getCVSResources();
        if (children.length == 0) return new Object[0];
        List result = new ArrayList();
        for (int i = 0; i < children.length; i++) {
            ICVSResource resource = children[i];
            if (resource.isFolder()) {
                result.add(new CVSFolderElement((ICVSFolder)resource, false));
            } else {
                result.add(new CVSFileElement((ICVSFile)resource));
            }
        }
        return result.toArray(new Object[result.size()]);
    }

    public ImageDescriptor getImageDescriptor(Object object) {
        // No image descriptor
        return null;
    }

    public String getLabel(Object o) {
        return tagSource.getShortDescription();
    }

    public Object getParent(Object o) {
        // No parent
        return null;
    }

    public <T> T getAdapter(Class<T> adapter) {
        if (adapter == IWorkbenchAdapter.class) {
            return adapter.cast(this);
        }
        return null;
    }

}

Back to the top