import eu.etaxonomy.taxeditor.ui.section.feature.CharacterNodeDtoDetailSection;
import eu.etaxonomy.taxeditor.ui.section.feature.FeatureDistributionDetailElement;
import eu.etaxonomy.taxeditor.ui.section.feature.FeatureDistributionDetailSection;
-import eu.etaxonomy.taxeditor.ui.section.feature.TermNodeDetailElement;
-import eu.etaxonomy.taxeditor.ui.section.feature.TermNodeDetailSection;
-import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailElement;
-import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailElementForNode;
-import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailSection;
-import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailSectionForNode;
import eu.etaxonomy.taxeditor.ui.section.feature.InapplicableIfCollectionElement;
import eu.etaxonomy.taxeditor.ui.section.feature.InapplicableIfEntityCollectionSection;
import eu.etaxonomy.taxeditor.ui.section.feature.InapplicableIfEntityCollectionSectionForNode;
import eu.etaxonomy.taxeditor.ui.section.feature.OnlyApplicableIfCollectionElement;
import eu.etaxonomy.taxeditor.ui.section.feature.OnlyApplicableIfEntityCollectionSection;
import eu.etaxonomy.taxeditor.ui.section.feature.OnlyApplicableIfEntityCollectionSectionForNode;
+import eu.etaxonomy.taxeditor.ui.section.feature.TermNodeDetailElement;
+import eu.etaxonomy.taxeditor.ui.section.feature.TermNodeDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailElement;
+import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailElementForNode;
+import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.feature.TermTreeDetailSectionForNode;
import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityCollectionElement;
import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityDetailElement;
import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityDetailSection;
return createToggleableTextField(parentElement, labelString, initialText, initialState, CacheRelevance.CACHE1, style);
}
+ /**
+ * like {@link #createToggleableTextField(ICdmFormElement, String, String, boolean, CacheRelevance, int)}
+ * but with predefined cache relevance == 1
+ */
+ public RemovableTextElement createRemovableTextField(ICdmFormElement parentElement, String labelString,
+ String initialText, int style) {
+ RemovableTextElement element = new RemovableTextElement(this, parentElement, labelString, initialText,
+ style | orientation);
+
+ adapt(element);
+ parentElement.addElement(element);
+ return element;
+ }
+
/**
* createTimePeriodElement
--- /dev/null
+/**
+* Copyright (C) 2021 EDIT
+* 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.
+*/
+package eu.etaxonomy.taxeditor.ui.element;
+
+import org.apache.commons.lang3.StringUtils;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+import eu.etaxonomy.taxeditor.model.ImageResources;
+
+/**
+ * @author k.luther
+ * @since Apr 1, 2021
+ */
+public class RemovableTextElement extends AbstractCdmFormElement implements SelectionListener {
+
+ private final Text text_cache;
+ private final Button btnRemoveElement;
+ private final Label label;
+ private final Composite container;
+ private boolean state;
+
+ protected RemovableTextElement(CdmFormFactory formFactory, ICdmFormElement parentElement,
+ String labelString, String initialText, int style) {
+ super(formFactory, parentElement);
+
+ label = formFactory.createLabel(getLayoutComposite(), labelString, style);
+ addControl(label);
+
+ 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.setEnabled(false);
+ text_cache.setLayoutData(LayoutConstants.FILL());
+
+ btnRemoveElement = formFactory.createButton(container, "Edit", SWT.TOGGLE);
+ btnRemoveElement.setText("");
+ btnRemoveElement.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
+ addControl(btnRemoveElement);
+ btnRemoveElement.addSelectionListener(this);
+ if (initialText != null){
+ setState(true);
+ }else {
+ setState(false);
+ }
+
+ }
+
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ setText(null);
+ firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setText(String text){
+ if (text == null){
+ this.text_cache.setText("");
+ }
+ if (StringUtils.isBlank(text)){
+ setState(false);
+ }else{
+ setState(true);
+ }
+ }
+
+
+ public boolean isState() {
+ return state;
+ }
+
+
+ public void setState(boolean state) {
+ this.state = state;
+ }
+
+}
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
+import eu.etaxonomy.taxeditor.ui.element.RemovableTextElement;
import eu.etaxonomy.taxeditor.ui.element.RepresentationElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionSection;
private Label labelText_property;
private Text text_property;
- private Label labelText_ratioTo;
- private Text text_ratioTo;
+ private RemovableTextElement ratioTo;
+// private Label labelText_ratioTo;
+// private Text text_ratioTo;
+// private Button button_remove;
+
+
// private TextWithLabelElement text_structure;
// private TextWithLabelElement text_property;
comboStructuralModifier = formFactory.createDefinedTermComboElement(TermType.StructureModifier, formElement, "Structural Modifier", entity.getStructureModifier(), style);
- if (labelText_ratioTo != null){
- labelText_ratioTo.dispose();
- }
- labelText_ratioTo = new Label(formElement.getLayoutComposite(), SWT.NONE);
- labelText_ratioTo.setText("Ratio to");
- if (text_ratioTo != null){
- text_ratioTo.dispose();
- }
- text_ratioTo = new Text(formElement.getLayoutComposite(), SWT.WRAP);
- text_ratioTo.setEditable(false);
- text_ratioTo.setText( CharacterNodeDetailElement.getRatioToText(entity));
- text_ratioTo.setLayoutData(LayoutConstants.FILL());
- text_ratioTo.setForeground(ColorResources.getColor(Resources.BLACK));
+ ratioTo = formFactory.createRemovableTextField(formElement, "Ratio to", CharacterNodeDetailElement.getRatioToText(entity), style);
supportsQuantitativeData = formFactory.createCheckbox(formElement, "Supports Quantitative Data", entity.isSupportsQuantitativeData(), style);
supportsCategoricalData = formFactory.createCheckbox(formElement, "Supports Categorical Data", entity.isSupportsCategoricalData(), style);
sectionModifierVocabularies.setEntity(entity);
}
+
}
// public void createText(ICdmFormElement formElement, String label, String path) {
// labelText = new Label(formElement.getLayoutComposite(), SWT.NONE);
if(eventSource == comboStructuralModifier){
getEntity().setStructureModifier(comboStructuralModifier.getSelection());
}
+ if(eventSource == ratioTo){
+ if (!ratioTo.isState()){
+ getEntity().setRatioToStructure(null);
+ }
+ }
+
// if(eventSource == supportsQuantitativeData || eventSource == supportsCategoricalData){
// //if any type is selected disable supportsTextData
// getEntity().setSupportsTextData(false);
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
+import eu.etaxonomy.taxeditor.ui.element.RemovableTextElement;
import eu.etaxonomy.taxeditor.ui.element.RepresentationElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionSection;
private Label labelText_property;
private Text text_property;
- private Label labelText_ratioTo;
- private Text text_ratioTo;
+ private RemovableTextElement ratioTo;
+
// private TextWithLabelElement text_structure;
// private TextWithLabelElement text_property;
comboStructuralModifier = formFactory.createDefinedTermComboElementDto(TermType.StructureModifier, formElement, "Structural Modifier", entity.getStructureModifier(), style);
- if (labelText_ratioTo != null){
- labelText_ratioTo.dispose();
- }
- labelText_ratioTo = new Label(formElement.getLayoutComposite(), SWT.NONE);
- labelText_ratioTo.setText("Ratio to");
- if (text_ratioTo != null){
- text_ratioTo.dispose();
- }
- text_ratioTo = new Text(formElement.getLayoutComposite(), SWT.WRAP);
- text_ratioTo.setEditable(false);
- if (entity.getRatioTo() != null){
- text_ratioTo.setText(entity.getRatioTo().getPath());
- }
- text_ratioTo.setLayoutData(LayoutConstants.FILL());
- text_ratioTo.setForeground(ColorResources.getColor(Resources.BLACK));
+// if (labelText_ratioTo != null){
+// labelText_ratioTo.dispose();
+// }
+// labelText_ratioTo = new Label(formElement.getLayoutComposite(), SWT.NONE);
+// labelText_ratioTo.setText("Ratio to");
+// if (text_ratioTo != null){
+// text_ratioTo.dispose();
+// }
+// text_ratioTo = new Text(formElement.getLayoutComposite(), SWT.WRAP);
+// text_ratioTo.setEditable(false);
+// if (entity.getRatioTo() != null){
+// text_ratioTo.setText(entity.getRatioTo().getPath());
+// }
+// text_ratioTo.setLayoutData(LayoutConstants.FILL());
+// text_ratioTo.setForeground(ColorResources.getColor(Resources.BLACK));
+
+ ratioTo = formFactory.createRemovableTextField(formElement, "Ratio to", entity.getRatioTo() != null? entity.getRatioTo().getPath():null, style);
supportsQuantitativeData = formFactory.createCheckbox(formElement, "Supports Quantitative Data", ((FeatureDto) entity).isSupportsQuantitativeData(), style);
supportsCategoricalData = formFactory.createCheckbox(formElement, "Supports Categorical Data", ((FeatureDto) entity).isSupportsCategoricalData(), style);
if(eventSource == comboStructuralModifier){
getEntity().setStructureModifier(TermDto.fromTerm(comboStructuralModifier.getSelection()));
}
+ if(eventSource == ratioTo){
+ if (!ratioTo.isState()){
+ getEntity().setRatioTo(null);
+ }
+ }
+
// if(eventSource == supportsQuantitativeData || eventSource == supportsCategoricalData){
// //if any type is selected disable supportsTextData
// getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());