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

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

Introduction

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

Prototype

int ERROR

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

Click Source Link

Document

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

Usage

From source file:org.eclipse.ui.dialogs.WizardNewFolderMainPage.java

License:Open Source License

/**
 * Creates a new folder resource in the selected container and with the
 * selected name. Creates any missing resource containers along the path;
 * does nothing if the container resources already exist.
 * <p>/* w  ww  . j ava  2s .  c om*/
 * In normal usage, this method is invoked after the user has pressed Finish
 * on the wizard; the enablement of the Finish button implies that all
 * controls on this page currently contain valid values.
 * </p>
 * <p>
 * Note that this page caches the new folder once it has been successfully
 * created; subsequent invocations of this method will answer the same
 * folder resource without attempting to create it again.
 * </p>
 * <p>
 * This method should be called within a workspace modify operation since it
 * creates resources.
 * </p>
 * 
 * @return the created folder resource, or <code>null</code> if the folder
 *         was not created
 */
public IFolder createNewFolder() {
    if (newFolder != null) {
        return newFolder;
    }

    // create the new folder and cache it if successful
    final IPath containerPath = resourceGroup.getContainerFullPath();
    IPath newFolderPath = containerPath.append(resourceGroup.getResource());
    final IFolder newFolderHandle = createFolderHandle(newFolderPath);

    final boolean createVirtualFolder = useVirtualFolder != null && useVirtualFolder.getSelection();
    createLinkTarget();
    if (linkTargetPath != null) {
        URI resolvedPath = newFolderHandle.getPathVariableManager().resolveURI(linkTargetPath);
        try {
            IFileStore store = EFS.getStore(resolvedPath);
            if (!store.fetchInfo().exists()) {
                MessageDialog dlg = new MessageDialog(getContainer().getShell(),
                        IDEWorkbenchMessages.WizardNewFolderCreationPage_createLinkLocationTitle, null,
                        NLS.bind(IDEWorkbenchMessages.WizardNewFolderCreationPage_createLinkLocationQuestion,
                                linkTargetPath),
                        MessageDialog.QUESTION_WITH_CANCEL, new String[] { IDialogConstants.YES_LABEL,
                                IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                        0);
                int result = dlg.open();
                if (result == Window.OK) {
                    store.mkdir(0, new NullProgressMonitor());
                }
                if (result == 2)
                    return null;
            }
        } catch (CoreException e) {
            MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(),
                    IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorTitle,
                    NLS.bind(IDEWorkbenchMessages.WizardNewFileCreationPage_internalErrorMessage,
                            e.getMessage()),
                    SWT.SHEET);

            return null;
        }
    }
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            AbstractOperation op;
            op = new CreateFolderOperation(newFolderHandle, linkTargetPath, createVirtualFolder, filterList,
                    IDEWorkbenchMessages.WizardNewFolderCreationPage_title);
            try {
                // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=219901
                // directly execute the operation so that the undo state is
                // not preserved.  Making this undoable can result in accidental
                // folder (and file) deletions.
                op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
            } catch (final ExecutionException e) {
                getContainer().getShell().getDisplay().syncExec(new Runnable() {
                    public void run() {
                        if (e.getCause() instanceof CoreException) {
                            ErrorDialog.openError(getContainer().getShell(), // Was Utilities.getFocusShell()
                                    IDEWorkbenchMessages.WizardNewFolderCreationPage_errorTitle, null, // no special message
                                    ((CoreException) e.getCause()).getStatus());
                        } else {
                            IDEWorkbenchPlugin.log(getClass(), "createNewFolder()", e.getCause()); //$NON-NLS-1$
                            MessageDialog.openError(getContainer().getShell(),
                                    IDEWorkbenchMessages.WizardNewFolderCreationPage_internalErrorTitle,
                                    NLS.bind(IDEWorkbenchMessages.WizardNewFolder_internalError,
                                            e.getCause().getMessage()));
                        }
                    }
                });
            }
        }
    };

    try {
        getContainer().run(true, true, op);
    } catch (InterruptedException e) {
        return null;
    } catch (InvocationTargetException e) {
        // ExecutionExceptions are handled above, but unexpected runtime
        // exceptions and errors may still occur.
        IDEWorkbenchPlugin.log(getClass(), "createNewFolder()", e.getTargetException()); //$NON-NLS-1$
        MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(),
                IDEWorkbenchMessages.WizardNewFolderCreationPage_internalErrorTitle,
                NLS.bind(IDEWorkbenchMessages.WizardNewFolder_internalError,
                        e.getTargetException().getMessage()),
                SWT.SHEET);
        return null;
    }

    newFolder = newFolderHandle;

    return newFolder;
}

From source file:org.eclipse.ui.internal.ide.actions.OpenLocalFileAction.java

License:Open Source License

public void run() {
    FileDialog dialog = new FileDialog(window.getShell(), SWT.OPEN | SWT.MULTI);
    dialog.setText(IDEWorkbenchMessages.OpenLocalFileAction_title);
    dialog.setFilterPath(filterPath);/*  w  w w .j a  v  a2s. co  m*/
    dialog.open();
    String[] names = dialog.getFileNames();

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

        int numberOfFilesNotFound = 0;
        StringBuffer notFound = new StringBuffer();
        for (int i = 0; i < names.length; i++) {
            IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(filterPath));
            fileStore = fileStore.getChild(names[i]);
            IFileInfo fetchInfo = fileStore.fetchInfo();
            if (!fetchInfo.isDirectory() && fetchInfo.exists()) {
                IWorkbenchPage page = window.getActivePage();
                try {
                    IDE.openEditorOnFileStore(page, fileStore);
                } catch (PartInitException e) {
                    String msg = NLS.bind(IDEWorkbenchMessages.OpenLocalFileAction_message_errorOnOpen,
                            fileStore.getName());
                    IDEWorkbenchPlugin.log(msg, e.getStatus());
                    MessageDialog.open(MessageDialog.ERROR, window.getShell(),
                            IDEWorkbenchMessages.OpenLocalFileAction_title, msg, SWT.SHEET);
                }
            } else {
                if (++numberOfFilesNotFound > 1)
                    notFound.append('\n');
                notFound.append(fileStore.getName());
            }
        }

        if (numberOfFilesNotFound > 0) {
            String msgFmt = numberOfFilesNotFound == 1
                    ? IDEWorkbenchMessages.OpenLocalFileAction_message_fileNotFound
                    : IDEWorkbenchMessages.OpenLocalFileAction_message_filesNotFound;
            String msg = NLS.bind(msgFmt, notFound.toString());
            MessageDialog.open(MessageDialog.ERROR, window.getShell(),
                    IDEWorkbenchMessages.OpenLocalFileAction_title, msg, SWT.SHEET);
        }
    }
}

From source file:org.eclipse.ui.internal.wizards.preferences.WizardPreferencesExportPage1.java

License:Open Source License

/**
 * @param transfers//from w  ww .  j a  v a 2 s . co  m
 * @return <code>true</code> if the transfer was succesful, and
 *         <code>false</code> otherwise
 */
protected boolean transfer(IPreferenceFilter[] transfers) {
    File exportFile = new File(getDestinationValue());
    if (!ensureTargetIsValid(exportFile)) {
        return false;
    }
    FileOutputStream fos = null;
    try {
        if (transfers.length > 0) {
            try {
                fos = new FileOutputStream(exportFile);
            } catch (FileNotFoundException e) {
                WorkbenchPlugin.log(e.getMessage(), e);
                MessageDialog.open(MessageDialog.ERROR, getControl().getShell(), new String(),
                        e.getLocalizedMessage(), SWT.SHEET);
                return false;
            }
            IPreferencesService service = Platform.getPreferencesService();
            try {
                service.exportPreferences(service.getRootNode(), transfers, fos);
            } catch (CoreException e) {
                WorkbenchPlugin.log(e.getMessage(), e);
                MessageDialog.open(MessageDialog.ERROR, getControl().getShell(), new String(),
                        e.getLocalizedMessage(), SWT.SHEET);
                return false;
            }
        }
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
                WorkbenchPlugin.log(e.getMessage(), e);
                MessageDialog.open(MessageDialog.ERROR, getControl().getShell(), new String(),
                        e.getLocalizedMessage(), SWT.SHEET);
                return false;
            }
        }
    }
    return true;
}

From source file:org.eclipse.ui.internal.wizards.preferences.WizardPreferencesImportPage1.java

License:Open Source License

/**
 * @param filters//from w  w w .ja  va2  s.  co m
 * @return <code>true</code> if the transfer was succesful, and
 *         <code>false</code> otherwise
 */
protected boolean transfer(IPreferenceFilter[] filters) {
    File importFile = new File(getDestinationValue());
    FileInputStream fis = null;
    try {
        if (filters.length > 0) {
            try {
                fis = new FileInputStream(importFile);
            } catch (FileNotFoundException e) {
                WorkbenchPlugin.log(e.getMessage(), e);
                MessageDialog.open(MessageDialog.ERROR, getControl().getShell(), new String(),
                        e.getLocalizedMessage(), SWT.SHEET);
                return false;
            }
            IPreferencesService service = Platform.getPreferencesService();
            try {
                IExportedPreferences prefs = service.readPreferences(fis);

                service.applyPreferences(prefs, filters);
            } catch (CoreException e) {
                WorkbenchPlugin.log(e.getMessage(), e);
                MessageDialog.open(MessageDialog.ERROR, getControl().getShell(), new String(),
                        e.getLocalizedMessage(), SWT.SHEET);
                return false;
            }
        }
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException e) {
                WorkbenchPlugin.log(e.getMessage(), e);
                MessageDialog.open(MessageDialog.ERROR, getControl().getShell(), new String(),
                        e.getLocalizedMessage(), SWT.SHEET);
            }
        }
    }
    return true;
}

From source file:org.eclipse.ui.internal.wizards.preferences.WizardPreferencesPage.java

License:Open Source License

/**
 * Attempts to ensure that the specified directory exists on the local file
 * system. Answers a boolean indicating success.
 * //from w w  w  . j  a v  a2s.c o  m
 * @return boolean
 * @param directory
 *            java.io.File
 */
protected boolean ensureDirectoryExists(File directory) {
    if (!directory.exists()) {
        if (!queryYesNoQuestion(PreferencesMessages.PreferencesExport_createTargetDirectory)) {
            return false;
        }

        if (!directory.mkdirs()) {
            MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(),
                    PreferencesMessages.PreferencesExport_error,
                    PreferencesMessages.PreferencesExport_directoryCreationError, SWT.SHEET);
            return false;
        }
    }
    return true;
}

From source file:org.eclipse.ui.wizards.datatransfer.WizardExternalProjectImportPage.java

License:Open Source License

/**
 * Creates a new project resource with the selected name.
 * <p>//from ww  w . j a  va 2  s.c  o  m
 * In normal usage, this method is invoked after the user has pressed Finish on
 * the wizard; the enablement of the Finish button implies that all controls
 * on the pages currently contain valid values.
 * </p>
 *
 * @return the created project resource, or <code>null</code> if the project
 *    was not created
 */
IProject createExistingProject() {

    String projectName = projectNameField.getText();
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProject project = workspace.getRoot().getProject(projectName);
    if (this.description == null) {
        this.description = workspace.newProjectDescription(projectName);
        IPath locationPath = getLocationPath();
        //If it is under the root use the default location
        if (isPrefixOfRoot(locationPath)) {
            this.description.setLocation(null);
        } else {
            this.description.setLocation(locationPath);
        }
    } else {
        this.description.setName(projectName);
    }

    // create the new project operation
    WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
        protected void execute(IProgressMonitor monitor) throws CoreException {
            monitor.beginTask("", 2000); //$NON-NLS-1$
            project.create(description, new SubProgressMonitor(monitor, 1000));
            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }
            project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 1000));

        }
    };

    // run the new project creation operation
    try {
        getContainer().run(true, true, op);
    } catch (InterruptedException e) {
        return null;
    } catch (InvocationTargetException e) {
        // ie.- one of the steps resulted in a core exception   
        Throwable t = e.getTargetException();
        if (t instanceof CoreException) {
            if (((CoreException) t).getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                MessageDialog.open(MessageDialog.ERROR, getShell(),
                        DataTransferMessages.WizardExternalProjectImportPage_errorMessage,
                        NLS.bind(DataTransferMessages.WizardExternalProjectImportPage_caseVariantExistsError,
                                projectName),
                        SWT.SHEET);
            } else {
                ErrorDialog.openError(getShell(),
                        DataTransferMessages.WizardExternalProjectImportPage_errorMessage, null,
                        ((CoreException) t).getStatus());
            }
        }
        return null;
    }

    return project;
}

From source file:org.eclipse.viatra.query.tooling.localsearch.ui.debugger.handlers.StartLocalSearchHandler.java

License:Open Source License

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

    try {/*from  w w w  .  ja  v a  2 s.c  om*/
        final ISelection selection = HandlerUtil.getCurrentSelection(event);
        if (selection instanceof IStructuredSelection) {
            final Object obj = ((IStructuredSelection) selection).iterator().next();
            if (obj instanceof IFilteredMatcherContent) {
                IFilteredMatcherContent content = (IFilteredMatcherContent) obj;
                ViatraQueryMatcher<?> matcher = content.getMatcher();
                final IQuerySpecification<?> specification = matcher.getSpecification();
                final AdvancedViatraQueryEngine engine = AdvancedViatraQueryEngine.from(matcher.getEngine());
                final IQueryBackend lsBackend = engine.getQueryBackend(LocalSearchBackendFactory.INSTANCE);
                final Object[] adornment = content.getFilterMatch().toArray();

                final LocalSearchResultProvider lsResultProvider = (LocalSearchResultProvider) lsBackend
                        .getResultProvider(specification.getInternalQueryRepresentation());
                final LocalSearchBackend localSearchBackend = (LocalSearchBackend) lsBackend;
                final LocalSearchDebugger debugger = new LocalSearchDebugger() {
                    @Override
                    public void dispose() {
                        localSearchBackend.removeAdapter(this);
                        super.dispose();
                    }
                };
                localSearchBackend.addAdapter(debugger);

                // Create and start the matcher thread
                Runnable planExecutorRunnable = new Runnable() {
                    @Override
                    public void run() {
                        try {
                            final LocalSearchMatcher localSearchMatcher = lsResultProvider
                                    .newLocalSearchMatcher(adornment);
                            debugger.setStartHandlerCalled(true);

                            // Initiate the matching
                            localSearchMatcher.getAllMatches();
                        } catch (final Exception e) {
                            final Shell shell = HandlerUtil.getActiveShell(event);
                            shell.getDisplay().asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    MessageDialog.open(MessageDialog.ERROR, shell, "Local search debugger",
                                            "Error while initializing local search debugger: " + e.getMessage(),
                                            SWT.SHEET);

                                }
                            });
                            throw new RuntimeException(e);
                        }
                    }
                };

                if (planExecutorThread == null || !planExecutorThread.isAlive()) {
                    // Start the matching process if not started or in progress yet
                    planExecutorThread = new Thread(planExecutorRunnable);
                    planExecutorThread.start();
                } else if (planExecutorThread.isAlive()) {
                    planExecutorThread.interrupt();
                    planExecutorThread = new Thread(planExecutorRunnable);
                    planExecutorThread.start();
                }
            }
        }
    } catch (ViatraQueryException | QueryProcessingException e) {
        throw new ExecutionException("Error starting local search debugger", e);
    }

    return null;
}

From source file:org.eclipse.vorto.perspective.command.ProjectAction.java

License:Open Source License

@Override
public void run() {
    if (localWorkspace.getProjectBrowser().getSelectedProject() == null) {
        MessageDialog.open(MessageDialog.ERROR, localWorkspace.getShell(), "No Model Project",
                "Please create a model project first!", SWT.NONE);
    } else {//from www.j a  va  2 s .  c o m
        doAction();
    }
}

From source file:org.eclipse.wb.internal.core.utils.ui.UiUtils.java

License:Open Source License

/**
 * Opens standard error dialog./*w w  w .  jav  a  2  s .  co m*/
 */
public static void openError(Shell parent, String title, String message) {
    MessageDialog dialog = new MessageDialog(parent, title, null, message, MessageDialog.ERROR,
            new String[] { IDialogConstants.OK_LABEL }, 0);
    dialog.open();
}

From source file:org.eclipse.wst.jsdt.internal.ui.text.java.CompletionProposalComputerRegistry.java

License:Open Source License

/**
 * Log the status and inform the user about a misbehaving extension.
 * /* ww w .j  a  v a2 s .  c om*/
 * @param descriptor the descriptor of the misbehaving extension
 * @param status a status object that will be logged
 */
void informUser(CompletionProposalComputerDescriptor descriptor, IStatus status) {
    JavaScriptPlugin.log(status);
    String title = JavaTextMessages.CompletionProposalComputerRegistry_error_dialog_title;
    CompletionProposalCategory category = descriptor.getCategory();
    IContributor culprit = descriptor.getContributor();
    Set affectedPlugins = getAffectedContributors(category, culprit);

    final String avoidHint;
    final String culpritName = culprit == null ? null : culprit.getName();
    if (affectedPlugins.isEmpty())
        avoidHint = Messages.format(JavaTextMessages.CompletionProposalComputerRegistry_messageAvoidanceHint,
                new Object[] { culpritName, category.getDisplayName() });
    else
        avoidHint = Messages.format(
                JavaTextMessages.CompletionProposalComputerRegistry_messageAvoidanceHintWithWarning,
                new Object[] { culpritName, category.getDisplayName(), toString(affectedPlugins) });

    String message = status.getMessage();
    // inlined from MessageDialog.openError
    MessageDialog dialog = new MessageDialog(JavaScriptPlugin.getActiveWorkbenchShell(), title,
            null /* default image */, message, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL },
            0) {
        protected Control createCustomArea(Composite parent) {
            Link link = new Link(parent, SWT.NONE);
            link.setText(avoidHint);
            link.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent e) {
                    PreferencesUtil.createPreferenceDialogOn(getShell(),
                            "org.eclipse.wst.jsdt.ui.preferences.CodeAssistPreferenceAdvanced", null, null) //$NON-NLS-1$
                            .open();
                }
            });
            GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
            gridData.widthHint = this.getMinimumMessageWidth();
            link.setLayoutData(gridData);
            return link;
        }
    };
    dialog.open();
}