performed javacscript:fix and worked on documentation
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / section / description / DescriptionElementDetailSection.java
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.section.description;
12
13 import org.apache.log4j.Logger;
14 import org.eclipse.jface.action.Action;
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.api.conversation.ConversationHolder;
21 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
22 import eu.etaxonomy.cdm.model.description.TextData;
23 import eu.etaxonomy.taxeditor.editor.EditorUtil;
24 import eu.etaxonomy.taxeditor.forms.CdmFormFactory;
25 import eu.etaxonomy.taxeditor.forms.CdmFormFactory.DetailType;
26 import eu.etaxonomy.taxeditor.forms.ICdmFormElement;
27 import eu.etaxonomy.taxeditor.operations.ChangeDescriptionElementType;
28 import eu.etaxonomy.taxeditor.section.AbstractCdmDetailSection;
29 import eu.etaxonomy.taxeditor.store.CdmStore;
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 private static final Logger logger = Logger
42 .getLogger(DescriptionElementDetailSection.class);
43
44 /**
45 * <p>Constructor for DescriptionElementDetailSection.</p>
46 *
47 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory} object.
48 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
49 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
50 * @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
51 * @param style a int.
52 */
53 public DescriptionElementDetailSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation,
54 ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
55 super(cdmFormFactory, conversation, parentElement, selectionProvider, style);
56 }
57
58
59 private Control createToolbar() {
60 if(! hasSpecificElement()){
61 return null;
62 }
63
64 ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
65
66 final String destinationString = (getEntity() instanceof TextData) ? "the specific element" : "free text";
67
68 final String label = "Change to " + destinationString;
69
70 Action addAction = new Action("Change Type", Action.AS_PUSH_BUTTON) {
71 /* (non-Javadoc)
72 * @see org.eclipse.jface.action.Action#run()
73 */
74 @Override
75 public void run() {
76 boolean confirmed = EditorUtil.confirmDialog("Confirmation", "Do you really want to change to "
77 + destinationString + "? Current data will be lost.");
78 if (confirmed) {
79 ChangeDescriptionElementType operation = new ChangeDescriptionElementType(label,
80 getEntity(), EditorUtil.getDetailsView(), EditorUtil.getActiveMultiPageTaxonEditor().getUndoContext());
81 EditorUtil.executeOperation(operation);
82 }
83 }
84 };
85 // TODO enable this once a proper icon has been found
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 ICdmFormElement parentElement = this.getParentElement();
98
99
100 return toolBarManager.createControl(this);
101 }
102
103 /** {@inheritDoc} */
104 @Override
105 public String getHeading() {
106 return "Description Element";
107 }
108
109 /** {@inheritDoc} */
110 @Override
111 protected DetailType getDetailType() {
112 return DetailType.DESCRIPTIONELEMENT;
113 }
114
115 /** {@inheritDoc} */
116 @Override
117 protected void setSectionTitle() {
118 this.setText(getHeading() + ": " + getEntity().getFeature().getLabel(CdmStore.getDefaultLanguage()));
119 setTextClient(createToolbar());
120 }
121
122 private boolean hasSpecificElement(){
123 return getEntity().getFeature().isSupportsCategoricalData()
124 || getEntity().getFeature().isSupportsCommonTaxonName()
125 || getEntity().getFeature().isSupportsDistribution()
126 || getEntity().getFeature().isSupportsIndividualAssociation()
127 || getEntity().getFeature().isSupportsQuantitativeData()
128 || getEntity().getFeature().isSupportsTaxonInteraction();
129 }
130 }