]>
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
.eclipse
.ui
.ErrorFeedback
;
7 import org
.argeo
.slc
.akb
.AkbException
;
8 import org
.argeo
.slc
.akb
.AkbNames
;
9 import org
.argeo
.slc
.akb
.AkbTypes
;
10 import org
.argeo
.slc
.akb
.ui
.AkbUiPlugin
;
11 import org
.argeo
.slc
.akb
.ui
.AkbUiUtils
;
12 import org
.argeo
.slc
.akb
.utils
.AkbJcrUtils
;
13 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.events
.ModifyEvent
;
16 import org
.eclipse
.swt
.events
.ModifyListener
;
17 import org
.eclipse
.swt
.events
.SelectionAdapter
;
18 import org
.eclipse
.swt
.events
.SelectionEvent
;
19 import org
.eclipse
.swt
.layout
.GridData
;
20 import org
.eclipse
.swt
.layout
.GridLayout
;
21 import org
.eclipse
.swt
.widgets
.Button
;
22 import org
.eclipse
.swt
.widgets
.Combo
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Group
;
25 import org
.eclipse
.swt
.widgets
.Text
;
26 import org
.eclipse
.ui
.forms
.AbstractFormPart
;
27 import org
.eclipse
.ui
.forms
.IManagedForm
;
30 * Display and edit a connector Alias
32 public class ConnectorAliasEditor
extends AbstractAkbNodeEditor
{
33 // private final static Log log = LogFactory
34 // .getLog(AkbConnectorAliasEditor.class);
36 public final static String ID
= AkbUiPlugin
.PLUGIN_ID
37 + ".connectorAliasEditor";
39 private String
[] connectorTypesLbl
= new String
[] { "JDBC", "SSH", "JCR" };
40 private String
[] connectorTypes
= new String
[] {
41 AkbTypes
.AKB_JDBC_CONNECTOR
, AkbTypes
.AKB_SSH_CONNECTOR
,
42 AkbTypes
.AKB_JCR_CONNECTOR
};
44 private IManagedForm managedForm
;
46 /* CONTENT CREATION */
48 public void populateMainPage(Composite parent
, IManagedForm managedForm
) {
49 parent
.setLayout(AkbUiUtils
.gridLayoutNoBorder());
50 this.managedForm
= managedForm
;
52 // First line main info
53 Composite firstLine
= getToolkit()
54 .createComposite(parent
, SWT
.NO_FOCUS
);
55 firstLine
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
56 createConnectorAliasInfoCmp(firstLine
);
58 // Second line define defaut connector and test abilities
59 Composite secondLine
= getToolkit().createComposite(parent
,
61 secondLine
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
62 createDefaultTestConnectorCmp(secondLine
);
66 private void createConnectorAliasInfoCmp(Composite parent
) {
67 parent
.setLayout(new GridLayout(4, false));
69 // first line: connector type and name
70 getToolkit().createLabel(parent
, "Connector Type");
71 final Combo typeCmb
= new Combo(parent
, SWT
.READ_ONLY
);
72 typeCmb
.setItems(connectorTypesLbl
);
74 getToolkit().createLabel(parent
, "Name");
75 final Text titleTxt
= getToolkit().createText(parent
, "", SWT
.BORDER
);
76 GridData gd
= new GridData(SWT
.FILL
, SWT
.TOP
, true, false);
77 titleTxt
.setLayoutData(gd
);
79 // 2nd line: description
80 getToolkit().createLabel(parent
, "Short Description");
81 final Text descTxt
= getToolkit().createText(parent
, "", SWT
.BORDER
);
82 gd
= new GridData(SWT
.FILL
, SWT
.TOP
, true, false, 3, 1);
83 descTxt
.setLayoutData(gd
);
86 final AbstractFormPart part
= new AbstractFormPart() {
87 public void refresh() {
89 // update display value
90 AkbUiUtils
.refreshFormTextWidget(titleTxt
, getAkbNode(),
92 AkbUiUtils
.refreshFormTextWidget(descTxt
, getAkbNode(),
93 Property
.JCR_DESCRIPTION
);
94 typeCmb
.select(getCurrTypeIndex());
95 typeCmb
.setEnabled(AkbJcrUtils
96 .isNodeCheckedOutByMe(getAkbNode()));
100 AkbUiUtils
.addTextModifyListener(titleTxt
, getAkbNode(),
101 Property
.JCR_TITLE
, part
);
102 AkbUiUtils
.addTextModifyListener(descTxt
, getAkbNode(),
103 Property
.JCR_DESCRIPTION
, part
);
105 typeCmb
.addModifyListener(new ModifyListener() {
107 public void modifyText(ModifyEvent event
) {
109 try { // TODO enhance this
110 // retrieve old and new node type
111 int oldIndex
= getCurrTypeIndex();
112 int selIndex
= typeCmb
.getSelectionIndex();
114 // insure something has really been modified
115 if (selIndex
< 0 || oldIndex
== selIndex
)
118 // remove old mixin, add new and notify form
120 getAkbNode().removeMixin(connectorTypes
[oldIndex
]);
121 getAkbNode().addMixin(connectorTypes
[selIndex
]);
123 } catch (RepositoryException e
) {
124 throw new AkbException(
125 "Error while updating connector type", e
);
129 managedForm
.addPart(part
);
132 private int getCurrTypeIndex() {
135 for (int i
= 0; i
< connectorTypes
.length
; i
++) {
136 if (getAkbNode().isNodeType(connectorTypes
[i
])) {
143 } catch (RepositoryException e
) {
144 throw new AkbException("Error while getting connector type", e
);
149 private void createDefaultTestConnectorCmp(Composite parent
) {
150 String groupTitle
= "Default test instance";
151 parent
.setLayout(new GridLayout());
152 Group group
= new Group(parent
, SWT
.NONE
);
153 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
154 getToolkit().adapt(group
, false, false);
156 group
.setText(groupTitle
);
157 group
.setLayout(AkbUiUtils
.gridLayoutNoBorder());
160 Composite firstLine
= getToolkit().createComposite(group
);
161 firstLine
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
162 firstLine
.setLayout(new GridLayout(2, false));
164 getToolkit().createLabel(firstLine
, "URL");
165 final Text urlTxt
= getToolkit().createText(firstLine
, "", SWT
.BORDER
);
166 urlTxt
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
168 getToolkit().createLabel(firstLine
, "User");
169 final Text userTxt
= getToolkit().createText(firstLine
, "", SWT
.BORDER
);
170 userTxt
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, false));
172 final Button testBtn
= getToolkit().createButton(firstLine
,
173 "Test connection", SWT
.PUSH
);
174 // testBtn.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false,
178 final AbstractFormPart part
= new AbstractFormPart() {
179 public void refresh() {
181 // update display value
182 AkbUiUtils
.refreshFormTextWidget(urlTxt
, getAkbNode(),
183 AkbNames
.AKB_CONNECTOR_URL
);
184 AkbUiUtils
.refreshFormTextWidget(userTxt
, getAkbNode(),
185 AkbNames
.AKB_CONNECTOR_USER
);
189 AkbUiUtils
.addTextModifyListener(urlTxt
, getAkbNode(),
190 AkbNames
.AKB_CONNECTOR_URL
, part
);
191 AkbUiUtils
.addTextModifyListener(userTxt
, getAkbNode(),
192 AkbNames
.AKB_CONNECTOR_USER
, part
);
194 testBtn
.addSelectionListener(new SelectionAdapter() {
196 public void widgetSelected(SelectionEvent e
) {
197 boolean testSuccesfull
;
199 testSuccesfull
= getAkbService()
200 .testConnector(getAkbNode());
201 } catch (Exception e1
) {
202 testSuccesfull
= false;
203 ErrorFeedback
.show("Cannot test connection", e1
);
206 String name
= AkbJcrUtils
.get(getAkbNode(), Property
.JCR_TITLE
);
207 String url
= AkbJcrUtils
.get(getAkbNode(),
208 AkbNames
.AKB_CONNECTOR_URL
);
210 String msg
= "to " + name
+ " (" + url
+ ")";
212 MessageDialog
.openInformation(getSite().getShell(),
213 "Test successful", "Successfully connected " + msg
);
215 MessageDialog
.openError(getSite().getShell(),
216 "Test failure", "Unable to connect" + msg
);
220 managedForm
.addPart(part
);
225 protected String
getEditorId() {