user2816447
user2816447

Reputation: 55

create and return gwt widget from java code

I am new to GWT and I need to reslove this problem. I need to create a widget with gwt-links. To make it happened, I need to fetch some data from an ontology, and then based on the result, create the graph. The problem is that, when I mix java code with gwt code it doesn't want to compile.

The question is, how do I create a widged explained above that will be placed in a http page?

The code looks like this now :

public class Example1 {

    @Override
    public void draw() {

        // Create the elements

        String ontology = Ontology.get(1);

        Widget labelHello = new BoxLabel(ontology);
        controller.addWidget(labelHello,25,115);


        // Add DnD logic
        PickupDragController dragController = new PickupDragController(controller.getView(), true);
        dragController.makeDraggable(labelHello);


    }


    public Widget asWidget() {
        return controller.getView();
    }

}

the Ontology.get() doesn't want to compile.

Upvotes: 0

Views: 129

Answers (3)

Christian Kuetbach
Christian Kuetbach

Reputation: 16060

GWT projects uses three packages (by default)

com.myapp.client
com.myapp.shared
com.myapp.server

By default everything within the shared and client package will be compiled to JavaScript. Every Class, which is imported into a Class, which is inside the shared and client package must be:

  1. emulated by GWT
  2. Compilable to GWT (and inside the client or shared package)
  3. Compilable to GWT (and the package must be whitelists in *.gwt.xml)

Uf you code ISolver can be compiled to JavaScript you will have to create a module.gwt.xml and inheritt your project from this module. This may enable the GWT-compiler to compile ISolver (and its implementation) to JavaScript.

If your code can't be compiled to GWT you will have to write a remote-service to make the calculation.

Upvotes: 1

user2816447
user2816447

Reputation: 55

I don't really want to compile the code to javascript. All i want to do is to create a GWT widget ( which is a graph).

To create the widget, I need to do some calculations and repository fetch. I dont want to translate it( repository fetching), I just need to use it in order to create the model of the graph.

Basically, this is something I want to do:

String l = Repository.getLabel(); // Some advanced calculations that use many JavaSE classes;
GWTWidget widget = new GWTWidget(l);  // widget, that will be displayed on a page.

but when I put something in method onModuleLoad it doesn't compile.

This is probably a simple question, but I'm not really related with GWT and I'm forced to remake someone's work.


 public void onModuleLoad() {
        System.out.println("tes");
        VerticalPanel mainPanel = new VerticalPanel();
        RootPanel.get().add(mainPanel);

        //
        ISolver solver = null;
        System.out.println("TEST2");
    }
ERROR: Line 53: No source code is available for type pr.ISolver; did you forget to inherit a required module?
  ERROR: Unable to find type 'client.Link'
    ERROR: Hint: Previous compiler errors may have made this type unavailable

and other lines sthat start with " No source code..".

ISolver is an interface, but I dont want to translate it. I want to use it for calculations.

Upvotes: 0

Spiff
Spiff

Reputation: 4104

GWT can't compile just any java code.

These are the packages that are emulated by GWT: pls read

The code that can't be translated to javascript, (the stuff that is not emulated) you must handle on the server side.

Upvotes: 1

Related Questions