Project

General

Profile

Download (5.9 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.e4.ui.di.UISynchronize;
13
import org.eclipse.e4.ui.workbench.modeling.EPartService;
14
import org.eclipse.jface.action.Action;
15
import org.eclipse.jface.action.IAction;
16
import org.eclipse.jface.action.ToolBarManager;
17
import org.eclipse.jface.viewers.ISelectionProvider;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.widgets.Control;
20

    
21
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
22
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
23
import eu.etaxonomy.cdm.model.description.Feature;
24
import eu.etaxonomy.cdm.model.description.TextData;
25
import eu.etaxonomy.taxeditor.model.AbstractUtility;
26
import eu.etaxonomy.taxeditor.model.MessagingUtils;
27
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29
import eu.etaxonomy.taxeditor.store.StoreUtil;
30
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
31
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
32
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
33
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
34
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
35
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
36
import eu.etaxonomy.taxeditor.ui.section.description.operation.ChangeDescriptionElementType;
37
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
38

    
39
/**
40
 * <p>DescriptionElementDetailSection class.</p>
41
 *
42
 * @author n.hoffmann
43
 * @created Mar 5, 2010
44
 * @version 1.0
45
 */
46
public class DescriptionElementDetailSection extends
47
		AbstractCdmDetailSection<DescriptionElementBase> {
48

    
49

    
50

    
51
	/**
52
	 * <p>Constructor for DescriptionElementDetailSection.</p>
53
	 *
54
	 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
55
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
56
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
57
	 * @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
58
	 * @param style a int.
59
	 */
60
	public DescriptionElementDetailSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation,
61
			ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
62
		super(cdmFormFactory, conversation, parentElement, selectionProvider, style);
63
	}
64

    
65

    
66
	@Override
67
    protected Control createToolbar() {
68

    
69
		ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
70

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

    
73
		final String label = "Change to " + destinationString;
74

    
75
		Action addAction = new Action("Change Type", IAction.AS_PUSH_BUTTON) {
76
			/* (non-Javadoc)
77
			 * @see org.eclipse.jface.action.Action#run()
78
			 */
79
			@Override
80
			public void run() {
81
				boolean confirmed = MessagingUtils.confirmDialog("Confirmation", "Do you really want to change to "
82
						+ destinationString + "? Current data will be lost.");
83
				if (confirmed) {
84
					EPartService partService = formFactory.getContext().get(EPartService.class);
85
                    DetailsPartE4 detailsView = AbstractUtility.getDetailsView(partService);
86
                    ChangeDescriptionElementType operation = new ChangeDescriptionElementType(label,
87
							getEntity(), detailsView, StoreUtil.getUndoContext());
88
					AbstractUtility.executeOperation(operation, formFactory.getContext().get(UISynchronize.class));
89
				}
90
			}
91
		};
92
		// TODO enable this once a proper icon has been found
93
		// ticket #5043
94
//		addAction.setImageDescriptor(new ImageDescriptor() {
95
//
96
//			@Override
97
//			public ImageData getImageData() {
98
//				return ImageResources.getImage(ImageResources.ADD_ICON).getImageData();
99
//			}
100
//		});
101
		addAction.setToolTipText(label);
102

    
103
		toolBarManager.add(addAction);
104

    
105
		return toolBarManager.createControl(this);
106
	}
107

    
108
	/** {@inheritDoc} */
109
	@Override
110
	public String getHeading() {
111
		return "Description Element";
112
	}
113

    
114
	/** {@inheritDoc} */
115
	@Override
116
	protected void setSectionTitle() {
117
		this.setText(getHeading() + ": " + getEntity().getFeature().getPreferredRepresentation(CdmStore.getDefaultLanguage()));
118
		        //getLabel(CdmStore.getDefaultLanguage()));
119

    
120
        if(IsMoreThanOneTypeSupported()){
121
            setTextClient(createToolbar());
122
        }
123
	}
124

    
125
	private boolean IsMoreThanOneTypeSupported(){
126
	    int count = 0;
127
	    Feature feature = getEntity().getFeature();
128
	    if(feature.isSupportsCategoricalData()){count++;}
129
	    if(feature.isSupportsCommonTaxonName()){count++;}
130
	    if(feature.isSupportsDistribution()){count++;}
131
	    if(feature.isSupportsIndividualAssociation()){count++;}
132
	    if(feature.isSupportsQuantitativeData()){count++;}
133
	    if(feature.isSupportsTaxonInteraction()){count++;}
134
	    if(feature.isSupportsTextData()){count++;}
135
	    if(feature.isSupportsTemporalData()){count++;}
136
	    return count > 1;
137
	}
138

    
139
	/* (non-Javadoc)
140
	 * @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection#createCdmDetailElement(eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection, int)
141
	 */
142
	@Override
143
	protected AbstractCdmDetailElement<DescriptionElementBase> createCdmDetailElement(AbstractCdmDetailSection<DescriptionElementBase> parentElement, int style) {
144
	    return formFactory.createDescriptionElementDetailElement(parentElement, style);
145
	}
146
	@Override
147
    public void setEntity(DescriptionElementBase entity) {
148
        super.setEntity(entity);
149
        boolean isEnabled = true;
150
        if ((entity.getInDescription().isComputed() || entity.getInDescription().isCloneForSource())&& PreferencesUtil.isComputedDesciptionHandlingDisabled() ){
151
            isEnabled = false;
152
        }
153
        setEnabled(isEnabled);
154

    
155
    }
156

    
157

    
158
}
(7-7/26)