15fcf7e6b654bc738c70efc155a7184cfe31af65
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / 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.ui.section;
12
13 import org.eclipse.jface.action.ToolBarManager;
14 import org.eclipse.jface.viewers.ISelectionProvider;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.graphics.Color;
17 import org.eclipse.swt.widgets.Control;
18 import org.eclipse.ui.forms.events.ExpansionEvent;
19 import org.eclipse.ui.forms.events.IExpansionListener;
20 import org.eclipse.ui.forms.widgets.Section;
21 import org.eclipse.ui.forms.widgets.TableWrapLayout;
22
23 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
24 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
25 import eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection;
26 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
27 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
28 import eu.etaxonomy.taxeditor.ui.forms.IEnableableFormElement;
29 import eu.etaxonomy.taxeditor.ui.forms.ISelectableElement;
30 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType;
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 AbstractFormSection<ENTITY> implements IEnableableFormElement, IExpansionListener{
40
41 protected AbstractCdmDetailElement<ENTITY> detailElement;
42
43 /**
44 * <p>Constructor for AbstractCdmDetailSection.</p>
45 *
46 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
47 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
48 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
49 * @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
50 * @param style a int.
51 * @param <ENTITY> a ENTITY object.
52 */
53 public AbstractCdmDetailSection(CdmFormFactory formFactory,
54 ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
55 super(formFactory, conversation, parentElement, selectionProvider, Section.CLIENT_INDENT | style);
56
57 setText(getHeading());
58
59 addExpansionListener(this);
60
61 createControls(this, SWT.NULL);
62 }
63
64
65 /**
66 * <p>createControls</p>
67 *
68 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection} object.
69 * @param style a int.
70 */
71 protected void createControls(AbstractCdmDetailSection<ENTITY> formElement, int style) {
72 TableWrapLayout layout = (TableWrapLayout) getLayoutComposite().getLayout();
73 layout.topMargin = 10;
74 layout.numColumns = 2;
75
76 getLayoutComposite().setLayout(layout);
77 detailElement = formFactory.createCdmDetailElement(getDetailType(), formElement, style);
78 }
79
80 /**
81 * <p>getDetailType</p>
82 *
83 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType} object.
84 */
85 protected abstract DetailType getDetailType();
86
87 /**
88 * <p>getHeading</p>
89 *
90 * @return the heading for this section
91 */
92 public abstract String getHeading();
93
94 /** {@inheritDoc} */
95 @Override
96 public void dispose() {
97 if(detailElement instanceof ISelectableElement){
98 ISelectableElement selectableElement = (ISelectableElement) detailElement;
99 if(selectableElement.getSelectionArbitrator() != null){
100 formFactory.destroySelectionArbitrator(selectableElement.getSelectionArbitrator());
101 }
102 }
103 super.dispose();
104 }
105
106 /* (non-Javadoc)
107 * @see eu.etaxonomy.taxeditor.forms.section.AbstractEditorFormSection#setBackground(org.eclipse.swt.graphics.Color)
108 */
109 /** {@inheritDoc} */
110 @Override
111 public void setBackground(Color color) {
112 if(detailElement != null){
113 // detailComposite.setBackground(color);
114 }
115 super.setBackground(color);
116 }
117
118 /**
119 * <p>setEntity</p>
120 *
121 * @param entity a ENTITY object.
122 */
123 public void setEntity(ENTITY entity) {
124 if(detailElement != null){
125 detailElement.setEntity(entity);
126 }
127 super.setEntity(entity);
128 setSectionTitle();
129 layout();
130 }
131
132 /**
133 * <p>setSectionTitle</p>
134 */
135 protected void setSectionTitle(){
136 String title = "";
137 if(getEntity() != null && (getEntity() instanceof IdentifiableEntity)){
138 title = ": " + ((IdentifiableEntity) getEntity()).getTitleCache();
139 }
140 this.setText(getHeading() + title);
141 setTextClient(createToolbar());
142 }
143
144
145 /**
146 * @return
147 */
148 protected Control createToolbar() {
149 ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
150 return toolBarManager.createControl(this);
151 }
152
153 /**
154 * <p>updateTitle</p>
155 */
156 public void updateTitle(){
157 if(!isDisposed()){
158 setSectionTitle();
159 layout();
160 }
161 }
162
163 /** {@inheritDoc} */
164 public void setIrrelevant(boolean irrelevant) {
165 if(detailElement != null){
166 detailElement.setIrrelevant(irrelevant);
167 }
168 }
169
170 /** {@inheritDoc} */
171 public void expansionStateChanging(ExpansionEvent e) {
172 // logger.warn("Expansion State Changing");
173 }
174
175 /** {@inheritDoc} */
176 public void expansionStateChanged(ExpansionEvent e) {
177 // logger.warn("Expansion State Changed");
178 }
179 }