Example usage for org.eclipse.jface.dialogs MessageDialog getReturnCode

List of usage examples for org.eclipse.jface.dialogs MessageDialog getReturnCode

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog getReturnCode.

Prototype

public int getReturnCode() 

Source Link

Document

Returns this window's return code.

Usage

From source file:com.cea.papyrus.views.panels.CppAbstractPanel.java

License:Open Source License

/**
 * Action executed just before moving to the new element.
 *//*from w w  w.  j av a 2 s.co  m*/
public void exitAction() {
    boolean modelChanged = false;

    // check if model was modified (read only action)
    modelChanged = checkModifications();

    // model has change, must go in a write transaction => save
    if (modelChanged) {
        MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(),
                Activator.getResourceString("panel.property.dialog.saveorignore.title"),
                Activator.getImage(Activator.WARNING_IMAGE),
                Activator.getResourceString("panel.property.dialog.saveorignore"), 0,
                new String[] { Activator.getResourceString("panel.property.dialog.saveorignore.button.save"),
                        Activator.getResourceString("panel.property.dialog.saveorignore.button.ignore") },
                0);
        dialog.open();
        if (dialog.getReturnCode() == 0) { //saveButton pressed
            save();
        }
    }
}

From source file:com.conwet.wirecloud.ide.wizards.WizardProjectsImportPage.java

License:Open Source License

/**
 * The <code>WizardDataTransfer</code> implementation of this
 * <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 *
 * @param pathString//from   w w w .  jav a 2  s. c o  m
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
 *    <code>"ALL"</code>, or <code>"CANCEL"</code>
 */
public String queryOverwrite(String pathString) {

    Path path = new Path(pathString);

    String messageString;
    // Break the message up if there is a file name and a directory
    // and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);
    } else {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
                path.lastSegment(), path.removeLastSegments(1).toOSString());
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question,
            null, messageString, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0) {
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    getControl().getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:com.elphel.vdt.core.options.OptionsCore.java

License:Open Source License

private static void checkVersionCompatibility(Context context, IPreferenceStore store) {
    if (OptionsUtils.isVersionCompatible(context.getVersion(), context.getName(), store))
        return;// ww w  .  j av a 2  s.  com

    Shell shell = VerilogPlugin.getActiveWorkbenchShell();
    String message = "Version of TSL description has been changed.\nDo you wish to delete stored values?";
    MessageDialog messageBox = new MessageDialog(shell, "Warning", null, message, MessageDialog.WARNING,
            new String[] { "Yes", "No" }, 1);
    messageBox.open();
    if (messageBox.getReturnCode() == 0) {
        OptionsUtils.clearStore(context.getName(), store);
        finalizeDoStore(store);
    }
}

From source file:com.elphel.vdt.ui.views.ClearAction.java

License:Open Source License

public void run() {
    Shell shell = VerilogPlugin.getActiveWorkbenchShell();
    MessageDialog messageBox = new MessageDialog(shell, "Warning", null, message, MessageDialog.QUESTION,
            buttonText, 1);/*www . jav a 2 s . co  m*/
    messageBox.open();
    if (messageBox.getReturnCode() == 0) {
        clear();
    }
}

From source file:com.elphel.vdt.ui.views.ClearLogFiles.java

License:Open Source License

public void clear() {
    String msg = "The following files will be deleted:\n\n";
    Set<IFile> toRemove = toolSequence.getOldFiles(toolSequence.getLogDirs());
    int index = 0;
    for (IFile file : toRemove) {
        index++;//from w  ww .ja va2s .com
        //         msg+=file.getLocation().toOSString()+"\n";
        msg += file.getName() + "\n";
        if (index > 25) {
            msg += "\n... and more";
            break;
        }
    }
    if (toRemove.size() == 0) {
        msg = "There are no files to be deleted";
    }
    Shell shell = VerilogPlugin.getActiveWorkbenchShell();
    MessageDialog messageBox = new MessageDialog(shell, "Warning", null, msg, MessageDialog.QUESTION,
            buttonText, 1);
    messageBox.open();
    if (messageBox.getReturnCode() == 0) {
        for (IFile file : toRemove) {
            try {
                //               file.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT ,null);
                file.delete(true, null); // force
            } catch (CoreException e) {
                System.out.println("Could not delete " + file.getLocation().toOSString() + ", exception:" + e);
            }
        }
    }
}

From source file:com.elphel.vdt.ui.views.ClearStateFiles.java

License:Open Source License

public void clear() {
    String msg = "The following files will be deleted:\n\n";
    Set<IFile> toRemove = toolSequence.getOldFiles(toolSequence.getStateDirs());
    int index = 0;
    for (IFile file : toRemove) {
        index++;/*w w  w  . j  ava2  s  .  co m*/
        msg += file.getName() + "\n";
        if (index > 25) {
            msg += "\n... and more";
            break;
        }
    }
    if (toRemove.size() == 0) {
        msg = "There are no files to be deleted";
    }
    Shell shell = VerilogPlugin.getActiveWorkbenchShell();
    MessageDialog messageBox = new MessageDialog(shell, "Warning", null, msg, MessageDialog.QUESTION,
            buttonText, 1);
    messageBox.open();
    if (messageBox.getReturnCode() == 0) {
        for (IFile file : toRemove) {
            try {
                file.delete(true, null); // force - in log files was needed
            } catch (CoreException e) {
                System.out.println("Could not delete " + file.getLocation().toOSString());
            }
        }
    }
}

From source file:com.google.gdt.eclipse.gph.egit.wizard.ImportProjectsWizardPage.java

License:Open Source License

/**
 * The <code>WizardDataTransfer</code> implementation of this
 * <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 * /* w ww  .j av  a2  s . com*/
 * @param pathString
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
 *         <code>"ALL"</code>, or <code>"CANCEL"</code>
 */
@Override
public String queryOverwrite(String pathString) {

    Path path = new Path(pathString);

    String messageString;
    // Break the message up if there is a file name and a directory
    // and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = NLS.bind("''{0}'' already exists.  Would you like to overwrite it?", pathString);
    } else {
        messageString = NLS.bind("Overwrite ''{0}'' in folder ''{1}''?", path.lastSegment(),
                path.removeLastSegments(1).toOSString());
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), "Question", null, messageString,
            MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0) {
        @Override
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    getControl().getDisplay().syncExec(new Runnable() {
        @Override
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:com.iauto.mist.spec.m2t.uml2html.launch.UML2HtmlDynamicSpecificationLaunch.java

License:Open Source License

private void giveErrorMessage(List<StateMachine> stateMachines) {
    // ??//w ww. j  a  va  2s . c  om
    StringBuffer opendFilesb = new StringBuffer();
    FileOutputStream out = null;
    for (StateMachine sm : stateMachines) {
        try {
            File filePath = new File(XlsRender2.write_path);
            if (!filePath.exists()) {
                filePath.mkdirs();
            }
            String fileName = XlsRender2.write_path + File.separator + sm.getName() + Define.FILE_SUFFIX_XLS;
            File file = new File(fileName);
            if (file.exists()) {
                out = new FileOutputStream(fileName);
            }
        } catch (FileNotFoundException e) {
            // ???
            opendFilesb.append(sm.getName());
            opendFilesb.append("\r\n");
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
            }
        }
    }
    // ???
    String dialogMessageFixed = "The excel file corresponding to the following model(s) is opening now, please close it(them) and click \"Retry\".";
    if ("".equals(opendFilesb.toString())) {
        retryFlg = false;
        return;
    }
    final String dialogMessage = dialogMessageFixed + "\r\n\r\n" + opendFilesb.toString();
    // ??
    Display.getDefault().syncExec(new Runnable() {
        @Override
        public void run() {
            MessageDialog dialog = new MessageDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", null,
                    dialogMessage, MessageDialog.ERROR, new String[] { IDialogConstants.RETRY_LABEL }, 0);
            dialog.open();
            if (dialog.getReturnCode() == Window.OK) {
                retryFlg = true;
            }
        }
    });
}

From source file:com.mobilesorcery.sdk.importproject.MoSyncWizardProjectsImportPage.java

License:Open Source License

/**
 * The <code>WizardDataTransfer</code> implementation of this
 * <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 *
 * @param pathString//  www . ja v a2s.co  m
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
 *    <code>"ALL"</code>, or <code>"CANCEL"</code>
 */
@Override
public String queryOverwrite(String pathString) {

    Path path = new Path(pathString);

    String messageString;
    // Break the message up if there is a file name and a directory
    // and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);
    } else {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
                path.lastSegment(), path.removeLastSegments(1).toOSString());
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question,
            null, messageString, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0) {
        @Override
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    getControl().getDisplay().syncExec(new Runnable() {
        @Override
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:com.mulgasoft.emacsplus.preferences.EmacsPlusPreferencePage.java

License:Open Source License

/**
 * Pop up a message dialog to request the restart of the workbench
 *//* ww w  .j  a  v  a 2s .co  m*/
private void requestRestart(String rePreference) {

    String reMessage = EmacsPlusActivator.getString("EmacsPlusPref_RestartMessage"); //$NON-NLS-1$ 
    IProduct product = Platform.getProduct();
    String productName = product != null && product.getName() != null ? product.getName()
            : EmacsPlusActivator.getString("EmacsPlusPref_DefaultProduct"); //$NON-NLS-1$ 

    final String msg = String.format(reMessage, productName, rePreference);
    final String reTitle = EmacsPlusActivator.getString("EmacsPlusPref_RestartTitle"); //$NON-NLS-1$ 

    PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
        public void run() {
            if (PlatformUI.getWorkbench().isClosing())
                return;
            // yes == 0, no == 1
            MessageDialog dialog = new MessageDialog(getDefaultShell(), reTitle, null, msg,
                    MessageDialog.QUESTION,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
            if (dialog.open() != Window.CANCEL) {
                if (dialog.getReturnCode() == 0) {
                    // restart workbench
                    PlatformUI.getWorkbench().restart();
                }
            }
        }
    });
}