Hey im using the d3 plugin to work with the Collapse Tree. This is my example: http://bl.ocks.org/mbostock/4339083
Now i created 2 Widgets which are in 2 different classes. One for the tree and one for a control element. Now i want to change the properties of clicked nodes with my control element widget. So I need to get the Data(Object) from the clicked node in my other class. After I need to manipulate that data using my control widget.
"Dojo on" / "Dojo connect" are just for DOM interactions right?.
I want to communicate between the javascript classes.
Here is my onclick function for clicking the nodes:
.on("click", function (d) {
toggle(d);
update(d)
})
You can create a custom event in the tree class and handle it from the other class. First, define an event handler for the onClick event on the tree node.
onClick: function(evt) {
// here comes your code
// when you're finished, fire a custom event
this.onNodeClicked(params);
},
onNodeClicked: function(params) {}
In the other class, listen for the custom event. Here I assume you create the tree widget from there. Otherwise, you can pass a reference to your tree object.
var tree = new MyTree();
dojo.on(tree, "onNodeClicked", this._handleOnNodeClicked);
Hope this helps.
Related
I would like to create a custom tooltip for an RCP MDirectToolItem or MHandledToolItem. JFace provides the org.eclipse.jface.window.ToolTip class, which I can extend and override the createToolTipContentArea() method. However, to instantiate a JFace ToolTip, I have to give it the SWT Control that will use the ToolTip. I cannot figure out a way to get the underlying SWT Control from the MDirectToolItem.
I have been able to get the MToolBar and the MDirectToolItem (which I defined in the Application.e4xmi) using the EModelService.find() method. I tried getting the underlying SWT Control from the MDirectToolItem, but it does not appear there is a way to do that.
I also tried creating an SWT ToolItem and adding it to the MToolBar, but the children of the MToolBar are only MToolBarElement's.
Tool items don't have a separate control, they are part of the parent ToolBar control. The SWT ToolItem class represents the tool item, this is just derived from Widget rather than Control.
So you will have to set the tool tip on the tool bar control and work out which tool item is active when the tool tip is shown.
The application model classes which represent UI objects all extend the MUIElement interface. This provides a getWidget method to get the UI object.
So for MToolBar you can do:
ToolBar toolbar = (ToolBar)mtoolbar.getWidget();
and for MToolItem (either handled or direct) you can do:
ToolItem toolitem = (ToolItem)mtoolitem.getWidget();
If you create the ToolTip with the NO_RECREATE style it will call the
getToolTipArea method to determine if the tool tip need to be changed. You can use something like the following to have a different area for each tool item:
#Override
protected Object getToolTipArea(final Event event)
{
// TODO save the ToolBar in the class as 'toolBar'
ToolItem item = toolBar.getItem(new Point(event.x, event.y));
if (item != null)
return item;
return super.getToolTipArea(event);
}
I have two custom controls. Control A attaches an event handler on Control B by calling
b.attachEventName( function(event, data){ ... })
after instantiating b.
Control B reacts on a click and fires the relevant event by doing something like this:
this.fireEventName( { key: value } );
I observe that I don't have access to the object, I gave as parameter in the firing of the event in the attached function in control A. How can I get access to that object?
PS: For clarification: I want to reuse Control B, and different controls, which use B might want to attach different functions for a specific event.
Thanks,
Christian
The problem is with syntax you are using to attach event to the control.
If you want to pass an object along with the event object when firing the event, code would be:
b.attachEventName(oData, function(oEvent){
// your stuff
});
This should do:
b.attachEventName(function(event, data) {
var sKey = event.getParameter("key")
});
The second parameter data in this function is the data that you potentialy passed when registering the event listener as described above by Dopedev.
BR
Chris
I created a custom Kendo widget that is will be a composite control made up of a few other widgets. I have everything working except MVVM-enabling it, specifically I can't get the view model's value to update whenever the control is updated. However, if I update the view model directly, the control's value get's updated, just not the other way around. It needs to be two-way. I put together an example of this issue:
http://jsbin.com/obejey/3/
Any help would be hugely appreciated!!
You are SO close! :) All you are missing is to trigger a change event when your value changes. To do this, simply monitor the change event of your ComboBox and when it changes, trigger a change of your custom widget.
Add this bit of code:
_initAutoComplete: function () {
var that = this;
that.select.kendoComboBox({
...,
// ADDED CODE...
change: function () {
that.trigger("change", {field: "value"});
}
});
},
I have a Vertiacal panel object and This object contains many radiobuttons
So can i get those radioButton objects through Vertiacal panel object.
Maybe via iteration or ?
private void initCourse() {
coursePopupPanel.clear();
VerticalPanel verticalPanel = new VerticalPanel();
coursePopupPanel.setWidget(verticalPanel);
JsArray<JCourse> jCourseArray = JCourse.getList(stringMainData);
for (int i = 0; i < jCourseArray.length(); i++) {
final RadioButton courseRadioButton = new RadioButton("course");
courseRadioButton.setText(jCourseArray.get(i).getName());
courseRadioButton.getElement().setId(jCourseArray.get(i).getView());
verticalPanel.add(courseRadioButton);
//handler of course radio buttons
courseRadioButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
}
});
}
}
I have a reference to coursePopupPanel. but i have not reference to vertical panel, so can i get elements of vertical panel sonce holding reference to coursePopupPanel.
A GWT VerticalPanel is a subclass of ComplexPanel, an abstract class for Panels that contain more than one child widget. In ComplexPanel (and so inherited by VerticalPanel) are methods for getting the number of child widgets, getting references to them by index, and so on. You could build an iterator something like this:
Iterator<Widget> vPanelWidgets = myVerticalPanel.iterator();
while (vPanelWidgets.hasNext()){
Widget childWidget = vPanelWidgets.next();
if (childWidget instanceof RadioButton) {
...do stuff
}
}
I tend not to query a widget for its members. That ties me to the decisions I made about how to display the RadioButtons, following your example. What if you decide later to display your radio buttons in the cells of a FlexTable in order to control vertical and horizontal arrangement? To make that change means your widget iterator won't work. FlexTable is a Panel but not a ComplexPanel. The code I wrote above won't work if you decide to replace the VerticalPanel with a FlexTable.
If was to take something like this approach, I would keep my lists of related widgets (like a group of RadioButtons) in some sort of Java Collection. I pass that Collection to my presentation class, and inside there I write the code to do the layout. Usually that's a UiBinder class, with "#UiField(provided = true)" for these RadioButtons. The code in the presenter then associates the RadioButton elements of the Collection I passed in to the UiField placeholders for the RadioButtons in the UiBinder layout. So all my layout decisions are actually in the UiBinder xml file. If I decide to rip out my Vertical Panel and replace it with a FlexTable, I might not have to touch a single line of Java code, assuming I separated things out correctly.
[Actually, I would probably keep my decision to use RadioButtons inside the presentation layer, and inside the XML file in particular. That presentation class would fire a message on the EventBus to indicate the user had made a selection via a RadioButton ValueChangeHandler, and I wouldn't care if I used RadioButtons in a VerticalPanel or ToggleButtons in a FlexTable.]
You're not being to specific, add more details and maybe a code example.
I'm gonan try to guesstimate what you're trying to say here: You have a verticalPanel object. To it you add several radioButton objects. Later you want to retrive those radioButton objects (to maybe check if they're selected or not), right? There's several ways to do this. At any rate, why don't you check the code examples at the Gwt Showcase site here:
http://gwt.google.com/samples/Showcase/Showcase.html?locale=en_UM#!CwRadioButton
it has tons of visual examples, each with the attached code and css.
Since PopupPanel implements HasOneWidget interface you can coursePopupPanel.getWidget() to get a reference to your verticalPanel. And iterate widgets in it simply using
for (Widget w : verticalPanel){
//Do Stuff
}
This may have been asked before but I have no idea how to word it to search for it.
I have a composite widget that has methods to update some of the widgets that make up the composite widget. When I add this composite widget to my panel I use a do while loop to pull data from an XML file and populate the composite data. When I instantiate the object each time to add the data it has a scope local to the do-while loop and I cannot call methods to update the data in the composite widget later on. Is there maybe a way to make an array of these composite widgets or another solution to be able to access the Widget?
Eric
Sure... use
List<Composite> widgetList = new ArrayList<Composite>();
// loop
widgetList.add(widget);
// end loop
widgetList.get(3).toString();
You'll want to use your custom class instead of Composite in the list generic... there's nothing stopping you from making data structures using widgets, just like you would with any other Java class.
If you are putting all your Widgets in that loop into one panel (presumably on of the subclasses of ComplexPanel, since you are adding many Widgets to one panel), then you could use one of the methods to access Widgets contained within a panel (assuming you add only those XML generated Widgets to the panel and nothing more):
com.google.gwt.user.client.ui.ComplexPanel.iterator() - returns an java.util.Iterator<Widget> you can use to traverse the list of Widgets within that Panel
com.google.gwt.user.client.ui.ComplexPanel.getWidgetCount() and getWidget(int index) can be used in a for loop to go through all the Widgets within a panel
So, let's look at an example:
VerticalPanel vPanel = new VerticalPanel();
// Fill up the vPanel using XML
Iterator<Widget> iterator = vPanel.iterator();
while(iterator.hasNext()) {
Widget w = iterator.next();
// Do something with w
}
// Or...
for (int i = 0; i < vPanel.getWidgetCount(); i++) {
Widget w = vPanel.getWidget(i);
// Do something with w
}
Of course, substitute VerticalPanel with the one you are you using :)
I definately recommend that you watch "Best Practices for Architecting GWT App" (from Google I/O 2009):
http://www.youtube.com/watch?v=PDuhR18-EdM
At about 24 minutes through it talks about how to write composite widgets using the MVP design pattern - although you should watch it all. Unfortunately it does not provide ready to use code snipets, but it does show you how to construct a framework to decouple your XML and UI objects nicely.