use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestXSLLineStyleProvider method loadXSLFile.
protected void loadXSLFile() throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
IModelManager modelManager = StructuredModelManager.getModelManager();
model = modelManager.getNewModelForEdit(file, true);
document = model.getStructuredDocument();
IDocumentPartitioner partitioner = defaultPartitioner.newInstance();
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class XMLQuickAssistProcessor method getNodeAt.
/**
* Returns the closest IndexedRegion for the offset and viewer allowing
* for differences between viewer offsets and model positions. note: this
* method returns an IndexedRegion for read only
*
* @param viewer
* the viewer whose document is used to compute the proposals
* @param documentOffset
* an offset within the document for which completions should
* be computed
* @return an IndexedRegion
*/
private IndexedRegion getNodeAt(ITextViewer viewer, int documentOffset) {
// copied from ContentAssistUtils.getNodeAt()
if (viewer == null)
return null;
IndexedRegion node = null;
IModelManager mm = StructuredModelManager.getModelManager();
IStructuredModel model = null;
if (mm != null)
model = mm.getExistingModelForRead(viewer.getDocument());
try {
if (model != null) {
int lastOffset = documentOffset;
node = model.getIndexedRegion(documentOffset);
while (node == null && lastOffset >= 0) {
lastOffset--;
node = model.getIndexedRegion(lastOffset);
}
}
} finally {
if (model != null)
model.releaseFromRead();
}
return node;
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestStructuredModel method getTestModel.
/**
* Be sure to release any models obtained from this method.
*/
IStructuredModel getTestModel() throws IOException, CoreException {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(fProjectName);
IFile iFile = (IFile) project.findMember("/files/simple.xml");
// fProjectName + "/files/simple.xml"
IStructuredModel model = null;
IModelManager modelManager = StructuredModelManager.getModelManager();
model = modelManager.getModelForEdit(iFile);
return model;
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestStructuredPartitionerXML method doTimedComputePartitioningTest.
/**
* Compute the partitions for the given filename using the default partitioner
* for that file type.
*
* @param filename
* @return int
* @throws IOException
* @throws BadLocationException
*/
protected int doTimedComputePartitioningTest(String filename) throws IOException, BadLocationException {
IModelManager modelManager = StructuredModelManager.getModelManager();
InputStream inStream = getClass().getResourceAsStream(filename);
if (inStream == null)
inStream = new NullStream();
IStructuredModel model = modelManager.getModelForEdit(filename, inStream, null);
IStructuredDocument structuredDocument = model.getStructuredDocument();
if (DEBUG_PRINT_RESULT && useFormatter) {
double baseTen = Math.log(10);
formatter.setMinimumIntegerDigits((int) (Math.log(structuredDocument.getLength()) / baseTen) + 1);
formatter.setGroupingUsed(false);
}
long startTime = System.currentTimeMillis();
partitions = structuredDocument.computePartitioning(0, structuredDocument.getLength());
long endTime = System.currentTimeMillis();
if (DEBUG_PRINT_RESULT) {
String contents = null;
System.out.println("\nfilename: " + filename);
System.out.println("Time to compute " + partitions.length + ": " + (endTime - startTime) + " (msecs)");
for (int i = 0; i < partitions.length; i++) {
try {
contents = structuredDocument.get(partitions[i].getOffset(), partitions[i].getLength());
} catch (BadLocationException e) {
contents = "*error*";
}
if (useFormatter)
System.out.println(formatter.format(partitions[i].getOffset()) + ":" + formatter.format(partitions[i].getLength()) + " - " + partitions[i].getType() + " [" + StringUtils.escape(contents) + "]");
else
System.out.println(partitions[i] + " [" + StringUtils.escape(contents) + "]");
}
}
checkSeams();
model.releaseFromEdit();
inStream.close();
if (partitions == null)
return -1;
return partitions.length;
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestStructuredPartitionerXML method doComputePartitioningTest.
/**
* Compute the partitions for the given filename using the default partitioner
* for that file type.
*
* @param filename
* @return int
* @throws IOException
* @throws BadLocationException
*/
protected int doComputePartitioningTest(String filename) throws IOException, BadLocationException {
IModelManager modelManager = StructuredModelManager.getModelManager();
InputStream inStream = getClass().getResourceAsStream(filename);
if (inStream == null)
inStream = new NullStream();
IStructuredModel model = modelManager.getModelForEdit(filename, inStream, null);
IStructuredDocument structuredDocument = model.getStructuredDocument();
if (DEBUG_PRINT_RESULT && useFormatter) {
double baseTen = Math.log(10);
formatter.setMinimumIntegerDigits((int) (Math.log(structuredDocument.getLength()) / baseTen) + 1);
formatter.setGroupingUsed(false);
}
partitions = structuredDocument.computePartitioning(0, structuredDocument.getLength());
if (DEBUG_PRINT_RESULT) {
String contents = null;
System.out.println("\nfilename: " + filename);
for (int i = 0; i < partitions.length; i++) {
try {
contents = structuredDocument.get(partitions[i].getOffset(), partitions[i].getLength());
} catch (BadLocationException e) {
contents = "*error*";
}
if (useFormatter)
System.out.println(formatter.format(partitions[i].getOffset()) + ":" + formatter.format(partitions[i].getLength()) + " - " + partitions[i].getType() + " [" + StringUtils.escape(contents) + "]");
else
System.out.println(partitions[i] + " [" + StringUtils.escape(contents) + "]");
}
}
checkSeams();
model.releaseFromEdit();
inStream.close();
if (partitions == null)
return -1;
return partitions.length;
}
Aggregations