Search in sources :

Example 26 with ClassIdentifier

use of org.eclipse.scout.rt.platform.classid.ClassIdentifier in project scout.rt by eclipse.

the class ClassIdentifierTest method testTemplateClassUsingShortestPath.

@Test
public void testTemplateClassUsingShortestPath() {
    ClassIdentifier aid = new ClassIdentifier(Foo.A.class, AbstractTemplate.InnerClass.class);
    ClassIdentifier bid = new ClassIdentifier(Foo.B.class, AbstractTemplate.InnerClass.class);
    assertFalse(aid.equals(bid));
    assertNotSame(aid.getClasses()[0], bid.getClasses()[0]);
    assertSame(aid.getLastSegment(), bid.getLastSegment());
}
Also used : ClassIdentifier(org.eclipse.scout.rt.platform.classid.ClassIdentifier) Test(org.junit.Test)

Example 27 with ClassIdentifier

use of org.eclipse.scout.rt.platform.classid.ClassIdentifier in project scout.rt by eclipse.

the class ClassIdentifierTest method testCreateWithContextAndCalss.

@Test
public void testCreateWithContextAndCalss() {
    ClassIdentifier cid = new ClassIdentifier(String.class);
    ClassIdentifier cid2 = new ClassIdentifier(cid, Long.class);
    assertNotSame(cid, cid2);
    assertArrayEquals(new Class[] { String.class, Long.class }, cid2.getClasses());
}
Also used : ClassIdentifier(org.eclipse.scout.rt.platform.classid.ClassIdentifier) Test(org.junit.Test)

Example 28 with ClassIdentifier

use of org.eclipse.scout.rt.platform.classid.ClassIdentifier in project scout.rt by eclipse.

the class ClassIdentifierTest method testTemplateClassUsingFullPath.

@Test
public void testTemplateClassUsingFullPath() {
    ClassIdentifier aid = new ClassIdentifier(Foo.A.class, Foo.A.InnerClass.class);
    ClassIdentifier bid = new ClassIdentifier(Foo.B.class, Foo.B.InnerClass.class);
    assertFalse(aid.equals(bid));
    assertNotSame(aid.getClasses()[0], bid.getClasses()[0]);
    assertSame(aid.getLastSegment(), bid.getLastSegment());
}
Also used : ClassIdentifier(org.eclipse.scout.rt.platform.classid.ClassIdentifier) Test(org.junit.Test)

Example 29 with ClassIdentifier

use of org.eclipse.scout.rt.platform.classid.ClassIdentifier in project scout.rt by eclipse.

the class ExtensionRegistry method createModelMoveDescriptorFor.

@Override
public <T> MoveDescriptor<T> createModelMoveDescriptorFor(T modelObject, Iterator<?> parentModelObjectIterator) {
    if (modelObject == null) {
        throw new IllegalExtensionException("modelObject must not be null.");
    }
    Set<ExtensionRegistryMoveItem> moveItems = null;
    m_readWriteLock.readLock().lock();
    try {
        moveItems = getModelMoveItemsFor(modelObject.getClass(), parentModelObjectIterator);
    } finally {
        m_readWriteLock.readLock().unlock();
    }
    if (CollectionUtility.isEmpty(moveItems)) {
        return null;
    }
    // collapse multiple move items into one move descriptor
    ClassIdentifier newContainer = null;
    Double newOrder = null;
    for (ExtensionRegistryMoveItem item : moveItems) {
        if (item.getNewModelContainerClassIdentifier() != null) {
            newContainer = item.getNewModelContainerClassIdentifier();
        }
        if (item.getNewModelOrder() != null) {
            newOrder = item.getNewModelOrder();
        }
    }
    return new MoveDescriptor<T>(modelObject, newContainer, newOrder);
}
Also used : ClassIdentifier(org.eclipse.scout.rt.platform.classid.ClassIdentifier)

Example 30 with ClassIdentifier

use of org.eclipse.scout.rt.platform.classid.ClassIdentifier in project scout.rt by eclipse.

the class ExtensionRegistry method autoRegisterInternal.

protected void autoRegisterInternal(Class<?> extensionClass, Class<?> declaringClass, ClassIdentifier ownerClassIdentifier, ClassIdentifier ownerClassIdentifierFromDeclaring, Double order) {
    if (extensionClass == null) {
        throw new IllegalExtensionException("Extension or contribution cannot be null.");
    }
    boolean isExtension = IExtension.class.isAssignableFrom(extensionClass);
    Class<?> extensionGeneric = null;
    if (isExtension) {
        extensionGeneric = TypeCastUtility.getGenericsParameterClass(extensionClass, IExtension.class);
    }
    if (ownerClassIdentifier == null) {
        if (isExtension) {
            // 1. try type parameter of extension
            InheritOuterExtensionScope inheritOuterExtensionScope = extensionClass.getAnnotation(InheritOuterExtensionScope.class);
            if (inheritOuterExtensionScope == null || inheritOuterExtensionScope.value()) {
                ownerClassIdentifier = new ClassIdentifier(ownerClassIdentifierFromDeclaring, extensionGeneric);
            } else {
                ownerClassIdentifier = new ClassIdentifier(extensionGeneric);
            }
        }
        if (ownerClassIdentifier == null) {
            // 2. try @Extends annotation
            Extends extendsAnnotation = getExtendsAnnotation(extensionClass);
            if (extendsAnnotation != null) {
                int pathToContainerLength = extendsAnnotation.pathToContainer().length;
                if (pathToContainerLength > 0) {
                    Class[] segments = new Class[pathToContainerLength + 1];
                    System.arraycopy(extendsAnnotation.pathToContainer(), 0, segments, 0, pathToContainerLength);
                    segments[pathToContainerLength] = extendsAnnotation.value();
                    ownerClassIdentifier = new ClassIdentifier(segments);
                } else {
                    ownerClassIdentifier = new ClassIdentifier(extendsAnnotation.value());
                }
            }
            if (ownerClassIdentifier == null) {
                // 3. inherit owner from declaring type
                ownerClassIdentifier = ownerClassIdentifierFromDeclaring;
            }
        }
    }
    if (Modifier.isStatic(extensionClass.getModifiers())) {
        // not required
        declaringClass = null;
    }
    registerInternal(ownerClassIdentifier, declaringClass, extensionClass, order, extensionGeneric, isExtension);
    if (isExtension) {
        // only step in if it is an "unmanaged" extension.
        // managed scout objects (e.g. AbstractCompositeField) create their inner classes itself, therefore inner classes must not be registered
        List<Class<?>> innerExtensionClasses = collectInnerExtensionClasses(extensionClass);
        for (Class<?> innerExtensionClass : innerExtensionClasses) {
            autoRegisterInternal(innerExtensionClass, extensionClass, null, ownerClassIdentifier, null);
        }
    } else {
        // step into all static inner classes for form field data if the inner class itself has an @Extends annotation: this is a row data extension
        boolean isFormFieldData = AbstractFormFieldData.class.isAssignableFrom(extensionClass);
        if (isFormFieldData) {
            List<Class<?>> innerExtensionClasses = collectInnerExtensionClasses(extensionClass);
            for (Class<?> innerExtensionClass : innerExtensionClasses) {
                if (innerExtensionClass.isAnnotationPresent(Extends.class) && Modifier.isStatic(innerExtensionClass.getModifiers())) {
                    autoRegisterInternal(innerExtensionClass, extensionClass, null, ownerClassIdentifier, null);
                }
            }
        }
    }
}
Also used : InheritOuterExtensionScope(org.eclipse.scout.rt.platform.extension.InheritOuterExtensionScope) ClassIdentifier(org.eclipse.scout.rt.platform.classid.ClassIdentifier) Extends(org.eclipse.scout.rt.platform.extension.Extends)

Aggregations

ClassIdentifier (org.eclipse.scout.rt.platform.classid.ClassIdentifier)31 Test (org.junit.Test)23 IExtensionRegistry (org.eclipse.scout.rt.shared.extension.IExtensionRegistry)11 MultiTemplateUsageForm (org.eclipse.scout.rt.client.extension.ui.form.fixture.MultiTemplateUsageForm)10 FirstTemplateBox (org.eclipse.scout.rt.client.extension.ui.form.fixture.MultiTemplateUsageForm.MainBox.FirstTemplateBox)10 SecondTemplateBox (org.eclipse.scout.rt.client.extension.ui.form.fixture.MultiTemplateUsageForm.MainBox.SecondTemplateBox)10 TopFieldsBox (org.eclipse.scout.rt.client.extension.ui.form.fixture.AbstractTemplateGroupsBox.TopFieldsBox)7 AbstractTemplateFieldsBox (org.eclipse.scout.rt.client.extension.ui.form.fixture.AbstractTemplateFieldsBox)4 AbstractFormData (org.eclipse.scout.rt.shared.data.form.AbstractFormData)4 AbstractStringField (org.eclipse.scout.rt.client.ui.form.fields.stringfield.AbstractStringField)3 Map (java.util.Map)2 TreeSet (java.util.TreeSet)2 TopStringField (org.eclipse.scout.rt.client.extension.ui.form.fixture.AbstractTemplateFieldsBox.TopStringField)2 MainBoxStringField (org.eclipse.scout.rt.client.extension.ui.form.fixture.MultiTemplateUsageForm.MainBox.MainBoxStringField)2 AbstractFormFieldData (org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData)2 AbstractValueFieldData (org.eclipse.scout.rt.shared.data.form.fields.AbstractValueFieldData)2 AbstractPropertyData (org.eclipse.scout.rt.shared.data.form.properties.AbstractPropertyData)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1