use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class TestStructuredPartitionerHTML method testGetPartitionType.
public void testGetPartitionType() {
IStructuredModel model = null;
try {
model = getModelForEdit("testfiles/html/example01.xml");
if (model != null) {
IStructuredDocument sDoc = model.getStructuredDocument();
assertTrue("sDoc implementation not instance of IDocumentExtension3", sDoc instanceof IDocumentExtension3);
IDocumentPartitioner partitioner = ((IDocumentExtension3) sDoc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
assertTrue("paritioner doesn't implement IStructuredTextPartitioner", partitioner instanceof IStructuredTextPartitioner);
IStructuredTextPartitioner stp = (IStructuredTextPartitioner) partitioner;
String defaultPartitionType = stp.getDefaultPartitionType();
assertTrue("wrong default partition type was: [" + defaultPartitionType + "] should be: [" + IXMLPartitions.XML_DEFAULT + "]", defaultPartitionType.equals(IXMLPartitions.XML_DEFAULT));
} else {
assertTrue("could not retrieve structured model", false);
}
} finally {
if (model != null)
model.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class TestStructuredPartitionerHTML method testDisconnectConnect.
public void testDisconnectConnect() {
IStructuredModel model = null;
try {
model = getModelForEdit("testfiles/html/example01.xml");
if (model != null) {
IStructuredDocument sDoc = model.getStructuredDocument();
assertTrue("sDoc implementation not instance of IDocumentExtension3", sDoc instanceof IDocumentExtension3);
IDocumentPartitioner partitioner = ((IDocumentExtension3) sDoc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
assertTrue("partitioner doesn't implement IStructuredTextPartitioner", partitioner instanceof IStructuredTextPartitioner);
IStructuredTextPartitioner stp = (IStructuredTextPartitioner) partitioner;
assertNotNull("partitioner was null for sDoc:" + sDoc, partitioner);
try {
stp.disconnect();
} catch (Exception e) {
assertTrue("problem disconnecting w/:" + sDoc + "/n" + e, false);
}
try {
stp.connect(sDoc);
} catch (Exception e) {
assertTrue("problem connecting w/:" + sDoc + "/n" + e, false);
}
} else {
assertTrue("could not retrieve structured model", false);
}
} finally {
if (model != null)
model.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class TestJSPContentFormatter method formatAndAssertEquals.
private void formatAndAssertEquals(String beforePath, String afterPath, boolean resetPreferences) throws UnsupportedEncodingException, IOException, CoreException {
IStructuredModel beforeModel = null, afterModel = null;
try {
beforeModel = getModelForEdit(beforePath);
assertNotNull("could not retrieve structured model for : " + beforePath, beforeModel);
afterModel = getModelForEdit(afterPath);
assertNotNull("could not retrieve structured model for : " + afterPath, afterModel);
if (resetPreferences) {
resetPreferencesToDefault();
}
SourceViewerConfiguration configuration = (SourceViewerConfiguration) ExtendedConfigurationBuilder.getInstance().getConfiguration(ExtendedConfigurationBuilder.SOURCEVIEWERCONFIGURATION, "org.eclipse.jst.jsp.core.jspsource");
IContentFormatterExtension formatter = (IContentFormatterExtension) configuration.getContentFormatter(null);
IDocument document = beforeModel.getStructuredDocument();
Region region = new Region(0, document.getLength());
fContext.setProperty(FormattingContextProperties.CONTEXT_REGION, region);
formatter.format(document, fContext);
ByteArrayOutputStream formattedBytes = new ByteArrayOutputStream();
// "beforeModel" should now be
beforeModel.save(formattedBytes);
// after the formatter
ByteArrayOutputStream afterBytes = new ByteArrayOutputStream();
afterModel.save(afterBytes);
String expectedContents = new String(afterBytes.toByteArray(), UTF_8);
expectedContents = StringUtils.replace(expectedContents, "\r\n", "\r");
expectedContents = StringUtils.replace(expectedContents, "\r", "\n");
String actualContents = new String(formattedBytes.toByteArray(), UTF_8);
actualContents = StringUtils.replace(actualContents, "\r\n", "\r");
actualContents = StringUtils.replace(actualContents, "\r", "\n");
assertTrue(onlyWhiteSpaceDiffers(expectedContents, actualContents));
assertEquals("Formatted document differs from the expected.", expectedContents, actualContents);
} finally {
if (beforeModel != null)
beforeModel.releaseFromEdit();
if (afterModel != null)
afterModel.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class StructuredTextViewer method doModelOperation.
/**
* Perform the operation under a model change event
* @param operation the operation to perform
*/
private void doModelOperation(int operation) {
IStructuredModel model = StructuredModelManager.getModelManager().getModelForRead((IStructuredDocument) getDocument());
model.aboutToChangeModel();
try {
super.doOperation(operation);
} finally {
model.changedModel();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class CleanupAction method run.
public void run() {
if (getTextEditor() instanceof StructuredTextEditor) {
final StructuredTextEditor editor = (StructuredTextEditor) getTextEditor();
Dialog cleanupDialog = getCleanupDialog(editor.getSite().getShell());
if (cleanupDialog != null) {
if (cleanupDialog.open() == Window.OK) {
// setup runnable
Runnable runnable = new Runnable() {
public void run() {
IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor();
if (cleanupProcessor != null)
cleanupProcessor.cleanupModel(editor.getModel());
}
};
// TODO: make independent of 'model'.
IStructuredModel model = editor.getModel();
if (model != null) {
try {
// begin recording
ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
// $NON-NLS-1$ //$NON-NLS-2$
model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_, SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength());
// tell the model that we are about to make a big
// model change
model.aboutToChangeModel();
// run
BusyIndicator.showWhile(editor.getTextViewer().getControl().getDisplay(), runnable);
} finally {
// tell the model that we are done with the big
// model
// change
model.changedModel();
// end recording
ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
model.endRecording(this, selection.getOffset(), selection.getLength());
}
}
}
}
}
}
Aggregations