我想通过Eclipse RAP创建高图小部件,我按照“RAP /自定义小部件常见问题解答”,但有错误?

时间:2015-07-10 02:18:20

标签: eclipse-rap

我想通过Eclipse RAP创建一些高清小部件,我按照这样的官方指南

handlejs:

var CKEDITOR_BASEPATH = "rwt-resources/";
(function(){
    'use strict';
    rap.registerTypeHandler( "rap.sunline.HighCharts", {
       factory : function( properties ) {
            var parent = rap.getObject( properties.parent );
            // var element = document.createElement( "div" );
            // parent.append( element );
            // $(element).html("askldfjaskljdk");
            return {};
       }
    });
}());

widget.java:

public class HightChartComposite extends Composite {

    private static final String RESOURCES_PATH = "resources/";
    private static final String REGISTER_PATH = "hightcharts/";

    private static final String[] RESOURCE_FILES = { "jquery-2.1.0.min.js", "highcharts.js","ChartPaintListener.js" };
    private static final String REMOTE_TYPE = "rap.sunline.HightCharts";

    private final RemoteObject remoteObject;

    private final OperationHandler operationHandler = new AbstractOperationHandler() {
        @Override
        public void handleSet(JsonObject properties) {
//          JsonValue textValue = properties.get("text");
//          if (textValue != null) {
//              text = textValue.asString();
//          }
        }
    };

    public HightChartComposite(Composite parent, int style) {
        super(parent, style);
        registerResources();
        loadJavaScript();
        Connection connection = RWT.getUISession().getConnection();
        remoteObject = connection.createRemoteObject(REMOTE_TYPE);
        remoteObject.setHandler(operationHandler);
        remoteObject.set("parent", WidgetUtil.getId(this));
    }

    private void registerResources() {
        ResourceManager resourceManager = RWT.getResourceManager();
        boolean isRegistered = resourceManager.isRegistered(REGISTER_PATH + RESOURCE_FILES[0]);
        if (!isRegistered) {
            try {
                for (String fileName : RESOURCE_FILES) {
                    register(resourceManager, fileName);
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Failed to load resources", ioe);
            }
        }
    }

    private void loadJavaScript() {
        JavaScriptLoader jsLoader = RWT.getClient().getService(JavaScriptLoader.class);
        ResourceManager resourceManager = RWT.getResourceManager();
        jsLoader.require(resourceManager.getLocation(REGISTER_PATH + "jquery-2.1.0.min.js"));
        jsLoader.require(resourceManager.getLocation(REGISTER_PATH + "highcharts.js"));
        jsLoader.require(resourceManager.getLocation(REGISTER_PATH + "ChartPaintListener.js"));
    }

    private void register(ResourceManager resourceManager, String fileName) throws IOException {
        ClassLoader classLoader = HightChartComposite.class.getClassLoader();
        InputStream inputStream = classLoader.getResourceAsStream(RESOURCES_PATH + fileName);
        try {
            resourceManager.register(REGISTER_PATH + fileName, inputStream);
        } finally {
            inputStream.close();
        }
    }

    // //////////////////
    // overwrite methods

    @Override
    public void setLayout(Layout layout) {
        throw new UnsupportedOperationException("Cannot change internal layout of CkEditor");
    }

}

发生错误:

  

未捕获错误:“null”类型的目标“r6”上的“create”操作失败:   没有类型rap.sunline.HightCharts的处理程序   属性:   parent = w5

我有一个关于此的问题,来自Canvas和Composite的不同之处;

1 个答案:

答案 0 :(得分:0)

您忘记在javascript代码中实施setter。

  

创建的对象由框架存储在其对象id下。此对象必须实现与处理程序中定义的属性匹配的setter方法,然后在服务器发送给定属性的set操作时调用该方法。