Package pt.webdetails.cdf.dd.model.meta

Examples of pt.webdetails.cdf.dd.model.meta.ComponentType


   
    // camelName is the name by which the property will be registered
    // on the client, by means of PropertiesManager.register(...)
    String fullName = camelName;
   
    ComponentType owner = prop.getOwner();
    if(owner != null)
    {
      String modelId = CdeRunJsHelper.getComponentTypeModelId(owner);
      fullName = modelId + "_" + fullName;
    }
View Full Code Here


public class XmlComponentTypeWriter implements IThingWriter
{
  public void write(java.lang.Object output, IThingWriteContext context, Thing t) throws ThingWriteException
  {
    //TODO: use methods instead of comments to segment this
    ComponentType comp = (ComponentType)t;
    Branch parent = (Branch)output; // Element or Document
   
    Element compElem = parent.addElement("DesignerComponent");

    writeHeader(comp, compElem);

    Attribute cdeModelIgnoreAttr = comp.tryGetAttribute("cdeModelIgnore");
    Attribute cdeModelPrefixAttr = comp.tryGetAttribute("cdeModelPrefix");
    int ignoreCount = 0;
    if(cdeModelIgnoreAttr != null) { ignoreCount++; }
    if(cdeModelPrefixAttr != null) { ignoreCount++; }
   
    if(comp.getAttributeCount() > ignoreCount)
    {
      writeMetadata(comp, compElem);
    }
   
    // ----------------
    // CONTENTS
    Element contentsElem = compElem.addElement("Contents");

    Element modelElem = contentsElem.addElement("Model");
    if(cdeModelIgnoreAttr != null)
    {
      modelElem.addAttribute("ignore", cdeModelIgnoreAttr.getValue());
    }
   
    if(cdeModelPrefixAttr != null)
    {
      modelElem.addAttribute("prefix", cdeModelPrefixAttr.getValue());
    }
   
    // Property Usages
    for(String defName : comp.getDefinitionNames())
    {
      Element definitionElem;
      Iterable<PropertyTypeUsage> propUsages = comp.getPropertiesByDefinition(defName);
      if(StringUtils.isEmpty(defName))
      {
        definitionElem = modelElem;
      }
      else
      {
        definitionElem = modelElem.addElement("Definition");
        definitionElem.addAttribute("name", defName);
      }
     
      for (PropertyTypeUsage propUsage : propUsages)
      {
        String propName = propUsage.getProperty().getName();

        // TODO: exclusion of "system" properties should not be done
        // in such an explicit way.
        if(!"name".equalsIgnoreCase(propName) && !"priority".equalsIgnoreCase(propName))
        {
          Element propertyElem = definitionElem.addElement("Property");

          propertyElem.setText(propName);

          String propAlias = propUsage.getAlias();
          if(propAlias != null && !propAlias.equals(propName))
          {
            propertyElem.addAttribute("name", propAlias);
          }
        }
      }
    }
   
    // ------------------------
    // CONTENTS / IMPLEMENTATION
    Element implElem = null;

    String implPath = comp.getImplementationPath();
    if(StringUtils.isNotEmpty(implPath))
    {
      implElem = contentsElem.addElement("Implementation");
     
      implElem
        .addElement("Code")
        .addAttribute("src", comp.getImplementationPath());
    }
   
    if(comp.getResourceCount() > 0)
    {
      if(implElem == null)
      {
        implElem = contentsElem.addElement("Implementation");
      }
     
      Element depsElem   = implElem.addElement("Dependencies");
      Element stylesElem = implElem.addElement("Styles");
      Element rawElem    = implElem.addElement("Raw");

      for (Resource res : comp.getResources())
      {
        Element resElem;
        if(res.getType() == Resource.Type.SCRIPT)
        {
          // Script
          resElem = depsElem.addElement("Dependency");

          resElem.addAttribute("src", res.getSource());
          resElem.setText(res.getName());
        }
        else if(res.getType() == Resource.Type.STYLE)
        {
          resElem = stylesElem.addElement("Style");

          resElem.addAttribute("src", res.getSource());
          resElem.setText(res.getName());
        }
        else if(res.getType() == Resource.Type.RAW)
        {
          resElem = rawElem.addElement("Code"); // TODO: couldn't find any example using this so I made up the item tag name "Code"...

          resElem.addAttribute("name", res.getName());
          resElem.setText(res.getSource());
        }
        else
        {
          continue;
        }

        resElem
           .addAttribute("version", res.getVersion())
           .addAttribute("app", res.getApp());
      }
     
      if(!depsElem.hasContent()  ) { implElem.remove(depsElem);   }
      if(!stylesElem.hasContent()) { implElem.remove(stylesElem); }
      if(!rawElem.hasContent()   ) { implElem.remove(rawElem);    }
    }
     
    // OwnProperties
    if(comp.getPropertyUsageCount() > 0)
    {
      Element custPropsElem = null;

      IThingWriterFactory factory = context.getFactory();
      for(PropertyTypeUsage propUsage : comp.getPropertyUsages())
      {
        if(propUsage.isOwned())
        {
          if(custPropsElem == null)
          {
View Full Code Here

*/
public class CdeRunJsComponentTypeWriter extends JsWriterAbstract implements IThingWriter
{
  public void write(Object output, IThingWriteContext context, Thing t) throws ThingWriteException
  {
    ComponentType comp = (ComponentType)t;
    StringBuilder out  = (StringBuilder)output;
 
    Attribute cdeModelIgnoreAttr = comp.tryGetAttribute("cdeModelIgnore");
   
    if(cdeModelIgnoreAttr != null && "true".equals(cdeModelIgnoreAttr.getValue())) { return; }
   
    String name = comp.getName();
   
    // the name in cdefdejs/components/rows/type
    String modelPrefix  = CdeRunJsHelper.getComponentTypeModelPrefix(comp);
    String modelName    = CdeRunJsHelper.getComponentTypeModelId(comp, modelPrefix);
    String modelVarName = modelName + "Model";
   
    String label = comp.getLabel();
    String jsTooltip = JsonUtils.toJsString(comp.getTooltip());

    // --------------
    // ENTRY
    if(comp.getVisible())
    {
      String entryName = name + "Entry";
      String entryId   = name.toUpperCase() + "_ENTRY";
      String baseEntryType = comp.tryGetAttributeValue("cdePalleteType", "PalleteEntry");
      out.append(NEWLINE);
      out.append("var ");
      out.append(entryName);
      out.append(" = ");
      out.append(baseEntryType);
      out.append(".extend({");
      out.append(NEWLINE);

      addJsProperty(out, "id",           JsonUtils.toJsString(entryId), INDENT1, true);
      addJsProperty(out, "name",         JsonUtils.toJsString(label  ), INDENT1, false);
      addJsProperty(out, "description",  jsTooltip, INDENT1, false);
      addJsProperty(out, "category",     JsonUtils.toJsString(comp.getCategory()), INDENT1, false);
      addJsProperty(out, "categoryDesc", JsonUtils.toJsString(comp.getCategoryLabel()), INDENT1, false);
      addCommaAndLineSep(out);
      out.append(INDENT1);
      out.append("getStub: function() {");
      out.append(NEWLINE);
      out.append(INDENT2);
      out.append("return ");
      out.append(modelVarName);
      out.append(".getStub();");
      out.append(NEWLINE);
      out.append(INDENT1);
      out.append("}");
      out.append(NEWLINE);
      out.append("});");
      out.append(NEWLINE);
     
      // TODO: maybe asbtract this into some explicit ComponentType «Class» concept/field or something?
      String collectionName = (comp instanceof DataSourceComponentType) ?
              "CDFDDDatasourcesArray" :
              "CDFDDComponentsArray";

      out.append(collectionName);
      out.append(".push(new ");
      out.append(entryName);
      out.append("());");
      out.append(NEWLINE);
    }
   
    // --------------
    // OWN PROPERTIES
    if(comp.getPropertyUsageCount() > 0)
    {
      IThingWriterFactory factory = context.getFactory();
      for(PropertyTypeUsage propUsage : comp.getPropertyUsages())
      {
        if(propUsage.isOwned())
        {
          PropertyType prop = propUsage.getProperty();
          IThingWriter writer;
          try
          {
            writer = factory.getWriter(prop);
          }
          catch (UnsupportedThingException ex)
          {
            throw new ThingWriteException(ex);
          }

          writer.write(out, context, prop);
        }
      }
    }
   
    // --------------
    // MODEL
    //
    // Models aren't instantiated.
    // Their class is registered and only its static methods are used.
    // It's a static factory:
    //    AModelClass.getStub() --> creates a new model of given type
    // Own properties
    // Aliased properties
    out.append(NEWLINE);
    out.append("var "); out.append(modelVarName); out.append(" = BaseModel.create({"); out.append(NEWLINE);
   
    addJsProperty(out, "name",        JsonUtils.toJsString(modelName), INDENT1, true);
    addJsProperty(out, "description", jsTooltip, INDENT1, false);
    if(comp.getLegacyNameCount() > 0)
    {
      addCommaAndLineSep(out); out.append(INDENT1);
      out.append("legacyNames: [");
      boolean isFirstLegacyName = true;
      for(String legacyName : comp.getLegacyNames())
      {
        if(isFirstLegacyName)
        {
          isFirstLegacyName = false;
        }
        else
        {
          out.append(", ");
        }

        out.append(JsonUtils.toJsString(legacyName));
      }
      out.append("]");
    }
   
    boolean isFirstAttr = true;
    for(Attribute attribute : comp.getAttributes())
    {
      String attName = attribute.getName();
     
      if(!"cdeModelIgnore".equals(attName) &&
         !"cdeModelPrefix".equals(attName) &&
         !"cdePalleteType".equals(attName))
      {
        if(isFirstAttr)
        {
          addJsProperty(out, "metas", "{", INDENT1, false);
          out.append(NEWLINE);
        }
       
        String jsAttrName = attribute.getName();
        if(StringUtils.isEmpty(jsAttrName))
        {
          jsAttrName = "meta";
        }
        else
        {
          jsAttrName = "meta_" + jsAttrName;
        }
       
        addJsProperty(
            out,
            JsonUtils.toJsString(jsAttrName),
            JsonUtils.toJsString(attribute.getValue()),
            INDENT2,
            isFirstAttr);
       
        if(isFirstAttr) { isFirstAttr = false; }
      }
    }
   
    if(!isFirstAttr)
    {
      out.append(NEWLINE);
      out.append(INDENT1);
      out.append("}");
    }
   
    addJsProperty(out, "properties", "[", INDENT1, false);
    if(comp.getPropertyUsageCount() > 0)
    {
      boolean isFirstProp = true;
      for(PropertyTypeUsage propUsage : comp.getPropertyUsages())
      {
        if(isFirstProp) { isFirstProp = false; }
        else            { out.append(","); }
        out.append(NEWLINE);
        out.append(INDENT2);
View Full Code Here

          StringBuilder out,
          CggRunJsDashboardWriteContext context,
          GenericComponent comp,
          String dashDir) throws ThingWriteException
  {
    ComponentType compType = comp.getMeta();

    for(Resource resource : compType.getResources())
    {
      Resource.Type resType = resource.getType();
      switch(resType)
      {
        case RAW:
          out.append(NEWLINE);
          out.append(resource.getSource());
          out.append(NEWLINE);
          break;

        case SCRIPT:
          out.append(NEWLINE);
          out.append("load('");
          out.append(makeDashRelative(resource.getSource(), dashDir));
          out.append("');");
          out.append(NEWLINE);
          break;
      }
    }

    // Implementation
    String srcImpl = compType.getImplementationPath();
    if(StringUtils.isNotEmpty(srcImpl))
    {
      out.append(NEWLINE);
      out.append("load('");
      out.append(makeDashRelative(srcImpl, dashDir));
View Full Code Here

      if(StringUtils.isEmpty(this._alias))
      {
        throw new ValidationException(new RequiredAttributeError("Alias"));
      }

      ComponentType compType = owner.getMeta();
     
      // Bind by alias first
      PropertyTypeUsage propUsage = compType.tryGetPropertyUsage(this._alias);
      if(propUsage == null)
      {
        // Only then bind by name
        propUsage = compType.tryGetPropertyUsageByName(this._alias);
      }
     
      if(propUsage != null)
      {
        ExpectedPropertyBinding.Builder builder = new ExpectedPropertyBinding.Builder();
View Full Code Here

TOP

Related Classes of pt.webdetails.cdf.dd.model.meta.ComponentType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.