/** * Returns a debug string. * @return the string */ @Override public final String toString () { TypeDescriptor typeDescriptor = getTypeDescriptor (); if (typeDescriptor == null) return super.toString (); return typeDescriptor.getThisType ().toString (); }
private void reloadCore () { // TODO - reload from project descriptor registry HashMap<TypeID, ComponentDescriptor> tempDescriptors = new HashMap<TypeID, ComponentDescriptor> (); ArrayList<ComponentProducer> tempProducers = new ArrayList<ComponentProducer> (); Collection<ComponentDescriptor> _descriptors = globalDescriptorRegistry.getComponentDescriptors (); for (ComponentDescriptor descriptor : _descriptors) tempDescriptors.put (descriptor.getTypeDescriptor ().getThisType (), descriptor); tempProducers.addAll (globalDescriptorRegistry.getComponentProducers ()); this.descriptors = tempDescriptors; this.producers = tempProducers; for (DescriptorRegistryListener _listener : listeners) { try { _listener.descriptorRegistryUpdated (); } catch (Exception e) { Exceptions.printStackTrace (e); } } }
static ComponentProducer createDefault (ComponentDescriptor descriptor) { PaletteDescriptor paletteDescriptor = descriptor.getPaletteDescriptor (); TypeID typeid = descriptor.getTypeDescriptor ().getThisType (); if (paletteDescriptor == null) return null; return new ComponentProducer (typeid.toString (), typeid, paletteDescriptor) { public Boolean checkValidity(DesignDocument document, boolean useCachedValue) { return true; } }; }
DesignComponent(DesignDocument document, long componentID, ComponentDescriptor componentDescriptor) { assert Debug.isFriend(DesignDocument.class, "createRawComponent"); // NOI18N this.document = document; this.componentID = componentID; this.type = componentDescriptor.getTypeDescriptor().getThisType(); assert type.getKind() == TypeID.Kind.COMPONENT && type.getDimension() == 0; children = new ArrayList<DesignComponent> (); properties = new HashMap<String, PropertyValue> (); defaultProperties = new HashMap<String, PropertyValue> (); referencePropertyValue = PropertyValue.createComponentReferenceCore(this); presenters = Lookup.EMPTY; setComponentDescriptor(componentDescriptor, false); }
/** * 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); }
public void run () { for (ComponentDescriptor descriptor : registry.getComponentDescriptors ()) { TypeID thisType = descriptor.getTypeDescriptor ().getThisType (); String string = thisType.getString (); if (! checkForJavaIdentifierCompliant (string)) continue; if (! registry.isInHierarchy (ClassCD.TYPEID, thisType) || ClassCD.TYPEID.equals (thisType)) continue; registryMap.put (string, descriptor); } } });
public List<Presenter> createPresenters (ComponentDescriptor descriptor) { DefaultPropertiesPresenter presenter = new DefaultPropertiesPresenter () .addPropertiesCategory (MidpPropertiesCategories.CATEGORY_PROPERTIES); if (EDITOR_BOOLEAN.equals (editor)) presenter.addProperty (displayName, PropertyEditorBooleanUC.createInstance (), propertyName); else if (EDITOR_INT.equals (editor)) presenter.addProperty (displayName, PropertyEditorNumber.createIntegerInstance(false, NbBundle.getMessage(MidpPropertyPresenterDeserializer.class, "LBL_INTEGER_STR")), propertyName); // NOI18N else if (EDITOR_FLOAT.equals (editor)) presenter.addProperty (displayName, PropertyEditorNumber.createFloatInstance(NbBundle.getMessage(MidpPropertyPresenterDeserializer.class, "LBL_FLOAT_STR")), propertyName); // NOI18N else if (EDITOR_STRING.equals (editor)) presenter.addProperty (displayName, PropertyEditorString.createInstance(NbBundle.getMessage(MidpPropertyPresenterDeserializer.class, "LBL_STRING")), propertyName); // NOI18N else if (EDITOR_JAVA_CODE.equals (editor)) presenter.addProperty (displayName, PropertyEditorJavaString.createInstance (descriptor.getTypeDescriptor ().getThisType ()), propertyName); else if (EDITOR_CHAR.equals (editor)) presenter.addProperty (displayName, PropertyEditorNumber.createCharInstance (false, NbBundle.getMessage(MidpPropertyPresenterDeserializer.class, "LBL_CHAR_STR")), propertyName); // NOI18N else if (EDITOR_BYTE.equals (editor)) presenter.addProperty (displayName, PropertyEditorNumber.createByteInstance(false, NbBundle.getMessage(MidpPropertyPresenterDeserializer.class, "LBL_BYTE_STR")), propertyName); // NOI18N else if (EDITOR_SHORT.equals (editor)) presenter.addProperty (displayName, PropertyEditorNumber.createShortInstance(false, NbBundle.getMessage(MidpPropertyPresenterDeserializer.class, "LBL_SHORT_STR")), propertyName); // NOI18N else if (EDITOR_LONG.equals (editor)) presenter.addProperty (displayName, PropertyEditorNumber.createLongInstance(false, NbBundle.getMessage(MidpPropertyPresenterDeserializer.class, "LBL_LONG_STR")), propertyName); // NOI18N else if (EDITOR_DOUBLE.equals (editor)) presenter.addProperty (displayName, PropertyEditorNumber.createDoubleInstance(NbBundle.getMessage(MidpPropertyPresenterDeserializer.class, "LBL_DOUBLE_STR")), propertyName); // NOI18N else return null; return Arrays.<Presenter>asList (presenter); }
public Image getIcon (DesignComponent component, InfoPresenter.IconType iconType) { if (InfoPresenter.IconType.COLOR_16x16.equals (iconType)) { ComponentDescriptor descriptor = component.getComponentDescriptor (); while (descriptor != null) { Image image = MidpTypes.getRegisteredIcon (descriptor.getTypeDescriptor ().getThisType ()); if (image != null) return image; descriptor = descriptor.getSuperDescriptor (); } } return null; }
final TypeID thisType = typeDescriptor.getThisType (); if (tempDescriptors.containsKey (thisType)) { Debug.warning ("Duplicate descriptor", thisType); // NOI18N continue; tempDescriptors.put (typeDescriptor.getThisType (), descriptor);
public Image getIcon(DesignComponent component, InfoPresenter.IconType iconType) { if (InfoPresenter.IconType.COLOR_16x16.equals(iconType)) { ComponentDescriptor descriptor = component.getComponentDescriptor(); while (descriptor != null) { Image image = MidpTypes.getRegisteredIcon(descriptor.getTypeDescriptor().getThisType()); if (image != null) return image; descriptor = descriptor.getSuperDescriptor(); } } return null; } }
public List<Presenter> createPresenters (ComponentDescriptor descriptor) { MidpSetter setter; if (name != null) setter = MidpSetter.createSetter (name, Versionable.FOREVER); else setter = MidpSetter.createConstructor (descriptor.getTypeDescriptor ().getThisType (), Versionable.FOREVER); setter.addParameters (parameters); return Arrays.<Presenter>asList ( new CodeSetterPresenter ().addParameters (MidpParameter.create (parameters)).addSetters (setter) ); }
public AddActionItem[] getAddActionItems() { List<Action> actions = new ArrayList<Action>(); DesignDocument document = getComponent().getDocument(); for (TypeID type : types) { for (ComponentDescriptor descriptor : document.getDescriptorRegistry().getComponentDescriptors()){ if (getComponent().getDocument().getDescriptorRegistry().isInHierarchy(type, descriptor.getTypeDescriptor().getThisType())) { for (ComponentProducer producer : document.getDescriptorRegistry().getComponentProducers()) { if (producer.getMainComponentTypeID ().equals(descriptor.getTypeDescriptor().getThisType()) && AcceptSupport.isAcceptable(getComponent(), producer, null)) { Boolean isValid = producer.checkValidity(document, true); if (isValid != null && isValid) actions.add(AddActionItem.getInstance(getComponent(), producer)); } } } } } Collections.sort(actions, ACTIONS_COMPARATOR); return actions.toArray( new AddActionItem[actions.size()]); }
/** * Checks whether a component descriptor is compatible (descriptor analogy of instanceof operator) with a type id. * Means: Specified component descriptor or its super descriptor has the same type id as the specified one. * @param typeID the type id * @param componentDescriptor the component descriptor * @return true if compatible */ private boolean isComponentDescriptorCompatibleWithTypeID (TypeID typeID, ComponentDescriptor componentDescriptor) { assert isAccess (); if (typeID == null) return false; for (;;) { if (componentDescriptor == null) return false; TypeDescriptor typeDescriptor = componentDescriptor.getTypeDescriptor (); TypeID checked = typeDescriptor.getThisType (); if (checked == null) return false; if (checked.equals (typeID)) return true; componentDescriptor = getComponentDescriptor (typeDescriptor.getSuperType ()); } }
private ComponentDescriptor dao2descriptor (DataObject dataObject, Map<TypeID, FileObject> fileObjects) { InstanceCookie.Of instanceCookie = dataObject.getCookie (InstanceCookie.Of.class); if (instanceCookie != null) { try { Object instance = instanceCookie.instanceCreate (); if (instance instanceof ComponentDescriptor) return (ComponentDescriptor) instance; } catch (IOException e) { Debug.warning (e); } catch (ClassNotFoundException e) { Debug.warning (e); } Debug.warning ("Instance is not ComponentDescriptor class"); // NOI18N return null; } if (dataObject instanceof XMLDataObject) { ComponentDescriptor descriptor = deserializeComponentDescriptorFromXML ((XMLDataObject) dataObject); fileObjects.put(descriptor.getTypeDescriptor().getThisType(), dataObject.getPrimaryFile()); return descriptor; } return null; }
if (typeDescriptor.getSuperType () != null) 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 ())); if (! writeDocument (registryFolder.getPrimaryFile (), typeDescriptor.getThisType ().toString (), "xml", document)) // NOI18N Debug.warning ("Error while serializing a component descriptor", typeDescriptor.getThisType ().toString ()); // NOI18N
private static void resolveDescriptor (String projectType, HashMap<TypeID, ComponentDescriptor> allDescriptors, HashSet<TypeID> resolvingDescriptors, ComponentDescriptor descriptor) { assert Debug.isFriend (GlobalDescriptorRegistry.class) || Debug.isFriend (DescriptorRegistry.class); TypeID thisType = descriptor.getTypeDescriptor ().getThisType (); if (thisType == null) { Debug.warning ("Null TypeID", descriptor); // NOI18N