Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3dd63559cbcdaf5dc103536ace84767f6eb968c2 (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
/*******************************************************************************
 * Copyright (c) 2008 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.common.ui.internal.widgets;

import java.util.Collection;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/**
 * The dialog used to requests a name from the user.
 *
 * @version 2.0
 * @since 2.0
 */
public class NewNameDialog extends ValidatingDialog<NewNameStateObject>
{
	private String description;
	private Image descriptionImage;
	private String descriptionTitle;
	private String labelText;
	private String name;
	private Collection<String> names;

	/**
	 * Creates a new <code>NewNameDialog</code>.
	 *
	 * @param parentShell
	 * @param dialogTitle
	 * @param descriptionTitle
	 * @param descriptionImage
	 * @param description
	 * @param labelText
	 * @param name
	 * @param names
	 */
	NewNameDialog(Shell parentShell,
	              String dialogTitle,
	              String descriptionTitle,
	              Image descriptionImage,
	              String description,
	              String labelText,
	              String name,
	              Collection<String> names)
	{
		super(parentShell, dialogTitle);

		this.name             = name;
		this.names            = names;
		this.labelText        = labelText;
		this.description      = description;
		this.descriptionImage = descriptionImage;
		this.descriptionTitle = descriptionTitle;
	}

	/*
	 * (non-Javadoc)
	 */
	@Override
	protected DialogPane<NewNameStateObject> buildLayout(Composite container) {
		return new NewNameDialogPane(container);
	}

	/*
	 * (non-Javadoc)
	 */
	@Override
	protected NewNameStateObject buildStateObject() {
		return new NewNameStateObject(name, names);
	}

	/*
	 * (non-Javadoc)
	 */
	@Override
	public void create() {
		super.create();

		NewNameDialogPane pane = (NewNameDialogPane) getPane();
		pane.selectAll();

		getButton(OK).setEnabled(false);
	}

	/*
	 * (non-Javadoc)
	 */
	@Override
	protected String getDescription() {
		return description;
	}

	/*
	 * (non-Javadoc)
	 */
	@Override
	protected Image getDescriptionImage() {
		return descriptionImage;
	}

	/* (non-Javadoc)
	 */
	@Override
	protected String getDescriptionTitle() {
		return descriptionTitle;
	}

	/**
	 * Returns the text field's input, which is the new name the user entered.
	 *
	 * @return The name the user entered
	 */
	public String getName() {
		return getSubject().getName();
	}

	private class NewNameDialogPane extends DialogPane<NewNameStateObject> {

		private Text text;

		NewNameDialogPane(Composite parent) {
			super(NewNameDialog.this.getSubjectHolder(), parent);
		}

		private WritablePropertyValueModel<String> buildNameHolder() {
			return new PropertyAspectAdapter<NewNameStateObject, String>(getSubjectHolder(), NewNameStateObject.NAME_PROPERTY) {
				@Override
				protected String buildValue_() {
					return subject.getName();
				}

				@Override
				protected void setValue_(String value) {
					subject.setName(value);
				}
			};
		}

		/*
		 * (non-Javadoc)
		 */
		@Override
		protected void initializeLayout(Composite container) {

			text = addLabeledText(
				container,
				labelText,
				buildNameHolder()
			);
		}

		void selectAll() {
			text.selectAll();
		}
	}
}

Back to the top