Revision a83b0d46
Added by Patrick Plitzner about 7 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/TaxonAssociationDetailElement.java | ||
---|---|---|
13 | 13 |
import java.util.Collection; |
14 | 14 |
import java.util.Set; |
15 | 15 |
|
16 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
|
17 | 16 |
import org.eclipse.jface.viewers.DoubleClickEvent; |
18 | 17 |
import org.eclipse.jface.viewers.IDoubleClickListener; |
19 |
import org.eclipse.jface.viewers.ISelection; |
|
20 | 18 |
import org.eclipse.jface.viewers.IStructuredSelection; |
21 |
import org.eclipse.jface.viewers.LabelProvider; |
|
22 |
import org.eclipse.jface.viewers.ListViewer; |
|
23 | 19 |
import org.eclipse.swt.SWT; |
20 |
import org.eclipse.swt.custom.StyledText; |
|
24 | 21 |
import org.eclipse.swt.dnd.Clipboard; |
25 | 22 |
import org.eclipse.swt.dnd.TextTransfer; |
26 | 23 |
import org.eclipse.swt.dnd.Transfer; |
... | ... | |
29 | 26 |
import org.eclipse.swt.widgets.Label; |
30 | 27 |
import org.eclipse.swt.widgets.Menu; |
31 | 28 |
import org.eclipse.swt.widgets.MenuItem; |
29 |
import org.eclipse.ui.forms.widgets.TableWrapLayout; |
|
32 | 30 |
|
33 | 31 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade; |
34 | 32 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
... | ... | |
68 | 66 |
associations.addAll(typeDesignations); |
69 | 67 |
associations.addAll(determinationEvents); |
70 | 68 |
|
69 |
TableWrapLayout layout = (TableWrapLayout) getLayoutComposite().getLayout(); |
|
70 |
layout.bottomMargin = 0; |
|
71 |
layout.topMargin = 0; |
|
72 |
|
|
71 | 73 |
if(associatedTaxa.isEmpty() && typeDesignations.isEmpty() && determinationEvents.isEmpty()){ |
72 | 74 |
Label label = formFactory.createLabel(getLayoutComposite(), "No associations"); |
73 | 75 |
label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1)); |
74 | 76 |
return; |
75 | 77 |
} |
76 |
if(!associations.isEmpty()){ |
|
77 |
final ListViewer viewer = new ListViewer(getLayoutComposite(), SWT.SINGLE); |
|
78 |
viewer.getList().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1)); |
|
79 |
viewer.setContentProvider(new ArrayContentProvider()); |
|
80 |
viewer.setLabelProvider(new LabelProvider(){ |
|
81 |
@Override |
|
82 |
public String getText(Object element) { |
|
83 |
if(element instanceof TaxonBase){ |
|
84 |
return "Associated with "+element.toString(); |
|
85 |
} |
|
86 |
else if(element instanceof DeterminationEvent){ |
|
87 |
DeterminationEvent determinationEvent = (DeterminationEvent)element; |
|
88 |
if(determinationEvent.getTaxon()!=null){ |
|
89 |
return "Determined as taxon "+determinationEvent.getTaxon(); |
|
90 |
} |
|
91 |
if(determinationEvent.getTaxonName()!=null){ |
|
92 |
return "Determined as name "+determinationEvent.getTaxonName(); |
|
93 |
} |
|
94 |
} |
|
95 |
else if(element instanceof SpecimenTypeDesignation){ |
|
96 |
SpecimenTypeDesignation typeDesignation = (SpecimenTypeDesignation)element; |
|
97 |
String label = typeDesignation.getTypeStatus()!=null?typeDesignation.getTypeStatus().getLabel()+" of ":"Type of "; |
|
98 |
Set<TaxonNameBase> typifiedNames = typeDesignation.getTypifiedNames(); |
|
99 |
for (TaxonNameBase taxonNameBase : typifiedNames) { |
|
100 |
label += taxonNameBase+", "; |
|
101 |
} |
|
102 |
if(label.endsWith(", ")){ |
|
103 |
label = label.substring(0, label.length()-2); |
|
104 |
} |
|
105 |
return label; |
|
106 |
} |
|
107 |
return ""; |
|
108 |
} |
|
109 |
}); |
|
110 |
viewer.setInput(associations); |
|
111 |
viewer.addDoubleClickListener(this); |
|
78 |
for (CdmBase cdmBase : associations) { |
|
79 |
final StyledText styledTextWidget = new StyledText(getLayoutComposite(), SWT.WRAP); |
|
80 |
styledTextWidget.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1)); |
|
81 |
styledTextWidget.setText(getLabelText(cdmBase)); |
|
82 |
styledTextWidget.setBackground(getLayoutComposite().getBackground()); |
|
83 |
styledTextWidget.setEditable(false); |
|
84 |
//Set caret null this will hide caret |
|
85 |
styledTextWidget.setCaret(null); |
|
112 | 86 |
|
113 | 87 |
//TODO add context menu for deleting associations |
114 |
//context menu
|
|
115 |
Menu menu = new Menu(viewer.getControl());
|
|
116 |
MenuItem copyItem = new MenuItem(menu, SWT.PUSH);
|
|
117 |
copyItem.setText("Copy");
|
|
118 |
copyItem.addSelectionListener(new SelectionListener() {
|
|
88 |
//context menu
|
|
89 |
Menu menu = new Menu(styledTextWidget);
|
|
90 |
MenuItem copyItem = new MenuItem(menu, SWT.PUSH);
|
|
91 |
copyItem.setText("Copy");
|
|
92 |
copyItem.addSelectionListener(new SelectionListener() {
|
|
119 | 93 |
|
120 | 94 |
@Override |
121 | 95 |
public void widgetSelected(SelectionEvent e) { |
122 |
ISelection selection = viewer.getSelection(); |
|
123 |
if(!selection.isEmpty() && selection instanceof IStructuredSelection){ |
|
124 |
Object firstElement = ((IStructuredSelection) selection).getFirstElement(); |
|
125 |
Object[] data = new Object[]{firstElement.toString()}; |
|
126 |
Clipboard clipboard = new Clipboard(viewer.getControl().getDisplay()); |
|
127 |
clipboard.setContents(data, new Transfer[]{TextTransfer.getInstance()}); |
|
128 |
} |
|
96 |
Object[] data = new Object[]{styledTextWidget.getText()}; |
|
97 |
Clipboard clipboard = new Clipboard(styledTextWidget.getDisplay()); |
|
98 |
clipboard.setContents(data, new Transfer[]{TextTransfer.getInstance()}); |
|
129 | 99 |
} |
130 | 100 |
|
131 | 101 |
@Override |
132 | 102 |
public void widgetDefaultSelected(SelectionEvent e) { |
133 | 103 |
} |
134 | 104 |
}); |
135 |
viewer.getControl().setMenu(menu); |
|
105 |
styledTextWidget.setMenu(menu); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
private String getLabelText(Object element) { |
|
110 |
if(element instanceof TaxonBase){ |
|
111 |
return "Associated with "+element.toString(); |
|
112 |
} |
|
113 |
else if(element instanceof DeterminationEvent){ |
|
114 |
DeterminationEvent determinationEvent = (DeterminationEvent)element; |
|
115 |
if(determinationEvent.getTaxon()!=null){ |
|
116 |
return "Determined as taxon "+determinationEvent.getTaxon(); |
|
117 |
} |
|
118 |
if(determinationEvent.getTaxonName()!=null){ |
|
119 |
return "Determined as name "+determinationEvent.getTaxonName(); |
|
120 |
} |
|
121 |
} |
|
122 |
else if(element instanceof SpecimenTypeDesignation){ |
|
123 |
SpecimenTypeDesignation typeDesignation = (SpecimenTypeDesignation)element; |
|
124 |
String label = typeDesignation.getTypeStatus()!=null?typeDesignation.getTypeStatus().getLabel()+" of ":"Type of "; |
|
125 |
Set<TaxonNameBase> typifiedNames = typeDesignation.getTypifiedNames(); |
|
126 |
for (TaxonNameBase taxonNameBase : typifiedNames) { |
|
127 |
label += taxonNameBase+", "; |
|
128 |
} |
|
129 |
if(label.endsWith(", ")){ |
|
130 |
label = label.substring(0, label.length()-2); |
|
131 |
} |
|
132 |
return label; |
|
136 | 133 |
} |
134 |
return ""; |
|
137 | 135 |
} |
138 | 136 |
|
139 | 137 |
/** {@inheritDoc} */ |
Also available in: Unified diff
ref #5348 Wrap text of taxon associations