Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 96901d929a8d6ef85126806d15f640c50f3098e3 (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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*******************************************************************************
 * Copyright (c) 2007, 2008 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.internal.core.settings.model;

import java.util.List;

import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICFileDescription;
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICMultiResourceDescription;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.core.settings.model.ICSettingContainer;
import org.eclipse.cdt.core.settings.model.ICSettingObject;
import org.eclipse.cdt.core.settings.model.MultiItemsHolder;
import org.eclipse.cdt.core.settings.model.WriteAccessException;
import org.eclipse.core.runtime.IPath;

/**
 * This class represents multi-resource holder
 */
public abstract class MultiResourceDescription extends MultiItemsHolder implements ICMultiResourceDescription {
	ICResourceDescription[] fRess = null;
	ICConfigurationDescription fCfg = null;
	
	public MultiResourceDescription(ICResourceDescription[] res) {
		fRess = res;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.settings.model.ICResourceDescription#canExclude(boolean)
	 * 
	 * returns TRUE only if all res.configurations return true  
	 */
	public boolean canExclude(boolean exclude) {
		for (int i=0; i<fRess.length; i++)
			if (! fRess[i].canExclude(exclude))
				return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.settings.model.ICResourceDescription#getParentFolderDescription()
	 */
	public ICFolderDescription getParentFolderDescription() {
		if (DEBUG)
			System.out.println("Bad multi access: MultiResourceDescription.getParentFolderDescription()"); //$NON-NLS-1$
		throw new UnsupportedOperationException();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.settings.model.ICResourceDescription#getPath()
	 */
	public IPath getPath() {
		IPath p = fRess[0].getPath();
		if (p != null) {
			for (int i=1; i<fRess.length; i++) {
				if (!p.equals(fRess[i].getPath()))
					throw new UnsupportedOperationException();
			}
			return p;
		}
		throw new UnsupportedOperationException();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.settings.model.ICResourceDescription#isExcluded()
	 */
	public boolean isExcluded() {
		for (int i=0; i<fRess.length; i++)
			if (! fRess[i].isExcluded())
				return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.settings.model.ICResourceDescription#setExcluded(boolean)
	 */
	public void setExcluded(boolean excluded) throws WriteAccessException {
		for (int i=0; i<fRess.length; i++)
			fRess[i].setExcluded(excluded);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.settings.model.ICResourceDescription#setPath(org.eclipse.core.runtime.IPath)
	 */
	public void setPath(IPath path) throws WriteAccessException {
		for (int i=0; i<fRess.length; i++)
			fRess[i].setPath(path);			
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.settings.model.ICSettingContainer#getChildSettings()
	 */
	public ICSettingObject[] getChildSettings() {
		if (DEBUG)
			System.out.println("Bad multi access: MultiResourceDescription.getChildSettings()"); //$NON-NLS-1$
		throw new UnsupportedOperationException();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.settings.model.ICSettingObject#getConfiguration()
	 * 
	 * returns multi-configuration object 
	 */
	public ICConfigurationDescription getConfiguration() {
		if (fCfg == null) {
			ICConfigurationDescription[] cfgs = new ICConfigurationDescription[fRess.length];
			for (int i=0; i<fRess.length; i++)
				cfgs[i] = fRess[i].getConfiguration();
			fCfg = new MultiConfigDescription(cfgs);
		}
		return fCfg; 
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.settings.model.ICSettingObject#getId()
	 */
	public String getId() {
		return fRess[0].getId() + "_etc"; //$NON-NLS-1$
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.settings.model.ICSettingObject#getName()
	 */
	public String getName() {
		return "Multiple Resource Description"; //$NON-NLS-1$
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.settings.model.ICSettingObject#getParent()
	 * 
	 * If there's the same parent for all res cfgs, return it.
	 * Else return null;
	 */
	public ICSettingContainer getParent() {
		ICSettingContainer sc = fRess[0].getParent();
		if (sc == null)
			return null;
		for (int i=1; i<fRess.length; i++) 
			if (!sc.equals(fRess[i].getParent()))
				return null;
		return sc;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.settings.model.ICSettingObject#getType()
	 * 
	 * If there's the same type for all res cfgs, return it.
	 * Else return null;
	 */
	public int getType() {
		int t = fRess[0].getType();
		for (int i=1; i<fRess.length; i++)
			if (t != fRess[i].getType())
				return 0; 
		return t;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.settings.model.ICSettingObject#isReadOnly()
	 */
	public boolean isReadOnly() {
		for (int i=0; i<fRess.length; i++)
			if (! fRess[i].isReadOnly())
				return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.settings.model.ICSettingObject#isValid()
	 */
	public boolean isValid() {
		for (int i=0; i<fRess.length; i++)
			if (! fRess[i].isValid())
				return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.settings.model.ICMultiItemsHolder#getItems()
	 */
	@Override
	public Object[] getItems() {
		return fRess;
	}
	
	public void setSettingEntries(ICLanguageSetting lang, int kind, List<ICLanguageSettingEntry> incs, boolean toAll) {
		for (int i=0; i<fRess.length; i++) {
			if (fRess[i] instanceof ICFolderDescription) {
				String n = lang.getName();
				ICLanguageSetting[] l = ((ICFolderDescription)fRess[i]).getLanguageSettings();
				for (int j=0; j<l.length; j++) {
					if (toAll || n.equals(l[j].getName())) { 
						l[j].setSettingEntries(kind, incs);
						break;
					}
				}
			} else if (fRess[i] instanceof ICFileDescription) {
				ICLanguageSetting l = ((ICFileDescription)fRess[i]).getLanguageSetting();
				if (l.getName().equals(lang.getName())) 
					l.setSettingEntries(kind, incs);
			}
		}
	}
}

Back to the top