FileDocCategorySizeDatePackage
XmlEditor.javaAPI DocAndroid 1.5 API6684Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.xml

XmlEditor

public class XmlEditor extends com.android.ide.eclipse.editors.AndroidEditor
Multi-page form editor for /res/xml XML files.

Fields Summary
public static final String
ID
private com.android.ide.eclipse.editors.uimodel.UiDocumentNode
mUiRootNode
Root node of the UI element hierarchy
Constructors Summary
public XmlEditor()
Creates the form editor for resources XML files.


                 
      
        super();
    
Methods Summary
public static booleancanHandleFile(org.eclipse.core.resources.IFile file)
Indicates if this is a file that this {@link XmlEditor} can handle.

The {@link XmlEditor} can handle XML files that have a or root XML element with the adequate xmlns:android attribute.

return
True if the {@link XmlEditor} can handle that file.

        // we need the target of the file's project to access the descriptors.
        IProject project = file.getProject();
        IAndroidTarget target = Sdk.getCurrent().getTarget(project);
        if (target != null) {
            AndroidTargetData data = Sdk.getCurrent().getTargetData(target);
        
            FirstElementParser.Result result = FirstElementParser.parse(
                    file.getLocation().toOSString(),
                    SdkConstants.NS_RESOURCES);
            
            if (result != null) {
                String name = result.getElement(); 
                if (name != null && result.getXmlnsPrefix() != null) {
                    DocumentDescriptor desc = data.getXmlDescriptors().getDescriptor();
                    for (ElementDescriptor elem : desc.getChildren()) {
                        if (elem.getXmlName().equals(name)) {
                            // This is an element that this document can handle
                            return true;
                        }
                    }
                }
            }
        }
        
        return false;
    
protected voidcreateFormPages()
Create the various form pages.

        try {
            addPage(new XmlTreePage(this));
        } catch (PartInitException e) {
            AdtPlugin.log(e, "Error creating nested page"); //$NON-NLS-1$
        }
        
    
public com.android.ide.eclipse.editors.uimodel.UiDocumentNodegetUiRootNode()
Returns the root node of the UI element hierarchy, which here is the document node.

        return mUiRootNode;
    
protected voidinitUiRootNode(boolean force)
Creates the initial UI Root Node, including the known mandatory elements.

param
force if true, a new UiRootNode is recreated even if it already exists.

        // The root UI node is always created, even if there's no corresponding XML node.
        if (mUiRootNode == null || force) {
            Document doc = null;
            if (mUiRootNode != null) {
                doc = mUiRootNode.getXmlDocument();
            }

            // get the target data from the opened file (and its project)
            AndroidTargetData data = getTargetData();

            DocumentDescriptor desc;
            if (data == null) {
                desc = new DocumentDescriptor("temp", null /*children*/);
            } else {
                desc = data.getXmlDescriptors().getDescriptor();
            }

            mUiRootNode = (UiDocumentNode) desc.createUiNode();
            mUiRootNode.setEditor(this);

            onDescriptorsChanged(doc);
        }
    
public booleanisSaveAsAllowed()
Returns whether the "save as" operation is supported by this editor.

Save-As is a valid operation for the ManifestEditor since it acts on a single source file.

see
IEditorPart

        return true;
    
private voidonDescriptorsChanged(org.w3c.dom.Document document)
Reloads the UI manifest node from the XML, and calls the pages to update.

        if (document != null) {
            mUiRootNode.loadFromXmlNode(document);
        } else {
            mUiRootNode.reloadFromXmlNode(mUiRootNode.getXmlNode());
        }
    
protected voidsetInput(org.eclipse.ui.IEditorInput input)

        super.setInput(input);
        if (input instanceof FileEditorInput) {
            FileEditorInput fileInput = (FileEditorInput) input;
            IFile file = fileInput.getFile();
            setPartName(String.format("%1$s", file.getName()));
        }
    
protected voidxmlModelChanged(org.w3c.dom.Document xml_doc)
Processes the new XML Model, which XML root node is given.

param
xml_doc The XML document, if available, or null if none exists.

        // init the ui root on demand
        initUiRootNode(false /*force*/);

        mUiRootNode.loadFromXmlNode(xml_doc);
        
        super.xmlModelChanged(xml_doc);