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.larz.dom4.dm.ui.editor.DmXtextEditor.java

License:Open Source License

@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {

    Shell shell = getSite().getShell();//from w  w w.j  a v a  2  s  .  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(AUTOLINK_PROJECT_NAME)) {
        final IEditorInput newInput;
        IDocumentProvider provider = getDocumentProvider();

        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        IPath oldPath = URIUtil.toPath(((IURIEditorInput) input).getURI());
        if (oldPath != null) {
            dialog.setFileName(oldPath.lastSegment());
            dialog.setFilterPath(oldPath.toOSString());
        }

        dialog.setFilterExtensions(new String[] { "*.dm", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
        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, "File Exists", null,
                    path + " already exists. Do you wish to overwrite? ", 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) {
            MessageDialog.openError(shell, "Error", "Couldn't write file. " + ex.getMessage());
            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 = obtainLink(uri);

            newInput = new FileEditorInput(linkedFile);
        }

        if (provider == null) {
            // editor has programmatically 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) {
                MessageDialog.openError(shell, "Error", "Couldn't write file. " + x.getMessage());
            }
        } finally {
            provider.changed(newInput);
            if (success)
                setInput(newInput);
        }

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

        return;
    }

    super.performSaveAs(progressMonitor);
}

From source file:org.larz.dom4.editor.NewDialog.java

License:Open Source License

@Override
protected void okPressed() {
    final String name = modName.getText();
    final String description = descText.getText();
    final String version = versionText.getText();
    super.okPressed();
    FileDialog dialog = new FileDialog(getParentShell(), SWT.SAVE);
    dialog.setFilterExtensions(new String[] { "*.dm" });
    dialog.open();/*from  w  w w  . j a va 2 s .  com*/
    String[] names = dialog.getFileNames();
    String filterPath = System.getProperty("user.home"); //$NON-NLS-1$

    if (names != null) {
        filterPath = dialog.getFilterPath();

        for (int i = 0; i < names.length; i++) {
            IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(filterPath));
            if (!names[i].endsWith(".dm")) {
                names[i] += ".dm";
            }
            fileStore = fileStore.getChild(names[i]);
            IFileInfo fetchInfo = fileStore.fetchInfo();
            if (fetchInfo.exists()) {
                MessageDialog overwriteDialog = new MessageDialog(getParentShell(),
                        Messages.getString("NewDialog.save.fileExists.title"), null,
                        Messages.format("NewDialog.save.fileExists.fmt", fetchInfo.getName()),
                        MessageDialog.WARNING,
                        new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); // 'No' is the default
                if (overwriteDialog.open() != Window.OK) {
                    return;
                }
            }
            if (!fetchInfo.isDirectory()) {
                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                try {
                    File newFile = fileStore.toLocalFile(0, null);

                    newFile.createNewFile();
                    FileWriter out = new FileWriter(newFile);
                    out.write("#modname \"" + name + "\"\n");
                    out.write("#description \"" + description + "\"\n");
                    out.write("#version " + version + "\n");
                    out.flush();
                    out.close();

                    IDE.openEditorOnFileStore(page, fileStore);
                } catch (PartInitException e) {
                    MessageDialog.open(MessageDialog.ERROR, getParentShell(),
                            Messages.getString("NewDialog.save.openError.title"),
                            Messages.format("NewDialog.save.openError.fmt", fileStore.getName()), SWT.SHEET);
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (CoreException e) {
                    e.printStackTrace();
                }
            }
        }

    }

}

From source file:org.larz.dom4.FixIds.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    MessageDialog overwriteDialog = new MessageDialog(
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            Messages.getString("FixIDsDialog.title"), null, Messages.getString("FixIDsDialog.text"),
            MessageDialog.INFORMATION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL },
            1); // 'No' is the default
    if (overwriteDialog.open() != Window.OK) {
        return null;
    }//ww w.  j  a  v a  2 s.  c o  m
    IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
    ((DmEditor) page.getActiveEditor()).fixIdNumbers();
    return null;
}

From source file:org.limy.eclipse.code.preference.JavadocPropDialog.java

License:Open Source License

@Override
public boolean close() {

    if (modified) {
        String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL, };
        MessageDialog d = new MessageDialog(getShell(), "Save Resourse", null,
                MessageFormat.format("e?X?V?B''{0}'' t@C?X?V?H",
                        getPropFile().getAbsolutePath()),
                MessageDialog.QUESTION, buttons, 0);
        int ret = d.open();

        if (ret == 0/*YES*/) {
            try {
                javadocBean.save(getPropFile());
            } catch (IOException e) {
                LimyEclipsePluginUtils.log(e);
            }//from   www. j a v a 2 s.  c o  m
        }
        if (ret == 2/*CANCEL*/) {
            return false;
        }
    }
    return super.close();
}

From source file:org.mags.remas.view.dialogs.TextAreaMessageDialog.java

License:Apache License

public static boolean openErrorAndQuestion(Shell parent, String title, String message, String textArea,
        Throwable throwable) {//  w w w .  j  ava 2s  .c o  m
    TextAreaMessageDialog dialog = new TextAreaMessageDialog(parent, title, null, message, ERROR,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0, throwable);
    dialog.setShellStyle(dialog.getShellStyle() | SWT.SHEET | SWT.RESIZE);
    dialog.setTextArea(textArea);
    dialog.open();
    return dialog.open() == 0;
}

From source file:org.obeonetwork.dsl.dart.usage.internal.dialog.UsageDialog.java

License:Open Source License

/**
 * {@inheritDoc}/*from ww  w.ja va  2  s  . c  om*/
 * 
 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
 */
@Override
protected void createButtonsForButtonBar(Composite parent) {
    createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, false);
    createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
}

From source file:org.obeonetwork.dsl.uml2.usage.dialog.UsageDialog.java

License:Open Source License

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

From source file:org.opentravel.schemas.stl2developer.DialogUserNotifier.java

License:Apache License

public static int openQuestionWithCancel(final String title, final String question) {
    if (!OtmRegistry.getMainWindow().hasDisplay())
        return 2;
    final MessageDialog dg = new MessageDialog(OtmRegistry.getActiveShell(), title, null, question,
            MessageDialog.QUESTION_WITH_CANCEL, new String[] { IDialogConstants.YES_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
            0);/*from   w w w . ja  v  a 2  s  .c o m*/
    return dg.open();
}

From source file:org.python.pydev.navigator.actions.copied.CopyFilesAndFoldersOperation.java

License:Open Source License

/**
 * Check if the user wishes to overwrite the supplied resource or all
 * resources.//  w  w  w  . j  av  a  2s.  c om
 *
 * @param source
 *            the source resource
 * @param destination
 *            the resource to be overwritten
 * @return one of IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID,
 *         IDialogConstants.NO_ID, IDialogConstants.CANCEL_ID indicating
 *         whether the current resource or all resources can be overwritten,
 *         or if the operation should be canceled.
 */
private int checkOverwrite(final IResource source, final IResource destination) {
    final int[] result = new int[1];

    // Dialogs need to be created and opened in the UI thread
    Runnable query = new Runnable() {
        public void run() {
            String message;
            int resultId[] = { IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID, IDialogConstants.NO_ID,
                    IDialogConstants.CANCEL_ID };
            String labels[] = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };

            if (destination.getType() == IResource.FOLDER) {
                if (homogenousResources(source, destination)) {
                    message = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteMergeQuestion,
                            destination.getFullPath().makeRelative());
                } else {
                    if (destination.isLinked()) {
                        message = NLS.bind(
                                IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeLinkQuestion,
                                destination.getFullPath().makeRelative());
                    } else {
                        message = NLS.bind(
                                IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeNoLinkQuestion,
                                destination.getFullPath().makeRelative());
                    }
                    resultId = new int[] { IDialogConstants.YES_ID, IDialogConstants.NO_ID,
                            IDialogConstants.CANCEL_ID };
                    labels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                            IDialogConstants.CANCEL_LABEL };
                }
            } else {
                String[] bindings = new String[] { IDEResourceInfoUtils.getLocationText(destination),
                        IDEResourceInfoUtils.getDateStringValue(destination),
                        IDEResourceInfoUtils.getLocationText(source),
                        IDEResourceInfoUtils.getDateStringValue(source) };
                message = NLS.bind(
                        IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteWithDetailsQuestion,
                        bindings);
            }
            MessageDialog dialog = new MessageDialog(messageShell,
                    IDEWorkbenchMessages.CopyFilesAndFoldersOperation_resourceExists, null, message,
                    MessageDialog.QUESTION, labels, 0);
            dialog.open();
            if (dialog.getReturnCode() == SWT.DEFAULT) {
                // A window close returns SWT.DEFAULT, which has to be
                // mapped to a cancel
                result[0] = IDialogConstants.CANCEL_ID;
            } else {
                result[0] = resultId[dialog.getReturnCode()];
            }
        }
    };
    messageShell.getDisplay().syncExec(query);
    return result[0];
}

From source file:org.python.pydev.navigator.actions.copied.CopyFilesAndFoldersOperation.java

License:Open Source License

/**
 * Performs an import of the given stores into the provided container.
 * Returns a status indicating if the import was successful.
 *
 * @param stores/*from  www.j av a2  s .com*/
 *            stores that are to be imported
 * @param target
 *            container to which the import will be done
 * @param monitor
 *            a progress monitor for showing progress and for cancelation
 */
private void performFileImport(IFileStore[] stores, IContainer target, IProgressMonitor monitor) {
    IOverwriteQuery query = new IOverwriteQuery() {
        public String queryOverwrite(String pathString) {
            if (alwaysOverwrite) {
                return ALL;
            }

            final String returnCode[] = { CANCEL };
            final String msg = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteQuestion,
                    pathString);
            final String[] options = { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
            messageShell.getDisplay().syncExec(new Runnable() {
                public void run() {
                    MessageDialog dialog = new MessageDialog(messageShell,
                            IDEWorkbenchMessages.CopyFilesAndFoldersOperation_question, null, msg,
                            MessageDialog.QUESTION, options, 0);
                    dialog.open();
                    int returnVal = dialog.getReturnCode();
                    String[] returnCodes = { YES, ALL, NO, CANCEL };
                    returnCode[0] = returnVal == -1 ? CANCEL : returnCodes[returnVal];
                }
            });
            if (returnCode[0] == ALL) {
                alwaysOverwrite = true;
            } else if (returnCode[0] == CANCEL) {
                canceled = true;
            }
            return returnCode[0];
        }
    };

    ImportOperation op = new ImportOperation(target.getFullPath(), stores[0].getParent(),
            FileStoreStructureProvider.INSTANCE, query, Arrays.asList(stores));
    op.setContext(messageShell);
    op.setCreateContainerStructure(false);
    try {
        op.run(monitor);
    } catch (InterruptedException e) {
        return;
    } catch (InvocationTargetException e) {
        if (e.getTargetException() instanceof CoreException) {
            displayError(((CoreException) e.getTargetException()).getStatus());
        } else {
            display(e);
        }
        return;
    }
    // Special case since ImportOperation doesn't throw a CoreException on
    // failure.
    IStatus status = op.getStatus();
    if (!status.isOK()) {
        if (errorStatus == null) {
            errorStatus = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.ERROR, getProblemsMessage(), null);
        }
        errorStatus.merge(status);
    }
}