Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 00d5b6107ba9b71ee7ba0546a413ba01fb07fd61 (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
/*******************************************************************************
 * Copyright (c) 2008 QNX Software Systems 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:
 * QNX Software Systems - Initial API and implementation
 * QNX Software Systems - catchpoints - bug 226689
 *******************************************************************************/
package org.eclipse.cdt.debug.ui.breakpoints;

import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.debug.ui.preferences.ReadOnlyFieldEditor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.swt.widgets.Composite;

class DefaultCBreakpointUIContribution implements ICBreakpointsUIContribution {
    
    private final IConfigurationElement fConfig;
    private String mainElement;
	private String attLabel;
	private String attId;
	private String fieldEditorClassName;
	private String fieldEditorFactoryClass;
	private IFieldEditorFactory fieldEditorFactory;
	private String markerType;
	private String modelId;
	private String attType;
	private Map<String, String> valueLabels = new LinkedHashMap<String, String>();
	private Map<String, String> conditions = new HashMap<String, String>();

	DefaultCBreakpointUIContribution(IConfigurationElement config) {
	    fConfig = config;
	}
	
	
	@Override
	public String getId() {
		return attId;
	}

	@Override
	public String getLabel() {
		return attLabel;
	}

	@Override
	public String getDebugModelId() {
		return modelId;
	}

	@Override
	public String getMainElement() {
	    return mainElement;
	}
	
	static private Class<?>[] fieldSignature = new Class[] { String.class, String.class,
			Composite.class };

	@Override
	public FieldEditor getFieldEditor(String name, String labelText, Composite parent) {
        if (fieldEditorFactory != null) {
            return fieldEditorFactory.createFieldEditor(name, labelText, parent);
        } else if (fieldEditorFactoryClass != null) {
            try {
                fieldEditorFactory = (IFieldEditorFactory) fConfig.createExecutableExtension("fieldEditorFactory"); //$NON-NLS-1$
            } catch (CoreException e) {
                CDebugUIPlugin.log(e);
                return null;
            } 
            return fieldEditorFactory.createFieldEditor(name, labelText, parent);
        } else if (fieldEditorClassName != null) {
            try {
                @SuppressWarnings("unchecked")
                Class<FieldEditor> cclass = (Class<FieldEditor>)Class.forName(fieldEditorClassName);
                Constructor<FieldEditor> constructor = cclass.getConstructor(fieldSignature);
                FieldEditor editor = constructor.newInstance(name, labelText, parent);
                if (editor instanceof ICBreakpointsUIContributionUser) {
                    ((ICBreakpointsUIContributionUser)editor).setContribution(this);
                }
                return editor;
            } catch (Exception e) {
                CDebugUIPlugin.log(e);
                return null;
            }
        } else {
            return new ReadOnlyFieldEditor(name, labelText, parent);
        }
	}

	@Override
	public String getLabelForValue(String value) {
		if (valueLabels.containsKey(value))
			return valueLabels.get(value);
		return value;
	}

	@Override
	public String getMarkerType() {
		return markerType;
	}

	@Override
	public String[] getPossibleValues() {
		Set<String> set = valueLabels.keySet();
		return set.toArray(new String[set.size()]);
	}

	@Override
	public String getType() {
		return attType;
	}

	@Override
	public boolean isApplicable(Map<String, Object> properties) {
		for (Object key : properties.keySet()) {
			String value = conditions.get(key);
			if (value != null) {
				String realValue = (String) properties.get(key);
				if (!value.equals(realValue)) {
					return false;
				}
			}
		}
		return true;
	}

	public void setMainElement(String mainElement) {
	    this.mainElement = mainElement;
	}
	
	public void setLabel(String attLabel) {
		this.attLabel = attLabel;
	}

	public void setId(String attId) {
		this.attId = attId;
	}

	public void setControlClass(String controlClass) {
		this.fieldEditorClassName = controlClass;
	}
	
	public void setFieldEditorFactory(String factoryClass) {
	    fieldEditorFactoryClass = factoryClass;
	}

	public void setMarkerType(String markerId) {
		this.markerType = markerId;
	}

	public void setDebugModelId(String modelId) {
		this.modelId = modelId;
	}

	public void setType(String attType) {
		this.attType = attType;
	}

	public void addValue(String value, String valueLabel) {
		valueLabels.put(value, valueLabel);
	};

	public void addContionEquals(String property, String value) {
		conditions.put(property, value);
	}

	public void setVisible(boolean visible) {
		// TODO Auto-generated method stub

	}

	public Map<String, String> getConditions() {
		return conditions;
	}

	public void addContionsAll(Map<String, String> conditions2) {
		conditions.putAll(conditions2);
	}

	@Override
	public String toString() {
		return attId + " " + attLabel; //$NON-NLS-1$
	}

	@Override
	public String getFieldEditorClassName() {
		return fieldEditorClassName;
	}
}

Back to the top