Project

General

Profile

Download (4.75 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.ui.section.description;
11

    
12
import org.eclipse.jface.action.Action;
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.widgets.Control;
17

    
18
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
19
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
20
import eu.etaxonomy.cdm.model.description.Feature;
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

    
59
		ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
60

    
61
		final String destinationString = (getEntity().isInstanceOf(TextData.class)) ? "the specific element" : "free text";
62

    
63
		final String label = "Change to " + destinationString;
64

    
65
		Action addAction = new Action("Change Type", Action.AS_PUSH_BUTTON) {
66
			/* (non-Javadoc)
67
			 * @see org.eclipse.jface.action.Action#run()
68
			 */
69
			@Override
70
			public void run() {
71
				boolean confirmed = MessagingUtils.confirmDialog("Confirmation", "Do you really want to change to "
72
						+ destinationString + "? Current data will be lost.");
73
				if (confirmed) {
74
					// FIXME
75
					ChangeDescriptionElementType operation = new ChangeDescriptionElementType(label,
76
							getEntity(), StoreUtil.getDetailsView(), StoreUtil.getUndoContext());
77
					StoreUtil.executeOperation(operation);
78
				}
79
			}
80
		};
81
		// TODO enable this once a proper icon has been found
82
		// ticket #5043
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
		return toolBarManager.createControl(this);
95
	}
96

    
97
	/** {@inheritDoc} */
98
	@Override
99
	public String getHeading() {
100
		return "Description Element";
101
	}
102

    
103
	/** {@inheritDoc} */
104
	@Override
105
	protected void setSectionTitle() {
106
		this.setText(getHeading() + ": " + getEntity().getFeature().getLabel(CdmStore.getDefaultLanguage()));
107

    
108
        if(IsMoreThanOneTypeSupported()){
109
            setTextClient(createToolbar());
110
        }
111
	}
112

    
113
	private boolean IsMoreThanOneTypeSupported(){
114
	    int count = 0;
115
	    Feature feature = getEntity().getFeature();
116
	    if(feature.isSupportsCategoricalData()){count++;}
117
	    if(feature.isSupportsCommonTaxonName()){count++;}
118
	    if(feature.isSupportsDistribution()){count++;}
119
	    if(feature.isSupportsIndividualAssociation()){count++;}
120
	    if(feature.isSupportsQuantitativeData()){count++;}
121
	    if(feature.isSupportsTaxonInteraction()){count++;}
122
	    if(feature.isSupportsTextData()){count++;}
123
	    return count > 1;
124
	}
125

    
126
	/* (non-Javadoc)
127
	 * @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection#createCdmDetailElement(eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection, int)
128
	 */
129
	@Override
130
	protected AbstractCdmDetailElement<DescriptionElementBase> createCdmDetailElement(AbstractCdmDetailSection<DescriptionElementBase> parentElement, int style) {
131
	    return formFactory.createDescriptionElementDetailElement(parentElement, style);
132
	}
133
}
(6-6/25)