Search in sources :

Example 26 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class PropertyFunctionScriptPage method addActions.

@Override
protected void addActions(ToolBar toolbar, CompilingSourceViewer<GroovyAST> viewer) {
    super.addActions(toolbar, viewer);
    PageHelp.createToolItem(toolbar, this);
    TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.SOURCE, new TypeProvider() {

        @Override
        public Collection<? extends TypeDefinition> getTypes() {
            // create a dummy type with the variables as children
            DefaultTypeDefinition dummy = new DefaultTypeDefinition(TypeStructureTray.VARIABLES_TYPE_NAME);
            DefaultCustomPropertyFunction cf = getWizard().getUnfinishedFunction();
            int index = 0;
            for (EntityDefinition variable : getVariables()) {
                DefaultCustomPropertyFunctionEntity source = cf.getSources().get(index);
                if (variable.getDefinition() instanceof PropertyDefinition) {
                    PropertyDefinition prop = (PropertyDefinition) variable.getDefinition();
                    TypeDefinition propertyType;
                    boolean useInstanceValue = CustomGroovyTransformation.useInstanceVariableForSource(source);
                    if (useInstanceValue) {
                        // use instance type
                        propertyType = prop.getPropertyType();
                    } else {
                        // use dummy type with only the
                        // binding/HasValueFlag copied
                        DefaultTypeDefinition crippledType = new DefaultTypeDefinition(prop.getPropertyType().getName());
                        crippledType.setConstraint(prop.getPropertyType().getConstraint(Binding.class));
                        crippledType.setConstraint(prop.getPropertyType().getConstraint(HasValueFlag.class));
                        propertyType = crippledType;
                    }
                    DefaultPropertyDefinition dummyProp = new DefaultPropertyDefinition(new QName(source.getName()), dummy, propertyType);
                    // number of times
                    if (source.isEager())
                        dummyProp.setConstraint(Cardinality.CC_ANY_NUMBER);
                }
                index++;
            }
            return Collections.singleton(dummy);
        }
    });
    TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.TARGET, new TypeProvider() {

        @Override
        public Collection<? extends TypeDefinition> getTypes() {
            DefaultCustomPropertyFunctionEntity target = getWizard().getUnfinishedFunction().getTarget();
            if (target != null) {
                return Collections.singleton(createDummyType(target));
            }
            return Collections.emptyList();
        }
    });
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultCustomPropertyFunction(eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunction) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) QName(javax.xml.namespace.QName) TypeProvider(eu.esdihumboldt.hale.ui.functions.groovy.internal.TypeStructureTray.TypeProvider) Collection(java.util.Collection) DefaultCustomPropertyFunctionEntity(eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunctionEntity) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 27 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class GroovyCreatePage method addActions.

@Override
protected void addActions(ToolBar toolbar, CompilingSourceViewer<GroovyAST> viewer) {
    super.addActions(toolbar, viewer);
    PageHelp.createToolItem(toolbar, this);
    TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.TARGET, new TypeProvider() {

        @Override
        public Collection<? extends TypeDefinition> getTypes() {
            Type typeEntity = (Type) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
            if (typeEntity != null) {
                return Collections.singleton(typeEntity.getDefinition().getDefinition());
            }
            return Collections.emptyList();
        }
    });
    PageFunctions.createToolItem(toolbar, this);
}
Also used : Type(eu.esdihumboldt.hale.common.align.model.Type) TypeProvider(eu.esdihumboldt.hale.ui.functions.groovy.internal.TypeStructureTray.TypeProvider) Collection(java.util.Collection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 28 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class GroovyJoinPage method addActions.

@Override
protected void addActions(ToolBar toolbar, CompilingSourceViewer<GroovyAST> viewer) {
    PageHelp.createToolItem(toolbar, this);
    // FIXME TypeStructureTray does not support FamilyInstances
    // XXX for now only use Join base type
    JoinTypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.SOURCE, new TypeProvider() {

        @Override
        public Collection<? extends TypeDefinition> getTypes() {
            ParameterValue param = CellUtil.getFirstParameter(getWizard().getUnfinishedCell(), JoinFunction.PARAMETER_JOIN);
            JoinParameter joinParameter = param.as(JoinParameter.class);
            if (joinParameter != null && joinParameter.getTypes() != null && !joinParameter.getTypes().isEmpty()) {
                return Collections.singleton(joinParameter.getTypes().get(0).getDefinition());
            }
            return Collections.emptyList();
        }
    });
    TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.TARGET, new TypeProvider() {

        @Override
        public Collection<? extends TypeDefinition> getTypes() {
            Type targetType = (Type) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
            if (targetType != null) {
                return Collections.singleton(targetType.getDefinition().getDefinition());
            }
            return Collections.emptyList();
        }
    });
    PageFunctions.createToolItem(toolbar, this);
}
Also used : Type(eu.esdihumboldt.hale.common.align.model.Type) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) TypeProvider(eu.esdihumboldt.hale.ui.functions.groovy.internal.TypeStructureTray.TypeProvider) Collection(java.util.Collection) JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 29 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class GroovyTransformationPage method addActions.

@Override
protected void addActions(ToolBar toolbar, CompilingSourceViewer<GroovyAST> viewer) {
    super.addActions(toolbar, viewer);
    PageHelp.createToolItem(toolbar, this);
    TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.SOURCE, new TypeProvider() {

        @Override
        public Collection<? extends TypeDefinition> getTypes() {
            // create a dummy type with the variables as children
            DefaultTypeDefinition dummy = new DefaultTypeDefinition(TypeStructureTray.VARIABLES_TYPE_NAME);
            Cell cell = getWizard().getUnfinishedCell();
            boolean useInstanceValues = CellUtil.getOptionalParameter(cell, GroovyTransformation.PARAM_INSTANCE_VARIABLES, Value.of(false)).as(Boolean.class);
            for (EntityDefinition variable : getVariables()) {
                if (variable.getDefinition() instanceof PropertyDefinition) {
                    PropertyDefinition prop = (PropertyDefinition) variable.getDefinition();
                    TypeDefinition propertyType;
                    if (useInstanceValues) {
                        // use instance type
                        propertyType = prop.getPropertyType();
                    } else {
                        // use dummy type with only the
                        // binding/HasValueFlag copied
                        DefaultTypeDefinition crippledType = new DefaultTypeDefinition(prop.getPropertyType().getName());
                        crippledType.setConstraint(prop.getPropertyType().getConstraint(Binding.class));
                        crippledType.setConstraint(prop.getPropertyType().getConstraint(HasValueFlag.class));
                        propertyType = crippledType;
                    }
                    DefaultPropertyDefinition dummyProp = new DefaultPropertyDefinition(new QName(getVariableName(variable)), dummy, propertyType);
                    // number of times
                    if (cell.getTransformationIdentifier().equals(GroovyGreedyTransformation.ID))
                        dummyProp.setConstraint(Cardinality.CC_ANY_NUMBER);
                }
            }
            return Collections.singleton(dummy);
        }
    });
    TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.TARGET, new TypeProvider() {

        @Override
        public Collection<? extends TypeDefinition> getTypes() {
            Property targetProperty = (Property) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
            if (targetProperty != null) {
                return Collections.singleton(targetProperty.getDefinition().getDefinition().getPropertyType());
            }
            return Collections.emptyList();
        }
    });
    PageFunctions.createToolItem(toolbar, this);
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) QName(javax.xml.namespace.QName) TypeProvider(eu.esdihumboldt.hale.ui.functions.groovy.internal.TypeStructureTray.TypeProvider) Collection(java.util.Collection) Cell(eu.esdihumboldt.hale.common.align.model.Cell) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) Property(eu.esdihumboldt.hale.common.align.model.Property) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 30 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class InstanceBuilderCode method appendBuildProperties.

/**
 * Append example code to build the properties identified by the given path
 * tree.
 *
 * @param example the example code to append to
 * @param baseIndent the base indent to use
 * @param tree the path tree representing a specific segment
 * @param parent the parent of the segment
 * @param useBrackets if brackets should be used in the generated code
 * @param startWithIndent if at the beginning the indent should be added
 * @param endWithNewline if at the end a new line break should be added
 * @param useExampleValues if example values should be used
 * @return the relative offset where editing should be continued
 */
public static int appendBuildProperties(StringBuilder example, String baseIndent, PathTree tree, DefinitionGroup parent, final boolean useBrackets, final boolean startWithIndent, final boolean endWithNewline, final boolean useExampleValues) {
    Definition<?> def = (Definition<?>) tree.getSegment();
    final String indent = baseIndent;
    int cursor = 0;
    boolean opened = false;
    if (def instanceof PropertyDefinition) {
        // property name
        if (startWithIndent) {
            example.append(indent);
        }
        // TODO test if property must be accessed explicitly through
        // builder?
        example.append(def.getName().getLocalPart());
        // test if uniquely accessible from parent
        boolean useNamespace = true;
        if (parent instanceof Definition<?>) {
            try {
                new DefinitionAccessor((Definition<?>) parent).findChildren(def.getName().getLocalPart()).eval();
                useNamespace = false;
            } catch (IllegalStateException e) {
            // ignore - namespace needed
            }
        }
        boolean needComma = false;
        // add namespace if necessary
        if (useNamespace) {
            if (useBrackets && !needComma) {
                example.append('(');
            }
            example.append(" namespace: '");
            example.append(def.getName().getNamespaceURI());
            example.append('\'');
            needComma = true;
        }
        TypeDefinition propertyType = ((PropertyDefinition) def).getPropertyType();
        boolean hasValue = propertyType.getConstraint(HasValueFlag.class).isEnabled();
        if (hasValue) {
            // add an example value
            if (useBrackets && !needComma) {
                example.append('(');
            }
            if (needComma) {
                example.append(',');
            }
            example.append(' ');
            if (useExampleValues) {
                switch(Classification.getClassification(def)) {
                    case NUMERIC_PROPERTY:
                        example.append("42");
                        break;
                    case STRING_PROPERTY:
                        example.append("'some value'");
                        break;
                    default:
                        example.append("some_value");
                }
            }
            needComma = true;
        }
        if (DefinitionUtil.hasChildren(propertyType) && (!tree.getChildren().isEmpty() || !needComma || !hasValue)) {
            if (needComma) {
                if (useBrackets) {
                    example.append(" )");
                } else {
                    example.append(',');
                }
            }
            example.append(" {");
            example.append('\n');
            opened = true;
        } else {
            cursor = example.length();
            if (useBrackets && needComma) {
                example.append(" )");
            }
            if (endWithNewline) {
                example.append('\n');
            }
        }
    } else {
    // groups are ignored
    }
    if (opened) {
        // set the new parent
        parent = DefinitionUtil.getDefinitionGroup(def);
        // create child properties
        String newIndent = indent + createIndent(1);
        if (tree.getChildren().isEmpty()) {
            example.append(newIndent);
            cursor = example.length();
            example.append('\n');
        } else {
            for (PathTree child : tree.getChildren()) {
                cursor = appendBuildProperties(example, newIndent, child, parent, useBrackets, true, true, useExampleValues);
            }
        }
        // close bracket
        example.append(indent);
        example.append('}');
        if (endWithNewline) {
            example.append('\n');
        }
    }
    return cursor;
}
Also used : HasValueFlag(eu.esdihumboldt.hale.common.schema.model.constraint.type.HasValueFlag) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefinitionAccessor(eu.esdihumboldt.hale.common.schema.groovy.DefinitionAccessor) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)192 QName (javax.xml.namespace.QName)58 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)38 ArrayList (java.util.ArrayList)32 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)26 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)26 Test (org.junit.Test)24 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)22 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)21 HashSet (java.util.HashSet)21 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)20 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)20 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)16 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)15 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)15 Cell (eu.esdihumboldt.hale.common.align.model.Cell)14 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)14 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)12 Binding (eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding)12 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)12