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.section.AbstractCdmDetailElement;
|
33
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
|
34
|
import eu.etaxonomy.taxeditor.ui.section.description.operation.ChangeDescriptionElementType;
|
35
|
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
|
36
|
|
37
|
/**
|
38
|
* <p>DescriptionElementDetailSection class.</p>
|
39
|
*
|
40
|
* @author n.hoffmann
|
41
|
* @created Mar 5, 2010
|
42
|
* @version 1.0
|
43
|
*/
|
44
|
public class DescriptionElementDetailSection extends
|
45
|
AbstractCdmDetailSection<DescriptionElementBase> {
|
46
|
|
47
|
|
48
|
|
49
|
/**
|
50
|
* <p>Constructor for DescriptionElementDetailSection.</p>
|
51
|
*
|
52
|
* @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
53
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
54
|
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
55
|
* @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
|
56
|
* @param style a int.
|
57
|
*/
|
58
|
public DescriptionElementDetailSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation,
|
59
|
ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
|
60
|
super(cdmFormFactory, conversation, parentElement, selectionProvider, style);
|
61
|
}
|
62
|
|
63
|
|
64
|
@Override
|
65
|
protected Control createToolbar() {
|
66
|
|
67
|
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
|
68
|
|
69
|
final String destinationString = (getEntity().isInstanceOf(TextData.class)) ? "the specific element" : "free text";
|
70
|
|
71
|
final String label = "Change to " + destinationString;
|
72
|
|
73
|
Action addAction = new Action("Change Type", IAction.AS_PUSH_BUTTON) {
|
74
|
/* (non-Javadoc)
|
75
|
* @see org.eclipse.jface.action.Action#run()
|
76
|
*/
|
77
|
@Override
|
78
|
public void run() {
|
79
|
boolean confirmed = MessagingUtils.confirmDialog("Confirmation", "Do you really want to change to "
|
80
|
+ destinationString + "? Current data will be lost.");
|
81
|
if (confirmed) {
|
82
|
EPartService partService = formFactory.getContext().get(EPartService.class);
|
83
|
DetailsPartE4 detailsView = AbstractUtility.getDetailsView(partService);
|
84
|
ChangeDescriptionElementType operation = new ChangeDescriptionElementType(label,
|
85
|
getEntity(), detailsView, StoreUtil.getUndoContext());
|
86
|
AbstractUtility.executeOperation(operation, formFactory.getContext().get(UISynchronize.class));
|
87
|
}
|
88
|
}
|
89
|
};
|
90
|
// TODO enable this once a proper icon has been found
|
91
|
// ticket #5043
|
92
|
// addAction.setImageDescriptor(new ImageDescriptor() {
|
93
|
//
|
94
|
// @Override
|
95
|
// public ImageData getImageData() {
|
96
|
// return ImageResources.getImage(ImageResources.ADD_ICON).getImageData();
|
97
|
// }
|
98
|
// });
|
99
|
addAction.setToolTipText(label);
|
100
|
|
101
|
toolBarManager.add(addAction);
|
102
|
|
103
|
return toolBarManager.createControl(this);
|
104
|
}
|
105
|
|
106
|
/** {@inheritDoc} */
|
107
|
@Override
|
108
|
public String getHeading() {
|
109
|
return "Description Element";
|
110
|
}
|
111
|
|
112
|
/** {@inheritDoc} */
|
113
|
@Override
|
114
|
protected void setSectionTitle() {
|
115
|
this.setText(getHeading() + ": " + getEntity().getFeature().getPreferredRepresentation(CdmStore.getDefaultLanguage()));
|
116
|
//getLabel(CdmStore.getDefaultLanguage()));
|
117
|
|
118
|
if(IsMoreThanOneTypeSupported()){
|
119
|
setTextClient(createToolbar());
|
120
|
}
|
121
|
}
|
122
|
|
123
|
private boolean IsMoreThanOneTypeSupported(){
|
124
|
int count = 0;
|
125
|
Feature feature = getEntity().getFeature();
|
126
|
if(feature.isSupportsCategoricalData()){count++;}
|
127
|
if(feature.isSupportsCommonTaxonName()){count++;}
|
128
|
if(feature.isSupportsDistribution()){count++;}
|
129
|
if(feature.isSupportsIndividualAssociation()){count++;}
|
130
|
if(feature.isSupportsQuantitativeData()){count++;}
|
131
|
if(feature.isSupportsTaxonInteraction()){count++;}
|
132
|
if(feature.isSupportsTextData()){count++;}
|
133
|
if(feature.isSupportsTemporalData()){count++;}
|
134
|
return count > 1;
|
135
|
}
|
136
|
|
137
|
/* (non-Javadoc)
|
138
|
* @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection#createCdmDetailElement(eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection, int)
|
139
|
*/
|
140
|
@Override
|
141
|
protected AbstractCdmDetailElement<DescriptionElementBase> createCdmDetailElement(AbstractCdmDetailSection<DescriptionElementBase> parentElement, int style) {
|
142
|
return formFactory.createDescriptionElementDetailElement(parentElement, style);
|
143
|
}
|
144
|
@Override
|
145
|
public void setEntity(DescriptionElementBase entity) {
|
146
|
super.setEntity(entity);
|
147
|
boolean isEnabled = true;
|
148
|
if (entity.getInDescription().isComputed() && PreferencesUtil.isComputedDesciptionHandlingDisabled()){
|
149
|
isEnabled = false;
|
150
|
}
|
151
|
setEnabled(isEnabled);
|
152
|
this.getDetailElement().setEnabled(isEnabled);
|
153
|
|
154
|
}
|
155
|
|
156
|
|
157
|
}
|