Example usage for org.eclipse.jface.wizard WizardDialog setErrorMessage

List of usage examples for org.eclipse.jface.wizard WizardDialog setErrorMessage

Introduction

In this page you can find the example usage for org.eclipse.jface.wizard WizardDialog setErrorMessage.

Prototype

public void setErrorMessage(String newErrorMessage) 

Source Link

Document

Display the given error message.

Usage

From source file:bndtools.editor.BndEditor.java

License:Open Source License

public Promise<IStatus> resolveRunBundles(IProgressMonitor monitor, boolean onSave) {
    final Shell shell = getEditorSite().getShell();
    final IFile file = ResourceUtil.getFile(getEditorInput());
    if (file == null) {
        MessageDialog.openError(shell, "Resolution Error",
                "Unable to run resolution because the file is not in the workspace.");
        reallySave(monitor);//from w ww.j  av a2  s  .co  m
        return Central.promiseFactory().resolved(Status.CANCEL_STATUS);
    }

    Job loadWorkspaceJob = new Job("Loading workspace...") {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            if (monitor == null)
                monitor = new NullProgressMonitor();
            monitor.beginTask("Loading workspace", 2);
            try {
                Central.getWorkspace();
                monitor.worked(1);
                modelReady.getValue();
                return Status.OK_STATUS;
            } catch (Exception e) {
                return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Failed to initialize workspace.", e);
            } finally {
                monitor.done();
            }
        }
    };
    final UIJob runResolveInUIJob = new UIJob("Resolve") {
        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            // Make sure all the parts of this editor page have committed their
            // dirty state to the model
            for (Object pageObj : pages) {
                if (pageObj instanceof IFormPage) {
                    IFormPage formPage = (IFormPage) pageObj;
                    IManagedForm form = formPage.getManagedForm();
                    if (form != null) {
                        IFormPart[] formParts = form.getParts();
                        for (IFormPart formPart : formParts) {
                            if (formPart.isDirty())
                                formPart.commit(false);
                        }
                    }
                }
            }
            if (sourcePage.isActive() && sourcePage.isDirty()) {
                sourcePage.commit(false);
            }

            // Create resolver job and pre-validate
            final ResolveJob job = new ResolveJob(model);
            IStatus validation = job.validateBeforeRun();
            if (!validation.isOK()) {
                if (onSave)
                    reallySave(monitor);
                return validation;
            }

            // Add operation to perform at the end of resolution (i.e. display
            // results and actually save the file)
            final UIJob completionJob = new UIJob(shell.getDisplay(), "Display Resolution Results") {
                @Override
                public IStatus runInUIThread(IProgressMonitor monitor) {
                    ResolutionResult result = job.getResolutionResult();
                    ResolutionWizard wizard = new ResolutionWizard(model, file, result);

                    if (onSave) {
                        // We are in auto-resolve-on-save, only show the dialog if there is a problem
                        wizard.setAllowFinishUnresolved(true);
                        wizard.setPreserveRunBundlesUnresolved(true);
                        if (result.getOutcome() != ResolutionResult.Outcome.Resolved) {
                            WizardDialog dialog = new DuringSaveWizardDialog(shell, wizard);
                            dialog.create();
                            dialog.setErrorMessage(
                                    "Resolve Failed! Saving now will not update the Run Bundles.");
                            if (dialog.open() == Window.OK)
                                reallySave(monitor);
                        } else {
                            wizard.performFinish();
                            reallySave(monitor);
                        }
                    } else {
                        // This is an interactive resolve, always show the dialog
                        boolean dirtyBeforeResolve = isDirty();
                        WizardDialog dialog = new WizardDialog(shell, wizard);
                        if (dialog.open() == Window.OK && !dirtyBeforeResolve) {
                            // save changes immediately if there were no unsaved changes before the resolve
                            reallySave(monitor);
                        }
                    }
                    return Status.OK_STATUS;
                }
            };
            job.addJobChangeListener(new JobChangeAdapter() {
                @Override
                public void done(IJobChangeEvent event) {
                    completionJob.schedule();
                }
            });

            // Start job
            job.setUser(true);
            job.schedule();
            return Status.OK_STATUS;
        }
    };
    runResolveInUIJob.setUser(true);
    return JobUtil.chainJobs(loadWorkspaceJob, runResolveInUIJob);
}

From source file:net.refractions.udig.catalog.ui.export.CatalogExportWizard.java

License:Open Source License

/**
 * Export data, currently focused on Features.
 * // w w  w  . j  a v a 2s.c  om
 * @param monitor
 * @param data
 * @return success
 */
@SuppressWarnings("unchecked")
private boolean exportResource(Data data, IProgressMonitor monitor) {
    if (monitor == null)
        monitor = new NullProgressMonitor();

    final WizardDialog wizardDialog = (WizardDialog) getContainer();
    IGeoResource resource = data.getResource();

    try {
        FeatureSource<SimpleFeatureType, SimpleFeature> fs = resource.resolve(FeatureSource.class, null);
        FeatureCollection<SimpleFeatureType, SimpleFeature> fc = fs.getFeatures(data.getQuery());

        // TODO: remove from catalog/close layers if open?
        SimpleFeatureType schema = fs.getSchema();
        if (data.getName() != null) {
            SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
            builder.init(schema);
            builder.setName(data.getName());
            schema = builder.buildFeatureType();
        }

        File file = determineDestinationFile(data);

        monitor.beginTask("", IProgressMonitor.UNKNOWN); //$NON-NLS-1$

        CoordinateReferenceSystem fromCRS = schema.getCoordinateReferenceSystem();
        CoordinateReferenceSystem crs = data.getCRS();
        MathTransform mt;

        if (fromCRS != null && crs != null) {
            mt = CRS.findMathTransform(fromCRS, crs, true);
        } else {
            if (crs != null)
                mt = IdentityTransform.create(crs.getCoordinateSystem().getDimension());
            else if (fromCRS != null)
                mt = IdentityTransform.create(fromCRS.getCoordinateSystem().getDimension());
            else
                mt = IdentityTransform.create(2);

        }

        if (isAbstractGeometryType(schema)) {
            // possibly multiple geometry types
            String geomName = schema.getGeometryDescriptor().getName().getLocalPart();

            FeatureCollection<SimpleFeatureType, SimpleFeature> pointCollection = FeatureCollections
                    .newCollection();
            FeatureCollection<SimpleFeatureType, SimpleFeature> lineCollection = FeatureCollections
                    .newCollection();
            FeatureCollection<SimpleFeatureType, SimpleFeature> polygonCollection = FeatureCollections
                    .newCollection();

            FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = fs.getFeatures();
            FeatureIterator<SimpleFeature> featureIterator = featureCollection.features();
            while (featureIterator.hasNext()) {
                SimpleFeature feature = featureIterator.next();
                String geometryType = ((Geometry) feature.getDefaultGeometry()).getGeometryType();

                if (geometryType.endsWith("Point")) {
                    pointCollection.add(feature);
                } else if (geometryType.endsWith("LineString")) {
                    lineCollection.add(feature);
                } else if (geometryType.endsWith("Polygon")) {
                    polygonCollection.add(feature);
                }
            }

            if (polygonCollection.size() > 0) {
                exportPolygonFeatures(data, monitor, file, polygonCollection, schema, geomName, mt);
            }
            if (pointCollection.size() > 0) {
                exportPointFeatures(data, monitor, file, pointCollection, schema, geomName, mt);
            }
            if (lineCollection.size() > 0) {
                exportLineFeatures(data, monitor, file, lineCollection, schema, geomName, mt);
            }
        } else {
            // single geometry type
            SimpleFeatureType destinationFeatureType = createFeatureType(schema,
                    (Class<? extends Geometry>) schema.getGeometryDescriptor().getType().getBinding(), crs);
            ReprojectingFeatureCollection processed = new ReprojectingFeatureCollection(fc, monitor,
                    destinationFeatureType, mt);
            boolean success = writeToShapefile(processed, destinationFeatureType, file);
            if (success) {
                addToCatalog(file, data);
            } else {
                Display.getDefault().asyncExec(new Runnable() {
                    public void run() {
                        String msg = "No features were exported; did you select anything?"; //$NON-NLS-1$
                        CatalogUIPlugin.log(msg, null);
                        wizardDialog.setErrorMessage(msg);
                    }
                });
                return false;
            }
        }
    } catch (IOException e) {
        String msg = MessageFormat.format(Messages.CatalogExport_layerFail, resource.getIdentifier());
        CatalogUIPlugin.log(msg, e);
        wizardDialog.setErrorMessage(msg);
        return false;
    } catch (IllegalFilterException e) {
        String msg = MessageFormat.format(Messages.CatalogExport_layerFail, resource.getIdentifier());
        CatalogUIPlugin.log(msg, e);
        wizardDialog.setErrorMessage(msg);
        return false;
    } catch (SchemaException e) {
        String msg = MessageFormat.format(Messages.CatalogExport_layerFail, resource.getIdentifier());
        CatalogExport.setError(wizardDialog, msg, e);
        return false;
    } catch (FactoryException e) {
        String msg = resource.getIdentifier() + Messages.CatalogExport_reprojectError;
        CatalogExport.setError(wizardDialog, msg, e);
        return false;
    } catch (RuntimeException e) {
        e.printStackTrace();
        if (e.getCause() instanceof TransformException) {
            String msg = resource.getIdentifier() + Messages.CatalogExport_reprojectError;
            CatalogExport.setError(wizardDialog, msg, e);
        } else {
            String msg = MessageFormat.format(Messages.CatalogExport_layerFail, resource.getIdentifier());
            CatalogExport.setError(wizardDialog, msg, e);
        }
        return false;
    }
    return true;
}

From source file:org.locationtech.udig.catalog.ui.export.CatalogExport.java

License:Open Source License

public static void setError(final WizardDialog wizardDialog, final String msg, Throwable e) {

    CatalogUIPlugin.log(msg, e);/*from  www .j  a  v  a  2 s . c  o m*/

    if (Display.getCurrent() == null) {
        wizardDialog.getShell().getDisplay().asyncExec(new Runnable() {
            public void run() {
                wizardDialog.setErrorMessage(msg);
            }
        });
    } else {
        wizardDialog.setErrorMessage(msg);
    }
}

From source file:org.locationtech.udig.catalog.ui.export.CatalogExportWizard.java

License:Open Source License

/**
 * Export data, currently focused on Features.
 * //from  ww  w.  j  a  v a2  s.  c om
 * @param monitor
 * @param data
 * @return success
 */
@SuppressWarnings("unchecked")
private boolean exportResource(Data data, IProgressMonitor monitor) {
    if (monitor == null)
        monitor = new NullProgressMonitor();

    final WizardDialog wizardDialog = (WizardDialog) getContainer();
    IGeoResource resource = data.getResource();

    try {
        SimpleFeatureSource fs = resource.resolve(SimpleFeatureSource.class, null);
        SimpleFeatureCollection fc = fs.getFeatures(data.getQuery());

        // TODO: remove from catalog/close layers if open?
        SimpleFeatureType schema = fs.getSchema();
        if (data.getName() != null) {
            SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
            builder.init(schema);
            builder.setName(data.getName());
            schema = builder.buildFeatureType();
        }

        File file = determineDestinationFile(data);

        monitor.beginTask("", IProgressMonitor.UNKNOWN); //$NON-NLS-1$

        CoordinateReferenceSystem fromCRS = schema.getCoordinateReferenceSystem();
        CoordinateReferenceSystem crs = data.getCRS();
        MathTransform mt;

        if (fromCRS != null && crs != null) {
            mt = CRS.findMathTransform(fromCRS, crs, true);
        } else {
            if (crs != null)
                mt = IdentityTransform.create(crs.getCoordinateSystem().getDimension());
            else if (fromCRS != null)
                mt = IdentityTransform.create(fromCRS.getCoordinateSystem().getDimension());
            else
                mt = IdentityTransform.create(2);

        }

        if (isAbstractGeometryType(schema)) {
            // possibly multiple geometry types
            String geomName = schema.getGeometryDescriptor().getName().getLocalPart();

            DefaultFeatureCollection pointCollection = new DefaultFeatureCollection();
            DefaultFeatureCollection lineCollection = new DefaultFeatureCollection();
            DefaultFeatureCollection polygonCollection = new DefaultFeatureCollection();

            SimpleFeatureCollection featureCollection = fs.getFeatures();
            FeatureIterator<SimpleFeature> featureIterator = featureCollection.features();
            while (featureIterator.hasNext()) {
                SimpleFeature feature = featureIterator.next();
                String geometryType = ((Geometry) feature.getDefaultGeometry()).getGeometryType();

                if (geometryType.endsWith("Point")) {
                    pointCollection.add(feature);
                } else if (geometryType.endsWith("LineString")) {
                    lineCollection.add(feature);
                } else if (geometryType.endsWith("Polygon")) {
                    polygonCollection.add(feature);
                }
            }

            if (polygonCollection.size() > 0) {
                exportPolygonFeatures(data, monitor, file, polygonCollection, schema, geomName, mt);
            }
            if (pointCollection.size() > 0) {
                exportPointFeatures(data, monitor, file, pointCollection, schema, geomName, mt);
            }
            if (lineCollection.size() > 0) {
                exportLineFeatures(data, monitor, file, lineCollection, schema, geomName, mt);
            }
        } else {
            // single geometry type
            SimpleFeatureType destinationFeatureType = createFeatureType(schema,
                    (Class<? extends Geometry>) schema.getGeometryDescriptor().getType().getBinding(), crs);
            ReprojectingFeatureCollection processed = new ReprojectingFeatureCollection(fc, monitor,
                    destinationFeatureType, mt);
            boolean success = writeToShapefile(processed, destinationFeatureType, file);
            if (success) {
                addToCatalog(file, data);
            } else {
                Display.getDefault().asyncExec(new Runnable() {
                    public void run() {
                        String msg = "No features were exported; did you select anything?"; //$NON-NLS-1$
                        CatalogUIPlugin.log(msg, null);
                        wizardDialog.setErrorMessage(msg);
                    }
                });
                return false;
            }
        }
    } catch (IOException e) {
        String msg = MessageFormat.format(Messages.CatalogExport_layerFail, resource.getIdentifier());
        CatalogUIPlugin.log(msg, e);
        wizardDialog.setErrorMessage(msg);
        return false;
    } catch (IllegalFilterException e) {
        String msg = MessageFormat.format(Messages.CatalogExport_layerFail, resource.getIdentifier());
        CatalogUIPlugin.log(msg, e);
        wizardDialog.setErrorMessage(msg);
        return false;
    } catch (SchemaException e) {
        String msg = MessageFormat.format(Messages.CatalogExport_layerFail, resource.getIdentifier());
        CatalogExport.setError(wizardDialog, msg, e);
        return false;
    } catch (FactoryException e) {
        String msg = resource.getIdentifier() + Messages.CatalogExport_reprojectError;
        CatalogExport.setError(wizardDialog, msg, e);
        return false;
    } catch (RuntimeException e) {
        e.printStackTrace();
        if (e.getCause() instanceof TransformException) {
            String msg = resource.getIdentifier() + Messages.CatalogExport_reprojectError;
            CatalogExport.setError(wizardDialog, msg, e);
        } else {
            String msg = MessageFormat.format(Messages.CatalogExport_layerFail, resource.getIdentifier());
            CatalogExport.setError(wizardDialog, msg, e);
        }
        return false;
    }
    return true;
}