1 19 20 26 package org.netbeans.modules.xml.wsdl.ui.actions; 27 28 import java.beans.PropertyVetoException ; 29 import javax.swing.SwingUtilities ; 30 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 31 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 32 import org.netbeans.modules.xml.wsdl.ui.cookies.WSDLDefinitionNodeCookie; 33 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.Utils; 34 import org.netbeans.modules.xml.xam.ui.cookies.ViewComponentCookie; 35 import org.openide.explorer.ExplorerManager; 36 import org.openide.filesystems.FileObject; 37 import org.openide.loaders.DataObject; 38 import org.openide.loaders.DataObjectNotFoundException; 39 import org.openide.nodes.Node; 40 41 47 public class ActionHelper { 48 49 54 public static void selectNode(WSDLComponent comp) { 55 DataObject dobj = getDataObject(comp); 56 if (dobj != null) { 57 ViewComponentCookie cookie = (ViewComponentCookie) dobj.getCookie( 58 ViewComponentCookie.class); 59 if (cookie != null) { 60 cookie.view(ViewComponentCookie.View.CURRENT, comp, 62 (Object []) null); 63 } 64 } 65 } 66 67 public static DataObject getDataObject(WSDLComponent comp) { 68 try { 69 WSDLModel model = comp.getModel(); 70 if (model != null) { 71 FileObject fobj = (FileObject) model.getModelSource(). 72 getLookup().lookup(FileObject.class); 73 if (fobj != null) { 74 return DataObject.find(fobj); 75 } 76 } 77 } catch (DataObjectNotFoundException donfe) { 78 } 80 return null; 81 } 82 83 public static DataObject getDataObject(WSDLModel model) { 84 try { 85 if (model != null) { 86 FileObject fobj = (FileObject) model.getModelSource(). 87 getLookup().lookup(FileObject.class); 88 if (fobj != null) { 89 return DataObject.find(fobj); 90 } 91 } 92 } catch (DataObjectNotFoundException donfe) { 93 } 95 return null; 96 } 97 112 113 128 129 public static void selectNode(final Node node) { 130 if(node == null) { 131 return; 132 } 133 134 WSDLDefinitionNodeCookie cookie = Utils.getWSDLDefinitionNodeCookie(node); 135 if(cookie != null) { 136 final ExplorerManager manager = cookie.getDefinitionsNode().getExplorerManager(); 137 138 Runnable run = new Runnable () { 139 public void run() { 140 if(manager != null) { 141 try { 142 manager.setExploredContextAndSelection(node, new Node[] {node}); 143 } catch(PropertyVetoException ex) { 144 } 146 147 } 148 } 149 }; 150 SwingUtilities.invokeLater(run); 151 } 152 } 153 154 public static void selectNode(final Node node, final Node parentNode) { 155 if(node == null) { 156 return; 157 } 158 159 WSDLDefinitionNodeCookie cookie = Utils.getWSDLDefinitionNodeCookie(node); 160 if(cookie != null) { 161 final ExplorerManager manager = cookie.getDefinitionsNode().getExplorerManager(); 162 163 Runnable run = new Runnable () { 164 public void run() { 165 if(manager != null) { 166 try { 167 manager.setExploredContextAndSelection(node, new Node[] {node}); 168 } catch(PropertyVetoException ex) { 169 } 171 172 } 173 } 174 }; 175 SwingUtilities.invokeLater(run); 176 } 177 } 178 179 public static void selectExploredContext(final Node node) { 180 if(node == null) { 181 return; 182 } 183 WSDLDefinitionNodeCookie cookie = Utils.getWSDLDefinitionNodeCookie(node); 184 if(cookie != null) { 185 final ExplorerManager manager = cookie.getDefinitionsNode().getExplorerManager(); 186 187 Runnable run = new Runnable () { 188 public void run() { 189 if(manager != null) { 190 manager.setExploredContext(node); 191 } 192 } 193 }; 194 195 SwingUtilities.invokeLater(run); 196 197 } 198 } 199 } 200 | Popular Tags |