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

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

Introduction

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

Prototype

public static void openWarning(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a standard warning dialog.

Usage

From source file:de.cau.cs.se.software.evaluation.views.ExportDataAction.java

License:Apache License

@Override
public void run() {
    try {// w  ww . j av  a  2s. c om
        if (AnalysisResultModelProvider.INSTANCE.getValues().size() == 0) {
            MessageDialog.openWarning(this.shell, "Missing values", "There are values to export.");
        } else {
            final IProject project = AnalysisResultModelProvider.INSTANCE.getProject();
            final FileDialog dialog = new FileDialog(this.shell, SWT.SAVE);
            dialog.setText("Save");
            if (project != null) {
                dialog.setFilterPath(project.getLocation().toString());
            }
            final String[] filterExt = { "*.csv", "*.*" };
            dialog.setFilterExtensions(filterExt);
            final String outputFilePath = dialog.open();
            if (outputFilePath != null) {
                if (!outputFilePath.endsWith(".csv")) {
                    outputFilePath.concat(".csv");
                }

                final File result = new File(outputFilePath);
                final BufferedWriter br = new BufferedWriter(new FileWriter(result));
                final StringBuilder sb = new StringBuilder();
                for (final NamedValue element : AnalysisResultModelProvider.INSTANCE.getValues()) {
                    sb.append(element.getProjectName() + ";" + element.getPropertyName() + ";"
                            + element.getValue() + "\n");
                }
                br.write(sb.toString());
                br.close();
                try {
                    project.refreshLocal(IResource.DEPTH_INFINITE, null);
                } catch (final CoreException e) {
                    e.printStackTrace();
                }
            }
        }
    } catch (final IOException e) {
        MessageDialog.openError(this.shell, "Export Error",
                "Error exporting data set " + e.getLocalizedMessage());
    }

}

From source file:de.cau.cs.se.software.evaluation.views.ExportGraphAction.java

License:Apache License

@Override
public void run() {
    try {//from w  ww  . j a  v a2s .c om
        if (AnalysisResultModelProvider.INSTANCE.getHypergraph() == null) {
            MessageDialog.openWarning(null, "Missing EObject", "No Graph (EObject) found.");
        } else {
            final IProject project = AnalysisResultModelProvider.INSTANCE.getProject();
            final FileDialog dialog = new FileDialog(this.shell, SWT.SAVE);
            dialog.setText("Save");
            if (project != null) {
                dialog.setFilterPath(project.getLocation().toString());
            }
            final String[] filterExt = { "*.xmi", "*.*" };
            dialog.setFilterExtensions(filterExt);
            final String outputFilePath = dialog.open();
            if (outputFilePath != null) {

                if (!outputFilePath.endsWith(".xmi")) {
                    outputFilePath.concat(".xmi");
                }

                final ResourceSet resourceSet = new ResourceSetImpl();

                // Register XMI Factory implementation to handle .ecore files
                resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi",
                        new XMIResourceFactoryImpl());

                // Create empty resource with the given URI
                final Resource resource = resourceSet.createResource(URI.createURI(outputFilePath));

                // Add model to contents list of the resource
                resource.getContents().add(AnalysisResultModelProvider.INSTANCE.getHypergraph());

                // Save the resource
                final File destination = new File(outputFilePath);
                final FileOutputStream stream = new FileOutputStream(destination);
                resource.save(stream, null);
                stream.close();
                try {
                    project.refreshLocal(IResource.DEPTH_INFINITE, null);
                } catch (final Exception e) {
                    System.out.println("Warning: could not refresh resources.");
                    // e.printStackTrace();
                }
            }
        }
    } catch (final IOException e) {
        MessageDialog.openError(this.shell, "Export Error",
                "Error exporting hypergraph " + e.getLocalizedMessage());
    }
}

From source file:de.fhg.igd.mapviewer.server.wms.overlay.WMSTileOverlay.java

License:Open Source License

/**
 * Handle errors messages//from w  w  w . j  a  v a  2s.  c  om
 * 
 * @param message the error message
 */
private void handleError(final String message) {
    final Display display = PlatformUI.getWorkbench().getDisplay();

    display.asyncExec(new Runnable() {

        @Override
        public void run() {
            MessageDialog.openWarning(display.getActiveShell(), Messages.WMSTileOverlay_5, message);
        }
    });
}

From source file:de.gulden.modeling.wave.diagram.part.WaveDiagramEditor.java

License:Open Source License

/**
 * @generated/*from   w  w  w  .  j  a  v  a 2 s.  co m*/
 */
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    IEditorInput input = getEditorInput();
    SaveAsDialog dialog = new SaveAsDialog(shell);
    IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
    if (original != null) {
        dialog.setOriginalFile(original);
    }
    dialog.create();
    IDocumentProvider provider = getDocumentProvider();
    if (provider == null) {
        // editor has been programmatically closed while the dialog was open
        return;
    }
    if (provider.isDeleted(input) && original != null) {
        String message = NLS.bind(Messages.WaveDiagramEditor_SavingDeletedFile, original.getName());
        dialog.setErrorMessage(null);
        dialog.setMessage(message, IMessageProvider.WARNING);
    }
    if (dialog.open() == Window.CANCEL) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IPath filePath = dialog.getResult();
    if (filePath == null) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IFile file = workspaceRoot.getFile(filePath);
    final IEditorInput newInput = new FileEditorInput(file);
    // Check if the editor is already open
    IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
    IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getEditorReferences();
    for (int i = 0; i < editorRefs.length; i++) {
        if (matchingStrategy.matches(editorRefs[i], newInput)) {
            MessageDialog.openWarning(shell, Messages.WaveDiagramEditor_SaveAsErrorTitle,
                    Messages.WaveDiagramEditor_SaveAsErrorMessage);
            return;
        }
    }
    boolean success = false;
    try {
        provider.aboutToChange(newInput);
        getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
                getDocumentProvider().getDocument(getEditorInput()), true);
        success = true;
    } catch (CoreException x) {
        IStatus status = x.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            ErrorDialog.openError(shell, Messages.WaveDiagramEditor_SaveErrorTitle,
                    Messages.WaveDiagramEditor_SaveErrorMessage, x.getStatus());
        }
    } finally {
        provider.changed(newInput);
        if (success) {
            setInput(newInput);
        }
    }
    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}

From source file:de.hentschel.visualdbc.dbcmodel.diagram.part.DbCDiagramEditor.java

License:Open Source License

/**
 * @generated/*from   ww w  .  j av  a 2s  .com*/
 */
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    IEditorInput input = getEditorInput();
    SaveAsDialog dialog = new SaveAsDialog(shell);
    IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
    if (original != null) {
        dialog.setOriginalFile(original);
    }
    dialog.create();
    IDocumentProvider provider = getDocumentProvider();
    if (provider == null) {
        // editor has been programmatically closed while the dialog was open
        return;
    }
    if (provider.isDeleted(input) && original != null) {
        String message = NLS.bind(Messages.DbCDiagramEditor_SavingDeletedFile, original.getName());
        dialog.setErrorMessage(null);
        dialog.setMessage(message, IMessageProvider.WARNING);
    }
    if (dialog.open() == Window.CANCEL) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IPath filePath = dialog.getResult();
    if (filePath == null) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IFile file = workspaceRoot.getFile(filePath);
    final IEditorInput newInput = new FileEditorInput(file);
    // Check if the editor is already open
    IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
    IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getEditorReferences();
    for (int i = 0; i < editorRefs.length; i++) {
        if (matchingStrategy.matches(editorRefs[i], newInput)) {
            MessageDialog.openWarning(shell, Messages.DbCDiagramEditor_SaveAsErrorTitle,
                    Messages.DbCDiagramEditor_SaveAsErrorMessage);
            return;
        }
    }
    boolean success = false;
    try {
        provider.aboutToChange(newInput);
        getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
                getDocumentProvider().getDocument(getEditorInput()), true);
        success = true;
    } catch (CoreException x) {
        IStatus status = x.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            ErrorDialog.openError(shell, Messages.DbCDiagramEditor_SaveErrorTitle,
                    Messages.DbCDiagramEditor_SaveErrorMessage, x.getStatus());
        }
    } finally {
        provider.changed(newInput);
        if (success) {
            setInput(newInput);
        }
    }
    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}

From source file:de.innot.avreclipse.ui.actions.UploadProjectAction.java

License:Open Source License

/**
 * Check that the current properties are valid.
 * <p>//from ww  w. j a  v  a2  s  . c om
 * This method will check that:
 * <ul>
 * <li>there has been a Programmer selected</li>
 * <li>avrdude supports the selected MCU</li>
 * <li>there are some actions to perform</li>
 * <li>all source files exist</li>
 * <li>the fuse bytes (if uploaded) are valid for the target MCU</li>
 * </ul>
 * <p>
 * 
 * @param buildcfg
 *            The current build configuration
 * @param props
 *            The current Properties
 * @return <code>true</code> if everything is OK.
 */
private boolean checkProperties(IConfiguration buildcfg, AVRProjectProperties props) {

    boolean perconfig = ProjectPropertyManager.getPropertyManager(fProject).isPerConfig();
    String source = perconfig ? SOURCE_BUILDCONFIG : SOURCE_PROJECT;

    // Check that a Programmer has been selected
    if (props.getAVRDudeProperties().getProgrammer() == null) {
        String message = MessageFormat.format(MSG_NOPROGRAMMER, source);
        MessageDialog.openError(getShell(), TITLE_UPLOAD, message);
        return false;
    }

    // Check that the MCU is valid for avrdude
    String mcuid = props.getMCUId();
    if (!AVRDude.getDefault().hasMCU(mcuid)) {
        String message = MessageFormat.format(MSG_WRONGMCU, AVRMCUidConverter.id2name(mcuid));
        MessageDialog.openError(getShell(), TITLE_UPLOAD, message);
        return false;
    }

    // Check that there is actually anything to upload
    List<String> actionlist = props.getAVRDudeProperties().getActionArguments(buildcfg, true);
    if (actionlist.size() == 0) {
        String message = MessageFormat.format(MSG_NOACTIONS, source);
        MessageDialog.openWarning(getShell(), TITLE_UPLOAD, message);
        return false;
    }

    // Check all referenced files
    // It would be cumbersome to go through all possible cases. Instead we
    // convert all action arguments back to AVRDudeActions and get the
    // filename from it.
    IPath invalidfile = null;
    String formemtype = null;
    for (String argument : actionlist) {
        AVRDudeAction action = AVRDudeAction.getActionForArgument(argument);
        String filename = action.getFilename();
        if (filename == null)
            continue;
        IPath rawfile = new Path(filename);
        IPath unresolvedfile = rawfile;
        IPath resolvedfile = rawfile;
        if (!rawfile.isAbsolute()) {
            // The filename is relative to the build folder. Get the build
            // folder and append our filename. Then resolve any macros
            unresolvedfile = buildcfg.getBuildData().getBuilderCWD().append(rawfile);
            resolvedfile = new Path(BuildMacro.resolveMacros(buildcfg, unresolvedfile.toString()));
        }
        File realfile = resolvedfile.toFile();
        if (!realfile.canRead()) {
            invalidfile = unresolvedfile;
            formemtype = action.getMemType().toString();
            break;
        }
    }
    if (invalidfile != null) {
        String message = MessageFormat.format(MSG_MISSING_FILE, invalidfile.toString(), formemtype);
        MessageDialog.openError(getShell(), TITLE_UPLOAD, message);
        return false;
    }

    // Check that the fuses and locks are valid (if they are to be uploaded)
    for (FuseType type : FuseType.values()) {

        if (props.getAVRDudeProperties().getBytesProperties(type, buildcfg).getWrite()) {
            BaseBytesProperties bytesproperties = props.getAVRDudeProperties().getBytesProperties(type,
                    buildcfg);
            if (bytesproperties.getMCUId() == null) {
                // A non-existing file has been selected as source for the fuses
                String message = MessageFormat.format(MSG_MISSING_FUSES_FILE, type.toString(),
                        bytesproperties.getFileNameResolved());
                MessageDialog.openError(getShell(), TITLE_UPLOAD, message);
                return false;
            }
            if (!bytesproperties.isCompatibleWith(props.getMCUId())) {
                String fusesmcuid = AVRMCUidConverter.id2name(bytesproperties.getMCUId());
                String propsmcuid = AVRMCUidConverter.id2name(props.getMCUId());
                String message = MessageFormat.format(MSG_INVALIDFUSEBYTE, type.toString(), fusesmcuid,
                        propsmcuid, source);
                MessageDialog.openError(getShell(), TITLE_UPLOAD, message);
                return false;
            }
        }
    }

    // Everything is OK
    return true;
}

From source file:de.innot.avreclipse.ui.propertypages.TabTargetHardware.java

License:Open Source License

/**
 * Check if the FuseBytesProperties and Lockbits in the current properties are compatible with
 * the selected mcu. If not, a warning dialog is shown.
 *///  w  ww . j av a  2  s.co m
private void checkFuseBytes(String mcuid) {
    AVRDudeProperties avrdudeprops = fTargetProps.getAVRDudeProperties();

    // State:
    // 0x00 = neither fuses nor lockbits are written
    // 0x01 = fuses not compatible
    // 0x02 = lockbits not compatible
    // 0x03 = both not compatible
    // The state is used as an index to the String arrays with the texts.
    int state = 0x00;

    // Check fuse bytes
    boolean fusewrite = avrdudeprops.getFuseBytes(getCfg()).getWrite();
    if (fusewrite) {
        boolean fusecompatible = avrdudeprops.getFuseBytes(getCfg()).isCompatibleWith(mcuid);
        if (!fusecompatible) {
            state |= 0x01;
        }
    }

    // check lockbits
    boolean lockwrite = avrdudeprops.getLockbitBytes(getCfg()).getWrite();
    if (lockwrite) {
        boolean lockcompatible = avrdudeprops.getLockbitBytes(getCfg()).isCompatibleWith(mcuid);
        if (!lockcompatible) {
            state |= 0x02;
        }
    }

    if (!fusewrite && !lockwrite) {
        // Neither Fuses nor Lockbits are written, so no need for a warning.
        // The fuses tab respective lockbits tab will show a warning once the write flag is
        // changed.
        return;
    }

    if (state == 0) {
        // both fuses and lockbits are compatible, so no need for a warning.
        return;
    }

    // Now show the warning.
    String title = MessageFormat.format(TITLE_FUSEBYTEWARNING, TITLEINSERT[state]);
    String text = MessageFormat.format(TEXT_FUSEBYTEWARNING, TEXTINSERT[state], TABNAMEINSERT[state]);
    MessageDialog.openWarning(fMCUcombo.getShell(), title, text);
}

From source file:de.jcup.egradle.eclipse.EGradleMessageDialogSupport.java

License:Apache License

public void showWarning(String message) {
    EGradleUtil.safeAsyncExec(new Runnable() {

        @Override//from   w  ww. ja va 2  s.  c om
        public void run() {
            Shell shell = getActiveWorkbenchShell();
            MessageDialog.openWarning(shell, "EGradle", message);
        }

    });

}

From source file:de.jcup.egradle.eclipse.ide.EGradleMessageDialogSupport.java

License:Apache License

public void showWarning(String message) {
    EclipseUtil.safeAsyncExec(new Runnable() {

        @Override//w  ww .  j  a v  a 2 s  .  co m
        public void run() {
            Shell shell = getActiveWorkbenchShell();
            MessageDialog.openWarning(shell, "EGradle", message);
        }

    });

}

From source file:de.ovgu.cide.tools.featureview.FeatureView.java

License:Open Source License

private void makeActions() {
    filterAction = new AbstractToggleProjectionAction() {
        public void run() {
            redraw();/*from w w w  .  j  a v a 2  s .  c om*/
        }
    };

    selectAllAction = new ToggleAllFeatureVisibility(featureModel, true) {
        @Override
        public void run() {
            for (IFeature feature : featureModel.getFeatures()) {
                feature.setVisible(visible);
            }
            updateValidPanel();
        }
    };
    ColoredIDEImages.setImageDescriptors(selectAllAction, ColoredIDEImages.CHECKED_IMAGE);

    selectNoneAction = new ToggleAllFeatureVisibility(featureModel, false) {
        @Override
        public void run() {
            for (IFeature feature : featureModel.getFeatures()) {
                feature.setVisible(visible);
            }
            updateValidPanel();
        }
    };
    ColoredIDEImages.setImageDescriptors(selectNoneAction, ColoredIDEImages.UNCHECKED_IMAGE);

    renameAction = new Action("Rename...") {
        public void run() {
            IFeature feature = getSelectedFeature();
            if (feature == null)
                return;

            String oldName = feature.getName();

            InputDialog input = new InputDialog(getSite().getShell(), "Rename IFeature", "New name:", oldName,
                    new IInputValidator() {
                        public String isValid(String newText) {
                            if (newText.length() == 0)
                                return "Name must not be empty";
                            return null;
                        }
                    });
            if (input.open() == InputDialog.OK)
                try {
                    feature.setName(input.getValue());
                } catch (UnsupportedOperationException e) {
                    // nothing yet. TODO prevent renaming features that
                    // cannot
                    // be renamed
                }
        }
    };
    renameAction.setToolTipText("Rename IFeature");
    renameAction.setAccelerator(SWT.F2);

    selectColorAction = new Action("Select color...") {
        @Override
        public void run() {
            IFeature feature = getSelectedFeature();
            if (feature == null)
                return;

            RGB oldColor = feature.getRGB();
            ColorDialog colorDialog = new ColorDialog(getSite().getShell());
            colorDialog.setRGB(oldColor);
            colorDialog.setText("Color for IFeature \"" + feature.getName() + "\"");
            RGB newColor = colorDialog.open();
            if (newColor != null && newColor != oldColor)
                try {
                    feature.setRGB(newColor);
                } catch (UnsupportedOperationException e) {
                    // nothing yet. TODO prevent renaming features that
                    // cannot be renamed
                }

        }
    };
    findFeatureCodeAction = new Action("Find feature's code") {
        @Override
        public void run() {
            MessageDialog.openWarning(getSite().getShell(), "Error", "not implemented yet");
            super.run();
        }
    };
}