Skip to main content
summaryrefslogtreecommitdiffstats
blob: fe3b78772183ee7addaf2cc6acd0a32280072c60 (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
/*******************************************************************************
 * 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.ui.internal.widgets;

import org.eclipse.jpt.ui.internal.JptUiMessages;
import org.eclipse.jpt.utility.model.Model;
import org.eclipse.jpt.utility.model.value.PropertyValueModel;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

/**
 * A chooser is simply a pane with three widgets, the label on the left, a main
 * widget, usually a text field, and a right widget which is usually a browse
 * button.
 *
 * @see ClassChooserPane
 * @see PackageChooserPane
 *
 * @version 2.0
 * @since 2.0
 */
public abstract class ChooserPane<T extends Model> extends Pane<T>
{
	/**
	 * The control shown after the label (left control).
	 */
	private Control mainControl;

	/**
	 * The control shown after the main control.
	 */
	private Control rightControl;

	/**
	 * Creates a new <code>ChooserPane</code>.
	 *
	 * @param parentPane The parent pane of this one
	 * @param parent The parent container
	 */
	public ChooserPane(Pane<? extends T> parentPane,
	                           Composite parent) {

		super(parentPane, parent);
	}

	/**
	 * Creates a new <code>ChooserPane</code>.
	 *
	 * @param parentPane The parent container of this one
	 * @param subjectHolder The holder of this pane's subject
	 * @param parent The parent container
	 */
	public ChooserPane(Pane<?> parentPane,
	                           PropertyValueModel<? extends T> subjectHolder,
	                           Composite parent) {

		super(parentPane, subjectHolder, parent);
	}

	/**
	 * Returns the text of the browse button. This method is called by
	 * {@link #buildRightControl(Composite)}.
	 *
	 * @return "Browse..."
	 */
	protected String getBrowseButtonText() {
		return JptUiMessages.ChooserPane_browseButton;
	}

	/**
	 * Creates the action responsible to perform the action when the Browse is
	 * clicked.
	 *
	 * @return A new <code>Runnable</code> performing the actual action of the
	 * button
	 */
	protected abstract Runnable buildBrowseAction();

	/**
	 * Creates the left control. By default a label is created and its text is
	 * retrieved by {@link #getLabelText()}.
	 *
	 * @param container The parent container
	 * @return The newly created left control
	 */
	protected Control addLeftControl(Composite container) {
		return addLabel(container, getLabelText());
	}

	/**
	 * Creates the main control of this pane.
	 *
	 * @param container The parent container
	 * @return The newly created main control
	 */
	protected abstract Control addMainControl(Composite container);

	/**
	 * Creates the right control. By default a browse button is created and its
	 * action is performed by {@link #buildBrowseAction()} and its text is
	 * retrieved by {@link #getBrowseButtonText()}.
	 *
	 * @param container The parent container
	 * @return The newly created right control
	 */
	protected Control addRightControl(Composite container) {
		return addButton(
			container,
			getBrowseButtonText(),
			buildBrowseAction()
		);
	}

	/*
	 * (non-Javadoc)
	 */
	@Override
	public void enableWidgets(boolean enabled) {

		super.enableWidgets(enabled);

		if (!mainControl.isDisposed()) {
			mainControl.setEnabled(enabled);
		}

		if (!rightControl.isDisposed()) {
			rightControl.setEnabled(enabled);
		}
	}

	/**
	 * Returns the help topic ID for the controls of this pane.
	 *
	 * @return <code>null</code> is returned otherwise the subclass can return an ID
	 */
	protected String getHelpId() {
		return null;
	}

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

		mainControl  = addMainControl(container);
		rightControl = addRightControl(container);

		addLabeledComposite(
			container,
			addLeftControl(container),
			mainControl,
			rightControl,
			getHelpId()
		);
	}

	/**
	 * The text of the label. This method is called by
	 * {@link #buildLeftControl(Composite)}.
	 *
	 * @return The localized text of the left control (which is a label by
	 * default)
	 */
	protected abstract String getLabelText();
}

Back to the top