2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.description
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
14 import org
.eclipse
.core
.commands
.operations
.IUndoableOperation
;
15 import org
.eclipse
.jface
.action
.Action
;
16 import org
.eclipse
.jface
.action
.IMenuListener
;
17 import org
.eclipse
.jface
.action
.IMenuManager
;
18 import org
.eclipse
.jface
.action
.MenuManager
;
19 import org
.eclipse
.swt
.graphics
.Font
;
20 import org
.eclipse
.swt
.graphics
.Image
;
21 import org
.eclipse
.swt
.widgets
.Composite
;
22 import org
.eclipse
.ui
.forms
.IManagedForm
;
23 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
25 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
26 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
27 import eu
.etaxonomy
.taxeditor
.ITaxEditorConstants
;
28 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
29 import eu
.etaxonomy
.taxeditor
.controller
.EditorController
;
30 import eu
.etaxonomy
.taxeditor
.controller
.GlobalController
;
31 import eu
.etaxonomy
.taxeditor
.editor
.ContextMenu
;
32 import eu
.etaxonomy
.taxeditor
.editor
.GroupedComposite
;
33 import eu
.etaxonomy
.taxeditor
.operations
.description
.AddElementOperation
;
34 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
35 import eu
.etaxonomy
.taxeditor
.propertysheet
.description
.TaxonDescriptionPropertySource
;
38 * Composite for editing a description's label / Title Cache information.
44 public class DescriptionLabelComposite
extends GroupedComposite
{
45 private static final Logger logger
= Logger
46 .getLogger(DescriptionLabelComposite
.class);
49 * ************ FONTS ************
51 public static final Font DESCRIPTION_LABEL_FONT
= TaxEditorPlugin
.getDefault()
52 .getFont(ITaxEditorConstants
.ACCEPTED_TAXON_FONT
);
55 * ************ ICONS ************
57 public static final Image DESCRIPTION_LABEL_ICON
= TaxEditorPlugin
.getDefault()
58 .getImage(ITaxEditorConstants
.BLACK_SQUARE_ICON
);
60 private static final String EMPTY_NAME_PROMPT
= "Click to add description label";
62 private TaxonDescription description
;
64 private IUndoContext undoContext
;
66 public DescriptionLabelComposite(Composite parent
, IManagedForm managedForm
, TaxonDescription description
) {
67 super(parent
, managedForm
);
69 this.description
= description
;
71 this.undoContext
= EditorController
.getUndoContext(taxon
);
74 createBorderSupport();
75 createLineWrapSupport();
78 createEmptyViewerPrompt(EMPTY_NAME_PROMPT
);
80 setIsDraggable(false);
81 setFont(DESCRIPTION_LABEL_FONT
);
82 setIcon(DESCRIPTION_LABEL_ICON
);
89 private void initTextViewer() {
90 if (textViewer
!= null) {
91 String text
= getDescription().getTitleCache();
92 textViewer
.getTextWidget().setText(text
);
94 logger
.warn("TextViewer is null.");
98 public TaxonDescription
getDescription() {
102 private void createMenu() {
104 MenuManager featuresMenu
= new MenuManager("Add description element");
105 featuresMenu
.setRemoveAllWhenShown(true);
106 featuresMenu
.addMenuListener(new IMenuListener() {
107 public void menuAboutToShow(IMenuManager manager
) {
108 for (final Feature feature
: PreferencesUtil
.getPreferredFeatures()) {
110 String text
= feature
.getLabel();
111 manager
.add(new Action(text
){
114 IUndoableOperation operation
= new AddElementOperation
115 (this.getText(), undoContext
, taxon
, description
, feature
);
116 GlobalController
.executeOperation(operation
);
123 // Important: add an empty action. Otherwise, when the main menu sees that
124 // there are no actions in the submenu, it will not be shown
125 featuresMenu
.add(new Action() {});
127 ContextMenu contextMenu
= createContextMenu();
128 contextMenu
.addSubmenu(featuresMenu
);
131 protected void parse(String text
) {
132 getDescription().setTitleCache(text
);
137 public IPropertySource
getPropertySource() {
138 return new TaxonDescriptionPropertySource(getDescription());
142 protected Font
getViewerFont() {
146 public Object
getData () {
147 return getDescription();