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

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

Introduction

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

Prototype

int YES_ID

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

Click Source Link

Document

Button id for a "Yes" button (value 2).

Usage

From source file:com.nokia.s60tools.creator.job.ShutdownCreatorInDeviceDialog.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  w w .jav a 2  s. com*/
    parent.setLayoutData(gd);

    createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, true);
}

From source file:com.nokia.s60tools.hticonnection.ui.dialogs.ErrorDialogWithHelp.java

License:Open Source License

@Override
protected void createButtonsForButtonBar(Composite parent) {
    // Creating Ok button.
    if ((style & SWT.OK) == SWT.OK) {
        okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false);
        okButton.addSelectionListener(this);
        PlatformUI.getWorkbench().getHelpSystem().setHelp(okButton, DEFAULT_CONTEXT_HELP);
    }/*from   ww w  . j  a  va2  s .  com*/

    // Creating Yes button
    if ((style & SWT.YES) == SWT.YES) {
        yesButton = createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
        yesButton.addSelectionListener(this);
        PlatformUI.getWorkbench().getHelpSystem().setHelp(yesButton, DEFAULT_CONTEXT_HELP);
    }

    //Creating No button
    if ((style & SWT.NO) == SWT.NO) {
        noButton = createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
        noButton.addSelectionListener(this);
        PlatformUI.getWorkbench().getHelpSystem().setHelp(noButton, DEFAULT_CONTEXT_HELP);
    }
}

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

License:Open Source License

/**
 * Download file and change it's name/*w w w  . j a v a  2 s .c  om*/
 * @param viewer Viewer
 * @param contentProvider Content provider
 */
static public void downloadFileAs(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;
    }

    FtpFileObject ftpObject = (FtpFileObject) selectedObject;

    // Show Save as dialog to user
    Shell sh = RemoteControlActivator.getCurrentlyActiveWbWindowShell();
    FileDialog fileDialog = new FileDialog(sh, SWT.SAVE);
    fileDialog.setFileName(ftpObject.getName());
    fileDialog.setText(Messages.getString("FtpUtils.DownloadAs_DialogText")); //$NON-NLS-1$
    // Get user selected folder
    String destFile = fileDialog.open();

    if (destFile == null) {
        // User is canceled dialog
        return;
    }

    // Full path for remote file
    String currentDirectory = getCurrentPath(contentProvider);
    String remoteFile = currentDirectory + ftpObject.getName();
    String destFileName = destFile.substring(destFile.lastIndexOf(File.separator) + File.separator.length());

    // Remember last used folder
    String destFolder = destFile.substring(0, destFile.lastIndexOf(File.separator));
    RCPreferences.setDownloadLocation(destFolder);
    destFolder = addFileSepatorToEnd(destFolder);

    FileDownloadJob job = null;
    boolean canWrite = true;

    if (RCPreferences.getDownloadConfirm()) {
        // Confirm replace from user if file already exists
        File file = new File(destFile);
        if (file.exists()) {
            // Show confirmation dialog
            ConfirmReplaceDialog dlg = new ConfirmReplaceDialog(sh, destFileName, false,
                    ConfirmReplaceDialog.Operation.DOWNLOAD);
            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
                destFile = destFolder + renameDlg.getFileName();
                canWrite = true;
                break;
            case IDialogConstants.YES_ID:
                // Replace this file
                canWrite = 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);
        job.setPriority(Job.DECORATE);
        job.schedule();
    }

}

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

License:Open Source License

/**
 * Download all selected files//w  w w . ja va2  s.  c  om
 * @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./*from   w w  w  . j a  v a  2  s  .co  m*/
 * @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

/**
 * Deletes selected directories and files
 * @param viewer Viewer//from   w  w  w  .  ja v a  2s  . co  m
 * @param contentProvider Content provider
 */
@SuppressWarnings("unchecked")
static public void delete(TableViewer viewer, ViewContentProvider contentProvider) {

    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();

    if (RCPreferences.getDeleteConfirm()) {
        // Show confirmation dialog to user
        Shell sh = RemoteControlActivator.getCurrentlyActiveWbWindowShell();
        ConfirmDeleteDialog dlg = new ConfirmDeleteDialog(sh);
        dlg.open();
        if (dlg.getSelection() != IDialogConstants.YES_ID) {
            // Do not delete
            return;
        }
    }

    // Get current folder      
    String path = getCurrentPath(contentProvider);

    // Delete all selected files and folders
    IFtpObject ftpObject = null;
    String dir = null;
    Iterator iter = selection.iterator();
    while (iter.hasNext()) {
        ftpObject = (IFtpObject) iter.next();
        // Add selected file/folder to path
        dir = path + ftpObject.getName();

        if (FtpFolderObject.class.isInstance(ftpObject)) {
            // Start job for deleting folder
            DeleteDirJob job = new DeleteDirJob(
                    Messages.getString("FtpUtils.Delete_Folder_Job_Name") + " " + dir, dir); //$NON-NLS-1$ //$NON-NLS-2$
            job.schedule();
        } else if (FtpFileObject.class.isInstance(ftpObject)) {
            // Start job for deleting file
            DeleteFileJob job = new DeleteFileJob(
                    Messages.getString("FtpUtils.Delete_File_Job_Name") + " " + dir, dir); //$NON-NLS-1$ //$NON-NLS-2$
            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/*from   www.ja v  a2 s .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.ConfirmDeleteDialog.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);// www .ja v  a 2  s.  c o m
    parent.setLayoutData(gd);

    createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
    createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
}

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  w w .  j ava2  s .  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:com.nokia.tools.s60.editor.actions.ElevenPieceConvertAction.java

License:Open Source License

@Override
protected void doRun(Object element) {
    IContentData data = getContentData(element);
    if (data == null) {
        return;// ww w .  j  a  v  a 2  s. com
    }
    if (type == TYPE_CONVERT2SINGLE) {

        IPreferenceStore iPreferenceStore = UtilsPlugin.getDefault().getPreferenceStore();
        boolean ask = !iPreferenceStore.getBoolean(IMediaConstants.PREF_NINE_PIECE_2SINGLE_ASK);

        boolean replaceGfx = iPreferenceStore.getBoolean(IMediaConstants.PREF_NINE_PIECE_2SINGLE);

        if (ask) {
            int result = IDialogConstants.YES_ID;

            ISkinnableEntityAdapter ska = (ISkinnableEntityAdapter) data
                    .getAdapter(ISkinnableEntityAdapter.class);
            boolean isElementSkinned = ska.isSkinned();

            if (isElementSkinned) {
                ElevenPieceOperationConfirmDialog dialog = new ElevenPieceOperationConfirmDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        ElevenPieceOperationConfirmDialog.TYPE_2SINGLE);
                result = dialog.open();

                if (result == IDialogConstants.OK_ID)
                    replaceGfx = true;
                else
                    return; // cancel pressed
            } else {
                replaceGfx = false;
            }

            /*if (result == IDialogConstants.YES_ID)
               replaceGfx = true;
            else if (result == IDialogConstants.NO_ID)
                  replaceGfx = false;*/

        }

        if (ask && iPreferenceStore.getBoolean(IMediaConstants.PREF_NINE_PIECE_2SINGLE_ASK)) {
            // user selects to remeber settings this time - store
            // selected option
            iPreferenceStore.setValue(IMediaConstants.PREF_NINE_PIECE_2SINGLE, replaceGfx);
        }

        EditPart ep = getEditPart(element);
        // special way of update / undo / redo
        Convert2SingleBitmapCommand cmd = new Convert2SingleBitmapCommand(getContentData(element), ep,
                replaceGfx);
        execute(cmd, ep);
    } else {
        if (type == TYPE_ELEVEN_PIECE) {

            IPreferenceStore iPreferenceStore = UtilsPlugin.getDefault().getPreferenceStore();
            boolean ask = !iPreferenceStore.getBoolean(IMediaConstants.PREF_SINGLE_PIECE_2NINE_ASK);

            boolean fillParts = iPreferenceStore.getBoolean(IMediaConstants.PREF_SINGLE_PIECE_2NINE);

            if (ask) {
                ElevenPieceOperationConfirmDialog dialog = new ElevenPieceOperationConfirmDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        ElevenPieceOperationConfirmDialog.TYPE_2ELEVEN);
                int result = dialog.open();
                /*if (result == IDialogConstants.YES_ID)
                   fillParts = true;
                else if (result == IDialogConstants.NO_ID)
                   fillParts = false;*/
                if (result == IDialogConstants.OK_ID)
                    fillParts = true;
                else
                    return; // cancel pressed
            }

            if (ask && iPreferenceStore.getBoolean(IMediaConstants.PREF_SINGLE_PIECE_2NINE_ASK)) {
                // user selects to remeber settings this time - store
                // selected option
                iPreferenceStore.setValue(IMediaConstants.PREF_SINGLE_PIECE_2NINE, fillParts);
            }

            EditPart ep = getEditPart(element);
            // special way of update / undo / redo
            Convert2ElevenBitmapCommand cmd = new Convert2ElevenBitmapCommand(data, ep, fillParts);
            execute(cmd, ep);
        }
    }
}