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

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

Introduction

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

Prototype

int WARNING

To view the source code for org.eclipse.jface.dialogs MessageDialog WARNING.

Click Source Link

Document

Constant for the warning image, or a simple dialog with the warning image and a single OK button (value 4).

Usage

From source file:net.sf.freeqda.common.handler.LoadProjectHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();

    //TODO check for active project and close if exists

    // File standard dialog
    FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);

    // Initialise the dialog
    fileDialog.setText(DIALOG_TEXT);// w ww.ja va 2s. co m
    fileDialog.setFilterNames(new String[] {
            MessageFormat.format(Messages.LoadProjectHandler_Filter_FQDAProjects,
                    new Object[] { SUFFIX_FQDA_PROJECTS }),
            MessageFormat.format(Messages.LoadProjectHandler_Filter_AllFiles,
                    new Object[] { SUFFIX_ALL_FILES }) });
    fileDialog.setFilterExtensions(new String[] { SUFFIX_FQDA_PROJECTS, SUFFIX_ALL_FILES }); //TODO create platform dependent wildcards!

    // Open Dialog and save result of selection
    String selected = fileDialog.open();

    /*
      * Check if dialog has been canceled
      */
    if (selected == null) {
        new MessageDialog(shell, DIALOG_LOAD_CANCELED_TITLE, null, DIALOG_LOAD_CANCELED_MESSAGE,
                MessageDialog.WARNING, new String[] { DIALOG_LOAD_CANCELED_BUTTONS }, 0).open();
        return null;
    }

    /*
     * Load selected project file
     */
    try {
        ProjectManager.getInstance().load(new File(selected));
        new MessageDialog(shell, DIALOG_PROJECT_LOADED_TITLE, null,
                MessageFormat.format(Messages.LoadProjectHandler_DialogProjectLoaded_Message,
                        new Object[] { selected }),
                MessageDialog.INFORMATION, new String[] { DIALOG_PROJECT_LOADED_BUTTONS }, 0).open();
    } catch (IOException e) {
        new MessageDialog(shell, DIALOG_LOADING_FAILED_TITLE, null,
                MessageFormat.format(Messages.LoadProjectHandler_DialogProjectLoadingFailed_Message,
                        new Object[] { selected }),
                MessageDialog.ERROR, new String[] { DIALOG_LOADING_FAILED_BUTTONS }, 0).open();
        e.printStackTrace();
    }
    return null;
}

From source file:net.sf.groovyMonkey.actions.PasteScriptFromClipboardAction.java

License:Open Source License

private IFile createScriptFile(final IFolder destination, final ScriptMetadata metadata, final String script)
        throws CoreException, IOException {
    final String defaultName = substringAfterLast(metadata.scriptPath(), "/");
    String basename = defaultName;
    final int ix = basename.lastIndexOf(".");
    if (ix > 0)
        basename = basename.substring(0, ix);
    createFolder(destination);//from  w w w .  j a v a 2 s .  c o  m
    final IResource[] members = destination.members(0);
    final Pattern suffix = compile(basename + "(-(\\d+))?\\" + FILE_EXTENSION);
    int maxsuffix = -1;
    for (final IResource resource : members) {
        if (resource instanceof IFile) {
            final IFile file = (IFile) resource;
            final String filename = file.getName();
            final Matcher match = suffix.matcher(filename);
            if (match.matches()) {
                if (file.exists() && file.getName().equals(defaultName)) {
                    final MessageDialog dialog = new MessageDialog(shell(), "Overwrite?", null,
                            "Overwrite existing script: " + file.getName() + " ?", MessageDialog.WARNING,
                            new String[] { "Yes", "No" }, 0);
                    if (dialog.open() == 0) {
                        file.delete(true, null);
                        closeEditor(file);
                        maxsuffix = -1;
                        basename = substringBeforeLast(file.getName(), ".");
                        break;
                    }
                }
                if (match.group(2) == null)
                    maxsuffix = max(maxsuffix, 0);
                else {
                    final int n = Integer.parseInt(match.group(2));
                    maxsuffix = max(maxsuffix, n);
                }
            }
        }
    }
    final String filename = maxsuffix == -1 ? basename + FILE_EXTENSION
            : basename + "-" + (maxsuffix + 1) + FILE_EXTENSION;
    final IFile file = destination.getFile(filename);
    final ByteArrayInputStream stream = new ByteArrayInputStream(script.getBytes());
    file.create(stream, true, null);
    stream.close();
    return file;
}

From source file:net.sf.jasperreports.eclipse.ui.util.UIUtils.java

License:Open Source License

public static void showWarning(final String message) {
    getDisplay().asyncExec(new Runnable() {
        public void run() {
            MessageDialog.open(MessageDialog.WARNING, getShell(), Messages.UIUtils_Warning, message, SWT.SHEET);
        }//from   w w  w  . jav a 2 s .  co  m
    });
}

From source file:net.sourceforge.appgen.job.GenerateFileJob.java

License:Apache License

private void runInternal(IProgressMonitor monitor) {
    try {// w  w  w.  j ava2s.com
        List<FileGenerator> fileGeneratorList = new ArrayList<FileGenerator>();

        ConnectionInformation connectionInformation = mappingData.getConnectionInformation();
        GenerationInformation generationInformation = mappingData.getGenerationInformation();
        List<Entity> entityList = mappingData.getEntityList();

        fileGeneratorList.add(new PomFileGenerator(generationInformation));
        fileGeneratorList.add(new WebXmlFileGenerator(generationInformation));
        fileGeneratorList.add(new ServletXmlFileGenerator(generationInformation, entityList));
        fileGeneratorList.add(new SqlMapConfigFileGenerator(generationInformation, entityList));
        fileGeneratorList.add(new Log4jDtdFileGenerator(generationInformation));
        fileGeneratorList.add(new Log4jXmlFileGenerator(generationInformation));
        fileGeneratorList.add(new MessagePropertiesFileGenerator(generationInformation));
        fileGeneratorList.add(new MessageKoPropertiesFileGenerator(generationInformation));

        fileGeneratorList.add(new JdbcPropertiesFileGenerator(generationInformation, connectionInformation));
        fileGeneratorList.add(new ResourcePropertiesFileGenerator(generationInformation));

        fileGeneratorList.add(new JdbcDriverFileGenerator(generationInformation, connectionInformation));

        fileGeneratorList.add(new BaseCriteriaFileGenerator(generationInformation));
        fileGeneratorList.add(new BaseServiceFileGenerator(generationInformation));
        fileGeneratorList.add(new PagingFileGenerator(generationInformation));

        fileGeneratorList.add(new UploadSaveDirectoryGenerator(generationInformation));
        fileGeneratorList.add(new AttachFileFileGenerator(generationInformation));
        fileGeneratorList.add(new AttachFilePersisterFileGenerator(generationInformation));
        fileGeneratorList.add(new AttachFilePropertyEditorFileGenerator(generationInformation));
        fileGeneratorList.add(new FilenameGeneratorFileGenerator(generationInformation));
        fileGeneratorList.add(new UUIDFilenameGeneratorFileGenerator(generationInformation));

        fileGeneratorList.add(new DefaultMethodInvocationLoggerFileGenerator(generationInformation));
        fileGeneratorList.add(new MethodInvocationInfoInterceptorFileGenerator(generationInformation));
        fileGeneratorList.add(new MethodInvocationLoggerFileGenerator(generationInformation));
        fileGeneratorList.add(new MethodInvocationLoggingAdviceFileGenerator(generationInformation));

        fileGeneratorList.add(new EntityFileGenerator(generationInformation));
        fileGeneratorList.add(new CriteriaFileGenerator(generationInformation));
        fileGeneratorList.add(new ValidatorFileGenerator(generationInformation));
        fileGeneratorList.add(new DaoInterfaceFileGenerator(generationInformation));
        fileGeneratorList.add(new DaoClassFileGenerator(generationInformation));
        fileGeneratorList.add(new SqlMapFileGenerator(generationInformation));
        fileGeneratorList.add(new ServiceInterfaceFileGenerator(generationInformation));
        fileGeneratorList.add(new ServiceClassFileGenerator(generationInformation));
        fileGeneratorList.add(new ControllerFileGenerator(generationInformation));
        fileGeneratorList.add(new FormControllerFileGenerator(generationInformation));

        fileGeneratorList.add(new StyleFileGenerator(generationInformation));
        fileGeneratorList.add(new TagsFileGenerator(generationInformation));
        fileGeneratorList.add(new DefaultPagingFileGenerator(generationInformation));

        fileGeneratorList.add(new IndexFileGenerator(generationInformation, entityList));
        fileGeneratorList.add(new ListPageFileGenerator(generationInformation));
        fileGeneratorList.add(new DetailPageFileGenerator(generationInformation));
        fileGeneratorList.add(new WritePageFileGenerator(generationInformation));
        fileGeneratorList.add(new EditPageFileGenerator(generationInformation));

        // IProgressMonitor monitor = editor.getEditorSite().getActionBars().getStatusLineManager().getProgressMonitor();

        monitor.beginTask("Generate soure files",
                (entityList != null && entityList.size() > 0) ? entityList.size() * fileGeneratorList.size()
                        : 0);

        if (entityList != null && entityList.size() > 0) {
            boolean overwriteYesToAll = false;
            boolean overwriteNoToAll = false;

            List<File> generatedFileList = new ArrayList<File>();

            // outer:
            for (FileGenerator fileGenerator : fileGeneratorList) {
                fileGenerator.generateDirectory();

                for (Entity entity : entityList) {
                    monitor.subTask(fileGenerator.getFile(entity).getPath());

                    if (entity.isCreate()) {
                        try {
                            if (fileGenerator.existFile(entity)) {
                                if (overwriteNoToAll) {
                                    continue;
                                }

                                if (!overwriteYesToAll) {
                                    boolean overwrite = false;

                                    MessageDialog overwriteDialog = new MessageDialog(
                                            editor.getSite().getShell(), "Question", null,
                                            "The file '" + fileGenerator.getFile(entity)
                                                    + "' already exists. Do you want to replace the existing file?",
                                            MessageDialog.WARNING,
                                            new String[] { IDialogConstants.YES_LABEL,
                                                    IDialogConstants.NO_LABEL,
                                                    IDialogConstants.YES_TO_ALL_LABEL,
                                                    IDialogConstants.NO_TO_ALL_LABEL },
                                            1);

                                    int value = overwriteDialog.open();

                                    switch (value) {
                                    case 0:
                                        overwrite = true;
                                        break;
                                    case 1:
                                        overwrite = false;
                                        break;
                                    case 2:
                                        overwrite = true;
                                        overwriteYesToAll = true;
                                        break;
                                    case 3:
                                        overwrite = false;
                                        overwriteNoToAll = true;
                                        break;
                                    default:
                                        overwriteNoToAll = true;
                                        break;
                                    }

                                    if (!overwrite) {
                                        continue;
                                    }
                                }
                            }

                            entity.setPackageName(generationInformation.getPackageName());

                            File file = fileGenerator.generate(entity);

                            if (file != null) {
                                generatedFileList.add(file);
                            }
                        } catch (Exception e) {
                            MessageDialog.openError(editor.getSite().getShell(), "Error - generate",
                                    e.getMessage());
                        }
                    }

                    monitor.worked(1);
                }
            }

            printGeneratedFileList(generatedFileList);
        }

        RefreshAction refreshAction = new RefreshAction(editor.getEditorSite());
        refreshAction.refreshAll();

        monitor.done();
    } catch (Exception e) {
        MessageDialog.openError(editor.getSite().getShell(), "Generate file error", e.getMessage());
    } finally {
    }
}

From source file:org.activiti.designer.kickstart.eclipse.navigator.handlers.DeleteHandler.java

License:Apache License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    List<CmisObject> selectedObjects = CmisNavigatorSelectionHolder.getInstance().getSelectedObjects();

    if (!selectedObjects.isEmpty()) {

        MessageDialog dialog = new MessageDialog(HandlerUtil.getActiveShellChecked(event),
                generateDialogTitle(selectedObjects), null, // icon
                generateDialogMessage(selectedObjects), MessageDialog.WARNING,
                new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);

        int result = dialog.open();
        if (result == 0) { // 'YES'
            CmisUtil.deleteCmisObjects(selectedObjects);

            Tree tree = getTreeView(event);
            TreeItem[] treeItems = tree.getSelection();
            for (TreeItem treeItem : treeItems) {
                treeItem.dispose();//from   w w w.ja va2s . co m
            }

        }
    }

    return this;
}

From source file:org.apache.directory.studio.common.ui.CommonUIUtils.java

License:Apache License

/**
 * Opens an Warning {@link MessageDialog} with the given title and message.
 *
 * @param title the title//from   w ww . j  a va 2s.c  om
 * @param message the message
 */
public static void openWarningDialog(String title, String message) {
    MessageDialog dialog = new MessageDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            title, null, message, MessageDialog.WARNING, new String[] { IDialogConstants.OK_LABEL },
            MessageDialog.OK);
    dialog.open();
}

From source file:org.apache.directory.studio.ldapservers.actions.StartAction.java

License:Apache License

/**
 * {@inheritDoc}/*w w w.  j a  va  2s . c  o m*/
 */
public void run() {
    if (view != null) {
        // Getting the selection
        StructuredSelection selection = (StructuredSelection) view.getViewer().getSelection();
        if ((!selection.isEmpty()) && (selection.size() == 1)) {
            // Getting the server
            LdapServer server = (LdapServer) selection.getFirstElement();

            LdapServerAdapterExtension ldapServerAdapterExtension = server.getLdapServerAdapterExtension();
            if ((ldapServerAdapterExtension != null) && (ldapServerAdapterExtension.getInstance() != null)) {
                LdapServerAdapter ldapServerAdapter = ldapServerAdapterExtension.getInstance();

                try {

                    // Getting the ports already in use
                    String[] portsAlreadyInUse = ldapServerAdapter.checkPortsBeforeServerStart(server);
                    if ((portsAlreadyInUse == null) || (portsAlreadyInUse.length > 0)) {
                        String title = null;
                        String message = null;

                        if (portsAlreadyInUse.length == 1) {
                            title = Messages.getString("StartAction.PortInUse"); //$NON-NLS-1$
                            message = NLS.bind(Messages.getString("StartAction.PortOfProtocolInUse"), //$NON-NLS-1$
                                    new String[] { portsAlreadyInUse[0] });
                        } else {
                            title = Messages.getString("StartAction.PortsInUse"); //$NON-NLS-1$
                            message = Messages.getString("StartAction.PortsOfProtocolsInUse"); //$NON-NLS-1$
                            for (String portAlreadyInUse : portsAlreadyInUse) {
                                message += "\n    - " + portAlreadyInUse; //$NON-NLS-1$
                            }
                        }

                        message += "\n\n" + Messages.getString("StartAction.Continue"); //$NON-NLS-1$ //$NON-NLS-2$

                        MessageDialog dialog = new MessageDialog(view.getSite().getShell(), title, null,
                                message, MessageDialog.WARNING,
                                new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL },
                                MessageDialog.OK);
                        if (dialog.open() == MessageDialog.CANCEL) {
                            return;
                        }
                    }

                    // Creating and scheduling the job to start the server
                    StudioLdapServerJob job = new StudioLdapServerJob(new StartLdapServerRunnable(server));
                    job.schedule();
                } catch (Exception e) {
                    // Showing an error in case no LDAP Server Adapter can be found
                    MessageDialog.openError(view.getSite().getShell(),
                            Messages.getString("StartAction.ErrorStartingServer"), //$NON-NLS-1$
                            NLS.bind(
                                    Messages.getString("StartAction.ServerCanNotBeStarted") + "\n" //$NON-NLS-1$//$NON-NLS-2$
                                            + Messages.getString("StartAction.Cause"), //$NON-NLS-1$
                                    server.getName(), e.getMessage()));
                }
            } else {
                // Showing an error in case no LDAP Server Adapter can be found
                MessageDialog.openError(view.getSite().getShell(),
                        Messages.getString("StartAction.NoLdapServerAdapter"), //$NON-NLS-1$
                        NLS.bind(Messages.getString("StartAction.ServerCanNotBeStarted") + "\n" //$NON-NLS-1$ //$NON-NLS-2$
                                + Messages.getString("StartAction.NoLdapServerAdapterCouldBeFound"), //$NON-NLS-1$
                                server.getName()));
            }
        }
    }
}

From source file:org.apache.directory.studio.ldifeditor.editor.LdifEditor.java

License:Apache License

/**
 * The input could be one of the following types:
 * - NonExistingLdifEditorInput: New file, not yet saved
 * - PathEditorInput: file opened with our internal "Open File.." action
 * - FileEditorInput: file is within workspace
 * - JavaFileEditorInput: file opend with "Open File..." action from org.eclipse.ui.editor
 *
 * In RCP the FileDialog appears.// w  ww . ja v  a  2  s  .  c o  m
 * In IDE the super implementation is called.
 * To detect if this plugin runs in IDE the org.eclipse.ui.ide extension point is checked.
 *
 * @see org.eclipse.ui.editors.text.TextEditor#performSaveAs(org.eclipse.core.runtime.IProgressMonitor)
 */
protected void performSaveAs(IProgressMonitor progressMonitor) {
    // detect IDE or RCP:
    // check if perspective org.eclipse.ui.resourcePerspective is available
    boolean isIDE = CommonUIUtils.isIDEEnvironment();

    if (isIDE) {
        // Just call super implementation for now
        IPreferenceStore store = EditorsUI.getPreferenceStore();
        String key = getEditorSite().getId() + ".internal.delegateSaveAs"; // $NON-NLS-1$ //$NON-NLS-1$
        store.setValue(key, true);
        super.performSaveAs(progressMonitor);
    } else {
        // Open FileDialog
        Shell shell = getSite().getShell();
        final IEditorInput input = getEditorInput();

        IDocumentProvider provider = getDocumentProvider();
        final IEditorInput newInput;

        FileDialog dialog = new FileDialog(shell, SWT.SAVE);

        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 externalFile = new File(path);
        if (externalFile.exists()) {
            MessageDialog overwriteDialog = new MessageDialog(shell, Messages.getString("LdifEditor.Overwrite"), //$NON-NLS-1$
                    null, Messages.getString("LdifEditor.OverwriteQuestion"), //$NON-NLS-1$
                    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;
                }
            }
        }

        IPath iPath = new Path(path);
        newInput = new PathEditorInput(iPath);

        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 = Messages.getString("LdifEditor.ErrorInSaveAs"); //$NON-NLS-1$
                String msg = Messages.getString("LdifEditor.ErrorInSaveAs") + x.getMessage(); //$NON-NLS-1$
                MessageDialog.openError(shell, title, msg);
            }
        } finally {
            provider.changed(newInput);
            if (success) {
                setInput(newInput);
            }
        }

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

}

From source file:org.apache.directory.studio.schemaeditor.view.ViewUtils.java

License:Apache License

/**
 * Displays a warning message dialog with the given title and message.
 *
 * @param title the title of the window/*  ww w  .  j a va 2 s .  c o m*/
 * @param message the message to display
 * @return <code>true</code> if the user presses the OK or Yes button,
 *         <code>false</code> otherwise
 */
public static boolean displayWarningMessageDialog(String title, String message) {
    return displayMessageDialog(MessageDialog.WARNING, title, message);
}

From source file:org.bbaw.bts.ui.egy.parts.EgyTextEditorPart.java

License:Open Source License

/**
 * Update model from transcription.//from w w w.  ja  v a  2s.com
 */
@SuppressWarnings("restriction")
protected boolean updateModelFromTranscription() {
    if (text != null) {
        IAnnotationModel am = embeddedEditor.getViewer().getAnnotationModel();
        IXtextDocument document = embeddedEditor.getDocument();

        EList<EObject> objects = document.readOnly(new IUnitOfWork<EList<EObject>, XtextResource>() {
            @Override
            public EList<EObject> exec(XtextResource state) throws Exception {
                return state.getContents();
            }
        });
        EObject eo = objects.get(0);
        Resource resource = eo.eResource();
        boolean valid = checkResourceErrors(resource);
        if (!valid) {
            if (shell == null)
                shell = new Shell();
            MessageDialog dialog = new MessageDialog(shell, "Errors in Text - Possible Data Loss", null,
                    "You are trying to save a text which contains errors, saving this text may lead to loss of data."
                            + "\n\nIt is not recommended to save a text which contains errors!"
                            + "\n\nAre you sure that you want to risk data loss and save with errors?",
                    MessageDialog.WARNING, new String[] { "Don't Save", "Save with Errors" }, 0);
            int result = dialog.open();
            if (result == 0)
                return false;

        }

        if (eo instanceof TextContent) {
            text.setTextContent(textEditorController.updateModelFromTextContent(text.getTextContent(), eo, am));
        }
    }

    return true;
}