performed javacscript:fix and worked on documentation
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / section / AbstractCdmDetailSection.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.section;
12
13 import org.eclipse.jface.viewers.ISelectionProvider;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.graphics.Color;
16 import org.eclipse.ui.forms.events.ExpansionEvent;
17 import org.eclipse.ui.forms.events.IExpansionListener;
18 import org.eclipse.ui.forms.widgets.Section;
19 import org.eclipse.ui.forms.widgets.TableWrapLayout;
20
21 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
22 import eu.etaxonomy.cdm.model.common.IAnnotatableEntity;
23 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
24 import eu.etaxonomy.taxeditor.forms.AbstractFormSection;
25 import eu.etaxonomy.taxeditor.forms.CdmFormFactory;
26 import eu.etaxonomy.taxeditor.forms.CdmFormFactory.DetailType;
27 import eu.etaxonomy.taxeditor.forms.ICdmFormElement;
28 import eu.etaxonomy.taxeditor.forms.IEnableableFormElement;
29 import eu.etaxonomy.taxeditor.forms.ISelectableElement;
30 import eu.etaxonomy.taxeditor.forms.SelectionArbitrator;
31
32 /**
33 * <p>Abstract AbstractCdmDetailSection class.</p>
34 *
35 * @author n.hoffmann
36 * @created Feb 26, 2010
37 * @version 1.0
38 */
39 public abstract class AbstractCdmDetailSection<ENTITY extends IAnnotatableEntity> extends AbstractFormSection<ENTITY> implements IEnableableFormElement, IExpansionListener{
40
41 protected AbstractCdmDetailElement<ENTITY> detailElement;
42
43 protected SelectionArbitrator selectionArbitrator;
44
45 /**
46 * <p>Constructor for AbstractCdmDetailSection.</p>
47 *
48 * @param formFactory a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory} object.
49 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
50 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
51 * @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
52 * @param style a int.
53 * @param <ENTITY> a ENTITY object.
54 */
55 public AbstractCdmDetailSection(CdmFormFactory formFactory,
56 ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
57 super(formFactory, conversation, parentElement, selectionProvider, Section.CLIENT_INDENT | style);
58 this.setText(getHeading());
59
60 this.addExpansionListener(this);
61
62 createControls(this, SWT.NULL);
63 }
64
65
66 /**
67 * <p>createControls</p>
68 *
69 * @param formElement a {@link eu.etaxonomy.taxeditor.section.AbstractCdmDetailSection} object.
70 * @param style a int.
71 */
72 protected void createControls(AbstractCdmDetailSection<ENTITY> formElement, int style) {
73 TableWrapLayout layout = (TableWrapLayout) getLayoutComposite().getLayout();
74 layout.topMargin = 10;
75 layout.numColumns = 2;
76
77 getLayoutComposite().setLayout(layout);
78 detailElement = formFactory.createCdmDetailElement(getDetailType(), formElement, style);
79 }
80
81 /**
82 * <p>getDetailType</p>
83 *
84 * @return a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory.DetailType} object.
85 */
86 protected abstract DetailType getDetailType();
87
88 /**
89 * <p>getHeading</p>
90 *
91 * @return the heading for this section
92 */
93 public abstract String getHeading();
94
95 /** {@inheritDoc} */
96 @Override
97 public void dispose() {
98 if(detailElement instanceof ISelectableElement){
99 formFactory.destroySelectionArbitrator(((ISelectableElement)detailElement).getSelectionArbitrator());
100 }
101 super.dispose();
102 }
103
104 /* (non-Javadoc)
105 * @see eu.etaxonomy.taxeditor.forms.section.AbstractEditorFormSection#setBackground(org.eclipse.swt.graphics.Color)
106 */
107 /** {@inheritDoc} */
108 @Override
109 public void setBackground(Color color) {
110 if(detailElement != null){
111 // detailComposite.setBackground(color);
112 }
113 super.setBackground(color);
114 }
115
116 /**
117 * <p>setEntity</p>
118 *
119 * @param entity a ENTITY object.
120 */
121 public void setEntity(ENTITY entity) {
122 if(detailElement != null){
123 detailElement.setEntity(entity);
124 }
125 super.setEntity(entity);
126 setSectionTitle();
127 layout();
128 }
129
130 /**
131 * <p>setSectionTitle</p>
132 */
133 protected void setSectionTitle(){
134 String title = "";
135 if(getEntity() != null && (getEntity() instanceof IdentifiableEntity)){
136 title = ": " + ((IdentifiableEntity) getEntity()).getTitleCache();
137 }
138 this.setText(getHeading() + title);
139 }
140
141 /**
142 * <p>updateTitle</p>
143 */
144 public void updateTitle(){
145 if(!isDisposed()){
146 setSectionTitle();
147 layout();
148 }
149 }
150
151 /** {@inheritDoc} */
152 public void setIrrelevant(boolean irrelevant) {
153 if(detailElement != null){
154 detailElement.setIrrelevant(irrelevant);
155 }
156 }
157
158 /** {@inheritDoc} */
159 public void expansionStateChanging(ExpansionEvent e) {
160 // logger.warn("Expansion State Changing");
161 }
162
163 /** {@inheritDoc} */
164 public void expansionStateChanged(ExpansionEvent e) {
165 // logger.warn("Expansion State Changed");
166 }
167 }