* 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.section.classification;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.Map;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import eu.etaxonomy.cdm.common.CdmUtils;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.common.Language;
import eu.etaxonomy.cdm.model.common.LanguageString;
+import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
import eu.etaxonomy.cdm.model.metadata.PublishEnum;
import eu.etaxonomy.cdm.model.name.TaxonName;
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.model.taxon.Classification;
-import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.model.taxon.TaxonNodeStatus;
+import eu.etaxonomy.taxeditor.l10n.Messages;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.preference.CdmPreferenceCache;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.preference.Resources;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
+import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
import eu.etaxonomy.taxeditor.ui.element.MultilanguageTextElement;
+import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
-import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
+import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractSingleSourceElement;
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
/**
- *
* @author n.hoffmann
* @created Sep 27, 2010
- * @version 1.0
*/
-public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode> {
+public class TaxonNodeDetailElement extends AbstractSingleSourceElement<TaxonNode> {
- private boolean createNew = false;
+ private static final String STATUS_NOTES = Messages.TaxonNodeWizardPage_STATUS_NOTES;
+ private static final String CLASSIFICATION_STR = Messages.TaxonNodeWizardPage_CLASSIFICATION;
+ private static final String REUSE_EXISTING_TAXON = Messages.TaxonNodeWizardPage_REUSE_EXISTING_TAXON;
+ private static final String REUSE_EXISTING_NAME = Messages.TaxonNodeWizardPage_REUSE_EXISTING_NAME;
+ private static final String SECUNDUM_REFERENCE = Messages.TaxonNodeWizardPage_SECUNDUM_REFERENCE;
-// private EntitySelectionElement<Classification> selection_classification;
+ private static final Font FONT_BOLD = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
+ private boolean createNew = false;
private Classification classification;
+ private TaxonNode parentNode;
+ private Taxon taxon;
+ private boolean complete;
+ private TaxonNodeStatus status = null;
+ private Map<Language, LanguageString> multilanguageTextCache;
private TaxonNodeSelectionElement selection_parentTaxonNode;
-
- private TaxonNode parentTreeNode;
-
private EntitySelectionElement<Taxon> selection_reuseExistingTaxon;
- private EntitySelectionElement<Reference> selection_SecRef;
- private EntitySelectionElement<Reference> selection_Ref;
- TextWithLabelElement textTaxonSec;
- private TextWithLabelElement microReference;
-
- private Taxon taxon;
+ private EntitySelectionElement<TaxonName> selection_reuseExistingName;
+ private EntitySelectionElement<Reference> selection_SecRef;
- private TextWithLabelElement textNewTaxonName;
+// private OriginalSourceElement singleSourceSection;
+ private TextWithLabelElement textTaxonSec;
+ private TextWithLabelElement microReference;
+ private TextWithLabelElement textNewTaxonName;
private TaxonNodeAgentRelationCollectionSection selectionNodeAgentRelation;
-
-// private CheckboxElement checkbox_openInEditor;
-
- private CheckboxElement checkbox_unplaced;
-
- private CheckboxElement checkbox_excluded;
+ private EnumComboElement<TaxonNodeStatus> combo_status;
private CheckboxElement checkbox_publish;
-
-
-
- private MultilanguageTextElement multiLanguageTextExcludedNotes;
-
-// private boolean openInEditor;
-
- private boolean complete;
-
- private boolean excluded = false;
- private boolean unplaced = false;
-
- private EntitySelectionElement<TaxonName> selection_reuseExistingName;
+ private MultilanguageTextElement multiLanguageTextStatusNotes;
+ String defaultPublish;
public TaxonNodeDetailElement(CdmFormFactory formFactory,
ICdmFormElement formElement, boolean isCreateNew) {
createNew = isCreateNew;
}
+ public Map<Language, LanguageString> getMultiLanguageTextExcludedNotes() {
+ return multiLanguageTextStatusNotes.getMultilanguageText();
+ }
+
+ public TaxonNodeStatus getTaxonNodeStatus(){
+ return status;
+ }
+ public Reference getRef() {
+ return getEntity().getCitation();
+ }
+ public TaxonName getExistingName() {
+ return selection_reuseExistingName.getEntity();
+ }
+ public String getMicroReference() {
+ return microReference.getText();
+ }
- /** {@inheritDoc} */
@Override
- protected void createControls(ICdmFormElement formElement,
- TaxonNode entity, int style) {
- taxon = entity.getTaxon();
+ public void createControls(ICdmFormElement formElement,TaxonNode entity, int style) {
+// taxon = entity.getTaxon();
+
+ Label taxonTitle = new Label(getLayoutComposite(), SWT.NULL);
+ taxonTitle.setText(Messages.TaxonNodeWizardPage_TAXON_INFORMATION);
+ taxonTitle.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ taxonTitle.setFont(FONT_BOLD);
+
+
+
if (isCreateNew()){
-// selection_classification = formFactory
-// .createSelectionElement(Classification.class,//getConversationHolder(),
-// formElement, "Classification",
-// null, EntitySelectionElement.DELETABLE, style);
- selection_parentTaxonNode = formFactory
- .createTaxonNodeSelectionElement(getConversationHolder(), formElement, "Parent", parentTreeNode,
- EntitySelectionElement.DELETABLE, style);
-
- selection_reuseExistingTaxon = formFactory
- .createSelectionElement(Taxon.class,//getConversationHolder(),
- formElement,
- "Reuse existing taxon", null,
- EntitySelectionElement.DELETABLE, style);
-
- selection_reuseExistingName = formFactory
- .createSelectionElement(TaxonName.class,//getConversationHolder(),
- formElement,
- "Reuse existing name", taxon.getName(),
- EntitySelectionElement.DELETABLE, style);
- selection_SecRef = formFactory
- .createSelectionElement(Reference.class,//getConversationHolder(),
- formElement, "Secundum Reference", taxon.getSec(),
- EntitySelectionElement.DELETABLE, style);
+ textNewTaxonName = formFactory.createTextWithLabelElement(formElement,
+ Messages.TaxonNodeWizardPage_NEW_TAXON, "", style);
+ textNewTaxonName.setFocus();
+ textNewTaxonName.setIndent(10);
- if (isCreateNew()){
- textNewTaxonName = formFactory.createTextWithLabelElement(formElement,"New Taxon", "", style);
- textNewTaxonName.setFocus();
- } else{
- textNewTaxonName = formFactory.createTextWithLabelElement(formElement,"Taxon", "", style);
+ selection_reuseExistingTaxon = formFactory
+ .createSelectionElement(Taxon.class,//getConversationHolder(),
+ formElement,
+ REUSE_EXISTING_TAXON, null,
+ EntitySelectionElement.DELETABLE, style);
+ selection_reuseExistingTaxon.setIndent(10);
+ selection_reuseExistingName = formFactory
+ .createSelectionElement(TaxonName.class,//getConversationHolder(),
+ formElement,
+ REUSE_EXISTING_NAME, taxon != null? taxon.getName(): null,
+ EntitySelectionElement.DELETABLE, style);
+ selection_reuseExistingName.setIndent(10);
+ selection_SecRef = formFactory
+ .createSelectionElement(Reference.class,//getConversationHolder(),
+ formElement, SECUNDUM_REFERENCE, taxon != null? taxon.getSec(): null,
+ EntitySelectionElement.DELETABLE, style, 100);
+ selection_SecRef.setIndent(10);
+ microReference = formFactory.createTextWithLabelElement(formElement, "Secundum Details", "", style);
+
+ microReference.setIndent(10);
+ checkbox_publish = formFactory.createCheckbox(formElement,
+ Messages.TaxonNodeWizardPage_TAXON_IS_PUBLISH, true, style);
+
+ checkbox_publish.setEnabled(isCreateNew());
+ checkbox_publish.setIndent(10);
+ Label spacer = new Label(getLayoutComposite(), SWT.NULL);
+ spacer.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 2));
+ Label nodeTitle = new Label(getLayoutComposite(), SWT.NULL);
+ nodeTitle.setText("Taxon Node");
+ nodeTitle.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ nodeTitle.setFont(FONT_BOLD);
+// LabelElement nodeTitle = formFactory.createLabel(formElement, Messages.TaxonNodeWizardPage_TAXON_INFORMATION);
+// nodeTitle.setLayout(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+// nodeTitle.setBackground(getPersistentBackground());
+// nodeTitle.setBold();
+
+ selection_parentTaxonNode = formFactory
+ .createTaxonNodeSelectionElement(getConversationHolder(), formElement, Messages.TaxonNodeWizardPage_PARENT, parentNode,
+ EntitySelectionElement.SELECTABLE, style, 100);
+ selection_parentTaxonNode.setIndent(10);
+ selection_parentTaxonNode.setEnabled(false);
- }
- }else{
- TextWithLabelElement textClassification = formFactory.createTextWithLabelElement(formElement,"Classification", entity.getClassification().getTitleCache(), style);
- textClassification.setEnabled(false);
-// TextWithLabelElement textTaxon = formFactory.createTextWithLabelElement(formElement,"Taxon", taxon.getTitleCache(), style);
-// textTaxon.setEnabled(false);
+ }else{
+ taxon = getEntity().getTaxon();
selection_reuseExistingTaxon = formFactory
- .createSelectionElement(Taxon.class,//getConversationHolder(),
- formElement,
- "Taxon", taxon,
- EntitySelectionElement.DELETABLE, style);
+ .createSelectionElement(Taxon.class, formElement,
+ Messages.TaxonNodeWizardPage_TAXON, taxon,
+ EntitySelectionElement.DELETABLE, SWT.NULL);
+
+ selection_reuseExistingTaxon.setIndent(10);
+ textTaxonSec = formFactory.createTextWithLabelElement(formElement,SECUNDUM_REFERENCE, "", SWT.NULL);
+ textTaxonSec.setIndent(10);
+ microReference = formFactory.createTextWithLabelElement(formElement, "Secundum Details", "", SWT.NULL);
+ microReference.setIndent(10);
- textTaxonSec = formFactory.createTextWithLabelElement(formElement,"Secundum Reference", "", style);
- if (entity.getTaxon().getSec() != null){
+ if (entity.getTaxon().getSec() != null){
textTaxonSec.setText(taxon.getSec().getTitleCache());
}
textTaxonSec.setEnabled(false);
-
-
-
+ microReference.setEnabled(false);
+ Label spacer = new Label(getLayoutComposite(), SWT.NULL);
+ spacer.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 2));
+
+ Label nodeTitle = new Label(getLayoutComposite(), SWT.NULL);
+ nodeTitle.setText("Taxon Node");
+ nodeTitle.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ nodeTitle.setFont(FONT_BOLD);
+
+// LabelElement nodeTitle = formFactory.createLabel(formElement, "Taxon Node");
+// nodeTitle.setLayout(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+// nodeTitle.setBackground(getPersistentBackground());
+// nodeTitle.setBold();
+
+
+ if (entity.getParent().getTaxon() == null){
+ TextWithLabelElement textParent = formFactory.createTextWithLabelElement(
+ formElement,CLASSIFICATION_STR, entity.getClassification().getTitleCache(), SWT.NULL);
+ textParent.setEnabled(false);
+ textParent.setIndent(10);
+ }else{
+ TextWithLabelElement textParent = formFactory.createTextWithLabelElement(
+ formElement, Messages.TaxonNodeWizardPage_PARENT, entity.getParent().getTaxon().getTitleCache(), SWT.NULL);
+ textParent.setEnabled(false);
+ textParent.setIndent(10);
+ }
}
- selection_Ref = formFactory
- .createSelectionElement(Reference.class,//getConversationHolder(),
- formElement, "Parent Child Relation Source", null,
- EntitySelectionElement.DELETABLE, style);
- microReference = formFactory.createTextWithLabelElement(formElement,"Detail", "", style);
- microReference.setText(getEntity().getMicroReference());
+
+ combo_status = formFactory.createEnumComboElement(TaxonNodeStatus.class, formElement, SWT.NULL, true);
if (!isCreateNew()){
- selection_Ref.setEntity(entity.getReference());
+ combo_status.setSelection(entity.getStatus());
}
- parentTreeNode = entity.getParent();
- if (entity instanceof TaxonNode && parentTreeNode.getTaxon() != null) {
- checkbox_publish = formFactory.createCheckbox(formElement,
- "Taxon is public", parentTreeNode.getTaxon().isPublish(), style);
- }else{
- checkbox_publish = formFactory.createCheckbox(formElement,
- "Taxon is public", true, style);
- }
- checkbox_publish.setEnabled(isCreateNew());
- if(isCreateNew()){
- setParentTreeNode(entity.getParent());
-
- String defaultPublish = PreferencesUtil.getStringValue(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey());
- if (defaultPublish != null && defaultPublish.equals(PublishEnum.Publish.getKey())){
- checkbox_publish.setSelection(true);
- } else if (defaultPublish != null && defaultPublish.equals(PublishEnum.NotPublish.getKey())){
- checkbox_publish.setSelection(false);
- }else{
- if(this.getParentTreeNode() != null && this.getParentTreeNode().isInstanceOf(TaxonNode.class) && ((TaxonNode)this.getParentTreeNode()).getTaxon() != null){
- checkbox_publish.setSelection(((TaxonNode)this.getParentTreeNode()).getTaxon().isPublish());
- }else{
- checkbox_publish.setSelection(true);
- }
- }
+ combo_status.setIndent(10);
+ if(isCreateNew()){
+ defaultPublish = PreferencesUtil.getStringValue(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey());
+ setDefaultPublish();
} else{
setTreeNode(entity);
complete = true;
}
- if (entity instanceof TaxonNode) {
- checkbox_unplaced = formFactory.createCheckbox(formElement,
- "Taxon is unplaced", entity.isUnplaced(), style);
- }else{
- checkbox_unplaced = formFactory.createCheckbox(formElement,
- "Taxon is unplaced", false, style);
- }
+
if (isCreateNew()){
preFillTaxonName();
}
- if (entity instanceof TaxonNode) {
- checkbox_excluded = formFactory.createCheckbox(formElement,
- "Taxon is excluded", entity.isExcluded(), style);
- multiLanguageTextExcludedNotes = formFactory.createMultiLanguageTextElement(formElement, "Excluded Notes", entity.getExcludedNote(), 50, style);
- multiLanguageTextExcludedNotes.setEnabled(entity.isExcluded());
- }else{
- checkbox_excluded = formFactory.createCheckbox(formElement,
- "Taxon is excluded", false, style);
- multiLanguageTextExcludedNotes = formFactory.createMultiLanguageTextElement(formElement, "Excluded Notes", new HashMap<Language, LanguageString>(), 50, style);
- multiLanguageTextExcludedNotes.setEnabled(false);
- }
- if (!isCreateNew()){
- selectionNodeAgentRelation = formFactory.createTaxonNodeAgentRelationCollectionSection(formElement, getConversationHolder(), style);
- selectionNodeAgentRelation.setEntity(entity);
- selectionNodeAgentRelation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
- }
-// checkbox_openInEditor = formFactory.createCheckbox(formElement,
-// "Open in Editor", true, style);
-// setOpenInEditor(true);
+ multiLanguageTextStatusNotes = formFactory.createMultiLanguageTextElement(formElement, STATUS_NOTES, null, 50, style);
+ if (!isCreateNew()){
+ multiLanguageTextStatusNotes.setMultilanguageText(entity.getStatusNote());
+ multiLanguageTextStatusNotes.setEnabled(entity.getStatus() != null);
+ }
+ multiLanguageTextStatusNotes.setIndent(10);
+ singleSourceSection = formFactory.createOriginalSourceElement(formElement, entity, "");
+ if (isCreateNew() || entity.getSource() == null){
+ DescriptionElementSource source = DescriptionElementSource.NewPrimarySourceInstance(null, null);
+ entity.setSource(source);
+ singleSourceSection.setEntity(source);
+ }else{
+ singleSourceSection.setEntity(entity.getSource());
+
+ }
+ singleSourceSection.setIndent(10);
+// singleSourceSection.set
+
+// super.createControls(formElement, entity, style);
+
+ setSourceLabel(Messages.TaxonNodeWizardPage_PLACEMENT_SOURCE);
+
+
+ selectionNodeAgentRelation = formFactory.createTaxonNodeAgentRelationCollectionSection(formElement, getConversationHolder(), StoreUtil.getSectionStyle(TaxonNodeAgentRelationCollectionSection.class, entity.getClass().getCanonicalName()));
+ selectionNodeAgentRelation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ selectionNodeAgentRelation.setEntity(entity);
+ selectionNodeAgentRelation.setIndent(10);
+ selectionNodeAgentRelation.setFont(AbstractUtility.getFont(Resources.COLOR_FONT_DEFAULT));
+ setBackground(getPersistentBackground());
+
}
+ private void setDefaultPublish() {
+ if (defaultPublish != null && defaultPublish.equals(PublishEnum.Publish.getKey())){
+ checkbox_publish.setSelection(true);
+ } else if (defaultPublish != null && defaultPublish.equals(PublishEnum.NotPublish.getKey())){
+ checkbox_publish.setSelection(false);
+ }else{
+ if(this.getParentTreeNode() != null && this.getParentTreeNode().isInstanceOf(TaxonNode.class) && this.getParentTreeNode().getTaxon() != null){
+ checkbox_publish.setSelection(this.getParentTreeNode().getTaxon().isPublish());
+ }else{
+ checkbox_publish.setSelection(true);
+ }
+ }
+ }
+
private void preFillTaxonName() {
- if(getEntity() instanceof TaxonNode ){
- TaxonNode node = parentTreeNode;
- if(node.getTaxon()!=null){
- Taxon taxon = HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class);
- if(taxon.getName()!=null){
- TaxonName name = HibernateProxyHelper.deproxy(node.getTaxon().getName());
- if (!isCreateNew()){
- textNewTaxonName.setText(name.getNameCache());
- } else if( ! name.isSupraGeneric() && name.getRank() != null){
- String taxonName = "";
- if(name.isGenus() || name.isInfraGeneric()|| name.isSpeciesAggregate() ){
- taxonName = name.getGenusOrUninomial();
- }
- else if(name.isSpecies() || name.isInfraSpecific() ){
- taxonName = CdmUtils.concat(" ", name.getGenusOrUninomial(),name.getSpecificEpithet());
- }
- if (StringUtils.isNotBlank(taxonName)){
- textNewTaxonName.setText(taxonName + " ");
- if(textNewTaxonName.getMainControl() instanceof Text){
- Text text = (Text)textNewTaxonName.getMainControl();
- text.setSelection(textNewTaxonName.getText().length());
- }
- }
+ TaxonNode node = parentNode;
+ if(node != null && node.getTaxon()!=null){
+ Taxon taxon = HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class);
+ if(taxon.getName()!=null){
+ TaxonName name = HibernateProxyHelper.deproxy(node.getTaxon().getName());
+ if (!isCreateNew()){
+ textNewTaxonName.setText(name.getNameCache());
+ } else if( ! name.isSupraGeneric() && name.getRank() != null){
+ String taxonName = "";
+ if(name.isGenus() || name.isInfraGeneric()|| name.isSpeciesAggregate() ){
+ taxonName = name.getGenusOrUninomial();
+ }
+ else if(name.isSpecies() || name.isInfraSpecific() ){
+ taxonName = CdmUtils.concat(" ", name.getGenusOrUninomial(),name.getSpecificEpithet());
+ }
+ if (StringUtils.isNotBlank(taxonName)){
+ textNewTaxonName.setText(taxonName + " ");
+ if(textNewTaxonName.getMainControl() instanceof Text){
+ Text text = (Text)textNewTaxonName.getMainControl();
+ text.setSelection(textNewTaxonName.getText().length());
+ }
}
}
}
}
}
- /** {@inheritDoc} */
@Override
public void handleEvent(Object eventSource) {
if (eventSource == selection_parentTaxonNode) {
if (selection_reuseExistingTaxon.getEntity() != null){
setTaxon(selection_reuseExistingTaxon.getEntity());
if (getTaxon().getSec()!= null){
+ microReference.setText(getTaxon().getSecMicroReference());
if (isCreateNew()){
selection_SecRef.setEntity(getTaxon().getSec());
+
}else{
- textTaxonSec.setText((getTaxon().getSec().getTitleCache()));
+ textTaxonSec.setText((getTaxon().getSec().getTitleCache()));
}
}else{
+ microReference.setText("");
if (isCreateNew()){
- selection_SecRef.setEntity(null);
+ selection_SecRef.setEntity(null);
+
}else{
- textTaxonSec.setText("");
+ textTaxonSec.setText("");
}
}
- checkbox_publish.setSelected(getTaxon().isPublish());
+ if (checkbox_publish != null){
+ checkbox_publish.setSelected(getTaxon().isPublish());
+ }
+ }else{
+ selection_SecRef.setEntity(null);
+ setDefaultPublish();
+ }
+ boolean enabled = selection_reuseExistingTaxon.getEntity() == null;
+ if (selection_reuseExistingName != null){
+ selection_reuseExistingName.setEnabled(enabled);
+ }
+ if (selection_SecRef != null){
+ selection_SecRef.setEnabled(enabled);
}
+ if (textNewTaxonName != null){
+ textNewTaxonName.setEnabled(enabled);
+ }
complete = true;
} else if (eventSource == selection_reuseExistingName) {
boolean enabled = selection_reuseExistingName.getEntity() == null;
}
textNewTaxonName.setEnabled(enabled);
complete = !textNewTaxonName.getText().isEmpty();
- }
-
- if (eventSource == selection_Ref) {
- getEntity().setReference(selection_Ref.getEntity());
- }else if (eventSource == selection_SecRef) {
- taxon.setSec(selection_SecRef.getEntity());
- }else if (eventSource == microReference) {
- getEntity().setMicroReference(microReference.getText());
- } else if (eventSource == checkbox_publish) {
- taxon.setPublish(checkbox_publish.getSelection());
}
- if (eventSource == checkbox_excluded) {
- excluded = checkbox_excluded.getSelection();
+ if (eventSource == combo_status) {
+ status = combo_status.getSelection();
+ if (status == null){
+ if (multiLanguageTextStatusNotes.getMultilanguageText() != null && !multiLanguageTextStatusNotes.getMultilanguageText().isEmpty()){
+ multilanguageTextCache = new HashMap<>();
+ for (LanguageString langString: multiLanguageTextStatusNotes.getMultilanguageText().values()){
+ multilanguageTextCache.put(langString.getLanguage(), langString);
+ }
+// multilanguageTextCache = multiLanguageTextStatusNotes.getMultilanguageText();
+ }
+ multiLanguageTextStatusNotes.setMultilanguageText(new HashMap<>());
+// multiLanguageTextStatusNotes.refresh();
- getEntity().setExcluded(excluded);
+ }else if (multilanguageTextCache != null ){
- multiLanguageTextExcludedNotes.setEnabled(excluded);
- }
- if (eventSource == checkbox_unplaced) {
- unplaced = checkbox_unplaced.getSelection();
- getEntity().setUnplaced(unplaced);
+ multiLanguageTextStatusNotes.setMultilanguageText(multilanguageTextCache);
+ multilanguageTextCache = null;
+ }
+ if (!isCreateNew()){
+ getEntity().setStatus(status);
+ if (status == null){
+ getEntity().getStatusNote().clear();
+ multiLanguageTextStatusNotes.setMultilanguageText(new HashMap<>());
+ multiLanguageTextStatusNotes.refresh();
+ }else{
+ if (multiLanguageTextStatusNotes.getMultilanguageText() != null){
+ for (LanguageString lang:multiLanguageTextStatusNotes.getMultilanguageText().values()){
+ getEntity().putStatusNote(lang);
+ }
+ }
+ }
+ }
+
+ multiLanguageTextStatusNotes.setEnabled(status != null);
+ complete = true;
}
+
if (eventSource == textNewTaxonName) {
boolean enabled = CdmUtils.isBlank(textNewTaxonName.getText());
if (selection_reuseExistingTaxon != null){
return classification;
}
-// public boolean isOpenInEditor() {
-// return openInEditor;
-// }
-
- public ITaxonTreeNode getParentTreeNode() {
- return parentTreeNode;
+ public TaxonNode getParentTreeNode() {
+ return parentNode;
}
- private void setClassification(Classification classification) {
- this.classification = classification;
- //setParentTreeNode(classification);
- }
-
- private void setParentTreeNode(TaxonNode parentTreeNode) {
- this.parentTreeNode = parentTreeNode;
-
+ public void setParentTreeNode(TaxonNode parentTreeNode) {
+ this.parentNode = parentTreeNode;
+ updateContent();
if (parentTreeNode.getTaxon() == null) {
classification = parentTreeNode.getClassification();
-// if (selection_classification != null){
-// selection_classification.setEntity(classification);
-// }
- selection_parentTaxonNode.setEntity(classification.getRootNode());
- selection_parentTaxonNode.setClassification(classification);
- selection_SecRef.setEntity(classification.getReference());
+ if (selection_parentTaxonNode != null){
+ selection_parentTaxonNode.setEntity(classification.getRootNode());
+ selection_parentTaxonNode.setClassification(classification);
+ selection_SecRef.setEntity(classification.getReference());
+ }
} else {
classification = HibernateProxyHelper
.deproxy(parentTreeNode.getClassification());
-// if (selection_classification != null){
-// selection_classification.setEntity(classification);
-// }
- selection_parentTaxonNode.setEntity(HibernateProxyHelper
- .deproxy(parentTreeNode));
- selection_parentTaxonNode.setClassification(classification);
- selection_SecRef.setEntity(parentTreeNode.getTaxon().getSec());
-
+ if (selection_parentTaxonNode != null){
+ selection_parentTaxonNode.setEntity(HibernateProxyHelper.deproxy(parentTreeNode));
+ selection_parentTaxonNode.setClassification(classification);
+ selection_SecRef.setEntity(parentTreeNode.getTaxon().getSec());
+ }
}
}
+ @Override
+ protected void updateControlStates(){
+ Collection<Object> except = new ArrayList<Object>();
+ for(ICdmFormElement formElement:getElements()){
+ if(formElement instanceof IEnableableFormElement && !((IEnableableFormElement) formElement).isEnabled()){
+ except.add(formElement);
+ }
+ }
+ if (isCreateNew() ){
+ enabled = true;
+ }else{
+ enabled = getEntity() != null && CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getEntity()), requiredCrud);
+ }
+ setEnabled(enabled, except);
+ }
+
private void setTreeNode(TaxonNode treeNode) {
classification = HibernateProxyHelper
.deproxy(treeNode.getClassification());
if (isCreateNew()){
- //selection_classification.setEntity(classification);
- selection_parentTaxonNode.setEntity(treeNode.getParent());
- selection_parentTaxonNode.setClassification(treeNode.getParent().getClassification());
- selection_SecRef.setEntity(treeNode.getTaxon().getSec());
+ selection_parentTaxonNode.setEntity(treeNode.getParent());
+ selection_parentTaxonNode.setClassification(treeNode.getParent().getClassification());
+ selection_SecRef.setEntity(treeNode.getTaxon().getSec());
}
}
private void setTaxon(Taxon taxon) {
this.taxon = taxon;
- getEntity().setTaxon(taxon);
+ if (!isCreateNew()){
+ getEntity().setTaxon(taxon);
+ }
+
+ this.set_publish(taxon.isPublish());
if (isCreateNew()){
textNewTaxonName.setText(taxon.getName().getTitleCache());
if (taxon.getSec() != null){
this.textTaxonSec.setText(taxon.getSec().getTitleCache());
}
}
-
-
}
private void setTaxon(TaxonName taxonName) {
secundum = this.selection_SecRef.getEntity();
}
}
- if (taxonName != null){
- taxon = Taxon.NewInstance(taxonName, secundum);
- if (textNewTaxonName.getText() == null || !taxonName.getTitleCache().trim().equals(textNewTaxonName.getText().trim())){
- textNewTaxonName.setText(taxonName.getTitleCache());
- }
- getEntity().setTaxon(taxon);
-// if (!taxonName.getTitleCache().trim().equals(textNewTaxonName.getText().trim())){
-// textNewTaxonName.setText(taxonName.getTitleCache());
-// }
- } else {
- textNewTaxonName.setText(null);
- }
- }
-// private void setOpenInEditor(boolean openInEditor) {
-// this.openInEditor = openInEditor;
-// }
+ }
public String getTaxonName() {
return textNewTaxonName.getText();
return taxon;
}
- public Reference getReference(){
+ public Reference getSecReference(){
return selection_SecRef.getSelection();
}
return createNew;
}
- public boolean isExcluded() {
- return excluded;
- }
-
- public boolean isUnplaced() {
- return unplaced;
- }
-
public boolean is_publish() {
boolean isPublishPreference = true;
- CdmPreference defaultPublish = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DefaultBehaviourForPublishFlag);
- if (defaultPublish != null && defaultPublish.getValue().equals(PublishEnum.NotPublish.getKey())){
+ CdmPreference defaultPublish = CdmPreferenceCache.instance().get(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey());
+ if (defaultPublish != null && defaultPublish.getValue()!= null && defaultPublish.getValue().equals(PublishEnum.NotPublish.getKey())){
isPublishPreference = false;
}
return checkbox_publish!=null?checkbox_publish.getSelection():isPublishPreference;
}
public void set_publish(boolean publish) {
- this.checkbox_publish.setSelection(publish);
+ if (checkbox_publish != null){
+ this.checkbox_publish.setSelection(publish);
+ }
}
+ /**
+ * Updates all widgets to display the latest data
+ */
+ @Override
+ protected void updateContent() {
+ removeElements();
+ if (isCreateNew()){
+ createControls(this, parentNode, SWT.NONE);
+ }else{
+ createControls(this, getEntity(), SWT.NONE);
+ }
+ updateControlStates();
+ }
+ @Override
+ public SelectionArbitrator getSelectionArbitrator() {
+ // TODO Auto-generated method stub
+ return null;
+ }
}