Package org.eclipse.wst.xml.core.internal.document

Examples of org.eclipse.wst.xml.core.internal.document.DOMModelImpl


  public IModelLoader newInstance() {
    return new XMLModelLoader();
  }

  public IStructuredModel newModel() {
    return new DOMModelImpl();
  }
View Full Code Here


    this.beanFile = beanFile;
    this.existingBean = existingNode;
    this.fileBrowsingEnabled = false;

    IModelManager modelManager = StructuredModelManager.getModelManager();
    DOMModelImpl modelForRead = null;
    try {
      modelForRead = (DOMModelImpl) modelManager.getModelForRead(beanFile);
      originalDocument = modelForRead.getDocument();

      DOMModelImpl copiedModel = (DOMModelImpl) modelManager.createNewInstance(modelForRead);
      IDOMDocument copiedDocument = copiedModel.getDocument();

      newBean = (IDOMElement) copiedDocument.importNode(existingNode, true);
    }
    catch (IOException e) {
      StatusHandler.log(new Status(IStatus.ERROR, WizardPlugin.PLUGIN_ID, "Failed to create bean node.", e));
View Full Code Here

    addPage(newBeanPage);
    addPage(propertiesPage);
  }

  private void createBean() {
    DOMModelImpl model = null;
    try {
      IEditorPart editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
          beanFile);

      IModelManager modelManager = StructuredModelManager.getModelManager();
      model = (DOMModelImpl) modelManager.getModelForEdit(beanFile);
      IDOMDocument document = model.getDocument();

      model.beginRecording(this);

      Node nextSibling = null;
      IDOMElement parentNode;

      if (existingBean != null) {
        nextSibling = existingBean.getNextSibling();
        parentNode = (IDOMElement) existingBean.getParentNode();
        parentNode.removeChild(existingBean);
      }
      else {
        parentNode = (IDOMElement) document.getDocumentElement();
      }

      IDOMElement bean = (IDOMElement) document.importNode(newBean, true);
      if (nextSibling != null) {
        parentNode.insertBefore(bean, nextSibling);
      }
      else {
        parentNode.appendChild(bean);
      }

      new ShallowFormatProcessorXML().formatNode(parentNode);
      new FormatProcessorXML().formatNode(bean);

      model.endRecording(this);

      if (editor instanceof IConfigEditor) {
        IConfigEditor configEditor = (IConfigEditor) editor;
        int startOffset = bean.getStartOffset();
        int length = bean.getEndOffset() - startOffset;

        StructuredTextViewer textViewer = configEditor.getTextViewer();
        textViewer.setRangeIndication(startOffset, length, true);
        textViewer.revealRange(startOffset, length);
      }

      newBean = bean;
    }
    catch (IOException e) {
      StatusHandler.log(new Status(IStatus.ERROR, WizardPlugin.PLUGIN_ID, "Failed to create new bean.", e));
    }
    catch (CoreException e) {
      StatusHandler.log(new Status(IStatus.ERROR, WizardPlugin.PLUGIN_ID, "Failed to create new bean.", e));
    }
    finally {
      if (model != null) {
        model.releaseFromEdit();
        model = null;
      }
    }
  }
View Full Code Here

  }

  public void setBeanFile(IFile beanFile) {
    this.beanFile = beanFile;
    IModelManager modelManager = StructuredModelManager.getModelManager();
    DOMModelImpl modelForRead = null;

    try {
      modelForRead = (DOMModelImpl) modelManager.getModelForRead(beanFile);
      originalDocument = modelForRead.getDocument();

      DOMModelImpl copiedModel = (DOMModelImpl) modelManager.createNewInstance(modelForRead);
      IDOMDocument copiedDocument = copiedModel.getDocument();

      newBean = (IDOMElement) copiedDocument.createElementNS(NamespaceUtils.DEFAULT_NAMESPACE_URI,
          BeansSchemaConstants.ELEM_BEAN);
    }
    catch (IOException e) {
View Full Code Here

            selectedFile = (IFile) resource;
            int startLine = bean.getElementStartLine() - 1;
            int endLine = bean.getElementEndLine();

            IModelManager modelManager = StructuredModelManager.getModelManager();
            DOMModelImpl modelForRead = null;
            try {
              modelForRead = (DOMModelImpl) modelManager.getModelForRead(selectedFile);
              IStructuredDocument document = modelForRead.getStructuredDocument();
              int startOffset = document.getLineOffset(startLine);
              int endOffset = document.getLineOffset(endLine);

              if (startOffset == endOffset) {
                endOffset = document.getLength();
              }

              for (int i = startOffset; i < endOffset; i++) {
                Node node = BeansEditorUtils.getNodeByOffset(document, i);
                String localName = node.getLocalName();
                if (localName != null && localName.equals(BeansSchemaConstants.ELEM_BEAN)) {
                  NamedNodeMap attributes = node.getAttributes();

                  String beanName = bean.getElementName();
                  boolean matched = matchAndSelect(beanName, BeansSchemaConstants.ATTR_ID,
                      attributes, node);

                  if (selectedBean != null) {
                    return;
                  }

                  if (!matched) {
                    String className = bean.getClassName();
                    matchAndSelect(className, BeansSchemaConstants.ATTR_CLASS, attributes, node);

                    if (selectedBean != null) {
                      return;
                    }
                  }
                }
              }
            }
            catch (IOException e) {
              StatusHandler.log(new Status(IStatus.ERROR, WizardPlugin.PLUGIN_ID,
                  "Failed to get XML node from bean selection.", e));
            }
            catch (CoreException e) {
              StatusHandler.log(new Status(IStatus.ERROR, WizardPlugin.PLUGIN_ID,
                  "Failed to get XML node from bean selection.", e));
            }
            catch (BadLocationException e) {
              StatusHandler.log(new Status(IStatus.ERROR, WizardPlugin.PLUGIN_ID,
                  "Failed to get XML node from bean selection.", e));
            }
            finally {
              if (modelForRead != null) {
                modelForRead.releaseFromRead();
                modelForRead = null;
              }
            }
          }
        }
View Full Code Here

TOP

Related Classes of org.eclipse.wst.xml.core.internal.document.DOMModelImpl

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.