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

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

Introduction

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

Prototype

public int open() 

Source Link

Document

Opens this window, creating it first if it has not yet been created.

Usage

From source file:com.safi.workshop.util.SafletPersistenceManager.java

public void addOrUpdateSaflets(IProject project, final List<Saflet> saflets, final boolean update,
        final boolean interactive) throws CoreException {
    final List<Saflet> safletsCopy = new ArrayList<Saflet>(saflets);
    // TODO Auto-generated method stub

    project.accept(new IResourceVisitor() {

        @Override/* w  w w  .j  a  v  a  2  s. c o m*/
        public boolean visit(IResource resource) throws CoreException {
            if (resource.getType() == IResource.FILE && "saflet".equals(resource.getFileExtension())) {
                boolean skipAll = false, overwriteAll = false;

                int pid = SafletPersistenceManager.getInstance().getResourceId(resource);
                String existingName = SafletPersistenceManager.getInstance().getSafletName(resource);
                for (Saflet saflet : saflets) {
                    final boolean sameName = StringUtils.equals(existingName, saflet.getName());
                    if ((pid == saflet.getId() && pid != -1) || sameName) {
                        safletsCopy.remove(saflet);
                        if (!update)
                            continue;

                        if (interactive) {
                            if (skipAll)
                                continue;
                            if (!overwriteAll) {
                                String dialogMessage = null;
                                if (sameName)
                                    dialogMessage = "A Saflet with name " + saflet.getName()
                                            + " already exists in the workspace. Do you wish to skip or overwrite? ";
                                else
                                    dialogMessage = "Saflet (" + saflet.getName()
                                            + ") exists with the same ID a different name in the workspace ("
                                            + existingName + "). Do you wish to skip or overwrite? ";
                                MessageDialog dlg = new MessageDialog(SafiWorkshopEditorUtil.getActiveShell(),
                                        "Overwrite Existing Saflet?", null, dialogMessage,
                                        MessageDialog.QUESTION,
                                        new String[] { "Skip", "Skip all", "Overwrite", "Overwrite All" }, 4);
                                int result = dlg.open();
                                switch (result) {
                                case 0: // Skip
                                    continue;
                                case 1: // Skip all
                                    skipAll = true;
                                    continue;
                                case 2: // Overwrite
                                    break;
                                case 3: // Overwrite All
                                    overwriteAll = true;
                                    break;
                                }
                            }
                        }
                        IPath fullPath = null;
                        try {
                            fullPath = SafletPersistenceManager.getInstance()
                                    .writeSafletToExistingFile((IFile) resource, saflet);// SafletPersistenceManager.getInstance().getSaflet(saflet.getId()));
                            AsteriskDiagramEditor editor = getOpenEditor((IFile) resource);
                            if (editor != null) {
                                AsteriskDiagramEditorPlugin.getDefault().getWorkbench()
                                        .getActiveWorkbenchWindow().getActivePage().closeEditor(editor, false);
                                editor = (AsteriskDiagramEditor) SafiWorkshopEditorUtil.openDiagram(
                                        URI.createFileURI(fullPath.toPortableString()), false, true);
                            }
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            MessageDialog.openError(SafiWorkshopEditorUtil.getActiveShell(), "Update Error",
                                    "Couldn't update Saflet: " + e.getLocalizedMessage());
                            AsteriskDiagramEditorPlugin.getInstance().logError("Couldn't update Saflet", e);
                            break;
                        }
                    }
                }

            }
            return true;
        }
    });
    for (Saflet saflet : safletsCopy) {
        String filename = SafiWorkshopEditorUtil.getUniqueFileName(project, saflet.getName(), "saflet");
        IFile file = project.getFile(filename);
        try {
            byte[] code = saflet.getCode() == null ? DBManager.getInstance().getSafletCode(saflet.getId())
                    : (saflet.getCode() == null ? null : saflet.getCode());
            file.create(new ByteArrayInputStream(code), true, null);
            Date now = new Date();
            file.setPersistentProperty(RES_ID_KEY, String.valueOf(saflet.getId()));
            file.setPersistentProperty(MODIFIED_KEY, String.valueOf(now.getTime()));
            file.setPersistentProperty(UPDATED_KEY, String.valueOf(now.getTime()));
            file.setPersistentProperty(SAFLET_NAME_KEY, saflet.getName());
        } catch (DBManagerException e) {
            // TODO Auto-generated catch block
            throw new CoreException(new Status(IStatus.ERROR, AsteriskDiagramEditorPlugin.ID,
                    "Couldn't write Saflet to local file", e));
        }

    }
    updateLocalProject(project, saflets.get(0).getProject());

}

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

License:Open Source License

public int retryAbortMessage(String title, String message) {
    // retry is the default
    MessageDialog dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.ERROR,
            new String[] { IDialogConstants.RETRY_LABEL, IDialogConstants.ABORT_LABEL },
            IDialogConstants.RETRY_ID);/*from   w  w w.  j  a v  a 2  s .  c o  m*/
    return dialog.open();
}

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

License:Open Source License

public int retryAbortCancelMessage(String title, String message) {
    // retry is the default
    MessageDialog dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.ERROR,
            new String[] { IDialogConstants.RETRY_LABEL, IDialogConstants.ABORT_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            IDialogConstants.RETRY_ID);/*from  w w w .  jav  a  2 s.c  o m*/
    return dialog.open();
}

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

License:Open Source License

public int retryOkCancelMessage(String title, String message) {
    // retry is the default
    MessageDialog dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.ERROR,
            new String[] { IDialogConstants.RETRY_LABEL, IDialogConstants.OK_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            IDialogConstants.RETRY_ID);/* w  ww. j a  va 2 s  . c o m*/
    return dialog.open();
}

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

License:Open Source License

public int retryOkMessage(String title, String message) {
    // retry is the default
    MessageDialog dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.ERROR,
            new String[] { IDialogConstants.RETRY_LABEL, IDialogConstants.OK_LABEL },
            IDialogConstants.RETRY_ID);//  ww  w . j  ava  2s.  c o m
    return dialog.open();
}

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

License:Open Source License

public int okMessage(String title, String message, int severity) {
    MessageDialog dialog = new MessageDialog(getShell(), title, null, message, severity,
            new String[] { IDialogConstants.OK_LABEL }, IDialogConstants.OK_ID);
    return dialog.open();
}

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

License:Open Source License

public int closeMessage(String title, String message) {
    MessageDialog dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.INFORMATION,
            new String[] { IDialogConstants.CLOSE_LABEL }, IDialogConstants.CLOSE_ID);
    return dialog.open();
}

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:com.salesforce.ide.core.internal.utils.DialogUtils.java

License:Open Source License

public int continueMessage(String title, String message, int severity) {
    MessageDialog dialog = new MessageDialog(getShell(), title, null, message, severity,
            new String[] { CONTINUE_LABEL }, 1);
    return dialog.open();
}

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

License:Open Source License

public int cancelMessage(String title, String message, int severity) {
    MessageDialog dialog = new MessageDialog(getShell(), title, null, message, severity,
            new String[] { IDialogConstants.CANCEL_LABEL }, IDialogConstants.CANCEL_ID);
    return dialog.open();
}