2 * Copyright (C) 2007 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.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
12 import org
.eclipse
.swt
.events
.SelectionListener
;
13 import org
.eclipse
.swt
.graphics
.Color
;
15 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
16 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
17 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
18 import eu
.etaxonomy
.taxeditor
.preference
.NameDetailsConfigurator
;
19 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
20 import eu
.etaxonomy
.taxeditor
.ui
.combo
.term
.TermComboElement
;
21 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
22 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.LabelElement
;
25 import eu
.etaxonomy
.taxeditor
.ui
.section
.supplemental
.AbstractReferencedEntityElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
29 * <p>NameRelationshipDetailElement class.</p>
32 * @created Mar 18, 2010
34 public class NameRelationshipDetailElement
extends AbstractReferencedEntityElement
<NameRelationship
>{
36 private RuleConsideredElement ruleConsidered
;
37 private EntitySelectionElement
<?
> selection_toName
;
38 private TermComboElement
<NameRelationshipType
> combo_relationshipType
;
39 private LabelElement label
;
42 * <p>Constructor for NameRelationshipDetailElement.</p>
44 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
45 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
46 * @param entity a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object.
47 * @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
50 public NameRelationshipDetailElement(CdmFormFactory cdmFormFactory
,
51 AbstractFormSection formElement
,
52 NameRelationship entity
, SelectionListener removeListener
, int style
) {
53 super(cdmFormFactory
, formElement
, entity
, removeListener
, style
);
57 public void createControls(ICdmFormElement element
, int style
) {
58 NameDetailsConfigurator config
= PreferencesUtil
.getPreferredNameDetailsConfiguration();
59 label
= formFactory
.createLabel(element
, null);
60 if (config
== null || config
.isNameRelationsRuleConsideredActivated()){
61 ruleConsidered
= formFactory
.createRuleConsideredElement(
62 element
, "Rule Considered", config
== null
63 || config
.isNameRelationsRuleConsideredCodeEditionActivated(), style
);
65 super.createControls(element
, style
);
69 public void setEntity(NameRelationship entity
) {
70 String text
= (entity
.getFromName() == null?
"-":entity
.getFromName().getTitleCache())
71 + " is " + (entity
.getType()==null?
"(no type)":entity
.getType().getLabel())
72 + " " + (entity
.getToName()==null?
"-":entity
.getToName().getTitleCache());
74 if (ruleConsidered
!= null){
75 ruleConsidered
.setElement(entity
);
77 super.setEntity(entity
);
81 public void handleEvent(Object eventSource
) {
82 if(eventSource
== combo_relationshipType
){
83 getEntity().setType(combo_relationshipType
.getSelection());
85 else if(eventSource
== selection_toName
){
86 MessagingUtils
.error(getClass(), "No API call available.", null);
88 else if(eventSource
== selection_reference
){
89 getEntity().setCitation(selection_reference
.getSelection());
91 else if(eventSource
== text_referenceDetail
){
92 getEntity().setCitationMicroReference(text_referenceDetail
.getText());
97 public void setBackground(Color color
) {
99 label
.setBackground(color
);
101 super.setBackground(color
);