2 * Copyright (C) 2021 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.ui
.element
;
11 import org
.apache
.commons
.lang3
.StringUtils
;
12 import org
.eclipse
.swt
.SWT
;
13 import org
.eclipse
.swt
.events
.SelectionEvent
;
14 import org
.eclipse
.swt
.events
.SelectionListener
;
15 import org
.eclipse
.swt
.widgets
.Button
;
16 import org
.eclipse
.swt
.widgets
.Composite
;
17 import org
.eclipse
.swt
.widgets
.Label
;
18 import org
.eclipse
.swt
.widgets
.Text
;
20 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
26 public class RemovableTextElement
extends AbstractCdmFormElement
implements SelectionListener
{
28 private final Text text_cache
;
29 private final Button btnRemoveElement
;
30 private final Label label
;
31 private final Composite container
;
32 private boolean state
;
34 protected RemovableTextElement(CdmFormFactory formFactory
, ICdmFormElement parentElement
,
35 String labelString
, String initialText
, int style
) {
36 super(formFactory
, parentElement
);
38 label
= formFactory
.createLabel(getLayoutComposite(), labelString
, style
);
41 container
= formFactory
.createComposite(getLayoutComposite(), SWT
.WRAP
);
42 container
.setLayout(LayoutConstants
.LAYOUT(2, false));
43 container
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
44 addControl(container
);
46 text_cache
= formFactory
.createText(container
, initialText
, SWT
.WRAP
| SWT
.MULTI
);
47 addControl(text_cache
);
48 text_cache
.setEnabled(false);
49 text_cache
.setLayoutData(LayoutConstants
.FILL());
51 btnRemoveElement
= formFactory
.createButton(container
, "Edit", SWT
.TOGGLE
);
52 btnRemoveElement
.setText("");
53 btnRemoveElement
.setImage(ImageResources
.getImage(ImageResources
.TRASH_ICON
));
54 addControl(btnRemoveElement
);
55 btnRemoveElement
.addSelectionListener(this);
56 if (initialText
!= null){
66 public void widgetSelected(SelectionEvent e
) {
68 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e
));
72 public void widgetDefaultSelected(SelectionEvent e
) {
73 // TODO Auto-generated method stub
77 public void setText(String text
){
79 this.text_cache
.setText("");
81 if (StringUtils
.isBlank(text
)){
89 public boolean isState() {
94 public void setState(boolean state
) {