Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 749a4ed509185a4b9559c2a9e2f5f15829839e06 (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
/*******************************************************************************
 * Copyright (c) 2012 Wind River Systems, Inc. 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/

package org.eclipse.tcf.te.launch.ui.model;

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

import org.eclipse.core.runtime.Assert;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.tcf.te.launch.core.lm.LaunchConfigHelper;
import org.eclipse.tcf.te.launch.core.lm.LaunchManager;
import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate;
import org.eclipse.tcf.te.runtime.model.ContainerModelNode;
import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;

/**
 * LaunchNode
 */
public class LaunchNode extends ContainerModelNode {

	public static final String TYPE_ROOT = "root"; //$NON-NLS-1$
	public static final String TYPE_LAUNCH_CONFIG_TYPE = "launchConfigType"; //$NON-NLS-1$
	public static final String TYPE_LAUNCH_CONFIG = "launchConfig"; //$NON-NLS-1$

	private static final String PROPERTY_MODEL = "model"; //$NON-NLS-1$

	private LaunchNode(String type) {
		super();
		setProperty(IModelNode.PROPERTY_TYPE, type);
	}

	public LaunchNode(LaunchModel model) {
		this(TYPE_ROOT);
		setProperty(PROPERTY_MODEL, model);
	}

	public LaunchNode(ILaunchConfiguration config) {
		this(TYPE_LAUNCH_CONFIG);
		setProperty(TYPE_LAUNCH_CONFIG, config);
	}

	public LaunchNode(ILaunchConfigurationType configType) {
		this(TYPE_LAUNCH_CONFIG_TYPE);
		setProperty(TYPE_LAUNCH_CONFIG_TYPE, configType);
	}

	public String getType() {
		return getStringProperty(IModelNode.PROPERTY_TYPE);
	}

	public LaunchModel getModel() {
		LaunchModel model = (LaunchModel)getProperty(PROPERTY_MODEL);
		IModelNode parent = getParent();

		while (model == null && parent != null) {
			model = (LaunchModel)parent.getProperty(PROPERTY_MODEL);
			parent = parent.getParent();
		}

		Assert.isNotNull(model);
		return model;
	}

	public ILaunchConfiguration getLaunchConfiguration() {
		if (TYPE_LAUNCH_CONFIG.equals(getType())) {
			return (ILaunchConfiguration)getProperty(TYPE_LAUNCH_CONFIG);
		}
		return null;
	}

	public ILaunchConfigurationType getLaunchConfigurationType() {
		if (TYPE_LAUNCH_CONFIG.equals(getType())) {
			return ((LaunchNode)getParent()).getLaunchConfigurationType();
		}
		else if (TYPE_LAUNCH_CONFIG_TYPE.equals(getType())) {
			return (ILaunchConfigurationType)getProperty(TYPE_LAUNCH_CONFIG_TYPE);
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.runtime.model.ModelNode#getName()
	 */
	@Override
	public String getName() {
		if (TYPE_ROOT.equals(getType())) {
			return "Launches"; //$NON-NLS-1$
		}
		else if (TYPE_LAUNCH_CONFIG_TYPE.equals(getType())) {
			return getLaunchConfigurationType().getName();
		}
		else if (TYPE_LAUNCH_CONFIG.equals(getType())) {
			return getLaunchConfiguration().getName();
		}
		return super.getName();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.runtime.properties.PropertiesContainer#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof LaunchNode && getType() != null && getType().equals(((LaunchNode)obj).getType())) {
			if (TYPE_LAUNCH_CONFIG_TYPE.equals(getType())) {
				return getLaunchConfigurationType().equals(((LaunchNode)obj).getLaunchConfigurationType());
			}
			else if (TYPE_LAUNCH_CONFIG.equals(getType())) {
				return getLaunchConfiguration().equals(((LaunchNode)obj).getLaunchConfiguration());
			}
		}
		return super.equals(obj);
	}

	public boolean isValidFor(String mode) {
		if (TYPE_LAUNCH_CONFIG.equals(getType())) {
			List<String> modes;
			if (mode != null && mode.trim().length() > 0) {
				modes = new ArrayList<String>();
				modes.add(mode);
			}
			else {
				modes = Arrays.asList(LaunchConfigHelper.getLaunchConfigTypeModes(getLaunchConfigurationType(), false));
			}
			for (String m : modes) {
				if (!getLaunchConfigurationType().supportsMode(m)) {
					return false;
				}
				ILaunchManagerDelegate delegate = LaunchManager.getInstance().getLaunchManagerDelegate(getLaunchConfigurationType(), m);
				if (delegate != null) {
					try {
						delegate.validate(mode, getLaunchConfiguration());
					}
					catch (Exception e) {
						return false;
					}
				}
			}
		}
		return true;
	}
}

Back to the top