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