Search in sources :

Example 1 with XSDModelAdapter

use of org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter in project webtools.sourceediting by eclipse.

the class InternalXSDMultiPageEditor method setInputToGraphicalViewer.

protected void setInputToGraphicalViewer(IDocument newDocument) {
    IStructuredModel structuredModel = null;
    try {
        // only set input if structured model already exists
        // (meaning source editor is already managing the model)
        structuredModel = StructuredModelManager.getModelManager().getExistingModelForRead(newDocument);
        if ((structuredModel != null) && (structuredModel instanceof IDOMModel)) {
            Document doc = ((IDOMModel) structuredModel).getDocument();
            if (doc != null) {
                XSDModelAdapter modelAdapter = XSDModelAdapter.lookupOrCreateModelAdapter(doc);
                if (// Assert should not be null
                modelAdapter != null) {
                    modelAdapter.setSchema(xsdSchema);
                    xsdSchema = modelAdapter.resetSchema(doc);
                    model = (IModel) XSDAdapterFactory.getInstance().adapt(xsdSchema);
                }
            }
        }
    } catch (Exception e) {
    } finally {
        if (structuredModel != null) {
            structuredModel.releaseFromRead();
        }
    }
}
Also used : XSDModelAdapter(org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) Document(org.w3c.dom.Document) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with XSDModelAdapter

use of org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter in project webtools.sourceediting by eclipse.

the class XSDHyperlinkDetector method getXSDSchema.

/**
 * Gets the xsd schema from document
 *
 * @param document
 * @return XSDSchema or null of one does not exist yet for document
 */
private XSDSchema getXSDSchema(IDocument document) {
    XSDSchema schema = null;
    IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
    if (model != null) {
        try {
            if (model instanceof IDOMModel) {
                IDOMDocument domDoc = ((IDOMModel) model).getDocument();
                if (domDoc != null) {
                    XSDModelAdapter modelAdapter = (XSDModelAdapter) domDoc.getExistingAdapter(XSDModelAdapter.class);
                    /*
             * ISSUE: Didn't want to go through initializing schema if it does
             * not already exist, so just attempted to get existing adapter. If
             * doesn't exist, just don't bother working.
             */
                    if (modelAdapter != null)
                        schema = modelAdapter.getSchema();
                }
            }
        } finally {
            model.releaseFromRead();
        }
    }
    return schema;
}
Also used : XSDModelAdapter(org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 3 with XSDModelAdapter

use of org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter in project webtools.sourceediting by eclipse.

the class InternalXSDMultiPageEditor method doSaveAs.

/* (non-Javadoc)
   * @see org.eclipse.ui.part.EditorPart#doSaveAs()
   */
public void doSaveAs() {
    // When performing a save as, the document changes.   Our model state listeners should listen
    // to the new document.
    // First get the current document
    IDocument currentDocument = getDocument();
    XSDModelAdapter modelAdapter = null;
    IDOMDocument doc = null;
    if (currentDocument != null) {
        IStructuredModel structuredModel = StructuredModelManager.getModelManager().getExistingModelForRead(currentDocument);
        if (structuredModel != null) {
            try {
                if ((structuredModel != null) && (structuredModel instanceof IDOMModel)) {
                    // Get the associated IDOMDocument model
                    doc = ((IDOMModel) structuredModel).getDocument();
                    // and now get our adapter that listens to DOM changes
                    if (doc != null) {
                        modelAdapter = (XSDModelAdapter) doc.getExistingAdapter(XSDModelAdapter.class);
                    }
                }
            } finally {
                structuredModel.releaseFromRead();
            }
        }
    }
    IEditorInput editorInput = structuredTextEditor.getEditorInput();
    // perform save as
    structuredTextEditor.doSaveAs();
    // See AbstractDecoratedTextEditor's performSaveAs
    if (editorInput != structuredTextEditor.getEditorInput()) {
        setInput(structuredTextEditor.getEditorInput());
        setPartName(structuredTextEditor.getEditorInput().getName());
        getCommandStack().markSaveLocation();
        // Now do the clean up on the old document
        if (modelAdapter != null) {
            // clear out model adapter
            modelAdapter.clear();
            modelAdapter = null;
        }
    }
}
Also used : XSDModelAdapter(org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDocument(org.eclipse.jface.text.IDocument) IEditorInput(org.eclipse.ui.IEditorInput)

Example 4 with XSDModelAdapter

use of org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter in project webtools.sourceediting by eclipse.

the class InternalXSDMultiPageEditor method dispose.

public void dispose() {
    IStructuredModel structuredModel = null;
    XSDModelAdapter modelAdapter = null;
    IDOMDocument doc = null;
    IDocument idoc = structuredTextEditor.getDocumentProvider().getDocument(getEditorInput());
    if (idoc != null) {
        structuredModel = StructuredModelManager.getModelManager().getExistingModelForRead(idoc);
        if ((structuredModel != null) && (structuredModel instanceof IDOMModel)) {
            try {
                if ((structuredModel != null) && (structuredModel instanceof IDOMModel)) {
                    doc = ((IDOMModel) structuredModel).getDocument();
                    if (doc != null) {
                        modelAdapter = (XSDModelAdapter) doc.getExistingAdapter(XSDModelAdapter.class);
                        if (modelAdapter != null) {
                            doc.getModel().removeModelStateListener(modelAdapter.getModelReconcileAdapter());
                            doc.removeAdapter(modelAdapter.getModelReconcileAdapter());
                            doc.removeAdapter(modelAdapter);
                            modelAdapter.clear();
                            modelAdapter = null;
                        }
                    }
                }
            } finally {
                structuredModel.releaseFromRead();
            }
        }
    }
    if (fOutlinePage != null) {
        // }
        if (fOutlineListener != null) {
            fOutlinePage.removeSelectionChangedListener(fOutlineListener);
        }
    }
    getSelectionManager().removeSelectionChangedListener(fXSDSelectionListener);
    XSDEditorPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(xsdPreferenceStoreListener);
    xsdPreferenceStoreListener = null;
    super.dispose();
}
Also used : XSDModelAdapter(org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with XSDModelAdapter

use of org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter in project webtools.sourceediting by eclipse.

the class XSDTabbedPropertySheetPage method selectionChanged.

/* (non-Javadoc)
   * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
   */
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    Object selected = ((IStructuredSelection) selection).getFirstElement();
    if (selected instanceof XSDBaseAdapter) {
        XSDBaseAdapter adapter = (XSDBaseAdapter) selected;
        if (oldSelection != null) {
            oldSelection.unregisterListener(this);
            if (oldSelection instanceof XSDElementDeclarationAdapter) {
                XSDElementDeclaration elem = (XSDElementDeclaration) ((XSDElementDeclarationAdapter) oldSelection).getTarget();
                if (elem.getContainer() != null) {
                    Adapter adap = XSDAdapterFactory.getInstance().adapt(elem.getContainer());
                    if (adap instanceof XSDParticleAdapter) {
                        XSDParticleAdapter particleAdapter = (XSDParticleAdapter) adap;
                        particleAdapter.unregisterListener(this);
                    }
                }
                if (elem.isElementDeclarationReference()) {
                    XSDElementDeclarationAdapter resolvedElementAdapter = (XSDElementDeclarationAdapter) XSDAdapterFactory.getInstance().adapt(elem.getResolvedElementDeclaration());
                    resolvedElementAdapter.unregisterListener(this);
                }
            }
        }
        if (adapter instanceof XSDElementDeclarationAdapter) {
            XSDElementDeclaration elem = (XSDElementDeclaration) ((XSDElementDeclarationAdapter) adapter).getTarget();
            Adapter adap = XSDAdapterFactory.getInstance().adapt(elem.getContainer());
            if (adap instanceof XSDParticleAdapter) {
                XSDParticleAdapter particleAdapter = (XSDParticleAdapter) adap;
                particleAdapter.registerListener(this);
            }
            if (elem.isElementDeclarationReference()) {
                XSDElementDeclarationAdapter resolvedElementAdapter = (XSDElementDeclarationAdapter) XSDAdapterFactory.getInstance().adapt(elem.getResolvedElementDeclaration());
                resolvedElementAdapter.registerListener(this);
            }
        } else if (adapter instanceof XSDAttributeUseAdapter) {
            XSDAttributeUseAdapter attributeUse = (XSDAttributeUseAdapter) adapter;
            XSDAttributeUse xsdAttrUse = (XSDAttributeUse) attributeUse.getTarget();
            adapter = (XSDBaseAdapter) XSDAdapterFactory.getInstance().adapt(xsdAttrUse.getAttributeDeclaration());
        }
        adapter.registerListener(this);
        oldSelection = adapter;
        Object model = adapter.getTarget();
        if (xsdModelAdapter != null && xsdModelAdapter.getModelReconcileAdapter() != null) {
            xsdModelAdapter.getModelReconcileAdapter().removeListener(internalNodeAdapter);
        }
        Element element = ((XSDConcreteComponent) adapter.getTarget()).getElement();
        if (element != null) {
            xsdModelAdapter = XSDModelAdapter.lookupOrCreateModelAdapter(element.getOwnerDocument());
        }
        if (xsdModelAdapter != null && xsdModelAdapter.getModelReconcileAdapter() != null) {
            xsdModelAdapter.getModelReconcileAdapter().addListener(internalNodeAdapter);
        }
        if (model instanceof XSDConcreteComponent) {
            selection = new StructuredSelection(model);
        }
        super.selectionChanged(part, selection);
        return;
    }
    super.selectionChanged(part, selection);
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Element(org.w3c.dom.Element) XSDParticleAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDParticleAdapter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDParticleAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDParticleAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) XSDModelAdapter(org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter) INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDAttributeUseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeUseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter) XSDAttributeUseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeUseAdapter)

Aggregations

XSDModelAdapter (org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter)5 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)4 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)4 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)4 IDocument (org.eclipse.jface.text.IDocument)3 Adapter (org.eclipse.emf.common.notify.Adapter)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 IEditorInput (org.eclipse.ui.IEditorInput)1 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1 XSDAttributeUseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeUseAdapter)1 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)1 XSDElementDeclarationAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter)1 XSDParticleAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDParticleAdapter)1 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)1 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)1 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)1 XSDSchema (org.eclipse.xsd.XSDSchema)1 Document (org.w3c.dom.Document)1