Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 88f77ceb719942aa6a070976d779a7293392c5d1 (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
/*******************************************************************************
 * Copyright (c) 2003, 2005 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.wst.server.ui.internal.viewers;

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

import org.eclipse.wst.server.core.*;
/**
 * Runtime type content provider.
 */
public class RuntimeTypeTreeContentProvider extends AbstractTreeContentProvider {
	public static final byte STYLE_VENDOR = 1;
	public static final byte STYLE_VERSION = 2;
	public static final byte STYLE_MODULE_TYPE = 3;
	
	protected boolean creation;
	protected String type;
	protected String version;
	protected String runtimeTypeId;

	/**
	 * RuntimeTypeContentProvider constructor.
	 * 
	 * @param style a style
	 * @param creation true to include runtimes that can be created
	 */
	public RuntimeTypeTreeContentProvider(byte style, boolean creation) {
		super(style);
		this.creation = creation;
	}
	
	public RuntimeTypeTreeContentProvider(byte style, boolean creation, String type, String version, String runtimeTypeId) {
		super(style, false);
		this.type = type;
		this.version = version;
		this.runtimeTypeId = runtimeTypeId;
		this.creation = creation;
		
		fillTree();
	}
	
	public void fillTree() {
		clean();
		List list = new ArrayList();
		if (style != STYLE_FLAT) {
			IRuntimeType[] runtimeTypes = ServerUtil.getRuntimeTypes(type, version, runtimeTypeId);
			if (runtimeTypes != null) {
				int size = runtimeTypes.length;
				for (int i = 0; i < size; i++) {
					IRuntimeType runtimeType = runtimeTypes[i];
					if (!creation || runtimeType.canCreate()) {
						TreeElement ele = null;
						if (style == STYLE_VENDOR) {
							ele = getOrCreate(list, runtimeType.getVendor());
							ele.contents.add(runtimeType);
							elementToParentMap.put(runtimeType, ele);
						} else if (style == STYLE_VERSION) {
							ele = getOrCreate(list, runtimeType.getVersion());
							ele.contents.add(runtimeType);
							elementToParentMap.put(runtimeType, ele);
						} else if (style == STYLE_MODULE_TYPE) {
							// TODO: does not handle "jst.*" format
							IModuleType[] moduleTypes = runtimeType.getModuleTypes();
							if (moduleTypes != null) {
								int size2 = moduleTypes.length;
								for (int j = 0; j < size2; j++) {
									IModuleType mb = moduleTypes[j];
									if (mb != null) {
										ele = getOrCreate(list, mb.getName());
										TreeElement ele2 = getOrCreate(ele.contents, mb.getName() + "/" + mb.getVersion(), mb.getVersion());
										ele2.contents.add(runtimeType);
										elementToParentMap.put(runtimeType, ele2);
										elementToParentMap.put(ele2, ele);
									}
								}
							}
						}
					}
				}
			}
		} else {
			IRuntimeType[] runtimeTypes = ServerUtil.getRuntimeTypes(type, version, runtimeTypeId);
			if (runtimeTypes != null) {
				int size = runtimeTypes.length;
				for (int i = 0; i < size; i++) {
					IRuntimeType runtimeType = runtimeTypes[i];
					if (!creation || runtimeType.canCreate())
						list.add(runtimeType);
				}
			}
		}
		elements = list.toArray();
	}
}

Back to the top