1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.console.wizards.resources;
20
21 import java.util.List;
22 import org.apache.commons.lang3.tuple.Pair;
23 import org.apache.syncope.client.console.SyncopeConsoleSession;
24 import org.apache.syncope.client.console.pages.BasePage;
25 import org.apache.syncope.client.console.wicket.markup.html.list.ConnConfPropertyListView;
26 import org.apache.syncope.client.ui.commons.Constants;
27 import org.apache.syncope.common.lib.to.EntityTO;
28 import org.apache.syncope.common.lib.types.ConnConfProperty;
29 import org.apache.wicket.ajax.AjaxRequestTarget;
30 import org.apache.wicket.ajax.markup.html.form.AjaxButton;
31 import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxButton;
32 import org.apache.wicket.extensions.wizard.WizardModel.ICondition;
33 import org.apache.wicket.extensions.wizard.WizardStep;
34 import org.apache.wicket.markup.html.WebMarkupContainer;
35 import org.apache.wicket.model.IModel;
36 import org.apache.wicket.model.LoadableDetachableModel;
37 import org.apache.wicket.model.ResourceModel;
38
39 public abstract class AbstractConnConfPanel<T extends EntityTO> extends WizardStep implements ICondition {
40
41 private static final long serialVersionUID = -2025535531121434050L;
42
43 protected LoadableDetachableModel<List<ConnConfProperty>> model;
44
45 protected final WebMarkupContainer propertiesContainer;
46
47 protected final AjaxButton check;
48
49 protected final T modelObject;
50
51 public AbstractConnConfPanel(final T model) {
52 super();
53 this.modelObject = model;
54 setOutputMarkupId(true);
55
56 propertiesContainer = new WebMarkupContainer("connectorPropertiesContainer");
57 propertiesContainer.setOutputMarkupId(true);
58 add(propertiesContainer);
59
60 check = new IndicatingAjaxButton("check", new ResourceModel("check")) {
61
62 private static final long serialVersionUID = -7978723352517770644L;
63
64 @Override
65 public void onSubmit(final AjaxRequestTarget target) {
66 final Pair<Boolean, String> result = check(target);
67 if (result.getLeft()) {
68 SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
69 } else {
70 SyncopeConsoleSession.get().error(getString("error_connection") + ": " + result.getRight());
71 }
72 ((BasePage) getPage()).getNotificationPanel().refresh(target);
73 }
74 };
75 propertiesContainer.add(check);
76 }
77
78 protected void setConfPropertyListView(final IModel<List<ConnConfProperty>> model, final boolean withOverridable) {
79 propertiesContainer.addOrReplace(new ConnConfPropertyListView(
80 "connectorProperties", model, withOverridable).setOutputMarkupId(true));
81 }
82
83 protected abstract Pair<Boolean, String> check(AjaxRequestTarget taget);
84
85 protected abstract List<ConnConfProperty> getConnProperties(T instance);
86
87 @Override
88 public boolean evaluate() {
89 return model != null && model.getObject() != null && !model.getObject().isEmpty();
90 }
91 }