use of org.eclipse.wst.sse.ui.internal.IModelProvider in project webtools.sourceediting by eclipse.
the class StructuredTextEditor method tryToGetModel.
/**
* <p>Attempts to get the {@link IStructuredModel} for the given {@link IEditorInput}</p>
*
* @param input the {@link IEditorInput} to try and get the {@link IStructuredModel} for
*
* @return The {@link IStructuredModel} associated with the given {@link IEditorInput} or
* <code>null</code> if no associated {@link IStructuredModel} could be found.
*/
private IStructuredModel tryToGetModel(IEditorInput input) {
IStructuredModel model = null;
IDocument newDocument = getDocumentProvider().getDocument(input);
if (newDocument instanceof IExecutionDelegatable) {
((IExecutionDelegatable) newDocument).setExecutionDelegate(new EditorExecutionContext(this));
}
// if we have a Model provider, get the model from it
if (getDocumentProvider() instanceof IModelProvider) {
model = ((IModelProvider) getDocumentProvider()).getModel(getEditorInput());
if (!model.isShared()) {
EditorModelUtil.addFactoriesTo(model);
}
} else if (newDocument instanceof IStructuredDocument) {
// corresponding releaseFromEdit occurs in dispose()
model = StructuredModelManager.getModelManager().getModelForEdit((IStructuredDocument) newDocument);
EditorModelUtil.addFactoriesTo(model);
}
return model;
}
use of org.eclipse.wst.sse.ui.internal.IModelProvider in project webtools.sourceediting by eclipse.
the class StructuredTextEditor method getModel.
/**
* Returns this editor's StructuredModel.
* <p>
* Not API. Will be removed in the future.
* </p>
*
* @return returns this editor's IStructuredModel
* @deprecated - This method allowed for uncontrolled access to the model
* instance and will be removed in the future. It is
* recommended that the current document provider be asked for
* the current document and the IModelManager then asked for
* the corresponding model with
* getExistingModelFor*(IDocument). Supported document
* providers ensure that the document maps to a shared
* structured model.
*/
public IStructuredModel getModel() {
IDocumentProvider documentProvider = getDocumentProvider();
if (documentProvider == null) {
// this indicated an error in startup sequence
// $NON-NLS-1$ //$NON-NLS-2$
Logger.trace(getClass().getName(), "Program Info Only: document provider was null when model requested");
}
// Remember if we entered this method without a model existing
boolean initialModelNull = (fStructuredModel == null);
if (fStructuredModel == null && documentProvider != null) {
// CODE PATH
if (documentProvider instanceof IModelProvider) {
fStructuredModel = ((IModelProvider) documentProvider).getModel(getEditorInput());
fisReleased = false;
} else {
IDocument doc = documentProvider.getDocument(getEditorInput());
if (doc instanceof IStructuredDocument) {
/*
* Called in this manner because getExistingModel can skip
* some calculations always performed in getModelForEdit
*/
IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(doc);
if (model == null) {
model = StructuredModelManager.getModelManager().getModelForEdit((IStructuredDocument) doc);
}
fStructuredModel = model;
fisReleased = false;
}
}
EditorModelUtil.addFactoriesTo(fStructuredModel);
if (initialModelNull && fStructuredModel != null) {
/*
* DMW: 9/1/2002 -- why is update called here? No change has
* been indicated? I'd like to remove, but will leave for now
* to avoid breaking this hack. Should measure/breakpoint to
* see how large the problem is. May cause performance
* problems.
*
* DMW: 9/8/2002 -- not sure why this was here initially, but
* the intent/hack must have been to call update if this was
* the first time fStructuredModel was set. So, I added the
* logic to check for that "first time" case. It would appear
* we don't really need. may remove in future when can test
* more.
*/
update();
}
}
return fStructuredModel;
}
use of org.eclipse.wst.sse.ui.internal.IModelProvider in project webtools.sourceediting by eclipse.
the class StructuredTextEditor method doSetInput.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetInput(org.eclipse.ui.IEditorInput)
*/
protected void doSetInput(IEditorInput input) throws CoreException {
IEditorInput oldInput = getEditorInput();
if (oldInput != null) {
IDocument olddoc = getDocumentProvider().getDocument(oldInput);
if (olddoc != null && olddoc instanceof IExecutionDelegatable) {
((IExecutionDelegatable) olddoc).setExecutionDelegate(null);
}
}
if (fStructuredModel != null && !(getDocumentProvider() instanceof IModelProvider)) {
fStructuredModel.releaseFromEdit();
}
// attempt to get the model for the given input
super.doSetInput(input);
IStructuredModel model = tryToGetModel(input);
/* if could not get the model prompt user to update content type
* if preferences allow, then try to get model again
*/
if (model == null && SSEUIPlugin.getDefault().getPreferenceStore().getBoolean(EditorPreferenceNames.SHOW_UNKNOWN_CONTENT_TYPE_MSG)) {
if (fInitializationData != null && fInitializationData.containsKey(PREFERRED_CONTENT_TYPE_WHEN_UNSUPPORTED)) {
IContentType contentType = Platform.getContentTypeManager().getContentType(fInitializationData.get(PREFERRED_CONTENT_TYPE_WHEN_UNSUPPORTED).toString());
if (contentType != null && !StringUtils.contains(contentType.getFileSpecs(IContentTypeSettings.FILE_NAME_SPEC), input.getName(), false)) {
/*
* Display a dialog informing user of unknown content type,
* offering to update preferences for them
*/
UnknownContentTypeDialog2 dialog = new UnknownContentTypeDialog2(getSite().getShell(), SSEUIPlugin.getDefault().getPreferenceStore(), input.getName(), contentType);
dialog.open();
}
} else {
/*
* Display a dialog informing user of unknown content type,
* giving them chance to update preferences
*/
UnknownContentTypeDialog dialog = new UnknownContentTypeDialog(getSite().getShell(), SSEUIPlugin.getDefault().getPreferenceStore(), EditorPreferenceNames.SHOW_UNKNOWN_CONTENT_TYPE_MSG);
dialog.open();
}
// try to get model again in hopes user updated preferences
super.doSetInput(input);
model = tryToGetModel(input);
// still could not get the model to open this editor, so log
if (model == null) {
logUnexpectedDocumentKind(input);
}
}
if (fStructuredModel != null || model != null) {
setModel(model);
}
if (getInternalModel() != null) {
updateEditorControlsForContentType(getInternalModel().getContentTypeIdentifier());
} else {
updateEditorControlsForContentType(null);
}
// start editor with smart insert mode
setInsertMode(SMART_INSERT);
}
Aggregations