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

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

Introduction

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

Prototype

public MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage,
        int dialogImageType, int defaultIndex, String... dialogButtonLabels) 

Source Link

Document

Create a message dialog.

Usage

From source file:de.fraunhofer.esk.ernest.core.cdt.wizards.GenerateSimulationWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    /* Initializing */
    final String projName = this.page.getProjName();
    final String projPath = this.page.getLocation() + "/" + this.page.getProjName();
    final String projTool = "MinGW GCC";

    /* If Project/Folder with this name already exists in path, ask override question (message dialog) */
    if (new java.io.File(projPath).exists()) {
        final MessageDialog dg = new MessageDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), UI_USERMSG_TITLE, null,
                UI_USERMSG_EXISTQST, MessageDialog.QUESTION,
                new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
        /* override dialog returns
         * in case "yes" 0// w ww . j ava2s.  co m
         * in case "no" 1
         */
        if (dg.open() == 1) {
            return false;
        }
    }

    /*
     * ProgressMonitor, work parted in
     * 70% GenerateSimulationProject
     * 30% runGenerator
     */
    try {
        this.getContainer().run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(UI_MONITOR_MAINTASKNAME, 100000);
                /* Generate Project */
                if (!new GenerateSimulationProject().createSimulationProj(projName, projPath, monitor, 70000,
                        projTool)) {
                    return;
                }
                if (monitor.isCanceled()) {
                    return;
                }

                /* Execute Generator */
                try {
                    GenerateSimulationWizard.this.runGenerator(GenerateSimulationWizard.this.file, projPath,
                            monitor, 30000);
                } catch (CoreException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

                /* End Monitor */
                monitor.done();

            }
        });
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    return true;
}

From source file:de.loskutov.anyedit.actions.SaveToFileAction.java

License:Open Source License

/**
 * @param file/*from  w w w .  ja  va2 s.  c  om*/
 *            non null
 * @return OVERRIDE if file not exists or exists and may be overriden, APPEND if it
 *         exists and should be reused, CANCEL if action should be cancelled
 */
private int checkForExisting(File file) {
    if (file.exists()) {
        MessageDialog md = new MessageDialog(AnyEditToolsPlugin.getShell(), Messages.SaveTo_ShouldOpen, null,
                Messages.SaveTo_FileExists, MessageDialog.WARNING,
                new String[] { Messages.SaveTo_Append, Messages.SaveTo_Override, "Cancel" }, 0);
        int result = md.open();
        switch (result) {
        case APPEND: // Append btn index
            return APPEND;
        case OVERRIDE: // Override btn index
            return OVERRIDE;
        default:
            return CANCEL;
        }
    }
    return OVERRIDE;
}

From source file:de.loskutov.eclipse.jdepend.views.SaveToFileAction.java

License:Open Source License

/**
 * @param file/*w  w  w.j ava 2s  .  c om*/
 *            non null
 * @return OVERRIDE if file not exists or exists and may be overriden, APPEND if it
 *         exists and should be reused, CANCEL if action should be cancelled
 */
private int checkForExisting(File file) {
    if (file.exists()) {
        MessageDialog md = new MessageDialog(getShell(), "Warning: file already exist", null,
                "Warning: file already exist", MessageDialog.WARNING,
                new String[] { "Append", "Override", "Cancel" }, 0);
        int result = md.open();
        switch (result) {
        case APPEND: // Append btn index
            return APPEND;
        case OVERRIDE: // Override btn index
            return OVERRIDE;
        default:
            return CANCEL;
        }
    }
    return OVERRIDE;
}

From source file:de.ovgu.featureide.examples.wizards.ExampleNewWizardPage.java

License:Open Source License

/**
 * The <code>WizardDataTransfer</code> implementation of this
 * <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 * /*from   w  ww. j  a  va2s .c  om*/
 * @param pathString
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
 *         <code>"ALL"</code>, or <code>"CANCEL"</code>
 */
public String queryOverwrite(String pathString) {
    Path path = new Path(pathString);

    String messageString;
    // Break the message up if there is a file name and a directory
    // and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = pathString + " already exists. Would you like to overwrite it?";
    } else {
        messageString = "Overwrite " + path.lastSegment() + " in folder "
                + path.removeLastSegments(1).toOSString() + " ?";
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), "Question", null, messageString,
            MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0);

    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    getControl().getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:de.ovgu.featureide.fm.ui.editors.featuremodel.operations.DeleteAllOperation.java

License:Open Source License

@Override
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {

    featureList = new LinkedList<Feature>();
    containedFeatureList = new LinkedList<Feature>();
    LinkedList<Feature> list = new LinkedList<Feature>();
    list.add(feature);/*  ww  w . j  ava 2  s.  c o  m*/
    getFeaturesToDelete(list);

    if (containedFeatureList.isEmpty()) {
        for (Feature feat : featureList) {
            AbstractFeatureModelOperation op = new FeatureDeleteOperation(featureModel, feat);
            executeOperation(op);
            operations.add(op);
        }
    } else {
        final String containedFeatures = containedFeatureList.toString();
        MessageDialog dialog = new MessageDialog(new Shell(), " Delete Error ", FEATURE_SYMBOL,
                "The following features are contained in constraints:" + '\n'
                        + containedFeatures.substring(1, containedFeatures.length() - 1) + '\n' + '\n'
                        + "Unable to delete this features until all relevant constraints are removed.",
                MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);

        dialog.open();
    }
    return Status.OK_STATUS;
}

From source file:de.ovgu.featureide.fm.ui.editors.featuremodel.operations.DeleteOperation.java

License:Open Source License

/**
 * Opens an error dialog displaying the {@link Feature}s which could not be replaced by alternatives.
 * @param notDeletable The not deletable features
 */// w w w. j  a v a  2 s. com
private void openErrorDialog(List<Feature> notDeletable) {
    String notDeletedFeatures = null;
    for (Feature f : notDeletable) {
        if (notDeletedFeatures == null) {
            notDeletedFeatures = "\"" + f.getName() + "\"";
        } else {
            notDeletedFeatures += ", \"" + f.getName() + "\"";
        }
    }

    MessageDialog dialog = new MessageDialog(new Shell(), " Delete Error ", FEATURE_SYMBOL,
            ((notDeletable.size() != 1) ? "The following features are contained in constraints:"
                    : "The following feature is contained in constraints:")
                    + "\n" + notDeletedFeatures + "\n"
                    + ((notDeletable.size() != 1)
                            ? "Select only one feature in order to replace it with an equivalent one."
                            : "It can not be replaced with an equivalent one."),
            MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
    dialog.open();
}

From source file:de.ovgu.featureide.fm.ui.editors.featuremodel.operations.ElementDeleteOperation.java

License:Open Source License

/**
 * Opens an error dialog displaying the {@link Feature}s which could not be replaced by alternatives.
 * //from ww w.  jav  a2s .c o  m
 * @param notDeletable The not deletable features
 */
private void openErrorDialog(List<IFeature> notDeletable) {
    String notDeletedFeatures = null;
    for (IFeature f : notDeletable) {
        if (notDeletedFeatures == null) {
            notDeletedFeatures = "\"" + f.getName() + "\"";
        } else {
            notDeletedFeatures += ", \"" + f.getName() + "\"";
        }
    }

    MessageDialog dialog = new MessageDialog(new Shell(), DELETE_ERROR, FEATURE_SYMBOL,
            ((notDeletable.size() != 1) ? "The following features are contained in constraints:"
                    : "The following feature is contained in constraints:")
                    + "\n" + notDeletedFeatures + "\n"
                    + ((notDeletable.size() != 1)
                            ? SELECT_ONLY_ONE_FEATURE_IN_ORDER_TO_REPLACE_IT_WITH_AN_EQUIVALENT_ONE_
                            : IT_CAN_NOT_BE_REPLACED_WITH_AN_EQUIVALENT_ONE_),
            MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
    dialog.open();
}

From source file:de.ovgu.featureide.fm.ui.editors.featuremodel.operations.FeatureTreeDeleteOperation.java

License:Open Source License

@Override
protected void createSingleOperations() {
    featureList = new LinkedList<IFeature>();
    containedFeatureList = new LinkedList<IFeature>();
    LinkedList<IFeature> list = new LinkedList<IFeature>();
    list.add(feature);//from   ww w .j  a va2s . c  om
    getFeaturesToDelete(list);

    if (containedFeatureList.isEmpty()) {
        for (IFeature feat : featureList) {
            AbstractFeatureModelOperation op = new DeleteFeatureOperation(featureModel, feat);
            operations.add(op);
        }
    } else {
        final String containedFeatures = containedFeatureList.toString();
        MessageDialog dialog = new MessageDialog(new Shell(), DELETE_ERROR, FEATURE_SYMBOL,
                "The following features are contained in constraints:" + '\n'
                        + containedFeatures.substring(1, containedFeatures.length() - 1) + '\n' + '\n'
                        + UNABLE_TO_DELETE_THIS_FEATURES_UNTIL_ALL_RELEVANT_CONSTRAINTS_ARE_REMOVED_,
                MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);

        dialog.open();
    }
}

From source file:de.ovgu.featureide.fm.ui.GraphicsExporter.java

License:Open Source License

public static boolean exportAs(GraphicalViewerImpl viewer, File file) {
    boolean succ = false;

    if (file.getAbsolutePath().endsWith(".svg")) {
        ScalableFreeformRootEditPart part = (ScalableFreeformRootEditPart) viewer.getEditPartRegistry()
                .get(LayerManager.ID);/* w  w w  .j a v a  2 s .c  o m*/
        IFigure rootFigure = part.getFigure();
        Bundle bundleExportSVG = null;
        for (Bundle b : InternalPlatform.getDefault().getBundleContext().getBundles()) {
            if (b.getSymbolicName().equals("nl.utwente.ce.imageexport.svg")) {
                bundleExportSVG = b;
                break;
            }
        }

        // check if gef-imageexport is existing and activated!
        if (bundleExportSVG != null) {
            try {
                org.osgi.framework.BundleActivator act = ((org.osgi.framework.BundleActivator) bundleExportSVG
                        .loadClass("nl.utwente.ce.imagexport.export.svg.Activator").newInstance());
                act.start(InternalPlatform.getDefault().getBundleContext());

                Class<?> cl = bundleExportSVG.loadClass("nl.utwente.ce.imagexport.export.svg.ExportSVG");
                Method m = cl.getMethod("exportImage", String.class, String.class, IFigure.class);
                m.invoke(cl.newInstance(), "SVG", file.getAbsolutePath(), rootFigure);
                succ = true;
            } catch (Exception e) {
                FMUIPlugin.getDefault().logError(e);
            }
        } else {
            final String infoMessage = "Eclipse plugin for exporting diagram in SVG format is not existing."
                    + "\nIf you want to use this, you have to install GEF Imageexport with SVG in Eclipse from "
                    + "\nhttp://veger.github.com/eclipse-gef-imageexport";

            MessageDialog dialog = new MessageDialog(new Shell(), "SVG export failed",
                    FMUIPlugin.getImage("FeatureIconSmall.ico"), infoMessage, MessageDialog.INFORMATION,
                    new String[] { IDialogConstants.OK_LABEL }, 0);

            dialog.open();
            FMUIPlugin.getDefault().logInfo(infoMessage);
            return false;
        }
    } else {
        GEFImageWriter.writeToFile(viewer, file);
        succ = true;
    }

    GraphicsExporter.printExportMessage(file, succ);

    return succ;
}

From source file:de.ovgu.featureide.ui.actions.generator.configuration.SPLCAToolConfigurationGenerator.java

License:Open Source License

@SuppressWarnings("deprecation")
private void runSPLCATool() {
    CoveringArray ca = null;/*  w  w  w  .  ja  v a2  s  .  com*/
    final boolean casa = algorithm.equals(CASA.substring(0, CASA.indexOf(" ")));
    try {
        if (casa) {
            URL url = BundleUtility.find(UIPlugin.getDefault().getBundle(), "lib/cover.exe");
            try {
                url = FileLocator.toFileURL(url);
            } catch (IOException e) {
                UIPlugin.getDefault().logError(e);
            }
            Path path = new Path(url.getFile());
            CoveringArrayCASA.CASA_PATH = path.toOSString();
        }

        ca = new GUIDSL(new de.ovgu.featureide.fm.core.FeatureModel(featureModel)).getSXFM().getCNF()
                .getCoveringArrayGenerator(algorithm, t);
        if (ca == null) {
            return;
        }
        ca.generate();
    } catch (FeatureModelException | TimeoutException | CoveringArrayGenerationException e) {
        UIPlugin.getDefault().logError(e);
        return;
    } catch (final Exception e) {
        final Display display = Display.getDefault();
        display.syncExec(new Runnable() {
            @Override
            public void run() {
                final String errorMessage = algorithm + " experienced an error during its execution.\n" + (casa
                        ? "Maybe some dependent libraries are missing (e.g., libgcc_s_dw2-1.dll or libstdc++-6.dll)"
                        : "Message:\n\t" + e.getMessage());
                new MessageDialog(display.getActiveShell(), "External Execution Error",
                        GUIDefaults.FEATURE_SYMBOL, errorMessage, MessageDialog.ERROR, new String[] { OK }, 0)
                                .open();
            }
        });
        return;
    }

    List<List<String>> solutions = Collections.emptyList();
    try {
        solutions = removeDuplicates(ca);
    } catch (Exception e) {
        UIPlugin.getDefault().logWarning("Problems occurred during the execution of " + algorithm);
    }
    builder.configurationNumber = solutions.size();
    for (final List<String> solution : solutions) {
        configuration.resetValues();
        for (final String selection : solution) {
            configuration.setManual(selection, Selection.SELECTED);
        }
        addConfiguration(configuration);
    }
}