use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class StructuredModelManager method getModelManager.
/**
* Provides access to the instance of IModelManager. Returns null if model
* manager can not be created or is not valid (such as, when workbench is
* shutting down).
*
* @return IModelManager - returns the one model manager for structured
* models or null if the owning bundle is neither active nor
* starting.
*/
public static IModelManager getModelManager() {
boolean isReady = false;
IModelManager modelManager = null;
boolean interrupted = false;
try {
while (!isReady) {
Bundle localBundle = Platform.getBundle(SSECorePlugin.ID);
int state = localBundle.getState();
if (state == Bundle.ACTIVE) {
isReady = true;
// getInstance is a synchronized static method.
modelManager = ModelManagerImpl.getInstance();
} else if (state == Bundle.STARTING) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// ignore, just loop again
interrupted = true;
}
} else if (state == Bundle.STOPPING || state == Bundle.UNINSTALLED) {
isReady = true;
modelManager = null;
} else {
// not sure about other states, 'resolved', 'installed'
isReady = true;
modelManager = null;
}
}
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
return modelManager;
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class CSSColorPage method setupPicker.
/**
* setupPicker method comment.
*/
protected void setupPicker(StyledTextColorPicker picker) {
IModelManager mmanager = StructuredModelManager.getModelManager();
picker.setParser(mmanager.createStructuredDocumentFor(ContentTypeIdForCSS.ContentTypeID_CSS).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 StructuredDocumentToDOMUnitTests method testNodeDeletion.
/**
* Unit test -- tests basic parsing results of inserting a test string
* into an initial string.
*/
void testNodeDeletion() {
// String initialString =
// "<par><x>\ntextx\n</x>\n<y>\ntexty\n</y></par>";
// String initialString = "<par><x>textx</x><y>texty</y></par>";
// test cases for two text nodes left together (remove <b/>):
// first case works, second doesn't
// String initialString = "<a>a<b /></a>"; // -> <a>a</a>
// String initialString = "<a>a<b />b</a>"; // -> <a>ab</a>
// String initialString = getTestString1();
String initialString = getTestString2();
// print out what we always can
System.out.println();
System.out.println("----------------");
System.out.println("Test Node Deletion");
String outString = StringUtils.escape(initialString);
System.out.println("Initial String: " + outString);
// always start with fresh model
IStructuredDocument f = null;
IModelManager mm = StructuredModelManager.getModelManager();
try {
f = mm.createStructuredDocumentFor("dummy.xml", (InputStream) null, null);
} catch (IOException e) {
// do nothing, since dummy
}
//
// we'll listen to structuredDocument events to print out diagnostics
f.addDocumentChangedListener(this);
//
IDOMModel tree = new DOMModelImpl();
f.addDocumentChangingListener((IStructuredDocumentListener) tree);
// set text to structuredDocument (which updates tree)
f.setText(null, initialString);
// dump initial structuredDocument
Debug.dump(f);
// dump initial dom
DebugDocument.dump(tree.getDocument());
//
//
// makeChange1(tree);
makeChange2(f);
// display resulting text
System.out.println("resultString (from structuredDocument): ");
System.out.println(StringUtils.escape(f.getText()));
//
//
// dump post change structuredDocument
Debug.dump(f);
// dump post change DOM
DebugDocument.dump(tree.getDocument());
//
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestPageDirective method testBasicPD.
public void testBasicPD() throws IOException {
// First make (empty) structuredDocument
IModelManager modelManager = StructuredModelManager.getModelManager();
IStructuredModel model = modelManager.createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
assertTrue("model could not be created!", model != null);
// Now, assigning use a page directive, but leaving embedded type the same as default
model.getStructuredDocument().setText(this, "<%@ page contentType=\"text/html\" language=\"java\" %>");
PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((IDOMModel) model).getDocument().getAdapterFor(PageDirectiveAdapter.class);
String contentType = pageDirectiveAdapter.getContentType();
String language = pageDirectiveAdapter.getLanguage();
assertTrue("contentType should be html", "text/html".equals(contentType));
assertTrue("language should be java", "java".equals(language));
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestModelsFromFiles method doTestNotEmptyDocument.
/**
* @param string
* @param class1
* @param class2
* @throws CoreException
* @throws IOException
* @throws ResourceInUse
* @throws ResourceAlreadyExists
*/
private void doTestNotEmptyDocument(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
String contents = null;
IModelManager modelManager = StructuredModelManager.getModelManager();
IFile file = (IFile) fTestProject.findMember(filePath);
if (file == null) {
file = fTestProject.getFile(filePath);
}
IStructuredDocument document = modelManager.createStructuredDocumentFor(file);
assertNotNull(document);
assertTrue("wrong class of document", expectedDocumentClass.isInstance(document));
IDocumentPartitioner setupPartitioner = null;
if (Utilities.contains(expectedDocumentClass.getInterfaces(), IDocumentExtension3.class)) {
setupPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
} else {
setupPartitioner = document.getDocumentPartitioner();
}
assertTrue("wrong partitioner in document.", expectedPartioner.isInstance(setupPartitioner));
contents = document.get();
assertNotNull("contents were null", contents);
assertTrue("contents were empty", contents.length() > 0);
}
Aggregations