Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 724197a3e1db2861f65250420b8afb913133b126 (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
/*****************************************************************************
 * Copyright (c) 2016 CEA LIST 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:
 *   CEA LIST - Initial API and implementation
 *   
 *****************************************************************************/

package org.eclipse.papyrus.customization.nattableconfiguration.pages;

import org.eclipse.papyrus.customization.nattableconfiguration.helper.TableConfigurationHelper;
import org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;

/**
 * This page allows to edit the name of the Papyrus Table configuration to create.
 */
public class NattableConfigurationFileCreationPage extends EditGenericNattableConfigurationFieldsNattableWizardPage {
	/**
	 * The nattable configuration file name text composite.
	 */
	private Text nattableConfigurationFileName;

	/**
	 * The file name modify listener.
	 */
	private Listener fileNameModifyListener = new Listener() {

		@Override
		public void handleEvent(final Event e) {
			setPageComplete(canFlipToNextPage());
		}
	};

	/**
	 * Default constructor.
	 *
	 * @param helper
	 *            The table configuration helper
	 */
	public NattableConfigurationFileCreationPage(TableConfigurationHelper helper) {
		super(helper);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	public void createControl(final Composite parent) {
		Composite container = new Composite(parent, SWT.BORDER);
		final GridLayout gridLayout = new GridLayout(1, false);
		container.setLayout(gridLayout);
		container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

		final Group group = createGroup(container, Messages.NattableConfigurationProjectCreationPage_nattableConfigurationFileNameLabel);
		nattableConfigurationFileName = new Text(group, SWT.BORDER);
		nattableConfigurationFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
		nattableConfigurationFileName.addListener(SWT.Modify, fileNameModifyListener);
		super.createControl(container);
		setControl(container);
	}

	/**
	 * Create a new group with the given name.
	 *
	 * @param parent
	 *            The parent composite
	 * @param name
	 *            The name of the group
	 * @return The created group
	 */
	private static Group createGroup(final Composite parent, final String name) {
		final Group group = new Group(parent, SWT.NONE);
		group.setText(name);
		final GridLayout layout = new GridLayout(1, true);
		layout.marginHeight = 5;
		layout.marginWidth = 5;
		group.setLayout(layout);
		final GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
		group.setLayoutData(data);
		return group;
	}

	/**
	 * @see org.eclipse.papyrus.customization.nattableconfiguration.pages.EditGenericNattableConfigurationFieldsNattableWizardPage#isPageComplete()
	 *
	 * @return <code>true</code> if the page is complete, <code>false</false> otherwise
	 */
	@Override
	public boolean isPageComplete() {
		if (null != nattableConfigurationFileName) {
			if ("".equals(nattableConfigurationFileName.getText())) { //$NON-NLS-1$
				this.setErrorMessage("Set nattable configuration file name"); //$NON-NLS-1$
				return false;
			}
		}

		return super.isPageComplete();
	}

	/**
	 * @return The nattable configuration file name
	 */
	public String getNattableConfigurationFileName() {
		return nattableConfigurationFileName.getText();
	}

}

Back to the top