com.founder.fix.fixwpe.wpeformdesigner.jst.pagedesigner.properties.FixPropertySourceProvider.java Source code

Java tutorial

Introduction

Here is the source code for com.founder.fix.fixwpe.wpeformdesigner.jst.pagedesigner.properties.FixPropertySourceProvider.java

Source

/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package com.founder.fix.fixwpe.wpeformdesigner.jst.pagedesigner.properties;

import java.util.Map;

import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.IPropertySourceProvider;
import org.eclipse.wst.html.core.internal.document.ElementStyleImpl;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.founder.fix.base.wpe.ConstantVariable;
import com.founder.fix.fixwpe.wpeformdesigner.XmlPropBufferProvider;
import com.founder.fix.fixwpe.wpeformdesigner.jst.pagedesigner.itemcreation.AbstractTagCreatorProvider;
import com.founder.fix.fixwpe.wpeformdesigner.wst.html.core.internal.document.FixElementStyleImpl;

/**
 * @author Fifteenth
 */
public class FixPropertySourceProvider implements IPropertySourceProvider {

    public String _propetyType;

    private ElementStyleImpl impl;

    /*
     *   @author Fifteenth
     *      1.impl:(model)
     *      2.fixImpl????
     */
    private FixElementStyleImpl fixImpl;
    private ElementStyleImpl implOld;

    /**
     * Constructor
     */
    public FixPropertySourceProvider(String propetyType) {

        this._propetyType = propetyType;
    }

    @SuppressWarnings("restriction")
    public IPropertySource getPropertySource(Object object) {
        /*
         *   @author Fifteenth
         *      1.objectgetPropertyValue??
         *   ?return null
         *      
         *      2.nullIPropertySource
         */
        if (!(object instanceof ElementStyleImpl)) {
            if (object instanceof FixSubAttributePropertySource) {
                /*
                 * @author Fifteenth
                 *      ??
                 */
                return (FixSubAttributePropertySource) object;
            } else {
                return null;
            }
        }

        impl = (ElementStyleImpl) object;
        if (!impl.equals(implOld)) {
            fixImpl = new FixElementStyleImpl(impl);
        } else {
            //
            return fixImpl.getPropertySource();
        }

        implOld = impl;

        // Tag?
        refleshTagProperty();

        // Model?
        refleshModelProperty();

        if (fixImpl.getPropertySource() == null) {
            /*
             *   @author Fifteenth
             *      1.FixPropertySource
             *   
             *
             *      2.?FixPropertySource
             *   ????
             */
            fixImpl.setPropertySource(new FixPropertySource(this, _propetyType, fixImpl, impl));
        }

        /*
         *   @author Fifteenth
         *      ?
         */
        return fixImpl.getPropertySource();
    }

    /**
     *   model
     */
    public void refleshModelProperty() {
        NodeList nodeList = implOld.getChildNodes();

        try {
            JSONObject attributeJsonModel = ModelCommet.getJson(nodeList, _propetyType,
                    ConstantVariable.fixAttributeNameSpace);
            /*
             *   @author Fifteenth
             *      model
             */
            if (fixImpl.getObjectJson() == null) {
                fixImpl.setObjectJson(new JSONObject());
                fixImpl.getObjectJson().put(ConstantVariable.childJsonAttributeModel, attributeJsonModel);
            } else {
                fixImpl.getObjectJson().put(ConstantVariable.childJsonAttributeModel, attributeJsonModel);
            }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /**
     *   tag
     */
    public void refleshTagProperty() {
        NamedNodeMap attributes = impl.getAttributes();
        // ?
        JSONObject attributeJsonTag = new JSONObject();
        for (int i = 0; i < attributes.getLength(); i++) {
            try {
                attributeJsonTag.put(attributes.item(i).getNodeName(), attributes.item(i).getNodeValue());

                if (fixImpl.getObjectJson() == null) {
                    fixImpl.setObjectJson(new JSONObject());
                    fixImpl.getObjectJson().put(ConstantVariable.childJsonAttributeTag, attributeJsonTag);
                } else {
                    fixImpl.getObjectJson().put(ConstantVariable.childJsonAttributeTag, attributeJsonTag);
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    public static Map getTagAttrMap(FixElementStyleImpl proImpl, String key_en) {
        Map<String, Object> tag_ttr_map;

        if (proImpl.getNodeName().equals(AbstractTagCreatorProvider.nodeName_INPUT)) {
            tag_ttr_map = XmlPropBufferProvider.getXMLProperty("input|text", key_en);
        } else {
            tag_ttr_map = XmlPropBufferProvider.getXMLProperty(proImpl.getAttribute("ComponentType"), key_en);
        }

        return tag_ttr_map;
    }
}