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
|
package eu.etaxonomy.taxeditor.ui.section.description;
|
10
|
|
11
|
import org.eclipse.e4.ui.di.UISynchronize;
|
12
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
13
|
import org.eclipse.jface.action.Action;
|
14
|
import org.eclipse.jface.action.IAction;
|
15
|
import org.eclipse.jface.action.ToolBarManager;
|
16
|
import org.eclipse.jface.viewers.ISelectionProvider;
|
17
|
import org.eclipse.swt.SWT;
|
18
|
import org.eclipse.swt.widgets.Control;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
21
|
import eu.etaxonomy.cdm.model.description.Feature;
|
22
|
import eu.etaxonomy.cdm.model.description.TextData;
|
23
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
24
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
25
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
28
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
29
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
30
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
31
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
|
32
|
import eu.etaxonomy.taxeditor.ui.section.description.operation.ChangeDescriptionElementType;
|
33
|
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
|
34
|
|
35
|
/**
|
36
|
* <p>DescriptionElementDetailSection class.</p>
|
37
|
*
|
38
|
* @author n.hoffmann
|
39
|
* @created Mar 5, 2010
|
40
|
*/
|
41
|
public class DescriptionElementDetailSection extends
|
42
|
AbstractCdmDetailSection<DescriptionElementBase> {
|
43
|
|
44
|
|
45
|
public DescriptionElementDetailSection(CdmFormFactory cdmFormFactory,
|
46
|
ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
|
47
|
super(cdmFormFactory, parentElement, selectionProvider, style);
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
protected Control createToolbar() {
|
52
|
|
53
|
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
|
54
|
|
55
|
final String destinationString = (getEntity().isInstanceOf(TextData.class)) ? "the specific element" : "free text";
|
56
|
|
57
|
final String label = "Change to " + destinationString;
|
58
|
|
59
|
Action addAction = new Action("Change Type", IAction.AS_PUSH_BUTTON) {
|
60
|
|
61
|
@Override
|
62
|
public void run() {
|
63
|
boolean confirmed = MessagingUtils.confirmDialog("Confirmation", "Do you really want to change to "
|
64
|
+ destinationString + "? Current data will be lost.");
|
65
|
if (confirmed) {
|
66
|
EPartService partService = formFactory.getContext().get(EPartService.class);
|
67
|
DetailsPartE4 detailsView = AbstractUtility.getDetailsView(partService);
|
68
|
ChangeDescriptionElementType operation = new ChangeDescriptionElementType(label,
|
69
|
getEntity(), detailsView, StoreUtil.getUndoContext());
|
70
|
AbstractUtility.executeOperation(operation, formFactory.getContext().get(UISynchronize.class));
|
71
|
}
|
72
|
}
|
73
|
};
|
74
|
// TODO enable this once a proper icon has been found
|
75
|
// ticket #5043
|
76
|
// addAction.setImageDescriptor(new ImageDescriptor() {
|
77
|
//
|
78
|
// @Override
|
79
|
// public ImageData getImageData() {
|
80
|
// return ImageResources.getImage(ImageResources.ADD_ICON).getImageData();
|
81
|
// }
|
82
|
// });
|
83
|
addAction.setToolTipText(label);
|
84
|
|
85
|
toolBarManager.add(addAction);
|
86
|
|
87
|
return toolBarManager.createControl(this);
|
88
|
}
|
89
|
|
90
|
@Override
|
91
|
public String getHeading() {
|
92
|
return "Description Element";
|
93
|
}
|
94
|
|
95
|
@Override
|
96
|
protected void setSectionTitle() {
|
97
|
this.setText(getHeading() + ": " + getEntity().getFeature().getPreferredRepresentation(CdmStore.getDefaultLanguage()));
|
98
|
//getLabel(CdmStore.getDefaultLanguage()));
|
99
|
|
100
|
if(IsMoreThanOneTypeSupported()){
|
101
|
setTextClient(createToolbar());
|
102
|
}
|
103
|
}
|
104
|
|
105
|
private boolean IsMoreThanOneTypeSupported(){
|
106
|
int count = 0;
|
107
|
Feature feature = getEntity().getFeature();
|
108
|
if(feature.isSupportsCategoricalData()){count++;}
|
109
|
if(feature.isSupportsCommonTaxonName()){count++;}
|
110
|
if(feature.isSupportsDistribution()){count++;}
|
111
|
if(feature.isSupportsIndividualAssociation()){count++;}
|
112
|
if(feature.isSupportsQuantitativeData()){count++;}
|
113
|
if(feature.isSupportsTaxonInteraction()){count++;}
|
114
|
if(feature.isSupportsTextData()){count++;}
|
115
|
if(feature.isSupportsTemporalData()){count++;}
|
116
|
return count > 1;
|
117
|
}
|
118
|
|
119
|
@Override
|
120
|
protected AbstractCdmDetailElement<DescriptionElementBase> createCdmDetailElement(AbstractCdmDetailSection<DescriptionElementBase> parentElement, int style) {
|
121
|
return formFactory.createDescriptionElementDetailElement(parentElement, style);
|
122
|
}
|
123
|
@Override
|
124
|
public void setEntity(DescriptionElementBase entity) {
|
125
|
super.setEntity(entity);
|
126
|
boolean isEnabled = true;
|
127
|
if ((entity.getInDescription().isComputed() || entity.getInDescription().isCloneForSource())&& PreferencesUtil.isComputedDesciptionHandlingDisabled() ){
|
128
|
isEnabled = false;
|
129
|
}
|
130
|
setEnabled(isEnabled);
|
131
|
}
|
132
|
}
|