how to change widget name at runtime in GWT - gwt

I have a label which i need to create as per the size of my record
like if there are 2 records from database , my method should check and create 2 new labels at runtime , if 10 records there should be 10 labels to be created at run time
I am able to create 10 new labels at run time but how can i name them differently
some thing like
for (int i =0;i<array.size();i++)
{
Label lbl = new Label();
}
in this way there are 10 labels and showing perfectly , but all ten have the same name i.e lbl can this name could also be change like lbl1,lbl2,lbl3...
is it possible in GWT
Thanks

The thing you want to do isn't poosible in any programming language.
The solution you are searching for is storing them inside a list and then access the labels via the index. Eg. if you want the first label you say List[0]
GWT supports such list, the easiast for you to use ist the ArrayList!
here is some more or less pseudo code:
ArrayList<Label> labelList = new ArrayList<Label>();
for (int i =0;i<array.size();i++)
{
Label lbl = new Label();
labelList.add(lbl);
}
...
//the first item has the index 0!
Label lbl1 = labelList.get(0);
..
//doing stuff with the first label
...
//getting the secont label
Label lbl2 = labelList.get(1);
...
//you get the idea right
...

Related

Text style in google script TextItem title

I have written an app to automatically update an order form everytime an order is passed. Currently, the form consists in N Textitems, which titles are like:
Product (remains : [number of remaining products])
Product description
This is performed by the following lines :
var Products= wsStocks.getRange(1,1,wsStocks.getLastRow(),1).getValues();
var Description = wsStocks.getRange(1,2,wsStocks.getLastRow(),2).getValues();
var Qtys = wsStocks.getRange(1,3,wsStocks.getLastRow(),3).getValues();
for(j=0;j<Products.length;j++){
Items[j].setTitle( `${Products[j][0]} (remains: ${Qtys[j][0]})`+ "\n" +`${Description[j][0]}`;
};
I would like to set a text style for this title : I want the information on the number of remaining products to be in italic, and the description to be in small size. But while I have found how to set the style for a Text variable, I can't find how to do this for a string used in the setTitle method ?
You should get the Range of each item from the Items array first and then you should be able to change the TextStyle according to your needs by using the setTextStyle() method.
For customizing the text styles, you can create your own, something similar to this.
// italic text style
var style1 = SpreadsheetApp.newTextStyle()
.setFontSize(14)
.setItalic(true)
.build();
// small size text style
var style2 = var style = SpreadsheetApp.newTextStyle();
.setFontSize(11)
.build();
Afterwards, for each element of the Items array, you should do this
for(j = 0; j < Products.length; j++)
sheet.getRange("RANGE_OF_Items[j]_ELEMENT").setTextStyle(style1); //or style2
Reference
Apps Script Class TextStyle;
Apps Script Range Class - setTextStyle(style).

adding/changing 'text' to an item in a group

I'm designing a UI with Enthought's TraitsUI, and I can't figure out how to get done what I want...
Here's what I want:
I have Items() in the view that I want to display as either English or SI units. I can change the value in the 'edit' box based on a SI/English button, but I can't figure out how to change the text of the label. For example, if I have an item 'Length, ft [ 3.28]' and convert it to SI, I'd like it to show 'Length, m [ 1.00]'. I can handle the 3.28->1.00 conversion, but can't figure out how to change the 'ft' to 'm'.
Any suggestions?
One thing I've tried is to define a string which holds the units name (like 'm' or 'ft')...then, in the item, I set the label like this:
label = 'Top, '+lengthUnits
This works fine when the view is first built, but it doesn't update the label when I change the units control. Is there some way to force the view to update with all the new values?
Here's a small py program that shows what I'm trying to do (feel free to critique my style :)). I'll also try and add in a couple of images that shows what happens:
# NOTE: This version of the code has been modified so that it works as I want it to :)
# Example trying to change text on a View...
from traits.api \
import HasTraits, Enum, CFloat, String
from traitsui.api \
import View, Group, HGroup, Item, spring
class TestDialog ( HasTraits ):
length = CFloat(1.0)
choose_units = Enum('English', 'SI')
current_units = 'English'
unit_name = String('ft')
ft_to_m = CFloat(3.28)
view = View(
Group(
HGroup(
spring,
Item(name = "length", label = 'Test length'),
Item(name = 'unit_name', style = 'readonly', show_label = False),
spring
),
HGroup(
spring,
Item(name = "choose_units"),
spring
)
),
title = 'Test Changing View Test'
)
def _choose_units_changed(self):
if self.current_units != self.choose_units:
if self.choose_units == 'SI':
self.length /= self.ft_to_m
self.unit_name = 'm'
else:
self.length *= self.ft_to_m
self.unit_name = 'ft'
self.current_units = self.choose_units
# Run the program (if invoked from the command line):
if __name__ == '__main__':
# Create the dialog:
TestIt = TestDialog()
# put the actual dialog up...
TestIt.configure_traits()
Use a notification as described here: http://code.enthought.com/projects/traits/docs/html/traits_user_manual/notification.html
Update in response to updated question:
Right, labels are not dynamically updated. Instead, make a text field that looks like a label, e.g. with:
label_text = String('Test length, English:')
Then display it in your View with something like:
Item("label_text", style='readonly', show_label=False),
You'll probably also want to use an HGroup nested inside your (V)Group, to position it to the left of your "length" display.
Then modify label_text inside your listener.

Add new labels on button listener GWT

I'm trying to add new labels to a panel and this is when a button is clicked, in fact the number of labels is unknowing because my application consists in extracting some informations from a file and then display each information in a label so i have to upload the file and then extract the informations, i created an uploadfile and i'm able to extract the informations but i face a problem to display each information in its label, i can't create many labels and then with label.settext() make each information in its label beacuase the number of labels/informations is variable.
So can you advice/help me so i can make this working.
Best regards.
If you get the result from an Array for example you can do like this:
String[] data; //You can add you data here
addButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
for (String s : data) {
RootPanel.get().add(new Label(s));
}
}
});
That way you can add as much Labels as you want
You can create a variable number of Labels with a LinkedList.
int count = x ; //Quantity of labels you need;
LinkedList<Label> labelList = new LinkedList<Label>();
for (int i = 0; i < count ;i++)
{
Label tmpLabel = new Label();
tmpLabel.setText(STUFF) //Here you have to set your content
labelList.add(tmpLabel);
}
// Now we add the Labels to the Panel
for (int ind = 0; ind < labelList.size() ;ind++)
{
panel.add(labelList.get(ind)); //panel is the panel you show
}
If you don't have to access the labels later, you don't need the LinkedList and could add them direct to your panel.
You didnt say how you exactly attach the Labels, but if you use a Grid you have to set the size of it depending on your information.

Legend hides chart created using JFreeChart

i've to create a chart using library JFreeChart, i try this:
TimeSeriesCollection dataset = new TimeSeriesCollection();
ArrayList<MyObject> list = this.FillArray();
MyObject tmp;
String date[];
for(int i=0;i<list.size();i++){
tmp = list.get(i);
ArrayList<MyObject1> obj = this.FillArray1(tmp);
TimeSeries pop = new TimeSeries(tmp.getName(),Day.class);
for(MyObject1 ob1 : obj){
date = ob1.getDate().split("-");
Day day = new Day(Integer.parseInt(date[0]), Integer.parseInt(date[1]), Integer.parseInt(date[2]));
pop.addOrUpdate(day, ob1.getValue());
}
dataset.addSeries(pop);
}
My problem borns when the number of object is very high and legend will cover the panelchart. What can i do? is possible to add a scrollpane to the legend?
Legends are rendered in a LegendTitle, the first Title added to List subtitles when the JFreeChart instance is constructed with the createLegend parameter set to true. Because JFreeChart is not a Container, nor is Title a Component, adding a LegendTitle to a JScrollPane is not supported.
You can always invoke getLegendItems() and render the items in a Scrollable Container such as JList or JTable. To avoid duplication, set createLegend to false.

How to get row values from a Rounded Rectangle List in Dashcode?

I am new to dashcode and trying to build a simple web app for iphone using it. My primary aim is to have a Rectangular List (I have used the "Rounded rectangle list"). It is a static list and has three rows. What I want is a website to open when user clicks on any of the row, and each row would have a different URL. I was able to add a Rounded rectangle list with three static rows like
The object ID is "list"
Row 1-- Label- "Gift Cards" , Value - "http://www.abcxyz.com/giftcard"
Row 2-- Label- "Toys" , Value - "http://www.abcxyz.com/toys"
Row 3-- Label- "Bikes" , Value - "http://www.abcxyz.com/bikes"
i added onclick even to call a java script function like below
function myButtonPressHandler(event)
{
var websiteURL = "http://www.abcxyz.com/giftcard";
location = websiteURL;
}
the above code opens the same URL "http://www.abcxyz.com/giftcard" when the user clicks on any of the three buttons, but what I want is to fetch the value of each child node (which would be their respective URLs) at runtime and open it using location = WebsiteURL something like below (did'nt work for me :( -
function myButtonPressHandler(event)
{
var websiteURL = document.getElementById("list").children;
var WebURL = websiteURL[???].value;
location = WebURL;
}
Any help would be appreciated.
Thanks
OK ... so figured out my own answer. The Rounded Rectangular list is actually a multidimensional array. so to get the value of each of the rows i.e. the Http URLs and open them on the browser when the rows were touched/tapped/pressed is as below.
function buttonpresshandler(event)
{
// Insert Code Here
var list = document.getElementById("list").object;
var selectedObjects = list.selectedObjects();
//Open webpage with the value of each label
location = selectedObjects[0][1];
}
Hurray!