Search in sources :

Example 96 with FeatureDescriptor

use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.

the class XsiModelTemplate method visit.

public void visit(IEntity entity) {
    IEntity adaptee = entity.wGetAdaptee(false);
    EntityDescriptor<?> adapteeEd = adaptee.wGetEntityDescriptor();
    if (adapteeEd.getLanguageKit().getURI().equals(CommonsLanguageKit.URI)) {
        switch(adapteeEd.getOrdinal()) {
            case CommonsEntityDescriptorEnum.Resolver_ord:
                return;
            case CommonsEntityDescriptorEnum.SameStageFragment_ord:
            case CommonsEntityDescriptorEnum.RootFragment_ord:
            case CommonsEntityDescriptorEnum.StageDownFragment_ord:
            case CommonsEntityDescriptorEnum.StageUpFragment_ord:
                // String lang = entity.wGetLanguageKit().getURI();
                IEntity root = entity.wGetRoot();
                if (XmlLanguageKit.URI.equals(root.wGetLanguageKit().getURI())) {
                    ModelTemplate template = new ModelTemplate(root);
                    template.apply(new XmlGenericBuilderAdapter(builder));
                } else
                    visit(root);
                return;
        }
    }
    EntityDescriptor<?> ed = entity.wGetEntityDescriptor();
    EntityDescriptor<?> context;
    FeatureDescriptor fd;
    String languageURI;
    IEntity parent = entity.wGetParent();
    if (EntityUtils.isNull(parent) || CommonsEntityDescriptorEnum.RootFragment.equals(parent.wGetEntityDescriptor()) || CommonsEntityDescriptorEnum.StageUpFragment.equals(parent.wGetEntityDescriptor())) {
        context = CommonsEntityDescriptorEnum.RootFragment;
        fd = CommonsFeatureDescriptorEnum.rootEntity;
        // get languageURI from parent entity descriptor but from RootFragment
        languageURI = ed.getLanguageKit().getURI();
    } else {
        context = parent.wGetEntityDescriptor();
        // always skip SameStageFragment parent
        if (CommonsEntityDescriptorEnum.SameStageFragment.equals(context)) {
            IEntity parentParent = parent.wGetParent();
            context = parentParent.wGetEntityDescriptor();
            fd = parentParent.wGetFeatureDescriptor(parent);
            languageURI = context.getLanguageKit().getURI();
        } else {
            fd = parent.wGetFeatureDescriptor(entity);
            languageURI = parent.wGetEntityDescriptor().getLanguageKit().getURI();
        }
    }
    IMappingStrategy strategy = getXsiMappingStrategy(languageURI);
    // if (!hasNCName(strategy, context, ed, fd)) {
    if (getElementNCName(entity) == null) {
        if (isMixedType(strategy, context, ed))
            builder.CharData(toContentValue(entity, strategy));
        else {
            final int size = entity.wSize();
            for (int i = 0; i < size; i++) visit(entity.wGet(i));
        }
    } else {
        nsPrefixes.wEnterScope();
        boolean needNamespacePrefix = (strategy.isElementsFormQualified()) && !NamespaceUtils.isInternalNamespace(languageURI);
        boolean needNamespaceDeclaration = needNamespacePrefix && !hasNamespacePrefix(entity, strategy.getNamespace());
        builder.Element_();
        String tagName = getElementNCName(entity);
        if (needNamespacePrefix) {
            String prefix = getNamespacePrefix(entity, languageURI);
            builder.QualifiedName_();
            builder.NameSpace(prefix);
            builder.Name(tagName);
            builder._QualifiedName();
        } else
            builder.Name(tagName);
        builder.Attributes_();
        if (needNamespaceDeclaration)
            addNamespaceDeclaration(entity, languageURI);
        if (needSchemaLocationDeclaration(strategy, context, ed, fd))
            addSchemaLocationDeclaration(entity, languageURI);
        if (entity.wGetEntityKind().isData()) {
            builder._Attributes();
            builder.CharData(toContentValue(entity, strategy));
        } else {
            applyAttributes(entity, 0);
            builder._Attributes();
            builder.Content_();
            final int size = entity.wSize();
            for (int i = 0; i < size; i++) {
                context = entity.wGetEntityDescriptor();
                fd = context.getEntityFeatureDescriptor(i);
                IEntity child = entity.wGet(i);
                ed = child.wGetEntityDescriptor();
                if (!isAttributeMapping(strategy, context, ed, fd)) {
                    if (isContentMapping(strategy, context, ed, fd))
                        builder.CharData(toContentValue(child, strategy));
                    else
                        visit(child);
                }
            }
            builder._Content();
        }
        builder._Element();
        nsPrefixes.wExitScope();
    }
}
Also used : ModelTemplate(org.whole.lang.templates.ModelTemplate) IMappingStrategy(org.whole.lang.xsd.codebase.IMappingStrategy) IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) XmlGenericBuilderAdapter(org.whole.lang.xml.builders.XmlGenericBuilderAdapter)

Example 97 with FeatureDescriptor

use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.

the class IsSetUnsetTest method testUndoRedo.

@Test
public void testUndoRedo() {
    e = ef.create(TestEntitiesEntityDescriptorEnum.SimpleTestEntity);
    IHistoryManager history = ReflectionFactory.getHistoryManager(e);
    history.setHistoryEnabled(true);
    FeatureDescriptor feature = TestEntitiesFeatureDescriptorEnum.anyEntityValue;
    IEntity newValue = ef.create(TestEntitiesEntityDescriptorEnum.SimpleTestEntity);
    e.wSet(feature, newValue);
    assertTrue(e.wIsSet(feature));
    history.undo();
    assertFalse(e.wIsSet(feature));
    history.redo();
    assertTrue(e.wIsSet(feature));
}
Also used : FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IHistoryManager(org.whole.lang.lifecycle.IHistoryManager) Test(org.junit.Test)

Example 98 with FeatureDescriptor

use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.

the class OutlinePart method getModelSpecificChildren.

protected List<IEntity> getModelSpecificChildren() {
    IEntity e = getModelEntity();
    FeatureDescriptor[] fd = provider.getFeatures(e);
    List<IEntity> list = new ArrayList<IEntity>(fd.length);
    for (int i = 0; i < fd.length; i++) list.add(e.wGet(fd[i]));
    return list;
}
Also used : IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) ArrayList(java.util.ArrayList)

Example 99 with FeatureDescriptor

use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.

the class AbstractFreeformNodePart method propertyChangeUI.

protected void propertyChangeUI(PropertyChangeEvent evt) {
    // TODO place in AbstractNodePart ?
    FeatureDescriptor fd = CommonsFeatureDescriptorEnum.composite_element.getName().equals(evt.getPropertyName()) ? getModelEntity().wGetFeatureDescriptor((IEntity) evt.getSource()) : getModelEntity().wGetEntityDescriptor().getFeatureDescriptorEnum().valueOf(evt.getPropertyName());
    if (sourceConnections != null && sourceConnections.contains(fd) && !EntityUtils.isNotResolver((IEntity) evt.getNewValue())) {
        Object connectioneditPart = getViewer().getEditPartRegistry().get(evt.getOldValue());
        if (connectioneditPart instanceof ConnectionEditPart)
            removeSourceConnection((ConnectionEditPart) connectioneditPart);
    }
    if (targetConnections != null && targetConnections.contains(fd) && !EntityUtils.isNotResolver((IEntity) evt.getNewValue())) {
        Object connectioneditPart = getViewer().getEditPartRegistry().get(evt.getOldValue());
        if (connectioneditPart instanceof ConnectionEditPart)
            removeTargetConnection((ConnectionEditPart) connectioneditPart);
    }
    refresh();
}
Also used : ConnectionEditPart(org.eclipse.gef.ConnectionEditPart) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IEntity(org.whole.lang.model.IEntity)

Example 100 with FeatureDescriptor

use of org.whole.lang.reflect.FeatureDescriptor in project whole by wholeplatform.

the class AbstractContentPaneManagerPart method propertyChangeUI.

@Override
protected void propertyChangeUI(PropertyChangeEvent evt) {
    IEntity entity = getModelEntity();
    FeatureDescriptor fd = entity.wGetEntityDescriptor().getFeatureDescriptorEnum().valueOf(evt.getPropertyName());
    int index = entity.wGetEntityDescriptor().indexOf(fd);
    ((IEntityFigure) getFigure()).setContentPaneVisible(index, true);
    super.propertyChangeUI(evt);
}
Also used : IEntityFigure(org.whole.lang.ui.figures.IEntityFigure) IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor)

Aggregations

FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)100 IEntity (org.whole.lang.model.IEntity)43 InternalIEntity (org.whole.lang.model.InternalIEntity)6 ILanguageKit (org.whole.lang.reflect.ILanguageKit)6 HashSet (java.util.HashSet)5 IContributionItem (org.eclipse.jface.action.IContributionItem)5 ActionsVisibleWhen (org.whole.lang.e4.ui.expressions.ActionsVisibleWhen)5 VisibilityExpression (org.whole.lang.e4.ui.expressions.VisibilityExpression)5 ActionsCompositeContributionItem (org.whole.lang.e4.ui.menu.ActionsCompositeContributionItem)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 HashMap (java.util.HashMap)3 IBindingManager (org.whole.lang.bindings.IBindingManager)3 ITransactionScope (org.whole.lang.bindings.ITransactionScope)3 IdentityRequestEventHandler (org.whole.lang.events.IdentityRequestEventHandler)3 IMappingStrategy (org.whole.lang.xsd.codebase.IMappingStrategy)3 IEntityFactory (org.whole.lang.factories.IEntityFactory)2 ArrayType (org.whole.lang.pojo.model.ArrayType)2 CollectionType (org.whole.lang.pojo.model.CollectionType)2 MapType (org.whole.lang.pojo.model.MapType)2