FileDocCategorySizeDatePackage
ResourcesEditor.javaAPI DocAndroid 1.5 API5626Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.resources

ResourcesEditor

public class ResourcesEditor extends com.android.ide.eclipse.editors.AndroidEditor
Multi-page form editor for /res/values and /res/drawable XML files.

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



                 
      
        super();
    
Methods Summary
protected voidcreateFormPages()
Create the various form pages.

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

        return mUiResourcesNode;
    
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 manifest UI node is always created, even if there's no corresponding XML node.
        if (mUiResourcesNode == null || force) {
            ElementDescriptor resources_desc =
                    ResourcesDescriptors.getInstance().getElementDescriptor();   
            mUiResourcesNode = resources_desc.createUiNode();
            mUiResourcesNode.setEditor(this);
            
            onDescriptorsChanged();
        }
    
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()

        // nothing to be done, as the descriptor are static for now.
        // FIXME Update when the descriptors are not static
    
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*/);

        mUiResourcesNode.setXmlDocument(xml_doc);
        if (xml_doc != null) {
            ElementDescriptor resources_desc =
                    ResourcesDescriptors.getInstance().getElementDescriptor();
            try {
                XPath xpath = AndroidXPathFactory.newXPath();
                Node node = (Node) xpath.evaluate("/" + resources_desc.getXmlName(),  //$NON-NLS-1$
                        xml_doc,
                        XPathConstants.NODE);
                assert node != null && node.getNodeName().equals(resources_desc.getXmlName());

                // Refresh the manifest UI node and all its descendants 
                mUiResourcesNode.loadFromXmlNode(node);
            } catch (XPathExpressionException e) {
                AdtPlugin.log(e, "XPath error when trying to find '%s' element in XML.", //$NON-NLS-1$
                        resources_desc.getXmlName());
            }
        }
        
        super.xmlModelChanged(xml_doc);