Project

General

Profile

Download (4.57 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.description;
12

    
13
import org.eclipse.jface.action.Action;
14
import org.eclipse.jface.action.ToolBarManager;
15
import org.eclipse.jface.viewers.ISelectionProvider;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.widgets.Control;
18

    
19
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
20
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
21
import eu.etaxonomy.cdm.model.description.TextData;
22
import eu.etaxonomy.taxeditor.model.MessagingUtils;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24
import eu.etaxonomy.taxeditor.store.StoreUtil;
25
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
26
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
27
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
28
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
29
import eu.etaxonomy.taxeditor.ui.section.description.operation.ChangeDescriptionElementType;
30

    
31
/**
32
 * <p>DescriptionElementDetailSection class.</p>
33
 *
34
 * @author n.hoffmann
35
 * @created Mar 5, 2010
36
 * @version 1.0
37
 */
38
public class DescriptionElementDetailSection extends
39
		AbstractCdmDetailSection<DescriptionElementBase> {
40

    
41
	/**
42
	 * <p>Constructor for DescriptionElementDetailSection.</p>
43
	 *
44
	 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
45
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
46
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
47
	 * @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
48
	 * @param style a int.
49
	 */
50
	public DescriptionElementDetailSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation,
51
			ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
52
		super(cdmFormFactory, conversation, parentElement, selectionProvider, style);
53
	}
54

    
55

    
56
	@Override
57
    protected Control createToolbar() {
58
		if(! hasSpecificElement()){
59
			return null;
60
		}
61

    
62
		ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
63

    
64
		final String destinationString = (getEntity() instanceof TextData) ? "the specific element" : "free text";
65

    
66
		final String label = "Change to " + destinationString;
67

    
68
		Action addAction = new Action("Change Type", Action.AS_PUSH_BUTTON) {
69
			/* (non-Javadoc)
70
			 * @see org.eclipse.jface.action.Action#run()
71
			 */
72
			@Override
73
			public void run() {
74
				boolean confirmed = MessagingUtils.confirmDialog("Confirmation", "Do you really want to change to "
75
						+ destinationString + "? Current data will be lost.");
76
				if (confirmed) {
77
					// FIXME
78
					ChangeDescriptionElementType operation = new ChangeDescriptionElementType(label,
79
							getEntity(), StoreUtil.getDetailsView(), StoreUtil.getUndoContext());
80
					StoreUtil.executeOperation(operation);
81
				}
82
			}
83
		};
84
		// TODO enable this once a proper icon has been found
85
		// ticket #5043
86
//		addAction.setImageDescriptor(new ImageDescriptor() {
87
//
88
//			@Override
89
//			public ImageData getImageData() {
90
//				return ImageResources.getImage(ImageResources.ADD_ICON).getImageData();
91
//			}
92
//		});
93
		addAction.setToolTipText(label);
94

    
95
		toolBarManager.add(addAction);
96

    
97
		return toolBarManager.createControl(this);
98
	}
99

    
100
	/** {@inheritDoc} */
101
	@Override
102
	public String getHeading() {
103
		return "Description Element";
104
	}
105

    
106
	/** {@inheritDoc} */
107
	@Override
108
	protected void setSectionTitle() {
109
		this.setText(getHeading() + ": " + getEntity().getFeature().getLabel(CdmStore.getDefaultLanguage()));
110
		setTextClient(createToolbar());
111
	}
112

    
113
	private boolean hasSpecificElement(){
114
		return  getEntity().getFeature().isSupportsCategoricalData()
115
				|| getEntity().getFeature().isSupportsCommonTaxonName()
116
				|| getEntity().getFeature().isSupportsDistribution()
117
				|| getEntity().getFeature().isSupportsIndividualAssociation()
118
				|| getEntity().getFeature().isSupportsQuantitativeData()
119
				|| getEntity().getFeature().isSupportsTaxonInteraction();
120
	}
121

    
122
	/* (non-Javadoc)
123
	 * @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection#createCdmDetailElement(eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection, int)
124
	 */
125
	@Override
126
	protected AbstractCdmDetailElement<DescriptionElementBase> createCdmDetailElement(AbstractCdmDetailSection<DescriptionElementBase> parentElement, int style) {
127
	    return formFactory.createDescriptionElementDetailElement(parentElement, style);
128
	}
129
}
(6-6/24)