- builder.setTitle("Scegli una regola:")
- .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- if (selectedRule == null) return;
- for (Node n : selectedRule.Children) {
- for (Hypothesis hp : n.NodeHP)
- hp.fromNode = DrawActivity.selectedNode; //le ipotesi dei nuovi figli provengono dal nodo in cui stanno per essere inserite
- n.addHPList(DrawActivity.selectedNode.NodeHP);
- n.handler = null;
- DrawActivity.selectedNode.addChild(n);
- }
- DrawActivity.selectedNode.hasFocus = false;
- DrawActivity.selectedNode.ruleName = selectedRule.Children.get(0).ruleName;
- DrawActivity.selectedNode.Children.get(0).hasFocus = true;
- DrawActivity.nmoves++;
- DrawActivity.rootNode.Clean();
- DrawActivity.startDraw();
- selectedRule=null;
- }
- });
+ builder.setTitle("Scegli una regola:");
+ builder.setPositiveButton("Incolla sottoalbero",new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (DrawActivity.copiedNode == null) //non ci sono nodi da copiare
+ {
+ Toast.makeText(DrawActivity.rootNode.view.getContext(),"Impossibile incollare: nessun nodo copiato",Toast.LENGTH_LONG).show();
+ }
+ else if (!checkHP(DrawActivity.copiedNode, DrawActivity.selectedNode)) //ipotesi incompatibili: impossibile incollare in questo punto
+ Toast.makeText(DrawActivity.rootNode.view.getContext(),"Impossibile incollare: sottoalberi incompatibili",Toast.LENGTH_LONG).show();
+ else {
+ Node tmp = duplicateNode(DrawActivity.copiedNode); //duplica il nodo copiato
+ DrawActivity.selectedNode.ruleName=tmp.ruleName; //eredita il nome della regola
+ DrawActivity.selectedNode.Children = new ArrayList<Node>();
+ for (Node c:tmp.Children)
+ DrawActivity.selectedNode.addChild(c); //incolla il sottoalbero del nodo copiato nella posizione richiesta
+ DrawActivity.rootNode.Clean();
+ DrawActivity.startDraw();
+ }
+ }
+ });