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
.name
.container
;
12 import java
.util
.Iterator
;
13 import java
.util
.List
;
16 import org
.eclipse
.core
.runtime
.Assert
;
17 import org
.eclipse
.jface
.dialogs
.Dialog
;
18 import org
.eclipse
.jface
.text
.IDocument
;
19 import org
.eclipse
.jface
.text
.Position
;
20 import org
.eclipse
.jface
.window
.DefaultToolTip
;
21 import org
.eclipse
.swt
.custom
.StyledText
;
22 import org
.eclipse
.swt
.dnd
.DND
;
23 import org
.eclipse
.swt
.dnd
.DragSource
;
24 import org
.eclipse
.swt
.dnd
.Transfer
;
25 import org
.eclipse
.swt
.events
.ControlAdapter
;
26 import org
.eclipse
.swt
.events
.ControlEvent
;
27 import org
.eclipse
.swt
.events
.ControlListener
;
28 import org
.eclipse
.swt
.events
.FocusAdapter
;
29 import org
.eclipse
.swt
.events
.FocusEvent
;
30 import org
.eclipse
.swt
.events
.FocusListener
;
31 import org
.eclipse
.swt
.events
.ModifyEvent
;
32 import org
.eclipse
.swt
.events
.ModifyListener
;
33 import org
.eclipse
.swt
.events
.MouseAdapter
;
34 import org
.eclipse
.swt
.events
.MouseEvent
;
35 import org
.eclipse
.swt
.graphics
.Color
;
36 import org
.eclipse
.swt
.graphics
.Font
;
37 import org
.eclipse
.swt
.graphics
.Image
;
38 import org
.eclipse
.swt
.widgets
.Composite
;
39 import org
.eclipse
.swt
.widgets
.Control
;
40 import org
.eclipse
.swt
.widgets
.Display
;
41 import org
.eclipse
.swt
.widgets
.Label
;
42 import org
.eclipse
.swt
.widgets
.Menu
;
43 import org
.eclipse
.ui
.forms
.IFormPart
;
44 import org
.eclipse
.ui
.forms
.IManagedForm
;
45 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
46 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
48 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
49 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
50 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
51 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
52 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
53 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
54 import eu
.etaxonomy
.cdm
.strategy
.parser
.ParserProblem
;
55 import eu
.etaxonomy
.taxeditor
.editor
.CdmDataTransfer
;
56 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
57 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
58 import eu
.etaxonomy
.taxeditor
.editor
.name
.container
.EditorAnnotation
.EditorAnnotationType
;
59 import eu
.etaxonomy
.taxeditor
.editor
.name
.dnd
.NameEditorDragListener
;
60 import eu
.etaxonomy
.taxeditor
.editor
.name
.dnd
.NameEditorDragSourceEffect
;
61 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.CreateSynonymInNewGroupOperation
;
62 import eu
.etaxonomy
.taxeditor
.labels
.ILabelImageStrategy
;
63 import eu
.etaxonomy
.taxeditor
.labels
.LabelImageProvider
;
64 import eu
.etaxonomy
.taxeditor
.model
.IElementHasDetails
;
65 import eu
.etaxonomy
.taxeditor
.model
.NameHelper
;
66 import eu
.etaxonomy
.taxeditor
.model
.TextHelper
;
67 import eu
.etaxonomy
.taxeditor
.parser
.ParseHandler
;
68 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
71 * Formats <code>GroupedComposite</code> with cosmetic and layout properties
72 * specific to the Editor. This should be used to maintain a consistent look and
73 * feel for all Editor freetext area components, such as
74 * DescriptionElementComposite.
76 * Requires an <code>IManagedForm</code>, whose <code>input</code> is set to the
77 * contents of {@link #getData()} when the <code>GroupedComposite</code> gets
78 * focus, i.e. to populate the property sheet with the data.
81 * The <code>IManagedForm</code> is also required to have a <code>Taxon</code>
82 * in its own <code>getData()</code>.
85 * The <code>IManagedForm</code> can also used for drawing borders by calling
86 * the method <code>createBorderSupport()</code>.
94 abstract public class AbstractGroupedContainer
<T
extends TaxonBase
> implements
95 IFormPart
, IContainerConstants
, IElementHasDetails
{
97 protected ParseHandler parseHandler
;
99 private FocusListener nameCompositeFocusListener
;
100 private ModifyListener nameCompositeModifyListener
;
102 protected NameViewer nameViewer
;
104 private AbstractGroup group
;
106 private Label nonEditableInfoLabel
;
107 private DefaultToolTip nonEditableInfoHover
;
109 private static AbstractGroupedContainer selection
;
111 private FocusListener focusListener
;
112 private LineBreakListener lineBreakListener
;
114 private int cursorPosition
;
116 protected Composite control
;
118 private Color backgroundColor
;
119 private boolean isDirty
;
123 * Constructor for AbstractGroupedContainer.
127 * a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor}
131 * {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup}
138 public AbstractGroupedContainer(T taxonBase
) {
140 parseHandler
= ParseHandler
.NewInstance(taxonBase
.getName());
143 public void createContent() {
147 createLineWrapSupport();
148 createLineBreakListener();
150 setMenu(getEditor().getMenu());
152 setDraggableControl(new Control
[] { getControl(),
153 getNameViewer().getRulerControl() });
155 createEmptyViewerPrompt(EMPTY_NAME_PROMPT
);
157 initializeComposite();
169 protected void createListener() {
170 nameCompositeModifyListener
= new ModifyListener() {
172 public void modifyText(ModifyEvent e
) {
173 // mark the composite dirty
176 String text
= nameViewer
.getTextWidget().getText();
178 NonViralName name
= parseHandler
.parse(text
);
179 getTaxonBase().setName(name
);
180 getTaxonBase().setTitleCache((getTaxonBase().generateTitle()));
182 // show errors resulting from parsing
183 calculateAnnotations();
184 // store the position of the cursor
186 // notify selection listener
187 setDelayedSelection();
190 nameCompositeFocusListener
= new FocusAdapter() {
196 * org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt
197 * .events.FocusEvent)
200 public void focusLost(FocusEvent e
) {
210 private void addListener() {
211 getNameViewer().getTextWidget().addModifyListener(
212 nameCompositeModifyListener
);
213 getNameViewer().getTextWidget().addFocusListener(
214 nameCompositeFocusListener
);
217 private void removeListener() {
218 getNameViewer().getTextWidget().removeModifyListener(
219 nameCompositeModifyListener
);
220 getNameViewer().getTextWidget().removeFocusListener(
221 nameCompositeFocusListener
);
225 * Initialize the composite specific code
227 protected abstract void initializeComposite();
234 * @return a {@link java.lang.String} object.
236 protected String
getEmptyTextPrompt() {
237 return EMPTY_NAME_PROMPT
;
243 private void showNameRelations() {
244 TaxonNameBase
<?
, ?
> name
= getName();
249 ILabelImageStrategy strategy
= LabelImageProvider
250 .getLabelStrategy(name
);
251 LabelImageProvider labelProvider
= new LabelImageProvider(strategy
);
253 Set
<NameRelationship
> nameRelations
= name
.getNameRelations();
254 if (nameRelations
.size() == 0) {
257 // for (NameRelationship nameRelation : nameRelations) {
258 // String typeLabel = null;
259 // TaxonNameBase<?, ?> relatedName = null;
261 // if (name.equals(nameRelation.getFromName())) {
262 // typeLabel = labelProvider.getNameRelationTypeLabel(
263 // nameRelation.getType());
264 // relatedName = nameRelation.getToName();
266 // typeLabel = labelProvider.getNameRelationTypeInverseLabel(
267 // nameRelation.getType());
268 // relatedName = nameRelation.getFromName();
271 // setNonEditableInfo(typeLabel + " " +
272 // NameHelper.getDisplayName(relatedName));
281 protected void initTextViewer() {
283 // showNameRelations();
289 String text
= NameHelper
.getDisplayNameWithRef(getData());
291 if (text
.length() == 0) {
294 getNameViewer().setText(text
);
297 calculateAnnotations();
305 synchronized protected void calculateAnnotations() {
306 getNameViewer().clearAnnotations();
313 public void showAnnotations() {
315 if (getName().hasProblem()) {
316 showParsingProblems();
319 if (!isNameParsable()) {
322 new EditorAnnotation(EditorAnnotationType
.WARNING
,
324 "This name may only be edited in the details view."));
327 if (isNameUsedMultipleTimes()) {
328 getNameViewer().addAnnotation(
329 new EditorAnnotation(EditorAnnotationType
.WARNING
, 0,
330 "This taxons name is used multiple times."));
338 private void showParsingProblems() {
339 String text
= getNameViewer().getTextWidget().getText();
341 List
<ParserProblem
> parsingProblems
= getName().getParsingProblems();
343 for (ParserProblem problem
: parsingProblems
) {
344 getNameViewer().addAnnotation(new EditorAnnotation(problem
),
345 getParsingProblemPosition());
349 private Position
getParsingProblemPosition() {
350 String text
= getNameViewer().getTextWidget().getText();
352 if (getName().hasProblem() && text
.length() > 0) {
353 int start
= getName().getProblemStarts();
354 int length
= getName().getProblemEnds() - start
;
356 if (start
== -1 || getName().getProblemEnds() == -1) {
360 // Don't let squigglies try to draw beyond the end of the text
361 if (text
.length() < start
+ length
) {
362 length
= text
.length() - start
;
367 return new Position(start
, length
);
378 * a {@link java.lang.String} object.
380 protected void handleSplitText(String text
) {
381 // Create a synonym in a new homotypic group using text as name
382 TaxonNameBase synonymName
= ParseHandler
383 .parseReferencedName(text
, null);
385 EditorUtil
.executeOperation(new CreateSynonymInNewGroupOperation(
386 "New Heterotypic Synonym", getEditor().getUndoContext(),
387 getEditor().getTaxon(), synonymName
, getEditor()));
391 * Refreshes the display with latest data from the model.
393 * Note: Will not parse the text and not calculate errors!
395 public void refresh() {
396 // showNameRelations();
398 String text
= NameHelper
.getDisplayNameWithRef(getTaxonBase());
400 if (getNameViewer().getTextWidget() == null) {
401 // we might get here via dnd. Look slike it can be ignored
405 if (text
.length() == 0) {
407 } else if (!getNameViewer().getTextWidget().getText().equals(text
)) {
409 getNameViewer().getTextWidget().setText(text
);
413 updateNonEditableInfo();
425 protected abstract void updateIcon();
427 protected abstract void updateIndent();
431 * updateNonEditableInfo
434 protected abstract void updateNonEditableInfo();
439 private void enableFreeText() {
440 setEnabled(isFreetextEditingAllowed());
444 * Checks whether the freetext should be editable based on specific empty
449 private boolean isFreetextEditingAllowed() {
450 NonViralName name
= (NonViralName
) HibernateProxyHelper
452 boolean enableFreetext
= true;
454 enableFreetext
|= isNameUsedMultipleTimes();
455 enableFreetext
&= isNameParsable();
457 return enableFreetext
;
461 * Checks whether there are more than one, non-orphaned taxon bases
462 * attached to the taxon name
466 private boolean isNameUsedMultipleTimes() {
468 Set
<TaxonBase
> taxonBases
= getName().getTaxonBases();
469 Iterator
<TaxonBase
> tbItr
= taxonBases
.iterator();
470 int nonOrphanedTaxonBaseCount
= taxonBases
.size();
472 while(tbItr
.hasNext()) {
473 TaxonBase tb
= tbItr
.next();
474 if(tb
.isOrphaned()) {
475 nonOrphanedTaxonBaseCount
--;
478 if(nonOrphanedTaxonBaseCount
> 1) {
484 private boolean isNameParsable() {
485 TaxonNameBase name
= getName();
487 boolean isParsable
= true;
488 isParsable
&= CdmUtils
.isEmpty(name
.getAppendedPhrase()); // taxonFieldsEmpty();
490 if (name
instanceof NonViralName
) {
491 NonViralName nonViralName
= (NonViralName
) name
;
492 isParsable
&= !nonViralName
.isProtectedAuthorshipCache();
493 isParsable
&= !nonViralName
.isProtectedNameCache();
500 * Parse the text and calculate errors
502 public void parseAndCalculateAnnotations() {
504 String unparsedNameString
= getNameViewer().getTextWidget().getText();
505 parseHandler
.parse(unparsedNameString
);
507 calculateAnnotations();
515 * @return the taxonBase
517 public T
getTaxonBase() {
526 * @return a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object.
528 public TaxonNameBase
getName() {
529 return (TaxonNameBase
) HibernateProxyHelper
.deproxy(getTaxonBase()
538 public void persistName() {
540 getNameViewer().getTextWidget().setEnabled(false);
541 final String unparsedNameString
= getNameViewer().getTextWidget()
543 // Job job = new Job("Persisting Name"){
546 // protected IStatus run(IProgressMonitor monitor) {
548 final NonViralName name
= parseHandler
549 .parseAndResolveDuplicates(unparsedNameString
);
551 // Display.getDefault().asyncExec(new Runnable(){
552 // public void run() {
553 getTaxonBase().setName(name
);
554 getTaxonBase().setTitleCache((getTaxonBase().generateTitle()));
556 getNameViewer().getTextWidget().setEnabled(true);
561 // return Status.OK_STATUS;
566 // job.setPriority(Job.DECORATE);
573 * Getter for the field <code>group</code>.
577 * {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup}
580 public AbstractGroup
getGroup() {
582 throw new IllegalStateException("Group shall not be null.");
592 public void remove() {
593 getGroup().remove(this);
601 protected void createControl() {
602 control
= getEditor().getToolkit().createComposite(
603 getGroup().getControl());
605 control
.setLayoutData(new TableWrapData(TableWrapData
.FILL_GRAB
));
606 TableWrapLayout layout
= new TableWrapLayout();
607 layout
.leftMargin
= 0;
608 layout
.rightMargin
= 0;
609 layout
.topMargin
= 5;
610 layout
.bottomMargin
= 5;
612 layout
.verticalSpacing
= 0;
613 layout
.horizontalSpacing
= 0;
615 control
.setLayout(layout
);
622 protected TaxonNameEditor
getEditor() {
623 return getGroup().getEditor();
628 * Getter for the field <code>control</code>.
631 * @return a {@link org.eclipse.swt.widgets.Composite} object.
633 public Composite
getControl() {
639 * createLineWrapSupport
642 protected void createLineWrapSupport() {
643 new LineWrapSupport(getNameViewer(), getEditor().getManagedForm());
651 protected void createTextViewer() {
652 nameViewer
= new NameViewer(control
);
654 focusListener
= new FocusAdapter() {
656 public void focusGained(FocusEvent e
) {
660 for (AbstractGroupedContainer container
: getEditor()
661 .getGroupedContainers()) {
662 container
.colorSelected(NOT_SELECTED
);
664 getEditor().getManagedForm().setInput(
665 AbstractGroupedContainer
.this);
667 colorSelected(SELECTED_FOCUS
);
670 nameViewer
.getTextWidget().addFocusListener(focusListener
);
673 MouseAdapter mouseListener
= new MouseAdapter() {
675 public void mouseDown(MouseEvent e
) {
679 control
.addMouseListener(mouseListener
);
680 nameViewer
.getRulerControl().addMouseListener(mouseListener
);
681 nameViewer
.getTextWidget().addMouseListener(mouseListener
);
690 * a {@link org.eclipse.swt.graphics.Image} object.
692 public void setIcon(Image icon
) {
693 getNameViewer().setIcon(icon
);
704 public void setIndent(int indent
) {
705 if (control
.getLayout() instanceof TableWrapLayout
) {
706 TableWrapLayout layout
= ((TableWrapLayout
) control
.getLayout());
707 layout
.leftMargin
= indent
;
708 layout
.rightMargin
= ACCEPTED_INDENT
;
709 control
.setLayout(layout
);
712 new RuntimeException(
713 "Couldn't indent - composite's layout must be TableWrapLayout.");
722 public void setSelected() {
723 getNameViewer().getTextWidget().setFocus();
733 public boolean isSelected() {
734 return getEditor().getSelectedContainer() == this;
745 public void colorSelected(int mode
) {
746 if (!control
.isDisposed()) {
747 String colorString
= null;
751 colorString
= Resources
.COLOR_CONTROL_SELECTED_FOCUS
;
753 case SELECTED_NO_FOCUS
:
754 colorString
= Resources
.COLOR_CONTROL_SELECTED
;
757 colorString
= Resources
.COLOR_COMPOSITE_BACKGROUND
;
760 backgroundColor
= EditorUtil
.getColor(colorString
);
762 setBackground(backgroundColor
);
768 * setDelayedSelection
771 protected void setDelayedSelection() {
772 // TODO this might be done better
773 // this is the quickest solution i could come up with and it improves
775 // please reimplement if you know better.
779 Display display
= Display
.getCurrent();
780 Runnable runnable
= new Runnable() {
783 getEditor().getManagedForm().setInput(selection
);
786 display
.timerExec(1000, runnable
);
796 * a {@link org.eclipse.swt.graphics.Color} object.
798 public void setBackground(Color color
) {
799 control
.setBackground(color
);
801 for (Control child
: control
.getChildren()) {
802 child
.setBackground(color
);
805 getNameViewer().setBackground(color
);
812 * org.eclipse.swt.widgets.Control#setFont(org.eclipse.swt.graphics.Font)
820 * a {@link org.eclipse.swt.graphics.Font} object.
822 public void setFont(Font font
) {
823 getNameViewer().getTextWidget().setFont(font
);
828 * Getter for the field <code>nameViewer</code>.
831 * @return a {@link eu.etaxonomy.taxeditor.editor.name.container.NameViewer}
834 public NameViewer
getNameViewer() {
835 if (nameViewer
== null) {
836 throw new RuntimeException(
837 "The Name Viewer is corrupt for Name Container: "
838 + getTaxonBase().getName().getTitleCache());
844 * If <code>textViewer</code> has already been set, it will show a
845 * <code>prompt</code> along the lines of
846 * "Click here to start entering data" when empty.
849 * a {@link java.lang.String} object.
851 public void createEmptyViewerPrompt(final String prompt
) {
853 Assert
.isNotNull(getNameViewer());
855 final StyledText textControl
= getNameViewer().getTextWidget();
856 final IDocument document
= getNameViewer().getDocument();
858 setFocusListener(new FocusListener() {
860 public void focusGained(FocusEvent e
) {
861 if (document
.get().equals(prompt
)) {
862 textControl
.setFont(getViewerFont());
867 public void focusLost(FocusEvent e
) {
868 if (document
.getLength() == 0) {
874 textControl
.addFocusListener(getFocusListener());
876 if (document
.getLength() == 0) {
877 textControl
.setFont(EditorUtil
878 .getFont(Resources
.FONT_DEFAULT_PROMPT
));
879 document
.set(prompt
);
888 * @return a {@link org.eclipse.swt.graphics.Font} object.
890 abstract protected Font
getViewerFont();
897 protected void initEmptyText() {
898 Font defaultFont
= EditorUtil
.getFont(Resources
.FONT_DEFAULT_PROMPT
);
899 getNameViewer().getTextWidget().setFont(defaultFont
);
901 getNameViewer().getDocument().set(getEmptyTextPrompt());
907 * Setter for the field <code>focusListener</code>.
910 * @param focusListener
911 * a {@link org.eclipse.swt.events.FocusListener} object.
913 protected void setFocusListener(FocusListener focusListener
) {
914 this.focusListener
= focusListener
;
917 private FocusListener
getFocusListener() {
918 return focusListener
;
929 public void setDirty(boolean isDirty
) {
931 getEditor().getManagedForm().dirtyStateChanged();
933 this.isDirty
= isDirty
;
943 public boolean isDirty() {
953 * a {@link org.eclipse.swt.widgets.Menu} object.
955 public void setMenu(Menu menu
) {
956 control
.setMenu(menu
);
958 getNameViewer().setMenu(menu
);
961 private Control
[] draggableControls
;
965 * setDraggableControl
969 * an array of {@link org.eclipse.swt.widgets.Control} objects.
971 protected void setDraggableControl(Control
[] controls
) {
972 draggableControls
= controls
;
983 public void setIsDraggable(boolean draggable
) {
987 if (draggableControls
== null) {
988 throw new NullPointerException(
989 "Draggable controls must be set to add draggability");
992 Transfer
[] types
= new Transfer
[] { CdmDataTransfer
.getInstance() };
993 int operations
= DND
.DROP_MOVE
;
995 for (Control draggableControl
: draggableControls
) {
996 DragSource dragSource
= new DragSource(draggableControl
,
998 dragSource
.setTransfer(types
);
1000 dragSource
.addDragListener(new NameEditorDragListener(this));
1001 dragSource
.setDragSourceEffect(new NameEditorDragSourceEffect(
1007 private String nonEditableText
;
1009 ControlListener nonEditableResizeListener
= new ControlAdapter() {
1014 public void controlResized(ControlEvent e
) {
1015 if (nonEditableInfoLabel
.getBounds().width
== width
) {
1018 width
= nonEditableInfoLabel
.getBounds().width
;
1019 if (nonEditableInfoLabel
.getBounds().width
> 0) {
1020 nonEditableInfoLabel
.setText(Dialog
.shortenText(
1021 nonEditableText
.toUpperCase(), nonEditableInfoLabel
));
1026 private String nonEditableHoverText
;
1028 private LabelEllipsisListener nonEditableLabelEllipsisListener
;
1032 private boolean enabled
;
1035 * nonEditableInfo is a label displayed underneath a GroupedComposite's
1036 * input field. For instance, NameComposites display things like name
1037 * relations, sec. references, etc. here.
1040 * the text to display in the label
1042 * whether the string should be appended to text that is already
1043 * shown in the label
1045 public void setNonEditableInfo(String info
, boolean append
) {
1046 // TODO non editable info should only be drawn once, when everything
1048 info
= info
.toUpperCase();
1051 nonEditableText
+= ", " + info
;
1052 nonEditableHoverText
+= "\n" + info
;
1054 nonEditableText
= info
;
1055 nonEditableHoverText
= info
;
1058 if (nonEditableInfoLabel
== null) {
1059 nonEditableInfoLabel
= getEditor().getToolkit().createLabel(
1061 TableWrapData layoutData
= new TableWrapData(
1062 TableWrapData
.FILL_GRAB
, TableWrapData
.TOP
);
1063 // Set indent to viewer ruler's width
1064 if (getNameViewer().getRulerControl() != null) {
1065 // TODO right justify
1066 layoutData
.indent
= NameViewer
.RULER_WIDTH
;
1068 nonEditableInfoLabel
.setLayoutData(layoutData
);
1070 nonEditableLabelEllipsisListener
= new LabelEllipsisListener(
1071 nonEditableInfoLabel
) {
1073 public String
getLabelText() {
1074 return nonEditableText
.toUpperCase();
1077 nonEditableInfoLabel
1078 .addControlListener(nonEditableLabelEllipsisListener
);
1080 nonEditableInfoHover
= new DefaultToolTip(nonEditableInfoLabel
);
1081 nonEditableInfoHover
.setRespectDisplayBounds(true);
1084 nonEditableInfoHover
.setText(nonEditableHoverText
);
1085 nonEditableInfoLabel
.setText(nonEditableText
);
1087 calculateAnnotations();
1092 * Getter for the field <code>data</code>.
1095 * @return a T object.
1097 public T
getData() {
1103 * Setter for the field <code>data</code>.
1109 public void setData(T data
) {
1110 this.data
= (T
) HibernateProxyHelper
.deproxy(data
);
1114 * If the user hitting carriage return should cause something to happen -
1115 * i.e. the creation of a new composite - call this method and override the
1116 * method handleSplitText().
1118 protected void createLineBreakListener() {
1119 lineBreakListener
= new LineBreakListener() {
1121 public void handleSplitText(String text
) {
1122 AbstractGroupedContainer
.this.handleSplitText(text
);
1126 getNameViewer().getTextWidget().addVerifyListener(lineBreakListener
);
1129 abstract class LabelEllipsisListener
extends ControlAdapter
{
1131 private final Label label
;
1134 LabelEllipsisListener(Label label
) {
1138 abstract public String
getLabelText();
1141 public void controlResized(ControlEvent e
) {
1142 if (label
.getBounds().width
== width
) {
1145 width
= label
.getBounds().width
;
1146 if (label
.getBounds().width
> 0) {
1147 label
.setText(TextHelper
.shortenText(getLabelText(), label
));
1157 public void storeCursor() {
1158 this.cursorPosition
= getNameViewer().getCursorPosition();
1162 * Puts the cursor to the position it was last seen on or to the end of line
1163 * if no former position is known.
1165 public void placeCursor() {
1166 if (cursorPosition
== 0) {
1167 getNameViewer().setCursorToEOL();
1169 getNameViewer().setCursorPosition(cursorPosition
);
1175 * Setter for the field <code>group</code>.
1180 * {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup}
1183 public void setGroup(AbstractGroup group
) {
1192 public void restoreColor() {
1193 setBackground(backgroundColor
);
1200 * org.eclipse.ui.forms.IFormPart#initialize(org.eclipse.ui.forms.IManagedForm
1204 public void initialize(IManagedForm form
) {
1205 // TODO Auto-generated method stub
1212 * @see org.eclipse.ui.forms.IFormPart#dispose()
1215 public void dispose() {
1216 if (getControl() != null) {
1218 getControl().dispose();
1225 * @see org.eclipse.ui.forms.IFormPart#commit(boolean)
1228 public void commit(boolean onSave
) {
1237 * @see org.eclipse.ui.forms.IFormPart#setFormInput(java.lang.Object)
1240 public boolean setFormInput(Object input
) {
1247 * @see org.eclipse.ui.forms.IFormPart#setFocus()
1250 public void setFocus() {
1251 getNameViewer().getControl().setFocus();
1257 * @see org.eclipse.ui.forms.IFormPart#isStale()
1260 public boolean isStale() {
1264 public void setDisabled(boolean disabled
) {
1265 this.enabled
= !disabled
;
1266 setEnabled(enabled
);
1269 public void setEnabled(boolean enabled
) {
1270 this.enabled
= enabled
;
1271 Color color
= enabled ? control
.getForeground() : EditorUtil
.getColor(Resources
.COLOR_DISABLED_EDITOR
);
1273 getNameViewer().getTextWidget().setEditable(enabled
);
1274 getNameViewer().getTextWidget().setEnabled(enabled
);
1275 getNameViewer().getTextWidget().setForeground(color
);
1278 public boolean isEnabled(){