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

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

Introduction

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

Prototype

String NO_LABEL

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

Click Source Link

Document

The label for no buttons.

Usage

From source file:org.eclipse.andmore.android.common.utilities.EclipseUtils.java

License:Apache License

/**
 * Show a question message using the given title and message
 * /*www  .j av  a2s . c o  m*/
 * @param title
 *            of the dialog
 * @param message
 *            to be displayed in the dialog.
 */
public static int showQuestionWithCancelDialog(final String title, final String message) {
    class IntWrapper {
        public int diagReturn = 0;
    }

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

        @Override
        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.NO_LABEL,
                            IDialogConstants.CANCEL_LABEL },
                    0);
            int diagResults = dialog.open();
            switch (diagResults) {
            case 0:
                intWrapper.diagReturn = SWT.YES;
                break;
            case 1:
                intWrapper.diagReturn = SWT.NO;
                break;
            case 2:
            default:
                intWrapper.diagReturn = SWT.CANCEL;
                break;
            }
        }
    });

    return intWrapper.diagReturn;
}

From source file:org.eclipse.andmore.android.common.utilities.EclipseUtils.java

License:Apache License

/**
 * Show a question message using the given title and message
 * /*  w ww.  j  a  va  2 s  .co  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() {

        @Override
        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:org.eclipse.andmore.traceview.editors.TraceviewEditor.java

License:Apache License

@Override
public void doSaveAs() {
    Shell shell = getSite().getShell();//  www . j  av  a  2  s  . c o  m
    final IEditorInput input = getEditorInput();

    final IEditorInput newInput;

    if (input instanceof FileEditorInput) {
        // the file is part of the current workspace
        FileEditorInput fileEditorInput = (FileEditorInput) input;
        SaveAsDialog dialog = new SaveAsDialog(shell);

        IFile original = fileEditorInput.getFile();
        if (original != null) {
            dialog.setOriginalFile(original);
        }

        dialog.create();

        if (original != null && !original.isAccessible()) {
            String message = String.format("The original file ''%s'' has been deleted or is not accessible.",
                    original.getName());
            dialog.setErrorMessage(null);
            dialog.setMessage(message, IMessageProvider.WARNING);
        }

        if (dialog.open() == Window.CANCEL) {
            return;
        }

        IPath filePath = dialog.getResult();
        if (filePath == null) {
            return;
        }

        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IFile file = workspace.getRoot().getFile(filePath);

        if (copy(shell, fileEditorInput.getURI(), file.getLocationURI()) == null) {
            return;
        }

        try {
            file.refreshLocal(IResource.DEPTH_ZERO, null);
        } catch (CoreException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        newInput = new FileEditorInput(file);
        setInput(newInput);
        setPartName(newInput.getName());
    } else if (input instanceof FileStoreEditorInput) {
        // the file is not part of the current workspace
        FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) input;
        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        IPath oldPath = URIUtil.toPath(fileStoreEditorInput.getURI());
        if (oldPath != null) {
            dialog.setFileName(oldPath.lastSegment());
            dialog.setFilterPath(oldPath.toOSString());
        }

        String path = dialog.open();
        if (path == null) {
            return;
        }

        // Check whether file exists and if so, confirm overwrite
        final File localFile = new File(path);
        if (localFile.exists()) {
            MessageDialog overwriteDialog = new MessageDialog(shell, "Save As", null,
                    String.format("%s already exists.\nDo you want to replace it?", path),
                    MessageDialog.WARNING,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); // 'No'
            // is
            // the
            // default
            if (overwriteDialog.open() != Window.OK) {
                return;
            }
        }

        IFileStore destFileStore = copy(shell, fileStoreEditorInput.getURI(), localFile.toURI());
        if (destFileStore != null) {
            IFile file = getWorkspaceFile(destFileStore);
            if (file != null) {
                newInput = new FileEditorInput(file);
            } else {
                newInput = new FileStoreEditorInput(destFileStore);
            }
            setInput(newInput);
            setPartName(newInput.getName());
        }
    }
}

From source file:org.eclipse.b3.beelang.ui.xtext.linked.ExtLinkedXtextEditor.java

License:Open Source License

@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {

    Shell shell = getSite().getShell();//from  w ww.  java 2s . c o m
    final IEditorInput input = getEditorInput();

    // Customize save as if the file is linked, and it is in the special external link project
    //
    if (input instanceof IFileEditorInput && ((IFileEditorInput) input).getFile().isLinked()
            && ((IFileEditorInput) input).getFile().getProject().getName()
                    .equals(ExtLinkedFileHelper.AUTOLINK_PROJECT_NAME)) {
        final IEditorInput newInput;
        IDocumentProvider provider = getDocumentProvider();

        // 1. If file is "untitled" suggest last save location
        // 2. ...otherwise use the file's location (i.e. likely to be a rename in same folder)
        // 3. If a "last save location" is unknown, use user's home
        //
        String suggestedName = null;
        String suggestedPath = null;
        {
            // is it "untitled"
            java.net.URI uri = ((IURIEditorInput) input).getURI();
            String tmpProperty = null;
            try {
                tmpProperty = ((IFileEditorInput) input).getFile()
                        .getPersistentProperty(TmpFileStoreEditorInput.UNTITLED_PROPERTY);
            } catch (CoreException e) {
                // ignore - tmpProperty will be null
            }
            boolean isUntitled = tmpProperty != null && "true".equals(tmpProperty);

            // suggested name
            IPath oldPath = URIUtil.toPath(uri);
            // TODO: input.getName() is probably always correct
            suggestedName = isUntitled ? input.getName() : oldPath.lastSegment();

            // suggested path
            try {
                suggestedPath = isUntitled
                        ? ((IFileEditorInput) input).getFile().getWorkspace().getRoot()
                                .getPersistentProperty(LAST_SAVEAS_LOCATION)
                        : oldPath.toOSString();
            } catch (CoreException e) {
                // ignore, suggestedPath will be null
            }

            if (suggestedPath == null) {
                // get user.home
                suggestedPath = System.getProperty("user.home");
            }
        }
        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        if (suggestedName != null)
            dialog.setFileName(suggestedName);
        if (suggestedPath != null)
            dialog.setFilterPath(suggestedPath);

        dialog.setFilterExtensions(new String[] { "*.b3", "*.*" });
        String path = dialog.open();
        if (path == null) {
            if (progressMonitor != null)
                progressMonitor.setCanceled(true);
            return;
        }

        // Check whether file exists and if so, confirm overwrite
        final File localFile = new File(path);
        if (localFile.exists()) {
            MessageDialog overwriteDialog = new MessageDialog(shell, "Save As", null,
                    path + " already exists.\nDo you want to replace it?", MessageDialog.WARNING,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); // 'No' is the default
            if (overwriteDialog.open() != Window.OK) {
                if (progressMonitor != null) {
                    progressMonitor.setCanceled(true);
                    return;
                }
            }
        }

        IFileStore fileStore;
        try {
            fileStore = EFS.getStore(localFile.toURI());
        } catch (CoreException ex) {
            EditorsPlugin.log(ex.getStatus());
            String title = "Problems During Save As...";
            String msg = "Save could not be completed. " + ex.getMessage();
            MessageDialog.openError(shell, title, msg);
            return;
        }

        IFile file = getWorkspaceFile(fileStore);
        if (file != null)
            newInput = new FileEditorInput(file);
        else {
            IURIEditorInput uriInput = new FileStoreEditorInput(fileStore);
            java.net.URI uri = uriInput.getURI();
            IFile linkedFile = ExtLinkedFileHelper.obtainLink(uri, false);

            newInput = new FileEditorInput(linkedFile);
        }

        if (provider == null) {
            // editor has been closed while the dialog was open
            return;
        }

        boolean success = false;
        try {

            provider.aboutToChange(newInput);
            provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
            success = true;

        } catch (CoreException x) {
            final IStatus status = x.getStatus();
            if (status == null || status.getSeverity() != IStatus.CANCEL) {
                String title = "Problems During Save As...";
                String msg = "Save could not be completed. " + x.getMessage();
                MessageDialog.openError(shell, title, msg);
            }
        } finally {
            provider.changed(newInput);
            if (success)
                setInput(newInput);
            // the linked file must be removed (esp. if it is an "untitled" link).
            ExtLinkedFileHelper.unlinkInput(((IFileEditorInput) input));
            // remember last saveAs location
            String lastLocation = URIUtil.toPath(((FileEditorInput) newInput).getURI()).toOSString();
            try {
                ((FileEditorInput) newInput).getFile().getWorkspace().getRoot()
                        .setPersistentProperty(LAST_SAVEAS_LOCATION, lastLocation);
            } catch (CoreException e) {
                // ignore
            }
        }

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

        return;
    }

    super.performSaveAs(progressMonitor);
}

From source file:org.eclipse.b3.build.ui.dialogs.B3MessageDialog.java

License:Open Source License

/**
 * Convenience method to open a simple Yes/No question dialog.
 * //w w  w  .j av  a  2s .c  o m
 * @param parent
 *            the parent shell of the dialog, or <code>null</code> if none
 * @param title
 *            the dialog's title, or <code>null</code> if none
 * @param message
 *            the message
 * @param detail
 *            the error
 * @param defaultIndex
 *            the default index of the button to select
 * @return <code>true</code> if the user presses the OK button, <code>false</code> otherwise
 */
public static boolean openQuestion(Shell parent, String title, String message, Throwable detail,
        int defaultIndex) {
    String[] labels;
    if (detail == null) {
        labels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL };
    } else {
        labels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.SHOW_DETAILS_LABEL };
    }

    B3MessageDialog dialog = new B3MessageDialog(parent, title, null, // accept the default window icon
            message, detail, QUESTION, labels, defaultIndex);
    if (detail != null) {
        dialog.setDetailButton(2);
    }
    return dialog.open() == 0;
}

From source file:org.eclipse.birt.chart.integration.wtp.ui.internal.dialogs.WebArtifactOverwriteQuery.java

License:Open Source License

/**
 * Open confirm dialog/*from w w w  .ja va 2  s  .co  m*/
 * 
 * @param file
 * @return
 */
private int openDialog(final String item) {
    final int[] result = { IDialogConstants.CANCEL_ID };
    shell.getDisplay().syncExec(new Runnable() {

        public void run() {
            String title = BirtWTPMessages.BIRTOverwriteQuery_webartifact_title;
            String msg = NLS.bind(BirtWTPMessages.BIRTOverwriteQuery_webartifact_message, item);
            String[] options = { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                    IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.CANCEL_LABEL };
            MessageDialog dialog = new MessageDialog(shell, title, null, msg, MessageDialog.QUESTION, options,
                    0);
            result[0] = dialog.open();
        }
    });
    return result[0];
}

From source file:org.eclipse.birt.report.designer.internal.ui.dialogs.DeleteWarningDialog.java

License:Open Source License

protected boolean initDialog() {
    getButton(IDialogConstants.OK_ID).setText(IDialogConstants.YES_LABEL);
    Button no = getButton(IDialogConstants.CANCEL_ID);
    no.setText(IDialogConstants.NO_LABEL);
    /**/*from ww w  . j  a  v  a 2 s.c  om*/
     * Set cancel button on focus when initial.
     */
    no.setFocus();
    getShell().setDefaultButton(no);
    return true;
}

From source file:org.eclipse.birt.report.designer.internal.ui.dialogs.resource.ExportElementDialog.java

License:Open Source License

private int confirmOverride(String confirmTitle, String confirmMsg) {
    String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
            IDialogConstants.CANCEL_LABEL };

    if (confirmTitle == null || confirmTitle.trim().length() == 0) {
        confirmTitle = Messages.getString("ExportElementDialog.WarningMessageDuplicate.Title"); //$NON-NLS-1$
    }/*from   w  w w  .  ja v a  2  s  .c  o  m*/
    if (confirmMsg == null || confirmMsg.trim().length() == 0) {
        confirmMsg = Messages.getFormattedString("ExportElementDialog.WarningMessageDuplicate.Message", //$NON-NLS-1$
                buttons);
    }

    MessageDialog dialog = new MessageDialog(UIUtil.getDefaultShell(), confirmTitle, null, confirmMsg,
            MessageDialog.QUESTION, buttons, 0);

    return dialog.open();

}

From source file:org.eclipse.birt.report.designer.internal.ui.editors.wizards.WizardSaveAsPage.java

License:Open Source License

public IPath getResult() {

    IPath path = support.getFileLocationFullPath().append(support.getFileName());

    // If the user does not supply a file extension and if the save
    // as dialog was provided a default file name append the extension
    // of the default filename to the new name
    if (ReportPlugin.getDefault().isReportDesignFile(support.getInitialFileName())
            && !ReportPlugin.getDefault().isReportDesignFile(path.toOSString())) {
        String[] parts = support.getInitialFileName().split("\\."); //$NON-NLS-1$
        path = path.addFileExtension(parts[parts.length - 1]);
    } else if (support.getInitialFileName().endsWith(IReportEditorContants.TEMPLATE_FILE_EXTENTION)
            && !path.toOSString().endsWith(IReportEditorContants.TEMPLATE_FILE_EXTENTION)) {
        path = path.addFileExtension("rpttemplate"); //$NON-NLS-1$
    }/*from  w ww.j av a2s.c  o  m*/
    // If the path already exists then confirm overwrite.
    File file = path.toFile();
    if (file.exists()) {
        String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL };

        String question = Messages.getFormattedString("SaveAsDialog.overwriteQuestion", //$NON-NLS-1$
                new Object[] { path.toOSString() });
        MessageDialog d = new MessageDialog(getShell(), Messages.getString("SaveAsDialog.Question"), //$NON-NLS-1$
                null, question, MessageDialog.QUESTION, buttons, 0);
        int overwrite = d.open();
        switch (overwrite) {
        case 0: // Yes
            break;
        case 1: // No
            return null;
        case 2: // Cancel
        default:
            return Path.EMPTY;
        }
    }

    return path;
}

From source file:org.eclipse.birt.report.designer.internal.ui.wizards.PublishCSSWizard.java

License:Open Source License

private boolean publishiCSSFile() {
    // copy to resource folder

    if (!(new File(filePath).exists())) {
        ExceptionHandler.openErrorMessageBox(Messages.getString("PublishCSSAction.wizard.errorTitle"), //$NON-NLS-1$
                Messages.getString("PublishCSSAction.wizard.message.SourceFileNotExist")); //$NON-NLS-1$
        return true;
    }// w  w w .jav a2  s. c  o m

    File targetFolder = new File(folderName);
    if (targetFolder.exists() && (!targetFolder.isDirectory())) {
        ExceptionHandler.openErrorMessageBox(Messages.getString("PublishCSSAction.wizard.errorTitle"), //$NON-NLS-1$
                Messages.getString("PublishCSSAction.wizard.notvalidfolder")); //$NON-NLS-1$
        //$NON-NLS-1$
        return true;
    }
    boolean folderExists = targetFolder.exists();
    if (!folderExists) {
        // if creating dirs fails, it'll return false.
        folderExists = targetFolder.mkdirs();
    }
    if (!folderExists) {
        ExceptionHandler.openErrorMessageBox(Messages.getString("PublishCSSAction.wizard.errorTitle"), //$NON-NLS-1$
                Messages.getString("PublishCSSAction.wizard.msgDirErr")); //$NON-NLS-1$
        return false;
    }

    File targetFile = new File(targetFolder, fileName);
    if (new File(filePath).compareTo(targetFile) == 0) {
        ExceptionHandler.openErrorMessageBox(Messages.getString("PublishCSSAction.wizard.errorTitle"), //$NON-NLS-1$
                Messages.getString("PublishCSSAction.wizard.message")); //$NON-NLS-1$
        return false;
    }

    int overwrite = Window.OK;
    try {
        if (targetFile.exists()) {
            String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                    IDialogConstants.CANCEL_LABEL };
            String question = Messages.getFormattedString("SaveAsDialog.overwriteQuestion", //$NON-NLS-1$
                    new Object[] { targetFile.getAbsolutePath() });
            MessageDialog d = new MessageDialog(UIUtil.getDefaultShell(),
                    Messages.getString("SaveAsDialog.Question"), //$NON-NLS-1$
                    null, question, MessageDialog.QUESTION, buttons, 0);
            overwrite = d.open();
        }
        if (overwrite == Window.OK
                && (targetFile.exists() || (!targetFile.exists() && targetFile.createNewFile()))) {
            copyFile(filePath, targetFile);

            IReportResourceSynchronizer synchronizer = ReportPlugin.getDefault()
                    .getResourceSynchronizerService();

            if (synchronizer != null) {
                synchronizer.notifyResourceChanged(
                        new ReportResourceChangeEvent(this, Path.fromOSString(targetFile.getAbsolutePath()),
                                IReportResourceChangeEvent.NewResource));
            }
        }
    } catch (IOException e) {
        ExceptionHandler.handle(e);
    }

    return overwrite != 1;
}