]> git.argeo.org Git - gpl/argeo-suite.git/blob - org.argeo.app.ui/src/org/argeo/app/ui/forms/AbstractTermsPart.java
Default edition layer supports SWT UI provider
[gpl/argeo-suite.git] / org.argeo.app.ui / src / org / argeo / app / ui / forms / AbstractTermsPart.java
1 package org.argeo.app.ui.forms;
2
3 import javax.jcr.Item;
4
5 import org.argeo.api.cms.ux.CmsIcon;
6 import org.argeo.app.api.Term;
7 import org.argeo.app.api.TermsManager;
8 import org.argeo.app.api.Typology;
9 import org.argeo.cms.Localized;
10 import org.argeo.cms.swt.CmsSwtTheme;
11 import org.argeo.cms.swt.CmsSwtUtils;
12 import org.argeo.cms.swt.SwtEditablePart;
13 import org.argeo.cms.swt.widgets.ContextOverlay;
14 import org.argeo.cms.ui.widgets.StyledControl;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.graphics.Color;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Control;
20 import org.eclipse.swt.widgets.Label;
21 import org.eclipse.swt.widgets.Text;
22 import org.eclipse.swt.widgets.ToolItem;
23
24 /** Common logic between single and mutliple terms editable part. */
25 public abstract class AbstractTermsPart extends StyledControl implements SwtEditablePart {
26 private static final long serialVersionUID = -5497097995341927710L;
27 protected final TermsManager termsManager;
28 protected final Typology typology;
29
30 private final boolean editable;
31
32 private CmsIcon deleteIcon;
33 private CmsIcon addIcon;
34 private CmsIcon cancelIcon;
35
36 private Color highlightColor;
37 private Composite highlight;
38
39 protected final CmsSwtTheme theme;
40
41 public AbstractTermsPart(Composite parent, int style, Item item, TermsManager termsManager, String typology) {
42 super(parent, style, item);
43 if (item == null)
44 throw new IllegalArgumentException("Item cannot be null");
45 this.termsManager = termsManager;
46 this.typology = termsManager.getTypology(typology);
47 this.theme = CmsSwtUtils.getCmsTheme(parent);
48 editable = !(SWT.READ_ONLY == (style & SWT.READ_ONLY));
49 highlightColor = parent.getDisplay().getSystemColor(SWT.COLOR_GRAY);
50 }
51
52 public boolean isEditable() {
53 return editable;
54 }
55
56 protected void createHighlight(Composite block) {
57 highlight = new Composite(block, SWT.NONE);
58 highlight.setBackground(highlightColor);
59 GridData highlightGd = new GridData(SWT.FILL, SWT.FILL, false, false);
60 highlightGd.widthHint = 5;
61 highlightGd.heightHint = 3;
62 highlight.setLayoutData(highlightGd);
63
64 }
65
66 protected String getTermLabel(Term term) {
67 if (term instanceof Localized)
68 return ((Localized) term).lead();
69 else
70 return term.getName();
71
72 }
73
74 protected abstract void refresh(ContextOverlay contextArea, String filter, Text txt);
75
76 protected boolean isTermSelectable(Term term) {
77 return true;
78 }
79
80 protected void processTermListLabel(Term term, Label label) {
81
82 }
83
84 protected void setControlLayoutData(Control control) {
85 control.setLayoutData(CmsSwtUtils.fillAll());
86 }
87
88 protected void setContainerLayoutData(Composite composite) {
89 composite.setLayoutData(CmsSwtUtils.fillAll());
90 }
91
92 //
93 // STYLING
94 //
95 public void setDeleteIcon(CmsIcon deleteIcon) {
96 this.deleteIcon = deleteIcon;
97 }
98
99 public void setAddIcon(CmsIcon addIcon) {
100 this.addIcon = addIcon;
101 }
102
103 public void setCancelIcon(CmsIcon cancelIcon) {
104 this.cancelIcon = cancelIcon;
105 }
106
107 protected TermsManager getTermsManager() {
108 return termsManager;
109 }
110
111 protected void styleDelete(ToolItem deleteItem) {
112 if (deleteIcon != null)
113 deleteItem.setImage(theme.getSmallIcon(deleteIcon));
114 else
115 deleteItem.setText("-");
116 }
117
118 protected void styleCancel(ToolItem cancelItem) {
119 if (cancelIcon != null)
120 cancelItem.setImage(theme.getSmallIcon(cancelIcon));
121 else
122 cancelItem.setText("X");
123 }
124
125 protected void styleAdd(ToolItem addItem) {
126 if (addIcon != null)
127 addItem.setImage(theme.getSmallIcon(addIcon));
128 else
129 addItem.setText("+");
130 }
131 }