Package hidb2.gui

Source Code of hidb2.gui.DBDataViewContentProvider

/**
* This file is part of HIDB2.
*
* HIDB2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PoJamas is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser Public License
* along with PoJamas.  If not, see <http://www.gnu.org/licenses/>.
*/

package hidb2.gui;

import hidb2.gui.node.DefaultNode;
import hidb2.gui.node.EnumItemListNode;
import hidb2.gui.node.FolderDescrNode;
import hidb2.gui.node.FolderDescrTitleNode;
import hidb2.gui.node.FolderListNode;
import hidb2.gui.node.ListDescrNode;
import hidb2.gui.node.ListDescrTitleNode;
import hidb2.gui.ressources.RscMan;
import hidb2.kern.FolderDescription;
import hidb2.kern.ListDescription;

import java.util.List;
import java.util.logging.Logger;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

/**
* Provides the content of the data tree
*
*/
public class DBDataViewContentProvider implements IStructuredContentProvider, ITreeContentProvider
  {
  final static Logger log = Logger.getLogger("hidb2.gui");

  private DBDataView _arbre;

  private DefaultNode invisibleRoot;

  private FolderDescrTitleNode FolderDescr;

  private ListDescrTitleNode ListDescr;

  public DBDataViewContentProvider(DBDataView arbre)
    {
    _arbre = arbre;
    if (_arbre != null)
      {
      DefaultNode.init(_arbre.getTree().getTree().getDisplay());
      }
    }

  public DefaultNode getRoot()
    {
    return invisibleRoot;
    }

  public void inputChanged(Viewer v, Object oldInput, Object newInput)
    {
    }

  public void dispose()
    {
    }

  public Object[] getElements(Object parent)
    {
    if ((parent == null) || ((_arbre != null) && (parent.equals(_arbre.getViewSite()))))
      {
      if (invisibleRoot == null)
        {
        initialize();
        }

      return getChildren(invisibleRoot);
      }

    return getChildren(parent);
    }

  public Object getParent(Object child)
    {
    if (child instanceof DefaultNode)
      {
      return ((DefaultNode) child).getParent();
      }
    return null;
    }

  public Object[] getChildren(Object parent)
    {
    if (parent instanceof DefaultNode)
      {
      return ((DefaultNode) parent).getChildren();
      }
    return new Object[0];
    }

  public boolean hasChildren(Object parent)
    {
    if (parent instanceof DefaultNode)
      return ((DefaultNode) parent).hasChildren();

    return false;
    }

  private void initialize()
    {
    invisibleRoot = new DefaultNode("root", "");

    updateFolderDescr(null);
    invisibleRoot.addChild(FolderDescr);

    // Fill tree with ListDescriptions
    updateListDescr(null);
    invisibleRoot.addChild(ListDescr);
    }

  /**
   * Create or Update the list of FolderDescription nodes.
   * @return
   */
  public FolderDescrTitleNode updateFolderDescr(FolderDescription fdin)
    {
    if (FolderDescr == null)
      {
      FolderDescr = new FolderDescrTitleNode("Folders", RscMan.IN_FILM);
      }

    List<FolderDescription> lstFldDescr = Application.getDataStore().getFolderDescriptionList();

    if (fdin == null)
      {
      FolderDescr.removeAllChildren();

      for (FolderDescription fd : lstFldDescr)
        {
        FolderDescr.addChild(new FolderListNode(fd));
        }
      }
    else
      {
      for (DefaultNode node : FolderDescr.getChildren())
        {
        FolderDescrNode fdn = (FolderDescrNode) node;

        fdn.setName(fdn.getDescr().getName());

        if (fdn.getDescr() == fdin)
          {
          fdn.removeAllChildren();
          fdn.createChildren();
          }
        }
      }

    return getFolderDescr();
    }

  public FolderDescrTitleNode getFolderDescr()
    {
    return FolderDescr;
    }

  /**
   * Create or Update the list of FolderDescription nodes.
   * @return
   */
  public ListDescrTitleNode updateListDescr(ListDescription ldin)
    {
    if (ListDescr == null)
      {
      ListDescr = new ListDescrTitleNode("Lists", RscMan.IN_LIST);
      }

    // List Description node filling
    List<ListDescription> lstLdDescr = Application.getDataStore().getListDescriptionList();

    if (ldin == null)
      {
      ListDescr.removeAllChildren();

      for (ListDescription fd : lstLdDescr)
        {
        ListDescr.addChild(new EnumItemListNode(fd));
        }
      }
    else
      {
      for (DefaultNode node : ListDescr.getChildren())
        {
        ListDescrNode fdn = (ListDescrNode) node;

        fdn.setName(fdn.getDescr().getName());

        if (fdn.getDescr() == ldin)
          {
          fdn.createChildren();
          }
        }
      }

    return getListDescr();
    }

  public ListDescrTitleNode getListDescr()
    {
    return ListDescr;
    }
  }
TOP

Related Classes of hidb2.gui.DBDataViewContentProvider

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.