1 package org
.argeo
.slc
.akb
.ui
.composites
;
6 import javax
.jcr
.Property
;
8 import org
.argeo
.slc
.akb
.ui
.AkbUiUtils
;
9 import org
.argeo
.slc
.akb
.utils
.AkbJcrUtils
;
10 import org
.eclipse
.swt
.SWT
;
11 import org
.eclipse
.swt
.events
.ModifyEvent
;
12 import org
.eclipse
.swt
.events
.ModifyListener
;
13 import org
.eclipse
.swt
.layout
.GridData
;
14 import org
.eclipse
.swt
.layout
.GridLayout
;
15 import org
.eclipse
.swt
.widgets
.Combo
;
16 import org
.eclipse
.swt
.widgets
.Composite
;
17 import org
.eclipse
.swt
.widgets
.Label
;
18 import org
.eclipse
.swt
.widgets
.Text
;
19 import org
.eclipse
.ui
.forms
.AbstractFormPart
;
20 import org
.eclipse
.ui
.forms
.IManagedForm
;
21 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
23 public class ItemTemplateTitleComposite
extends Composite
{
24 // private final static Log log =
25 // LogFactory.getLog(MixTitleComposite.class);
27 private final Node akbNode
;
28 private final FormToolkit toolkit
;
29 private final IManagedForm form
;
30 // Don't forget to unregister on dispose
31 private AbstractFormPart formPart
;
33 // To enable set focus
34 private Text titleTxt
;
36 public ItemTemplateTitleComposite(Composite parent
, int style
,
37 FormToolkit toolkit
, IManagedForm form
, Node akbNode
) {
39 this.akbNode
= akbNode
;
40 this.toolkit
= toolkit
;
46 private void populate() {
48 Composite parent
= this;
50 parent
.setLayout(new GridLayout(4, false));
52 // first line: Item name
53 toolkit
.createLabel(parent
, "Name");
54 titleTxt
= toolkit
.createText(parent
, "", SWT
.BORDER
);
55 GridData gd
= new GridData(SWT
.FILL
, SWT
.TOP
, true, false, 3, 1);
56 titleTxt
.setLayoutData(gd
);
58 // Second line: alias management
59 toolkit
.createLabel(parent
, "Alias");
60 final Combo typeCmb
= new Combo(parent
, SWT
.READ_ONLY
);
62 // TODO enable live refresh
63 final List
<Node
> definedAliases
= AkbJcrUtils
64 .getDefinedAliasForNode(akbNode
);
66 final String
[] names
= new String
[definedAliases
.size()];
68 for (Node node
: definedAliases
)
69 names
[i
++] = AkbJcrUtils
.get(node
, Property
.JCR_TITLE
);
70 typeCmb
.setItems(names
);
72 gd
= new GridData(SWT
.FILL
, SWT
.TOP
, true, false, 3, 1);
73 typeCmb
.setLayoutData(gd
);
75 // 3rd line: description
76 Label lbl
= toolkit
.createLabel(parent
, "Description");
77 lbl
.setLayoutData(new GridData(SWT
.LEFT
, SWT
.TOP
, false, false));
78 final Text descTxt
= toolkit
.createText(parent
, "", SWT
.BORDER
79 | SWT
.MULTI
| SWT
.WRAP
);
80 gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 3, 1);
81 descTxt
.setLayoutData(gd
);
84 final AbstractFormPart part
= new AbstractFormPart() {
85 public void refresh() {
87 // update display value
88 AkbUiUtils
.refreshFormTextWidget(titleTxt
, akbNode
,
90 AkbUiUtils
.refreshFormTextWidget(descTxt
, akbNode
,
91 Property
.JCR_DESCRIPTION
);
93 // TODO implement this
94 // typeCmb.select(getCurrTypeIndex());
95 typeCmb
.setEnabled(AkbJcrUtils
.isNodeCheckedOutByMe(akbNode
));
100 AkbUiUtils
.addTextModifyListener(titleTxt
, akbNode
, Property
.JCR_TITLE
,
102 AkbUiUtils
.addTextModifyListener(descTxt
, akbNode
,
103 Property
.JCR_DESCRIPTION
, part
);
105 typeCmb
.addModifyListener(new ModifyListener() {
107 public void modifyText(ModifyEvent event
) {
109 int oldIndex
= -1; // getCurrTypeIndex();
110 int selIndex
= typeCmb
.getSelectionIndex();
112 // insure something has really been modified
113 if (selIndex
< 0 || oldIndex
== selIndex
)
116 // TODO set new alias
118 // } catch (RepositoryException e) {
119 // throw new AkbException(
120 // "Error while updating connector alias", e);
129 public boolean setFocus() {
130 return titleTxt
.setFocus();
133 protected void disposePart(AbstractFormPart part
) {
135 form
.removePart(part
);
141 public void dispose() {
142 disposePart(formPart
);