Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 25d2a2b45ccb460c49fcca36a278886e83777c64 (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
/*******************************************************************************
 * 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.managedbuilder.ui.properties;

import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICMultiConfigDescription;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.internal.core.MultiConfiguration;
import org.eclipse.cdt.ui.newui.AbstractCPropertyTab;
import org.eclipse.core.runtime.IPath;

/**
 * Proposed parent for Build System property tabs.
 * 
 * In addition to AbstractCPropertyTab functionality,
 * provides several utility methods for configurations
 * handling.
 */
public abstract class AbstractCBuildPropertyTab extends AbstractCPropertyTab {
	public IConfiguration getConfigurationFromHoldsOptions(IHoldsOptions ho){
		if(ho instanceof IToolChain)
			return ((IToolChain)ho).getParent();
		else if(ho instanceof ITool)
			return getConfigurationFromTool((ITool)ho);
		return null;
	}
	public IConfiguration getConfigurationFromTool(ITool tool){
		return tool.getParentResourceInfo().getParent();
	}
	
	public IConfiguration getCfg() {
		return getCfg(getResDesc().getConfiguration());
	}
	public IConfiguration getCfg(ICConfigurationDescription cfgd) {
		if (cfgd instanceof ICMultiConfigDescription) {
			ICConfigurationDescription[] cfds = (ICConfigurationDescription[])((ICMultiConfigDescription)cfgd).getItems();
			return new MultiConfiguration(cfds, 9);
		} else 
			return ManagedBuildManager.getConfigurationForDescription(cfgd);
	}

	/**
	 * Returns ResourceInfo for given ResourceDescription.
	 * Creates resourceInfo if it has not exist before.
	 * @param cfgd
	 * @return
	 */
	public IResourceInfo getResCfg(ICResourceDescription cfgd) {
		IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cfgd.getConfiguration());
		
		if (page.isForProject()) 
			return cfg.getRootFolderInfo();
		
		IPath p = cfgd.getPath();
		IResourceInfo f = null;
		f = cfg.getResourceInfo(p, false);
		
		if (f != null && (!p.equals(f.getPath()))) {
			String s = p.toString().replace('/', '_').replace('\\', '_');
			if (page.isForFile()) 
				f = cfg.createFileInfo(p, (IFolderInfo)f, null,
						f.getId()+ s, f.getName() + s);
			else
				f = cfg.createFolderInfo(p, (IFolderInfo)f, 
						f.getId() + s, f.getName() + s);
		}
		if (f == null) {
			if (page.isForFile()) 
				f = cfg.createFileInfo(p);
			
			else
				f = cfg.createFolderInfo(p);
		}
		return f;
	}
}

Back to the top