1 19 20 package org.netbeans.modules.javadoc.comments; 21 22 import javax.swing.SwingUtilities ; 23 import org.netbeans.modules.javacore.internalapi.JavaMetamodel; 24 import org.openide.ErrorManager; 25 import org.openide.nodes.Node; 26 import org.openide.util.NbBundle; 27 import org.openide.util.HelpCtx; 28 import org.openide.util.RequestProcessor; 29 import org.openide.util.actions.NodeAction; 30 import org.netbeans.jmi.javamodel.*; 31 32 import javax.jmi.reflect.JmiException; 33 import org.netbeans.modules.javacore.api.JavaModel; 34 35 40 public final class CorrectJavaDocAction extends NodeAction { 41 42 static final long serialVersionUID =4989490116568783623L; 43 44 public CorrectJavaDocAction () { 45 putValue("noIconInMenu", Boolean.TRUE); } 47 48 52 public String getName () { 53 return NbBundle.getBundle( CorrectJavaDocAction.class ).getString("CTL_CORRECTJAVADOC_MenuItem"); } 55 56 59 public HelpCtx getHelpCtx () { 60 return new HelpCtx (CorrectJavaDocAction.class); 61 } 62 63 66 protected boolean enable( Node[] activatedNodes ) { 67 if (activatedNodes.length != 1) { 68 return false; 69 } 70 ClassMember element = (ClassMember) activatedNodes[0].getLookup().lookup(ClassMember.class); 71 if (element == null) 72 return false; 73 74 try { 75 JavaModel.getJavaRepository().beginTrans(false); 76 try { 77 if (!element.isValid()) { 78 return false; 79 } 80 AutoCommenter.Element jdElement = AutoCommenter.createAutoCommenterElement(element); 81 if( jdElement == null ) return false; 83 84 return jdElement.isCorrectable(); 85 } finally { 86 JavaModel.getJavaRepository().endTrans(); 87 } 88 } catch (JmiException e) { 89 ErrorManager.getDefault().notify(ErrorManager.WARNING, e); 90 } 91 return false; 92 } 93 94 99 public void performAction (final Node[] nodes ) { 100 Runnable run = new Runnable () { 101 public void run() { 102 if (SwingUtilities.isEventDispatchThread()) { 103 RequestProcessor.getDefault().post(this); 104 return ; 105 } 106 ClassMember element = (ClassMember) nodes[0].getLookup().lookup(ClassMember.class); 107 if(element == null) 108 return; 109 110 try { 111 JavaModel.getJavaRepository().beginTrans(true); 112 boolean fail = true; 113 try { 114 if (!element.isValid()) { 115 fail = false; 116 return; 117 } 118 AutoCommenter.Element jdElement = AutoCommenter.createAutoCommenterElement(element); 119 if (jdElement.isCorrectable()) { 120 jdElement.autoCorrect(); 121 } 122 fail = false; 123 } finally { 124 JavaModel.getJavaRepository().endTrans(fail); 125 } 126 } catch (JmiException e) { 127 ErrorManager.getDefault().notify(e); 128 } catch (org.openide.src.SourceException e) { 129 ErrorManager.getDefault().notify(e); 130 } 131 } 132 }; 133 JavaMetamodel.getManager().invokeAfterScanFinished(run, getName()); 134 } 135 136 140 protected boolean asynchronous() { 141 return false; 142 } 143 } 144 | Popular Tags |