1 19 20 package org.netbeans.modules.mdrxml.looks.actions; 21 22 import java.util.Collection ; 23 import java.util.Iterator ; 24 import javax.jmi.reflect.*; 25 import org.openide.nodes.*; 26 import org.openide.util.actions.NodeAction; 27 import org.openide.util.NbBundle; 28 import org.openide.util.HelpCtx; 29 import org.netbeans.api.looks.*; 30 import org.netbeans.api.mdr.MDRObject; 31 import org.netbeans.api.mdr.MDRepository; 32 36 public class DeleteAction extends NodeAction { 37 38 39 public DeleteAction() { 40 } 41 42 public void performAction(Node[] nodes) { 43 for (int i=0; i< nodes.length; i++) { 44 LookNode ln = (LookNode) nodes[i]; 45 xmlmodel.Node node = (xmlmodel.Node) ln.getRepresentedObject(); 46 MDRepository repo = ((MDRObject)node).repository(); 47 repo.beginTrans(true); 48 try { 49 if (node instanceof xmlmodel.ElementNode) 50 this.deleteHierarchy ((xmlmodel.ElementNode)node); 51 ((RefObject)node).refDelete(); 52 }catch (Exception e) { 53 e.printStackTrace(); 54 } 55 finally { 56 repo.endTrans(); 57 } 58 } 59 } 60 61 public boolean enable(Node[] nodes) { 62 if (nodes == null) 63 return false; 64 for (int i=0; i< nodes.length; i++) { 65 if (!(nodes[i] instanceof LookNode)) 66 return false; 67 if (!(((LookNode)nodes[i]).getRepresentedObject() instanceof xmlmodel.Node)) 68 return false; 69 } 70 return true; 71 } 72 73 public String getName() { 74 return NbBundle.getMessage(DeleteAction.class, "TXT_Delete"); 75 } 76 77 public HelpCtx getHelpCtx() { 78 return HelpCtx.DEFAULT_HELP; 79 } 80 81 82 protected void deleteHierarchy(xmlmodel.ElementNode node) { 83 Collection subNodes = node.getNodes(); 84 for (Iterator it = subNodes.iterator(); it.hasNext();) { 85 xmlmodel.Node subNode = (xmlmodel.Node)it.next(); 86 it.remove (); 87 if (subNode instanceof xmlmodel.ElementNode) 88 deleteHierarchy ((xmlmodel.ElementNode)subNode); 89 if (subNode != null) 90 try { 91 ((RefObject)subNode).refDelete(); 92 } catch (javax.jmi.reflect.InvalidObjectException invalidObjectExc) { 93 } 95 } 96 } 97 } 98 | Popular Tags |