View Javadoc

1   /*
2    * Copyright 2007-2008 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.gwe.app.client.web.view;
18  
19  import java.util.List;
20  
21  import org.gwe.GWEAppContext;
22  import org.gwe.p2elv2.model.PVariable;
23  import org.gwe.utils.web.HtmlLink;
24  import org.gwe.utils.web.HtmlTable;
25  import org.gwe.utils.web.HtmlTableCell;
26  
27  /**
28   * @author Marco Ruiz
29   * @since Dec 17, 2008
30   */
31  public class HtmlPVarTable extends HtmlTable {
32  	
33  	public HtmlPVarTable(List<PVariable> vars) {
34  	    super("Variable", "Value Generator", "Parameters");
35  	    if (vars == null) return;
36  		for (PVariable var : vars) {
37  	        String params = var.getFunctionInvocation().getParams().toString();
38  	        params = params.substring(1, params.length() - 1);
39  	        String functionName = var.getFunctionInvocation().getFunctionName();
40  	        
41  	        boolean isFunction = GWEAppContext.getP2ELFunctionNames().contains(functionName);
42  	        String caption = new StringBuffer(functionName).append(" (").append(isFunction ? "function" : "macro").append(")").toString();
43  	        
44  			HtmlTableCell function = new HtmlTableCell(caption, "", getURLLink(functionName, isFunction));
45  			addRow(var.getFullName(), function, params);
46          }
47      }
48  
49  	private HtmlLink getURLLink(String functionName, boolean isFunction) {
50  	    String baseURL = isFunction ? "http://www.gridwizardenterprise.org/guides/p2el-semantics.html" : "grid?expanded=true";
51  		String url = new StringBuffer(baseURL).append("#").append(functionName).toString();
52  		return new HtmlLink(isFunction, url);
53      }
54  }