package de.FeatureModellingTool.Pattern;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import java.util.Map.Entry;
import research.ConnectionFigure;
import research.DrawingView;
import research.Figure;
import research.FigureEnumeration;
import research.figure.ArrowTip;
import de.FeatureModellingTool.FeatureModel.CFRelation;
import de.FeatureModellingTool.FeatureModel.CompositeConstraint;
import de.FeatureModellingTool.FeatureModel.CompositeConstraintEditor;
import de.FeatureModellingTool.FeatureModel.Constraint;
import de.FeatureModellingTool.FeatureModel.ConstraintModel;
import de.FeatureModellingTool.FeatureModel.ConstraintModelEditor;
import de.FeatureModellingTool.FeatureModel.Feature;
import de.FeatureModellingTool.FeatureModel.FeatureEditor;
import de.FeatureModellingTool.FeatureModel.FeatureModel;
import de.FeatureModellingTool.FeatureModel.FeatureModelEditor;
import de.FeatureModellingTool.FeatureModel.FeatureProperties;
import de.FeatureModellingTool.FeatureModel.FeatureRelation;
import de.FeatureModellingTool.FeatureModel.GroupConstraint;
import de.FeatureModellingTool.FeatureModel.GroupConstraintEditor;
import de.FeatureModellingTool.FeatureModel.VPConstraint;
import de.FeatureModellingTool.FeatureModel.VPConstraintEditor;
import de.FeatureModellingTool.GraphicalEditor.ConstraintConnection;
import de.FeatureModellingTool.GraphicalEditor.CrossDecoration;
import de.FeatureModellingTool.GraphicalEditor.AttributeConnection;
import de.FeatureModellingTool.GraphicalEditor.FeatureFigure;
import de.FeatureModellingTool.GraphicalEditor.DecomposeConnection;
public class FeatureModelHelper {
public static Figure createFeatureFigure() {
return null;
}
private static void collectSubFeatureIDs(Feature feature , HashSet<String> hsSubFeatureIDs) {
hsSubFeatureIDs.add(feature.getID());
for (Iterator<FeatureRelation> itRelation
= (Iterator<FeatureRelation>)feature.getAllRelatedRelation().iterator()
; itRelation.hasNext() ; ) {
FeatureRelation relation = itRelation.next();
if (ConstantDefinition.isStructRelation(relation)
&& relation.getStartFeature().getID().equals(feature.getID())
&& !hsSubFeatureIDs.contains(relation.getEndFeature().getID())) {
collectSubFeatureIDs(relation.getEndFeature() , hsSubFeatureIDs);
}
}
}
public static void cloneFeatureTree(Feature feature
, FeatureEditor featureEditor
, FeatureModel featureModel
, FeatureModelEditor featureModelEditor
, ConstraintModel constraintModel
, ConstraintModelEditor constraintModelEditor
, GroupConstraintEditor groupConstraintEditor
, CompositeConstraintEditor compositeConstraintEditor
, VPConstraintEditor vpConstraintEditor) {
HashSet<String> hsSubFeatureIDs = new HashSet<String>();
FeatureModelHelper.collectSubFeatureIDs(feature , hsSubFeatureIDs);
Hashtable<String , String> htNameMap = new Hashtable<String , String>();
FeatureModelHelper.cloneFeatureTree(feature , featureEditor
, featureModel , featureModelEditor , htNameMap , hsSubFeatureIDs);
Set constraints = new HashSet();
constraints.clear();
constraints.addAll(featureModel.getAllFeatureRelation().values());
for (Iterator<FeatureRelation> itRelation = constraints.iterator() ; itRelation.hasNext() ; ) {
FeatureRelation relation = itRelation.next();
if (!htNameMap.containsKey(relation.getID())) {
Feature start = featureModel.getFeature(htNameMap.get(relation.getStartFeature().getID()));
Feature end = featureModel.getFeature(htNameMap.get(relation.getEndFeature().getID()));
if (start!=null || end!=null) {
if (start==null)
start = relation.getStartFeature();
if (end==null)
end = relation.getEndFeature();
FeatureRelation newRelation = featureModelEditor.addRelation(relation.getName() , start, end);
htNameMap.put(relation.getID() , newRelation.getID());
}
}
}
constraints.clear();
constraints.addAll(constraintModel.getAllGroupConstraint().values());
for (Iterator<GroupConstraint> itConstraint = constraints.iterator() ; itConstraint.hasNext() ; ) {
GroupConstraint gc = itConstraint.next();
boolean newFeature = false;
boolean allNewFeature = true;
for (Iterator<Feature> itFeature = gc.getFeatureSet().iterator() ; itFeature.hasNext() ; ) {
Feature constraintFeature = itFeature.next();
if (htNameMap.containsKey(constraintFeature.getID())) {
newFeature = true;
} else {
allNewFeature = false;
}
}
GroupConstraint newConstraint = null;
if (newFeature) {
if (allNewFeature) {
newConstraint = constraintModelEditor.addGroupConstraint();
groupConstraintEditor.setType(newConstraint , gc.getType());
htNameMap.put(gc.getID() , newConstraint.getID());
} else {
newConstraint = gc;
}
for (Iterator<Feature> itFeature = gc.getFeatureSet().iterator() ; itFeature.hasNext() ; ) {
Feature constraintFeature = itFeature.next();
if (allNewFeature || htNameMap.containsKey(constraintFeature.getID())) {
constraintFeature = featureModel.getFeature(htNameMap.get(constraintFeature.getID()));
groupConstraintEditor.addFeature(newConstraint , constraintFeature);
}
}
}
}
constraints.clear();
constraints.addAll(constraintModel.getAllCompositeConstraint().values());
for (Iterator<CompositeConstraint> itConstraint = constraints.iterator() ; itConstraint.hasNext() ; ) {
CompositeConstraint gc = itConstraint.next();
boolean newFeature = false;
boolean allNewFeature = true;
for (Iterator<Feature> itFeature = gc.getSinkFeatureSet().iterator() ; itFeature.hasNext() ; ) {
Feature constraintFeature = itFeature.next();
if (htNameMap.containsKey(constraintFeature.getID())) {
newFeature = true;
} else {
allNewFeature = false;
}
}
for (Iterator<Feature> itFeature = gc.getSourceFeatureSet().iterator() ; itFeature.hasNext() ; ) {
Feature constraintFeature = itFeature.next();
if (htNameMap.containsKey(constraintFeature.getID())) {
newFeature = true;
} else {
allNewFeature = false;
}
}
if (newFeature) {
CompositeConstraint newConstraint = null;
if (allNewFeature) {
newConstraint = constraintModelEditor.addCompositeConstraint();
compositeConstraintEditor.setPLType(newConstraint , gc.getPLType());
compositeConstraintEditor.setSinkType(newConstraint , gc.getSinkType());
compositeConstraintEditor.setSourceType(newConstraint , gc.getSourceType());
htNameMap.put(gc.getID() , newConstraint.getID());
} else {
newConstraint = gc;
}
for (Iterator<Feature> itFeature = gc.getSourceFeatureSet().iterator() ; itFeature.hasNext() ; ) {
Feature constraintFeature = itFeature.next();
if (allNewFeature || htNameMap.containsKey(constraintFeature.getID())) {
constraintFeature = featureModel.getFeature(htNameMap.get(constraintFeature.getID()));
compositeConstraintEditor.addSourceFeature(newConstraint , constraintFeature);
}
}
for (Iterator<Feature> itFeature = gc.getSinkFeatureSet().iterator() ; itFeature.hasNext() ; ) {
Feature constraintFeature = itFeature.next();
if (allNewFeature || htNameMap.containsKey(constraintFeature.getID())) {
constraintFeature = featureModel.getFeature(htNameMap.get(constraintFeature.getID()));
compositeConstraintEditor.addSinkFeature(newConstraint , constraintFeature);
}
}
}
}
constraints.clear();
constraints.addAll(constraintModel.getAllVPConstraint().values());
for (Iterator<VPConstraint> itConstraint = constraints.iterator() ; itConstraint.hasNext() ; ) {
VPConstraint gc = itConstraint.next();
boolean newFeature = false;
boolean allNewFeature = true;
for (Iterator<Feature> itFeature = gc.getSinkFeatureSet().iterator() ; itFeature.hasNext() ; ) {
Feature constraintFeature = itFeature.next();
if (htNameMap.containsKey(constraintFeature.getID())) {
newFeature = true;
} else {
allNewFeature = false;
}
}
for (Iterator<Feature> itFeature = gc.getSourceFeatureSet().iterator() ; itFeature.hasNext() ; ) {
Feature constraintFeature = itFeature.next();
if (htNameMap.containsKey(constraintFeature.getID())) {
newFeature = true;
} else {
allNewFeature = false;
}
}
if (newFeature) {
VPConstraint newConstraint = null;
if (allNewFeature) {
newConstraint = constraintModelEditor.addVPConstraint();
vpConstraintEditor.setType(newConstraint , gc.getType());
htNameMap.put(gc.getID() , newConstraint.getID());
} else {
newConstraint = gc;
}
for (Iterator<Feature> itFeature = gc.getSourceFeatureSet().iterator() ; itFeature.hasNext() ; ) {
Feature constraintFeature = itFeature.next();
if (allNewFeature || htNameMap.containsKey(constraintFeature.getID())) {
constraintFeature = featureModel.getFeature(htNameMap.get(constraintFeature.getID()));
vpConstraintEditor.addSourceFeature(newConstraint , constraintFeature);
}
}
for (Iterator<Feature> itFeature = gc.getSinkFeatureSet().iterator() ; itFeature.hasNext() ; ) {
Feature constraintFeature = itFeature.next();
if (allNewFeature || htNameMap.containsKey(constraintFeature.getID())) {
constraintFeature = featureModel.getFeature(htNameMap.get(constraintFeature.getID()));
vpConstraintEditor.addSinkFeature(newConstraint , constraintFeature);
}
}
}
}
constraints.clear();
constraints.addAll(constraintModel.getAllCFRelation().values());
for (Iterator<CFRelation> itConstraint = constraints.iterator() ; itConstraint.hasNext() ; ) {
CFRelation gc = itConstraint.next();
boolean newFeature = false;
Feature cfFeature = gc.getFeature();
if (htNameMap.containsKey(gc.getFeature().getID())) {
cfFeature = featureModel.getFeature(htNameMap.get(gc.getFeature().getID()));
newFeature = true;
}
Constraint cfConstraint = gc.getConstraint();
if (htNameMap.containsKey(gc.getConstraint().getID())) {
cfConstraint = constraintModel.getConstraint(htNameMap.get(gc.getConstraint().getID()));
newFeature = true;
}
if (newFeature) {
CFRelation newConstraint = constraintModelEditor.addCFRelation(cfFeature , cfConstraint , gc.isSource() , gc.getModifier());
htNameMap.put(gc.getID() , newConstraint.getID());
}
}
}
private static void cloneFeatureTree(Feature feature
, FeatureEditor featureEditor
, FeatureModel featureModel
, FeatureModelEditor featureModelEditor
, Hashtable<String , String> htNameMap
, HashSet<String> hsSubFeatureIDs) {
Feature newFeature = featureModelEditor.addFeature(feature.getName());
htNameMap.put(feature.getID() , newFeature.getID());
featureEditor.setBindingTime(newFeature , feature.getBindingTime());
featureEditor.setCategory(newFeature , feature.getCategory());
featureEditor.setDescription(newFeature , feature.getDescription());
featureEditor.setVariability(newFeature , feature.getVariability());
for (Iterator<FeatureRelation> itRelation
= feature.getAllRelatedRelation().iterator()
; itRelation.hasNext() ; ) {
FeatureRelation relation = itRelation.next();
if (ConstantDefinition.isStructRelation(relation)
&& relation.getStartFeature().getID().equals(feature.getID())) {
cloneFeatureTree(relation.getEndFeature() , featureEditor , featureModel , featureModelEditor , htNameMap , hsSubFeatureIDs);
}
}
}
public static void removeFeatureTree(Feature feature
, FeatureModel featureModel
, FeatureModelEditor featureModelEditor
, ConstraintModel constraintModel
, ConstraintModelEditor constraintModelEditor
, GroupConstraintEditor groupConstraintEditor
, CompositeConstraintEditor compositeConstraintEditor
, VPConstraintEditor vpConstraintEditor) {
HashSet<String> hsSubFeatureIDs = new HashSet<String>();
FeatureModelHelper.collectSubFeatureIDs(feature , hsSubFeatureIDs);
Set constraints = new HashSet();
constraints.clear();
constraints.addAll(featureModel.getAllFeatureRelation().values());
for (Iterator<FeatureRelation> itRelation = constraints.iterator()
; itRelation.hasNext() ; ) {
FeatureRelation relation = itRelation.next();
if (hsSubFeatureIDs.contains(relation.getStartFeature().getID())
|| hsSubFeatureIDs.contains(relation.getEndFeature().getID())) {
featureModelEditor.removeRelation(relation.getID());
}
}
constraints.clear();
constraints.addAll(constraintModel.getAllCFRelation().values());
for (Iterator<CFRelation> itRelation = constraints.iterator()
; itRelation.hasNext() ; ) {
CFRelation relation = itRelation.next();
if (hsSubFeatureIDs.contains(relation.getFeature())) {
constraintModelEditor.removeCFRelation(relation.getID());
}
}
}
public static void pasteFeatureTree(Feature fSrc
, FeatureModel fmSrc
, ConstraintModel cmSrc
, DrawingView dvSrc
, Feature fDist
, FeatureModel fmDist
, ConstraintModel cmDist
, DrawingView dvDist
, FeatureModelEditor fmEditor
, FeatureEditor fEditor) {
Set<Feature> features = new HashSet<Feature>(fmSrc.getAllFeature().values());
features.remove(fSrc);
Hashtable<String , Figure> srcFigureMap = new Hashtable<String , Figure>();
for (FigureEnumeration fe=dvSrc.getDrawing().getFigures()
; fe.hasMoreElements() ; ) {
Figure figure = fe.nextFigure();
srcFigureMap.put((String)figure.getAttribute("id") , figure);
}
Hashtable<String , String> nameMap = new Hashtable<String , String>();
nameMap.put(fSrc.getID() , fDist.getID());
Hashtable<String , Figure> figureMap = new Hashtable<String , Figure>();
for (FigureEnumeration fe=dvDist.getDrawing().getFigures()
; fe.hasMoreElements() ; ) {
Figure figure = fe.nextFigure();
if (fDist.getID().equals(figure.getAttribute("id"))) {
figureMap.put(fDist.getID() , figure);
break;
}
}
Figure rSrc = srcFigureMap.get(fSrc.getID());
Figure rDist = figureMap.get(fDist.getID());
for (Iterator<Feature> itFeature=features.iterator() ; itFeature.hasNext() ; ) {
Feature feature = itFeature.next();
Feature newFeature = fmEditor.addFeature(feature.getName());
fEditor.setBindingTime(newFeature , feature.getBindingTime());
fEditor.setCategory(newFeature , feature.getCategory());
fEditor.setVariability(newFeature , feature.getVariability());
nameMap.put(feature.getID() , newFeature.getID());
FeatureFigure figDist = new FeatureFigure();
figDist.setText(feature.getName());
figDist.setAttribute("id" , feature.getID());
figDist.setAttribute(FeatureProperties.VARIABILITY , feature.getVariability().getName());
dvDist.add(figDist);
Figure fOld = srcFigureMap.get(feature.getID());
figDist.moveBy(rDist.getDisplayBox().x - rSrc.getDisplayBox().x + fOld.getDisplayBox().x
, rDist.getDisplayBox().y - rSrc.getDisplayBox().y + fOld.getDisplayBox().y);
figureMap.put(newFeature.getID() , figDist);
}
for (Iterator<FeatureRelation> itRelation=fmSrc.getAllFeatureRelation().values().iterator()
; itRelation.hasNext() ; ) {
FeatureRelation relation = itRelation.next();
FeatureRelation newRelation = fmEditor.addRelation(relation.getName() , fmDist.getFeature(nameMap.get(relation.getStartFeature().getID())) , fmDist.getFeature(nameMap.get(relation.getEndFeature().getID())));
nameMap.put(relation.getID() , newRelation.getID());
ConnectionFigure cf = null;
if (FeatureRelation.ATTRIBUTE.equals(newRelation.getName())) {
AttributeConnection dvc = new AttributeConnection();
cf = dvc;
} else if (FeatureRelation.DECOMPOSE.equals(newRelation.getName())) {
DecomposeConnection ic = new DecomposeConnection();
cf = ic;
} else if (FeatureRelation.REQUIRE.equals(newRelation.getName())) {
ConstraintConnection cc = new ConstraintConnection(FeatureRelation.REQUIRE);
cc.setEndDecoration(new ArrowTip());
cf = cc;
} else if (FeatureRelation.EXCLUDE.equals(newRelation.getName())) {
ConstraintConnection cc = new ConstraintConnection(FeatureRelation.EXCLUDE);
cc.setMidDecoration(new CrossDecoration(5));
cf = cc;
}
if (cf!=null) {
cf.setAttribute("id" , newRelation.getID());
cf.startPoint(figureMap.get(newRelation.getStartFeature().getID()).center().x , figureMap.get(newRelation.getStartFeature().getID()).center().y);
cf.endPoint(figureMap.get(newRelation.getEndFeature().getID()).center().x , figureMap.get(newRelation.getEndFeature().getID()).center().y);
if (de.FeatureModellingTool.Pattern.ConstantDefinition.isStructRelation(relation)) {
cf.connectStart(figureMap.get(newRelation.getStartFeature().getID()).getConnectors()[2]);
cf.connectEnd(figureMap.get(newRelation.getEndFeature().getID()).getConnectors()[1]);
} else {
cf.connectStart(figureMap.get(newRelation.getStartFeature().getID()).getConnectors()[0]);
cf.connectEnd(figureMap.get(newRelation.getEndFeature().getID()).getConnectors()[0]);
}
dvDist.add(cf);
cf.updateConnection();
}
}
}
public static void pasteFeatureTree(Feature fSrc
, FeatureModel fmSrc
, ConstraintModel cmSrc
// , DrawingView dvSrc
, Feature fDist
, FeatureModel fmDist
, ConstraintModel cmDist
, DrawingView dvDist
, FeatureModelEditor fmEditor
, FeatureEditor fEditor
, Hashtable<String , String> nameMap
, Hashtable<String , Figure> figureMap) {
Set<Feature> features = new HashSet<Feature>();
features.add(fSrc);
boolean changed = false;
do {
for (Iterator<Feature> itFeature=fmSrc.getAllFeature().values().iterator() ; itFeature.hasNext() ; ) {
Feature feature = itFeature.next();
if (!features.contains(feature) && features.contains(fmSrc.getParentFeature(feature.getID()))) {
features.add(feature);
changed = true;
}
}
changed = false;
} while (changed);
features.remove(fSrc);
// Hashtable<String , Figure> srcFigureMap = new Hashtable<String , Figure>();
// for (FigureEnumeration fe=dvSrc.getDrawing().getFigures()
// ; fe.hasMoreElements() ; ) {
// Figure figure = fe.nextFigure();
// srcFigureMap.put((String)figure.getAttribute("id") , figure);
// }
//
// Hashtable<String , String> nameMap = new Hashtable<String , String>();
nameMap.put(fSrc.getID() , fDist.getID());
// Hashtable<String , Figure> figureMap = new Hashtable<String , Figure>();
for (FigureEnumeration fe=dvDist.getDrawing().getFigures()
; fe.hasMoreElements() ; ) {
Figure figure = fe.nextFigure();
if (fDist.getID().equals(figure.getAttribute("id"))) {
figureMap.put(fDist.getID() , figure);
break;
}
}
// Figure rSrc = srcFigureMap.get(fSrc.getID());
Figure rDist = figureMap.get(fDist.getID());
for (Iterator<Feature> itFeature=features.iterator() ; itFeature.hasNext() ; ) {
Feature feature = itFeature.next();
Feature newFeature = fmEditor.addFeature(feature.getName());
fEditor.setBindingTime(newFeature , feature.getBindingTime());
fEditor.setCategory(newFeature , feature.getCategory());
fEditor.setVariability(newFeature , feature.getVariability());
nameMap.put(feature.getID() , newFeature.getID());
FeatureFigure figDist = new FeatureFigure();
figDist.setText(feature.getName());
figDist.setAttribute("id" , feature.getID());
figDist.setAttribute(FeatureProperties.VARIABILITY , feature.getVariability().getName());
dvDist.add(figDist);
// Figure fOld = srcFigureMap.get(feature.getID());
// figDist.moveBy(rDist.getDisplayBox().x - rSrc.getDisplayBox().x + fOld.getDisplayBox().x
// , rDist.getDisplayBox().y - rSrc.getDisplayBox().y + fOld.getDisplayBox().y);
figureMap.put(newFeature.getID() , figDist);
}
for (Iterator<FeatureRelation> itRelation=fmSrc.getAllFeatureRelation().values().iterator()
; itRelation.hasNext() ; ) {
FeatureRelation relation = itRelation.next();
if (!nameMap.containsKey(relation.getStartFeature().getID()) || !nameMap.containsKey(relation.getEndFeature().getID())) {
continue;
}
FeatureRelation newRelation = fmEditor.addRelation(relation.getName() , fmDist.getFeature(nameMap.get(relation.getStartFeature().getID())) , fmDist.getFeature(nameMap.get(relation.getEndFeature().getID())));
nameMap.put(relation.getID() , newRelation.getID());
ConnectionFigure cf = null;
if (FeatureRelation.ATTRIBUTE.equals(newRelation.getName())) {
AttributeConnection dvc = new AttributeConnection();
cf = dvc;
} else if (FeatureRelation.DECOMPOSE.equals(newRelation.getName())) {
DecomposeConnection ic = new DecomposeConnection();
cf = ic;
} else if (FeatureRelation.REQUIRE.equals(newRelation.getName())) {
ConstraintConnection cc = new ConstraintConnection(FeatureRelation.REQUIRE);
cc.setEndDecoration(new ArrowTip());
cf = cc;
} else if (FeatureRelation.EXCLUDE.equals(newRelation.getName())) {
ConstraintConnection cc = new ConstraintConnection(FeatureRelation.EXCLUDE);
cc.setMidDecoration(new CrossDecoration(5));
cf = cc;
}
if (cf!=null) {
cf.setAttribute("id" , newRelation.getID());
cf.startPoint(figureMap.get(newRelation.getStartFeature().getID()).center().x , figureMap.get(newRelation.getStartFeature().getID()).center().y);
cf.endPoint(figureMap.get(newRelation.getEndFeature().getID()).center().x , figureMap.get(newRelation.getEndFeature().getID()).center().y);
if (de.FeatureModellingTool.Pattern.ConstantDefinition.isStructRelation(relation)) {
cf.connectStart(figureMap.get(newRelation.getStartFeature().getID()).getConnectors()[2]);
cf.connectEnd(figureMap.get(newRelation.getEndFeature().getID()).getConnectors()[1]);
} else {
cf.connectStart(figureMap.get(newRelation.getStartFeature().getID()).getConnectors()[0]);
cf.connectEnd(figureMap.get(newRelation.getEndFeature().getID()).getConnectors()[0]);
}
dvDist.add(cf);
cf.updateConnection();
}
}
}
public static void pasteFeatureTree(Feature fSrc
, FeatureModel fmSrc
, ConstraintModel cmSrc
, Feature fDist
, FeatureModel fmDist
, ConstraintModel cmDist
, DrawingView dvDist
, FeatureModelEditor fmEditor
, FeatureEditor fEditor
, Hashtable<String , Integer> cloneCount
, Hashtable<String , String> nameMap
, Hashtable<String , Figure> figureMap
) {
// Hashtable<String , String> nameMap = new Hashtable<String , String>();
// Hashtable<String , Figure> figureMap = new Hashtable<String , Figure>();
pasteFeatureTree(fSrc , fmSrc , cmSrc, fDist , fmDist , cmDist , dvDist , fmEditor , fEditor , nameMap , figureMap);
Hashtable<String , String> waittingMap = new Hashtable<String , String>();
for (Iterator<Entry<String,String>> itNameMap = nameMap.entrySet().iterator() ; itNameMap.hasNext() ; ) {
Entry<String,String> entry = itNameMap.next();
waittingMap.put(entry.getValue() , entry.getKey());
}
HashSet<String> counts = new HashSet<String>(cloneCount.keySet());
ArrayList<String> alCount = new ArrayList<String>();
while (counts.size()>0) {
for (Iterator<Entry<String,Integer>> itCount=cloneCount.entrySet().iterator() ; itCount.hasNext() ; ) {
Entry<String,Integer> entry = itCount.next();
if (!alCount.contains(entry.getKey())) {
Feature feature = fmSrc.getFeature(entry.getKey());
feature = fmSrc.getParentFeature(feature.getID());
while (feature!=null) {
counts.remove(feature.getID());
feature = fmSrc.getParentFeature(feature.getID());
}
}
}
alCount.addAll(counts);
counts.clear();
counts.addAll(cloneCount.keySet());
counts.removeAll(alCount);
}
// for (Iterator<Entry<String,Integer>> itCount=cloneCount.entrySet().iterator() ; itCount.hasNext() ; ) {
for (int i=0 ; i<alCount.size() ; i++) {
String srcKey = alCount.get(i);
Integer srcCount = cloneCount.get(srcKey);
for (int j=1 ; j<srcCount ; j++) {
for (Iterator<Entry<String,String>> itWaitting = waittingMap.entrySet().iterator() ; itWaitting.hasNext() ; ) {
Entry<String , String> waitting = itWaitting.next();
if (waitting.getValue().equals(srcKey)) {
Hashtable<String , String> tmpNameMap = new Hashtable<String , String>();
cloneThroughPaste(fmDist.getFeature(waitting.getKey()) , fmDist , cmDist , fmDist.getParentFeature(waitting.getKey())
, fmDist , cmDist , dvDist , fmEditor , fEditor , tmpNameMap , figureMap);
// cloneThroughPaste(fmSrc.getFeature(entry.getKey()) , fmSrc , cmSrc , fmDist.getParentFeature(waitting.getKey())
// , fmDist , cmDist , dvDist , fmEditor , fEditor , tmpWaittingMap , figureMap);
nameMap.putAll(tmpNameMap);
}
}
}
}
}
public static void cloneThroughPaste(Feature fSrc
, FeatureModel fmSrc
, ConstraintModel cmSrc
, Feature fDist
, FeatureModel fmDist
, ConstraintModel cmDist
, DrawingView dvDist
, FeatureModelEditor fmEditor
, FeatureEditor fEditor
, Hashtable<String , String> nameMap
, Hashtable<String , Figure> figureMap) {
Feature fTarget = fmEditor.addFeature(fSrc.getName());
FeatureFigure figDist = new FeatureFigure();
figDist.setText(fTarget.getName());
figDist.setAttribute("id" , fTarget.getID());
figDist.setAttribute(FeatureProperties.VARIABILITY , fTarget.getVariability().getName());
dvDist.add(figDist);
nameMap.put(fSrc.getID() , fTarget.getID());
figureMap.put(fTarget.getID() , figDist);
Feature fParent = fmSrc.getParentFeature(fSrc.getID());
if (fParent!=null) {
for (Iterator<FeatureRelation> itRelation=fSrc.getAllRelatedRelation().iterator() ; itRelation.hasNext() ; ) {
FeatureRelation relation = itRelation.next();
if (relation.getStartFeature().getID().equals(fParent.getID())) {
FeatureRelation newRelation = fmEditor.addRelation(relation.getName() , fDist , fTarget);
ConnectionFigure cf = null;
if (FeatureRelation.ATTRIBUTE.equals(newRelation.getName())) {
AttributeConnection dvc = new AttributeConnection();
cf = dvc;
} else if (FeatureRelation.DECOMPOSE.equals(newRelation.getName())) {
DecomposeConnection ic = new DecomposeConnection();
cf = ic;
} else if (FeatureRelation.REQUIRE.equals(newRelation.getName())) {
ConstraintConnection cc = new ConstraintConnection(FeatureRelation.REQUIRE);
cc.setEndDecoration(new ArrowTip());
cf = cc;
} else if (FeatureRelation.EXCLUDE.equals(newRelation.getName())) {
ConstraintConnection cc = new ConstraintConnection(FeatureRelation.EXCLUDE);
cc.setMidDecoration(new CrossDecoration(5));
cf = cc;
}
if (cf!=null) {
cf.setAttribute("id" , newRelation.getID());
cf.startPoint(figureMap.get(newRelation.getStartFeature().getID()).center().x , figureMap.get(newRelation.getStartFeature().getID()).center().y);
cf.endPoint(figureMap.get(newRelation.getEndFeature().getID()).center().x , figureMap.get(newRelation.getEndFeature().getID()).center().y);
if (de.FeatureModellingTool.Pattern.ConstantDefinition.isStructRelation(relation)) {
cf.connectStart(figureMap.get(newRelation.getStartFeature().getID()).getConnectors()[2]);
cf.connectEnd(figureMap.get(newRelation.getEndFeature().getID()).getConnectors()[1]);
} else {
cf.connectStart(figureMap.get(newRelation.getStartFeature().getID()).getConnectors()[0]);
cf.connectEnd(figureMap.get(newRelation.getEndFeature().getID()).getConnectors()[0]);
}
dvDist.add(cf);
cf.updateConnection();
}
break;
}
}
}
pasteFeatureTree(fSrc , fmSrc , cmSrc, fTarget , fmDist , cmDist , dvDist , fmEditor , fEditor , nameMap , figureMap);
}
}