View Javadoc

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  import org.apache.tapestry5.Asset;
18  import org.apache.tapestry5.BindingConstants;
19  import org.apache.tapestry5.annotations.IncludeStylesheet;
20  import org.apache.tapestry5.annotations.Parameter;
21  import org.apache.tapestry5.annotations.Property;
22  import org.apache.tapestry5.corelib.components.Grid;
23  
24  import br.com.arsmachina.tapestrycrud.Constants;
25  
26  /**
27   * Component that renders the action links in a listing page. It is meant to be used in a
28   * {@link Grid} column. <a
29   * href="http://ars-machina.svn.sourceforge.net/viewvc/ars-machina/example/trunk/src/main/webapp/project/ListProject.tml?view=markup"
30   * >Ars Machina Project Example</a>. The default icons used are taken from the <a
31   * href="http://www.famfamfam.com/lab/icons/silk/">Silk</a> icon set (Creative Commons Attribution
32   * 2.5 License).
33   * 
34   * @author Thiago H. de Paula Figueiredo
35   */
36  @IncludeStylesheet(Constants.TAPESTRY_CRUD_CSS_ASSET)
37  public class ActionLinks {
38  
39  	private static final String IMAGES_ASSET_ROOT = "asset:classpath:/br/com/arsmachina/tapestrycrud/components/images/";
40  
41  	private static final String DEFAULT_EDIT_ICON_ASSET = IMAGES_ASSET_ROOT + "edit.png";
42  
43  	private static final String DEFAULT_DELETE_ICON_ASSET = IMAGES_ASSET_ROOT + "delete.png";
44  
45  	private static final String DEFAULT_VIEW_ICON_ASSET = IMAGES_ASSET_ROOT + "view.png";
46  
47  	/**
48  	 * Name of the page that is used to edits objects listed in this page.
49  	 */
50  	@Parameter(defaultPrefix = BindingConstants.LITERAL)
51  	@SuppressWarnings("unused")
52  	private String editPage;
53  
54  	/**
55  	 * Name of the page that is used to edits objects listed in this page.
56  	 */
57  	@Parameter(defaultPrefix = BindingConstants.LITERAL)
58  	@SuppressWarnings("unused")
59  	private String viewPage;
60  
61  	/**
62  	 * Show the edit link?
63  	 */
64  	@Parameter(value = "true")
65  	@Property
66  	@SuppressWarnings("unused")
67  	private boolean edit;
68  
69  	/**
70  	 * Show the remove link?
71  	 */
72  	@Parameter(value = "true")
73  	@Property
74  	@SuppressWarnings("unused")
75  	private boolean remove;
76  
77  	/**
78  	 * Show the view link?
79  	 */
80  	@Parameter(value = "false")
81  	@Property
82  	@SuppressWarnings("unused")
83  	private boolean view;
84  
85  	/**
86  	 * The object that the links will refer to.
87  	 */
88  	@Parameter(required = true)
89  	@Property
90  	@SuppressWarnings("unused")
91  	private Object object;
92  
93  	@Parameter(defaultPrefix = BindingConstants.ASSET, value = DEFAULT_EDIT_ICON_ASSET)
94  	@Property
95  	@SuppressWarnings("unused")
96  	private Asset editIcon;
97  
98  	@Parameter(defaultPrefix = BindingConstants.ASSET, value = DEFAULT_VIEW_ICON_ASSET)
99  	@Property
100 	@SuppressWarnings("unused")
101 	private Asset viewIcon;
102 
103 	@Parameter(defaultPrefix = BindingConstants.ASSET, value = DEFAULT_DELETE_ICON_ASSET)
104 	@Property
105 	@SuppressWarnings("unused")
106 	private Asset deleteIcon;
107 
108 	/**
109 	 * Returns the value of the <code>editPage</code> property.
110 	 * 
111 	 * @return a {@link String}.
112 	 */
113 	public String getEditPage() {
114 
115 		if (edit && (editPage == null || editPage.trim().length() == 0)) {
116 			
117 			throw new IllegalArgumentException(
118 					"When parameter edit is true, parameter editPage must have a non-empty value");
119 			
120 		}
121 
122 		return editPage;
123 	}
124 
125 	/**
126 	 * Returns the value of the <code>viewPage</code> property.
127 	 * 
128 	 * @return a {@link String}.
129 	 */
130 	public String getViewPage() {
131 
132 		if (view && viewPage == null || viewPage.trim().length() == 0) {
133 			
134 			throw new IllegalArgumentException(
135 					"When parameter view is true, parameter viewPage must have a non-empty value");
136 			
137 		}
138 		
139 		return viewPage;
140 		
141 	}
142 
143 }