1 19 20 package org.netbeans.modules.xml.xam.ui; 21 22 import org.netbeans.modules.xml.xam.Component; 23 import org.netbeans.modules.xml.xam.Model; 24 import org.netbeans.modules.xml.xam.ModelSource; 25 import org.netbeans.modules.xml.xam.ui.cookies.GetComponentCookie; 26 import org.netbeans.modules.xml.xam.ui.cookies.ViewComponentCookie; 27 import org.openide.filesystems.FileObject; 28 import org.openide.loaders.DataObject; 29 import org.openide.loaders.DataObjectNotFoundException; 30 import org.openide.nodes.Node; 31 32 38 public class XAMUtils { 39 40 46 public static Component getComponent(Node node) { 47 GetComponentCookie cake = (GetComponentCookie) node.getCookie( 48 GetComponentCookie.class); 49 Component component = null; 50 try { 51 if (cake != null) { 52 component = cake.getComponent(); 53 } 54 } catch (IllegalStateException ise) { 55 } 58 if (component == null) { 59 component = (Component) node.getLookup().lookup(Component.class); 60 } 61 return component; 62 } 63 64 71 public static ViewComponentCookie getViewCookie(Component comp, 72 ViewComponentCookie.View view) { 73 if (comp == null) { 74 return null; 75 } 76 try { 77 Model model = comp.getModel(); 78 if (model != null) { 79 FileObject fobj = (FileObject) model.getModelSource(). 80 getLookup().lookup(FileObject.class); 81 if (fobj != null) { 82 DataObject dobj = DataObject.find(fobj); 83 if (dobj != null) { 84 ViewComponentCookie cake = (ViewComponentCookie) dobj. 85 getCookie(ViewComponentCookie.class); 86 if (cake != null && cake.canView(view, comp)) { 87 return cake; 88 } 89 } 90 } 91 } 92 } catch (DataObjectNotFoundException donfe) { 93 } 95 return null; 96 } 97 98 105 public static boolean isWritable(Model model) { 106 if (model != null) { 107 ModelSource ms = model.getModelSource(); 108 if (ms.isEditable()) { 109 FileObject fo = (FileObject) ms.getLookup().lookup(FileObject.class); 110 if (fo != null) { 111 return fo.canWrite(); 112 } 113 } 114 } 115 return false; 116 } 117 } 118 | Popular Tags |