// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import eu.etaxonomy.taxeditor.model.ImageResources;
import eu.etaxonomy.taxeditor.preference.Resources;
import eu.etaxonomy.taxeditor.store.StoreUtil;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
/**
* When the button is pressed, this textfield may be edited.
*/
public class ToggleableTextElement extends AbstractCdmFormElement implements SelectionListener, ModifyListener, IEnableableFormElement, ISelectable {
- private Text text_cache;
- private Button button_toggle;
-
+ private final Text text_cache;
+ private final Button button_toggle;
private boolean state;
- private Set<SelectionListener> selectionListener = new HashSet<SelectionListener>();
- private Label label;
- private Composite container;
+ private final Set<SelectionListener> selectionListener = new HashSet<SelectionListener>();
+ private final Label label;
+ private final Composite container;
+
+ //TODO for RL
+ public void setVisible(boolean b) {
+ text_cache.setVisible(b);
+ button_toggle.setVisible(b);
+ label.setVisible(b);
+ container.setVisible(b);
+ }
+
/**
* <p>Constructor for ToggleableTextElement.</p>
protected ToggleableTextElement(CdmFormFactory formFactory, ICdmFormElement parentElement,
String labelString, String initialText, boolean initialState, int style) {
super(formFactory, parentElement);
-
+
label = formFactory.createLabel(getLayoutComposite(), labelString, style);
addControl(label);
-
- container = formFactory.createComposite(getLayoutComposite(), SWT.WRAP);
+
+ container = formFactory.createComposite(getLayoutComposite(), SWT.WRAP);
container.setLayout(LayoutConstants.LAYOUT(2, false));
container.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
addControl(container);
-
+
text_cache = formFactory.createText(container, initialText, SWT.WRAP | SWT.MULTI);
addControl(text_cache);
text_cache.addModifyListener(this);
text_cache.addKeyListener( new KeyAdapter(){
@Override
public void keyPressed(KeyEvent e) {
- if(e.character == SWT.CR)
- e.doit = false;
+ if(e.character == SWT.CR) {
+ e.doit = false;
+ }
}
});
-
+
button_toggle = formFactory.createButton(container, "Edit", SWT.TOGGLE);
+ button_toggle.setText("");
+ button_toggle.setImage(ImageResources.getImage(ImageResources.LOCK_ICON));
addControl(button_toggle);
button_toggle.addSelectionListener(this);
-
+
setState(initialState);
}
if(text != null){
// store current caret position
int caretPosition = text_cache.getCaretPosition();
-
+
text_cache.removeModifyListener(this);
text_cache.setText(text);
text_cache.addModifyListener(this);
public String getText(){
return text_cache.getText();
}
-
+
/**
* <p>Setter for the field <code>state</code>.</p>
*
* @param state a boolean.
*/
- public void setState(boolean state) {
+ private void setState(boolean state) {
+ if(state){
+ button_toggle.setImage(ImageResources.getImage(ImageResources.LOCK_OPEN_ICON));
+ }
+ else{
+ button_toggle.setImage(ImageResources.getImage(ImageResources.LOCK_ICON));
+ }
+ text_cache.setEnabled(state);
this.state = state;
- setEnabled(state);
}
-
+
/** {@inheritDoc} */
- public void setEnabled(boolean enabled) {
+ @Override
+ public void setEnabled(boolean enabled) {
text_cache.setEnabled(enabled);
+ button_toggle.setEnabled(enabled);
+ button_toggle.setGrayed(enabled);
+ button_toggle.setSelection(enabled);
String symbolicName = enabled ? Resources.COLOR_FONT_DEFAULT : Resources.COLOR_TEXT_DISABLED;
text_cache.setForeground(StoreUtil.getColor(symbolicName));
- button_toggle.setSelection(enabled);
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement#isEnabled()
+ */
+ @Override
+ public boolean isEnabled() {
+ return text_cache.isEnabled();
}
/**
public boolean getState(){
return state;
}
-
+
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
/** {@inheritDoc} */
- public void widgetSelected(SelectionEvent e) {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
setState(button_toggle.getSelection());
for(SelectionListener listener : selectionListener){
listener.widgetSelected(e);
}
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
}
-
+
/**
* <p>addSelectionListener</p>
*
public void addSelectionListener(SelectionListener listener){
selectionListener.add(listener);
}
-
+
/**
* <p>removeSelectionListener</p>
*
public void removeSelectionListener(SelectionListener listener){
selectionListener.remove(listener);
}
-
+
/** {@inheritDoc} */
- public void widgetDefaultSelected(SelectionEvent e) {}
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {}
/** {@inheritDoc} */
- public void modifyText(ModifyEvent e) {
+ @Override
+ public void modifyText(ModifyEvent e) {
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
}
/** {@inheritDoc} */
- public void setIrrelevant(boolean irrelevant) {
+ @Override
+ public void setIrrelevant(boolean irrelevant) {
String colorId = irrelevant ? Resources.COLOR_COMPOSITE_IRRELEVANT : Resources.COLOR_COMPOSITE_BACKGROUND;
-
+
Color color = getColor(colorId);
text_cache.setBackground(color);
}
-
+
/** {@inheritDoc} */
@Override
public void setBackground(Color color) {
label.setBackground(color);
container.setBackground(color);
}
-
+
@Override
public void setSelected(boolean selected) {
setBackground(selected ? SELECTED : getPersistentBackground());