Search in sources :

Example 1 with IModelHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project liferay-ide by liferay.

the class AlloyJSPDocumentFactory method createDocument.

@Override
public IDocument createDocument() {
    IModelHandler handler = null;
    IContentType contentType = Platform.getContentTypeManager().getContentType("com.liferay.ide.alloy.core.alloyjspsource");
    while ((handler == null) && !IContentTypeManager.CT_TEXT.equals(contentType.getId())) {
        handler = ModelHandlerRegistry.getInstance().getHandlerForContentTypeId(contentType.getId());
        contentType = contentType.getBaseType();
    }
    if (handler != null) {
        return handler.getDocumentLoader().createNewStructuredDocument();
    } else {
        return new JobSafeStructuredDocument();
    }
}
Also used : IContentType(org.eclipse.core.runtime.content.IContentType) JobSafeStructuredDocument(org.eclipse.wst.sse.core.internal.text.JobSafeStructuredDocument) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 2 with IModelHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.

the class ModelManagerImpl method createNewStructuredDocumentFor.

/**
 * Factory method, since a proper IStructuredDocument must have a proper
 * parser assigned. Note: its assume that IFile does not actually exist as
 * a resource yet. If it does, ResourceAlreadyExists exception is thrown.
 * If the resource does already exist, then createStructuredDocumentFor is
 * the right API to use.
 *
 * @throws ResourceInUse
 */
public IStructuredDocument createNewStructuredDocumentFor(IFile iFile) throws ResourceAlreadyExists, IOException, CoreException {
    if (iFile.exists()) {
        throw new ResourceAlreadyExists(iFile.getFullPath().toOSString());
    }
    // Will reconsider in future version
    // String id = calculateId(iFile);
    // if (isResourceInUse(id)) {
    // throw new ResourceInUse(iFile.getFullPath().toOSString());
    // }
    IDocumentLoader loader = null;
    IModelHandler handler = calculateType(iFile);
    loader = handler.getDocumentLoader();
    // for this API, "createNew" we assume the IFile does not exist yet
    // as checked above, so just create empty document.
    IStructuredDocument result = (IStructuredDocument) loader.createNewStructuredDocument();
    return result;
}
Also used : IDocumentLoader(org.eclipse.wst.sse.core.internal.document.IDocumentLoader) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ResourceAlreadyExists(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 3 with IModelHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.

the class ModelManagerImpl method reinitialize.

/*
	 * @see IModelManager#reinitialize(IStructuredModel)
	 */
public IStructuredModel reinitialize(IStructuredModel model) {
    // getHandler (assume its the "new one")
    IModelHandler handler = model.getModelHandler();
    // getLoader for that new one
    IModelLoader loader = handler.getModelLoader();
    // ask it to reinitialize
    model = loader.reinitialize(model);
    // its embedded content checking and initialization
    return model;
}
Also used : IModelLoader(org.eclipse.wst.sse.core.internal.provisional.IModelLoader) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 4 with IModelHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.

the class ModelManagerImpl method calculateType.

private IModelHandler calculateType(String filename, InputStream inputStream) throws IOException {
    ModelHandlerRegistry cr = getModelHandlerRegistry();
    IModelHandler cd = cr.getHandlerFor(filename, inputStream);
    return cd;
}
Also used : ModelHandlerRegistry(org.eclipse.wst.sse.core.internal.modelhandler.ModelHandlerRegistry) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 5 with IModelHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler in project webtools.sourceediting by eclipse.

the class ModelManagerImpl method getModelForEdit.

public IStructuredModel getModelForEdit(String id, InputStream inputStream, URIResolver resolver) throws IOException {
    if (id == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("Program Error: id may not be null");
    }
    IStructuredModel result = null;
    InputStream istream = Utilities.getMarkSupportedStream(inputStream);
    IModelHandler handler = calculateType(id, istream);
    if (handler != null) {
        result = _commonCreateModel(istream, id, handler, resolver, EDIT, null, null);
    } else {
        // $NON-NLS-1$
        Logger.log(Logger.INFO, "no model handler found for id");
    }
    return result;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Aggregations

IModelHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)41 ModelHandlerRegistry (org.eclipse.wst.sse.core.internal.modelhandler.ModelHandlerRegistry)14 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)9 CoreException (org.eclipse.core.runtime.CoreException)6 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 IContentType (org.eclipse.core.runtime.content.IContentType)5 IModelLoader (org.eclipse.wst.sse.core.internal.provisional.IModelLoader)5 InputStream (java.io.InputStream)4 IFile (org.eclipse.core.resources.IFile)4 IDocumentLoader (org.eclipse.wst.sse.core.internal.document.IDocumentLoader)4 ResourceInUse (org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)4 IOException (java.io.IOException)3 IProject (org.eclipse.core.resources.IProject)3 BasicStructuredDocument (org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument)3 URIResolver (org.eclipse.wst.sse.core.internal.util.URIResolver)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 IDocument (org.eclipse.jface.text.IDocument)2 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)2