1 package org
.argeo
.entity
.ui
.forms
;
5 import org
.argeo
.cms
.Localized
;
6 import org
.argeo
.cms
.ui
.CmsTheme
;
7 import org
.argeo
.cms
.ui
.util
.CmsIcon
;
8 import org
.argeo
.cms
.ui
.viewers
.EditablePart
;
9 import org
.argeo
.cms
.ui
.widgets
.ContextOverlay
;
10 import org
.argeo
.cms
.ui
.widgets
.StyledControl
;
11 import org
.argeo
.entity
.Term
;
12 import org
.argeo
.entity
.TermsManager
;
13 import org
.argeo
.entity
.Typology
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.graphics
.Color
;
16 import org
.eclipse
.swt
.layout
.GridData
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.swt
.widgets
.Label
;
19 import org
.eclipse
.swt
.widgets
.Text
;
20 import org
.eclipse
.swt
.widgets
.ToolItem
;
22 /** Common logic between single and mutliple terms editable part. */
23 public abstract class AbstractTermsPart
extends StyledControl
implements EditablePart
{
24 private static final long serialVersionUID
= -5497097995341927710L;
25 protected final TermsManager termsManager
;
26 protected final Typology typology
;
28 protected final boolean editable
;
30 private CmsIcon deleteIcon
;
31 private CmsIcon addIcon
;
32 private CmsIcon cancelIcon
;
34 private Color highlightColor
;
35 private Composite highlight
;
37 protected final CmsTheme theme
;
39 public AbstractTermsPart(Composite parent
, int style
, Item item
, TermsManager termsManager
, String typology
) {
40 super(parent
, style
, item
);
42 throw new IllegalArgumentException("Item cannot be null");
43 this.termsManager
= termsManager
;
44 this.typology
= termsManager
.getTypology(typology
);
45 this.theme
= CmsTheme
.getCmsTheme(parent
);
46 editable
= !(SWT
.READ_ONLY
== (style
& SWT
.READ_ONLY
));
47 highlightColor
= parent
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
);
50 protected void createHighlight(Composite block
) {
51 highlight
= new Composite(block
, SWT
.NONE
);
52 highlight
.setBackground(highlightColor
);
53 GridData highlightGd
= new GridData(SWT
.FILL
, SWT
.FILL
, false, false);
54 highlightGd
.widthHint
= 5;
55 highlightGd
.heightHint
= 3;
56 highlight
.setLayoutData(highlightGd
);
60 protected String
getTermLabel(Term term
) {
61 if (term
instanceof Localized
)
62 return ((Localized
) term
).lead();
64 return term
.getName();
68 protected abstract void refresh(ContextOverlay contextArea
, String filter
, Text txt
);
70 protected boolean isTermSelectable(Term term
) {
74 protected void processTermListLabel(Term term
, Label label
) {
81 public void setDeleteIcon(CmsIcon deleteIcon
) {
82 this.deleteIcon
= deleteIcon
;
85 public void setAddIcon(CmsIcon addIcon
) {
86 this.addIcon
= addIcon
;
89 public void setCancelIcon(CmsIcon cancelIcon
) {
90 this.cancelIcon
= cancelIcon
;
93 protected TermsManager
getTermsManager() {
97 protected void styleDelete(ToolItem deleteItem
) {
98 if (deleteIcon
!= null)
99 deleteItem
.setImage(deleteIcon
.getSmallIcon(theme
));
101 deleteItem
.setText("-");
104 protected void styleCancel(ToolItem cancelItem
) {
105 if (cancelIcon
!= null)
106 cancelItem
.setImage(cancelIcon
.getSmallIcon(theme
));
108 cancelItem
.setText("X");
111 protected void styleAdd(ToolItem addItem
) {
113 addItem
.setImage(addIcon
.getSmallIcon(theme
));
115 addItem
.setText("+");