Package clips.delegate.expenditure

Source Code of clips.delegate.expenditure.ExpenditureLocal$ExpenditureList

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package clips.delegate.expenditure;

import beans.expenditure.ExpenditureBean;
import beans.expenditure.ExpenditureBeanRemote;
import beans.expenditure.entity.ExpenditureDetails;
import clips.delegate.directory.filtered.DirectoryServiceItem;
import cli_fmw.delegate.DelegateStandart;
import cli_fmw.delegate.cache.ExtraDataManager;
import cli_fmw.delegate.lists.DataChunkList;
import cli_fmw.utils.SelectorEditable;
import cli_fmw.main.ClipsException;
import java.util.HashMap;
import java.util.Iterator;


/**
*
* @author axe
*/
public class ExpenditureLocal extends DelegateStandart<ExpenditureBeanRemote> {

    private HashMap<DirectoryServiceItem, ExpenditureList> expenditureList
            = new HashMap<DirectoryServiceItem, ExpenditureList>();
    private ExtraDataManager ecm;
   
    public ExpenditureLocal() throws ClipsException {
        super(ExpenditureBean.class.getSimpleName());
        initBean();
        ecm = new ExtraDataManager(getBean(), this, false);
    }
   
    public boolean canModify() throws ClipsException {
        return getBeanRights().isCommandAccessible(ExpenditureBean.COMMAND_WRITE_EXPENDITURE);
    }
   
    @Override
    public void save1() throws ClipsException {
        Iterator<ExpenditureList> i = expenditureList.values().iterator();
        while(i.hasNext()) {
            ExpenditureList el = i.next();
            el.save();
        }
    }

    @Override
    public void restore() {
        Iterator<ExpenditureList> i = expenditureList.values().iterator();
        while(i.hasNext()) {
            ExpenditureList el = i.next();
            el.restore();
        }
        fireContentStateEvent();
    }

    @Override
    public boolean isDirty() {
        Iterator<ExpenditureList> i = expenditureList.values().iterator();
        while(i.hasNext()) {
            ExpenditureList el = i.next();
            if(el.isDirty()) {
                return true;
            }
        }
        return false;
    }


    public SelectorEditable<ExpenditureItemData> getExpenditureList(DirectoryServiceItem service) throws
            ClipsException {
        ExpenditureList list = expenditureList.get(service);
        if (list == null) {
            list = new ExpenditureList(ecm, service);
            expenditureList.put(service, list);
        }
        return list.selector();       
    }
   
   
    class ExpenditureList extends DataChunkList<ExpenditureItemData> {
        private DirectoryServiceItem service;
       
        public ExpenditureList(ExtraDataManager contaner, DirectoryServiceItem service) {
            super(contaner);
            this.service = service;
        }
       
        @Override
        protected void deleteDB(ExpenditureItemData data) throws Exception {
             bean().removeExpenditure(data.getDetails().getId());
        }

        @Override
        protected int saveDB(ExpenditureItemData data) throws Exception {
            return bean().setExpenditure(data.getDetails());
        }

        @Override
        protected void loadDB() throws Exception {
            for(ExpenditureDetails d : bean().getExpenditureList(service.getID())) {
                initByDetails(new ExpenditureItemData(d));
            }
        }
    }  
}
TOP

Related Classes of clips.delegate.expenditure.ExpenditureLocal$ExpenditureList

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.