+ private void forceRefresh(ExecutionEvent event) {
+ IWorkbenchWindow iww = HandlerUtil.getActiveWorkbenchWindow(event);
+ if (iww == null)
+ return;
+ IWorkbenchPage activePage = iww.getActivePage();
+ IWorkbenchPart part = activePage.getActivePart();
+ if (part instanceof GroupsView)
+ ((GroupsView) part).refresh();
+ }
+
+ private class NewGroupWizard extends Wizard {
+
+ // pages
+ private MainGroupInfoWizardPage mainGroupInfo;
+
+ // End user fields
+ private Text dNameTxt, commonNameTxt, descriptionTxt;
+
+ public NewGroupWizard() {
+ }
+
+ @Override
+ public void addPages() {
+ mainGroupInfo = new MainGroupInfoWizardPage();
+ addPage(mainGroupInfo);
+
+ setWindowTitle("Create a new group");
+ // mainGroupInfo.setMessage(message, WizardPage.WARNING);
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ public boolean performFinish() {
+ if (!canFinish())
+ return false;
+ String commonName = commonNameTxt.getText();
+ try {
+ UiAdminUtils.beginTransactionIfNeeded(userTransaction);
+ Group user = (Group) userAdmin.createRole(getDn(commonName),
+ Role.GROUP);
+ Dictionary props = user.getProperties();
+ String descStr = descriptionTxt.getText();
+ if (UiAdminUtils.notNull(descStr))
+ props.put(UserAdminConstants.KEY_DESC, descStr);
+ return true;
+ } catch (Exception e) {
+ ErrorFeedback.show("Cannot create new group " + commonName, e);
+ return false;
+ }
+ }
+
+ private class MainGroupInfoWizardPage extends WizardPage implements
+ ModifyListener, ArgeoNames {
+ private static final long serialVersionUID = -3150193365151601807L;
+
+ public MainGroupInfoWizardPage() {
+ super("Main");
+ setTitle("General information");
+ setMessage("Please provide a common name and a free description");
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ Composite bodyCmp = new Composite(parent, SWT.NONE);
+ bodyCmp.setLayout(new GridLayout(2, false));
+ dNameTxt = EclipseUiUtils.createGridLT(bodyCmp,
+ "Distinguished name", this);
+ dNameTxt.setEnabled(false);
+ commonNameTxt = EclipseUiUtils.createGridLT(bodyCmp,
+ "Common name", this);
+ commonNameTxt.addModifyListener(new ModifyListener() {
+ private static final long serialVersionUID = -1435351236582736843L;
+
+ @Override
+ public void modifyText(ModifyEvent event) {
+ String name = commonNameTxt.getText();
+ if (name.trim().equals("")) {
+ dNameTxt.setText("");
+ } else {
+ dNameTxt.setText(getDn(name));
+ }
+ }
+ });
+
+ Label descLbl = new Label(bodyCmp, SWT.LEAD);
+ descLbl.setText("Description");
+ descLbl.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false,
+ false));
+ descriptionTxt = new Text(bodyCmp, SWT.LEAD | SWT.MULTI
+ | SWT.WRAP | SWT.BORDER);
+ descriptionTxt.setLayoutData(EclipseUiUtils.fillAll());
+ descriptionTxt.addModifyListener(this);
+
+ setControl(bodyCmp);
+
+ // Initialize buttons
+ setPageComplete(false);
+ getContainer().updateButtons();
+ }
+
+ @Override
+ public void modifyText(ModifyEvent event) {
+ String message = checkComplete();
+ if (message != null) {
+ setMessage(message, WizardPage.ERROR);
+ setPageComplete(false);
+ } else {
+ setMessage("Complete", WizardPage.INFORMATION);
+ setPageComplete(true);
+ }
+ getContainer().updateButtons();
+ }
+
+ /** @return error message or null if complete */
+ protected String checkComplete() {
+ String name = commonNameTxt.getText();
+
+ if (name.trim().equals(""))
+ return "Common name must not be empty";
+ Role role = userAdmin.getRole(getDn(name));
+ if (role != null)
+ return "Group " + name + " already exists";
+ return null;
+ }
+
+ @Override
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ if (visible)
+ commonNameTxt.setFocus();
+ }
+ }
+ }
+