Project

General

Profile

Download (5.11 KB) Statistics
| Branch: | Tag: | Revision:
1 729887cf n.hoffmann
// $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 f211dd28 n.hoffmann
package eu.etaxonomy.taxeditor.ui.section;
12 729887cf n.hoffmann
13 6747dad6 n.hoffmann
import org.eclipse.jface.action.ToolBarManager;
14 729887cf n.hoffmann
import org.eclipse.jface.viewers.ISelectionProvider;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.graphics.Color;
17 6747dad6 n.hoffmann
import org.eclipse.swt.widgets.Control;
18 2d9a13f7 n.hoffmann
import org.eclipse.ui.forms.events.ExpansionEvent;
19
import org.eclipse.ui.forms.events.IExpansionListener;
20 729887cf n.hoffmann
import org.eclipse.ui.forms.widgets.Section;
21
import org.eclipse.ui.forms.widgets.TableWrapLayout;
22
23 2d9a13f7 n.hoffmann
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
24 729887cf n.hoffmann
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
25 f211dd28 n.hoffmann
import eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection;
26
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
27 707b6237 n.hoffmann
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType;
28 f211dd28 n.hoffmann
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
29
import eu.etaxonomy.taxeditor.ui.forms.IEnableableFormElement;
30
import eu.etaxonomy.taxeditor.ui.forms.ISelectableElement;
31 729887cf n.hoffmann
32
/**
33 3be6ef3e n.hoffmann
 * <p>Abstract AbstractCdmDetailSection class.</p>
34
 *
35 729887cf n.hoffmann
 * @author n.hoffmann
36
 * @created Feb 26, 2010
37
 * @version 1.0
38
 */
39 35861667 n.hoffmann
public abstract class AbstractCdmDetailSection<ENTITY> extends AbstractFormSection<ENTITY> implements IEnableableFormElement, IExpansionListener{
40 729887cf n.hoffmann
	
41 74b9f670 n.hoffmann
	protected AbstractCdmDetailElement<ENTITY> detailElement;
42 729887cf n.hoffmann
	
43 3be6ef3e n.hoffmann
	/**
44
	 * <p>Constructor for AbstractCdmDetailSection.</p>
45
	 *
46 f211dd28 n.hoffmann
	 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
47 3be6ef3e n.hoffmann
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
48 f211dd28 n.hoffmann
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
49 3be6ef3e n.hoffmann
	 * @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
50
	 * @param style a int.
51
	 * @param <ENTITY> a ENTITY object.
52
	 */
53 729887cf n.hoffmann
	public AbstractCdmDetailSection(CdmFormFactory formFactory,
54 2d9a13f7 n.hoffmann
			ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
55
		super(formFactory, conversation, parentElement, selectionProvider, Section.CLIENT_INDENT | style);
56 729887cf n.hoffmann
		
57 6747dad6 n.hoffmann
		setText(getHeading());
58
		
59
		addExpansionListener(this);
60 2d9a13f7 n.hoffmann
		
61 729887cf n.hoffmann
		createControls(this, SWT.NULL);
62
	}
63 6747dad6 n.hoffmann
64
65 3be6ef3e n.hoffmann
	/**
66
	 * <p>createControls</p>
67
	 *
68 f211dd28 n.hoffmann
	 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection} object.
69 3be6ef3e n.hoffmann
	 * @param style a int.
70
	 */
71 74b9f670 n.hoffmann
	protected void createControls(AbstractCdmDetailSection<ENTITY> formElement, int style) {
72 729887cf n.hoffmann
		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 3be6ef3e n.hoffmann
	/**
81
	 * <p>getDetailType</p>
82
	 *
83 f211dd28 n.hoffmann
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType} object.
84 3be6ef3e n.hoffmann
	 */
85 729887cf n.hoffmann
	protected abstract DetailType getDetailType();
86
87
	/**
88 3be6ef3e n.hoffmann
	 * <p>getHeading</p>
89
	 *
90 729887cf n.hoffmann
	 * @return the heading for this section
91
	 */
92
	public abstract String getHeading();
93
	
94 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
95 729887cf n.hoffmann
	@Override
96
	public void dispose() {
97
		if(detailElement instanceof ISelectableElement){
98 6a6ea365 n.hoffmann
			ISelectableElement selectableElement = (ISelectableElement) detailElement;
99
			if(selectableElement.getSelectionArbitrator() != null){
100
				formFactory.destroySelectionArbitrator(selectableElement.getSelectionArbitrator());
101
			}
102 729887cf n.hoffmann
		}
103
		super.dispose();
104
	}
105
	
106
	/* (non-Javadoc)
107
	 * @see eu.etaxonomy.taxeditor.forms.section.AbstractEditorFormSection#setBackground(org.eclipse.swt.graphics.Color)
108
	 */
109 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
110 729887cf n.hoffmann
	@Override
111
	public void setBackground(Color color) {
112
		if(detailElement != null){
113
//			detailComposite.setBackground(color);
114
		}
115
		super.setBackground(color);
116
	}
117
	
118 3be6ef3e n.hoffmann
	/**
119
	 * <p>setEntity</p>
120
	 *
121
	 * @param entity a ENTITY object.
122
	 */
123 707b6237 n.hoffmann
	@Override
124 74b9f670 n.hoffmann
	public void setEntity(ENTITY entity) {
125 729887cf n.hoffmann
		if(detailElement != null){
126
			detailElement.setEntity(entity);
127
		}
128
		super.setEntity(entity);
129
		setSectionTitle();
130
		layout();
131
	}
132
	
133 3be6ef3e n.hoffmann
	/**
134
	 * <p>setSectionTitle</p>
135
	 */
136 729887cf n.hoffmann
	protected void setSectionTitle(){
137
		String title = "";
138
		if(getEntity() != null && (getEntity() instanceof IdentifiableEntity)){
139
			 title = ": " + ((IdentifiableEntity) getEntity()).getTitleCache();
140
		}
141 707b6237 n.hoffmann
		this.setText(String.format("%s%s", getHeading(), title));
142 6747dad6 n.hoffmann
		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 729887cf n.hoffmann
	}
153
	
154 3be6ef3e n.hoffmann
	/**
155
	 * <p>updateTitle</p>
156
	 */
157 729887cf n.hoffmann
	public void updateTitle(){
158 30140758 n.hoffmann
		if(!isDisposed()){
159
			setSectionTitle();
160
			layout();
161
		}
162 729887cf n.hoffmann
	}
163
	
164 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
165 729887cf n.hoffmann
	public void setIrrelevant(boolean irrelevant) {
166
		if(detailElement != null){
167
			detailElement.setIrrelevant(irrelevant);
168
		}
169
	}
170 2d9a13f7 n.hoffmann
	
171 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
172 2d9a13f7 n.hoffmann
	public void expansionStateChanging(ExpansionEvent e) {
173 cfcb0ce6 n.hoffmann
//		logger.warn("Expansion State Changing");
174 2d9a13f7 n.hoffmann
	}
175
	
176 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
177 2d9a13f7 n.hoffmann
	public void expansionStateChanged(ExpansionEvent e) {
178 cfcb0ce6 n.hoffmann
//		logger.warn("Expansion State Changed");
179 2d9a13f7 n.hoffmann
	}
180 729887cf n.hoffmann
}