private IContentOutlinePage getInitialPage() {
    IPreferenceStore store = UIPlugin.getDefault().getPreferenceStore();
    boolean flag = store.getBoolean(SHOW_TAPESTRY_OUTLINE);
    if (flag) return fTapestryOutlinePage;

    return fXMLOutlinePage;
  }
  public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
    if (getEditor() == null) return super.getContentAssistant(sourceViewer);

    ContentAssistant assistant = getEditor().getContentAssistant();
    AbstractContentAssistProcessor tagProcessor = new TagCompletionProcessor(fEditor);
    AbstractContentAssistProcessor commentProcessor = new CommentCompletionProcessor(fEditor);
    AbstractContentAssistProcessor attributeProcessor = new AttributeCompletionProcessor(fEditor);
    AbstractContentAssistProcessor declProcessor = new DeclCompletionProcessor(fEditor);
    AbstractContentAssistProcessor defaultProcessor = new DefaultCompletionProcessor(fEditor);
    AbstractContentAssistProcessor cdataProcessor = new CDATACompletionProcessor(fEditor);

    assistant.setContentAssistProcessor(tagProcessor, XMLPartitionScanner.XML_TAG);
    assistant.setContentAssistProcessor(commentProcessor, XMLPartitionScanner.XML_COMMENT);
    assistant.setContentAssistProcessor(attributeProcessor, XMLPartitionScanner.XML_ATTRIBUTE);
    assistant.setContentAssistProcessor(declProcessor, XMLPartitionScanner.XML_DECL);
    assistant.setContentAssistProcessor(defaultProcessor, IDocument.DEFAULT_CONTENT_TYPE);
    assistant.setContentAssistProcessor(cdataProcessor, XMLPartitionScanner.XML_CDATA);
    assistant.enableAutoActivation(true);
    assistant.setProposalSelectorBackground(
        UIPlugin.getDefault().getSharedTextColors().getColor(new RGB(254, 241, 233)));
    assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
    assistant.install(sourceViewer);

    return assistant;
  }
 public void valueChanged(boolean on, boolean store) {
   setChecked(on);
   if (store) {
     fInitiatedByMe = true;
     UIPlugin.getDefault().getPreferenceStore().setValue(SHOW_TAPESTRY_OUTLINE, on);
     fInitiatedByMe = false;
   }
 }
Example #4
0
 private boolean attributeHasValue() {
   try {
     String content = document.get(getOffset(), getLength());
     return content.indexOf('=') > 0 && getAttributeValueStart() > 0;
   } catch (BadLocationException e) {
     UIPlugin.log(e);
   }
   return false;
 }
  private void setXMLOutlineInput() {
    IDocumentProvider provider = fEditor.getDocumentProvider();

    // force creation of the document & the model.
    IDocument document = provider.getDocument(fEditor.getEditorInput());
    IXMLModelProvider modelProvider = UIPlugin.getDefault().getXMLModelProvider();
    XMLReconciler model = (modelProvider).getModel(document);
    fXMLOutlinePage.setInput(model.getRoot());
  }
Example #6
0
 private String getAttributeName() {
   try {
     String content = document.get(getOffset(), getLength());
     int index = content.indexOf("=");
     if (index == -1) {
       index = content.indexOf("\"");
       if (index == -1) {
         index = content.indexOf("'");
         if (index == -1) index = content.length();
       }
     }
     return content.substring(0, index).trim();
   } catch (BadLocationException e) {
     UIPlugin.log(e);
   }
   return null;
 }
Example #7
0
  public String getAttributeValue() {

    if (!attributeHasValue()) return null;
    try {
      int index = getAttributeValueStart();

      if (index < 0) return null;

      String content = document.get(getOffset(), getLength());
      content = content.substring(index).trim();

      if (content.length() < 2) return "";

      return content.substring(1, content.length() - 1);
    } catch (BadLocationException e) {
      UIPlugin.log(e);
    }

    return null;
  }
    public ToggleAction(MultiPageContentOutline outline) {
      super();
      fOutline = outline;
      setText("Toggle between outline views");
      setToolTipText("Toggle between outline views");
      setImageDescriptor(Images.getImageDescriptor("application16.gif"));

      IPreferenceStore store = UIPlugin.getDefault().getPreferenceStore();
      store.addPropertyChangeListener(
          new IPropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent event) {
              if (event.getProperty().equals(SHOW_TAPESTRY_OUTLINE)) {
                if (fInitiatedByMe == false) {
                  boolean showTapestry = ((Boolean) event.getNewValue()).booleanValue();
                  valueChanged(showTapestry, false);
                  fOutline.switchPages(showTapestry);
                }
              }
            }
          });
      boolean checked = store.getBoolean(SHOW_TAPESTRY_OUTLINE);
      valueChanged(checked, false);
    }
 /*
  * (non-Javadoc)
  *
  * @see com.iw.plugins.spindle.editors.IReconcileListener#reconciled(java.lang.Object)
  */
 public void reconciled(Object reconcileResults) {
   try {
     fReconciledObject = reconcileResults;
     setXMLOutlineInput();
     fTapestryOutlinePage.setInput(fReconciledObject);
     if (fCurrentPage == fTapestryOutlinePage || fCurrentPage == fMessagePage) {
       if (fReconciledObject == null) {
         fMessagePoster.postMessage("Outline is not available.");
         fPageTurner.post(fMessagePage);
       } else {
         fPageTurner.post(fTapestryOutlinePage);
       }
     }
   } catch (IllegalArgumentException e) {
     fMessagePoster.postMessage("internalError");
     fPageTurner.post(fMessagePage);
   } catch (RuntimeException e) {
     UIPlugin.log(e);
     throw e;
   } finally {
     fToggleAction.setEnabled(true);
   }
 }
Example #10
0
  public int getStateAt(int offset) {
    int state = TAG;
    String content = null;
    try {
      content = document.get(getOffset(), offset - getOffset());
    } catch (BadLocationException e) {
      UIPlugin.log(e);
      return TAG;
    }

    String name = getName();
    if (name == null) return TAG;

    String type = getType();
    if (type == "/") return -1;

    String terminator = (String) TERMINATORS.get(type);
    int terminatorLength = terminator.length();

    for (int i = name.length(); i < content.length(); i++) {
      char c = content.charAt(i);
      switch (c) {
        case '=':
          if (state == AFTER_ATTRIBUTE || state == ATTRIBUTE) {
            state = ATT_VALUE;
          }
          break;
        case '"':
          if (state == DOUBLEQUOTE) {
            state = AFTER_ATT_VALUE;
          } else if (state == SINGLEQUOTE) {
            break;
          } else {
            state = DOUBLEQUOTE;
          }
          break;
        case '\'':
          if (state == SINGLEQUOTE) {
            state = AFTER_ATT_VALUE;
          } else if (state == DOUBLEQUOTE) {
            break;
          } else {
            state = SINGLEQUOTE;
          }
          break;
        default:
          if (Character.isWhitespace(c)) {
            switch (state) {
              case TAG:
                state = ATTRIBUTE;
                break;
              case ATTR:
                state = AFTER_ATTRIBUTE;
                break;
              case AFTER_ATT_VALUE:
                state = ATTRIBUTE;
                break;
            }
          } else if (terminatorLength > 0) {
            switch (state) {
              case IN_TERMINATOR:
                break;
              case DOUBLEQUOTE:
              case SINGLEQUOTE:
                break;
              default:
                if (c == terminator.charAt(0)) state = IN_TERMINATOR;
                break;
            }
          }
      }
    }

    return state;
  }
Example #11
0
  public List getAttributes() {
    List attrs = new ArrayList();
    String content = null;
    int state = TAG;
    int start = -1;
    int startLength = 0;
    int endLength = 0;
    if (ITypeConstants.PI.equals(getType())) {
      startLength = 2;
      endLength = 2;
    } else if (ITypeConstants.DECL.equals(getType())) {
      //      if ("!DOCTYPE".equals(getName()))
      //        return getDoctypeAttributes();
      startLength = 1;
      endLength = 1;
    } else if (ITypeConstants.TAG.equals(getType())) {
      startLength = 1;
      endLength = 1;
    } else if (ITypeConstants.EMPTYTAG.equals(getType())) {
      startLength = 1;
      endLength = 2;
    } else {
      return attrs;
    }

    try {
      content = document.get(getOffset(), getLength());
    } catch (BadLocationException e) {
      UIPlugin.log(e);
      return attrs;
    }

    String name = getName();
    int initial = name == null ? 0 : content.indexOf(name) + name.length();

    for (int i = startLength + initial; i < content.length() - endLength; i++) {
      char c = content.charAt(i);
      switch (c) {
        case '"':
          if (state == DOUBLEQUOTE) {
            attrs.add(
                new XMLNode(getOffset() + start, i - start + 1, ITypeConstants.ATTR, document));
            start = -1;
            state = TAG;
          } else if (state == SINGLEQUOTE) {
            break;
          } else if (state != ATTR) {
            start = i;
            state = DOUBLEQUOTE;
          } else {
            state = DOUBLEQUOTE;
          }
          break;
        case '\'':
          if (state == SINGLEQUOTE) {
            attrs.add(
                new XMLNode(getOffset() + start, i - start + 1, ITypeConstants.ATTR, document));
            start = -1;
            state = TAG;
          } else if (state == DOUBLEQUOTE) {
            break;
          } else if (state != ATTR) {
            start = i;
            state = SINGLEQUOTE;
          } else {
            state = SINGLEQUOTE;
          }
          break;
        default:
          if (!Character.isWhitespace(c)) {
            if (state == TAG) {
              start = i;
              state = ATTR;
            }
          } else if (state == ATTR) {
            boolean stop = false;
            int j = i;
            // lookahead to see if this is an attribute name with no value
            for (; j < content.length() - endLength; j++) {
              char lookahead = content.charAt(j);

              switch (lookahead) {
                case '=':
                  break;
                case '"':
                  break;
                case '\'':
                  break;
                default:
                  stop = !Character.isWhitespace(lookahead);
                  break;
              }
              if (stop) break;
            }
            if (stop) {

              attrs.add(
                  new XMLNode(getOffset() + start, i - start + 1, ITypeConstants.ATTR, document));
              start = -1;
              state = TAG;
            }
          }
      }
    }

    if (start != -1) {
      attrs.add(
          new XMLNode(
              getOffset() + start,
              content.length()
                  - startLength
                  - start
                  - (!getType().equals(ITypeConstants.TAG) ? 1 : 0),
              ITypeConstants.ATTR,
              document));
    }
    for (Iterator iter = attrs.iterator(); iter.hasNext(); ) {
      XMLNode attr = (XMLNode) iter.next();
      attr.length = StringUtils.stripEnd(attr.getContent(), null).length();
    }

    return attrs;
  }