Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: be2e709363aff1b67b900994c250308cc5a79056 (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
/*******************************************************************************
 * Copyright (c) 2007 Intel 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:
 * Intel Corporation - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.core;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.cdt.core.settings.model.ICSettingBase;
import org.eclipse.cdt.core.settings.model.util.IPathSettingsContainerVisitor;
import org.eclipse.cdt.core.settings.model.util.PathSettingsContainer;
import org.eclipse.cdt.managedbuilder.core.IFileInfo;
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
import org.eclipse.core.runtime.IPath;

public class ResourceInfoContainer {
	private PathSettingsContainer fRcDataContainer;
	private boolean fIncludeCurrent;
	
	public ResourceInfoContainer(PathSettingsContainer pathSettings, boolean includeCurrent){
		fRcDataContainer = pathSettings;
		fIncludeCurrent = includeCurrent;
	}
	
	public void changeCurrentPath(IPath path, boolean moveChildren){
		fRcDataContainer.setPath(path, moveChildren);
	}
	
	public IPath getCurrentPath(){
		return fRcDataContainer.getPath();
	}
	
	public IResourceInfo getCurrentResourceInfo(){
		return (IResourceInfo)fRcDataContainer.getValue();
	}
	
	public IResourceInfo getResourceInfo(IPath path, boolean exactPath) {
		PathSettingsContainer cr = fRcDataContainer.getChildContainer(path, false, exactPath);
		if(cr != null)
			return (IResourceInfo)cr.getValue();
		return null;
	}

	public IResourceInfo[] getResourceInfos(Class clazz) {
		return getResourceInfos(ICSettingBase.SETTING_FILE | ICSettingBase.SETTING_FOLDER, clazz);
	}

	public IResourceInfo[] getResourceInfos() {
		return getResourceInfos(ICSettingBase.SETTING_FILE | ICSettingBase.SETTING_FOLDER);
	}

	public IResourceInfo[] getResourceInfos(final int kind) {
		return getResourceInfos(kind, IResourceInfo.class);
	}
	
	public IResourceInfo[] getResourceInfos(int kind, Class clazz){
		List<IResourceInfo> list = getRcInfoList(kind);

		IResourceInfo datas[] = (IResourceInfo[])Array.newInstance(clazz, list.size());
		
		return list.toArray(datas);
	}

	public IResourceInfo[] getDirectChildResourceInfos(){
		PathSettingsContainer[] children = fRcDataContainer.getDirectChildren();
		
		IResourceInfo datas[] = new IResourceInfo[children.length];
		
		for(int i = 0; i < datas.length; i++){
			datas[i] = (IResourceInfo)children[i].getValue();
		}
		
		return datas;
	}

	public List<IResourceInfo> getRcInfoList(final int kind){
		return getRcInfoList(kind, fIncludeCurrent);
	}		
	
	public List<IResourceInfo> getRcInfoList(final int kind, final boolean includeCurrent){
		final List<IResourceInfo> list = new ArrayList<IResourceInfo>(); 
		fRcDataContainer.accept(new IPathSettingsContainerVisitor(){

			public boolean visit(PathSettingsContainer container) {
				if(includeCurrent || container != fRcDataContainer){
					IResourceInfo data = (IResourceInfo)container.getValue();
					if((data.getKind() & kind) == data.getKind())
						list.add(data);
				}
				return true;
			}
		});
		
		return list;
	}

	public IResourceInfo getResourceInfo(IPath path, boolean exactPath, int kind){
		IResourceInfo data = getResourceInfo(path, exactPath);
		if(data != null && (data.getKind() & kind) == data.getKind())
			return data;
		return null;
	}

	public void removeResourceInfo(IPath path) {
		fRcDataContainer.removeChildContainer(path);
	}
	
	public void addResourceInfo(IResourceInfo data){
		PathSettingsContainer cr = fRcDataContainer.getChildContainer(data.getPath(), true, true);
		cr.setValue(data);
	}
	
	public IFileInfo getFileInfo(IPath path){
		return (IFileInfo)getResourceInfo(path, true, ICSettingBase.SETTING_FILE);
	}
	
	public IFolderInfo getFolderInfo(IPath path){
		return (IFolderInfo)getResourceInfo(path, true, ICSettingBase.SETTING_FOLDER);
	}
}

Back to the top