Package clips.contract.info.contractService

Source Code of clips.contract.info.contractService.TreeModelServiceGroup

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

package clips.contract.info.contractService;

import cli_fmw.delegate.directory.Directory;
import cli_fmw.delegate.directory.DirectoryItem;
import clips.delegate.directory.complex.DirectoryServicesGroupItem;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.Selector;
import cli_fmw.main.ClipsException;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;

/**
* Модель дерева, не отображающая листки
* @author ViP
*/
public class TreeModelServiceGroup extends DefaultTreeModel {

    Selector<DirectoryItem> items;

    public TreeModelServiceGroup(Directory delegate) throws ClipsException {
        super(new DefaultMutableTreeNode("Группы услуг"));
        items = delegate.getItems();
    }
   
    @Override
    public int getChildCount(Object parent) {
        //try {
            if(parent instanceof DefaultMutableTreeNode) {
                return items.size();
            } else {
                DirectoryServicesGroupItem item = (DirectoryServicesGroupItem)parent;
                return item.getItems().size();
            }
    /*    } catch (ClipsException ex) {
            ex.printStackTrace();
        }
        return 0;*/
    }


   
    @Override
    public Object getChild(Object parent, int index) {
      //  try {
            if(parent instanceof DefaultMutableTreeNode) {
              return items.get(index);
            } else {
                DirectoryServicesGroupItem item = (DirectoryServicesGroupItem)parent;
                return item.getItems().get(index);
            }
      /*  } catch (ClipsException ex) {
            ex.printStackTrace();
        }
        return null;*/
    }

    @Override
    public boolean isLeaf(Object node) {
        return getChildCount(node) == 0;
    }

    //Изменение текста группы услуг
    @Override
    public void valueForPathChanged(TreePath path, Object newValue) {
        try {
            DirectoryServicesGroupItem item = (DirectoryServicesGroupItem) path.getLastPathComponent();
            item.setTitle(newValue.toString());
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }

    @Override
    public int getIndexOfChild(Object parent, Object child) {
        //чтобы не ругался на каст
        return 0;
    }
}
TOP

Related Classes of clips.contract.info.contractService.TreeModelServiceGroup

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.