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 org.gwe.app.client.web.request.Operation;
20  import org.gwe.app.client.web.request.Param;
21  import org.gwe.persistence.model.HeadResourceInfo;
22  import org.gwe.persistence.model.OrderInfo;
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 18, 2008
30   */
31  public class HtmlOrdersTable extends HtmlTable {
32  
33  	public HtmlOrdersTable(HeadResourceInfo daemonInfo) {
34  	    super("Id", "", "Submitted at", "Completed at", "Progress (completed / total)", "");
35  		if (daemonInfo == null) return;
36          for (OrderInfo order : daemonInfo.getOrdersList()) {
37          	String clusterId = daemonInfo.getName();
38  			HtmlTableCell id = new HtmlTableCell("[ " + order.getId() + " ]", "", new HtmlOrderLink(clusterId, order)) ;
39  			HtmlTableCell pause = getOperationLink(clusterId, order, order.isPaused() ? Operation.RESUME : Operation.PAUSE);
40          	String progress = order.getCompletedJobsCount() + " / " + order.getTotalJobsCount();
41  //        	HtmlContent priority = getOperationLink(clusterId, order, Operation.DOWN);
42  //        	priority.getLink().addParam(Param.OTHER_ORDER_ID, prevOrderId);
43          	HtmlTableCell delete = getOperationLink(clusterId, order, Operation.DELETE);
44  
45  			addRow(id, pause, order.getWhenCreated(), order.getWhenCompleted(), progress, delete);
46          }
47  	    return;
48      }
49  
50  	private HtmlTableCell getOperationLink(String clusterId, OrderInfo order, Operation oper) {
51  		return new HtmlTableCell(order.getId() + "", "", new HtmlOperLink(clusterId, order, oper), oper.getImage());
52  	}
53  }
54  
55  class HtmlOrderLink extends HtmlLink {
56  
57  	public HtmlOrderLink(String clusterId, OrderInfo order) {
58  	    super(false, "order");
59  	    addParam(Param.CLUSTER_ID, clusterId);
60  	    addParam(Param.ORDER_ID, order.getId());
61      }
62  }
63  
64  class HtmlOperLink extends HtmlLink {
65  
66  	public HtmlOperLink(String clusterId, OrderInfo order, Operation oper) {
67  	    super(false, "cluster");
68  	    addParam(Param.CLUSTER_ID, clusterId);
69  	    addParam(Param.ORDER_ID, order.getId());
70  	    addParam(Param.OPER, oper.toString());
71      }
72  }