Package com.puppetlabs.geppetto.catalog

Examples of com.puppetlabs.geppetto.catalog.CatalogResource


    }

    @Override
    public CatalogResource deserialize(JsonElement json, java.lang.reflect.Type typeOfT,
        JsonDeserializationContext context) throws JsonParseException {
      final CatalogResource result = CatalogFactory.eINSTANCE.createCatalogResource();
      JsonObject jsonObj = json.getAsJsonObject();

      result.setFile(getString(jsonObj, "file"));
      result.setLine(getString(jsonObj, "line"));
      result.setType(getString(jsonObj, "type"));
      result.setTitle(getString(jsonObj, "title"));
      result.setExported(getBoolean(jsonObj, "exported"));
      result.setVirtual(getBoolean(jsonObj, "virtual"));

      json = jsonObj.get("tags");
      if(json != null)
        deserializeInto(json, result.getTags(), String.class, context);

      json = jsonObj.get("parameters");
      // if(json != null) {
      // deserializeInto(json, result.getParameters(), CatalogResourceParameter.class, context);
      // }
      if(json != null) {
        JsonObject parameterHash = json.getAsJsonObject();
        EList<CatalogResourceParameter> pList = result.getParameters();
        for(Map.Entry<String, JsonElement> entry : parameterHash.entrySet()) {
          CatalogResourceParameter rp = CatalogFactory.eINSTANCE.createCatalogResourceParameter();
          rp.setName(entry.getKey());
          if(entry.getValue().isJsonArray()) {
            deserializeInto(entry.getValue(), rp.getValue(), String.class, context);
View Full Code Here


  private StyleSet labelStyleForResource(CatalogResource oldR, IPath oldRoot, CatalogResource newR, IPath newRoot,
      String[] resultingStyle) {
    if(resultingStyle == null || resultingStyle.length != 1)
      throw new IllegalArgumentException("resulting style must be String[1]");
    final CatalogResource singleResource = newR == null
        ? oldR
        : newR;
    final IPath singleRoot = newR == null
        ? oldRoot
        : newRoot;

    if(singleResource == null)
      throw new IllegalArgumentException("At least one catalog must be specified");
    if(oldR != null && newR != null) {
      if(!(oldR.getType().equals(newR.getType()) && oldR.getTitle().toLowerCase().equals(
        newR.getTitle().toLowerCase())))
        throw new IllegalArgumentException("old and new resource must have same type and title");
    }
    // PROPERTIES
    List<LabelRow> innerLabelRows = Lists.newArrayList();
    final PropertyDeltaInfo propertyInfo = computePropertyRows(oldR, newR, innerLabelRows);
    int width = propertyInfo.width;

    // RESULTING OVERALL STYLE
    // i.e. if only one resource - it is either added or removed
    // and if the two were compared, it is unmodified if all properties were present with equal value
    if(propertyInfo.singleResourceStyle != null)
      resultingStyle[0] = propertyInfo.singleResourceStyle;
    else
      resultingStyle[0] = propertyInfo.modifiedCount == 0
          ? STYLE_UnModified
          : STYLE_Modified;

    // The title can never differ as that means different resources - it is either a single catalog
    // (the non null catalog), or the newCatalog in case both are passed.
    // Add a labelRow for the 'type[id]'
    StringBuilder builder = new StringBuilder();
    if(resultingStyle[0].equals(STYLE_Added)) {
      builder.append(GT);
      builder.append(" ");
    }
    else if(resultingStyle[0].equals(STYLE_Removed)) {
      builder.append(LT);
      builder.append(" ");
    }
    builder.append(singleResource.getType());
    builder.append("[");
    builder.append(singleResource.getTitle());
    builder.append("]");

    boolean hasParameters = propertyInfo.width > 0;
    boolean hasFooter = singleResource.getFile() != null; // only show new Catalog file even if different
    List<LabelRow> labelRows = Lists.newArrayList();

    if(hasParameters || hasFooter)
      labelRows.add(getStyles().labelRow(
        "RowSeparator", getStyles().labelCell("SpacingCell", "", Span.colSpan(1))));

    labelRows.add(getStyles().labelRow(STYLE_ResourceTitleRow, //
      getStyles().labelCell(STYLE_ResourceTitleCell, builder.toString(), Span.colSpan(1))));
    width = Math.max(width, builder.length());

    // Rendering of separator line fails in graphviz 2.28 with an error
    // labelRows.add(getStyles().rowSeparator());
    if(hasParameters || hasFooter) {
      labelRows.add(getStyles().labelRow(
        "RowSeparator", getStyles().labelCell("SpacingCell", "", Span.colSpan(1))));
      labelRows.add(getStyles().labelRow("RowSeparator", getStyles().labelCell("HRCell", "", Span.colSpan(1))));
      labelRows.add(getStyles().labelRow(
        "RowSeparator", getStyles().labelCell("SpacingCell", "", Span.colSpan(1))));
    }

    // // OLD STYLE
    // labelRows.addAll(innerLabelRows);
    // NEW STYLE
    if(innerLabelRows.size() > 0) {
      LabelCell tableCell = getStyles().labelCell(
        "ResourceTableCell",//
        getStyles().labelTable(STYLE_ResourceTable, innerLabelRows.toArray(new LabelRow[innerLabelRows.size()])));
      labelRows.add(getStyles().labelRow("ResourceTableRow", tableCell));
    }

    // FOOTER
    // A footer with filename[line]
    // (is not always present)
    if(hasFooter) {
      builder = new StringBuilder();
      // shorten the text by making it relative to root if possible
      if(singleRoot != null)
        builder.append(new Path(singleResource.getFile()).makeRelativeTo(singleRoot).toString());
      else
        builder.append(singleResource.getFile());
      if(singleResource.getLine() != null) {
        builder.append("[");
        builder.append(singleResource.getLine());
        builder.append("]");
      }

      String tooltip = builder.toString();
      if(builder.length() > width) {
        builder.delete(0, builder.length() - width);
        builder.insert(0, "[...]");
      }

      if(hasParameters)
        labelRows.add(getStyles().labelRow(
          "RowSeparator", getStyles().labelCell("SpacingCell", "", Span.colSpan(1))));

      int line = -1;
      try {
        line = Integer.valueOf(singleResource.getLine());
      }
      catch(NumberFormatException e) {
        line = -1;
      }
      labelRows.add(getStyles().labelRow(
        STYLE_ResourceFileInfoRow, //
        getStyles().labelCell(STYLE_ResourceFileInfoCell, builder.toString(), Span.colSpan(1)).withStyles(
          getStyles().tooltip(tooltip), //
          getStyles().href(
            getHrefProducer().hrefToManifest(new Path(singleResource.getFile()), singleRoot, line)) //
        )) //
      );
    }
    else if(hasParameters) {
      // add a bit of padding at the bottom if there is no footer
View Full Code Here

TOP

Related Classes of com.puppetlabs.geppetto.catalog.CatalogResource

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.