1 package org
.argeo
.slc
.akb
.ui
.composites
;
6 import javax
.jcr
.Property
;
7 import javax
.jcr
.RepositoryException
;
8 import javax
.jcr
.Session
;
10 import org
.argeo
.eclipse
.ui
.utils
.CommandUtils
;
11 import org
.argeo
.slc
.akb
.AkbException
;
12 import org
.argeo
.slc
.akb
.AkbNames
;
13 import org
.argeo
.slc
.akb
.ui
.AkbUiUtils
;
14 import org
.argeo
.slc
.akb
.ui
.commands
.OpenAkbNodeEditor
;
15 import org
.argeo
.slc
.akb
.utils
.AkbJcrUtils
;
16 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.events
.ModifyEvent
;
19 import org
.eclipse
.swt
.events
.ModifyListener
;
20 import org
.eclipse
.swt
.events
.SelectionAdapter
;
21 import org
.eclipse
.swt
.events
.SelectionEvent
;
22 import org
.eclipse
.swt
.layout
.GridData
;
23 import org
.eclipse
.swt
.layout
.GridLayout
;
24 import org
.eclipse
.swt
.widgets
.Combo
;
25 import org
.eclipse
.swt
.widgets
.Composite
;
26 import org
.eclipse
.swt
.widgets
.Label
;
27 import org
.eclipse
.swt
.widgets
.Link
;
28 import org
.eclipse
.swt
.widgets
.Text
;
29 import org
.eclipse
.ui
.forms
.AbstractFormPart
;
30 import org
.eclipse
.ui
.forms
.IManagedForm
;
31 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
33 public class ItemTemplateTitleComposite
extends Composite
{
34 // private final static Log log =
35 // LogFactory.getLog(MixTitleComposite.class);
37 private final Node akbNode
;
38 private final FormToolkit toolkit
;
39 private final IManagedForm form
;
40 // Don't forget to unregister on dispose
41 private AbstractFormPart formPart
;
43 // To enable set focus
44 private Text titleTxt
;
45 private Combo typeCmb
;
47 private List
<Node
> definedAliases
;
49 public ItemTemplateTitleComposite(Composite parent
, int style
,
50 FormToolkit toolkit
, IManagedForm form
, Node akbNode
) {
52 this.akbNode
= akbNode
;
53 this.toolkit
= toolkit
;
59 private void populate() {
61 Composite parent
= this;
63 parent
.setLayout(new GridLayout(5, false));
65 // first line: Item name
66 toolkit
.createLabel(parent
, "Name");
67 titleTxt
= toolkit
.createText(parent
, "", SWT
.BORDER
);
68 GridData gd
= new GridData(SWT
.FILL
, SWT
.TOP
, true, false, 4, 1);
69 titleTxt
.setLayoutData(gd
);
71 // Second line: alias management
72 toolkit
.createLabel(parent
, "Alias");
73 typeCmb
= new Combo(parent
, SWT
.READ_ONLY
);
74 toolkit
.adapt(typeCmb
, false, false);
75 gd
= new GridData(SWT
.FILL
, SWT
.TOP
, true, false, 3, 1);
76 typeCmb
.setLayoutData(gd
);
78 final Link openAliasLk
= new Link(parent
, SWT
.NONE
);
79 toolkit
.adapt(openAliasLk
, false, false);
80 openAliasLk
.setText("<a> Edit Alias </a>");
81 openAliasLk
.addSelectionListener(new SelectionAdapter() {
83 public void widgetSelected(final SelectionEvent event
) {
84 int index
= typeCmb
.getSelectionIndex();
86 Node currAlias
= definedAliases
.get(index
);
87 String id
= AkbJcrUtils
.getIdentifierQuietly(currAlias
);
88 CommandUtils
.callCommand(OpenAkbNodeEditor
.ID
,
89 OpenAkbNodeEditor
.PARAM_NODE_JCR_ID
, id
);
91 MessageDialog
.openError(getShell(), "Error",
96 // final Link testAliasLk= new Link(parent, SWT.NONE);
97 // openAliasLk.setText("<a> Edit Alias </a>");
98 // openAliasLk.addSelectionListener(new SelectionAdapter() {
99 // private static final long serialVersionUID = 1L;
102 // public void widgetSelected(final SelectionEvent event) {
103 // MessageDialog.openInformation(getShell(), "test", "test");
107 // 3rd line: description
108 Label lbl
= toolkit
.createLabel(parent
, "Description");
109 lbl
.setLayoutData(new GridData(SWT
.LEFT
, SWT
.TOP
, false, false));
110 final Text descTxt
= toolkit
.createText(parent
, "", SWT
.BORDER
111 | SWT
.MULTI
| SWT
.WRAP
);
112 gd
= new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 4, 1);
113 descTxt
.setLayoutData(gd
);
116 final AbstractFormPart part
= new AbstractFormPart() {
117 public void refresh() {
119 // update display value
120 AkbUiUtils
.refreshFormTextWidget(titleTxt
, akbNode
,
122 AkbUiUtils
.refreshFormTextWidget(descTxt
, akbNode
,
123 Property
.JCR_DESCRIPTION
);
125 refreshTypeCmbValues();
126 typeCmb
.select(getCurrAliasIndex());
127 typeCmb
.setEnabled(AkbJcrUtils
.isNodeCheckedOutByMe(akbNode
));
132 AkbUiUtils
.addTextModifyListener(titleTxt
, akbNode
, Property
.JCR_TITLE
,
134 AkbUiUtils
.addTextModifyListener(descTxt
, akbNode
,
135 Property
.JCR_DESCRIPTION
, part
);
137 typeCmb
.addModifyListener(new ModifyListener() {
139 public void modifyText(ModifyEvent event
) {
141 int oldIndex
= getCurrAliasIndex();
142 int selIndex
= typeCmb
.getSelectionIndex();
144 // insure something has really been modified
145 if (selIndex
< 0 || oldIndex
== selIndex
)
149 Node newAlias
= definedAliases
.get(selIndex
);
150 akbNode
.setProperty(AkbNames
.AKB_USED_CONNECTOR
,
153 } catch (RepositoryException e
) {
154 throw new AkbException(
155 "Error while updating connector alias", e
);
163 private void refreshTypeCmbValues() {
164 List
<Node
> newAliases
= AkbJcrUtils
.getDefinedAliasForNode(akbNode
);
165 boolean hasChanged
= false;
166 // manually ckeck if something has changed
167 if (definedAliases
== null
168 || newAliases
.size() != definedAliases
.size())
172 for (int i
= 0; i
< newAliases
.size(); i
++) {
173 if (!newAliases
.get(i
).equals(definedAliases
.get(i
))) {
181 definedAliases
= newAliases
;
182 final String
[] names
= new String
[definedAliases
.size()];
184 for (Node node
: definedAliases
)
185 names
[i
++] = AkbJcrUtils
.get(node
, Property
.JCR_TITLE
);
186 typeCmb
.setItems(names
);
191 * Returns the index in definedAliases list of the CURRENT defined alias as
192 * set in the item node <CODE>AkbNames.AKB_USED_CONNECTOR</CODE> if defined,
195 private int getCurrAliasIndex() {
198 int currAliasIndex
= -1;
199 if (akbNode
.hasProperty(AkbNames
.AKB_USED_CONNECTOR
))
200 path
= akbNode
.getProperty(AkbNames
.AKB_USED_CONNECTOR
)
203 Session session
= akbNode
.getSession();
204 if (path
!= null && session
.nodeExists(path
)) {
205 for (int i
= 0; i
< definedAliases
.size(); i
++) {
206 if (path
.equals(definedAliases
.get(i
).getPath())) {
212 // Node chosenAlias = session.getNode(path);
213 // currAliasIndex = definedAliases.indexOf(chosenAlias);
215 return currAliasIndex
;
216 } catch (RepositoryException re
) {
217 throw new AkbException("Unable to retrieve current Alias", re
);
222 public boolean setFocus() {
223 return titleTxt
.setFocus();
226 protected void disposePart(AbstractFormPart part
) {
228 form
.removePart(part
);
234 public void dispose() {
235 disposePart(formPart
);