]>
git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.akb.ui/src/main/java/org/argeo/slc/akb/ui/editors/ConnectorAliasEditor.java
1 package org
.argeo
.slc
.akb
.ui
.editors
;
3 import javax
.jcr
.Property
;
4 import javax
.jcr
.RepositoryException
;
6 import org
.argeo
.slc
.akb
.AkbException
;
7 import org
.argeo
.slc
.akb
.AkbNames
;
8 import org
.argeo
.slc
.akb
.AkbTypes
;
9 import org
.argeo
.slc
.akb
.ui
.AkbUiPlugin
;
10 import org
.argeo
.slc
.akb
.ui
.AkbUiUtils
;
11 import org
.argeo
.slc
.akb
.utils
.AkbJcrUtils
;
12 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.events
.ModifyEvent
;
15 import org
.eclipse
.swt
.events
.ModifyListener
;
16 import org
.eclipse
.swt
.events
.SelectionAdapter
;
17 import org
.eclipse
.swt
.events
.SelectionEvent
;
18 import org
.eclipse
.swt
.layout
.GridData
;
19 import org
.eclipse
.swt
.layout
.GridLayout
;
20 import org
.eclipse
.swt
.widgets
.Button
;
21 import org
.eclipse
.swt
.widgets
.Combo
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
23 import org
.eclipse
.swt
.widgets
.Group
;
24 import org
.eclipse
.swt
.widgets
.Text
;
25 import org
.eclipse
.ui
.forms
.AbstractFormPart
;
26 import org
.eclipse
.ui
.forms
.IManagedForm
;
29 * Display and edit a connector Alias
31 public class ConnectorAliasEditor
extends AbstractAkbNodeEditor
{
32 // private final static Log log = LogFactory
33 // .getLog(AkbConnectorAliasEditor.class);
35 public final static String ID
= AkbUiPlugin
.PLUGIN_ID
36 + ".connectorAliasEditor";
38 private String
[] connectorTypesLbl
= new String
[] { "JDBC", "SSH", "JCR" };
39 private String
[] connectorTypes
= new String
[] {
40 AkbTypes
.AKB_JDBC_CONNECTOR
, AkbTypes
.AKB_SSH_CONNECTOR
,
41 AkbTypes
.AKB_JCR_CONNECTOR
};
43 private IManagedForm managedForm
;
45 /* CONTENT CREATION */
47 public void populateMainPage(Composite parent
, IManagedForm managedForm
) {
48 parent
.setLayout(AkbUiUtils
.gridLayoutNoBorder());
49 this.managedForm
= managedForm
;
51 // First line main info
52 Composite firstLine
= getToolkit()
53 .createComposite(parent
, SWT
.NO_FOCUS
);
54 firstLine
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
55 createConnectorAliasInfoCmp(firstLine
);
57 // Second line define defaut connector and test abilities
58 Composite secondLine
= getToolkit().createComposite(parent
,
60 secondLine
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
61 createDefaultTestConnectorCmp(secondLine
);
65 private void createConnectorAliasInfoCmp(Composite parent
) {
66 parent
.setLayout(new GridLayout(4, false));
68 // first line: connector type and name
69 getToolkit().createLabel(parent
, "Connector Type");
70 final Combo typeCmb
= new Combo(parent
, SWT
.READ_ONLY
);
71 typeCmb
.setItems(connectorTypesLbl
);
73 getToolkit().createLabel(parent
, "Name");
74 final Text titleTxt
= getToolkit().createText(parent
, "", SWT
.BORDER
);
75 GridData gd
= new GridData(SWT
.FILL
, SWT
.TOP
, true, false);
76 titleTxt
.setLayoutData(gd
);
78 // 2nd line: description
79 getToolkit().createLabel(parent
, "Short Description");
80 final Text descTxt
= getToolkit().createText(parent
, "", SWT
.BORDER
);
81 gd
= new GridData(SWT
.FILL
, SWT
.TOP
, true, false, 3, 1);
82 descTxt
.setLayoutData(gd
);
85 final AbstractFormPart part
= new AbstractFormPart() {
86 public void refresh() {
88 // update display value
89 AkbUiUtils
.refreshFormTextWidget(titleTxt
, getAkbNode(),
91 AkbUiUtils
.refreshFormTextWidget(descTxt
, getAkbNode(),
92 Property
.JCR_DESCRIPTION
);
93 typeCmb
.select(getCurrTypeIndex());
94 typeCmb
.setEnabled(AkbJcrUtils
95 .isNodeCheckedOutByMe(getAkbNode()));
99 AkbUiUtils
.addTextModifyListener(titleTxt
, getAkbNode(),
100 Property
.JCR_TITLE
, part
);
101 AkbUiUtils
.addTextModifyListener(descTxt
, getAkbNode(),
102 Property
.JCR_DESCRIPTION
, part
);
104 typeCmb
.addModifyListener(new ModifyListener() {
106 public void modifyText(ModifyEvent event
) {
108 try { // TODO enhance this
109 // retrieve old and new node type
110 int oldIndex
= getCurrTypeIndex();
111 int selIndex
= typeCmb
.getSelectionIndex();
113 // insure something has really been modified
114 if (selIndex
< 0 || oldIndex
== selIndex
)
117 // remove old mixin, add new and notify form
119 getAkbNode().removeMixin(connectorTypes
[oldIndex
]);
120 getAkbNode().addMixin(connectorTypes
[selIndex
]);
122 } catch (RepositoryException e
) {
123 throw new AkbException(
124 "Error while updating connector type", e
);
128 managedForm
.addPart(part
);
131 private int getCurrTypeIndex() {
134 for (int i
= 0; i
< connectorTypes
.length
; i
++) {
135 if (getAkbNode().isNodeType(connectorTypes
[i
])) {
142 } catch (RepositoryException e
) {
143 throw new AkbException("Error while getting connector type", e
);
148 private void createDefaultTestConnectorCmp(Composite parent
) {
149 String groupTitle
= "Default test instance";
150 parent
.setLayout(new GridLayout());
151 Group group
= new Group(parent
, SWT
.NONE
);
152 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
153 getToolkit().adapt(group
, false, false);
155 group
.setText(groupTitle
);
156 group
.setLayout(AkbUiUtils
.gridLayoutNoBorder());
159 Composite firstLine
= getToolkit().createComposite(group
);
160 firstLine
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
161 firstLine
.setLayout(new GridLayout(3, false));
163 getToolkit().createLabel(firstLine
, "URL");
164 final Text urlTxt
= getToolkit().createText(firstLine
, "", SWT
.BORDER
);
165 urlTxt
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
167 final Button testBtn
= getToolkit().createButton(firstLine
,
168 "Test connection", SWT
.PUSH
);
169 // testBtn.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false,
173 final AbstractFormPart part
= new AbstractFormPart() {
174 public void refresh() {
176 // update display value
177 AkbUiUtils
.refreshFormTextWidget(urlTxt
, getAkbNode(),
178 AkbNames
.AKB_CONNECTOR_URL
);
182 AkbUiUtils
.addTextModifyListener(urlTxt
, getAkbNode(),
183 AkbNames
.AKB_CONNECTOR_URL
, part
);
185 testBtn
.addSelectionListener(new SelectionAdapter() {
187 public void widgetSelected(SelectionEvent e
) {
188 boolean testSuccesfull
= getAkbService().testConnector(
191 String name
= AkbJcrUtils
.get(getAkbNode(), Property
.JCR_TITLE
);
192 String url
= AkbJcrUtils
.get(getAkbNode(),
193 AkbNames
.AKB_CONNECTOR_URL
);
195 String msg
= "to " + name
+ " (" + url
+ ")";
197 MessageDialog
.openInformation(getSite().getShell(),
198 "Test successful", "Successfully connected " + msg
);
200 MessageDialog
.openError(getSite().getShell(),
201 "Test failure", "Unable to connect" + msg
);
205 managedForm
.addPart(part
);
210 protected String
getEditorId() {