implementation and generalization of a form framework to be used in the tabbed proper...
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / forms / AbstractSelectionComposite.java
1 /**
2 *
3 */
4 package eu.etaxonomy.taxeditor.forms;
5
6 import org.eclipse.swt.SWT;
7 import org.eclipse.swt.events.SelectionEvent;
8 import org.eclipse.swt.events.SelectionListener;
9 import org.eclipse.swt.layout.GridData;
10 import org.eclipse.swt.layout.GridLayout;
11 import org.eclipse.swt.widgets.Button;
12 import org.eclipse.swt.widgets.Composite;
13 import org.eclipse.swt.widgets.Label;
14 import org.eclipse.swt.widgets.Text;
15
16 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
17
18 /**
19 * @author nho
20 *
21 */
22 public abstract class AbstractSelectionComposite<T extends IdentifiableEntity> extends AbstractFormComposite implements SelectionListener{
23
24 protected T selection;
25
26 protected Label label;
27 protected Text text;
28 protected Button button;
29
30 /**
31 * @param parent
32 * @param style
33 */
34 public AbstractSelectionComposite(Composite parent, String labelString, T selection, int style) {
35 super(parent, style);
36
37 this.selection = selection;
38
39 this.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
40 GridLayout layout = (GridLayout) this.getLayout();
41 layout.numColumns = 2;
42
43 label = toolkit.createLabel(this, labelString, SWT.WRAP);
44 GridData labelData = new GridData();
45 labelData.horizontalSpan = 2;
46 label.setLayoutData(labelData);
47
48 text = toolkit.createText(this, "", SWT.BORDER | SWT.WRAP);
49 text.setEditable(false);
50 text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
51
52 button = toolkit.createButton(this, "Browse", SWT.PUSH);
53 button.addSelectionListener(this);
54
55 updateText();
56 }
57
58 /* (non-Javadoc)
59 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
60 */
61 public void widgetDefaultSelected(SelectionEvent e) {
62 // do nothing
63 }
64
65 /* (non-Javadoc)
66 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
67 */
68 public void widgetSelected(SelectionEvent e) {
69 firePropertyChangeEvent(null);
70 }
71
72 /**
73 * Return the selected object
74 *
75 * @return
76 */
77 public T getSelection(){
78 return selection;
79 }
80
81 /**
82 *
83 * @param selection
84 */
85 public void setSelection(T selection){
86 this.selection = selection;
87 updateText();
88 }
89
90 protected void updateText(){
91 if(selection != null)
92 text.setText(selection.getTitleCache());
93 }
94 }