Package clips.service.newSerRen

Source Code of clips.service.newSerRen.TreeModelForNewSerRen

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

package clips.service.newSerRen;

import cli_fmw.delegate.directory.complex.DirectoryLocator;
import clips.delegate.directory.complex.DirectoryPacketTemplate;
import clips.delegate.directory.complex.DirectoryPacketTemplateListItem;
import clips.delegate.directory.complex.DirectoryPacketTemplateItem;
import clips.delegate.directory.filtered.DirectoryService;
import clips.delegate.directory.filtered.DirectoryServiceItem;
import clips.delegate.directory.complex.DirectoryServicesGroup;
import clips.delegate.directory.complex.DirectoryServicesGroupItem;
import cli_fmw.utils.Selector;
import cli_fmw.utils.SelectorEditableExceptional;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.ErrorValue;
import cli_fmw.utils.MessageBox;
import beans.directory.simple.entities.MedexamType;
import framework.utils.ROList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;

/**
*
* @author lacoste
*/
public class TreeModelForNewSerRen implements TreeModel {

    DefaultMutableTreeNode root;   
    private final static DefaultMutableTreeNode SERVICES = new DefaultMutableTreeNode("Услуги");
    private final static DefaultMutableTreeNode SERVICE_PACKETS = new DefaultMutableTreeNode("Пакеты услуг");
    private final static DefaultMutableTreeNode medexamS = new DefaultMutableTreeNode("Медосмотры");
    private final static DefaultMutableTreeNode PROFCHECKUPS = new DefaultMutableTreeNode("Профосмотры при приеме на работу");
    private final static DefaultMutableTreeNode DISPANSERS = new DefaultMutableTreeNode("Диспансеризации");

    ArrayList<DirectoryPacketTemplateItem> packetList = new ArrayList<DirectoryPacketTemplateItem>();
    ArrayList<DirectoryPacketTemplateItem> medexamList = new ArrayList<DirectoryPacketTemplateItem>();
    ArrayList<DirectoryPacketTemplateItem> profcheckupList = new ArrayList<DirectoryPacketTemplateItem>();
    ArrayList<DirectoryPacketTemplateItem> dispanserList = new ArrayList<DirectoryPacketTemplateItem>();


    Map<DirectoryServicesGroupItem, Selector<DirectoryServiceItem>> services =
            new HashMap<DirectoryServicesGroupItem, Selector<DirectoryServiceItem>>();

    DirectoryServicesGroup dsg;
    DirectoryService ds;

    public TreeModelForNewSerRen() throws ClipsException {

        root = new DefaultMutableTreeNode("Назначить:");
        root.add(SERVICES);
        root.add(SERVICE_PACKETS);
        root.add(medexamS);
        root.add(PROFCHECKUPS);
        root.add(DISPANSERS);

        dsg = (DirectoryServicesGroup) DirectoryLocator.getDirectory(DirectoryServicesGroup.class, false);
        ds = (DirectoryService) DirectoryLocator.getDirectory(DirectoryService.class, false);

        DirectoryPacketTemplate dp = (DirectoryPacketTemplate)
                        DirectoryLocator.getDirectory(DirectoryPacketTemplate.class, false);
        ROList<DirectoryPacketTemplateItem> itemsList = dp.getItemsList();
        for (int i = 0; i < itemsList.size(); i++) {
            DirectoryPacketTemplateItem item = itemsList.get(i);
            switch (item.getmedexamType().getID()) {
                case 0 : {
                    packetList.add(item);
                    break;
                }
                case MedexamType.medexam_TYPE_medexam : {
                    medexamList.add(item);
                    break;
                }
                case MedexamType.medexam_TYPE_PROFCHECKUP : {
                    profcheckupList.add(item);
                    break;
                }
                case MedexamType.medexam_TYPE_DISPANSER : {
                    dispanserList.add(item);
                    break;
                }
                default: throw new ClipsException("Некорректный тип медосмотра");
            }
        }
        dp.getItemsList();
    }  
   
    @Override
    public Object getRoot() {
        return this.root;
    }

    private Selector<DirectoryServiceItem> getServices(DirectoryServicesGroupItem item) throws ClipsException {
        Selector<DirectoryServiceItem> ss = services.get(item);
        if(ss == null) {
            ss = ds.getFilteredItems(item);
            services.put(item, ss);
        }
        return ss;
    }   
   
    @Override
    public Object getChild(Object parent, int index) {
        if (parent == root) {
            return root.getChildAt(index);
        } else if (parent == SERVICES) {
            return dsg.getItems().get(index);
        } else if (parent instanceof DirectoryServicesGroupItem) {
            try {
                DirectoryServicesGroupItem item = (DirectoryServicesGroupItem) parent;
                SelectorEditableExceptional<DirectoryServicesGroupItem> groups = item.getItems();
                if (index < groups.size()) {
                    return groups.get(index);
                } else {
                    return getServices(item).get(index - groups.size());
                }
            } catch (ClipsException ex) {
                return new ErrorValue(ex);
            }

        }  else if (parent == SERVICE_PACKETS) {
            return packetList.get(index);
        else if (parent == medexamS) {
            return medexamList.get(index);
        else if (parent == PROFCHECKUPS) {
            return profcheckupList.get(index);
        else if (parent == DISPANSERS) {
            return dispanserList.get(index);

        } else if (parent instanceof DirectoryPacketTemplateItem) {
            DirectoryPacketTemplateItem item = (DirectoryPacketTemplateItem) parent;
            DirectoryPacketTemplateListItem pItem = item.getPacketItem(index);
            Object s = pItem;
            return s;
        } else {
            throw new IllegalArgumentException("Неизвестный элемент дерева");
        }
    }
   
    @Override
    public int getChildCount(Object parent) {  
        if (parent == root) {
            return root.getChildCount();
        }
        else if (parent == SERVICES) {
            return dsg.getItems().size();
        }
        else if (parent instanceof DirectoryServicesGroupItem) {
            try {
                DirectoryServicesGroupItem item = (DirectoryServicesGroupItem) parent;
                return item.getItems().size() + getServices(item).size();
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
                return 0;
            }
        }  else if (parent == SERVICE_PACKETS) {
            return packetList.size();
        else if (parent == medexamS) {
            return medexamList.size();
        else if (parent == PROFCHECKUPS) {
            return profcheckupList.size();
        else if (parent == DISPANSERS) {
            return dispanserList.size();

        }
        else if (parent instanceof DirectoryPacketTemplateItem) {
            try {
                DirectoryPacketTemplateItem item = (DirectoryPacketTemplateItem) parent;
                return item.getPacketItemCount();
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
                return 0;
            }
        }
        else {
            return 0;
        }
    }


    @Override
    public boolean isLeaf(Object node) {
        if (node instanceof DirectoryServiceItem){
            return true;
        }
        if (node instanceof DirectoryPacketTemplateListItem) {
            return true;
        }      
        return false;
    }

    @Override
    public void valueForPathChanged(TreePath path, Object newValue) {

    }

    @Override
    public int getIndexOfChild(Object parent, Object child) {       
        return 0;
    }

    @Override
    public void addTreeModelListener(TreeModelListener l) {
    }

    @Override
    public void removeTreeModelListener(TreeModelListener l) {
    } 
   
}
TOP

Related Classes of clips.service.newSerRen.TreeModelForNewSerRen

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.