001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.example.main.web.contract;
016:
017: import java.util.List;
018: import org.apache.commons.logging.Log;
019: import org.apache.commons.logging.LogFactory;
020: import org.araneaframework.example.main.TemplateBaseWidget;
021: import org.araneaframework.example.main.business.model.ContractMO;
022: import org.araneaframework.framework.FlowContext;
023: import org.araneaframework.uilib.list.ListWidget;
024: import org.araneaframework.uilib.list.dataprovider.MemoryBasedListDataProvider;
025:
026: /**
027: * This widget is for listing contracts.
028: * It returns selected contract's Id or cancels current call.
029: * It also allows a user to add or remove contracts if it's set to edit mode.
030: *
031: * @author Rein Raudjärv <reinra@ut.ee>
032: */
033: public class ContractListWidget extends TemplateBaseWidget {
034: private static final long serialVersionUID = 1L;
035:
036: protected static final Log log = LogFactory
037: .getLog(ContractListWidget.class);
038:
039: private ListWidget list;
040:
041: public ContractListWidget() {
042: }
043:
044: protected void init() throws Exception {
045: setViewSelector("contract/contractList");
046: log.debug("TemplateContractListWidget init called");
047:
048: initList();
049: }
050:
051: protected void initList() throws Exception {
052: list = new ListWidget();
053: list.setDataProvider(new TemplateContractListDataProvider());
054: list.addField("id", "#Id");
055: list.addField("company", "#Company");
056: list.addField("person", "#Person");
057: list.addField("notes", "#Notes");
058: list.addField("dummy", null, false);
059: addWidget("contractList", list);
060: }
061:
062: private void refreshList() throws Exception {
063: this .list.getDataProvider().refreshData();
064: }
065:
066: public void handleEventAdd(String eventParameter) throws Exception {
067: getFlowCtx().start(new ContractAddEditWidget(),
068: new FlowContext.Handler() {
069: private static final long serialVersionUID = 1L;
070:
071: public void onFinish(Object returnValue)
072: throws Exception {
073: log.debug("Contract added with Id of "
074: + returnValue + " sucessfully");
075: refreshList();
076: }
077:
078: public void onCancel() throws Exception {
079: }
080: });
081: }
082:
083: public void handleEventRemove(String eventParameter)
084: throws Exception {
085: Long id = ((ContractMO) this .list
086: .getRowFromRequestId(eventParameter)).getId();
087: getGeneralDAO().remove(ContractMO.class, id);
088: refreshList();
089: log.debug("Contract with Id of " + id + " removed sucessfully");
090: }
091:
092: public void handleEventEdit(String eventParameter) throws Exception {
093: Long id = ((ContractMO) this .list
094: .getRowFromRequestId(eventParameter)).getId();
095: getFlowCtx().start(new ContractAddEditWidget(id));
096: }
097:
098: public void handleEventCancel(String eventParameter)
099: throws Exception {
100: getFlowCtx().cancel();
101: }
102:
103: private class TemplateContractListDataProvider extends
104: MemoryBasedListDataProvider {
105: private static final long serialVersionUID = 1L;
106:
107: protected TemplateContractListDataProvider() {
108: super (ContractMO.class);
109: }
110:
111: public List loadData() throws Exception {
112: return getGeneralDAO().getAll(ContractMO.class);
113: }
114: }
115: }
|