Search in sources :

Example 36 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.

the class AbstractCSSModelAdapter method createModel.

/**
 */
protected ICSSModel createModel() {
    // create embedded CSS model (not for external CSS)
    Element element = getElement();
    if (element == null)
        return null;
    String contentType = null;
    if (element instanceof ElementStyleImpl) {
        contentType = ((ElementStyleImpl) element).getEmbeddedStyleType();
    }
    IStructuredModel baseModel = ((IDOMNode) element).getModel();
    ICSSModel newModel = (ICSSModel) baseModel.getModelManager().createUnManagedStructuredModelFor(contentType != null ? contentType : CSS_ID);
    ((CSSModelImpl) newModel).setOwnerDOMNode(element);
    return newModel;
}
Also used : ElementStyleImpl(org.eclipse.wst.html.core.internal.document.ElementStyleImpl) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) Element(org.w3c.dom.Element) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) CSSModelImpl(org.eclipse.wst.css.core.internal.document.CSSModelImpl)

Example 37 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.

the class StyleElementAdapter method replaceData.

/**
 * Apply changes from CSS sub-model to HTML model
 */
private void replaceData(int offset, int length, String data) {
    IDOMNode element = (IDOMNode) getElement();
    if (element == null)
        return;
    IDOMModel ownerModel = element.getModel();
    if (ownerModel == null)
        return;
    IStructuredDocument structuredDocument = ownerModel.getStructuredDocument();
    if (structuredDocument == null)
        return;
    IStructuredDocumentRegion flatNode = element.getStartStructuredDocumentRegion();
    if (flatNode == null)
        return;
    int contentOffset = flatNode.getEndOffset();
    if (data == null)
        // $NON-NLS-1$
        data = "";
    this.ignoreNotification = true;
    structuredDocument.replaceText(getRequesterC2H(), contentOffset + offset, length, data);
    this.ignoreNotification = false;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 38 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.

the class HTMLTextFormatter method canRemoveTailingSpaces.

/**
 */
private boolean canRemoveTailingSpaces(IDOMNode node) {
    if (node == null)
        return false;
    if (node.getNextSibling() != null)
        return false;
    Node parent = node.getParentNode();
    if (parent == null || parent.getNodeType() != Node.ELEMENT_NODE)
        return false;
    CMElementDeclaration decl = getElementDeclaration((Element) parent);
    if (decl == null || (!decl.supports(HTMLCMProperties.LINE_BREAK_HINT)))
        return false;
    String hint = (String) decl.getProperty(HTMLCMProperties.LINE_BREAK_HINT);
    return hint.equals(HTMLCMProperties.Values.BREAK_BEFORE_START_AND_AFTER_END);
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Node(org.w3c.dom.Node) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)

Example 39 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.

the class TEIValidation method testCustomTagInAttribute.

public void testCustomTagInAttribute() throws Exception {
    // $NON-NLS-1$
    final String path = "/" + PROJECT_NAME + "/WebContent/test.jsp";
    final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path));
    IStructuredModel model = StructuredModelManager.getModelManager().getModelForRead(file);
    try {
        assertTrue("Not an IDOMModel", model instanceof IDOMModel);
        NodeList divs = ((IDOMModel) model).getDocument().getElementsByTagName("div");
        assertTrue("Missing a div", divs.getLength() > 0);
        IDOMNode node = (IDOMNode) divs.item(0);
        IStructuredDocumentRegion region = node.getStartStructuredDocumentRegion();
        ITextRegionList regions = region.getRegions();
        assertTrue(regions.size() > 2);
        /* This test is failing as of 20180213 so until someone can debug and fix it, comment it out */
        /* JSPJavaTranslatorCoreTest.waitForBuildAndValidation(getProject()); */
        final TaglibHelper helper = new TaglibHelper(getProject());
        final List problems = new ArrayList();
        final IStructuredDocument document = model.getStructuredDocument();
        ITextRegion embedded = regions.get(2);
        assertTrue("Not a container region", embedded instanceof ITextRegionContainer);
        helper.getCustomTag("test:foo", document, (ITextRegionContainer) embedded, problems);
    /* assertEquals("No problems should be generated", 0, problems.size()); */
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IFile(org.eclipse.core.resources.IFile) TaglibHelper(org.eclipse.jst.jsp.core.internal.taglib.TaglibHelper) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 40 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.

the class ShowTranslationHandler method execute.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands
	 * .ExecutionEvent)
	 */
public Object execute(final ExecutionEvent event) throws ExecutionException {
    // IDE.openEditor(event.getApplicationContext(), createEditorInput(),
    // JavaUI.ID_CU_EDITOR, true);
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        List list = ((IStructuredSelection) selection).toList();
        if (!list.isEmpty()) {
            if (list.get(0) instanceof IDOMNode) {
                final IDOMModel model = ((IDOMNode) list.get(0)).getModel();
                INodeAdapter adapter = model.getDocument().getAdapterFor(IJsTranslation.class);
                if (adapter != null) {
                    Job opener = new UIJob("Opening JavaScript Translation") {

                        public IStatus runInUIThread(IProgressMonitor monitor) {
                            JsTranslationAdapter translationAdapter = (JsTranslationAdapter) model.getDocument().getAdapterFor(IJsTranslation.class);
                            final IJsTranslation translation = translationAdapter.getJsTranslation(false);
                            // create an IEditorInput for the Java editor
                            final IStorageEditorInput input = new JSTranslationEditorInput(translation, model.getBaseLocation());
                            try {
                                IEditorPart editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), input, JavaScriptUI.ID_CU_EDITOR, true);
                                // Now add the problems we found
                                if (editor instanceof ITextEditor) {
                                    IAnnotationModel annotationModel = ((ITextEditor) editor).getDocumentProvider().getAnnotationModel(input);
                                    translation.reconcileCompilationUnit();
                                    List problemsList = translation.getProblems();
                                    IProblem[] problems = (IProblem[]) problemsList.toArray(new IProblem[problemsList.size()]);
                                    AnnotationTypeLookup lookup = new AnnotationTypeLookup();
                                    for (int i = 0; i < problems.length; i++) {
                                        int length = problems[i].getSourceEnd() - problems[i].getSourceStart() + 1;
                                        Position position = new Position(problems[i].getSourceStart(), length);
                                        Annotation annotation = null;
                                        String type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_INFO);
                                        if (problems[i].isError()) {
                                            type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_ERROR);
                                        } else if (problems[i].isWarning()) {
                                            type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_WARNING);
                                        }
                                        annotation = new Annotation(type, false, problems[i].getMessage());
                                        if (annotation != null) {
                                            annotationModel.addAnnotation(annotation, position);
                                        }
                                    }
                                }
                            } catch (PartInitException e) {
                                e.printStackTrace();
                                Display.getCurrent().beep();
                            }
                            return Status.OK_STATUS;
                        }
                    };
                    opener.setSystem(false);
                    opener.setUser(true);
                    opener.schedule();
                }
            }
        }
    }
    return null;
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Position(org.eclipse.jface.text.Position) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) JsTranslationAdapter(org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter) IEditorPart(org.eclipse.ui.IEditorPart) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IProblem(org.eclipse.wst.jsdt.core.compiler.IProblem) Annotation(org.eclipse.jface.text.source.Annotation) AnnotationTypeLookup(org.eclipse.ui.texteditor.AnnotationTypeLookup) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ISelection(org.eclipse.jface.viewers.ISelection) UIJob(org.eclipse.ui.progress.UIJob) List(java.util.List) PartInitException(org.eclipse.ui.PartInitException) Job(org.eclipse.core.runtime.jobs.Job) UIJob(org.eclipse.ui.progress.UIJob)

Aggregations

IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)250 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)91 Node (org.w3c.dom.Node)63 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)57 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)44 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)43 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)38 List (java.util.List)35 ArrayList (java.util.ArrayList)34 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)30 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)30 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)27 Element (org.w3c.dom.Element)27 NodeList (org.w3c.dom.NodeList)23 BadLocationException (org.eclipse.jface.text.BadLocationException)22 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)22 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)20 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)19 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)18 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)18