Package org.freeplane.core.ui.ribbon

Source Code of org.freeplane.core.ui.ribbon.RibbonBuildContext

package org.freeplane.core.ui.ribbon;

import java.util.Enumeration;

import org.freeplane.core.ui.ribbon.StructureTree.StructurePath;
import org.freeplane.core.ui.ribbon.StructureTree.StructureTreeHull;

public class RibbonBuildContext {
  private final RibbonBuilder ribbonBuilder;
  private StructurePath currentPath;

  /***********************************************************************************
   * CONSTRUCTORS
   **********************************************************************************/

  public RibbonBuildContext(RibbonBuilder builder) {
    this.ribbonBuilder = builder;
    currentPath = builder.structure.getRootPath();
  }
  /***********************************************************************************
   * METHODS
   **********************************************************************************/

  public RibbonBuilder getBuilder() {
    return ribbonBuilder;
  }
 
  public void processChildren(StructurePath path, ARibbonContributor parent) {
    WeightedMutableTreeNode<StructureTreeHull> parentNode = ribbonBuilder.structure.get(path);
    if(parentNode != null) {
      StructurePath lastPath = getCurrentPath();
      try {
        Enumeration<WeightedMutableTreeNode<StructureTreeHull>> children = parentNode.children();
        while (children.hasMoreElements()) {
          WeightedMutableTreeNode<StructureTreeHull> node = children.nextElement();
          currentPath = node.getUserObject().getPath();
          ((ARibbonContributor) node.getUserObject().getObject()).contribute(this, parent);
        }
      }
      finally {
        currentPath = lastPath;
      }
    }
  }
 
  public StructurePath getCurrentPath() {
    return this.currentPath;
  }
 
  public StructurePath getPathForObject(Object obj) {
    return ribbonBuilder.structure.getPathByUserObject(obj);
  }
 
  public boolean hasChildren(StructurePath path) {
    WeightedMutableTreeNode<StructureTreeHull> node = ribbonBuilder.structure.get(path);
    if(node != null) {
      return !node.isLeaf();
    }
    return false;
  }

  /***********************************************************************************
   * REQUIRED METHODS FOR INTERFACES
   **********************************************************************************/
TOP

Related Classes of org.freeplane.core.ui.ribbon.RibbonBuildContext

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.