Package org.objectstyle.wolips.bindings.wod

Examples of org.objectstyle.wolips.bindings.wod.SimpleWodElement


    TemplateEditor te = getTemplateEditor();
    WodEditor we = getWodEditor();
    InsertComponentSpecification ics = getComponentSpecification();
    System.out.println("InsertHtmlAndWodAction.insert: " + te + ", " + we + ", " + ics);
    if (te != null && we != null && ics != null) {
      SimpleWodElement wodElement = new SimpleWodElement(ics.getComponentInstanceName(), ics.getComponentName());
      List<Binding> bindings = ics.getRequiredBindings();
      if (bindings != null) {
        for (Binding binding : bindings) {
          wodElement.addBinding(new SimpleWodBinding(null, binding.getName(), "", true));
        }
      }

      // If the component name is blank, then this is an HTML tag
      if (ics.getComponentName() == null || ics.getComponentName().length() == 0) {
        wodElement.setTagName(ics.getTagName());
      }

      SimpleWodElement htmlElement;
      if (ics.isInline()) {
        htmlElement = wodElement;
      } else {
        htmlElement = new SimpleWodElement("", "");
        htmlElement.setTagName(ics.getTagName());
      }

      Map<String, String> htmlAttributes = ics.getHtmlAttributes();
      if (htmlAttributes != null) {
        for (Map.Entry<String, String> htmlAttribute : htmlAttributes.entrySet()) {
          htmlElement.addBinding(new SimpleWodBinding(null, htmlAttribute.getKey(), htmlAttribute.getValue(), true));
        }
      }

      IDocument teDoc = te.getHtmlEditDocument();
      IDocument weDoc = we.getWodEditDocument();
      ITextSelection teDocTSel = (ITextSelection) te.getSourceEditor().getSelectionProvider().getSelection();

      // insert the WebObjects component into the template portion.
      try {
        ITextViewerExtension teExt = (ITextViewerExtension) te.getSourceEditor().getViewer();
        teExt.getRewriteTarget().beginCompoundChange();
        try {
          int selectionStartOffset = teDocTSel.getOffset();
          int selectionEndOffset = teDocTSel.getOffset() + teDocTSel.getLength();

          if (ics.isComponentContent()) {
            int selectionStartLine = teDocTSel.getStartLine();
            int selectionEndLine = teDocTSel.getEndLine();

            StringWriter startTagWriter = new StringWriter();
            htmlElement.writeInlineFormat(startTagWriter, "", true, true, false, false, "$", "");
            String startTag = startTagWriter.toString();

            StringWriter endTagWriter = new StringWriter();
            htmlElement.writeInlineFormat(endTagWriter, "", true, false, false, true, "$", "");
            String endTag = endTagWriter.toString();

            String indentText = getIndentText(teDoc, selectionStartOffset);
            IRegion startLineRegion = teDoc.getLineInformationOfOffset(selectionStartOffset);
            IRegion endLineRegion = teDoc.getLineInformationOfOffset(selectionEndOffset);

            // MS: If the selection starts within the indent
            // area, then you're actually selecting
            // from the beginning of the line, not splitting an
            // existing line of HTML.
            int selectionLineStartOffset = (selectionStartOffset - startLineRegion.getOffset());
            boolean selectionStartedInIndent = (indentText.length() >= selectionLineStartOffset);

            if (selectionStartLine == selectionEndLine) {
              if (selectionEndOffset == endLineRegion.getOffset() && selectionEndOffset > 0) {
                teDoc.replace(selectionEndOffset - 1, 0, endTag);
              } else {
                teDoc.replace(selectionEndOffset, 0, endTag);
              }

              if (selectionStartedInIndent) {
                if (indentText.length() == 0) {
                  int offset = Math.max(startLineRegion.getOffset() - 1, 0);
                  teDoc.replace(offset, 0, startTag);
                } else {
                  teDoc.replace(startLineRegion.getOffset() + indentText.length(), 0, startTag);
                }
              } else {
                teDoc.replace(selectionStartOffset, 0, startTag);
              }
            } else {
              int indentEndOffset;
              String lastLineIndentText = getIndentText(teDoc, selectionEndOffset);
              int selectionLineEndOffset = (selectionEndOffset - endLineRegion.getOffset());
              if (lastLineIndentText.length() >= selectionLineEndOffset) {
                String endText = indentText + endTag + "\n";
                teDoc.replace(endLineRegion.getOffset(), 0, endText);
                indentEndOffset = 1;
              } else {
                String endText = "\n" + indentText + endTag + "\n" + indentText;
                teDoc.replace(selectionEndOffset, 0, endText);
                indentEndOffset = 2;
              }

              int indentStartOffset;
              if (selectionStartedInIndent) {
                indentStartOffset = 1;
                String startText = startTag + "\n" + indentText;
                teDoc.replace(startLineRegion.getOffset() + indentText.length(), 0, startText);
              } else {
                indentStartOffset = 2;
                String startText = "\n" + indentText + startTag + "\n" + indentText;
                teDoc.replace(selectionStartOffset, 0, startText);
              }
              for (int line = selectionStartLine + indentStartOffset; line <= selectionEndLine + indentEndOffset; line++) {
                int lineOffset = teDoc.getLineOffset(line);
                teDoc.replace(lineOffset, 0, "\t");
              }
            }
          } else {
            StringWriter startTagWriter = new StringWriter();
            htmlElement.writeInlineFormat(startTagWriter, null, true, true, false, true, "$", "");
            String tag = startTagWriter.toString();
            teDoc.replace(selectionStartOffset, 0, tag);
          }
        } finally {
          teExt.getRewriteTarget().endCompoundChange();
View Full Code Here


              try {
                WodParserCache inheritCache = WodParserCache.parser(_wodFile.getProject(), componentName);
                WodCacheEntry wodCacheEntry = inheritCache.getWodEntry();
                IWodModel parentWodModel = wodCacheEntry.getModel();
                for (IWodElement parentWodElement : parentWodModel.getElements()) {
                  SimpleWodElement inheritedWodElement = new SimpleWodElement(parentWodElement);
                  inheritedWodElement.setInherited(true);
                  addElement(inheritedWodElement);
                }
              }
              catch (Throwable t) {
                addParseProblem(element, "WOD inheritance of '" + componentName + "' failed: " + t.getMessage() + ".", rulePosition, false);
View Full Code Here

  private WodParserCache _cache;

  public RefactoringWodElement(IWodElement element, WodParserCache cache) {
    _cache = cache;
    _wodElement = new SimpleWodElement(element);
    _propertyChange = new PropertyChangeSupport(this);
  }
View Full Code Here

    try {
      if (WodHtmlUtils.isWOTag(element.getName()) && WodHtmlUtils.isInline(element.getName())) {
        BuildProperties buildProperties = (BuildProperties)file.getProject().getAdapter(BuildProperties.class);
        if (attrName == null) {
          WodParserCache cache = WodParserCache.parser(file);
          SimpleWodElement wodElement = new FuzzyXMLWodElement(element, buildProperties);
          if (wodElement.isTypeWithin(new Region(offset, 0))) {
            hyperlinkInfo = new HTMLHyperlinkInfo();
            hyperlinkInfo.setOffset(wodElement.getElementTypePosition().getOffset());
            hyperlinkInfo.setLength(wodElement.getElementTypePosition().getLength());
            hyperlinkInfo.setObject(WodElementTypeHyperlink.toElementTypeHyperlink(wodElement, cache));
          }
        }
        else {
          WodParserCache cache;
          cache = WodParserCache.parser(file);
          SimpleWodElement wodElement = new FuzzyXMLWodElement(element, buildProperties);
          IWodBinding wodBinding = wodElement.getBindingNamed(attrName);
          if (wodBinding != null) {
            Position valuePosition = wodBinding.getValuePosition();
            if (valuePosition != null) {
              hyperlinkInfo = new HTMLHyperlinkInfo();
              hyperlinkInfo.setOffset(valuePosition.getOffset());
View Full Code Here

      FuzzyXMLElement element = htmlModel.getElementByOffset(_offset);
      if (element != null) {
        IWodModel wodModel = _cache.getWodEntry().getModel();
        String tagName = element.getName();
        if (WodHtmlUtils.isInline(tagName)) {
          SimpleWodElement wodElement = new FuzzyXMLWodElement(element, _buildProperties);
          ElementRename elementRename = ElementRename.newUniqueName(wodModel, wodElement, true);
          wodElement.setElementName(elementRename.getNewName());

          List<ElementRename> elementRenames = new LinkedList<ElementRename>();
          elementRenames.add(elementRename);

          ConvertInlineToWodRefactoring.appendWodElement(_cache, wodElement);
View Full Code Here

TOP

Related Classes of org.objectstyle.wolips.bindings.wod.SimpleWodElement

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.