Using Vala 0.30, how do you find a GTK child widget by name?
The main code calls a function to set up the application layout:
text.application_layout ();
The function creates the window and layout boxes.
class Example : Gtk.Window
{
public void application_layout ()
I want unrelated code to place content in some of the boxes. In C + GTK I could define the window as a global variable and any code could find a child box then add content. I cannot find a working equivalent in Vala.
Jen suggested using Container.get_children(). I will experiment with that. In the previous C code, the get_children approach produced thousands of children when a grid was populated.
Some Web pages show Vala classes with public strings. Vala will not compile the examples of a class when the public variable is a GTK widget. I also tried a dozen variations that work in other languages and fail in Vala.
Finally I found a way to have a public GTK widget that can be found by other code. The following compiles. All the online examples are slightly different and fail to compile in the current Vala.
class Example : Gtk.Window
{
public Grid example_grid = new Grid ();
public void application_layout ()
If this is the only option, I will have to make many items public public.
I will still have the problem of finding the last child in a variable length set of children, something like the last label added to a box or the last row added to a grid. I would like to label items in a long list with a name like last then find it direct instead of reading through a thousand children every time.
Another update. The following grid definition works from within the class. It works from other methods of the class when called within the class.
class Example : Gtk.Window
{
public Grid example_grid;
this.directory_grid = new Grid ();
My main code has var example = new Example(); and passes the example object to other code that needs user interface elements. The other code can then access example.example_grid or a method that updates example.grid. This means changing the other code to accept the example object.
I found then lost a page showing how you can access the main window object without having the object passed to the function. If I can find that again, it would let me access example.example_grid without having to change the code to pass the example object. This is getting close to a solution.
Related
Is it possible to dynamically create objects or modify them on run-time ?for example,on button click,another button created or change number of lines of a road?
When I write this code for a button Action,in run-time
road123.setBackwardLanesCount(3);
I get error below:
root:
road123: Markup element is already initiated and cannot be modified.Please use constructor without arguments,perform setup and finally call initialize() .function
You'll get that error with any object you attempt to create at runtime using a parameterized constructor. If you create the object with a simple constructor (just "()") and then set all of the parameters individually, you won't run into that issue. Check the Anylogic API for specific information about the object you are using, because some require you to call .initiliaze() on that object after setting all of it's parameters if you created it using a simple constructor. Furthermore, if you want to add the object to the screen at runtime you'll need to add this code to the function that creates it:
#Override
public void onDraw( Panel panel, Graphics2D graphics) {
obj.drawModel(panel, graphics, true);
}
where obj is replaced with the name of the object you created dynamically.
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.
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.
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:
emulated by GWT
Compilable to GWT (and inside the client or shared package)
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.
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.
I am creating a custom widget, say "CustomWid" in UiBinder.
And in CustomWid.java file I am writing two constructors
one with zero args like
CustomWid(){....}
another with some args like
CustomWid(String a,String b){......}
So,Now I am using my custom widget in another .ui.xml file,in that .ui.xml file
it is working fine when we give
<my:CustomWid/> alone,
and also fine when we give like
<my:CustomWid a="srt1" b="str2"/> alone
But "MY PROBLEM" is whenever I am trying to give both the tags in the one .ui.xml as
<my:CustomWid/>
<my:CustomWid a="str1" b="str2"/>
Now it is throwing error when i am using both types of tags in a single .ui.xml
I mean How to use my custom widget tag like a prdefined tag?
I am using #uiConstructor, but it showing error
Please developers... I need answer as early as possible
UiBinder will only ever use a single constructor for a given widget: either its zero-arg constructor, or a #UiConstructor (I'm surprised that you say it works when using either one or the other call but not both: one should fail in every case, and one should succeed in every case; if you haven't annotated a constructor with #UiConstructor, then <my:CustomWid/> should always work and <my:CustomWid a="str1" b="str2"/> should always fail)
There are two solutions here:
use setters for the a and b attributes (void setA(String a) and void setB(String b))), and possibly check later (say, in onLoad or onAttach) that you have either none or both of A and B, but not one without the other (if that's your rule).
use #UiField(provided = true) when you need to use the other constructor (if you choose to have UiBinder use the zero-arg constructor –i.e. no #UiConstructor–, then that means you'll have to move the a="str1" b="str2" from the XML to the Java code: #UiField(provided = true) CustomWid myCustomWid = new CustomWid("str1", "str2")).
The first option has my preference.
It Will not show any errors...'
#UiConstructor
public Component(String displayText,String heading)
{
initWidget(uiBinder.createAndBindUi(this));
this.displayText.setText(displayText);
this.heading.setText(heading);
}`
now use another constructor with default parameters also it will work
public Component()
{
initWidget(uiBinder.createAndBindUi(this));
}
now if you add with xml parameters component and without parameters also works in the same page.
Is there any idea wich allows me using layouts declared in MyApplication.java from other classes and functions.
I tried put them in parameters it works but it becomes very complicated
For example xhen callin a function named Y in function X I have to pass all layouts on parameters like this:
X(layout1,layout2,layout3,layout4)
{
Y(a,b,c,layout1,layout2,layout3,layout4)
}
I tried to use a class named uiHelper but it didn't works
You can take a look at Blackboard addon for vaadin.
https://vaadin.com/addon/blackboard
From that page:
Sometimes, having a deep component hierarchy poses a problem, when you need to inform a component high up in the tree that something happened deep down below. You normally have one of two choices - either pass the listener all the way down the hierarchy, leading to more coupled code, or let each component in between be a listener/notifier, passing the event all the way back up. With the Blackboard, you can register any listener to listen for any event, and when that event is fired, all the listeners for that event are triggered. This keeps your components clean and rid of unnecessary boilerplate code.
For your example, you can create a LayoutChangeListener and LayoutChangeEvent.
MyApplication can then implements LayoutChangeListener and when a LayoutChangeEvent is fired, you can change your layout without passing it around.
Currently I have big difficulties extending Zend_Form.
I have the basic class called Forms_LpaManageEmailForm.
It is used separately and works fine.
Next I've created a new class form
called Default_Form_CartReport witch extends Forms_LpaManageEmailForm.
So the task is to render Default_Form_CartReport and slitely modificate it.
In other words I need all functionality of
Forms_LpaManageEmailForm class but with overriden _addMultiOptionsForMultiSelect() function
(what is done) and changed button label (doesn't solved).
In basic class I have hidden element named id which value is filled with
$this->_entry_id['entry_id']. When I use basic form separately - its woks fine. But
when I run extended form(Forms_LpaManageEmailForm) I see that hidden id element's value is empty. In basic class in construct section I run
Zend debugger(with this line Zend_Debug::dump($this->_entry_id['entry_id'])) to see if the
value is passed. And it's passed :) When I repeat this in init() section it shows NULL...
As I barely understand - the problem lays in init() functions, in the way it is called.
I think something is wrong with Default_Form_CartReport class skeleton.
I've uploaded code to: PASTEBIN
Really need help in this question.
Thank you!
I believe your issues are causing my the fact that Forms_LpaManageEmailForm:: __construct is calling $this->init() directly. if you open the Zend_Form, you will notice that the __construct is also calling the $this->init() function. This cause your init() function to executed twice.
Try to load all your logic & elements solely in the __construct function, and don't use the init() function. also, the __construct function in each form class should always call the parent::__construct before any additional logic.