refineRelation.put(FeatureRelation.ATTRIBUTE, "attribute");
Object evtSource = evt.getSource();
if (Feature.class.isInstance(evtSource)) {
Feature feature = (Feature) evtSource;
FeatureNode featureNode = getTreeNode(root, feature);
treeTable.repaint();
} else if (FeatureModel.class.isInstance(evtSource)) {
if (propertyName.equals(FeatureModelProperties.FEATURE_ADDED)) {
Feature feature = (Feature) evt.getNewValue();
FeatureNode featureNode = new FeatureNode(context, feature);
//root.add(featureNode);
treeTableModel.insertNodeInto(featureNode, root, root.getChildCount());
} else if (propertyName.equals(FeatureModelProperties.FEATURE_REMOVED)) {
//--ɾ��һ���ڵ㣺�Ӹ��ڵ���ɾ���ýڵ㣬�����ýڵ�������ӽڵ���Ϊ���ڵ�
///---�����ڵ㣨��ϵ�ڵ㣩���ٰ��������ڵ㣬��ɾ�����ڵ�
Feature feature = (Feature) evt.getOldValue();
FeatureNode featureNode = getTreeNode(root, feature);
FeatureNode parent = (FeatureNode) featureNode.getParent();
//int index = parent.getIndex(featureNode);
//parent.remove(featureNode);
treeTableModel.removeNodeFromParent(featureNode);
List<FeatureNode> children = new ArrayList<FeatureNode>();
Enumeration e = featureNode.children();
while (e.hasMoreElements()) { //--���������ォchild��ӵ�root,��������e��ʹ�ñ����������ȷ
FeatureNode child = (FeatureNode) e.nextElement();
children.add(child);
}
Iterator<FeatureNode> it = children.iterator();
while (it.hasNext()) {
FeatureNode child = it.next();
//root.add(child);
treeTableModel.insertNodeInto(child, root, root.getChildCount());
}
boolean bHasMoreChildren = parent.children().hasMoreElements();
if (!bHasMoreChildren) {
//FeatureNode grandParent = (FeatureNode) parent.getParent();
//grandParent.remove(parent);
treeTableModel.removeNodeFromParent(parent);
}
} else if (propertyName.equals(FeatureModelProperties.RELATION_ADDED)) {
//--��������˾�����ϵ����endNode��ΪstartNode�����ӽڵ㣬�м���Ϲ�ϵ�ڵ�
FeatureRelation fr = (FeatureRelation) evt.getNewValue();
String relationName = fr.getName();
if (refineRelation.containsKey(relationName)) {
Feature start = fr.getStartFeature();
Feature end = fr.getEndFeature();
FeatureNode startNode = getTreeNode(root, start);
FeatureNode endNode = getTreeNode(root, end);
if (relationName.equals(FeatureRelation.DECOMPOSE)) {
FeatureNode compNode = startNode.getCompositionNode();
if (compNode == null) {
compNode = new FeatureNode(context, FeatureNode.NODE_TYPE_COMPOSITION);
//startNode.add(compNode);
treeTableModel.insertNodeInto(compNode, startNode, startNode.getChildCount());
}
//compNode.add(endNode);
treeTableModel.removeNodeFromParent(endNode);
treeTableModel.insertNodeInto(endNode, compNode, compNode.getChildCount());
} else if (relationName.equals(FeatureRelation.ATTRIBUTE)) {
FeatureNode compNode = startNode.getCharacterizationNode();
if (compNode == null) {
compNode = new FeatureNode(context, FeatureNode.NODE_TYPE_CHARACTERIZATION);
//startNode.add(compNode);
treeTableModel.insertNodeInto(compNode, startNode, startNode.getChildCount());
}
//compNode.add(endNode);
treeTableModel.removeNodeFromParent(endNode);
treeTableModel.insertNodeInto(endNode, compNode, compNode.getChildCount());
}
}
} else if (propertyName.equals(FeatureModelProperties.RELATION_REMOVED)) {
//--���ɾ���˾�����ϵ����endNode��Ϊroot, ���endNode�ĸ��ڵ�(��ϵ�ڵ㣩û�������ӽڵ��ˣ���ɾ��endNode�ĸ��ڵ�
FeatureRelation fr = (FeatureRelation) evt.getOldValue();
String relationName = fr.getName();
if (refineRelation.containsKey(relationName)) {
Feature start = fr.getStartFeature();
Feature end = fr.getEndFeature();
FeatureNode startNode = getTreeNode(root, start);
FeatureNode endNode = getTreeNode(root, end);
FeatureNode relationNode = (FeatureNode) endNode.getParent();
//root.add(endNode);