Search in sources :

Example 1 with Toolkit

use of org.obeonetwork.dsl.cinematic.toolkits.Toolkit in project InformationSystem by ObeoNetwork.

the class CinematicToolkitsServices method associateToolkit.

public static CinematicRoot associateToolkit(CinematicRoot root, Toolkit toolkit) {
    URI toolkitUri = EcoreUtil.getURI(toolkit);
    // Check if it's already associated
    for (Toolkit usedToolkit : root.getToolkits()) {
        if (EcoreUtil.getURI(usedToolkit).equals(toolkitUri)) {
            // already associated, do nothing and just return
            return root;
        }
    }
    // We now have to associate the toolkit to the root object
    ResourceSet set = root.eResource().getResourceSet();
    EObject newToolkit = set.getEObject(toolkitUri, true);
    if (newToolkit instanceof Toolkit) {
        root.getToolkits().add((Toolkit) newToolkit);
    }
    return root;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Toolkit(org.obeonetwork.dsl.cinematic.toolkits.Toolkit) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 2 with Toolkit

use of org.obeonetwork.dsl.cinematic.toolkits.Toolkit in project InformationSystem by ObeoNetwork.

the class CinematicToolkitsServices method getCinematicProvidedToolkits.

public static Collection<Toolkit> getCinematicProvidedToolkits(CinematicRoot cinematicRoot) {
    Collection<Toolkit> toolkits = new ArrayList<Toolkit>();
    Collection<URI> toolkitsURI = new ArrayList<URI>();
    Collection<Toolkit> alreadyUsedToolkits = new ArrayList<Toolkit>(cinematicRoot.getToolkits());
    // Get toolkits in ResourceSet
    Collection<Toolkit> toolkitsInResourceSet = getToolkitsInResourceSet(cinematicRoot);
    for (Toolkit toolkitInResourceSet : toolkitsInResourceSet) {
        // We do not propose the already used toolkits
        if (!alreadyUsedToolkits.contains(toolkitInResourceSet)) {
            toolkits.add(toolkitInResourceSet);
            toolkitsURI.add(EcoreUtil.getURI(toolkitInResourceSet));
        }
    }
    // Get the already used toolkits URI which should not be proposed
    Collection<URI> alreadyUsedToolkitsURIs = new ArrayList<URI>();
    for (Toolkit usedToolkit : alreadyUsedToolkits) {
        alreadyUsedToolkitsURIs.add(EcoreUtil.getURI(usedToolkit));
    }
    // Get toolkits provided using the extension point
    Collection<URI> providedToolkitsURI = ToolkitsProvider.getProvidedToolkits();
    for (URI uri : providedToolkitsURI) {
        ResourceSet set = new ResourceSetImpl();
        Resource resource = set.getResource(uri, true);
        if (resource != null && resource.getContents() != null) {
            for (EObject root : resource.getContents()) {
                if (root instanceof Toolkit) {
                    Toolkit toolkit = (Toolkit) root;
                    URI toolkitURI = EcoreUtil.getURI(toolkit);
                    if (!toolkitsURI.contains(toolkitURI) && !alreadyUsedToolkitsURIs.contains(toolkitURI)) {
                        toolkits.add(toolkit);
                    }
                }
            }
        }
    }
    return toolkits;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) Resource(org.eclipse.emf.ecore.resource.Resource) Toolkit(org.obeonetwork.dsl.cinematic.toolkits.Toolkit) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 3 with Toolkit

use of org.obeonetwork.dsl.cinematic.toolkits.Toolkit in project InformationSystem by ObeoNetwork.

the class CinematicWidgetServices method getToolkitsFromWidget.

/**
 * Retrieve the list of toolkits and their widgets
 * @param context context
 * @param widgets
 *            the list of widgets that have the property isContainer set to
 *            true
 * @return list of toolkits and their widgets
 */
public List<EObject> getToolkitsFromWidget(EObject context, List<Widget> widgets) {
    List<Toolkit> toolkits = new ArrayList<Toolkit>();
    List<EObject> toolkitsAndWidgest = new ArrayList<EObject>();
    // Adds the associates toolkit to widget
    for (Widget widget : widgets) {
        if (!toolkits.contains(widget.getToolkit())) {
            toolkits.add(widget.getToolkit());
        }
    }
    toolkitsAndWidgest.addAll(toolkits);
    toolkitsAndWidgest.addAll(widgets);
    return toolkitsAndWidgest;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) Widget(org.obeonetwork.dsl.cinematic.toolkits.Widget) Toolkit(org.obeonetwork.dsl.cinematic.toolkits.Toolkit)

Example 4 with Toolkit

use of org.obeonetwork.dsl.cinematic.toolkits.Toolkit in project InformationSystem by ObeoNetwork.

the class CinematicWidgetServices method getWidgetsIsContainer.

/**
 * Retrieves widgets that have the property isContainer set to true and
 * contained in the semantic element.
 *
 * @param context
 *            VSM context
 * @param semanticElement
 *            Semantic element
 */
public List<Widget> getWidgetsIsContainer(EObject context, EObject semanticElement) {
    List<Widget> widgetsIsContainer = new ArrayList<Widget>();
    CinematicRoot cinematicRoot = null;
    if (semanticElement instanceof CinematicRoot) {
        cinematicRoot = (CinematicRoot) semanticElement;
    } else {
        EObject element = semanticElement;
        while (!(element.eContainer() instanceof CinematicRoot)) {
            element = semanticElement.eContainer();
        }
        cinematicRoot = (CinematicRoot) element.eContainer();
    }
    List<Toolkit> toolkits = cinematicRoot.getToolkits();
    for (Toolkit toolkit : toolkits) {
        EList<Widget> widgets = toolkit.getWidgets();
        for (Widget widget : widgets) {
            if (widget.isIsContainer()) {
                widgetsIsContainer.add(widget);
            }
        }
    }
    return widgetsIsContainer;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Widget(org.obeonetwork.dsl.cinematic.toolkits.Widget) ArrayList(java.util.ArrayList) Toolkit(org.obeonetwork.dsl.cinematic.toolkits.Toolkit) CinematicRoot(org.obeonetwork.dsl.cinematic.CinematicRoot)

Example 5 with Toolkit

use of org.obeonetwork.dsl.cinematic.toolkits.Toolkit in project InformationSystem by ObeoNetwork.

the class CinematicWidgetServices method getWidgetsHavePropertyIsContainer.

/**
 * Return the widgets that have container property.
 *
 * @param context
 *            the ViewContainer
 * @return List of widgets that have property is Container set to true
 */
public List<Widget> getWidgetsHavePropertyIsContainer(EObject context) {
    List<Widget> widgetsIsContainer = new ArrayList<Widget>();
    CinematicRoot cinematicRoot = null;
    EObject container = null;
    if (context.eContainer() != null) {
        container = context.eContainer();
    } else {
        container = context;
    }
    while (container.eContainer() != null && !(container instanceof CinematicRoot)) {
        container = container.eContainer();
    }
    if (context instanceof CinematicRoot) {
        cinematicRoot = (CinematicRoot) context;
    } else if (container instanceof CinematicRoot) {
        cinematicRoot = (CinematicRoot) container;
    }
    if (cinematicRoot != null) {
        List<Toolkit> toolkits = cinematicRoot.getToolkits();
        if (toolkits.isEmpty()) {
            MessageDialog.openInformation(Display.getDefault().getActiveShell(), CREATE_VIEW_CONTAINER_TITLE, "No toolkit has been associated yet.\nPlease use the 'Associate toolkit' tool on the root level.");
        } else {
            for (Toolkit toolkit : toolkits) {
                for (Widget widget : toolkit.getWidgets()) {
                    if (widget.isIsContainer()) {
                        widgetsIsContainer.add(widget);
                    }
                }
            }
        }
    }
    return widgetsIsContainer;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Widget(org.obeonetwork.dsl.cinematic.toolkits.Widget) ArrayList(java.util.ArrayList) Toolkit(org.obeonetwork.dsl.cinematic.toolkits.Toolkit) CinematicRoot(org.obeonetwork.dsl.cinematic.CinematicRoot)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)5 Toolkit (org.obeonetwork.dsl.cinematic.toolkits.Toolkit)5 ArrayList (java.util.ArrayList)4 Widget (org.obeonetwork.dsl.cinematic.toolkits.Widget)3 URI (org.eclipse.emf.common.util.URI)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 CinematicRoot (org.obeonetwork.dsl.cinematic.CinematicRoot)2 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1