Package de.FeatureModellingTool.InfoExplorer2

Source Code of de.FeatureModellingTool.InfoExplorer2.FeatureNode

/**
* @file: FeatureNode.java
* @author: tlc
* @date: 2006-12-9
* @version: 1.0.0
*/
package de.FeatureModellingTool.InfoExplorer2;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;


import de.FeatureModellingTool.FeatureModel.ConstraintModel;
import de.FeatureModellingTool.FeatureModel.Feature;
import de.FeatureModellingTool.FeatureModel.FeatureModel;
import de.FeatureModellingTool.GraphicalEditor.GraphicalEditor;
import de.reuse.Context;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;

/**
* @author tlc
*
*/
public class FeatureNode extends DefaultMutableTreeTableNode {
   
    public static final String NODE_TYPE_NORMAL = "feature";
    public static final String NODE_TYPE_ROOT = "root";
    public static final String NODE_TYPE_COMPOSITION = "composition";
    public static final String NODE_TYPE_SPECILIZATION = "specilization";
    public static final String NODE_TYPE_CHARACTERIZATION = "characterization";
   
    static private boolean sortNode = true; //--vp:�Ƿ�Ҫ�Խڵ�����
   
    static private FeatureSort sort = FeatureSort.getFeatureSort(); //--vp���Խڵ�������õ�׼��
   
    static private boolean dirFirst = true; //--vp: ����ʱĿ¼�ڵ�(���ӽڵ�Ľڵ㣩������Ҷ�ڵ�ǰ
   
    private String nodeType = null;
   
    private Context context = null;
   
    private Feature feature = null;
   
    private boolean isVirtualRoot = false;
   
    public FeatureNode(Context context, Feature feature) {
  this.context = context;
  this.feature = feature;
  nodeType = NODE_TYPE_NORMAL;
    }

    public FeatureNode(Context context, String nodeType) {
  this.context = context;
  isVirtualRoot = nodeType.equals(NODE_TYPE_ROOT);
  this.nodeType = nodeType;
    }

    @Override
    public String toString() {
  if (isVirtualRoot){
            String name = "";
           
            FeatureModel fm = getFeatureModel();
            if(fm != null){
                name = fm.getName();
            }
           
      return "FM: " + name;
        }
  else if (nodeType.equals(FeatureNode.NODE_TYPE_NORMAL))
      return feature.getName();
  else if (nodeType.equals(FeatureNode.NODE_TYPE_COMPOSITION))
      return "";//"�ֽ�";
  else if (nodeType.equals(FeatureNode.NODE_TYPE_SPECILIZATION))
      return "";//"�ػ�";
  else if (nodeType.equals(FeatureNode.NODE_TYPE_CHARACTERIZATION))
      return "";//"����";
  else
      return super.toString();
    }
   
    public Feature getFeature() {
  return feature;
    }
   
    protected List<FeatureNode> createChildren() {
  List<Feature> listFeature;
  if (isVirtualRoot) {
      listFeature =  FeatureModelHelper.getAllRoots(getFeatureModel(), getConstraintModel());
  }
  else {
      listFeature = FeatureModelHelper.getChildrenFeature(getFeatureModel(),
        getConstraintModel(), feature.getID());     
  }
 
  return createFeatureNodesFromFeatures(listFeature);

    }
   
    protected List<FeatureNode> createChildrenByComposition() {
  List<Feature> listFeature;
  if (isVirtualRoot) {
      listFeature =  FeatureModelHelper.getAllRoots(getFeatureModel(), getConstraintModel());     
  }
  else {
      FeatureModel featureModel = getFeatureModel();
      if (featureModel == null)
    listFeature = new ArrayList<Feature>();
      else
    listFeature = getFeatureModel().getChildrenFeatureByComposition(feature.getID());     
  }
  return createFeatureNodesFromFeatures(listFeature);
    }
   
    protected List<FeatureNode> createChildrenByCharacterization() {
  List<Feature> listFeature;
  if (isVirtualRoot) {
      listFeature =  FeatureModelHelper.getAllRoots(getFeatureModel(), getConstraintModel());     
  }
  else {
      FeatureModel featureModel = getFeatureModel();
      if (featureModel == null)
    listFeature = new ArrayList<Feature>();
      else
    listFeature = getFeatureModel().getChildrenFeatureByCharacterization(feature.getID());     
  }
  return createFeatureNodesFromFeatures(listFeature);
    }
   
    protected List<FeatureNode> createChildrenBySpecilization() {
  List<Feature> listFeature;
  if (isVirtualRoot) {
      listFeature =  FeatureModelHelper.getAllRoots(getFeatureModel(), getConstraintModel());     
  }
  else {
      ConstraintModel constraintModel = getConstraintModel();
      if (constraintModel == null)
    listFeature = new ArrayList<Feature>();
      else
    listFeature = getConstraintModel().getChildrenFeatureBySpecilization(feature.getID());     
  }
  return createFeatureNodesFromFeatures(listFeature);
    }
   
    private List<FeatureNode> createFeatureNodesFromFeatures(List<Feature> listFeature) {
 
  if (sortNode) {
      listFeature = sort.sortFeature(listFeature);
  }
 
  List<FeatureNode> listNode = new ArrayList<FeatureNode>();
  Iterator<Feature> it = listFeature.iterator();
  while (it.hasNext()) {
      Feature _feature = it.next();
      FeatureNode node = new FeatureNode(context, _feature);
      listNode.add(node);
  }
  return listNode; 
    }
   
    public String getNodeType() {
  return nodeType;
    }
   
    private FeatureNode getRelationNode(String nodeType) {
  Enumeration e = this.children();
  while (e.hasMoreElements()) {
      FeatureNode child = (FeatureNode)e.nextElement();
      if (child.nodeType.equals(nodeType))
    return child;
  }
  return null;
    }
    public FeatureNode getCompositionNode() {
  return getRelationNode(FeatureNode.NODE_TYPE_COMPOSITION);
    }
   
    public FeatureNode getSpecilizationNode() {
  return getRelationNode(FeatureNode.NODE_TYPE_SPECILIZATION);
    }
   
    public FeatureNode getCharacterizationNode() {
  return getRelationNode(FeatureNode.NODE_TYPE_CHARACTERIZATION);
    }
   
    private FeatureModel getFeatureModel() {
  return (FeatureModel)context.getValue(GraphicalEditor.FEATURE_MODEL);
    }
   
    private ConstraintModel getConstraintModel() {
  return (ConstraintModel)context.getValue(GraphicalEditor.CONSTRAINT_MODEL);
    }

    static public void setSortNode(boolean isSort) {
  sortNode = isSort;
    }
   
    static public void setSortAlgorithm(FeatureSort sortAlg) {
  sort = sortAlg;
    }
   
}
TOP

Related Classes of de.FeatureModellingTool.InfoExplorer2.FeatureNode

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.