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.ovgu.featureide.fm.ui.actions.AbstractImportAction.java

License:Open Source License

public void run(IAction action) {
    if (selection instanceof IStructuredSelection) {
        for (Iterator<?> it = ((IStructuredSelection) selection).iterator(); it.hasNext();) {
            Object element = it.next();
            IFile outputFile = null;//from   w  ww .java  2  s . co m
            if (element instanceof IFile) {

                outputFile = (IFile) element;

            } else if (element instanceof IAdaptable) {
                outputFile = (IFile) ((IAdaptable) element).getAdapter(IFile.class);
            }
            if (outputFile != null) {
                try {

                    boolean proceed = MessageDialog.openQuestion(new Shell(), "Warning!",
                            "This will override the current model irrepealable! Proceed?");
                    if (proceed) {

                        FileDialog fileDialog = new FileDialog(new Shell(), SWT.OPEN);
                        fileDialog.setOverwrite(false);

                        String filepath = fileDialog.open();
                        if (filepath == null)
                            return;
                        File inputFile = new File(filepath);

                        while (!inputFile.exists()) {
                            MessageDialog.openInformation(new Shell(), "File " + "not Found",
                                    "Specified file wasn't found");
                            inputFile = new File(fileDialog.open());
                        }

                        FeatureModel fm = new FeatureModel();
                        modelReader = setModelReader(fm);
                        modelReader.readFromFile(inputFile);
                        FeatureModelWriterIFileWrapper fmWriter = new FeatureModelWriterIFileWrapper(
                                new XmlFeatureModelWriter(fm));
                        fmWriter.writeToFile(outputFile);
                        outputFile.refreshLocal(IResource.DEPTH_ZERO, null);
                        openFileInEditor(outputFile);

                    }
                } catch (FileNotFoundException e) {
                    FMUIPlugin.getDefault().logError(e);
                } catch (UnsupportedModelException e) {
                    String errStr = e.getMessage();
                    MessageDialog.openWarning(new Shell(), "Warning!",
                            "Error while loading file: \n " + errStr);
                    FMUIPlugin.getDefault().logError(e);
                } catch (CoreException e) {
                    FMUIPlugin.getDefault().logError(e);
                }
            }
        }
    }
}

From source file:de.ovgu.featureide.fm.ui.handlers.base.AbstractImportHandler.java

License:Open Source License

@Override
protected final void singleAction(IFile outputFile) {
    final FileDialog fileDialog = new FileDialog(new Shell(), SWT.OPEN);
    fileDialog.setOverwrite(false);//  w ww.  j av a  2s  .c o m
    setFilter(fileDialog);

    File inputFile;
    while (true) {
        final String filepath = fileDialog.open();
        if (filepath == null) {
            return;
        }
        inputFile = new File(filepath);
        if (inputFile.exists()) {
            break;
        }
        MessageDialog.openInformation(new Shell(), FILE + NOT_FOUND, SPECIFIED_FILE_WASNT_FOUND);
    }

    final IFeatureModelFormat modelFormat = setModelReader();
    IFeatureModel fm = null;
    try {
        fm = FMFactoryManager.getFactory(inputFile.getAbsolutePath(), modelFormat).createFeatureModel();
    } catch (NoSuchExtensionException e) {
        FMCorePlugin.getDefault().logError(e);
    }
    if (fm != null) {
        final ProblemList errors = FileHandler.load(inputFile.toPath(), fm, modelFormat).getErrors();
        if (!errors.isEmpty()) {
            final StringBuilder sb = new StringBuilder("Error while loading file: \n");
            for (Problem problem : errors) {
                sb.append("Line ");
                sb.append(problem.getLine());
                sb.append(": ");
                sb.append(problem.getMessage());
                sb.append("\n");
            }
            MessageDialog.openWarning(new Shell(), "Warning!", sb.toString());
        } else {
            FileHandler.save(Paths.get(outputFile.getLocationURI()), fm, new XmlFeatureModelFormat());
            try {
                openFileInEditor(outputFile);
            } catch (PartInitException e) {
                FMUIPlugin.getDefault().logError(e);
            }
        }
    }
}

From source file:de.plugins.eclipse.depclipse.actions.SaveProjectRulesAction.java

License:Open Source License

public void run() {
    IRuleParser parser = DepclipsePlugin.getRuleParser();

    try {//  w ww .j ava  2 s  .  c  om
        parser.setProjectRules(file, DepclipsePlugin.getJDependData().getProjectRules());
    } catch (IOException e) {
        MessageDialog.openWarning(null, Messages.SaveProjectRulesAction_Error_saving_File,
                Messages.SaveProjectRulesAction_Please_check_your_permissions_to_write_this_file);
        DepclipsePlugin.handle(e);
    } catch (CoreException e) {
        MessageDialog.openWarning(null, Messages.SaveProjectRulesAction_Error_saving_File,
                Messages.SaveProjectRulesAction_Please_check_your_permissions_to_write_this_file);
        DepclipsePlugin.handle(e);
    }
}

From source file:de.quamoco.qm.diagram.part.QmDiagramEditor.java

License:Apache License

/**
 * @generated/*from w w w. j a  v  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.QmDiagramEditor_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.QmDiagramEditor_SaveAsErrorTitle,
                    Messages.QmDiagramEditor_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.QmDiagramEditor_SaveErrorTitle,
                    Messages.QmDiagramEditor_SaveErrorMessage, x.getStatus());
        }
    } finally {
        provider.changed(newInput);
        if (success) {
            setInput(newInput);
        }
    }
    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}

From source file:de.snertlab.xdccBee.tools.AbstractSaveDialog.java

License:Open Source License

protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OK_ID) {
        String msg = checkFields();
        if (StringUtils.isEmpty(msg)) {
            writeFields();/* w  w  w  . j a v a 2  s. c  o m*/
            super.buttonPressed(buttonId);
        } else {
            MessageDialog.openWarning(getShell(), "Fehler", msg);
        }
    } else {
        super.buttonPressed(buttonId);
    }
}

From source file:de.tobject.findbugs.actions.FilterPatternAction.java

License:Open Source License

public void run(IAction action) {
    Set<String> sortedIds = FindbugsPlugin.getFilteredIds();
    String patternType = getPatternOrPatternType();
    if (patternType != null) {
        if (!sortedIds.contains(patternType)) {
            sortedIds.add(patternType);/*from w w w.  j  av a2 s .co  m*/
        } else {
            sortedIds.remove(patternType);
        }
    }
    String ids = FindBugsConstants.encodeIds(sortedIds);
    final IPreferenceStore store = FindbugsPlugin.getDefault().getPreferenceStore();
    store.setValue(FindBugsConstants.LAST_USED_EXPORT_FILTER, ids);
    BugContentProvider provider = BugContentProvider.getProvider(navigator.getNavigatorContentService());
    if (!provider.isBugFilterActive()) {
        MessageDialog.openWarning(null, "Toggle Filter",
                "Filtering by pattern or type id is currently not enabled!\n"
                        + "To enable it, please select \"Toggle Filters...->Bugs by Id\" filter!");

    }
    provider.refreshFilters();
    CommonViewer viewer = navigator.getCommonViewer();
    Object[] expandedElements = viewer.getExpandedElements();
    viewer.refresh(true);
    viewer.setExpandedElements(expandedElements);
    data = null;
}

From source file:de.tobject.findbugs.actions.LoadXmlAction.java

License:Open Source License

@Override
public void run(final IAction action) {
    if (!(selection instanceof IStructuredSelection) || selection.isEmpty()) {
        return;//from  ww w .j  a v a  2  s.c  om
    }
    IStructuredSelection structuredSelection = (IStructuredSelection) selection;

    IProject project = getProject(structuredSelection);
    if (project == null) {
        return;
    }

    // Get the file name from a file dialog
    FileDialog dialog = createFileDialog(project);
    boolean validFileName = false;
    do {
        String fileName = openFileDialog(dialog);
        if (fileName == null) {
            // user cancel
            return;
        }
        validFileName = validateSelectedFileName(fileName);
        if (!validFileName) {
            MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Warning",
                    fileName + " is not a file or is not readable!");
            continue;
        }
        getDialogSettings().put(LOAD_XML_PATH_KEY, fileName);
        work(project, fileName);
    } while (!validFileName);
}

From source file:de.tobject.findbugs.actions.SaveXmlAction.java

License:Open Source License

@Override
public void run(final IAction action) {
    if (!(selection instanceof IStructuredSelection) || selection.isEmpty()) {
        return;/* ww  w .  ja va 2s .c o m*/
    }
    IStructuredSelection structuredSelection = (IStructuredSelection) selection;
    IProject project = getProject(structuredSelection);
    if (project == null) {
        return;
    }

    // Get the file name from a file dialog
    FileDialog fileDialog = createFileDialog(project);
    boolean validFileName = false;
    do {
        String fileName = openFileDialog(fileDialog);
        if (fileName == null) {
            // User cancelled
            break;
        }
        validFileName = validateSelectedFileName(fileName);
        if (!validFileName) {
            MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Warning",
                    fileName + " is not a file or is not writable!");
            continue;
        }
        if (new File(fileName).exists()) {
            if (!MessageDialog.openQuestion(Display.getDefault().getActiveShell(), "Warning",
                    fileName + " already exists. Override?")) {
                continue;
            }
        }
        getDialogSettings().put(SAVE_XML_PATH_KEY, fileName);
        work(project, fileName);
    } while (!validFileName);
}

From source file:de.tub.tfs.henshin.editor.actions.transSys.DeleteEPackageAction.java

License:Open Source License

@Override
public void run() {
    StringBuffer errMsg = new StringBuffer();

    for (EPackage model : models) {
        List<NamedElement> refs = HenshinUtil.INSTANCE.getEPackageReferences(model, rootModel);

        for (NamedElement ref : refs) {
            errMsg.append("  '" + model.getName() + "' is referenced by '" + ref.getName()
                    + (ref instanceof Graph ? "' (Graph).\n" : "' (Rule).\n"));
        }/*from  w w w  .  ja v  a  2s. c o  m*/
    }

    if (!errMsg.toString().isEmpty()) {
        MessageDialog.openWarning(getWorkbenchPart().getSite().getShell(), "EPackage Deletion Warning",
                "Some package(s) will not be deleted, due to following references:\n\n" + errMsg.toString()
                        + "\nPlease remove all references first.");
    }

    super.run();
}

From source file:de.tud.cs.st.vespucci.vespucci_model.diagram.part.VespucciDiagramEditor.java

License:Open Source License

/**
 * @generated/*from   w  w  w  .j a  v  a2  s .  c  o  m*/
 */
@Override
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(
                de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.VespucciDiagramEditor_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,
                    de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.VespucciDiagramEditor_SaveAsErrorTitle,
                    de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.VespucciDiagramEditor_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,
                    de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.VespucciDiagramEditor_SaveErrorTitle,
                    de.tud.cs.st.vespucci.vespucci_model.diagram.part.Messages.VespucciDiagramEditor_SaveErrorMessage,
                    x.getStatus());
        }
    } finally {
        provider.changed(newInput);
        if (success) {
            setInput(newInput);
        }
    }
    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}