Search in sources :

Example 1 with IGeneratorDescriptor

use of org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor in project statecharts by Yakindu.

the class SGenTemplateProposalProvider method createFeatureConfigurationTemplates.

private void createFeatureConfigurationTemplates(TemplateContext templateContext, ContentAssistContext context, ITemplateAcceptor acceptor) {
    GeneratorModel model = (GeneratorModel) EcoreUtil2.getRootContainer(context.getCurrentModel());
    IGeneratorDescriptor generatorDescriptor = GeneratorExtensions.getGeneratorDescriptor(model.getGeneratorId());
    Iterable<ILibraryDescriptor> libraryDescriptor = LibraryExtensions.getLibraryDescriptors(generatorDescriptor.getLibraryIDs());
    for (ILibraryDescriptor desc : libraryDescriptor) {
        ResourceSet set = new ResourceSetImpl();
        Resource resource = set.getResource(desc.getURI(), true);
        FeatureTypeLibrary lib = (FeatureTypeLibrary) resource.getContents().get(0);
        EList<FeatureType> types = lib.getTypes();
        for (FeatureType featureType : types) {
            Template template = new Template(featureType.getName() + " feature", "Creates feature " + featureType.getName(), featureType.getName(), creator.createProposal(featureType, desc.createFeatureValueProvider(SGenActivator.getInstance().getInjector(SGenActivator.ORG_YAKINDU_SCT_GENERATOR_GENMODEL_SGEN)), context.getCurrentModel()), false);
            TemplateProposal proposal = createProposal(template, templateContext, context, getImage(template), getRelevance(template));
            acceptor.accept(proposal);
        }
    }
}
Also used : TemplateProposal(org.eclipse.jface.text.templates.TemplateProposal) FeatureType(org.yakindu.sct.model.sgen.FeatureType) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) FeatureTypeLibrary(org.yakindu.sct.model.sgen.FeatureTypeLibrary) Resource(org.eclipse.emf.ecore.resource.Resource) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ILibraryDescriptor(org.yakindu.sct.generator.core.extensions.ILibraryDescriptor) Template(org.eclipse.jface.text.templates.Template)

Example 2 with IGeneratorDescriptor

use of org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor in project statecharts by Yakindu.

the class SGenWizardPage2 method createGeneratorCombo.

private void createGeneratorCombo(Composite container) {
    Label lblGenerator = new Label(container, SWT.NONE);
    lblGenerator.setText("Generator");
    generatorCombo = new ComboViewer(container, SWT.READ_ONLY);
    generatorCombo.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    generatorCombo.setLabelProvider(new GeneratorDescriptorLabelProvider());
    generatorCombo.setContentProvider(new ArrayContentProvider());
    List<IGeneratorDescriptor> descriptors = Lists.newArrayList(GeneratorExtensions.getGeneratorDescriptors());
    Collections.sort(descriptors, CoreGenerator.generatorOrder);
    generatorCombo.setInput(descriptors);
    generatorCombo.getCombo().select(0);
    generatorCombo.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            refreshInput();
        }
    });
}
Also used : ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor)

Example 3 with IGeneratorDescriptor

use of org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor in project statecharts by Yakindu.

the class SGenWizardPage2 method loadReferencedObject.

protected EObject loadReferencedObject(IResource resource) {
    URI uri = URI.createPlatformResourceURI(resource.getFullPath().toString(), true);
    ResourceSet resourceSet = new ResourceSetImpl();
    Resource emfResource = resourceSet.getResource(uri, true);
    IGeneratorDescriptor desc = getSelectedGenerator();
    String className = desc.getElementRefType();
    TreeIterator<EObject> content = emfResource.getAllContents();
    List<EObject> contentList = Lists.newArrayList(content);
    for (EObject obj : contentList) {
        if (obj.eClass().getInstanceClassName().equals(className))
            return obj;
    }
    for (EObject obj : contentList) {
        List<EClass> superClasses = obj.eClass().getEAllSuperTypes();
        for (EClass superClass : superClasses) {
            if (superClass.getInstanceClassName().equals(className)) {
                return obj;
            }
        }
    }
    return null;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) EObject(org.eclipse.emf.ecore.EObject) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) URI(org.eclipse.emf.common.util.URI)

Example 4 with IGeneratorDescriptor

use of org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor in project statecharts by Yakindu.

the class SGenScopeProvider method scope_GeneratorEntry_elementRef.

protected IScope scope_GeneratorEntry_elementRef(final EObject context, final EReference reference) {
    GeneratorModel generatorModel = (GeneratorModel) EcoreUtil2.getRootContainer(context);
    String id = generatorModel.getGeneratorId();
    final IGeneratorDescriptor desc = GeneratorExtensions.getGeneratorDescriptor(id);
    if (desc == null)
        return IScope.NULLSCOPE;
    final String elementRefType = desc.getElementRefType();
    IScope scope = new FilteringScope(getDelegate().getScope(context, reference), new Predicate<IEObjectDescription>() {

        public boolean apply(IEObjectDescription input) {
            EList<EClass> allSuperTypes = input.getEClass().getESuperTypes();
            for (EClass eClass : allSuperTypes) {
                if (elementRefType.equals(eClass.getInstanceClassName()))
                    return true;
            }
            return elementRefType.equals(input.getEClass().getInstanceClassName());
        }
    });
    return new SimpleScope(scope.getAllElements());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EList(org.eclipse.emf.common.util.EList) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) IScope(org.eclipse.xtext.scoping.IScope) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 5 with IGeneratorDescriptor

use of org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor in project statecharts by Yakindu.

the class SGenScopeProvider method getLibraryScope.

protected SimpleScope getLibraryScope(Resource resource) {
    GeneratorModel generatorModel = (GeneratorModel) EcoreUtil.getObjectByType(resource.getContents(), SGenPackage.Literals.GENERATOR_MODEL);
    Assert.isNotNull(generatorModel);
    String generatorId = generatorModel.getGeneratorId();
    IGeneratorDescriptor generatorDescriptor = GeneratorExtensions.getGeneratorDescriptor(generatorId);
    Iterable<IEObjectDescription> allElements = Lists.newArrayList();
    if (generatorDescriptor != null) {
        Iterable<ILibraryDescriptor> libraryDescriptor = LibraryExtensions.getLibraryDescriptors(generatorDescriptor.getLibraryIDs());
        for (ILibraryDescriptor desc : libraryDescriptor) {
            Resource library = resourceSet.getResource(desc.getURI(), true);
            FeatureResourceDescription description = new FeatureResourceDescription(library);
            injector.injectMembers(description);
            allElements = Iterables.concat(allElements, description.getExportedObjects());
        }
    }
    return new SimpleScope(allElements);
}
Also used : FeatureResourceDescription(org.yakindu.sct.generator.genmodel.resource.FeatureResourceDescription) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) Resource(org.eclipse.emf.ecore.resource.Resource) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) ILibraryDescriptor(org.yakindu.sct.generator.core.extensions.ILibraryDescriptor)

Aggregations

IGeneratorDescriptor (org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor)15 GeneratorModel (org.yakindu.sct.model.sgen.GeneratorModel)10 Resource (org.eclipse.emf.ecore.resource.Resource)6 ILibraryDescriptor (org.yakindu.sct.generator.core.extensions.ILibraryDescriptor)6 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 Check (org.eclipse.xtext.validation.Check)4 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)3 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)3 FeatureType (org.yakindu.sct.model.sgen.FeatureType)3 IResource (org.eclipse.core.resources.IResource)2 EClass (org.eclipse.emf.ecore.EClass)2 EObject (org.eclipse.emf.ecore.EObject)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 SimpleScope (org.eclipse.xtext.scoping.impl.SimpleScope)2 IDefaultFeatureValueProvider (org.yakindu.sct.generator.core.library.IDefaultFeatureValueProvider)2 FeatureResourceDescription (org.yakindu.sct.generator.genmodel.resource.FeatureResourceDescription)2 FeatureTypeLibrary (org.yakindu.sct.model.sgen.FeatureTypeLibrary)2 Injector (com.google.inject.Injector)1 IOException (java.io.IOException)1 IStatus (org.eclipse.core.runtime.IStatus)1