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
.runtime
.Assert
;
14 import org
.eclipse
.jface
.action
.Action
;
15 import org
.eclipse
.jface
.action
.MenuManager
;
16 import org
.eclipse
.jface
.text
.Document
;
17 import org
.eclipse
.jface
.text
.source
.SourceViewer
;
18 import org
.eclipse
.swt
.SWT
;
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
.forms
.widgets
.TableWrapData
;
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
.UiUtil
;
30 import eu
.etaxonomy
.taxeditor
.actions
.ui
.description
.AddDescriptionElementCompositeAction
;
31 import eu
.etaxonomy
.taxeditor
.editor
.ContextMenu
;
32 import eu
.etaxonomy
.taxeditor
.editor
.EditorGroupedComposite
;
33 import eu
.etaxonomy
.taxeditor
.editor
.ParseListener
;
36 * Composite for editing a description's label / Title Cache information
42 public class DescriptionLabelComposite
extends EditorGroupedComposite
{
43 private static final Logger logger
= Logger
44 .getLogger(DescriptionLabelComposite
.class);
47 * ************ FONTS ************
49 public static final Font DESCRIPTION_LABEL_FONT
= TaxEditorPlugin
.getDefault()
50 .getFont(ITaxEditorConstants
.ACCEPTED_TAXON_FONT
);
53 * ************ ICONS ************
55 public static final Image DESCRIPTION_LABEL_ICON
= TaxEditorPlugin
.getDefault()
56 .getImage(ITaxEditorConstants
.BLACK_SQUARE_ICON
);
58 private static final String EMPTY_NAME_PROMPT
= "Click to add description label";
60 public DescriptionLabelComposite(Composite parent
, IManagedForm managedForm
, TaxonDescription taxonDescription
) {
61 super(parent
, managedForm
);
64 createBorderSupport();
65 createLineWrapSupport();
67 setData(taxonDescription
);
70 createEmptyViewerPrompt(EMPTY_NAME_PROMPT
);
75 public void transform(String transformation
) {
77 setFont(DESCRIPTION_LABEL_FONT
);
78 setIcon(DESCRIPTION_LABEL_ICON
);
83 public void setData(Object data
) {
86 Assert
.isTrue((data
instanceof TaxonDescription
),
87 "DescriptionLabelComposite's data field must contain a TaxonDescription object");
89 String label
= ((TaxonDescription
) data
).getTitleCache();
90 getTextViewer().getTextWidget().setText(label
);
93 private void createMenu() {
94 ContextMenu contextMenu
= createContextMenu();
96 MenuManager menuManager
= new MenuManager("Add description element");
98 Composite parentComposite
= this.getParent();
100 for (Feature feature
: UiUtil
.getPreferredFeatures()) {
101 Action action
= new AddDescriptionElementCompositeAction(parentComposite
, managedForm
, feature
);
102 menuManager
.add(action
);
104 contextMenu
.addSubmenu(menuManager
);
107 private void createLabelViewer() {
108 this.textViewer
= new SourceViewer(this, null, SWT
.WRAP
| SWT
.MULTI
| SWT
.RESIZE
);
109 this.textViewer
.setDocument(new Document(""));
110 this.textViewer
.getTextWidget().setLayoutData(new TableWrapData(TableWrapData
.FILL_GRAB
));
111 this.textViewer
.getTextWidget().addModifyListener(new ParseListener() {
114 public void parse(String text
) {
115 Assert
.isTrue((getData() instanceof TaxonDescription
),
116 "DescriptionLabelComposite's data field must contain a TaxonDescription object");
118 ((TaxonDescription
) getData()).setTitleCache(text
);