Example usage for org.eclipse.jface.dialogs IDialogConstants NO_LABEL

List of usage examples for org.eclipse.jface.dialogs IDialogConstants NO_LABEL

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs IDialogConstants NO_LABEL.

Prototype

String NO_LABEL

To view the source code for org.eclipse.jface.dialogs IDialogConstants NO_LABEL.

Click Source Link

Document

The label for no buttons.

Usage

From source file:org.apache.directory.studio.apacheds.configuration.editor.ServerConfigurationEditorUtils.java

License:Apache License

/**
 * Performs the "Save as..." action.//from   w  w w . j a v  a  2s. com
 *
 * @param monitor the monitor
 * @param shell the shell
 * @param input the editor input
 * @param configWriter the configuration writer
 * @param newInput a flag to indicate if a new input is required
 * @return the new input for the editor
 * @throws Exception
 */
public static IEditorInput saveAs(IProgressMonitor monitor, Shell shell, IEditorInput input,
        ConfigWriter configWriter, Configuration configuration, boolean newInput) throws Exception {
    // detect IDE or RCP:
    // check if perspective org.eclipse.ui.resourcePerspective is available
    boolean isIDE = CommonUIUtils.isIDEEnvironment();

    if (isIDE) {
        // Asking the user for the location where to 'save as' the file
        SaveAsDialog dialog = new SaveAsDialog(shell);

        String inputClassName = input.getClass().getName();

        if (input instanceof FileEditorInput) {
            // FileEditorInput class is used when the file is opened
            // from a project in the workspace.
            dialog.setOriginalFile(((FileEditorInput) input).getFile());
        } else if (input instanceof IPathEditorInput) {
            dialog.setOriginalFile(
                    ResourcesPlugin.getWorkspace().getRoot().getFile(((IPathEditorInput) input).getPath()));
        } else if (inputClassName.equals("org.eclipse.ui.internal.editors.text.JavaFileEditorInput") //$NON-NLS-1$
                || inputClassName.equals("org.eclipse.ui.ide.FileStoreEditorInput")) //$NON-NLS-1$
        {
            // The class 'org.eclipse.ui.internal.editors.text.JavaFileEditorInput'
            // is used when opening a file from the menu File > Open... in Eclipse 3.2.x
            // The class 'org.eclipse.ui.ide.FileStoreEditorInput' is used when
            // opening a file from the menu File > Open... in Eclipse 3.3.x
            dialog.setOriginalFile(
                    ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(input.getToolTipText())));
        } else {
            dialog.setOriginalName(ApacheDS2ConfigurationPluginConstants.CONFIG_LDIF);
        }

        // Open the dialog
        if (openDialogInUIThread(dialog) != Dialog.OK) {
            return null;
        }

        // Getting if the resulting file
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(dialog.getResult());

        // Creating the file if it does not exist
        if (!file.exists()) {
            file.create(new ByteArrayInputStream("".getBytes()), true, null); //$NON-NLS-1$
        }

        // Creating the new input for the editor
        FileEditorInput fei = new FileEditorInput(file);

        // Saving the file to disk
        File configFile = fei.getPath().toFile();
        saveConfiguration(configFile, configWriter, configuration);

        return fei;
    } else {
        boolean canOverwrite = false;
        String path = null;

        while (!canOverwrite) {
            // Open FileDialog
            path = openFileDialogInUIThread(shell);

            if (path == null) {
                return null;
            }

            // Check whether file exists and if so, confirm overwrite
            final File externalFile = new File(path);

            if (externalFile.exists()) {
                String question = NLS.bind(
                        Messages.getString("ServerConfigurationEditorUtils.TheFileAlreadyExistsWantToReplace"), //$NON-NLS-1$
                        path);
                MessageDialog overwriteDialog = new MessageDialog(shell,
                        Messages.getString("ServerConfigurationEditorUtils.Question"), null, question, //$NON-NLS-1$
                        MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL,
                                IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                        0);
                int overwrite = openDialogInUIThread(overwriteDialog);

                switch (overwrite) {
                case 0: // Yes
                    canOverwrite = true;
                    break;

                case 1: // No
                    break;

                case 2: // Cancel
                default:
                    return null;
                }
            } else {
                canOverwrite = true;
            }
        }

        // Saving the file to disk
        saveConfiguration(new File(path), configWriter, configuration);

        // Checking if a new input is required
        if (newInput) {
            // Creating the new input for the editor
            return new PathEditorInput(new Path(path));
        } else {
            return null;
        }
    }
}

From source file:org.apache.directory.studio.connection.ui.preferences.PasswordsKeystorePreferencePage.java

License:Apache License

/**
 * Disables the passwords keystore.//from   ww  w .  j a v a  2s.c o m
 *
 * @return <code>true</code> if the passwords keystore was successfully disabled,
 *         <code>false</code> if not.
 */
private boolean disablePasswordsKeystore() {
    // Asking the user if he wants to keep its connections passwords
    MessageDialog keepConnectionsPasswordsDialog = new MessageDialog(enableKeystoreCheckbox.getShell(),
            Messages.getString("PasswordsKeystorePreferencePage.KeepConnectionsPasswords"), //$NON-NLS-1$
            null, Messages.getString("PasswordsKeystorePreferencePage.DoYouWantToKeepYourConnectionsPasswords"), //$NON-NLS-1$
            MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0);
    int keepConnectionsPasswordsValue = keepConnectionsPasswordsDialog.open();

    if (keepConnectionsPasswordsValue == 1) {
        // The user chose NOT to keep the connections passwords
        connectionsPasswordsBackup.clear();
        passwordsKeyStoreManager.deleteKeystoreFile();
        return true;
    } else if (keepConnectionsPasswordsValue == 0) {
        // The user chose to keep the connections passwords
        connectionsPasswordsBackup.clear();

        while (true) {
            // We ask the user for the keystore password
            PasswordDialog passwordDialog = new PasswordDialog(enableKeystoreCheckbox.getShell(),
                    Messages.getString("PasswordsKeystorePreferencePage.VerifyMasterPassword"), //$NON-NLS-1$
                    Messages.getString("PasswordsKeystorePreferencePage.PleaseEnterYourMasterPassword"), //$NON-NLS-1$
                    null);

            if (passwordDialog.open() == PasswordDialog.CANCEL) {
                // The user cancelled the action
                return false;
            }

            // Getting the password
            String password = passwordDialog.getPassword();

            // Checking the password
            Exception checkPasswordException = null;
            try {
                if (passwordsKeyStoreManager.checkMasterPassword(password)) {
                    break;
                }
            } catch (KeyStoreException e) {
                checkPasswordException = e;
            }

            // Creating the message
            String message = null;

            if (checkPasswordException == null) {
                message = Messages
                        .getString("PasswordsKeystorePreferencePage.MasterPasswordVerificationFailed"); //$NON-NLS-1$
            } else {
                message = Messages.getString(
                        "PasswordsKeystorePreferencePage.MasterPasswordVerificationFailedWithException") //$NON-NLS-1$
                        + checkPasswordException.getMessage();
            }

            // We ask the user if he wants to retry to unlock the passwords keystore
            MessageDialog errorDialog = new MessageDialog(enableKeystoreCheckbox.getShell(),
                    Messages.getString("PasswordsKeystorePreferencePage.VerifyMasterPasswordFailed"), null, //$NON-NLS-1$
                    message, MessageDialog.ERROR, new String[] { IDialogConstants.RETRY_LABEL, IDialogConstants.CANCEL_LABEL }, 0);

            if (errorDialog.open() == MessageDialog.CANCEL) {
                // The user cancelled the action
                return false;
            }
        }

        // Getting the connection IDs having their passwords saved in the keystore
        String[] connectionIds = passwordsKeyStoreManager.getConnectionIds();

        if (connectionIds != null) {
            // Adding the passwords to the backup map
            for (String connectionId : connectionIds) {
                String password = passwordsKeyStoreManager.getConnectionPassword(connectionId);

                if (password != null) {
                    connectionsPasswordsBackup.put(connectionId, password);
                }
            }
        }

        passwordsKeyStoreManager.deleteKeystoreFile();

        return true;
    } else {
        // The user cancelled the action
        return false;
    }
}

From source file:org.apache.directory.studio.entryeditors.EntryEditorManager.java

License:Apache License

private void askUpdateSharedWorkingCopy(IWorkbenchPartReference partRef, IEntry originalEntry,
        IEntry oscSharedWorkingCopy, Object source) {
    MessageDialog dialog = new MessageDialog(partRef.getPart(false).getSite().getShell(),
            Messages.getString("EntryEditorManager.EntryChanged"), null, Messages //$NON-NLS-1$
                    .getString("EntryEditorManager.EntryChangedDescription"), //$NON-NLS-1$
            MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
    int result = dialog.open();

    if (result == 0) {
        // update reference copy and working copy
        updateOscSharedReferenceCopy(originalEntry);
        updateOscSharedWorkingCopy(originalEntry);

        // inform all OSC editors
        List<IEntryEditor> oscEditors = getOscEditors(oscSharedWorkingCopy);

        for (IEntryEditor oscEditor : oscEditors) {
            oscEditor.workingCopyModified(source);
        }//from w w  w.j  a v  a 2  s . co  m
    }
}

From source file:org.apache.directory.studio.entryeditors.EntryEditorUtils.java

License:Apache License

/**
 * Asks the user if he wants to save the modifications made to the entry before 
 * opening the new input.//from  www.  j  a v a2 s  . co m
 * <p>
 * If the user answers 'Yes', then the entry's modifications are saved.
 * <p>
 * This method returns whether or not the whole operation completed.
 * <p>Based on this return value, <code>true</code> or <code>false</code>, the editor
 * then updates its input or not.
 *
 * @param editor
 *      the editor
 * @return
 *      <code>true</code> if the whole operation completed correctly,
 *      <code>false</code> if not.
 */
public static boolean askSaveSharedWorkingCopyBeforeInputChange(IEntryEditor editor) {
    // Asking for saving the modifications
    MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(),
            Messages.getString("EntryEditorUtils.SaveChanges"), null, Messages //$NON-NLS-1$
                    .getString("EntryEditorUtils.SaveChangesDescription"), //$NON-NLS-1$
            MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
    int result = dialog.open();
    if (result == 0) {
        // Saving the modifications
        EntryEditorInput eei = editor.getEntryEditorInput();
        IStatus status = eei.saveSharedWorkingCopy(true, editor);

        if ((status == null) || !status.isOK()) {
            // If save failed, let's keep the modifications in the editor and return false
            return false;
        }
    }

    return true;
}

From source file:org.apache.directory.studio.ldapbrowser.ui.wizards.BatchOperationWizard.java

License:Apache License

/**
 * {@inheritDoc}/*from  w  w w  . jav a 2  s.  c  o  m*/
 */
public boolean performFinish() {
    if (this.applyOnPage != null) {
        this.applyOnPage.saveDialogSettings();
        this.finishPage.saveDialogSettings();

        // get LDIF
        String ldifFragment = ""; //$NON-NLS-1$
        if (typePage.getOperationType() == BatchOperationTypeWizardPage.OPERATION_TYPE_CREATE_LDIF) {
            ldifFragment = this.ldifPage.getLdifFragment();
        } else if (typePage.getOperationType() == BatchOperationTypeWizardPage.OPERATION_TYPE_MODIFY) {
            ldifFragment = this.modifyPage.getLdifFragment();
        }
        if (typePage.getOperationType() == BatchOperationTypeWizardPage.OPERATION_TYPE_DELETE) {
            ldifFragment = "changetype: delete" + BrowserCoreConstants.LINE_SEPARATOR; //$NON-NLS-1$
        }

        // get DNs
        Dn[] dns = applyOnPage.getApplyOnDns();
        if (dns == null) {
            if (applyOnPage.getApplyOnSearch() != null) {
                ISearch search = applyOnPage.getApplyOnSearch();
                if (search.getBrowserConnection() != null) {
                    search.setSearchResults(null);
                    SearchRunnable runnable = new SearchRunnable(new ISearch[] { search });
                    IStatus status = RunnableContextRunner.execute(runnable, getContainer(), true);
                    if (status.isOK()) {
                        ISearchResult[] srs = search.getSearchResults();
                        dns = new Dn[srs.length];
                        for (int i = 0; i < srs.length; i++) {
                            dns[i] = srs[i].getDn();
                        }
                    }
                }
            }
        }

        if (dns != null) {
            StringBuffer ldif = new StringBuffer();
            for (int i = 0; i < dns.length; i++) {
                ldif.append("dn: "); //$NON-NLS-1$
                ldif.append(dns[i].getName());
                ldif.append(BrowserCoreConstants.LINE_SEPARATOR);
                ldif.append(ldifFragment);
                ldif.append(BrowserCoreConstants.LINE_SEPARATOR);
            }

            if (finishPage
                    .getExecutionMethod() == BatchOperationFinishWizardPage.EXECUTION_METHOD_LDIF_EDITOR) {
                // Opening an LDIF Editor with the LDIF content
                try {
                    IEditorInput input = new NonExistingLdifEditorInput();
                    IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                            .openEditor(input, LdifEditor.getId());
                    IDocumentProvider documentProvider = ((LdifEditor) editor).getDocumentProvider();
                    if (documentProvider != null) {
                        IDocument document = documentProvider.getDocument(input);
                        if (document != null) {
                            document.set(ldif.toString());
                        }
                    }
                } catch (PartInitException e) {
                    return false;
                }

                return true;
            } else if (finishPage
                    .getExecutionMethod() == BatchOperationFinishWizardPage.EXECUTION_METHOD_LDIF_FILE) // TODO
            {
                // Saving the LDIF to a file

                // Getting the shell
                Shell shell = Display.getDefault().getActiveShell();

                // detect IDE or RCP:
                // check if perspective org.eclipse.ui.resourcePerspective is available
                boolean isIDE = CommonUIUtils.isIDEEnvironment();

                if (isIDE) {
                    // Asking the user for the location where to 'save as' the file
                    SaveAsDialog dialog = new SaveAsDialog(shell);

                    if (dialog.open() != Dialog.OK) {
                        return false;
                    }

                    // Getting if the resulting file
                    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(dialog.getResult());

                    try {
                        // Creating the file if it does not exist
                        if (!file.exists()) {
                            file.create(new ByteArrayInputStream("".getBytes()), true, null); //$NON-NLS-1$
                        }

                        // Saving the LDIF to the file in the workspace
                        file.setContents(new ByteArrayInputStream(ldif.toString().getBytes()), true, true,
                                new NullProgressMonitor());
                    } catch (Exception e) {
                        return false;
                    }
                } else {
                    boolean canOverwrite = false;
                    String path = null;

                    while (!canOverwrite) {
                        // Open FileDialog
                        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
                        path = dialog.open();
                        if (path == null) {
                            return false;
                        }

                        // Check whether file exists and if so, confirm overwrite
                        final File externalFile = new File(path);
                        if (externalFile.exists()) {
                            String question = NLS.bind(
                                    Messages.getString("BatchOperationWizard.TheFileAlreadyExistsReplace"), //$NON-NLS-1$
                                    path);
                            MessageDialog overwriteDialog = new MessageDialog(shell,
                                    Messages.getString("BatchOperationWizard.Question"), null, question, //$NON-NLS-1$
                                    MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL,
                                            IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                                    0);
                            int overwrite = overwriteDialog.open();
                            switch (overwrite) {
                            case 0: // Yes
                                canOverwrite = true;
                                break;
                            case 1: // No
                                break;
                            case 2: // Cancel
                            default:
                                return false;
                            }
                        } else {
                            canOverwrite = true;
                        }
                    }

                    // Saving the LDIF to the file on disk
                    try {
                        BufferedWriter outFile = new BufferedWriter(new FileWriter(path));
                        outFile.write(ldif.toString());
                        outFile.close();
                    } catch (Exception e) {
                        return false;
                    }
                }

                return true;
            } else if (finishPage
                    .getExecutionMethod() == BatchOperationFinishWizardPage.EXECUTION_METHOD_LDIF_CLIPBOARD) {
                // Copying the LDIF to the clipboard
                CopyAction.copyToClipboard(new Object[] { ldif.toString() },
                        new Transfer[] { TextTransfer.getInstance() });

                return true;
            } else if (finishPage
                    .getExecutionMethod() == BatchOperationFinishWizardPage.EXECUTION_METHOD_ON_CONNECTION) {
                // Executing the LDIF on the connection
                ExecuteLdifRunnable runnable = new ExecuteLdifRunnable(getConnection(), ldif.toString(), true,
                        finishPage.getContinueOnError());
                StudioBrowserJob job = new StudioBrowserJob(runnable);
                job.execute();

                return true;
            }
        }

        return false;
    }

    return true;
}

From source file:org.apache.directory.studio.ldapservers.actions.CreateConnectionActionHelper.java

License:Apache License

public static void createLdapBrowserConnection(LdapServer server, Connection connection) {
    // Adding the connection to the connection manager
    ConnectionCorePlugin.getDefault().getConnectionManager().addConnection(connection);

    // Adding the connection to the root connection folder
    ConnectionCorePlugin.getDefault().getConnectionFolderManager().getRootConnectionFolder()
            .addConnectionId(connection.getId());

    // Getting the window, LDAP perspective and current perspective
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IPerspectiveDescriptor ldapPerspective = getLdapPerspective();
    IPerspectiveDescriptor currentPerspective = window.getActivePage().getPerspective();

    // Checking if we are already in the LDAP perspective
    if ((ldapPerspective != null) && (ldapPerspective.equals(currentPerspective))) {
        // As we're already in the LDAP perspective, we only indicate to the user 
        // the name of the connection that has been created
        MessageDialog dialog = new MessageDialog(window.getShell(),
                Messages.getString("CreateConnectionActionHelper.ConnectionCreated"), null, //$NON-NLS-1$
                NLS.bind(Messages.getString("CreateConnectionActionHelper.ConnectionCalledCreated"), //$NON-NLS-1$
                        new String[] { connection.getName() }),
                MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, MessageDialog.OK);
        dialog.open();/*from  www  . j a v  a2  s .co  m*/
    } else {
        // We're not already in the LDAP perspective, we indicate to the user
        // the name of the connection that has been created and we ask him
        // if we wants to switch to the LDAP perspective
        MessageDialog dialog = new MessageDialog(window.getShell(),
                Messages.getString("CreateConnectionActionHelper.ConnectionCreated"), null, //$NON-NLS-1$
                NLS.bind(Messages.getString("CreateConnectionActionHelper.ConnectionCalledCreatedSwitch"), //$NON-NLS-1$
                        new String[] { connection.getName() }), MessageDialog.INFORMATION,
                new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, MessageDialog.OK);
        if (dialog.open() == MessageDialog.OK) {
            // Switching to the LDAP perspective
            window.getActivePage().setPerspective(ldapPerspective);
        }
    }
}

From source file:org.apache.directory.studio.ldifeditor.editor.LdifEditor.java

License:Apache License

/**
 * The input could be one of the following types:
 * - NonExistingLdifEditorInput: New file, not yet saved
 * - PathEditorInput: file opened with our internal "Open File.." action
 * - FileEditorInput: file is within workspace
 * - JavaFileEditorInput: file opend with "Open File..." action from org.eclipse.ui.editor
 *
 * In RCP the FileDialog appears.//from   w  w  w  .jav  a  2  s  .  c o  m
 * In IDE the super implementation is called.
 * To detect if this plugin runs in IDE the org.eclipse.ui.ide extension point is checked.
 *
 * @see org.eclipse.ui.editors.text.TextEditor#performSaveAs(org.eclipse.core.runtime.IProgressMonitor)
 */
protected void performSaveAs(IProgressMonitor progressMonitor) {
    // detect IDE or RCP:
    // check if perspective org.eclipse.ui.resourcePerspective is available
    boolean isIDE = CommonUIUtils.isIDEEnvironment();

    if (isIDE) {
        // Just call super implementation for now
        IPreferenceStore store = EditorsUI.getPreferenceStore();
        String key = getEditorSite().getId() + ".internal.delegateSaveAs"; // $NON-NLS-1$ //$NON-NLS-1$
        store.setValue(key, true);
        super.performSaveAs(progressMonitor);
    } else {
        // Open FileDialog
        Shell shell = getSite().getShell();
        final IEditorInput input = getEditorInput();

        IDocumentProvider provider = getDocumentProvider();
        final IEditorInput newInput;

        FileDialog dialog = new FileDialog(shell, SWT.SAVE);

        String path = dialog.open();
        if (path == null) {
            if (progressMonitor != null) {
                progressMonitor.setCanceled(true);
            }
            return;
        }

        // Check whether file exists and if so, confirm overwrite
        final File externalFile = new File(path);
        if (externalFile.exists()) {
            MessageDialog overwriteDialog = new MessageDialog(shell, Messages.getString("LdifEditor.Overwrite"), //$NON-NLS-1$
                    null, Messages.getString("LdifEditor.OverwriteQuestion"), //$NON-NLS-1$
                    MessageDialog.WARNING,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); // 'No' is the default
            if (overwriteDialog.open() != Window.OK) {
                if (progressMonitor != null) {
                    progressMonitor.setCanceled(true);
                    return;
                }
            }
        }

        IPath iPath = new Path(path);
        newInput = new PathEditorInput(iPath);

        boolean success = false;
        try {
            provider.aboutToChange(newInput);
            provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
            success = true;
        } catch (CoreException x) {
            final IStatus status = x.getStatus();
            if (status == null || status.getSeverity() != IStatus.CANCEL) {
                String title = Messages.getString("LdifEditor.ErrorInSaveAs"); //$NON-NLS-1$
                String msg = Messages.getString("LdifEditor.ErrorInSaveAs") + x.getMessage(); //$NON-NLS-1$
                MessageDialog.openError(shell, title, msg);
            }
        } finally {
            provider.changed(newInput);
            if (success) {
                setInput(newInput);
            }
        }

        if (progressMonitor != null) {
            progressMonitor.setCanceled(!success);
        }
    }

}

From source file:org.bonitasoft.studio.actors.tests.organization.OrganizationCreationTest.java

License:Open Source License

/**
 * @author Florine Boudin/* www  .  ja v a  2s . com*/
 * @throws InterruptedException
 */
@Test
public void addNewUsersInACMETest() throws InterruptedException {

    //SWTBotTestUtil.createNewDiagram(bot);
    // open shell "Manage organization"
    bot.menu("Organization").menu("Manage...").click();
    bot.waitUntil(Conditions.shellIsActive(Messages.manageOrganizationTitle));

    SWTBotTable table = bot.table();
    Assert.assertNotNull(table);

    System.out.println("Table size = " + table.columnCount() + " x " + table.rowCount());

    // Set Description of the new Organisation
    int idxBonita = table.indexOf("ACME  (active)", 0);
    Assert.assertTrue("Error: No ACME found in the table", idxBonita != -1);

    // go to the next shell
    table.click(idxBonita, 0);

    for (int i = 0; i < 3; i++) {
        Thread.sleep(1000);
        Assert.assertTrue("Error: The NEXT label button is unavailable",
                bot.button(IDialogConstants.NEXT_LABEL).isEnabled());
        bot.button(IDialogConstants.NEXT_LABEL).click();
    }

    // in the user shell, get table of user list
    table = bot.table();
    Assert.assertNotNull("Error: No user table found", table);

    int nbUsers = table.rowCount();

    //add new user Elton John
    SWTBotButton addButton = bot.button("Add");

    addButton.click();

    Assert.assertEquals("Error : wrong number of added users", nbUsers + 1, table.rowCount());

    bot.textWithLabel(Messages.userName).setText("elton.john");
    bot.textWithLabel(Messages.password).setText("bpm");

    bot.comboBoxWithLabel(Messages.manager).setSelection("william.jobs");
    Assert.assertEquals("Error: Manager is not selected", "william.jobs",
            bot.comboBoxWithLabel(Messages.manager).getText());

    bot.tabItem("General").activate();
    bot.textWithLabel(Messages.firstName).setText("Elton");
    bot.textWithLabel(Messages.lastName).setText("John");

    Assert.assertEquals("Error: First name user is not setted", "Elton",
            bot.textWithLabel(Messages.firstName).getText());
    Assert.assertEquals("Error: Last name user is not setted", "John",
            bot.textWithLabel(Messages.lastName).getText());

    bot.tabItem(Messages.membership).activate();
    bot.button(Messages.addMembership).click();
    bot.comboBoxWithLabel("Group").setSelection("/acme");
    bot.comboBoxWithLabel("Role").setSelection("member");

    // Finish the user add
    bot.waitUntil(Conditions.widgetIsEnabled(bot.button(IDialogConstants.FINISH_LABEL)));
    bot.button(IDialogConstants.FINISH_LABEL).click();
    bot.button(IDialogConstants.NO_LABEL).click();
}

From source file:org.bonitasoft.studio.actors.ui.wizard.ManageOrganizationWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    try {/* w  w w .ja va 2 s. c o  m*/
        getContainer().run(true, false, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Messages.saveOrganization, IProgressMonitor.UNKNOWN);
                for (Organization organization : organizationsWorkingCopy) {
                    monitor.subTask(Messages.validatingOrganizationContent);
                    String errorMessage = isOrganizationValid(organization);
                    if (errorMessage != null) {
                        throw new InterruptedException(organization.getName() + ": " + errorMessage);
                    }
                    String fileName = organization.getName() + "."
                            + OrganizationRepositoryStore.ORGANIZATION_EXT;
                    IRepositoryFileStore file = store.getChild(fileName);
                    Organization oldOrga = null;
                    if (file == null) {
                        file = store.createRepositoryFileStore(fileName);
                    } else {
                        oldOrga = (Organization) file.getContent();
                    }
                    if (oldOrga != null) {
                        RefactorActorMappingsOperation refactorOp = new RefactorActorMappingsOperation(oldOrga,
                                organization);
                        refactorOp.run(monitor);
                    }
                    file.save(organization);
                }
                for (Organization orga : organizations) {
                    boolean exists = false;
                    for (Organization orgCopy : organizationsWorkingCopy) {
                        if (orgCopy.getName().equals(orga.getName())) {
                            exists = true;
                            break;
                        }
                    }
                    if (!exists) {
                        IRepositoryFileStore f = store
                                .getChild(orga.getName() + "." + OrganizationRepositoryStore.ORGANIZATION_EXT);
                        if (f != null) {
                            f.delete();
                        }
                    }
                }
                monitor.done();
            }
        });
    } catch (InterruptedException e) {
        openErrorStatusDialog(e.getMessage());
        return false;
    } catch (InvocationTargetException e) {
        BonitaStudioLog.error(e);
        return false;
    }
    IPreferenceStore preferenceStore = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore();
    String pref = preferenceStore.getString(ActorsPreferenceConstants.TOGGLE_STATE_FOR_PUBLISH_ORGANIZATION);
    boolean publishOrganization = preferenceStore.getBoolean(ActorsPreferenceConstants.PUBLISH_ORGANIZATION);
    if (publishOrganization && MessageDialogWithToggle.ALWAYS.equals(pref)) {
        try {
            publishOrganization(preferenceStore);
        } catch (InvocationTargetException e) {
            BonitaStudioLog.error(e);

        } catch (InterruptedException e) {
            BonitaStudioLog.error(e);
        }
    } else {
        if (MessageDialogWithToggle.NEVER.equals(pref) && activeOrganizationHasBeenModified) {
            String[] buttons = { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL };
            MessageDialogWithToggle mdwt = new MessageDialogWithToggle(Display.getDefault().getActiveShell(),
                    Messages.organizationHasBeenModifiedTitle, null,
                    Messages.bind(Messages.organizationHasBeenModifiedMessage, activeOrganization.getName()),
                    MessageDialog.WARNING, buttons, 0, Messages.doNotDisplayAgain, false);
            mdwt.setPrefStore(preferenceStore);
            mdwt.setPrefKey(ActorsPreferenceConstants.TOGGLE_STATE_FOR_PUBLISH_ORGANIZATION);
            int index = mdwt.open();
            if (index == 2) {
                try {
                    publishOrganization(preferenceStore);
                    if (mdwt.getToggleState()) {
                        preferenceStore.setDefault(ActorsPreferenceConstants.PUBLISH_ORGANIZATION, true);
                    }
                } catch (InvocationTargetException e) {
                    BonitaStudioLog.error(e);

                } catch (InterruptedException e) {
                    BonitaStudioLog.error(e);
                }
            } else {
                if (mdwt.getToggleState()) {
                    preferenceStore.setDefault(ActorsPreferenceConstants.PUBLISH_ORGANIZATION, false);
                    preferenceStore.setDefault(ActorsPreferenceConstants.TOGGLE_STATE_FOR_PUBLISH_ORGANIZATION,
                            MessageDialogWithToggle.ALWAYS);
                }
            }
        }

    }
    return true;
}

From source file:org.bonitasoft.studio.common.jface.MessageDialogWithPrompt.java

License:Open Source License

private static String[] getButtonLabelsFor(int kind) {
    String[] dialogButtonLabels;/*from w w w. j a v  a 2 s.co  m*/
    switch (kind) {
    case ERROR:
    case INFORMATION:
    case WARNING: {
        dialogButtonLabels = new String[] { IDialogConstants.OK_LABEL };
        break;
    }
    case CONFIRM: {
        dialogButtonLabels = new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL };
        break;
    }
    case QUESTION: {
        dialogButtonLabels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL };
        break;
    }
    case QUESTION_WITH_CANCEL: {
        dialogButtonLabels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL };
        break;
    }
    default: {
        throw new IllegalArgumentException("Illegal value for kind in MessageDialog.open()"); //$NON-NLS-1$
    }
    }
    return dialogButtonLabels;
}