public static void install (final Map<String,Item> allFoundComponents, final List<Item> componentsToInstall) { ComponentSerializationSupport.runUnderDescriptorRegistryWriteAccess (MidpDocumentSupport.PROJECT_TYPE_MIDP, new Runnable () { public void run () { installCore (allFoundComponents, componentsToInstall); } }); ComponentSerializationSupport.refreshDescriptorRegistry (MidpDocumentSupport.PROJECT_TYPE_MIDP); }
public static Map<String,Item> search (final Project project) { final Object[] ret = new Object[1]; ComponentSerializationSupport.runUnderDescriptorRegistryReadAccess (MidpDocumentSupport.PROJECT_TYPE_MIDP, new Runnable () { public void run () { ret[0] = searchCore (project); } }); return (Map<String, Item>) ret[0]; }
private static void serializeComponentProducer (String projectType, TypeID typeID, PaletteDescriptor paletteDescriptor) { Document document = XMLUtil.createDocument (XMLComponentProducer.COMPONENT_PRODUCER_NODE, null, null, null); Node rootNode = document.getFirstChild (); setAttribute (document, rootNode, XMLComponentProducer.VERSION_ATTR, XMLComponentProducer.VERSION_VALUE_1); setAttribute (document, rootNode, XMLComponentProducer.PRODUCERID_ATTR, typeID.toString ()); setAttribute (document, rootNode, XMLComponentProducer.MAIN_COMPONENT_TYPEID_ATTR, typeID.toString ()); setAttribute (document, rootNode, XMLComponentProducer.DISPLAY_NAME_ATTR, paletteDescriptor.getDisplayName ()); if (paletteDescriptor.getToolTip () != null) setAttribute (document, rootNode, XMLComponentProducer.TOOLTIP_ATTR, paletteDescriptor.getToolTip ()); if (paletteDescriptor.getCategoryID () != null) setAttribute (document, rootNode, XMLComponentProducer.PREFERRED_CATEGORYID_ATTR, paletteDescriptor.getCategoryID ()); if (paletteDescriptor.getSmallIcon () != null) setAttribute (document, rootNode, XMLComponentDescriptor.SMALL_ICON_ATTR, paletteDescriptor.getSmallIcon ()); if (paletteDescriptor.getLargeIcon () != null) setAttribute (document, rootNode, XMLComponentDescriptor.LARGE_ICON_ATTR, paletteDescriptor.getLargeIcon ()); GlobalDescriptorRegistry registry = GlobalDescriptorRegistry.getGlobalDescriptorRegistry (projectType); DataFolder producersFolder = registry.getProducersFolder (); if (! writeDocument (producersFolder.getPrimaryFile (), typeID.toString (), "xml", document)) // NOI18N Debug.warning ("Error while serializing a component producer", typeID.toString ()); // NOI18N }
/** * Creates a new component descriptor and stores it into xml file and add it into global descriptor registry. * After you add all custom component descriptors, then call <code>ComponentSerializationSupport.refresh</code> to refresh the registry. * @param projectType the project type * @param typeDescriptor the type descriptor * @param paletteDescriptor the palette descriptor * @param properties the list of declared properties * @param presenters the list of presenter serializers */ public static void serialize (String projectType, TypeDescriptor typeDescriptor, PaletteDescriptor paletteDescriptor, List<PropertyDescriptor> properties, List<PresenterSerializer> presenters) { assert projectType != null && typeDescriptor != null && properties != null && presenters != null; serializeComponentDescriptor (projectType, typeDescriptor, null, properties, presenters); if (typeDescriptor.isCanInstantiate ()) serializeComponentProducer (projectType, typeDescriptor.getThisType (), paletteDescriptor); }
synchronized void refreshDescriptorRegistry() { if (activeDocument == null || activeDocument.get() == null) { return; } String projectType = activeDocument.get().getDocumentInterface().getProjectType(); ComponentSerializationSupport.refreshDescriptorRegistry(projectType); }
public void run () throws IOException { FileObject file = folder.getFileObject (filename, ext); if (file == null) file = folder.createData (filename, ext); writeDocument (file, doc); } });
private static void installCore (Map<String,Item> allFoundComponents, List<Item> componentsToInstall) { HashMap<String,Item> toInstall = new HashMap<String,Item> (); for (Item item : componentsToInstall) recursiveAdd (toInstall, allFoundComponents, item); for (Item item : toInstall.values ()) ComponentSerializationSupport.serialize (MidpDocumentSupport.PROJECT_TYPE_MIDP, item.getTypeDescriptor (), item.getPaletteDescriptor (), item.getProperties (), item.getPresenters ()); }
private static void serializeComponentDescriptor (String projectType, TypeDescriptor typeDescriptor, PaletteDescriptor paletteDescriptor, List<PropertyDescriptor> properties, List<PresenterSerializer> presenters) { Document document = XMLUtil.createDocument (XMLComponentDescriptor.COMPONENT_DESCRIPTOR_NODE, null, null, null); Node rootNode = document.getFirstChild (); setAttribute (document, rootNode, XMLComponentDescriptor.VERSION_ATTR, XMLComponentDescriptor.VERSION_VALUE_1); setAttribute (document, typeNode, XMLComponentDescriptor.SUPER_TYPEID_ATTR, typeDescriptor.getSuperType ().toString ()); setAttribute (document, typeNode, XMLComponentDescriptor.THIS_TYPEID_ATTR, typeDescriptor.getThisType ().toString ()); setAttribute (document, typeNode, XMLComponentDescriptor.CAN_DERIVE_ATTR, Boolean.toString (typeDescriptor.isCanDerive ())); setAttribute (document, typeNode, XMLComponentDescriptor.CAN_INSTANTIATE_ATTR, Boolean.toString (typeDescriptor.isCanInstantiate ())); rootNode.appendChild (typeNode); setAttribute (document, paletteNode, XMLComponentDescriptor.DISPLAY_NAME_ATTR, paletteDescriptor.getDisplayName ()); if (paletteDescriptor.getToolTip () != null) setAttribute (document, paletteNode, XMLComponentDescriptor.TOOLTIP_ATTR, paletteDescriptor.getToolTip ()); if (paletteDescriptor.getCategoryID () != null) setAttribute (document, paletteNode, XMLComponentDescriptor.PREFERRED_CATEGORYID_ATTR, paletteDescriptor.getCategoryID ()); if (paletteDescriptor.getSmallIcon () != null) setAttribute (document, paletteNode, XMLComponentDescriptor.SMALL_ICON_ATTR, paletteDescriptor.getSmallIcon ()); if (paletteDescriptor.getLargeIcon () != null) setAttribute (document, paletteNode, XMLComponentDescriptor.LARGE_ICON_ATTR, paletteDescriptor.getLargeIcon ()); rootNode.appendChild (paletteNode); assert propertyDescriptor != null; Element propertyNode = document.createElement (XMLComponentDescriptor.PROPERTY_DESCRIPTOR_NODE); setAttribute (document, propertyNode, XMLComponentDescriptor.NAME_ATTR, propertyDescriptor.getName ()); setAttribute (document, propertyNode, XMLComponentDescriptor.TYPEID_ATTR, propertyDescriptor.getType ().toString ()); String userCode = propertyDescriptor.getDefaultValue ().getUserCode (); if (userCode != null) setAttribute (document, propertyNode, XMLComponentDescriptor.DEFAULT_VALUE_ATTR, userCode); setAttribute (document, propertyNode, XMLComponentDescriptor.ALLOW_NULL, Boolean.toString (propertyDescriptor.isAllowNull ()));