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;
}
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;
}
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);
}
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();
}
}
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;
}
Aggregations