Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1e867a57d92dfba3fab31f2b322be22e8ecfdd98 (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
/*******************************************************************************
* Copyright (c) 2010 Oracle. 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:
*     Oracle - initial API and implementation
*******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.wizards.classesgen;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages;
import org.eclipse.swt.SWT;
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.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

/**
 *  ClassesGeneratorExtensionOptionsWizardPage
 */
public class ClassesGeneratorExtensionOptionsWizardPage extends WizardPage
{
	
	private ExtensionOptionsComposite additionalArgsComposite;

	// ********** constructor **********

	protected ClassesGeneratorExtensionOptionsWizardPage() {
		super("Classes Generator Extension Options"); //$NON-NLS-1$
		
		this.initialize();
	}

	protected void initialize() {
		this.setTitle(JptJaxbUiMessages.ClassesGeneratorExtensionOptionsWizardPage_title);
		this.setDescription(JptJaxbUiMessages.ClassesGeneratorExtensionOptionsWizardPage_desc);
	}

	// ********** UI components **********

	public void createControl(Composite parent) {
		this.setPageComplete(true);
		this.setControl(this.buildTopLevelControl(parent));
	}

	private Control buildTopLevelControl(Composite parent) {
		Composite composite = new Composite(parent, SWT.NULL);
		composite.setLayout(new GridLayout());

		this.additionalArgsComposite = new ExtensionOptionsComposite(composite);
		
		return composite;
	}

	// ********** intra-wizard methods **********

	protected boolean allowsExtensions() {
		return this.additionalArgsComposite.allowsExtensions();
	}
	
	protected String getClasspath() {
		return this.additionalArgsComposite.getClasspath();
	}
	
	protected String getAdditionalArgs() {
		return this.additionalArgsComposite.getAdditionalArgs();
	}

	// ********** AdditionalArgsComposite **********

	class ExtensionOptionsComposite {

		private boolean allowsExtensions;
		private final Text classpathText;
		private final Button allowsExtensionsCheckBox;
		
		private final Text additionalArgsText;
		
		// ********** constructor **********
	
		private ExtensionOptionsComposite(Composite parent) {
			super();
			this.allowsExtensions = false;
			
			Composite composite = new Composite(parent, SWT.NONE);
			GridLayout layout = new GridLayout(1, false);
			layout.marginHeight = 0;
			layout.marginWidth = 0;
			composite.setLayout(layout);
			composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
			// TODO PlatformUI.getWorkbench().getHelpSystem().setHelp(this.group, JpaHelpContextIds.XXX);
			
			this.allowsExtensionsCheckBox = this.buildAllowsExtensionsCheckBox(composite, this.buildAllowsExtensionsSelectionListener());

			// Classpath
			Label classpathLabel = new Label(composite, SWT.NONE);
			classpathLabel.setText(JptJaxbUiMessages.ClassesGeneratorExtensionOptionsWizardPage_classpath);
			GridData gridData = new GridData();
			gridData.verticalIndent = 5;
			classpathLabel.setLayoutData(gridData);
			this.classpathText = this.buildClasspathText(composite);
			
			Label additionalArgsLabel = new Label(composite, SWT.NONE);
			additionalArgsLabel.setText(JptJaxbUiMessages.ClassesGeneratorExtensionOptionsWizardPage_additionalArguments);
			gridData = new GridData();
			gridData.verticalIndent = 5;
			additionalArgsLabel.setLayoutData(gridData);
			this.additionalArgsText = this.buildAdditionalArgsText(composite);
		}
		
		// ********** UI components **********
		
		private Button buildAllowsExtensionsCheckBox(Composite parent, SelectionListener listener) {
			Button checkBox = new Button(parent, SWT.CHECK);
			GridData gridData = new GridData();
			gridData.verticalIndent = 5;
			checkBox.setLayoutData(gridData);
			checkBox.setText(JptJaxbUiMessages.ClassesGeneratorExtensionOptionsWizardPage_allowExtensions);
			checkBox.setSelection(this.allowsExtensions());
			checkBox.addSelectionListener(listener);
			return checkBox;
		}

		private Text buildClasspathText(Composite parent) {
			Text text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
			GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
			gridData.horizontalSpan = 1;
			gridData.verticalIndent = 1;
			gridData.heightHint = text.getLineHeight() * 3;
			gridData.grabExcessHorizontalSpace = true;
			text.setLayoutData(gridData);
			return text;
		}

		private Text buildAdditionalArgsText(Composite parent) {
			Text text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
			GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
			gridData.horizontalSpan = 1;
			gridData.verticalIndent = 1;
			gridData.heightHint = text.getLineHeight() * 10;
			gridData.grabExcessHorizontalSpace = true;
			text.setLayoutData(gridData);
			return text;
		}

		// ********** listeners **********

		private SelectionListener buildAllowsExtensionsSelectionListener() {
			return new SelectionListener() {
				public void widgetDefaultSelected(SelectionEvent event) {
					this.widgetSelected(event);
				}
				public void widgetSelected(SelectionEvent event) {
					ExtensionOptionsComposite.this.setAllowsExtensions(
						ExtensionOptionsComposite.this.allowsExtensionsCheckBox.getSelection());
				}
			};
		}
		
		// ********** intra-wizard methods **********

		protected boolean allowsExtensions() {
			return this.allowsExtensions;
		}
		
		protected void setAllowsExtensions(boolean allowsExtensions){
			this.allowsExtensions = allowsExtensions;
		}

		protected String getClasspath() {
			return this.classpathText.getText();
		}
		
		protected String getAdditionalArgs() {
			return this.additionalArgsText.getText();
		}
		
	}	
}

Back to the top