Search in sources :

Example 1 with UnknownContentTypeDialog2

use of org.eclipse.wst.sse.ui.internal.UnknownContentTypeDialog2 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);
}
Also used : IExecutionDelegatable(org.eclipse.wst.sse.core.internal.text.IExecutionDelegatable) IContentType(org.eclipse.core.runtime.content.IContentType) UnknownContentTypeDialog2(org.eclipse.wst.sse.ui.internal.UnknownContentTypeDialog2) IModelProvider(org.eclipse.wst.sse.ui.internal.IModelProvider) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) UnknownContentTypeDialog(org.eclipse.wst.sse.ui.internal.UnknownContentTypeDialog) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

IContentType (org.eclipse.core.runtime.content.IContentType)1 IDocument (org.eclipse.jface.text.IDocument)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 IExecutionDelegatable (org.eclipse.wst.sse.core.internal.text.IExecutionDelegatable)1 IModelProvider (org.eclipse.wst.sse.ui.internal.IModelProvider)1 UnknownContentTypeDialog (org.eclipse.wst.sse.ui.internal.UnknownContentTypeDialog)1 UnknownContentTypeDialog2 (org.eclipse.wst.sse.ui.internal.UnknownContentTypeDialog2)1