Search in sources :

Example 6 with Order

use of org.apache.tapestry5.ioc.annotations.Order in project tapestry-5 by apache.

the class TemplateParserImplTest method component_with_parameters.

@Test
public void component_with_parameters() {
    List<TemplateToken> tokens = tokens("componentWithParameters.tml");
    assertEquals(tokens.size(), 9);
    TemplateToken templateToken = get(tokens, 2);
    Location l = templateToken.getLocation();
    AttributeToken t1 = get(tokens, 3);
    // TODO: Not sure what order the attributes appear in. Order in the XML? Sorted
    // alphabetically? Random 'cause they're hashed?
    assertEquals(t1.name, "cherry");
    assertEquals(t1.value, "bomb");
    assertSame(t1.getLocation(), l);
    AttributeToken t2 = get(tokens, 4);
    assertEquals(t2.name, "align");
    assertEquals(t2.value, "right");
    assertSame(t2.getLocation(), l);
    TextToken t3 = get(tokens, 5);
    assertEquals(t3.text.trim(), "fred's body");
    get(tokens, 6);
}
Also used : Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 7 with Order

use of org.apache.tapestry5.ioc.annotations.Order in project tapestry-5 by apache.

the class GeneratorAdapter method tableSwitch.

/**
 * Generates the instructions for a switch statement.
 *
 * @param keys the switch case keys.
 * @param generator a generator to generate the code for the switch cases.
 * @param useTable {@literal true} to use a TABLESWITCH instruction, or {@literal false} to use a
 *     LOOKUPSWITCH instruction.
 */
public void tableSwitch(final int[] keys, final TableSwitchGenerator generator, final boolean useTable) {
    for (int i = 1; i < keys.length; ++i) {
        if (keys[i] < keys[i - 1]) {
            throw new IllegalArgumentException("keys must be sorted in ascending order");
        }
    }
    Label defaultLabel = newLabel();
    Label endLabel = newLabel();
    if (keys.length > 0) {
        int numKeys = keys.length;
        if (useTable) {
            int min = keys[0];
            int max = keys[numKeys - 1];
            int range = max - min + 1;
            Label[] labels = new Label[range];
            Arrays.fill(labels, defaultLabel);
            for (int i = 0; i < numKeys; ++i) {
                labels[keys[i] - min] = newLabel();
            }
            mv.visitTableSwitchInsn(min, max, defaultLabel, labels);
            for (int i = 0; i < range; ++i) {
                Label label = labels[i];
                if (label != defaultLabel) {
                    mark(label);
                    generator.generateCase(i + min, endLabel);
                }
            }
        } else {
            Label[] labels = new Label[numKeys];
            for (int i = 0; i < numKeys; ++i) {
                labels[i] = newLabel();
            }
            mv.visitLookupSwitchInsn(defaultLabel, keys, labels);
            for (int i = 0; i < numKeys; ++i) {
                mark(labels[i]);
                generator.generateCase(keys[i], endLabel);
            }
        }
    }
    mark(defaultLabel);
    generator.generateDefault();
    mark(endLabel);
}
Also used : Label(org.apache.tapestry5.internal.plastic.asm.Label)

Example 8 with Order

use of org.apache.tapestry5.ioc.annotations.Order in project tapestry-5 by apache.

the class ToDoDatabaseImpl method add.

private void add(String title, Urgency urgency, int order) {
    ToDoItem item = new ToDoItem();
    item.setTitle(title);
    item.setUrgency(urgency);
    item.setOrder(order);
    add(item);
}
Also used : ToDoItem(org.apache.tapestry5.integration.app1.data.ToDoItem)

Example 9 with Order

use of org.apache.tapestry5.ioc.annotations.Order in project tapestry-5 by apache.

the class MixinWorker method replaceFieldWithMixin.

private void replaceFieldWithMixin(MutableComponentModel model, PlasticField field) {
    Mixin annotation = field.getAnnotation(Mixin.class);
    field.claim(annotation);
    String mixinType = annotation.value();
    String[] order = annotation.order();
    String fieldType = field.getTypeName();
    String mixinClassName = InternalUtils.isBlank(mixinType) ? fieldType : resolver.resolveMixinTypeToClassName(mixinType);
    model.addMixinClassName(mixinClassName, order);
    replaceFieldAccessWithMixin(field, mixinClassName);
}
Also used : Mixin(org.apache.tapestry5.annotations.Mixin)

Example 10 with Order

use of org.apache.tapestry5.ioc.annotations.Order in project tapestry-5 by apache.

the class ToDoList method onSuccess.

void onSuccess() {
    int order = 0;
    for (ToDoItem item : items) {
        item.setOrder(order++);
        database.update(item);
    }
}
Also used : ToDoItem(org.apache.tapestry5.integration.app1.data.ToDoItem)

Aggregations

Test (org.testng.annotations.Test)10 BeanModel (org.apache.tapestry5.beanmodel.BeanModel)6 Messages (org.apache.tapestry5.commons.Messages)6 PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)3 ToDoItem (org.apache.tapestry5.integration.app1.data.ToDoItem)3 Method (java.lang.reflect.Method)2 EventContext (org.apache.tapestry5.EventContext)2 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)2 Location (org.apache.tapestry5.commons.Location)2 ClassPropertyAdapter (org.apache.tapestry5.commons.services.ClassPropertyAdapter)2 PropertyAdapter (org.apache.tapestry5.commons.services.PropertyAdapter)2 Link (org.apache.tapestry5.http.Link)2 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)2 ObjectStreamException (java.io.ObjectStreamException)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1