eclipse-rap

I want to create highchart widget by Eclipse RAP and i follow "RAP/Custom Widgets FAQ",but there is error?


i want to create some highchart widget by Eclipse RAP ,and i follow the official guide like this

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");
    }

}

the error is occur:

Uncaught Error: Operation "create" on target "r6" of type "null" failed: No Handler for type rap.sunline.HightCharts Properties: parent = w5

and i have a question about this , what differents from extends Canvas and Composite;


Solution

  • You forget to implement setters in your javascript code.

    The created object is stored by the framework under its object id. This object has to implement setter methods that match the properties defined in the handler, which will then be called when the server sends a set operation for a given property.