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

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

Introduction

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

Prototype

String YES_LABEL

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

Click Source Link

Document

The label for yes buttons.

Usage

From source file:net.sourceforge.appgen.job.GenerateFileJob.java

License:Apache License

private void runInternal(IProgressMonitor monitor) {
    try {//  www . j a  v a 2s. co m
        List<FileGenerator> fileGeneratorList = new ArrayList<FileGenerator>();

        ConnectionInformation connectionInformation = mappingData.getConnectionInformation();
        GenerationInformation generationInformation = mappingData.getGenerationInformation();
        List<Entity> entityList = mappingData.getEntityList();

        fileGeneratorList.add(new PomFileGenerator(generationInformation));
        fileGeneratorList.add(new WebXmlFileGenerator(generationInformation));
        fileGeneratorList.add(new ServletXmlFileGenerator(generationInformation, entityList));
        fileGeneratorList.add(new SqlMapConfigFileGenerator(generationInformation, entityList));
        fileGeneratorList.add(new Log4jDtdFileGenerator(generationInformation));
        fileGeneratorList.add(new Log4jXmlFileGenerator(generationInformation));
        fileGeneratorList.add(new MessagePropertiesFileGenerator(generationInformation));
        fileGeneratorList.add(new MessageKoPropertiesFileGenerator(generationInformation));

        fileGeneratorList.add(new JdbcPropertiesFileGenerator(generationInformation, connectionInformation));
        fileGeneratorList.add(new ResourcePropertiesFileGenerator(generationInformation));

        fileGeneratorList.add(new JdbcDriverFileGenerator(generationInformation, connectionInformation));

        fileGeneratorList.add(new BaseCriteriaFileGenerator(generationInformation));
        fileGeneratorList.add(new BaseServiceFileGenerator(generationInformation));
        fileGeneratorList.add(new PagingFileGenerator(generationInformation));

        fileGeneratorList.add(new UploadSaveDirectoryGenerator(generationInformation));
        fileGeneratorList.add(new AttachFileFileGenerator(generationInformation));
        fileGeneratorList.add(new AttachFilePersisterFileGenerator(generationInformation));
        fileGeneratorList.add(new AttachFilePropertyEditorFileGenerator(generationInformation));
        fileGeneratorList.add(new FilenameGeneratorFileGenerator(generationInformation));
        fileGeneratorList.add(new UUIDFilenameGeneratorFileGenerator(generationInformation));

        fileGeneratorList.add(new DefaultMethodInvocationLoggerFileGenerator(generationInformation));
        fileGeneratorList.add(new MethodInvocationInfoInterceptorFileGenerator(generationInformation));
        fileGeneratorList.add(new MethodInvocationLoggerFileGenerator(generationInformation));
        fileGeneratorList.add(new MethodInvocationLoggingAdviceFileGenerator(generationInformation));

        fileGeneratorList.add(new EntityFileGenerator(generationInformation));
        fileGeneratorList.add(new CriteriaFileGenerator(generationInformation));
        fileGeneratorList.add(new ValidatorFileGenerator(generationInformation));
        fileGeneratorList.add(new DaoInterfaceFileGenerator(generationInformation));
        fileGeneratorList.add(new DaoClassFileGenerator(generationInformation));
        fileGeneratorList.add(new SqlMapFileGenerator(generationInformation));
        fileGeneratorList.add(new ServiceInterfaceFileGenerator(generationInformation));
        fileGeneratorList.add(new ServiceClassFileGenerator(generationInformation));
        fileGeneratorList.add(new ControllerFileGenerator(generationInformation));
        fileGeneratorList.add(new FormControllerFileGenerator(generationInformation));

        fileGeneratorList.add(new StyleFileGenerator(generationInformation));
        fileGeneratorList.add(new TagsFileGenerator(generationInformation));
        fileGeneratorList.add(new DefaultPagingFileGenerator(generationInformation));

        fileGeneratorList.add(new IndexFileGenerator(generationInformation, entityList));
        fileGeneratorList.add(new ListPageFileGenerator(generationInformation));
        fileGeneratorList.add(new DetailPageFileGenerator(generationInformation));
        fileGeneratorList.add(new WritePageFileGenerator(generationInformation));
        fileGeneratorList.add(new EditPageFileGenerator(generationInformation));

        // IProgressMonitor monitor = editor.getEditorSite().getActionBars().getStatusLineManager().getProgressMonitor();

        monitor.beginTask("Generate soure files",
                (entityList != null && entityList.size() > 0) ? entityList.size() * fileGeneratorList.size()
                        : 0);

        if (entityList != null && entityList.size() > 0) {
            boolean overwriteYesToAll = false;
            boolean overwriteNoToAll = false;

            List<File> generatedFileList = new ArrayList<File>();

            // outer:
            for (FileGenerator fileGenerator : fileGeneratorList) {
                fileGenerator.generateDirectory();

                for (Entity entity : entityList) {
                    monitor.subTask(fileGenerator.getFile(entity).getPath());

                    if (entity.isCreate()) {
                        try {
                            if (fileGenerator.existFile(entity)) {
                                if (overwriteNoToAll) {
                                    continue;
                                }

                                if (!overwriteYesToAll) {
                                    boolean overwrite = false;

                                    MessageDialog overwriteDialog = new MessageDialog(
                                            editor.getSite().getShell(), "Question", null,
                                            "The file '" + fileGenerator.getFile(entity)
                                                    + "' already exists. Do you want to replace the existing file?",
                                            MessageDialog.WARNING,
                                            new String[] { IDialogConstants.YES_LABEL,
                                                    IDialogConstants.NO_LABEL,
                                                    IDialogConstants.YES_TO_ALL_LABEL,
                                                    IDialogConstants.NO_TO_ALL_LABEL },
                                            1);

                                    int value = overwriteDialog.open();

                                    switch (value) {
                                    case 0:
                                        overwrite = true;
                                        break;
                                    case 1:
                                        overwrite = false;
                                        break;
                                    case 2:
                                        overwrite = true;
                                        overwriteYesToAll = true;
                                        break;
                                    case 3:
                                        overwrite = false;
                                        overwriteNoToAll = true;
                                        break;
                                    default:
                                        overwriteNoToAll = true;
                                        break;
                                    }

                                    if (!overwrite) {
                                        continue;
                                    }
                                }
                            }

                            entity.setPackageName(generationInformation.getPackageName());

                            File file = fileGenerator.generate(entity);

                            if (file != null) {
                                generatedFileList.add(file);
                            }
                        } catch (Exception e) {
                            MessageDialog.openError(editor.getSite().getShell(), "Error - generate",
                                    e.getMessage());
                        }
                    }

                    monitor.worked(1);
                }
            }

            printGeneratedFileList(generatedFileList);
        }

        RefreshAction refreshAction = new RefreshAction(editor.getEditorSite());
        refreshAction.refreshAll();

        monitor.done();
    } catch (Exception e) {
        MessageDialog.openError(editor.getSite().getShell(), "Generate file error", e.getMessage());
    } finally {
    }
}

From source file:net.sourceforge.sqlexplorer.dbproduct.ConnectionJob.java

License:Open Source License

/**
 * Prompts the user for a new username/password to attempt login with; if the dialog is
 * cancelled then this.user is set to null.
 * @param message/*from  ww  w  . ja va  2  s . c  o m*/
 */
private void promptForPassword(final String message) {
    final Shell shell = SQLExplorerPlugin.getDefault().getSite().getShell();

    // Switch to the UI thread to run the password dialog, but run it synchronously so we
    //   wait for it to complete
    shell.getDisplay().syncExec(new Runnable() {
        public void run() {
            if (message != null) {
                String title = Messages.getString("Progress.Connection.Title") + ' ' + alias.getName();
                if (user != null && !alias.hasNoUserName())
                    title += '/' + user.getUserName();
                if (alias.hasNoUserName()) {
                    MessageDialog dlg = new MessageDialog(shell, title, null,
                            Messages.getString("Progress.Connection.ErrorMessage_Part1") + "\n\n" + message,
                            MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
                    dlg.open();
                    cancelled = true;
                    return;
                } else {
                    MessageDialog dlg = new MessageDialog(shell, title, null,
                            Messages.getString("Progress.Connection.ErrorMessage_Part1") + "\n\n" + message
                                    + "\n\n" + Messages.getString("Progress.Connection.ErrorMessage_Part2"),
                            MessageDialog.ERROR,
                            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
                    boolean retry = dlg.open() == 0;
                    if (!retry) {
                        cancelled = true;
                        return;
                    }
                }
            }

            Shell shell = Display.getCurrent().getActiveShell();
            PasswordConnDlg dlg = new PasswordConnDlg(shell, user.getAlias(), user);
            if (dlg.open() != Window.OK) {
                cancelled = true;
                return;
            }

            // Create a new user and add it to the alias
            User userTmp = new User(dlg.getUserName(), dlg.getPassword());
            userTmp.setAutoCommit(dlg.getAutoCommit());
            userTmp.setCommitOnClose(dlg.getCommitOnClose());
            user = alias.addUser(userTmp);
        }
    });
}

From source file:net.tourbook.database.TourDatabase.java

License:Open Source License

/**
 * this must be implemented or updated when the database version must be updated
 *///  w w  w.  j  a v  a  2s . com
private boolean updateDbDesign(final Connection conn, int currentDbVersion, final IProgressMonitor monitor) {

    /*
     * confirm update
     */

    // define buttons with default to NO
    final String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL };

    if ((new MessageDialog(Display.getDefault().getActiveShell(), Messages.Database_Confirm_update_title, null,
            NLS.bind(Messages.Database_Confirm_update,
                    new Object[] { currentDbVersion, TOURBOOK_DB_VERSION, _databasePath }),
            MessageDialog.QUESTION, buttons, 1).open()) != Window.OK) {

        // no update -> close application
        PlatformUI.getWorkbench().close();

        return false;
    }

    /*
     * do an additional check because version 20 is restructuring the data series
     */
    if (currentDbVersion < 20) {

        if ((new MessageDialog(Display.getDefault().getActiveShell(), Messages.Database_Confirm_update_title,
                null, NLS.bind(Messages.Database_Confirm_Update20, _databasePath), MessageDialog.QUESTION,
                buttons, 1).open()) != Window.OK) {

            // no update -> close application
            PlatformUI.getWorkbench().close();

            return false;
        }
    }

    int newVersion = currentDbVersion;
    final int oldVersion = currentDbVersion;

    /*
     * database update
     */
    try {

        if (currentDbVersion == 1) {
            updateDbDesign_001_002(conn);
            currentDbVersion = newVersion = 2;
        }

        if (currentDbVersion == 2) {
            updateDbDesign_002_003(conn);
            currentDbVersion = newVersion = 3;
        }

        if (currentDbVersion == 3) {
            updateDbDesign_003_004(conn, monitor);
            currentDbVersion = newVersion = 4;
        }

        boolean isPostUpdate5 = false;
        if (currentDbVersion == 4) {
            updateDbDesign_004_005(conn, monitor);
            currentDbVersion = newVersion = 5;
            isPostUpdate5 = true;
        }

        if (currentDbVersion == 5) {
            updateDbDesign_005_006(conn, monitor);
            currentDbVersion = newVersion = 6;
        }

        if (currentDbVersion == 6) {
            updateDbDesign_006_007(conn, monitor);
            currentDbVersion = newVersion = 7;
        }

        if (currentDbVersion == 7) {
            updateDbDesign_007_008(conn, monitor);
            currentDbVersion = newVersion = 8;
        }

        boolean isPostUpdate9 = false;
        if (currentDbVersion == 8) {
            updateDbDesign_008_009(conn, monitor);
            currentDbVersion = newVersion = 9;
            isPostUpdate9 = true;
        }

        if (currentDbVersion == 9) {
            updateDbDesign_009_010(conn, monitor);
            currentDbVersion = newVersion = 10;
        }

        boolean isPostUpdate11 = false;
        if (currentDbVersion == 10) {
            currentDbVersion = newVersion = updateDbDesign_010_011(conn, monitor);
            isPostUpdate11 = true;
        }

        if (currentDbVersion == 11) {
            currentDbVersion = newVersion = updateDbDesign_011_012(conn, monitor);
        }

        boolean isPostUpdate13 = false;
        if (currentDbVersion == 12) {
            currentDbVersion = newVersion = updateDbDesign_012_013(conn, monitor);
            isPostUpdate13 = true;
        }

        if (currentDbVersion == 13) {
            currentDbVersion = newVersion = updateDbDesign_013_014(conn, monitor);
        }

        if (currentDbVersion == 14) {
            currentDbVersion = newVersion = updateDbDesign_014_015(conn, monitor);
        }

        if (currentDbVersion == 15) {
            currentDbVersion = newVersion = updateDbDesign_015_to_016(conn, monitor);
        }

        if (currentDbVersion == 16) {
            currentDbVersion = newVersion = updateDbDesign_016_to_017(conn, monitor);
        }

        if (currentDbVersion == 17) {
            currentDbVersion = newVersion = updateDbDesign_017_to_018(conn, monitor);
        }

        if (currentDbVersion == 18) {
            currentDbVersion = newVersion = updateDbDesign_018_to_019(conn, monitor);
        }

        boolean isPostUpdate20 = false;
        if (currentDbVersion == 19) {
            currentDbVersion = newVersion = updateDbDesign_019_to_020(conn, monitor);
            isPostUpdate20 = true;
        }

        /*
         * 21
         */
        if (currentDbVersion == 20) {
            currentDbVersion = newVersion = updateDbDesign_020_to_021(conn, monitor);
        }

        /*
         * 22
         */
        boolean isPostUpdate22 = false;

        if (currentDbVersion == 21) {
            currentDbVersion = newVersion = updateDbDesign_021_to_022(conn, monitor);
            isPostUpdate22 = true;
        }

        /*
         * 23
         */
        boolean isPostUpdate23 = false;

        if (currentDbVersion == 22) {
            currentDbVersion = newVersion = updateDbDesign_022_to_023(conn, monitor);
            isPostUpdate23 = true;
        }

        /*
         * 24
         */
        if (currentDbVersion == 23) {
            currentDbVersion = newVersion = updateDbDesign_023_to_024(conn, monitor);
        }

        /*
         * 24 -> 25
         */
        boolean isPostUpdate25 = false;

        if (currentDbVersion == 24) {
            isPostUpdate25 = true;
            currentDbVersion = newVersion = updateDbDesign_024_to_025(conn, monitor);
        }

        /*
         * 25 -> 26
         */
        if (currentDbVersion == 25) {
            currentDbVersion = newVersion = updateDbDesign_025_to_026(conn, monitor);
        }

        /*
         * 26 -> 27
         */
        if (currentDbVersion == 26) {
            currentDbVersion = newVersion = updateDbDesign_026_to_027(conn, monitor);
        }

        /*
         * 27 -> 28
         */
        boolean isPostUpdate28 = false;
        if (currentDbVersion == 27) {
            isPostUpdate28 = true;
            currentDbVersion = newVersion = updateDbDesign_027_to_028(conn, monitor);
        }

        /*
         * 28 -> 29
         */
        boolean isPostUpdate29 = false;
        if (currentDbVersion == 28) {
            isPostUpdate29 = true;
            currentDbVersion = newVersion = updateDbDesign_028_to_029(conn, monitor);
        }

        /*
         * 29 -> 30
         */
        if (currentDbVersion == 29) {
            currentDbVersion = newVersion = updateDbDesign_029_to_030(conn, monitor);
        }

        /*
         * 30 -> 31
         */
        if (currentDbVersion == 30) {
            currentDbVersion = newVersion = updateDbDesign_030_to_031(conn, monitor);
        }

        /*
         * 31 -> 32
         */
        boolean isPostUpdate32 = false;
        if (currentDbVersion == 31) {
            isPostUpdate32 = true;
            currentDbVersion = newVersion = updateDbDesign_031_to_032(conn, monitor);
        }

        /*
         * update version number
         */
        updateDbDesign_VersionNumber(conn, newVersion);

        /**
         * Do post update after the version number is updated because the post update uses
         * connections and entitymanager which is checking the version number.
         * <p>
         * Also the data structure must be updated otherwise the entity manager fails because
         * the data structure in the programm code MUST be the same as in the database.
         */
        if (isPostUpdate5) {
            TourDatabase.computeComputedValuesForAllTours(monitor);
            TourManager.getInstance().removeAllToursFromCache();
        }
        if (isPostUpdate9) {
            updateDbDesign_008_009_PostUpdate(conn, monitor);
        }
        if (isPostUpdate11) {
            updateDbDesign_010_011_PostUpdate(conn, monitor);
        }
        if (isPostUpdate13) {
            updateDbDesign_012_013_PostUpdate(conn, monitor);
        }
        if (isPostUpdate20) {
            updateDbDesign_019_to_020_PostUpdate(conn, monitor);
        }
        if (isPostUpdate22) {
            updateDbDesign_021_to_022_PostUpdate(conn, monitor);
        }
        if (isPostUpdate23) {
            updateDbDesign_022_to_023_PostUpdate(conn, monitor);
        }
        if (isPostUpdate25) {
            updateDbDesign_024_to_025_PostUpdate(conn, monitor);
        }
        if (isPostUpdate28) {
            updateDbDesign_027_to_028_PostUpdate(conn, monitor);
        }
        if (isPostUpdate29) {
            updateDbDesign_028_to_029_PostUpdate(conn, monitor);
        }
        if (isPostUpdate32) {
            updateDbDesign_031_to_032_PostUpdate(conn, monitor);
        }

    } catch (final SQLException e) {
        UI.showSQLException(e);
        _isSQLUpdateError = true;
        return false;
    }

    // display info for the successful update
    MessageDialog.openInformation(Display.getCurrent().getActiveShell(),
            Messages.tour_database_version_info_title,
            NLS.bind(Messages.Tour_Database_UpdateInfo, oldVersion, newVersion));

    return true;
}

From source file:net.tourbook.importdata.RawDataManager.java

License:Open Source License

private String importRawData_20_CopyFile(final TourbookDevice device, final String sourceFileName,
        final String destinationPath, final boolean buildNewFileName,
        final FileCollisionBehavior fileCollision) {

    String destFileName = new File(sourceFileName).getName();

    if (buildNewFileName) {

        destFileName = null;//from w  w  w .j a  va  2  s .  c  om

        try {
            destFileName = device.buildFileNameFromRawData(sourceFileName);
        } catch (final Exception e) {
            TourLogManager.logEx(e);
        } finally {

            if (destFileName == null) {

                MessageDialog
                        .openError(Display.getDefault().getActiveShell(),
                                Messages.Import_Data_Error_CreatingFileName_Title,
                                NLS.bind(Messages.Import_Data_Error_CreatingFileName_Message, //
                                        new Object[] { sourceFileName,
                                                new org.eclipse.core.runtime.Path(destinationPath)
                                                        .addTrailingSeparator().toString(),
                                                TEMP_IMPORTED_FILE }));

                destFileName = TEMP_IMPORTED_FILE;
            }
        }
    }
    final File newFile = new File(
            (new org.eclipse.core.runtime.Path(destinationPath).addTrailingSeparator().toString()
                    + destFileName));

    // get source file
    final File fileIn = new File(sourceFileName);

    // check if file already exist
    if (newFile.exists()) {
        // TODO allow user to rename the file

        boolean keepFile = false; // for MessageDialog result
        if (fileCollision.value == FileCollisionBehavior.ASK) {

            final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
            final MessageDialog messageDialog = new MessageDialog(shell, Messages.Import_Wizard_Message_Title,
                    null, NLS.bind(Messages.Import_Wizard_Message_replace_existing_file, newFile),
                    MessageDialog.QUESTION,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                            IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL },
                    0);
            messageDialog.open();
            final int returnCode = messageDialog.getReturnCode();
            switch (returnCode) {

            case 1: // YES_TO_ALL
                fileCollision.value = FileCollisionBehavior.REPLACE;
                break;

            case 3: // NO_TO_ALL
                fileCollision.value = FileCollisionBehavior.KEEP;
            case 2: // NO
                keepFile = true;
                break;

            default:
                break;
            }
        }

        if (fileCollision.value == FileCollisionBehavior.KEEP || keepFile) {
            _isImportCanceled = true;
            fileIn.delete();
            return null;
        }
    }

    // copy source file into destination file
    FileInputStream inReader = null;
    FileOutputStream outReader = null;
    try {
        inReader = new FileInputStream(fileIn);
        outReader = new FileOutputStream(newFile);
        int c;

        while ((c = inReader.read()) != -1) {
            outReader.write(c);
        }

        inReader.close();
        outReader.close();

    } catch (final FileNotFoundException e) {
        TourLogManager.logEx(e);
        return null;
    } catch (final IOException e) {
        TourLogManager.logEx(e);
        return null;
    } finally {
        // close the files
        if (inReader != null) {
            try {
                inReader.close();
            } catch (final IOException e) {
                TourLogManager.logEx(e);
                return null;
            }
        }
        if (outReader != null) {
            try {
                outReader.close();
            } catch (final IOException e) {
                TourLogManager.logEx(e);
                return null;
            }
        }
    }

    // delete source file
    fileIn.delete();

    return newFile.getAbsolutePath();
}

From source file:net.tourbook.preferences.PrefPageTags.java

License:Open Source License

private void onReset() {

    final MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(),
            Messages.pref_tourtag_dlg_reset_title, null, Messages.pref_tourtag_dlg_reset_message,
            MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1);

    if (dialog.open() != Window.OK) {
        setFocusToViewer();/*from   w w w.  j  a  v a2s  .c  o  m*/
        return;
    }

    try {

        System.out.println("RESET TAG STRUCTURE"); //$NON-NLS-1$

        final StringBuilder sb = new StringBuilder();
        final Connection conn = TourDatabase.getInstance().getConnection();

        /*
         * remove join table tag->category
         */
        sb.append("DELETE FROM "); //$NON-NLS-1$
        sb.append(TourDatabase.JOINTABLE__TOURTAGCATEGORY_TOURTAG);
        int result = conn.createStatement().executeUpdate(sb.toString());
        System.out.println("Deleted " //$NON-NLS-1$
                + result + " entries from " //$NON-NLS-1$
                + TourDatabase.JOINTABLE__TOURTAGCATEGORY_TOURTAG);

        /*
         * remove jointable category<->category
         */
        sb.setLength(0);
        sb.append("DELETE FROM "); //$NON-NLS-1$
        sb.append(TourDatabase.JOINTABLE__TOURTAGCATEGORY_TOURTAGCATEGORY);
        result = conn.createStatement().executeUpdate(sb.toString());
        System.out.println("Deleted " //$NON-NLS-1$
                + result + " entries from " //$NON-NLS-1$
                + TourDatabase.JOINTABLE__TOURTAGCATEGORY_TOURTAGCATEGORY);

        /*
         * set tags to root
         */
        sb.setLength(0);
        sb.append("UPDATE "); //$NON-NLS-1$
        sb.append(TourDatabase.TABLE_TOUR_TAG);
        sb.append(" SET isRoot=1"); //$NON-NLS-1$
        result = conn.createStatement().executeUpdate(sb.toString());
        System.out.println("Set " + result + " tour tags to root"); //$NON-NLS-1$ //$NON-NLS-2$

        /*
         * set categories to root
         */
        sb.setLength(0);
        sb.append("UPDATE "); //$NON-NLS-1$
        sb.append(TourDatabase.TABLE_TOUR_TAG_CATEGORY);
        sb.append(" SET isRoot=1"); //$NON-NLS-1$
        result = conn.createStatement().executeUpdate(sb.toString());
        System.out.println("Set " + result + " tour categories to root"); //$NON-NLS-1$ //$NON-NLS-2$

        conn.close();

        // update the tag viewer
        _rootItem = new TVIPrefTagRoot(_tagViewer);
        updateTagViewer();

        _isModified = true;

    } catch (final SQLException e) {
        UI.showSQLException(e);
    }

    setFocusToViewer();
}

From source file:net.tourbook.ui.UI.java

License:Open Source License

/**
 * @param file/*from w  ww. ja  v  a2 s. com*/
 * @return Returns <code>true</code> when the file should be overwritten, otherwise
 *         <code>false</code>
 */
public static boolean confirmOverwrite(final File file) {

    final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

    final MessageDialog dialog = new MessageDialog(//
            shell, Messages.app_dlg_confirmFileOverwrite_title, null,
            NLS.bind(Messages.app_dlg_confirmFileOverwrite_message, file.getPath()), MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.CANCEL_LABEL }, 0);

    dialog.open();

    return dialog.getReturnCode() == 0;
}

From source file:net.tourbook.ui.UI.java

License:Open Source License

public static boolean confirmOverwrite(final FileCollisionBehavior fileCollision, final File file) {

    final boolean[] isOverwrite = { false };

    final int fileCollisionValue = fileCollision.value;

    if (fileCollisionValue == FileCollisionBehavior.REPLACE_ALL) {

        // overwrite is already confirmed
        isOverwrite[0] = true;//w  ww.  j  a v  a  2s .com

    } else if (fileCollisionValue == FileCollisionBehavior.ASK
            || fileCollisionValue == FileCollisionBehavior.REPLACE
            || fileCollisionValue == FileCollisionBehavior.KEEP) {

        Display.getDefault().syncExec(new Runnable() {
            @Override
            public void run() {

                final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                final MessageDialog dialog = new MessageDialog(//
                        shell, Messages.app_dlg_confirmFileOverwrite_title, null,
                        NLS.bind(Messages.app_dlg_confirmFileOverwrite_message, file.getPath()),
                        MessageDialog.QUESTION,
                        new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                                IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                                IDialogConstants.CANCEL_LABEL },
                        0);
                dialog.open();

                final int returnCode = dialog.getReturnCode();
                switch (returnCode) {

                case -1: // dialog was canceled
                case 4:
                    fileCollision.value = FileCollisionBehavior.DIALOG_IS_CANCELED;
                    break;

                case 0: // YES
                    fileCollision.value = FileCollisionBehavior.REPLACE;
                    isOverwrite[0] = true;
                    break;

                case 1: // YES_TO_ALL
                    fileCollision.value = FileCollisionBehavior.REPLACE_ALL;
                    isOverwrite[0] = true;
                    break;

                case 2: // NO
                    fileCollision.value = FileCollisionBehavior.KEEP;
                    break;

                case 3: // NO_TO_ALL
                    fileCollision.value = FileCollisionBehavior.KEEP_ALL;
                    break;

                default:
                    break;
                }
            }
        });

    }

    return isOverwrite[0];
}

From source file:net.tourbook.ui.views.tourDataEditor.TourDataEditorView.java

License:Open Source License

/**
 * @return Returns <code>true</code> when the tour should be discarded<br>
 *         returns <code>false</code> when the tour is invalid but should be saved<br>
 *///from   w w  w .  j  ava 2  s .  co  m
private boolean isDiscardTour() {

    final MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(),
            Messages.tour_editor_dlg_save_tour_title, null,
            NLS.bind(Messages.tour_editor_dlg_save_invalid_tour, TourManager.getTourDateFull(_tourData)),
            MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1);

    final int result = dialog.open();
    if (result == 0) {

        // discard modifications

        return true;

    } else {

        // save modifications

        return false;
    }
}

From source file:net.tourbook.ui.views.tourDataEditor.TourDataEditorView.java

License:Open Source License

/**
 * @param isConfirmSave/*w ww . jav  a  2 s .co  m*/
 * @return Returns <code>true</code> when the tour was saved, <code>false</code> when the tour
 *         is not saved but canceled
 */
private boolean saveTourConfirmation() {

    if (_isTourDirty == false) {
        return true;
    }

    // show the tour data editor
    try {
        getSite().getPage().showView(ID, null, IWorkbenchPage.VIEW_VISIBLE);
    } catch (final PartInitException e) {
        e.printStackTrace();
    }

    // confirm save/discard/cancel
    final int returnCode = new MessageDialog(Display.getCurrent().getActiveShell(),
            Messages.tour_editor_dlg_save_tour_title, null,
            NLS.bind(Messages.tour_editor_dlg_save_tour_message, TourManager.getTourDateFull(_tourData)),
            MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0)//
                    .open();

    if (returnCode == 0) {

        // button YES: save tour

        saveTourIntoDB();

        return true;

    } else if (returnCode == 1) {

        // button NO: discard modifications

        discardModifications();

        return true;

    } else {

        // button CANCEL / dialog is canceled: tour is not saved and not discarded

        return false;
    }
}

From source file:net.yatomiya.e4.ui.dialogs.TextMessageDialog.java

License:Open Source License

static String[] getButtonLabels(Type type) {
    String[] dialogButtonLabels;//from  www  . j  a v  a2s . c  o m
    switch (type) {
    case NONE:
    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 NMessageDialog.open()"); //$NON-NLS-1$
    }
    }
    return dialogButtonLabels;
}