Search in sources :

Example 1 with EditNamespacePrefixDialog

use of org.eclipse.wst.xml.xpath.ui.internal.views.EditNamespacePrefixDialog in project webtools.sourceediting by eclipse.

the class PrefixHandler method execute.

/**
 * This will use the active editor, and try and retrieve a structured
 * model from it.  If successful, it setups the namespace edit dialog
 * to capture the namespace information.
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    XPathUIPlugin plugin = XPathUIPlugin.getDefault();
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    // suppress an NPE in the log (shouldn't happen with the enabledWhen rule)
    if (activeEditor == null)
        return null;
    IFile file = (IFile) activeEditor.getEditorInput().getAdapter(IFile.class);
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IDOMModel model = null;
    try {
        model = (IDOMModel) modelManager.getModelForRead(file);
        IDOMDocument document = model.getDocument();
        if (document != null) {
            List<NamespaceInfo> info = plugin.getNamespaceInfo(document);
            IPathEditorInput editorInput = (IPathEditorInput) activeEditor.getEditorInput();
            EditNamespacePrefixDialog dlg = new EditNamespacePrefixDialog(activeEditor.getSite().getShell(), editorInput.getPath());
            dlg.setNamespaceInfoList(info);
            if (SWT.OK == dlg.open()) {
            // Apply changes
            }
        }
    } catch (Exception ex) {
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
    return null;
}
Also used : IPathEditorInput(org.eclipse.ui.IPathEditorInput) IFile(org.eclipse.core.resources.IFile) XPathUIPlugin(org.eclipse.wst.xml.xpath.ui.internal.XPathUIPlugin) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IEditorPart(org.eclipse.ui.IEditorPart) EditNamespacePrefixDialog(org.eclipse.wst.xml.xpath.ui.internal.views.EditNamespacePrefixDialog) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

ExecutionException (org.eclipse.core.commands.ExecutionException)1 IFile (org.eclipse.core.resources.IFile)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IPathEditorInput (org.eclipse.ui.IPathEditorInput)1 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)1 NamespaceInfo (org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)1 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)1 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)1 XPathUIPlugin (org.eclipse.wst.xml.xpath.ui.internal.XPathUIPlugin)1 EditNamespacePrefixDialog (org.eclipse.wst.xml.xpath.ui.internal.views.EditNamespacePrefixDialog)1