Search in sources :

Example 1 with XMLUIPlugin

use of org.eclipse.wst.xml.ui.internal.XMLUIPlugin in project webtools.sourceediting by eclipse.

the class ToggleEditModeHandler method updateElement.

// Handlers that need to interact with the ui that the command came from
// need to use implement this method.
public void updateElement(UIElement element, Map parameters) {
    XMLUIPlugin xmluiPlugin = XMLUIPlugin.getDefault();
    if (xmluiPlugin == null)
        // probably shutting down
        return;
    IWorkbench workbench = xmluiPlugin.getWorkbench();
    if (workbench == null)
        return;
    IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
    if (activeWorkbenchWindow == null)
        return;
    IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
    if (activePage == null)
        return;
    IEditorPart editor = activePage.getActiveEditor();
    ITextEditor textEditor = null;
    if (editor instanceof ITextEditor)
        textEditor = (ITextEditor) editor;
    else if (editor != null) {
        Object o = editor.getAdapter(ITextEditor.class);
        if (o != null)
            textEditor = (ITextEditor) o;
    }
    if (textEditor != null) {
        IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
        IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
        if (model != null) {
            ModelQuery modelQuery;
            try {
                modelQuery = ModelQueryUtil.getModelQuery(model);
            } finally {
                model.releaseFromRead();
            }
            if (modelQuery != null) {
                setAppearanceForEditMode(modelQuery.getEditMode(), element);
            }
        }
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XMLUIPlugin(org.eclipse.wst.xml.ui.internal.XMLUIPlugin) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

IDocument (org.eclipse.jface.text.IDocument)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)1 XMLUIPlugin (org.eclipse.wst.xml.ui.internal.XMLUIPlugin)1