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

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

Introduction

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

Prototype

String YES_LABEL

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

Click Source Link

Document

The label for yes buttons.

Usage

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();// ww w  . ja  va2  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(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 .ja  v  a  2  s  .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 www. j  a  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);
    /**/* w w w. j  av  a  2s .  co  m*/
     * 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  va2s . c  om*/
    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$
    }// ww  w  . j av  a2 s . 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;
    }/* ww  w  . j  a v a2 s .  co 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;
}

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

License:Open Source License

private boolean publishiLibrary() {
    // copy to library folder

    if (!(new File(filePath).exists())) {
        ExceptionHandler.openErrorMessageBox(Messages.getString("PublishLibraryAction.wizard.errorTitle"), //$NON-NLS-1$
                Messages.getString("PublishLibraryAction.wizard.message.SourceFileNotExist")); //$NON-NLS-1$
        return true;
    }/*from  w w w.j a v a 2  s. c o m*/

    File targetFolder = new File(folderName);
    if (targetFolder.exists() && (!targetFolder.isDirectory())) {
        ExceptionHandler.openErrorMessageBox(Messages.getString("PublishLibraryAction.wizard.errorTitle"), //$NON-NLS-1$
                Messages.getString("PublishLibraryAction.wizard.notvalidfolder")); //$NON-NLS-1$
        //$NON-NLS-1$
        return true;
    }
    boolean folderExists = targetFolder.exists();
    if (!folderExists) {
        folderExists = targetFolder.mkdirs();
    }
    if (!folderExists) {
        ExceptionHandler.openErrorMessageBox(Messages.getString("PublishLibraryAction.wizard.errorTitle"), //$NON-NLS-1$
                Messages.getString("PublishLibraryAction.wizard.msgDirErr")); //$NON-NLS-1$
        return false;
    }
    File targetFile = new File(targetFolder, fileName);
    if (new File(filePath).compareTo(targetFile) == 0) {
        ExceptionHandler.openErrorMessageBox(Messages.getString("PublishLibraryAction.wizard.errorTitle"), //$NON-NLS-1$
                Messages.getString("PublishLibraryAction.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;
}

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

License:Open Source License

public boolean performFinish() {
    // copy to template folder
    String templateFolderPath = ReportPlugin.getDefault().getTemplatePreference();

    String filePath = handle.getFileName();

    if (!(new File(filePath).exists())) {
        ExceptionHandler.openErrorMessageBox(Messages.getString("PublishTemplateAction.wizard.errorTitle"), //$NON-NLS-1$
                Messages.getString("PublishTemplateAction.wizard.message.SourceFileNotExist")); //$NON-NLS-1$
        return true;
    }/*from  w  ww.  j  av  a  2 s  . c  om*/

    String fileName = filePath.substring(filePath.lastIndexOf(File.separator) + 1);
    File targetFolder = new File(templateFolderPath);
    // if ( !targetFolder.isDirectory( ) )
    // {
    //         ExceptionHandler.openErrorMessageBox( Messages.getString( "PublishTemplateAction.wizard.errorTitle" ), //$NON-NLS-1$
    //               Messages.getString( "PublishTemplateAction.wizard.notvalidfolder" ) ); //$NON-NLS-1$
    // return true;
    // }

    boolean folderExists = targetFolder.exists();
    if (!folderExists) {
        folderExists = targetFolder.mkdirs();
    }

    if (!folderExists) {
        ExceptionHandler.openErrorMessageBox(Messages.getString("PublishTemplateAction.wizard.errorTitle"), //$NON-NLS-1$
                Messages.getString("PublishTemplateAction.wizard.msgDirErr")); //$NON-NLS-1$
        return true;
    }

    String targetFileName = fileName;
    if (ReportPlugin.getDefault().isReportDesignFile(fileName)) {
        int index = fileName.lastIndexOf("."); //$NON-NLS-1$
        targetFileName = fileName.substring(0, index) + ".rpttemplate"; //$NON-NLS-1$
    }
    File targetFile = new File(targetFolder, targetFileName);
    if (new File(filePath).compareTo(targetFile) == 0) {
        ExceptionHandler.openErrorMessageBox(Messages.getString("PublishTemplateAction.wizard.errorTitle"), //$NON-NLS-1$
                Messages.getString("PublishTemplateAction.wizard.message")); //$NON-NLS-1$
        return true;
    }

    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(getShell(), 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);

            try {
                setDesignFile(targetFile.getAbsolutePath());
            } catch (DesignFileException e) {
                ExceptionHandler.handle(e);
                return false;
            } catch (SemanticException e) {
                ExceptionHandler.handle(e);
                return false;
            } catch (IOException e) {
                ExceptionHandler.handle(e);
                return false;
            }

            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;
}

From source file:org.eclipse.birt.report.designer.ui.cubebuilder.page.CubeBuilder.java

License:Open Source License

private boolean checkCubeLink() {
    List childList = new ArrayList();
    if (input != null) {
        DimensionHandle[] dimensions = (DimensionHandle[]) input.getContents(ICubeModel.DIMENSIONS_PROP)
                .toArray(new DimensionHandle[0]);
        for (int i = 0; i < dimensions.length; i++) {
            TabularHierarchyHandle hierarchy = (TabularHierarchyHandle) dimensions[i].getDefaultHierarchy();
            if (hierarchy != null && hierarchy.getDataSet() != null
                    && hierarchy.getDataSet() != input.getDataSet())
                childList.add(hierarchy);
        }/*  w w  w . ja  v a 2  s  .c  o m*/
    }
    if (childList.size() == 0)
        return true;
    else {
        boolean flag = true;

        HashMap conditionMap = new HashMap();
        for (int i = 0; i < childList.size(); i++) {
            flag = true;
            HierarchyHandle hierarchy = (HierarchyHandle) childList.get(i);
            Iterator iter = input.joinConditionsIterator();
            while (iter.hasNext()) {
                DimensionConditionHandle condition = (DimensionConditionHandle) iter.next();
                HierarchyHandle conditionHierarchy = condition.getHierarchy();
                if (ModuleUtil.isEqualHierarchiesForJointCondition(conditionHierarchy, hierarchy)) {
                    if (condition.getJoinConditions() != null) {
                        Iterator iter1 = condition.getJoinConditions().iterator();
                        while (iter1.hasNext()) {
                            iter1.next();
                            int number = conditionMap.containsKey(conditionHierarchy)
                                    ? ((Integer) conditionMap.get(conditionHierarchy)).intValue()
                                    : 0;
                            conditionMap.put(conditionHierarchy, ++number);
                            flag = false;
                        }
                    }
                }
            }
            if (flag)
                break;
        }
        if (flag) {
            conditionMap.clear();

            String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL };

            MessageDialog d = new MessageDialog(getShell(), Messages.getString("MissLinkDialog.Title"), //$NON-NLS-1$
                    null, Messages.getString("MissLinkDialog.Question"), //$NON-NLS-1$
                    MessageDialog.WARNING, buttons, 0);
            int result = d.open();
            if (result == 1)
                return true;
            else {
                this.showSelectionPage(getLinkGroupNode());
                return false;
            }
        }

        conditionMap.clear();
        return true;
    }
}