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

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

Introduction

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

Prototype

int NO_ID

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

Click Source Link

Document

Button id for a "No" button (value 3).

Usage

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  .com*/
 * @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/*from   www .ja  va  2s. co  m*/
 * @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);//from  w  w w  .  j av 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.ConfirmDeleteDialog.java

License:Open Source License

protected Control createDialogArea(Composite parent) {
    Composite dialogAreaComposite = (Composite) super.createDialogArea(parent);
    Label label = new Label(dialogAreaComposite, SWT.NONE);
    label.setText(Messages.getString("ConfirmDeleteDialog.ConfirmDelete_Text")); //$NON-NLS-1$

    // "Don't ask again" check box
    confirmDeleteRadioCB = new Button(dialogAreaComposite, SWT.CHECK);
    confirmDeleteRadioCB.setText(Messages.getString("ConfirmDeleteDialog.ConfirmAlwaysCheck_Text")); //$NON-NLS-1$
    confirmDeleteRadioCB.setSelection(!RCPreferences.getDeleteConfirm());

    // Disable "No" button when check box is selected
    confirmDeleteRadioCB.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent arg0) {
            getButton(IDialogConstants.NO_ID).setEnabled(!confirmDeleteRadioCB.getSelection());
        }//from w w w  . j a  v a  2  s  . com

        public void widgetDefaultSelected(SelectionEvent arg0) {
            // Not implemented
        }
    });

    return dialogAreaComposite;
}

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

License:Open Source License

protected void buttonPressed(int buttonId) {
    // Save pressed button id
    selection = buttonId;/*  w  w  w. j a  v a  2  s  . c  o  m*/

    if (buttonId != IDialogConstants.NO_ID) {
        // Save "Don't ask again" state
        RCPreferences.setDeleteConfirm(!confirmDeleteRadioCB.getSelection());
    }

    super.close();
}

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);//  ww  w .  ja  v a  2s .  c  om
    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.s60tools.remotecontrol.ui.dialogs.ConfirmReplaceDialog.java

License:Open Source License

protected Control createDialogArea(Composite parent) {
    Composite dialogAreaComposite = (Composite) super.createDialogArea(parent);
    Label label = new Label(dialogAreaComposite, SWT.NONE);
    label.setText(Messages.getString("FtpUtils.Confirm_Replace_DlgMsg_Prefix") //$NON-NLS-1$
            + "'" //$NON-NLS-1$
            + fileName + "'" //$NON-NLS-1$
            + ". " //$NON-NLS-1$
            + Messages.getString("FtpUtils.Confirm_Replace_DlgMsg_Postfix")); //$NON-NLS-1$); 

    // "Don't ask again" check box
    confirmReplaceRadioCB = new Button(dialogAreaComposite, SWT.CHECK);
    confirmReplaceRadioCB.setText(Messages.getString("ConfirmReplaceDialog.Confirm_Replace_CheckButton_Text")); //$NON-NLS-1$
    if (operation == Operation.DOWNLOAD) {
        confirmReplaceRadioCB.setSelection(!RCPreferences.getDownloadConfirm());
    } else if (operation == Operation.UPLOAD) {
        confirmReplaceRadioCB.setSelection(!RCPreferences.getUploadConfirm());
    } else {//from   w ww  .  j a v a2s .  c om
        confirmReplaceRadioCB.setSelection(!RCPreferences.getPasteConfirm());
    }
    // Disable "No" button when check box is selected
    confirmReplaceRadioCB.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent arg0) {
            getButton(IDialogConstants.NO_ID).setEnabled(!confirmReplaceRadioCB.getSelection());
        }

        public void widgetDefaultSelected(SelectionEvent arg0) {
            // Not implemented
        }
    });

    return dialogAreaComposite;
}

From source file:com.safi.workshop.sqlexplorer.dialogs.SaveOutsideProjectDlg.java

License:Open Source License

@Override
protected void createButtonsForButtonBar(Composite parent) {
    createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
    createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
}

From source file:com.salesforce.ide.core.internal.utils.DialogUtils.java

License:Open Source License

public int yesNoMessage(String title, String message, int severity) {
    MessageDialog dialog = new MessageDialog(getShell(), title, null, message, severity,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, IDialogConstants.NO_ID);
    return dialog.open();
}

From source file:de.loskutov.anyedit.actions.SaveToFileAction.java

License:Open Source License

@Override
protected void handleAction(IDocument doc, ISelectionProvider selectionProvider, IEditorInput currentInput) {

    IPreferenceStore prefs = AnyEditToolsPlugin.getDefault().getPreferenceStore();
    boolean shouldAsk = prefs.getBoolean(IAnyEditConstants.SAVE_TO_SHOW_OPTIONS);
    boolean shouldOpenEditor = prefs.getBoolean(IAnyEditConstants.SAVE_TO_OPEN_EDITOR);
    boolean ignoreSelection = prefs.getBoolean(IAnyEditConstants.SAVE_TO_IGNORE_SELECTION);
    ITextSelection selection = (ITextSelection) selectionProvider.getSelection();
    boolean hasSelection = false;
    if (!ignoreSelection && selection != null && selection.getLength() > 0) {
        hasSelection = true;//w  w  w .jav  a 2 s .  c  om
    } else {
        selection = new TextSelection(doc, 0, doc.getLength());
    }

    /*
     * Show dialog if prefs is set, asking for open in editor
     */
    if (shouldAsk) {
        MessageDialogWithToggle dialogWithToggle = MessageDialogWithToggle.openYesNoCancelQuestion(
                AnyEditToolsPlugin.getShell(), Messages.SaveTo_ShouldOpen,
                hasSelection ? Messages.SaveTo_MessageSelection : Messages.SaveTo_MessageNoSelection,
                Messages.SaveTo_MessageToggle, false, prefs, IAnyEditConstants.SAVE_TO_SHOW_OPTIONS);

        int returnCode = dialogWithToggle.getReturnCode();
        if (returnCode != IDialogConstants.YES_ID && returnCode != IDialogConstants.NO_ID) {
            return;
        }
        shouldOpenEditor = returnCode == IDialogConstants.YES_ID;
        if (!prefs.getBoolean(IAnyEditConstants.SAVE_TO_SHOW_OPTIONS)) {
            prefs.setValue(IAnyEditConstants.SAVE_TO_OPEN_EDITOR, shouldOpenEditor);
        }
    }

    /*
     * open file selection dialog (external)
     */
    File file = getFileFromUser();
    if (file == null) {
        return;
    }

    /*
     * if selected file exists, ask for override/append/another file
     */
    int overrideOrAppend = checkForExisting(file);
    if (overrideOrAppend == CANCEL) {
        return;
    }

    IFile iFile = EclipseUtils.getIFile(new Path(file.getAbsolutePath()));
    /*
     * if selected file is in the workspace, checkout it or show error message
     */
    if (iFile == null || !checkout(iFile, overrideOrAppend)) {
        return;
    }

    /*
     * save it
     */
    doSave(doc, selection, file, overrideOrAppend);

    /*
     * and if option is on, open in editor
     */
    if (shouldOpenEditor) {
        new DefaultOpenEditorParticipant().openEditor(doc, selectionProvider, currentInput, iFile);
    }
}