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

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

Introduction

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

Prototype

public static boolean open(int kind, Shell parent, String title, String message, int style) 

Source Link

Document

Convenience method to open a simple dialog as specified by the kind flag.

Usage

From source file:de.ovgu.featureide.ahead.actions.ChangeComposerAction.java

License:Open Source License

private boolean openDialog() {
    return MessageDialog.open(MessageDialog.WARNING,
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Composer Conversion",
            "Source files will be changed automatically. FeatureHouse suppors Java 5 and AHEAD Java 4, this can cause problems during converion. You should have a copy of this project.",
            SWT.NONE);/*from  w w w . ja va  2 s .  c  om*/

}

From source file:de.ovgu.featureide.core.conversion.ahead_featurehouse.handlers.ChangeComposerHandler.java

License:Open Source License

@Override
protected boolean startAction(IStructuredSelection selection) {
    return MessageDialog.open(MessageDialog.WARNING,
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), COMPOSER_CONVERSION,
            SOURCE_FILES_WILL_BE_CHANGED_AUTOMATICALLY__FEATUREHOUSE_SUPPORS_JAVA_5_AND_AHEAD_JAVA_4_COMMA__THIS_CAN_CAUSE_PROBLEMS_DURING_CONVERION__YOU_SHOULD_HAVE_A_COPY_OF_THIS_PROJECT_,
            SWT.NONE);/*from  w ww . ja v  a2 s  .c  o  m*/
}

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

License:Open Source License

private boolean canDeleteEPackage(Object targetObject, EPackage ePackage) {
    Module rootModel = (Module) ((EditPart) targetObject).getParent().getParent().getModel();
    String errMsg = ModelUtil.getEPackageReferences(ePackage, rootModel);

    if (errMsg != null) {
        MessageDialog.open(MessageDialog.INFORMATION, null, "Delete Failed", "EPackage [" + ePackage.getName()
                + "] is used in:\n\n" + errMsg + "\n\nPlease delete all references first.", SWT.NONE);
        return false;
    }//from w  ww. ja va2 s.c  o  m

    return true;
}

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

License:Open Source License

@Override
public void run() {
    ResourceDialog dialog = new ResourceDialog(getWorkbenchPart().getSite().getShell(),
            "Please select a file name: ", SWT.SAVE + SWT.SINGLE);

    // FileDialog dialog = new FileDialog(shell);
    // dialog.setFilterExtensions(new String[]{"*.ecore"});

    // dialog.//from w  w  w. j  a v  a2  s  .  c  o m
    int p = dialog.open();

    if (p == SWT.CANCEL || p == 1) {
        // MessageDialog.open(
        // SWT.ERROR,
        // PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite().getShell(),
        // "Cannot save instance graph.",
        // "Please select a valid file name.", SWT.SHEET);
        return;
    }

    List<URI> urIs = dialog.getURIs();

    if (urIs.isEmpty()) {
        MessageDialog.open(SWT.ERROR,
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite()
                        .getShell(),
                "Cannot save instance graph.", "Please select a valid file name.", SWT.SHEET);
        return;
    }

    // for (URI uri : urIs) {
    try {

        EMFModelManager modelManager = EMFModelManager.createModelManager("");
        Path path = new Path(urIs.get(0).toPlatformString(true));
        //         List<EObject> obj = modelManager.load(path,new LinkedList<EObject>());
        HenshinEGraph gr = new HenshinEGraph(graph);

        //         obj.addAll(gr.getRoots());
        for (EObject eObject : gr.getRoots()) {
            EList<EStructuralFeature> features = eObject.eClass().getEAllStructuralFeatures();
            for (EStructuralFeature feature : features) {
                if (feature.getDefaultValueLiteral() == null) {
                    ((EStructuralFeatureImpl) feature).setDefaultValueLiteral("");
                }
            }
        }
        try {

            modelManager.save(path, gr.getRoots().toArray(new EObject[0]));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        for (EObject eObject : gr.getRoots()) {
            EList<EStructuralFeature> features = eObject.eClass().getEAllStructuralFeatures();
            for (EStructuralFeature feature : features) {
                if (feature.getDefaultValueLiteral() == null) {
                    feature.setDefaultValueLiteral(null);
                }
            }
        }

        //         EMFModelManager modelManager = new EMFModelManager("");
        //         URI uri = urIs.get(0);
        //         Path path = uri.isPlatform() ? new Path(urIs.get(0)
        //               .toPlatformString(true)) : new Path(uri.toFileString());
        //         List<EObject> obj = modelManager.load(path,
        //               new LinkedList<EObject>());
        //         HenshinGraph gr = new HenshinGraph(graph);
        //
        //         obj.addAll(gr.getRootObjects());
        //         for (EObject eObject : gr.getRootObjects()) {
        //            EList<EStructuralFeature> features = eObject.eClass()
        //                  .getEAllStructuralFeatures();
        //            for (EStructuralFeature feature : features) {
        //               if (feature.getDefaultValueLiteral() == null) {
        //                  ((EStructuralFeatureImpl) feature)
        //                        .setDefaultValueLiteral("");
        //               }
        //            }
        //         }
        //         try {
        //
        //            modelManager.save(path, uri.isPlatform());
        //         } catch (IOException e) {
        //            e.printStackTrace();
        //         }
        //         for (EObject eObject : gr.getRootObjects()) {
        //            EList<EStructuralFeature> features = eObject.eClass()
        //                  .getEAllStructuralFeatures();
        //            for (EStructuralFeature feature : features) {
        //               if (feature.getDefaultValueLiteral() == null) {
        //                  feature.setDefaultValueLiteral(null);
        //               }
        //            }
        //         }
        //
        //          }
        //          resourceSet.getURIConverter().getURIMap().put(uri,
        //          URI.createFileURI(p));
    } catch (NullPointerException ex) {
        MessageDialog.open(SWT.ERROR,
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite()
                        .getShell(),
                "Cannot save instance graph.", "Please select a valid file name.", SWT.SHEET);

    }
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from  www. ja  va  2 s .co  m
public void run() {
    Shell shell = new Shell();
    ResourceDialog dialog = new ResourceDialog(shell, "Please select the instance model you want to load.",
            SWT.OPEN + SWT.MULTI);

    HashMap<EObject, Node> instanceGraphToHenshinGraphMapping = new HashMap<EObject, Node>();

    int p = dialog.open();

    if (p == 1) {
        return;
    }

    List<URI> urIs = dialog.getURIs();
    shell.dispose();

    if (urIs.isEmpty()) {
        MessageDialog.open(SWT.ERROR,
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite()
                        .getShell(),
                "No File selected.", "Please select a valid emf file to load an instance model.", SWT.SHEET);
        return;
    }

    for (URI uri : urIs) {
        ResourceImpl r = (ResourceImpl) transformationSystem.eResource().getResourceSet().getResource(uri,
                true);
        r.unload();
        try {
            r.load(null);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Graph graph = HenshinFactory.eINSTANCE.createGraph();

        if (r.getContents().isEmpty())
            continue;
        TreeIterator<EObject> itr = r.getAllContents();
        graph.setName(uri.segment(uri.segmentCount() - 1));

        while (itr.hasNext()) {
            EObject eObj = itr.next();
            Node node = HenshinFactory.eINSTANCE.createNode();
            node.setType(eObj.eClass());
            node.setName("");
            instanceGraphToHenshinGraphMapping.put(eObj, node);
            graph.getNodes().add(node);
        }
        itr = r.getAllContents();
        while (itr.hasNext()) {
            EObject eObj = itr.next();
            Node node = instanceGraphToHenshinGraphMapping.get(eObj);
            for (EStructuralFeature feat : eObj.eClass().getEAllStructuralFeatures()) {
                if (eObj.eIsSet(feat)) {
                    if (feat instanceof EReference) {
                        if (feat.isMany()) {
                            List<EObject> list = (List<EObject>) eObj.eGet(feat);
                            for (EObject ref : list) {
                                Edge edge = HenshinFactory.eINSTANCE.createEdge();
                                edge.setSource(node);
                                if (instanceGraphToHenshinGraphMapping.containsKey(ref)) {
                                    edge.setTarget(instanceGraphToHenshinGraphMapping.get(ref));
                                } else {
                                    edge.setTarget(createTargetNode(ref, graph));
                                }
                                edge.setType((EReference) feat);
                                graph.getEdges().add(edge);
                            }
                        } else {
                            EObject ref = (EObject) eObj.eGet(feat);
                            Edge edge = HenshinFactory.eINSTANCE.createEdge();
                            edge.setSource(node);
                            if (instanceGraphToHenshinGraphMapping.containsKey(ref)) {
                                edge.setTarget(instanceGraphToHenshinGraphMapping.get(ref));
                            } else {
                                edge.setTarget(createTargetNode(ref, graph));
                            }
                            edge.setType((EReference) feat);
                            graph.getEdges().add(edge);
                        }
                    } else if (feat instanceof EAttribute) {
                        if (feat.isMany()) {
                            // cannot handle array attributes right now
                        } else {
                            Attribute attr = HenshinFactory.eINSTANCE.createAttribute();
                            attr.setNode(node);
                            attr.setType((EAttribute) feat);
                            attr.setValue(eObj.eGet(feat).toString());
                            if (attr.getType().getName().contains("name") && !(eObj instanceof NamedElement)) {
                                node.setName(attr.getValue());
                            }
                        }
                    }
                }
            }
        }

        LinkedList<Layout> layouts = new LinkedList<Layout>();

        for (Node n : graph.getNodes()) {
            NodeLayout l = HenshinLayoutFactory.eINSTANCE.createNodeLayout();

            l.setModel(n);

            Point loc = NodeUtil.calculatePosition(NodeUtil.getPoints2NodeLyouts(n, layouts), l);

            l.setX(loc.x);
            l.setY(loc.y);

            layouts.add(l);
        }

        CompoundCommand cmd = new CompoundCommand("Import Instance Graph");
        LayoutSystem layoutSystem = HenshinLayoutUtil.INSTANCE.getLayoutSystem(transformationSystem);

        for (Layout l : layouts) {
            cmd.add(new SimpleAddEObjectCommand<EObject, EObject>(l,
                    HenshinLayoutPackage.LAYOUT_SYSTEM__LAYOUTS, layoutSystem));
        }

        cmd.add(new SimpleAddEObjectCommand<EObject, EObject>(graph, HenshinPackage.MODULE__INSTANCES,
                transformationSystem));

        execute(cmd);
    }
}

From source file:de.tub.tfs.henshin.editor.editparts.graph.graphical.GraphEditPart.java

License:Open Source License

@Override
protected IFigure createFigure() {
    FreeformLayer layer = new FreeformLayer();
    layer.setLayoutManager(new FreeformLayout());
    ConnectionLayer cLayer = (ConnectionLayer) getLayer(LayerConstants.CONNECTION_LAYER);
    cLayer.setAntialias(SWT.ON);/*  w w w .j  a  va 2 s . c om*/
    EdgeConnectionRouter edgeRouter = new EdgeConnectionRouter(layer);
    if (this.getCastedModel().getEdges().size() > 1000) {
        edgeRouter.setNextRouter(ConnectionRouter.NULL);

        MessageDialog.open(MessageDialog.INFORMATION, Display.getDefault().getActiveShell(), "Information",
                "The graph has too many edges. Therefore the edges will not be drawn around nodes.", SWT.SHEET);

    }
    cLayer.setConnectionRouter(edgeRouter);

    return layer;
}

From source file:de.tub.tfs.henshin.tggeditor.actions.exports.ExportInstanceModelAction.java

License:Open Source License

@Override
public void run() {
    Shell shell = new Shell();
    ResourceDialog dialog = new ResourceDialog(shell, "Please select a file name for the instance graph.",
            SWT.SAVE + SWT.SINGLE);//from   w  w  w. j  a  v a  2  s . c  o m

    //FileDialog dialog = new FileDialog(shell);
    //dialog.setFilterExtensions(new String[]{"*.ecore"});

    //dialog.
    int p = dialog.open();
    if (p == SWT.CANCEL || p == 1) {
        MessageDialog.open(SWT.ERROR,
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite()
                        .getShell(),
                "Cannot save instance graph.", "Please select a valid file name.", SWT.SHEET);
        return;
    }
    List<URI> urIs = dialog.getURIs();
    if (urIs.isEmpty()) {
        MessageDialog.open(SWT.ERROR,
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite()
                        .getShell(),
                "Cannot save instance graph.", "Please select a valid file name.", SWT.SHEET);
        return;
    }
    //for (URI uri : urIs) {
    try {

        EMFModelManager modelManager = EMFModelManager.createModelManager("");
        Path path = new Path(urIs.get(0).toPlatformString(true));
        //      List<EObject> obj = modelManager.load(path,new LinkedList<EObject>());
        HenshinEGraph gr = new HenshinEGraph(graph);

        //      obj.addAll(gr.getRoots());
        for (EObject eObject : gr.getRoots()) {
            EList<EStructuralFeature> features = eObject.eClass().getEAllStructuralFeatures();
            for (EStructuralFeature feature : features) {
                if (feature.getDefaultValueLiteral() == null) {
                    ((EStructuralFeatureImpl) feature).setDefaultValueLiteral("");
                }
            }
        }
        try {

            modelManager.save(path, gr.getRoots().toArray(new EObject[0]));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        for (EObject eObject : gr.getRoots()) {
            EList<EStructuralFeature> features = eObject.eClass().getEAllStructuralFeatures();
            for (EStructuralFeature feature : features) {
                if (feature.getDefaultValueLiteral() == null) {
                    feature.setDefaultValueLiteral(null);
                }
            }
        }

        //}   
        //resourceSet.getURIConverter().getURIMap().put(uri, URI.createFileURI(p));
    } catch (NullPointerException ex) {
        MessageDialog.open(SWT.ERROR,
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite()
                        .getShell(),
                "Cannot save instance graph.", "Please select a valid file name.", SWT.SHEET);

    }
    shell.dispose();

    super.run();
}

From source file:de.tub.tfs.henshin.tggeditor.actions.imports.ImportInstanceModelAction.java

License:Open Source License

/**
 * @return//  w  ww .  ja  va2  s.co m
 */
protected boolean openImportDialog() {
    shell = new Shell();
    ResourceDialog dialog = new ResourceDialog(shell, "Please select the instance model you want to load.",
            SWT.OPEN + SWT.MULTI);

    int p = dialog.open();
    if (p == 1 || p == SWT.CANCEL) {
        if (p == 1) {
            MessageDialog.open(SWT.ERROR,
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart()
                            .getSite().getShell(),
                    "No File selected.", "Please select a valid emf file to load an instance model.",
                    SWT.SHEET);
        }
        return false;
    }
    urIs = dialog.getURIs();
    if (urIs.isEmpty()) {
        MessageDialog.open(SWT.ERROR,
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite()
                        .getShell(),
                "No File selected.", "Please select a valid emf file to load an instance model.", SWT.SHEET);
        return false;
    }
    return true;
}

From source file:de.tub.tfs.henshin.tggeditor.actions.imports.ImportTargetInstanceModelAction.java

License:Open Source License

/**
 * @return//w w  w .j a  va  2s .c o  m
 */
protected boolean openImportDialog() {
    shell = new Shell();
    ResourceDialog dialog = new ResourceDialog(shell, "Please select the instance model you want to load.",
            SWT.OPEN + SWT.MULTI);

    int p = dialog.open();
    if (p == 1 || p == SWT.CANCEL) {
        MessageDialog.open(SWT.ERROR,
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite()
                        .getShell(),
                "No File selected.", "Please select a valid emf file to load an instance model.", SWT.SHEET);
        return false;
    }
    urIs = dialog.getURIs();
    if (urIs.isEmpty()) {
        MessageDialog.open(SWT.ERROR,
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite()
                        .getShell(),
                "No File selected.", "Please select a valid emf file to load an instance model.", SWT.SHEET);
        return false;
    }
    return true;
}

From source file:de.tub.tfs.henshin.tggeditor.editparts.graphical.GraphEditPart.java

License:Open Source License

@Override
protected IFigure createFigure() {
    FreeformLayer layer = new FreeformLayer() {

        @Override/*from w ww  .  j a  v  a2  s  .c  om*/
        protected void paintClientArea(Graphics graphics) {
            super.paintClientArea(graphics);
            Rectangle rect = getCorrectedBounds(this.getBounds(), this.getChildren(),
                    new HashSet<Class<? extends Figure>>(Arrays.asList(RectangleFigure.class)));

            if (tripleGraph.getDividerSC_X() == 0) {
                tripleGraph.setDividerSC_X(rect.width / 2 - rect.width / 8);
                tripleGraph.setDividerMaxY(rect.height - rect.y);
                tripleGraph.setDividerCT_X(rect.width / 2 + rect.width / 8);
                tripleGraph.setDividerMaxY(rect.height - rect.y);
            } else if (height != rect.height) {
                height = rect.height;
                if (rect.height + 20 - rect.y != tripleGraph.getDividerMaxY())
                    tripleGraph.setDividerMaxY(rect.height + 20 - rect.y);
            } else if (tripleGraph.getDividerMaxY() + rect.y > rect.height + 20) {
                if (rect.height + 20 - rect.y != tripleGraph.getDividerMaxY())
                    tripleGraph.setDividerMaxY(rect.height - 20 - rect.y);
            } else {
                if (rect.height + 20 - rect.y != tripleGraph.getDividerMaxY())
                    tripleGraph.setDividerMaxY(rect.height + 20 - rect.y);
            }
            if (rect.y != tripleGraph.getDividerYOffset())
                tripleGraph.setDividerYOffset(rect.y);
        }

        @Override
        public void paint(Graphics graphics) {
            graphics.pushState();
            String text = nameLabel.getText();
            graphics.setForegroundColor(TGGEditorConstants.FG_STANDARD_COLOR);
            TextLayout textLayout = new TextLayout(null);
            textLayout.setText(text);
            textLayout.setFont(TGGEditorConstants.TEXT_TITLE_FONT);
            graphics.drawTextLayout(textLayout, 5, 5);
            textLayout.dispose();

            graphics.popState();
            super.paint(graphics);

        }
    };
    layer.setLayoutManager(new TGGLayoutManager());
    nameLabel = new Label();
    nameLabel.setFont(TGGEditorConstants.TEXT_TITLE_FONT_SMALL);
    nameLabel.setForegroundColor(TGGEditorConstants.FG_STANDARD_COLOR);
    setFigureNameLabel();

    //layer.add(nameLabel, new Rectangle(10,10,-1,-1));

    ConnectionLayer cLayer = (ConnectionLayer) getLayer(LayerConstants.CONNECTION_LAYER);

    cLayer.setAntialias(SWT.ON);
    EdgeConnectionRouter edgeRouter = new EdgeConnectionRouter(layer);
    if (this.getCastedModel().getEdges().size() > 1000) {
        edgeRouter.setNextRouter(ConnectionRouter.NULL);
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                MessageDialog.open(MessageDialog.INFORMATION, Display.getDefault().getActiveShell(),
                        "Information",
                        "The graph has too many edges. Therefore the edges will not be drawn around nodes.",
                        SWT.SHEET);
            }
        });

    }
    cLayer.setConnectionRouter(edgeRouter);
    return layer;
}