1
|
/**
|
2
|
* Copyright (C) 2019 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
|
package eu.etaxonomy.taxeditor.view.search.facet.term;
|
10
|
|
11
|
import java.util.stream.Collectors;
|
12
|
|
13
|
import org.eclipse.jface.layout.GridDataFactory;
|
14
|
import org.eclipse.jface.resource.JFaceResources;
|
15
|
import org.eclipse.swt.SWT;
|
16
|
import org.eclipse.swt.events.ControlAdapter;
|
17
|
import org.eclipse.swt.events.ControlEvent;
|
18
|
import org.eclipse.swt.layout.GridData;
|
19
|
import org.eclipse.swt.layout.GridLayout;
|
20
|
import org.eclipse.swt.widgets.Composite;
|
21
|
import org.eclipse.swt.widgets.Label;
|
22
|
|
23
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
24
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
25
|
import eu.etaxonomy.taxeditor.view.search.facet.CheckBoxSearchResultComposite;
|
26
|
|
27
|
/**
|
28
|
* @author pplitzner
|
29
|
* @since Jan 23, 2019
|
30
|
*
|
31
|
*/
|
32
|
public class TermSearchResultComposite extends CheckBoxSearchResultComposite<TermDto, TermSearchResult> {
|
33
|
|
34
|
public TermSearchResultComposite(TermSearchResult result, Composite parent, int style) {
|
35
|
super(result, parent, style);
|
36
|
}
|
37
|
|
38
|
@Override
|
39
|
public Composite createContent(Composite parent) {
|
40
|
Composite content = new Composite(this, SWT.NONE);
|
41
|
content.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
|
42
|
GridLayout layout = new GridLayout(1, false);
|
43
|
content.setLayout(layout);
|
44
|
Label label = new Label(content, SWT.WRAP);
|
45
|
label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
|
46
|
label.setText(result.getContent().getRepresentation_L10n());
|
47
|
label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
|
48
|
GridDataFactory.fillDefaults().applyTo(label);
|
49
|
|
50
|
String facetText = result.getFacets().stream()
|
51
|
.map(facet -> (facet.getFacet() != null ? facet.getFacet() : "")
|
52
|
+ (facet.getCategory() != null ? " (" + facet.getCategory() + ")" : ""))
|
53
|
.collect(Collectors.joining(","));
|
54
|
if (CdmUtils.isNotBlank(facetText)) {
|
55
|
Label labelFacets = new Label(content, SWT.WRAP);
|
56
|
labelFacets.setText(facetText);
|
57
|
labelFacets.setFont(JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT));
|
58
|
}
|
59
|
|
60
|
Label lblDescription = new Label(content, SWT.WRAP);
|
61
|
GridData layoutData = new GridData();
|
62
|
lblDescription.setLayoutData(layoutData);
|
63
|
parent.addControlListener(new ControlAdapter() {
|
64
|
@Override
|
65
|
public void controlResized(ControlEvent e) {
|
66
|
layoutData.widthHint = parent.getClientArea().width - (6*layout.marginWidth);
|
67
|
parent.layout(true);
|
68
|
}
|
69
|
});
|
70
|
String representation_L10n_text = result.getContent().getRepresentation_L10n_text();
|
71
|
if(representation_L10n_text!=null){
|
72
|
lblDescription.setText(representation_L10n_text);
|
73
|
}
|
74
|
return content;
|
75
|
}
|
76
|
|
77
|
}
|