Project

General

Profile

Download (5.61 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.wizard;
12

    
13
import org.apache.log4j.Logger;
14
import org.eclipse.jface.util.IPropertyChangeListener;
15
import org.eclipse.jface.util.PropertyChangeEvent;
16
import org.eclipse.jface.wizard.WizardPage;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.graphics.Color;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Display;
21

    
22
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
23
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
24
import eu.etaxonomy.cdm.common.CdmUtils;
25
import eu.etaxonomy.cdm.model.common.LanguageString;
26
import eu.etaxonomy.cdm.model.taxon.Classification;
27
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
28
import eu.etaxonomy.taxeditor.forms.CdmFormFactory;
29
import eu.etaxonomy.taxeditor.forms.CdmFormFactory.SelectionType;
30
import eu.etaxonomy.taxeditor.forms.RootElement;
31
import eu.etaxonomy.taxeditor.forms.TextWithLabelElement;
32
import eu.etaxonomy.taxeditor.forms.selection.ReferenceSelectionElement;
33
import eu.etaxonomy.taxeditor.store.CdmStore;
34

    
35
/**
36
 * <p>ClassificationWizardPage class.</p>
37
 *
38
 * @author n.hoffmann
39
 * @created Sep 29, 2010
40
 * @version 1.0
41
 */
42
public class ClassificationWizardPage extends WizardPage implements IPropertyChangeListener, IConversationEnabled {
43
	private static final Logger logger = Logger
44
			.getLogger(ClassificationWizardPage.class);
45
	private Classification classification;
46
	
47
	private ConversationHolder conversation;
48
	private CdmFormFactory formFactory;
49
	private Composite control;
50
	private TextWithLabelElement text_classificationLabel;
51
	private ReferenceSelectionElement selection_reference;
52
	private TextWithLabelElement text_referenceDetail;
53

    
54
	/**
55
	 * <p>Constructor for ClassificationWizardPage.</p>
56
	 *
57
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
58
	 * @param classification a {@link eu.etaxonomy.cdm.model.taxon.TaxonomicTree} object.
59
	 */
60
	protected ClassificationWizardPage(ConversationHolder conversation, Classification classification){
61
		super("Classification");
62
		this.setTitle("Classification");
63
		this.setDescription(classification == null ? "Create a new Classification." : "Edit Classification.");
64
		
65
		this.classification = classification;
66
		this.conversation = conversation;
67
		
68
		this.formFactory = new CdmFormFactory(Display.getCurrent());
69
		
70
		formFactory.addPropertyChangeListener(this);
71
		
72
		initialize();
73
	}
74
	
75
	
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
78
	 */
79
	/** {@inheritDoc} */
80
	public void createControl(Composite parent) {
81
		control = formFactory.createComposite(parent);
82
		
83
		control.setLayout(CdmFormFactory.LAYOUT(2, false));
84
		RootElement rootElement = new RootElement(formFactory, control);
85
		
86
		text_classificationLabel = formFactory.createTextWithLabelElement(rootElement, "Label", classification.getName().getText(), SWT.NULL);
87
		selection_reference = (ReferenceSelectionElement) formFactory.createSelectionElement(SelectionType.REFERENCE, getConversationHolder(), rootElement, "Reference", classification.getReference(), SWT.NULL);
88
		text_referenceDetail = formFactory.createTextWithLabelElement(rootElement, "Reference Detail", classification.getMicroReference(), SWT.NULL);
89
		
90
		Color bgColor = getShell().getBackground();
91
		
92
		rootElement.setBackground(bgColor);
93
		control.setBackground(bgColor);
94
		
95
		setControl(control);
96
	}
97

    
98
	private void initialize() {
99
		if(classification == null){
100
			classification = Classification.NewInstance(null, null, CdmStore.getDefaultLanguage());
101
		}
102
	}
103
	
104
	/* (non-Javadoc)
105
	 * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
106
	 */
107
	/** {@inheritDoc} */
108
	@Override
109
	public void propertyChange(PropertyChangeEvent event) {
110
		Object eventSource = event.getSource();
111
		
112
		if(eventSource == text_classificationLabel){
113
			classification.setName(LanguageString.NewInstance(text_classificationLabel.getText(), CdmStore.getDefaultLanguage()));
114
		}
115
		else if(eventSource == selection_reference){
116
			classification.setReference(selection_reference.getEntity());
117
		}
118
		else if(eventSource == text_referenceDetail){
119
			classification.setMicroReference(text_referenceDetail.getText());
120
		}
121
		
122
		checkComplete();
123
	}
124

    
125

    
126
	/**
127
	 * 
128
	 */
129
	private void checkComplete() {
130
		if(CdmUtils.isEmpty(text_classificationLabel.getText())){
131
			setMessage("A Classifications label may not be empty");
132
			setPageComplete(false);
133
		}else{
134
			setMessage(null);
135
			setPageComplete(true);
136
		}
137
	}
138

    
139
	/**
140
	 * <p>Getter for the field <code>classification</code>.</p>
141
	 *
142
	 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonomicTree} object.
143
	 */
144
	public Classification getClassification() {
145
		return classification;
146
	}
147

    
148

    
149
	/* (non-Javadoc)
150
	 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
151
	 */
152
	/** {@inheritDoc} */
153
	@Override
154
	public void update(CdmDataChangeMap changeEvents) {}
155

    
156

    
157
	/* (non-Javadoc)
158
	 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
159
	 */
160
	/** {@inheritDoc} */
161
	@Override
162
	public ConversationHolder getConversationHolder() {
163
		return conversation;
164
	}
165
	
166
	/* (non-Javadoc)
167
	 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
168
	 */
169
	/** {@inheritDoc} */
170
	@Override
171
	public void dispose() {
172
		formFactory.removePropertyChangeListener(this);
173
		super.dispose();
174
	}
175
}
(2-2/4)