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

import java.util.Arrays;
import java.util.List;

import org.eclipse.jpt.utility.internal.StringConverter;
import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel;
import org.eclipse.jpt.utility.model.Model;
import org.eclipse.jpt.utility.model.value.ListValueModel;
import org.eclipse.jpt.utility.model.value.PropertyValueModel;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

/**
 * This chooser allows the user to choose a file when browsing.
 * <p>
 * Here the layout of this pane:
 * <pre>
 * -----------------------------------------------------------------------------
 * |        ---------------------------------------------------- ------------- |
 * | Label: | I                                            |v| | | Browse... | |
 * |        ---------------------------------------------------- ------------- |
 * -----------------------------------------------------------------------------</pre>
 *
 * @version 3.0
 * @since 3.0
 */
public abstract class FileChooserComboPane<T extends Model> extends FileChooserPane<T>
{
	/**
	 * Creates a new <code>FileChooserComboPane</code>.
	 *
	 * @param parentPane The parent pane of this one
	 * @param parent The parent container
	 */
	public FileChooserComboPane(Pane<? extends T> parentPane,
	                       Composite parent) {

		super(parentPane, parent);
	}

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

		super(parentPane, subjectHolder, parent);
	}

	@Override
	protected Control addMainControl(Composite container) {
		
		return addEditableCombo(
			container,
			this.buildListHolder(),
			this.getTextHolder(),
			this.buildStringConverter()
		);
	}

	/**
	 * Creates the list holder of the combo box.
	 */
	protected ListValueModel<String> buildListHolder() {
		return new SimpleListValueModel<String>(
			this.buildDefaultList()
		);
	}

	/**
	 * Creates the default list of the combo box.
	 */
	protected List<String> buildDefaultList() {
		return Arrays.asList(this.getDefaultString());
	}

	/**
	 * Returns the default value of the combo box.
	 */
	protected abstract String getDefaultString();
	
	/**
	 * The converter responsible to transform each combo box item
	 * into a string representation
	 */
	protected StringConverter<String> buildStringConverter() {
		return StringConverter.Default.<String>instance();
	}

}

Back to the top