.
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / editor / images / GalleryLabelComposite.java
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.editor.images;
11
12 import org.apache.log4j.Logger;
13 import org.eclipse.swt.graphics.Font;
14 import org.eclipse.swt.graphics.Image;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.ui.views.properties.IPropertySource;
17
18 import eu.etaxonomy.cdm.model.description.TaxonDescription;
19 import eu.etaxonomy.taxeditor.editor.AbstractTaxonEditor;
20 import eu.etaxonomy.taxeditor.editor.GroupedComposite;
21 import eu.etaxonomy.taxeditor.model.ImageResources;
22 import eu.etaxonomy.taxeditor.model.Resources;
23 import eu.etaxonomy.taxeditor.propertysheet.description.TaxonDescriptionPropertySource;
24
25 /**
26 * Composite for editing a description's label / Title Cache information.
27 *
28 * @author p.ciardelli
29 * @author n.hoffmann
30 * @created 09.09.2008
31 * @version 1.0
32 */
33 public class GalleryLabelComposite extends GroupedComposite {
34 private static final Logger logger = Logger
35 .getLogger(GalleryLabelComposite.class);
36
37 /**
38 * ************ FONTS ************
39 */
40 public static final Font DESCRIPTION_LABEL_FONT = Resources
41 .getFont(Resources.ACCEPTED_TAXON_FONT);
42
43 /**
44 * ************ ICONS ************
45 */
46 public static final Image DESCRIPTION_LABEL_ICON = ImageResources
47 .getImage(ImageResources.BLACK_SQUARE_ICON);
48
49 private static final String EMPTY_NAME_PROMPT = "Click to add label for image gallery";
50
51 private TaxonDescription description;
52
53 public GalleryLabelComposite(AbstractTaxonEditor editor, Composite parent, TaxonDescription description) {
54 super(editor, parent);
55
56 this.description = description;
57
58
59 createTextViewer();
60 createBorderSupport();
61 createLineWrapSupport();
62
63 createParser();
64 createEmptyViewerPrompt(EMPTY_NAME_PROMPT);
65
66 setIsDraggable(false);
67 setFont(DESCRIPTION_LABEL_FONT);
68 setIcon(DESCRIPTION_LABEL_ICON);
69
70 this.setMenu(editor.getMenu());
71
72 initTextViewer();
73 }
74
75 private void initTextViewer() {
76 if (textViewer != null) {
77 String text = getDescription().getTitleCache();
78
79 if (text.length() == 0) {
80 initEmptyText();
81 } else {
82 textViewer.getTextWidget().setText(text);
83 }
84 } else {
85 logger.warn("TextViewer is null.");
86 }
87 }
88
89 public TaxonDescription getDescription() {
90 return description;
91 }
92
93 // /**
94 // * FIXME migrate menu to plugin.xml configuration
95 // */
96 // private void createMenu() {
97 //
98 // MenuManager featuresMenu = new MenuManager("Add description element");
99 // featuresMenu.setRemoveAllWhenShown(true);
100 // featuresMenu.addMenuListener(new IMenuListener() {
101 // public void menuAboutToShow(IMenuManager manager) {
102 // for (final Feature feature : PreferencesUtil.getPreferredFeatures()) {
103 //
104 // String text = feature.getLabel();
105 // manager.add(new Action(text){
106 //
107 // public void run() {
108 // IUndoableOperation operation = new CreateDescriptionElementOperation
109 // (this.getText(), editor.getUndoContext(), taxon, description, feature, editor);
110 // EditorUtil.executeOperation(operation);
111 // }
112 // });
113 // }
114 // }
115 // });
116 //
117 // // Important: add an empty action. Otherwise, when the main menu sees that
118 // // there are no actions in the submenu, it will not be shown
119 // // HACK?
120 // featuresMenu.add(new Action() {});
121 //
122 // ContextMenu contextMenu = createContextMenu();
123 // contextMenu.addSubmenu(featuresMenu);
124 // }
125
126 protected void parse(String text) {
127 getDescription().setTitleCache(text);
128
129 // Manually refresh the property sheet to reflect changes
130 setSelection();
131
132 setDirty(true);
133 }
134
135 public IPropertySource getPropertySource() {
136 return new TaxonDescriptionPropertySource(getDescription());
137 }
138
139 @Override
140 protected Font getViewerFont() {
141 return DESCRIPTION_LABEL_FONT;
142 }
143
144 public Object getData () {
145 return getDescription();
146 }
147 }