Project

General

Profile

Download (4.25 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.description;
12 729887cf n.hoffmann
13 2d9a13f7 n.hoffmann
import org.eclipse.jface.action.Action;
14
import org.eclipse.jface.action.ToolBarManager;
15 729887cf n.hoffmann
import org.eclipse.jface.viewers.ISelectionProvider;
16 2d9a13f7 n.hoffmann
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.widgets.Control;
18 729887cf n.hoffmann
19 2d9a13f7 n.hoffmann
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
20 729887cf n.hoffmann
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
21 2d9a13f7 n.hoffmann
import eu.etaxonomy.cdm.model.description.TextData;
22 729887cf n.hoffmann
import eu.etaxonomy.taxeditor.store.CdmStore;
23 f211dd28 n.hoffmann
import eu.etaxonomy.taxeditor.store.StoreUtil;
24
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
25
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
26
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType;
27
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
28
import eu.etaxonomy.taxeditor.ui.section.description.operation.ChangeDescriptionElementType;
29 729887cf n.hoffmann
30
/**
31 3be6ef3e n.hoffmann
 * <p>DescriptionElementDetailSection class.</p>
32
 *
33 729887cf n.hoffmann
 * @author n.hoffmann
34
 * @created Mar 5, 2010
35
 * @version 1.0
36
 */
37
public class DescriptionElementDetailSection extends
38
		AbstractCdmDetailSection<DescriptionElementBase> {
39 2d9a13f7 n.hoffmann
	
40 3be6ef3e n.hoffmann
	/**
41
	 * <p>Constructor for DescriptionElementDetailSection.</p>
42
	 *
43 f211dd28 n.hoffmann
	 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
44 3be6ef3e n.hoffmann
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
45 f211dd28 n.hoffmann
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
46 3be6ef3e n.hoffmann
	 * @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
47
	 * @param style a int.
48
	 */
49 2d9a13f7 n.hoffmann
	public DescriptionElementDetailSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation,
50 729887cf n.hoffmann
			ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
51 2d9a13f7 n.hoffmann
		super(cdmFormFactory, conversation, parentElement, selectionProvider, style);
52
	}
53
	
54
	
55 6747dad6 n.hoffmann
	protected Control createToolbar() {
56 3fb05254 n.hoffmann
		if(! hasSpecificElement()){
57
			return null;
58
		}
59
		
60 2d9a13f7 n.hoffmann
		ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
61
		
62
		final String destinationString = (getEntity() instanceof TextData) ? "the specific element" : "free text";
63
		
64
		final String label = "Change to " + destinationString; 
65
		
66
		Action addAction = new Action("Change Type", Action.AS_PUSH_BUTTON) {
67
			/* (non-Javadoc)
68
			 * @see org.eclipse.jface.action.Action#run()
69
			 */
70
			@Override
71
			public void run() {
72 f211dd28 n.hoffmann
				boolean confirmed = StoreUtil.confirmDialog("Confirmation", "Do you really want to change to "
73 3fb05254 n.hoffmann
						+ destinationString + "? Current data will be lost.");
74 2d9a13f7 n.hoffmann
				if (confirmed) {
75 f211dd28 n.hoffmann
					// FIXME
76 3fb05254 n.hoffmann
					ChangeDescriptionElementType operation = new ChangeDescriptionElementType(label, 
77 f211dd28 n.hoffmann
							getEntity(), StoreUtil.getDetailsView(), StoreUtil.getUndoContext());
78
					StoreUtil.executeOperation(operation);
79 2d9a13f7 n.hoffmann
				}
80
			}
81
		};
82
		// TODO enable this once a proper icon has been found 
83
//		addAction.setImageDescriptor(new ImageDescriptor() {
84
//			
85
//			@Override
86
//			public ImageData getImageData() {
87
//				return ImageResources.getImage(ImageResources.ADD_ICON).getImageData();
88
//			}
89
//		});
90
		addAction.setToolTipText(label);
91
		
92
		toolBarManager.add(addAction);
93
		
94
		ICdmFormElement parentElement = this.getParentElement();
95
		
96
		
97
		return toolBarManager.createControl(this);
98 729887cf n.hoffmann
	}
99
	
100 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
101 729887cf n.hoffmann
	@Override
102
	public String getHeading() {
103
		return "Description Element";
104
	}
105
106 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
107 729887cf n.hoffmann
	@Override
108
	protected DetailType getDetailType() {
109
		return DetailType.DESCRIPTIONELEMENT;
110
	}
111
	
112 3be6ef3e n.hoffmann
	/** {@inheritDoc} */
113 729887cf n.hoffmann
	@Override
114
	protected void setSectionTitle() {
115
		this.setText(getHeading() + ": " + getEntity().getFeature().getLabel(CdmStore.getDefaultLanguage()));
116 3fb05254 n.hoffmann
		setTextClient(createToolbar());
117
	}
118
	
119
	private boolean hasSpecificElement(){
120
		return  getEntity().getFeature().isSupportsCategoricalData() 
121
				|| getEntity().getFeature().isSupportsCommonTaxonName()
122
				|| getEntity().getFeature().isSupportsDistribution()
123
				|| getEntity().getFeature().isSupportsIndividualAssociation()
124
				|| getEntity().getFeature().isSupportsQuantitativeData()
125
				|| getEntity().getFeature().isSupportsTaxonInteraction();
126 729887cf n.hoffmann
	}
127
}