Project

General

Profile

Download (5.09 KB) Statistics
| Branch: | Tag: | Revision:
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.CdmFormFactory.DetailType;
28
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
29
import eu.etaxonomy.taxeditor.ui.forms.IEnableableFormElement;
30
import eu.etaxonomy.taxeditor.ui.forms.ISelectableElement;
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
	@Override
124
	public void setEntity(ENTITY entity) {
125
		if(detailElement != null){
126
			detailElement.setEntity(entity);
127
		}
128
		super.setEntity(entity);
129
		setSectionTitle();
130
		layout();
131
	}
132
	
133
	/**
134
	 * <p>setSectionTitle</p>
135
	 */
136
	protected void setSectionTitle(){
137
		String title = "";
138
		if(getEntity() != null && (getEntity() instanceof IdentifiableEntity)){
139
			 title = ": " + ((IdentifiableEntity) getEntity()).getTitleCache();
140
		}
141
		this.setText(getHeading() + title);
142
		setTextClient(createToolbar());
143
	}
144
	
145

    
146
	/**
147
	 * @return
148
	 */
149
	protected Control createToolbar() {
150
		ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
151
		return toolBarManager.createControl(this);
152
	}
153
	
154
	/**
155
	 * <p>updateTitle</p>
156
	 */
157
	public void updateTitle(){
158
		if(!isDisposed()){
159
			setSectionTitle();
160
			layout();
161
		}
162
	}
163
	
164
	/** {@inheritDoc} */
165
	public void setIrrelevant(boolean irrelevant) {
166
		if(detailElement != null){
167
			detailElement.setIrrelevant(irrelevant);
168
		}
169
	}
170
	
171
	/** {@inheritDoc} */
172
	public void expansionStateChanging(ExpansionEvent e) {
173
//		logger.warn("Expansion State Changing");
174
	}
175
	
176
	/** {@inheritDoc} */
177
	public void expansionStateChanged(ExpansionEvent e) {
178
//		logger.warn("Expansion State Changed");
179
	}
180
}
(2-2/7)