Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 530a17dd28bf72347fabdc0366cad1b3a3e9bf5d (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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*******************************************************************************
 * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * CONTRIBUTORS:
 * 		Henrik Rentz-Reichert (initial contribution)
 * 
 *******************************************************************************/

package org.eclipse.etrice.generator.launch;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.etrice.generator.base.AbstractGeneratorOptions;
import org.eclipse.etrice.generator.ui.preferences.PreferenceConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.preferences.ScopedPreferenceStore;

/**
 * @author Henrik Rentz-Reichert
 *
 */
public abstract class GeneratorConfigTab extends AbstractLaunchConfigurationTab {

	protected class UpdateConfig implements SelectionListener {
		public UpdateConfig() {
		}

		@Override
		public void widgetSelected(SelectionEvent e) {
			validate();
			setDirty(true);
			updateLaunchConfigurationDialog();
		}

		@Override
		public void widgetDefaultSelected(SelectionEvent e) {
			widgetSelected(e);
		}
	}

	public static final String GEN_MODEL_PATH = "GenModelPath";
	public static final String SAVE_GEN_MODEL = "SaveGenModel";
	public static final String MAIN_METHOD_NAME = "MainMethodName";
	public static final String LIB = "Lib";
	public static final String DEBUG = "Debug";
	public static final String MSC_INSTR = "MSC";
	public static final String VERBOSE = "Verbose";
	public static final String USE_TRAANSLATION = "UseTranslation";
	public static final String OLD_STYLE_TRANSITION_DATA = "OldStyleTransitionData";
	public static final String OVERRIDE_DIRECTORIES = "OverrideDirectories";
	public static final String GEN_DEPS_WITHIN_PROJECT = "GenerateDepsWithinProject";
	public static final String SRCGEN_PATH = "SrcgenPath";
	
	private Button libButton;
	private Button saveGenModel;
	private Text genModelPath;
	private Button debugButton;
	private Button mscButton;
	private Button verboseButton;
	private Button useTranslationButton;
	private Button generateDepsWithinProject;
	private Button overrideDirectories;
	private Text srcgenPath;
	private Text mainMethodName;
	private Button useOldStyleTransitionDataButton;

	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	public void createControl(Composite parent) {
		// Create main composite
		Composite mainComposite = new Composite(parent,SWT.NONE);
		setControl(mainComposite);
		
		GridLayout layout= new GridLayout();
		layout.numColumns = 2;
		layout.marginHeight = 10;
		layout.marginWidth = 10;
		mainComposite.setLayout(layout);
		
		libButton = createCheckButton(mainComposite, "generate all classes as library");
		libButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));
		libButton.addSelectionListener(new UpdateConfig());

		saveGenModel = createCheckButton(mainComposite, "save generator model");
		saveGenModel.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));
		saveGenModel.addSelectionListener(new SelectionListener() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				handleSaveGenModelSelected();
			}
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				handleSaveGenModelSelected();
			}
			
		});
		Label label = new Label(mainComposite, SWT.NONE);
		label.setText("The file name for the generator model:");
		genModelPath = new Text(mainComposite, SWT.SINGLE | SWT.BORDER);
    	genModelPath.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		genModelPath.addModifyListener(new ModifyListener() {
			@Override
			public void modifyText(ModifyEvent e) {
				validate();
				setDirty(true);
				updateLaunchConfigurationDialog();
			}
		});

		useTranslationButton = createCheckButton(mainComposite, "perform code translation");
		useTranslationButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));
		useTranslationButton.addSelectionListener(new UpdateConfig());

		useOldStyleTransitionDataButton = createCheckButton(mainComposite, "use old style transition data names");
		useOldStyleTransitionDataButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));
		useOldStyleTransitionDataButton.addSelectionListener(new UpdateConfig());

		debugButton = createCheckButton(mainComposite, "generate debug output");
		debugButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));
		debugButton.addSelectionListener(new UpdateConfig());

		mscButton = createCheckButton(mainComposite, "generate instrumentation for MSC logging");
		mscButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));
		mscButton.addSelectionListener(new UpdateConfig());
		
		verboseButton = createCheckButton(mainComposite, "generate instrumentation for verbose output");
		verboseButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));
		verboseButton.addSelectionListener(new UpdateConfig());
		
		label = new Label(mainComposite, SWT.NONE);
		label.setText("The main method name:");
		mainMethodName = new Text(mainComposite, SWT.SINGLE | SWT.BORDER);
		mainMethodName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		mainMethodName.addModifyListener(new ModifyListener() {
			@Override
			public void modifyText(ModifyEvent e) {
				validate();
				setDirty(true);
				updateLaunchConfigurationDialog();
			}
		});

		createSeparator(mainComposite, 2);
		
		generateDepsWithinProject = createCheckButton(mainComposite, "generate all .etmap dependencies within project");
		generateDepsWithinProject.setToolTipText("this options automatically generates all referenced model files in this project");
		generateDepsWithinProject.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));
		generateDepsWithinProject.addSelectionListener(new UpdateConfig());
		
		overrideDirectories = createCheckButton(mainComposite, "override generation directories");
		overrideDirectories.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));
		overrideDirectories.addSelectionListener(new SelectionListener() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				handleOverrideDirectories();
			}
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				handleOverrideDirectories();
			}
			
		});
		
		label = new Label(mainComposite, SWT.NONE);
		label.setText("The directory for &generated code:");
		srcgenPath = new Text(mainComposite, SWT.SINGLE | SWT.BORDER);
		srcgenPath.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		srcgenPath.addModifyListener(new ModifyListener() {
			@Override
			public void modifyText(ModifyEvent e) {
				validate();
				setDirty(true);
				updateLaunchConfigurationDialog();
			}
		});
		
		addFurtherControls(mainComposite);
	}

	/**
	 * @param mainComposite
	 */
	protected void addFurtherControls(Composite mainComposite) {
	}

	protected void handleSaveGenModelSelected() {
		boolean save = saveGenModel.getSelection();
		genModelPath.setEnabled(save);
		validate();
		setDirty(true);
		updateLaunchConfigurationDialog();
	}

	protected void handleOverrideDirectories() {
		boolean override = overrideDirectories.getSelection();
		srcgenPath.setEnabled(override);
		if (!override) {
			ScopedPreferenceStore prefStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.etrice.generator.ui");
			srcgenPath.setText(prefStore.getString(PreferenceConstants.GEN_DIR));
		}
		validate();
		setDirty(true);
		updateLaunchConfigurationDialog();
	}

	/**
	 * 
	 */
	protected void validate() {
		if (saveGenModel.getSelection())
			if (genModelPath.getText().trim().isEmpty()) {
				setErrorMessage("generator model path must not be empty");
				return;
			}
		setErrorMessage(null);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
	 */
	@Override
	public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
	 */
	@Override
	public void initializeFrom(ILaunchConfiguration configuration) {
		try {
			// defaults: org.eclipse.etrice.generator.base.GlobalGeneratorSettings
			libButton.setSelection(configuration.getAttribute(LIB, false));
			boolean save = configuration.getAttribute(SAVE_GEN_MODEL, false);
			saveGenModel.setSelection(save);
			genModelPath.setEnabled(save);
			genModelPath.setText(configuration.getAttribute(GEN_MODEL_PATH, ""));
			mainMethodName.setText(configuration.getAttribute(MAIN_METHOD_NAME, AbstractGeneratorOptions.MAIN_NAME.getDefaultValue()));
			debugButton.setSelection(configuration.getAttribute(DEBUG, false));
			mscButton.setSelection(configuration.getAttribute(MSC_INSTR, false));
			verboseButton.setSelection(configuration.getAttribute(VERBOSE, false));
			
			ScopedPreferenceStore prefStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.etrice.generator.ui");
			boolean useTranslation = prefStore.getBoolean(PreferenceConstants.GEN_USE_TRANSLATION);
			useTranslationButton.setSelection(configuration.getAttribute(USE_TRAANSLATION, useTranslation));
			
			boolean useOldStyleTransitionData = prefStore.getBoolean(PreferenceConstants.GEN_OLD_STYLE_TRANSITION_DATA);
			useOldStyleTransitionDataButton.setSelection(configuration.getAttribute(OLD_STYLE_TRANSITION_DATA, useOldStyleTransitionData));
			
			boolean override = configuration.getAttribute(OVERRIDE_DIRECTORIES, false);
			String srcgenDir = prefStore.getString(PreferenceConstants.GEN_DIR);
			overrideDirectories.setSelection(override);
			srcgenPath.setEnabled(override);
			if (override) {
				srcgenPath.setText(configuration.getAttribute(SRCGEN_PATH, srcgenDir));
			}
			else {
				srcgenPath.setText(srcgenDir);
			}
			
			generateDepsWithinProject.setSelection(configuration.getAttribute(GEN_DEPS_WITHIN_PROJECT, true));
		}
		catch (CoreException e) {
			e.printStackTrace();
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
	 */
	@Override
	public void performApply(ILaunchConfigurationWorkingCopy configuration) {
		configuration.setAttribute(LIB, libButton.getSelection());
		configuration.setAttribute(SAVE_GEN_MODEL, saveGenModel.getSelection());
		configuration.setAttribute(GEN_MODEL_PATH, genModelPath.getText());
		configuration.setAttribute(MAIN_METHOD_NAME, mainMethodName.getText());
		configuration.setAttribute(DEBUG, debugButton.getSelection());
		configuration.setAttribute(MSC_INSTR, mscButton.getSelection());
		configuration.setAttribute(VERBOSE, verboseButton.getSelection());
		configuration.setAttribute(USE_TRAANSLATION, useTranslationButton.getSelection());
		configuration.setAttribute(OLD_STYLE_TRANSITION_DATA, useOldStyleTransitionDataButton.getSelection());
		
		boolean override = overrideDirectories.getSelection();
		configuration.setAttribute(OVERRIDE_DIRECTORIES, override);
		if (override) {
			configuration.setAttribute(SRCGEN_PATH, srcgenPath.getText());
		}
		
		configuration.setAttribute(GEN_DEPS_WITHIN_PROJECT, generateDepsWithinProject.getSelection());
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#canSave()
	 */
	@Override
	public boolean canSave() {
		if (saveGenModel.getSelection())
			return !genModelPath.getText().trim().isEmpty();
		
		return true;
	}

}

Back to the top