How to Create an Integer Column in a GXT Grid? - gxt

There have been a number of changes to the GXT library in version 3.1, and I'm not sure that I am using the correct technique for creating an editable integer column in a Grid. It seems that the required code is overly complex, but perhaps that's just how it is. Is there a better way than the following?
ColumnConfig<M, Integer> column = new ColumnConfig<M, Integer>(valueProvider, width, title);
IntegerPropertyEditor editor = new NumberPropertyEditor.IntegerPropertyEditor();
NumberInputCell<Integer> cell = new NumberInputCell<>(editor);
new IntegerField(cell);
column.setCell(cell);
Note that if the new IntegerField(cell) statement is omitted then the column contains a numeric (integer) cell that contains a down arrow (like a combobox arrow), which seems odd.

Related

How can I find if the value in a cell exists in a filter?

I have a spreadsheet that I'm using to compare old data against new data to make sure there were no changes to certain fields. Each set has
Object1.ID
Object1.Name
Object2.ID
Object2.Value
Object2.Obj1ID, which is used to link the two objects
Object1 can contain many Object2, and this is what's giving me trouble when trying to compare values. I need to make sure that for every Object1, all Object2.Value entries match in both sets. The IDs of each object can have changed between the two sets so I can't use that to compare the values, but the Object1.Name values are the same. So far I have gotten close with
B = Object1.Name - Old
D = Object2.Value - Old
G = Object1.Name - New
I = Object2.Value = New
N3=VLOOKUP(G3,B:B, 1,FALSE)
M3=CELL("address", INDEX(B:B,MATCH(N3,B:B,0)))
O3=OFFSET(INDEX(B:B,MATCH(N3,B:B,0)),0,2)
P3=I3
The purpose of N3 is to make sure there is a match found, new items were added and therefore the formula is broken, no big deal
The purpose of M3 is to return the cell address of the old Object1.Name against the value in N3 (I'm realizing now that might not be necessary).
The purpose of O3 is to return the matching old Object2.Value.
The purpose of P3 is to return the matching new Object2.Value for side-by-side compare.
The problem I ran into is that M3 will only return the first result, so I always compare my first values correctly, but the second and beyond are compared against the first again. So I tried a filter
S3=FILTER(D:D,N3=B:B)
This is listing all old Object2.Value values when the name is matched new to old. So far this seems good, but now I can't figure out how to search that result list for the new Object2.Value (I column). Any advice?

Visual Studio 2012 - Coded UI Test Builder: Assertion Formula?

While automating testing of a website shopping experience, I am attempting to verify that the subtotal, total, and tax are calculating properly. Since the price and/or tax will change in the future, I cannot simply assert the actual price value inside the control. Instead, I would need to build a calculation based upon the controls themselves and assert that quantity multiplied by individual price for each item added together equals the subtotal, and so on.
For example, say my controls for each are named such (control names are in asterisks):
Quantity = *UIItem2Cell*
(InnerText has a Value of 2)
Individual Price = *UIItem249Pane*
(DisplayText has a value of 2.49)
Individual Product Total (price x qty) = *UIItem498Pane*
(InnerText has a Value of 4.98)
Instead of validating the values are the actual numbers, can I write an assertion formula using the identifiers as variables?
Keep in mind, I am using the Coded UI Test Builder rather than writing the code outright.
If the Individual Product Total InnerText assertion comparator is AreEqual, can the Comparison Value be something like:
UIItem2Cell-InnerText * UIItem249Pane-DisplayText
A. Is this sort of formula possible?
B. If so, how do I write it?
(Please forgive me, as I am very green when it comes to this.)
You most certainly can. First off in your app itself it would be greatly useful to use IDs on your controls so you can match on just that criteria. that way your not using calculated values for search criteria.
Now as is in your question you will need to pull those values from the cells, calculate the Value and use it in your Search Criteria
// I'd recommend trimming text values:
// depending on how tables and such are rendered you'll have extra white-space characters
var firstValue = Double.Parse(UIItem2Cell.InnerText.Trim());
var secondValue = Double.Parse(UIItem249Pane.DisplayText.Trim());
var calculatedValue = string.Format("{0,N2}%", firstValue * secondValue);
// assuming your in a web app
var totalDiv = new HtmlDiv(currentHtmlDoc);
totalDiv.SearchProperties.Add(new PropertyExpression(HtmlDiv.PropertyNames.InnerText, calculatedValue, PropertyExpressionOperator.Contains));
Assert.IsTrue(totalDiv.TryFind());
SringAssert.Contains(totalDiv.InnerText,calculatedValue);

Javafx TableView formatting

My fxml file has the following declaration:
< TableView fx:id="myTable" prefHeight="756.0" prefWidth="472.0" />
then in Java code, I add the columns and then setItems as usual. This works as expected.
The only other code which affects the table is:
myTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
which nicely automatically re-sizes the columns. But I can't figure out how to do the following:
When I add say 1 or 10 items to the table, those appear as expected in the first 1 or 10 rows of the table, but the number of rows in the table are always 21. Rest of the rows are just empty. I want the table to have only 1 row if I set 1 item or 10 rows if I set 10 items. How do I achieve this ?
All the columns are of the same size. I can manually re-size them, but I want columns to auto-fit according to their size. For example if I have 2 columns one with integer from 1-10 and another with text description, they both have equal size. How do I tell it to autofit the column size according the the row contents ?
Thanks for the response!
The table fills up the layout with empty rows. Try hiding them by adding css
.table-row-cell:empty {
-fx-background-color: -fx-background;
}
.table-row-cell:empty .table-cell {
-fx-border-width: 0px;
}
For #2 you can check the length of text in the cells in the cell value factory but I have title problems like that. You can read the data set and figure out what it should be. These are both approximations depending on font size.
Added this, my play cellValueFactory where I tried out some things.
TableColumn<LineItem,String> amountCol = new TableColumn<>("Amount");
amountCol.setPrefWidth(amountCol.getText().length()*20);
amountCol.setCellValueFactory(new Callback<CellDataFeatures<LineItem, String>, ObservableValue<String>>() {
#Override
public ObservableValue<String> call(CellDataFeatures<LineItem, String> p) {
SimpleStringProperty ssp = new SimpleStringProperty(String.format("%.4f", p.getValue().getAmount()));
amountCol.setPrefWidth(Math.max(amountCol.getPrefWidth(), ssp.get().length()*20));
return ssp;
}
});

Apache POI : How to format numeric cell values

I am using Apache POI 3.9 for XLS/XLSX file processing.
In the XLS sheet, there is a column with numeric value like "3000053406".
When I read it with POI with..
cell.getNumericCellValue()
It gives me value like "3.00E+08". This create huge problem in my application.
How can I set the number formatting while reading data in Apcahe POI ?
There is a way that I know is to set the column as "text" type. But I want to know if there is any other way at Apache POI side while reading the data. OR can we format it by using simple java DecimalFormatter ?
This one comes up very often....
Picking one of my past answers to an almost identical question
What you want to do is use the DataFormatter class. You pass this a cell, and it does its best to return you a string containing what Excel would show you for that cell. If you pass it a string cell, you'll get the string back. If you pass it a numeric cell with formatting rules applied, it will format the number based on them and give you the string back.
For your case, I'd assume that the numeric cells have an integer formatting rule applied to them. If you ask DataFormatter to format those cells, it'll give you back a string with the integer string in it.
Problem can be strictly Java-related, not POI related, too.
Since your call returns a double,
double val = cell.getNumericCellValue();
You may want to get this
DecimalFormat df = new DecimalFormat("#");
int fractionalDigits = 2; // say 2
df.setMaximumFractionDigits(fractionalDigits);
double val = df.format(val);
Creating a BigDecimal with the double value from the numeric cell and then using the
BigDecimal.toPlainString()
function to convert it to a plain string and then storing it back to the same cell after erasing the value solved the whole problem of exponential representation of numeric values.
The below code solved the issue for me.
Double dnum = cellContent.getNumericCellValue();
BigDecimal bd = new BigDecimal(dnum);
System.out.println(bd.toPlainString());
cellContent.setBlank();
cellContent.setCellValue(bd.toPlainString());
System.out.println(cellContent.getStringCellValue());
long varA = new Double(cellB1.getNumericCellValue()).longValue();
This will bring the exact value in variable varA.

JExcel/POI: Creating a cell as type Text

I have a requirement that involves reading values from an excel spreadsheet, and populating a spreadsheet for users to modify and re-upload to our application. One of these cells contains a text string of 5 characters that may be letters, numbers, or a combination of both. Some of these strings contain only numbers, and begin with a zero. Because of this, the cell type is Text; however, when I use Apache POI or JExcel to populate a spreadsheet for the users to modify it is always set as cell type General.
Is there a way using either of these libraries, or some other excel api that I have not seen yet, to specify that a cell have type Text?
My co-worker just found a way to accomplish this. In JExcel, it can be accomplished by using a WritableCellFormat such as:
WritableCellFormat numberAsTextFormat = new WritableCellFormat(NumberFormats.TEXT);
Then, when you are creating your cell to add to a sheet you just pass in the format as normal:
Label l = new Label(0, 0, stringVal, numberAsTextFormat);
If you are using Apache POI, you would create a HSSFCellStyle, and then set it's data format like this:
HSSFCellStyle style = book.createCellStyle();
style.setDataFormat(BuiltInFormats.getBuiltInFormat("text"));
Many times when user enters number in cell which type(formatting) is text(string), spreadsheet software (openoffice or msoffice) changes it's formatting automatically. I am using apache poi and this is the way I wrote my code :
cell = row.getCell();
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
value = cell.getRichStringCellValue().getString();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
// if cell fomratting or cell data is Numeric
// Read numeric value
// suppose user enters 0123456 (which is string), in numeric way it is read as 123456.0
// Now I want ot read string and I got number...Problem?????
//well this is the solution
cell.setCellType(Cell.CELL_TYPE_STRING); // set cell type string, so it will retain original value "0123456"
value = cell.getRichStringCellValue().getString(); // value read is now "0123456"
break;
default:
}

Resources