Search in sources :

Example 6 with ClasspathPersistenceProvider

use of org.whole.lang.codebase.ClasspathPersistenceProvider in project whole by wholeplatform.

the class E4ModelProcessor method initialize.

@Execute
protected void initialize() throws CoreException {
    try {
        ClasspathPersistenceProvider pp = new ClasspathPersistenceProvider("org/whole/product/e4/lw/WorkspaceConfiguration.xwl");
        InterpreterOperation.interpret(XmlBuilderPersistenceKit.instance().readModel(pp));
        MUIElement placeholderWindow = modelService.find(PLACEHOLDER_WINDOW_ID, application);
        if (placeholderWindow == null || !placeholderWindow.getParent().getChildren().remove(placeholderWindow))
            throw new IllegalStateException("Unable to remove placeholder window with id: '" + PLACEHOLDER_WINDOW_ID + "'");
        MTrimmedWindow window = MBasicFactory.INSTANCE.createTrimmedWindow();
        window.setLabel("Whole Language Workbench Window");
        window.setX(500);
        window.setY(20);
        window.setWidth(800);
        window.setHeight(1000);
        MMenu mainMenu = MMenuFactory.INSTANCE.createMenu();
        mainMenu.setElementId("menu:org.eclipse.ui.main.menu");
        mainMenu.getChildren().add(createFileMenu());
        mainMenu.getChildren().add(createEditMenu());
        mainMenu.getChildren().add(createHelpMenu());
        window.setMainMenu(mainMenu);
        MTrimBar trimBar = MBasicFactory.INSTANCE.createTrimBar();
        trimBar.setSide(SideValue.TOP);
        trimBar.getChildren().add(createToolBar());
        window.getTrimBars().add(trimBar);
        MPerspectiveStack perspectiveStack = MAdvancedFactory.INSTANCE.createPerspectiveStack();
        MPerspective perspective = MAdvancedFactory.INSTANCE.createPerspective();
        perspective.setLabel("P1");
        MPartSashContainer partSashContainer = MBasicFactory.INSTANCE.createPartSashContainer();
        partSashContainer.setHorizontal(false);
        MPartStack partStack = MBasicFactory.INSTANCE.createPartStack();
        MPart part = MBasicFactory.INSTANCE.createPart();
        part.setContributionURI("bundleclass://org.whole.lang.e4.ui/org.whole.lang.e4.ui.parts.E4GraphicalPart");
        part.setLabel("Part1a");
        part.setCloseable(true);
        Map<String, String> persistedState = part.getPersistedState();
        persistedState.put("basePersistenceKitId", "org.whole.lang.xml.codebase.XmlBuilderPersistenceKit");
        persistedState.put("filePath", "/BaseProject/src/org/whole/lang/ExampleModel.xwl");
        persistedState.put("overridePersistenceKitId", "org.whole.lang.xml.codebase.XmlBuilderPersistenceKit");
        partStack.getChildren().add(part);
        partSashContainer.getChildren().add(partStack);
        perspective.getChildren().add(partSashContainer);
        perspectiveStack.getChildren().add(perspective);
        window.getChildren().add(perspectiveStack);
        application.getChildren().add(window);
    } catch (Exception e) {
        System.out.println("Unable to configure the initial workspace");
        e.printStackTrace();
    }
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MPartStack(org.eclipse.e4.ui.model.application.ui.basic.MPartStack) MTrimBar(org.eclipse.e4.ui.model.application.ui.basic.MTrimBar) MPerspectiveStack(org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) CoreException(org.eclipse.core.runtime.CoreException) MPerspective(org.eclipse.e4.ui.model.application.ui.advanced.MPerspective) MTrimmedWindow(org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow) ClasspathPersistenceProvider(org.whole.lang.codebase.ClasspathPersistenceProvider) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) MPartSashContainer(org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 7 with ClasspathPersistenceProvider

use of org.whole.lang.codebase.ClasspathPersistenceProvider in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testLanguageTest.

@Test
public void testLanguageTest() throws Exception {
    IEntity model = XmlBuilderPersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/templates/codebase/TemplateManagerArtifactsTemplates.xwl"));
    QueriesEntityFactory ef = QueriesEntityFactory.instance;
    for (IEntity e : BehaviorUtils.compileAndLazyEvaluate(ef.createFilter(ef.createDescendantOrSelfStep(), ef.createLanguageTest("http://lang.whole.org/Java")), model)) Assert.assertEquals("http://lang.whole.org/Java", e.wGetLanguageKit().getURI());
}
Also used : IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) ClasspathPersistenceProvider(org.whole.lang.codebase.ClasspathPersistenceProvider) Test(org.junit.Test)

Example 8 with ClasspathPersistenceProvider

use of org.whole.lang.codebase.ClasspathPersistenceProvider in project whole by wholeplatform.

the class DynamicModelDefinitionTest method testModelsInterpreter.

@Test
public void testModelsInterpreter() {
    Model model;
    try {
        model = (Model) XmlBuilderPersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/queries/QueriesModel.xwl"));
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
    String URI = "http://my/uri/for/queries/lang";
    model.getUri().setValue(URI);
    ILanguageKit qlk = ReflectionFactory.getLanguageKit("http://lang.whole.org/Queries");
    EntityDescriptorEnum qedenum = qlk.getEntityDescriptorEnum();
    FeatureDescriptorEnum qfdenum = qlk.getFeatureDescriptorEnum();
    InterpreterOperation.interpret(model);
    ILanguageKit lk = ReflectionFactory.getLanguageKit(URI);
    assertNotNull(lk);
    assertNotSame(qlk, lk);
    assertNotNull(lk.getMetaModelTemplate());
    IEntity metaModel = lk.getMetaModel();
    IEntity normalizedModel = NormalizerOperation.normalize(model);
    assertTrue(Matcher.match(normalizedModel, metaModel));
    metaModel = lk.getMetaModelTemplate().create();
    assertTrue(Matcher.match(normalizedModel, metaModel));
    EntityDescriptorEnum edenum = lk.getEntityDescriptorEnum();
    FeatureDescriptorEnum fdenum = lk.getFeatureDescriptorEnum();
    assertFalse(qfdenum.equals(fdenum));
    assertEquals(qfdenum.size(), fdenum.size());
    for (FeatureDescriptor qfd : qfdenum) {
        assertEquals(qfd.getOrdinal(), fdenum.valueOf(qfd.getName()).getOrdinal());
    }
    assertFalse(qedenum.equals(edenum));
    assertEquals(qedenum.size(), edenum.size());
    for (EntityDescriptor<?> qed : qedenum) {
        EntityDescriptor<?> ed = edenum.valueOf(qed.getName());
        assertEquals(qed.getOrdinal(), ed.getOrdinal());
        assertEquals(qed.getEntityKind(), ed.getEntityKind());
        assertEquals(qed.isAbstract(), ed.isAbstract());
        assertEquals(qed.isRelationship(), ed.isRelationship());
        switch(qed.getEntityKind()) {
            case SIMPLE:
                assertEquals(qed.featureSize(), ed.featureSize());
                for (int i = 0, size = qed.featureSize(); i < size; i++) {
                    FeatureDescriptor qfd = qed.getEntityFeatureDescriptor(i);
                    FeatureDescriptor fd = ed.getEntityFeatureDescriptor(i);
                    assertEquals(qfd.getName(), fd.getName());
                    assertEquals(qfd.getImplName(), fd.getImplName());
                    assertEquals(qfd.getOrdinal(), fd.getOrdinal());
                    assertEquals(qfd.isDerived(), fd.isDerived());
                    assertEquals(qfd.isId(), fd.isId());
                    assertEquals(qfd.isOptional(), fd.isOptional());
                    assertEquals(qfd.isReference(), fd.isReference());
                    assertEquals(qfd.isShared(), fd.isShared());
                    assertEquals(qfd.isToMany(), fd.isToMany());
                    if (qfd.getOppositeFeatureDescriptor() != null)
                        assertEquals(qfd.getOppositeFeatureDescriptor().getName(), fd.getOppositeFeatureDescriptor().getName());
                }
                break;
            case COMPOSITE:
                assertEquals(qed.getCompositeKind(), ed.getCompositeKind());
                FeatureDescriptor qfd = qed.getEntityFeatureDescriptor(0);
                FeatureDescriptor fd = ed.getEntityFeatureDescriptor(0);
                assertEquals(qfd.isDerived(), fd.isDerived());
                assertEquals(qfd.isReference(), fd.isReference());
                assertEquals(qfd.isShared(), fd.isShared());
                break;
            case DATA:
                assertEquals(qed.getDataKind(), ed.getDataKind());
                if (qed.getDataKind().isEnumValue()) {
                    assertEquals(qed.getDataEnumType().size(), ed.getDataEnumType().size());
                    for (int i = 0; i < qed.getDataEnumType().size(); i++) assertEquals(qed.getDataEnumType().valueOf(i).getName(), ed.getDataEnumType().valueOf(i).getName());
                } else
                    assertEquals(qed.getDataType(), ed.getDataType());
                break;
        }
    }
}
Also used : CommonsFeatureDescriptorEnum(org.whole.lang.commons.reflect.CommonsFeatureDescriptorEnum) IEntity(org.whole.lang.model.IEntity) Model(org.whole.lang.models.model.Model) ClasspathPersistenceProvider(org.whole.lang.codebase.ClasspathPersistenceProvider) Test(org.junit.Test)

Example 9 with ClasspathPersistenceProvider

use of org.whole.lang.codebase.ClasspathPersistenceProvider in project whole by wholeplatform.

the class XsdLanguageTest method testArtifactsMappedModel.

@Category(KnownFailingTests.class)
@Test
public void testArtifactsMappedModel() {
    try {
        IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
        PathExpression path = new ModelToXmlSchemaQuery().create();
        IEntity model = XmlBuilderPersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/artifacts/ArtifactsModel.xwl"));
        Assert.assertNotNull(BehaviorUtils.evaluateFirstResult(path, model, bm));
        InterpreterOperation.interpret(bm.wGet("mapping"));
        bm.wDefValue("folderLocation", new File("test/org/whole/lang/xsd/util").getAbsolutePath());
        bm.wDefValue("packageName", "");
        IEntity artifacts = XsiPersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream("Artifacts.xml"), null, bm));
        Assert.assertTrue(Matcher.match(new Artifacts().create(), artifacts));
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : ModelToXmlSchemaQuery(org.whole.lang.xsd.codebase.ModelToXmlSchemaQuery) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) ClasspathPersistenceProvider(org.whole.lang.codebase.ClasspathPersistenceProvider) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) File(java.io.File) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 10 with ClasspathPersistenceProvider

use of org.whole.lang.codebase.ClasspathPersistenceProvider in project whole by wholeplatform.

the class XsdLanguageTest method testModelToXsdMapping.

@Test
public void testModelToXsdMapping() {
    try {
        IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
        PathExpression path = new ModelToXmlSchemaQuery().create();
        IEntity model = XmlBuilderPersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/artifacts/ArtifactsModel.xwl"));
        Assert.assertNotNull(BehaviorUtils.evaluateFirstResult(path, model, bm));
        IEntity mappedXsd = bm.wGet("schema");
        IEntity xsd = loadXsd("artifacts.xsd");
        Assert.assertTrue(OrderedMatcher.match(xsd, mappedXsd, comparatorsMap));
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : ModelToXmlSchemaQuery(org.whole.lang.xsd.codebase.ModelToXmlSchemaQuery) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) ClasspathPersistenceProvider(org.whole.lang.codebase.ClasspathPersistenceProvider) Test(org.junit.Test)

Aggregations

ClasspathPersistenceProvider (org.whole.lang.codebase.ClasspathPersistenceProvider)15 IEntity (org.whole.lang.model.IEntity)12 Test (org.junit.Test)11 IBindingManager (org.whole.lang.bindings.IBindingManager)4 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)2 PathExpression (org.whole.lang.queries.model.PathExpression)2 IVisitor (org.whole.lang.visitors.IVisitor)2 ModelToXmlSchemaQuery (org.whole.lang.xsd.codebase.ModelToXmlSchemaQuery)2 File (java.io.File)1 HashSet (java.util.HashSet)1 CoreException (org.eclipse.core.runtime.CoreException)1 Execute (org.eclipse.e4.core.di.annotations.Execute)1 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)1 MPerspective (org.eclipse.e4.ui.model.application.ui.advanced.MPerspective)1 MPerspectiveStack (org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack)1 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)1 MPartSashContainer (org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer)1 MPartStack (org.eclipse.e4.ui.model.application.ui.basic.MPartStack)1 MTrimBar (org.eclipse.e4.ui.model.application.ui.basic.MTrimBar)1 MTrimmedWindow (org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow)1