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

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

Introduction

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

Prototype

int YES_TO_ALL_ID

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

Click Source Link

Document

Button id for a "Yes to All" button (value 4).

Usage

From source file:ch.elexis.core.ui.importer.div.importers.dialog.QueryOverwriteDialog.java

License:Open Source License

/**
 * Create contents of the button bar./*ww w  . j a v  a  2 s . c o  m*/
 * 
 * @param parent
 */
@Override
protected void createButtonsForButtonBar(Composite parent) {
    Button buttonNo = createButton(parent, IDialogConstants.NO_ID, IDialogConstants.OK_LABEL, true);
    buttonNo.setText(Messages.QueryOverwriteDialog_NO);
    Button buttonYesToAll = createButton(parent, IDialogConstants.YES_TO_ALL_ID, IDialogConstants.CANCEL_LABEL,
            false);
    buttonYesToAll.setText(Messages.QueryOverwriteDialog_YESTOALL);
    Button buttonYes = createButton(parent, IDialogConstants.YES_ID, IDialogConstants.CANCEL_LABEL, false);
    buttonYes.setText(Messages.QueryOverwriteDialog_YES);
}

From source file:com.amalto.workbench.export.ImportItemsWizard.java

License:Open Source License

private int isOveride(String name, String obTypeName) {

    final MessageDialog dialog = new MessageDialog(getShell(), Messages.ImportItemsWizard_12, null,
            Messages.ImportItemsWizard_13 + obTypeName + Messages.ImportItemsWizard_14 + name
                    + Messages.ImportItemsWizard_15,
            MessageDialog.QUESTION,//from w ww  .  j a  v a 2 s.  com
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
            0);
    dialog.open();
    int result = dialog.getReturnCode();
    if (result == 0) {
        return IDialogConstants.YES_ID;
    }
    if (result == 1) {
        return IDialogConstants.YES_TO_ALL_ID;
    }
    if (result == 2) {
        return IDialogConstants.NO_ID;
    }
    return IDialogConstants.CANCEL_ID;

}

From source file:com.motorola.studio.android.common.utilities.EclipseUtils.java

License:Apache License

/**
 * Show a question message using the given title and message
 * // ww w. ja  v a2 s.  c  o  m
 * @param title
 *            of the dialog
 * @param message
 *            to be displayed in the dialog.
 */
public static int showQuestionYesAllCancelDialog(final String title, final String message) {
    class IntWrapper {
        public int diagReturn = 0;
    }

    final IntWrapper intWrapper = new IntWrapper();
    Display.getDefault().syncExec(new Runnable() {

        public void run() {
            IWorkbench workbench = PlatformUI.getWorkbench();
            IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow();
            Shell shell = ww.getShell();
            MessageDialog dialog = new MessageDialog(shell, title, null, message, MessageDialog.QUESTION,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                            IDialogConstants.NO_LABEL },
                    0);
            int diagResults = dialog.open();
            switch (diagResults) {
            case 0:
                intWrapper.diagReturn = IDialogConstants.YES_ID;
                break;
            case 1:
                intWrapper.diagReturn = IDialogConstants.YES_TO_ALL_ID;
                break;
            case 2:
            default:
                intWrapper.diagReturn = IDialogConstants.NO_ID;
                break;
            }
        }
    });

    return intWrapper.diagReturn;
}

From source file:com.motorola.studio.android.common.utilities.FileUtil.java

License:Apache License

public static boolean extractZipArchive(File file, File destination, List<String> selectedEntries,
        IProgressMonitor monitor) throws IOException {
    SubMonitor subMonitor = SubMonitor.convert(monitor);
    ZipFile zipFile = null;//  w  w  w.  j a  va  2 s.c om
    CRC32 crc = new CRC32();
    byte[] buf = new byte[BUFFER_SIZE];

    File extractDestination = destination != null ? destination : file.getParentFile();

    if (!extractDestination.exists()) {
        extractDestination.mkdirs();
    }

    boolean unziped = true;
    try {
        zipFile = new ZipFile(file);
    } catch (Throwable e) {
        unziped = false;
        StudioLogger.error(FileUtil.class, "Error extracting file: " + file.getAbsolutePath() //$NON-NLS-1$
                + " to " + extractDestination, e); //$NON-NLS-1$

    }
    if (zipFile != null) {
        Enumeration<? extends ZipEntry> entries = zipFile.entries();

        subMonitor.beginTask("Extracting files", Collections.list(entries).size()); //$NON-NLS-1$
        entries = zipFile.entries();
        InputStream input = null;
        FileOutputStream output = null;
        int diagReturn = IDialogConstants.YES_ID;
        while (entries.hasMoreElements()) {
            crc.reset();
            try {
                ZipEntry entry = entries.nextElement();
                if (selectedEntries.contains(entry.getName())) {
                    File newFile = new File(extractDestination, entry.getName());
                    if ((diagReturn != IDialogConstants.YES_TO_ALL_ID) && newFile.exists()) {
                        diagReturn = EclipseUtils.showQuestionYesAllCancelDialog(
                                UtilitiesNLS.FileUtil_File_Exists_Title,
                                NLS.bind(UtilitiesNLS.FileUtil_File_Exists_Message, newFile.getAbsolutePath()));
                    }

                    if ((diagReturn == IDialogConstants.YES_ID)
                            || (diagReturn == IDialogConstants.YES_TO_ALL_ID)) {
                        newFile.delete();
                        if (entry.isDirectory()) {
                            newFile.mkdirs();
                        } else {
                            newFile.getParentFile().mkdirs();
                            if (newFile.createNewFile()) {
                                input = zipFile.getInputStream(entry);
                                output = new FileOutputStream(newFile);
                                int length = 0;
                                while ((length = input.read(buf, 0, BUFFER_SIZE)) > 1) {
                                    output.write(buf, 0, length);
                                    crc.update(buf, 0, length);
                                }

                                if (crc.getValue() != entry.getCrc()) {
                                    throw new IOException();
                                }

                            }
                        }
                    } else {
                        diagReturn = IDialogConstants.YES_ID; //Attempt to extract next entry
                    }
                }
            } catch (IOException e) {
                unziped = false;
                StudioLogger.error(FileUtil.class, "Error extracting file: " + file.getAbsolutePath() + " to " //$NON-NLS-1$ //$NON-NLS-2$
                        + extractDestination, e);
                throw e;
            } catch (Throwable t) {
                unziped = false;
                StudioLogger.error(FileUtil.class, "Error extracting file: " + file.getAbsolutePath() + " to " //$NON-NLS-1$ //$NON-NLS-2$
                        + extractDestination, t);
            } finally {
                try {
                    if (input != null) {
                        input.close();
                    }
                    if (output != null) {
                        output.close();
                    }
                } catch (Throwable t) {
                    //do nothing
                }
                subMonitor.worked(1);
            }
        }
    }
    return unziped;

}

From source file:com.nokia.s60tools.remotecontrol.ftp.ui.view.FtpUtils.java

License:Open Source License

/**
 * Download all selected files//from w w w.  j a  va2 s .c  o m
 * @param viewer Viewer
 * @param contentProvider Content provider
 */
@SuppressWarnings("unchecked")
static public void downloadFiles(TableViewer viewer, ViewContentProvider contentProvider) {

    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    Object selectedObject = selection.getFirstElement();

    if (selectedObject == null || !FtpFileObject.class.isInstance(selectedObject)) {
        // Nothing selected or selection is not file
        return;
    }

    // Show select folder dialog to user
    Shell sh = RemoteControlActivator.getCurrentlyActiveWbWindowShell();

    DirectoryDialog dirDialog = new DirectoryDialog(sh, SWT.OPEN);
    dirDialog.setText(Messages.getString("FtpUtils.Select_Folder_DlgText")); //$NON-NLS-1$
    dirDialog.setMessage(Messages.getString("FtpUtils.Select_Folder_DlgMsg")); //$NON-NLS-1$

    String downloadFilterPath = RCPreferences.getDownloadLocation();
    if (downloadFilterPath == "") { //$NON-NLS-1$
        // Workspace root is used as default folder
        IPath location = ResourcesPlugin.getWorkspace().getRoot().getLocation();
        dirDialog.setFilterPath(location.toString());
    } else {
        // use last used folder
        dirDialog.setFilterPath(downloadFilterPath);
    }

    // Get user selected folder
    String destPath = dirDialog.open();

    if (destPath == null) {
        // User is canceled dialog
        return;
    }
    // Remember last used folder
    RCPreferences.setDownloadLocation(destPath);
    destPath = addFileSepatorToEnd(destPath);

    // Full path for remote file
    String currentDirectory = getCurrentPath(contentProvider);

    IFtpObject ftpObject = null;
    String remoteFile = null;
    String destFile = null;
    FileDownloadJob job = null;

    // Download files
    Iterator iter = selection.iterator();
    boolean canWrite;
    boolean replaceAll = false;
    while (iter.hasNext()) {
        canWrite = true;
        ftpObject = (IFtpObject) iter.next();
        if (FtpFileObject.class.isInstance(ftpObject)) {
            // Folders are not downloaded
            // Full path for destination file
            destFile = destPath + ftpObject.getName();
            remoteFile = currentDirectory + ftpObject.getName();

            if (RCPreferences.getDownloadConfirm()) {
                // Confirm replace from user if file already exists
                File file = new File(destFile);
                if (file.exists() && !replaceAll) {
                    // Show confirmation dialog
                    ConfirmReplaceDialog dlg = new ConfirmReplaceDialog(sh, ftpObject.getName(), iter.hasNext(),
                            ConfirmReplaceDialog.Operation.DOWNLOAD);
                    dlg.open();

                    int sel = dlg.getSelection();
                    switch (sel) {
                    case ConfirmReplaceDialog.RENAME_ID:
                        // Rename this file
                        RenameDialog renameDlg = new RenameDialog(sh, ftpObject.getName(), true,
                                RENAME_FILE_DLG_NAME);
                        if (renameDlg.open() == Dialog.CANCEL) {
                            // User canceled dialog
                            return;
                        }
                        // Get new file name from dialog. If user canceled dialog the original
                        // filename is returned
                        destFile = destPath + renameDlg.getFileName();
                        canWrite = true;
                        break;
                    case IDialogConstants.YES_ID:
                        // Replace this file
                        canWrite = true;
                        break;
                    case IDialogConstants.YES_TO_ALL_ID:
                        // Replace all files
                        replaceAll = true;
                        break;
                    case IDialogConstants.NO_ID:
                        // Do not replace this file
                        canWrite = false;
                        break;
                    case IDialogConstants.CANCEL_ID:
                        // Cancel operation
                        return;
                    default:
                        break;
                    }
                }
            }
            if (canWrite) {
                job = new FileDownloadJob(
                        Messages.getString("FtpUtils.Download_File_Job_Name") + ftpObject.getName(), //$NON-NLS-1$
                        remoteFile, destFile, false);
                job.setPriority(Job.DECORATE);
                job.schedule();
            }
        }
    }
}

From source file:com.nokia.s60tools.remotecontrol.ftp.ui.view.FtpUtils.java

License:Open Source License

/**
 * Upload given source files.//  w  w  w  .j  a v  a 2  s .c  om
 * @param uploadDir Directory where files are to be uploaded.
 * @param sourceFiles Files with path which are to be uploaded.
 */
public static void uploadFiles(String uploadDir, String[] sourceFiles) {

    Shell sh = RemoteControlActivator.getCurrentlyActiveWbWindowShell();

    // Get file list from remote directory for checking
    // if file already exists
    String[] files = null;
    if (RCPreferences.getUploadConfirm()) {
        IFTPService ftpService = HTIServiceFactory.createFTPService(RemoteControlConsole.getInstance());
        try {
            // Get list of files on remote folder
            files = ftpService.listFiles(uploadDir, LIST_CONTENTS_TIMEOUT);
        } catch (Exception e) {
            // Failed to list files. Show message to user and return
            RemoteControlMessageBox message = new RemoteControlMessageBox(
                    Messages.getString("FtpUtils.Upload_Fail_ConsoleErrorMsg") //$NON-NLS-1$
                    , SWT.ICON_ERROR);
            message.open();
            e.printStackTrace();
            return;
        }
    }

    boolean replaceAll = false;
    String destFileName = null;

    for (int j = 0; j < sourceFiles.length; j++) {
        boolean canWrite = true;
        File sourceFile = new File(sourceFiles[j]);
        destFileName = sourceFile.getName();

        if (RCPreferences.getUploadConfirm()) {
            // Ask confirmation for replacing files if already exists on
            // target directory
            for (int i = 0; i < files.length; i++) {
                if (!replaceAll && files[i].equals(destFileName)) {
                    // No need to check other files
                    i = files.length;
                    // File exists on remote folder
                    // Show confirmation dialog
                    ConfirmReplaceDialog dlg = new ConfirmReplaceDialog(sh, destFileName,
                            (j < sourceFiles.length - 1), ConfirmReplaceDialog.Operation.UPLOAD);
                    dlg.open();

                    int sel = dlg.getSelection();
                    switch (sel) {
                    case ConfirmReplaceDialog.RENAME_ID:
                        // Rename this file
                        RenameDialog renameDlg = new RenameDialog(sh, destFileName, true, RENAME_FILE_DLG_NAME);
                        if (renameDlg.open() == Dialog.CANCEL) {
                            // User canceled dialog
                            return;
                        }
                        // Get new file name from dialog. If user canceled dialog the original
                        // filename is returned
                        destFileName = renameDlg.getFileName();
                        canWrite = true;
                        break;
                    case IDialogConstants.YES_ID:
                        // Replace this file
                        canWrite = true;
                        break;
                    case IDialogConstants.YES_TO_ALL_ID:
                        // Replace all files
                        replaceAll = true;
                        break;
                    case IDialogConstants.NO_ID:
                        // Do not replace this file
                        canWrite = false;
                        break;
                    case IDialogConstants.CANCEL_ID:
                        // Cancel operation
                        return;
                    default:
                        break;
                    }
                }
            }
        }
        // Upload file
        if (canWrite) {
            String srcFile = null;
            String destFile = null;

            // Full path for destination file
            destFile = uploadDir + destFileName;
            srcFile = sourceFiles[j];

            FileUploadJob job = new FileUploadJob(Messages.getString("FtpUtils.Upload_File_Job_Name") //$NON-NLS-1$
                    + " " //$NON-NLS-1$
                    + sourceFile.getName(), srcFile, destFile);
            job.setPriority(Job.DECORATE);
            job.schedule();
        }
    }
}

From source file:com.nokia.s60tools.remotecontrol.ftp.ui.view.FtpUtils.java

License:Open Source License

/**
 * Pastes previously selected files to target folder.
 * @param viewer Viewer//w ww  . ja  v a 2s  .  com
 * @param contentProvider Content provider
 */
public static void pasteFiles(TableViewer viewer, ViewContentProvider contentProvider) {
    // Getting required information.
    List<IFtpObject> selectedFiles = contentProvider.getSelectedFiles();
    IFtpObject[] sourceFiles = selectedFiles.toArray(new IFtpObject[0]);
    String sourcePath = contentProvider.getSelectedPath();
    String destFilePath = getSelectedPath(viewer, contentProvider);
    if (destFilePath == null) {
        // Can't paste to root.
        return;
    }

    Shell sh = RemoteControlActivator.getCurrentlyActiveWbWindowShell();

    // Getting files and folders.
    String filesAndFolders[] = getFilesAndFolders(destFilePath);
    if (filesAndFolders == null) {
        // Gettings list failed.
        // Failed to list files. Show message to user and return
        RemoteControlMessageBox message = new RemoteControlMessageBox(
                Messages.getString("FtpUtils.FailedToPaste_ErrMsg") //$NON-NLS-1$
                , SWT.ICON_ERROR);
        message.open();
        return;
    }

    boolean replaceAll = false;

    for (int j = 0; j < sourceFiles.length; j++) {

        if (isSubFolder(sourceFiles[j], sourcePath, destFilePath)) {
            // Can't copy folder to its subfolder.
            break;
        }

        boolean canWrite = true;
        String sourceFile = sourceFiles[j].getName();
        String destFileName = sourceFiles[j].getName();
        if (RCPreferences.getPasteConfirm()) {
            // Ask confirmation for replacing files if already exists on
            // target directory
            for (int i = 0; i < filesAndFolders.length; i++) {
                if (!replaceAll && filesAndFolders[i].equals(destFileName)) {
                    // No need to check other files
                    i = filesAndFolders.length;
                    // File exists on remote folder
                    // Show confirmation dialog
                    ConfirmReplaceDialog dlg = new ConfirmReplaceDialog(sh, destFileName,
                            (j < sourceFiles.length - 1), ConfirmReplaceDialog.Operation.PASTE);
                    dlg.open();

                    int sel = dlg.getSelection();
                    switch (sel) {
                    case ConfirmReplaceDialog.RENAME_ID:
                        // Rename this file
                        RenameDialog renameDlg = new RenameDialog(sh, destFileName, true, RENAME_FILE_DLG_NAME);
                        if (renameDlg.open() == Dialog.CANCEL) {
                            // User canceled dialog
                            return;
                        }
                        // Get new file name from dialog. If user canceled dialog the original
                        // filename is returned
                        destFileName = renameDlg.getFileName();
                        canWrite = true;
                        break;
                    case IDialogConstants.YES_ID:
                        // Replace this file
                        canWrite = true;
                        break;
                    case IDialogConstants.YES_TO_ALL_ID:
                        // Replace all files
                        replaceAll = true;
                        break;
                    case IDialogConstants.NO_ID:
                        // Do not replace this file
                        canWrite = false;
                        break;
                    case IDialogConstants.CANCEL_ID:
                        // Cancel operation
                        return;
                    default:
                        break;
                    }
                }
            }
        }

        if (canWrite) {
            if (sourceFiles[j] instanceof FtpFolderObject) {
                // Cut & Copy operation for empty folders needs to be handled specially because
                // ftp copy copies contents of folder to target folder. If there is nothing in
                // source folder, then cut/paste and copy/paste fails. This is handled user friendly by
                // creating new empty folder if necessary.
                pasteFolder(contentProvider, sourcePath, sourceFile, destFilePath, destFileName);
            } else {
                // Paste file by using default handling.
                doDefaultPasteOperation(contentProvider, sourcePath, destFilePath, sourceFile, destFileName);
            }
        }
    }

    // If files are moved, then clipboard needs to be cleared.
    if (contentProvider.getFileOperation() == OPERATION.CUT) {
        contentProvider.setClipboardFiles(new ArrayList<IFtpObject>(), "", OPERATION.NONE); //$NON-NLS-1$
    }
}

From source file:com.nokia.s60tools.remotecontrol.ui.dialogs.ConfirmReplaceDialog.java

License:Open Source License

protected void createButtonsForButtonBar(Composite parent) {
    GridLayout gdl = new GridLayout(1, false);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
    parent.setLayout(gdl);/*  w  ww  .ja  va  2s. co  m*/
    parent.setLayoutData(gd);

    createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
    if (multiFile) {
        createButton(parent, IDialogConstants.YES_TO_ALL_ID, IDialogConstants.YES_TO_ALL_LABEL, false);
    }
    createButton(parent, RENAME_ID, Messages.getString("ConfirmReplaceDialog.Rename_Button_Label"), false); //$NON-NLS-1$
    createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}

From source file:net.sf.eclipsensis.wizard.NSISWizardContentsPage.java

License:Open Source License

/**
 * @param tv/*from w ww .  j a va2  s .  c  o  m*/
 * @param sel
 */
private void deleteElements(final TreeViewer tv, ISelection sel) {
    if (sel instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) sel;
        if (!ssel.isEmpty()) {
            try {
                int buttonId = -1;
                for (Iterator<?> iter = ssel.iterator(); iter.hasNext();) {
                    INSISInstallElement element = (INSISInstallElement) iter.next();
                    if (element.hasChildren()) {
                        if (buttonId == IDialogConstants.NO_TO_ALL_ID) {
                            continue;
                        } else if (buttonId != IDialogConstants.YES_TO_ALL_ID) {
                            int index = new MessageDialog(getShell(), cDeleteConfirmTitle,
                                    EclipseNSISPlugin.getShellImage(),
                                    MessageFormat
                                            .format(cDeleteConfirmMessageFormat,
                                                    new Object[] { element.getDisplayName() }),
                                    MessageDialog.QUESTION,
                                    new String[] { IDialogConstants.YES_LABEL,
                                            IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL,
                                            IDialogConstants.NO_TO_ALL_LABEL },
                                    0).open();
                            if (index >= 0) {
                                buttonId = cDeleteConfirmButtonIds[index];
                            } else {
                                return;
                            }

                            if (buttonId == IDialogConstants.NO_ID
                                    || buttonId == IDialogConstants.NO_TO_ALL_ID) {
                                continue;
                            }
                        }
                    }
                    INSISInstallElement parent = element.getParent();
                    if (parent != null) {
                        parent.removeChild(element);
                        tv.refresh(parent, true);
                    }
                }
                setPageComplete(validatePage(VALIDATE_ALL));
            } catch (Exception ex) {
                delayedValidateAfterError(ex.getLocalizedMessage(), 2000);
            } finally {
                tv.refresh(false);
            }
        }
    }
}

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

License:Open Source License

protected void buttonPressed(int buttonId) {
    super.buttonPressed(buttonId);

    boolean toggleState = getToggleState();
    IPreferenceStore prefStore = getPrefStore();
    String prefKey = getPrefKey();
    if (buttonId != IDialogConstants.CANCEL_ID && toggleState && prefStore != null && prefKey != null) {
        switch (buttonId) {
        case IDialogConstants.YES_ID:
        case IDialogConstants.YES_TO_ALL_ID:
        case IDialogConstants.PROCEED_ID:
        case IDialogConstants.OK_ID:
            prefStore.setValue(prefKey, toggleState);
            break;
        case IDialogConstants.NO_ID:
        case IDialogConstants.NO_TO_ALL_ID:
            break;
        }//from   ww w. j  a  v  a  2s . c  o  m
    }
}