use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class ViewerTestXML method setupViewerForNew.
/**
* Set up source viewer with a new document & configure it
*/
private void setupViewerForNew() {
// if was following selection, stop
stopFollowSelection();
IModelManager modelManager = StructuredModelManager.getModelManager();
IDocument doc = modelManager.createStructuredDocumentFor(ContentTypeIdForXML.ContentTypeID_XML);
doc.set(DEFAULT_VIEWER_CONTENTS);
fSourceViewer.setDocument(doc);
// need to reconfigure after set document just so highlighter works
fSourceViewer.configure(fConfig);
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestOpenEditorXML method testBug151069.
/**
* Test structured document is reloaded on resource change
*/
public void testBug151069() {
IDocument doc = fEditor.getAdapter(IDocument.class);
doc.set("<html><body><h1>Title</h1></body></html>");
// set h1 to readonly
IModelManager modelManager = StructuredModelManager.getModelManager();
IDOMModel model = null;
try {
model = (IDOMModel) modelManager.getExistingModelForEdit(doc);
if (model != null) {
NodeList nl = model.getDocument().getElementsByTagName("h1");
IDOMElement h1 = (IDOMElement) nl.item(0);
h1.setEditable(false, true);
}
} finally {
if (model != null)
model.releaseFromEdit();
}
String newContent = "new content";
((IDocumentExtension4) doc).set(newContent, fFile.getModificationStamp());
assertEquals("Set contents in document with read only regions failed", newContent, doc.get());
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class XMLColorPage method setupPicker.
protected void setupPicker(StyledTextColorPicker picker) {
IModelManager mmanager = StructuredModelManager.getModelManager();
picker.setParser(mmanager.createStructuredDocumentFor(ContentTypeIdForXML.ContentTypeID_XML).getParser());
Dictionary descriptions = new Hashtable();
initDescriptions(descriptions);
Dictionary contextStyleMap = new Hashtable();
initContextStyleMap(contextStyleMap);
ArrayList styleList = new ArrayList();
initStyleList(styleList);
picker.setContextStyleMap(contextStyleMap);
picker.setDescriptions(descriptions);
picker.setStyleList(styleList);
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class NamespaceSelectionAdapter method widgetSelected.
@Override
public void widgetSelected(SelectionEvent e) {
IEditorPart activeEditor = Workbench.getInstance().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
IFile file = (IFile) activeEditor.getEditorInput().getAdapter(IFile.class);
IModelManager modelManager = StructuredModelManager.getModelManager();
IDOMModel model = null;
try {
model = (IDOMModel) modelManager.getModelForRead(file);
IDOMDocument document = model.getDocument();
if (document != null) {
List<NamespaceInfo> info = createNamespaceInfo(document);
IPathEditorInput editorInput = (IPathEditorInput) activeEditor.getEditorInput();
EditNamespacePrefixDialog dlg = new EditNamespacePrefixDialog(activeEditor.getSite().getShell(), editorInput.getPath());
dlg.setNamespaceInfoList(info);
if (SWT.OK == dlg.open()) {
// Apply changes
}
}
} catch (Exception ex) {
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class PrefixHandler method execute.
/**
* This will use the active editor, and try and retrieve a structured
* model from it. If successful, it setups the namespace edit dialog
* to capture the namespace information.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
XPathUIPlugin plugin = XPathUIPlugin.getDefault();
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
// suppress an NPE in the log (shouldn't happen with the enabledWhen rule)
if (activeEditor == null)
return null;
IFile file = (IFile) activeEditor.getEditorInput().getAdapter(IFile.class);
IModelManager modelManager = StructuredModelManager.getModelManager();
IDOMModel model = null;
try {
model = (IDOMModel) modelManager.getModelForRead(file);
IDOMDocument document = model.getDocument();
if (document != null) {
List<NamespaceInfo> info = plugin.getNamespaceInfo(document);
IPathEditorInput editorInput = (IPathEditorInput) activeEditor.getEditorInput();
EditNamespacePrefixDialog dlg = new EditNamespacePrefixDialog(activeEditor.getSite().getShell(), editorInput.getPath());
dlg.setNamespaceInfoList(info);
if (SWT.OK == dlg.open()) {
// Apply changes
}
}
} catch (Exception ex) {
} finally {
if (model != null) {
model.releaseFromRead();
}
}
return null;
}
Aggregations