/**
* Copyright 2009 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.safehaus.penrose.studio.ldap.connection.editor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.window.Window;
import org.safehaus.penrose.studio.connection.editor.ConnectionEditorPage;
import org.safehaus.penrose.studio.ldap.connection.wizard.LDAPConnectionSettingsWizard;
import org.safehaus.penrose.studio.dialog.ErrorDialog;
import javax.naming.Context;
import javax.naming.InitialContext;
/**
* @author Endi S. Dewata
*/
public class LDAPConnectionPropertiesPage extends ConnectionEditorPage {
Label adapterText;
Label urlText;
Label bindDnText;
Label passwordText;
String url;
public LDAPConnectionPropertiesPage(LDAPConnectionEditor editor) {
super(editor, "LDAP", "LDAP");
}
public void createFormContent(IManagedForm managedForm) {
super.createFormContent(managedForm);
ScrolledForm form = managedForm.getForm();
Composite body = form.getBody();
body.setLayout(new GridLayout());
Section ldapSection = toolkit.createSection(body, Section.TITLE_BAR | Section.EXPANDED);
ldapSection.setText("LDAP");
ldapSection.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Control ldapControl = createLDAPControl(ldapSection);
ldapSection.setClient(ldapControl);
refresh();
}
public Composite createLDAPControl(final Composite parent) {
Composite composite = toolkit.createComposite(parent);
composite.setLayout(new GridLayout(2, false));
Composite leftControl = createLDAPLeftControl(composite);
leftControl.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite rightControl = createLDAPRightControl(composite);
GridData gd = new GridData(GridData.FILL_VERTICAL);
gd.widthHint = 100;
rightControl.setLayoutData(gd);
return composite;
}
public Composite createLDAPLeftControl(final Composite parent) {
Composite composite = toolkit.createComposite(parent);
GridLayout layout = new GridLayout(2, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
composite.setLayout(layout);
toolkit.createLabel(composite, "Adapter:");
adapterText = toolkit.createLabel(composite, "", SWT.READ_ONLY);
adapterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
toolkit.createLabel(composite, "URL:");
urlText = toolkit.createLabel(composite, "", SWT.NONE);
urlText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
toolkit.createLabel(composite, "Principal:");
bindDnText = toolkit.createLabel(composite, "", SWT.NONE);
bindDnText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
toolkit.createLabel(composite, "Credentials:");
passwordText = toolkit.createLabel(composite, "", SWT.PASSWORD);
passwordText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
return composite;
}
public Composite createLDAPRightControl(final Composite parent) {
Composite composite = toolkit.createComposite(parent);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
composite.setLayout(layout);
Button editButton = new Button(composite, SWT.PUSH);
editButton.setText("Edit");
editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
editButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
try {
LDAPConnectionSettingsWizard wizard = new LDAPConnectionSettingsWizard();
wizard.setServer(server);
wizard.setPartitionName(partitionName);
wizard.setConnectionConfig(connectionConfig);
WizardDialog dialog = new WizardDialog(editor.getSite().getShell(), wizard);
dialog.setPageSize(600, 300);
int rc = dialog.open();
if (rc == Window.CANCEL) return;
editor.store();
refresh();
} catch (Exception e) {
log.error(e.getMessage(), e);
ErrorDialog.open(e);
}
}
});
return composite;
}
public void refresh() {
String adapter = connectionConfig.getAdapterName();
adapterText.setText(adapter == null ? "" : adapter);
String url = connectionConfig.getParameter(InitialContext.PROVIDER_URL);
//String[] s = LDAPClient.parseURL(url);
urlText.setText(url == null ? "" : url);
//hostText.setText(s[1] == null ? "" : s[1]);
//portText.setText(s[2] == null ? "" : s[2]);
String bindDn = connectionConfig.getParameter(Context.SECURITY_PRINCIPAL);
bindDnText.setText(bindDn == null ? "" : bindDn);
passwordText.setText("*****");
}
public void checkDirty() {
}
}