| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| PrimaryKeyEventLink |
|
| 0.0;0 |
| 1 | // Copyright 2008 Thiago H. de Paula Figueiredo | |
| 2 | // | |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 | // you may not use this file except in compliance with the License. | |
| 5 | // You may obtain a copy of the License at | |
| 6 | // | |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 | // | |
| 9 | // Unless required by applicable law or agreed to in writing, software | |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 | // See the License for the specific language governing permissions and | |
| 13 | // limitations under the License. | |
| 14 | ||
| 15 | package br.com.arsmachina.tapestrycrud.components; | |
| 16 | ||
| 17 | ||
| 18 | import org.apache.tapestry5.BindingConstants; | |
| 19 | import org.apache.tapestry5.PrimaryKeyEncoder; | |
| 20 | import org.apache.tapestry5.annotations.Parameter; | |
| 21 | import org.apache.tapestry5.annotations.Property; | |
| 22 | import org.apache.tapestry5.annotations.SupportsInformalParameters; | |
| 23 | import org.apache.tapestry5.ioc.annotations.Inject; | |
| 24 | ||
| 25 | import br.com.arsmachina.tapestrycrud.encoder.ActivationContextEncoder; | |
| 26 | import br.com.arsmachina.tapestrycrud.encoder.Encoder; | |
| 27 | import br.com.arsmachina.tapestrycrud.services.PrimaryKeyEncoderSource; | |
| 28 | ||
| 29 | /** | |
| 30 | * <p> | |
| 31 | * An alternative to {@link org.apache.tapestry5.corelib.components.EventLink} that, given an object | |
| 32 | * passed as parameter, uses the corresponding {@link Encoder} to get the context | |
| 33 | * {@link Encoder#toKey(Object) } activation value. | |
| 34 | * </p> | |
| 35 | * | |
| 36 | * @author Thiago H. de Paula Figueiredo | |
| 37 | * @see org.apache.tapestry5.corelib.components.ActionLink | |
| 38 | * @see ActivationContextEncoder | |
| 39 | */ | |
| 40 | @SupportsInformalParameters | |
| 41 | 0 | public class PrimaryKeyEventLink { |
| 42 | ||
| 43 | /** | |
| 44 | * The object that will be used to generate the context for the link. | |
| 45 | */ | |
| 46 | @Parameter | |
| 47 | private Object object; | |
| 48 | ||
| 49 | /** | |
| 50 | * The name of the event to be triggered in the parent component. Defaults to the id of the | |
| 51 | * component. An {@link org.apache.tapestry5.corelib.components.ActionLink} triggers an "action" | |
| 52 | * event on itself, and EventLink component triggers any arbitrary event on | |
| 53 | * <em>its container</em>. | |
| 54 | */ | |
| 55 | @Parameter(defaultPrefix = BindingConstants.LITERAL) | |
| 56 | @Property | |
| 57 | @SuppressWarnings("unused") | |
| 58 | private String event; | |
| 59 | ||
| 60 | /** | |
| 61 | * Binding the zone parameter turns the link into a an Ajax control that causes the related zone | |
| 62 | * to be updated. | |
| 63 | */ | |
| 64 | @Parameter(defaultPrefix = BindingConstants.LITERAL) | |
| 65 | @Property | |
| 66 | @SuppressWarnings("unused") | |
| 67 | private String zone; | |
| 68 | ||
| 69 | @Inject | |
| 70 | private PrimaryKeyEncoderSource primaryKeyEncoderSource; | |
| 71 | ||
| 72 | @SuppressWarnings("unchecked") | |
| 73 | public Object getContext() { | |
| 74 | ||
| 75 | 0 | PrimaryKeyEncoder encoder = primaryKeyEncoderSource.get(object.getClass()); |
| 76 | 0 | return encoder.toKey(object); |
| 77 | ||
| 78 | } | |
| 79 | ||
| 80 | } |