adding an image component to Table cell by overidding `createCell` - java-me

I am using LWUIT and showing data with Table, say, flight information!
Instead of writing air companies with text I just like to replace them with icons.
So, I need to override protected Component createCell(Object value, final int row, final int column, boolean editable) method of Table.
This is how I've implemented:
Initializing
imgAln[i]=null;
try {
imgAln[i] = Image.createImage(strPathToImage[i]);
//e.g /uta.png,/somonair.png and so on
lAln[i] = new Label(imgAln[i]);
} catch (IOException e) { }
Creating Table object
Table table = new Table(model) {
protected Component createCell(Object value, final int row,
final int column, boolean editable) {
final Component c = super.createCell(value, row, column, editable);
if (column == 6) {
return lAln[value]; //it does not work here
}
}
};
need help to add Image to table cell!!!
Is there any example??? links are welcome!

The problem in your createCell(...) implementation is that it does not return the super.createCell(...) when the column is not 6. Also your array of labels (lAln) may not be properly created. Try my implementation below, but make sure you store the appropriate image name in the table models' column 0.
This should solve it:
TableModel model = new DefaultTableModel(
new String[]{"Uneditable", "Editable", "CheckBox", "Multiline"},
new Object[][]{
{"/animations.png", "", new Boolean(false), "Multi-line text\nright here"},
{"/buttons.png", "", new Boolean(true), "Further text that\nspans lines"},
{"/dialogs.png", "", new Boolean(true), "No span"},
{"/fonts.png", "", new Boolean(false), "Spanning\nFor\nEvery\nWord"},
});
Table table = new Table(model) {
protected Component createCell(Object value, final int row,
final int column, boolean editable) {
if (row != -1 && column == 0) {
try {
//In my case Column 0 store the resource path names
return new Label(Image.createImage((String)value));
} catch (Exception ex) {
ex.printStackTrace();
}
}
return super.createCell(value, row, column, editable);
}
};
NOTE: If you see the names instead of images in column 0 it means the image path is incorrect, fix it to see the images.
Did you manage to have a look at TableLayoutDemo.java in project LWUITDemo? If i remember it correct, this comes bundled download package LWUIT1.5.zip (or you can always google it).
Let me know if you need more specific help.

Related

Hiding value of a selector in a grid dynamically

I am trying to hide these duplicate inventory ID values for the "price" and "Cost" lines (when one "adds" an item to the grid it creates three lines), but the selector description still appears.
How can I just make these value come up blank in the grid?
Even better, how can I disable a link command so if someone inadvertently clicks then it wont link to the stock item screen?
Here is my code thus far:
protected void _(Events.FieldSelecting<FPPriceSheetDetail, FPPriceSheetDetail.inventoryID> e)
{
if (e.Row is null) return;
if (e.Row.RowType == FPPriceSheetRowType.BreakQty) return;
var state = PXFieldState.CreateInstance(e.ReturnState, typeof(string), true, false, 1, null, null, null, nameof(FPPriceSheetDetail.inventoryID));
state.SelectorMode = PXSelectorMode.TextMode;
state.DescriptionName = "";
state.ValueField = "";
state.Visibility = PXUIVisibility.Visible;
state.Visible = true;
e.ReturnState = state;
e.ReturnValue = "";
}
I would rather review the pxSelector and in the condition only show 1-row type - this will remove the duplicates. The point of the selector is to select one of the values within the result - assuming all the information the selector are selectable.

How can i load dropdown values dynamically in acumatica for each row with different dropdown values?

Example:
As per the Below screenshot, i have to combine below two grids into one grid and the first grid(query list) will display as it is and the second grid values should show as drop down for the respective query.
Samplegridsimage
when i tried to use field selecting event, it is loading all vales from second grid but i need only 3 values for fuel type value and for others different drop down.
can anyone suggest how to get only particular values in the drop down.
protected virtual void KNRWTAXQueries_Response_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
KNRWTAXQueries doc = e.Row as KNRWTAXQueries;
if (doc == null) return;
List<string> Responsevalues = new List<string>();
List<string> ResponseLables = new List<string>();
if (QueryList.Current != null)
{
if (Base.Transactions.Current != null)
{
foreach (KNRWTAXQueries queries in PXSelect<KNRWTAXQueries, Where<KNRWTAXQueries.nonStockItemID, Equal<Required<APTran.inventoryID>>>>.Select(Base, doc.NonStockItemID))
{
foreach (KNRWTAXResponse response in PXSelect<KNRWTAXResponse, Where<KNRWTAXResponse.tAXQueID, Equal<Required<KNRWTAXResponse.tAXQueID>>>>.
Select(Base, queries.Taxqueid))
{
Responsevalues.Add(response.Response);
ResponseLables.Add(response.Response);
e.ReturnState = PXStringState.CreateInstance(e.ReturnState, 255, true, typeof(KNRWTAXQueries.response).Name, false, 1, string.Empty, Responsevalues.ToArray(),
ResponseLables.ToArray(), true, null);
}
}
}
}
// ((PXStringState)e.ReturnState).MultiSelect = false;
}
You can use RowSelected event of the row to set the list. No need to use FieldSelecting (however you can use field selecting too)
You should use PXStringListAttribute.SetList method to set new list instead of using string state
You should set MatrixMode=true in the aspx grid row so that list is recreated for each row (oterwise the list will be the same for all rows)
<px:PXGridColumn DataField="OrigTranType" Type="DropDownList" MatrixMode="true" />

PX.Data.XLSXReader not reading first row

I'm using the XLSXReader to read an Excel file, but it is failing to read the first row. I need to read the first row since it contains data and not headers.
Using test data, I put in a blank first row, but it still skipped the first row with data:
I copied the first row and duplicated it and it read the row:
I don't know why it is automatically skipping the first row.
Here is the action button code that imports the file, saves it, and reads it:
public PXAction<PMProject> importCostBudget;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Import Cost Budget")]
protected void ImportCostBudget()
{
if (ImportCostBudgetView.AskExt() == WebDialogResult.OK)
{
const string PanelSessionKey = "ImportCostBudget";
PX.SM.FileInfo info = (PX.SM.FileInfo)PX.Common.PXContext.SessionTyped<PXSessionStatePXData>().FileInfo[PanelSessionKey];
Byte[] bytes = info.BinData;
System.Web.HttpContext.Current.Session.Remove(PanelSessionKey);
if (info != null)
{
PXNoteAttribute.AttachFile(Base.Project.Cache, Base.Project.Current, info);
using (PX.Data.XLSXReader reader = new XLSXReader(bytes))
{
//List<PMCostBudget> costBudgets = new List<PMCostBudget>();
reader.Reset();
//This is to read the first row
RowRead(reader);
while (reader.MoveNext())
{
RowRead(reader);
}
}
}
}
}
Is there a way I can force read the very first row using the reader?
Header row is likely treated as a special case intended for reading column names.
You should be able to access it from the XLSXReader IndexKeyPairs collection:
public IDictionary<int, string> IndexKeyPairs
{
get { return _header; }
}

Filtering doesn't work after a while

I'm using in my app this example to let the user search/filter a table.
When you run the application, it works perfect.
The problem is when I left the program opened, minimized, and after a while (10-15min) I try to use it again. It's then when the search/filter doesn't work at all.
Here is the code:
#FXML
private void initialize() {
// 0. Initialize the columns.
firstNameColumn.setCellValueFactory(cellData -> cellData.getValue().firstNameProperty());
lastNameColumn.setCellValueFactory(cellData -> cellData.getValue().lastNameProperty());
// 1. Wrap the ObservableList in a FilteredList (initially display all data).
FilteredList<Person> filteredData = new FilteredList<>(masterData, p -> true);
// 2. Set the filter Predicate whenever the filter changes.
filterField.textProperty().addListener((observable, oldValue, newValue) -> {
filteredData.setPredicate(person -> {
// If filter text is empty, display all persons.
if (newValue == null || newValue.isEmpty()) {
return true;
}
// Compare first name and last name of every person with filter text.
String lowerCaseFilter = newValue.toLowerCase();
if (person.getFirstName().toLowerCase().contains(lowerCaseFilter)) {
return true; // Filter matches first name.
} else if (person.getLastName().toLowerCase().contains(lowerCaseFilter)) {
return true; // Filter matches last name.
}
return false; // Does not match.
});
});
// 3. Wrap the FilteredList in a SortedList.
SortedList<Person> sortedData = new SortedList<>(filteredData);
// 4. Bind the SortedList comparator to the TableView comparator.
sortedData.comparatorProperty().bind(personTable.comparatorProperty());
// 5. Add sorted (and filtered) data to the table.
personTable.setItems(sortedData);
}
}
I tried the code and it works for me.
However, step 2 must be the last step because the filteredData.setPredicate will be effective only after the second user input.
If someone just add a single letter, then the filtering will not happen.

Delete Specific record in RMS?

I am creating one J2ME application which read/write RMS record. I able to read and write
record in RMS but now problem is that I want to delete record by accepting some value
like accountNumber.
Format of RMS record.
101,ABC,12345,12345
and String str contain following data.
String str=accountSrNumber +","+ name +","+ balance +","+ TextDeposit;
deleteRecStore(str,accountSrNumber);
And I need to accept accountNumber(101) from user and need to delete this record.
Here is my Delete method.
public void deleteRecStore(String str, String accNumber121) //
{
int s=str.indexOf(accNumber121);
System.out.println("index in delete function"+s);
if(s==0)
{
try{
rs.deleteRecord(s);
// RecordStore.deleteRecordStore(REC_STORE);
System.out.println("record delete successfully");
}
catch (Exception e)
{}
}
}
I tried to use both of method rs.deleteRecord(s) and RecordStore.deleteRecordStore(REC_STORE);.
But none helps.
You always delete record 0 which is the first record, which is a bad idea.
For example, if you add two records, and delete them, and than add another record, it will be indexed as 2, so you will have to call deleteRecord(2) to remove it.
Method deleteRecordStore() removes entire recordStore (which contains records) - after that, if you create one, the next added record will be indexed as zero.
If I got the idea, you want to delete a record by it's acoountNumber.
If i'm right, you need to find the recordID by it's contents. The code will probably look like this (may have mistakes, did not test it, but the idea is important):
public void deleteRecStore(String accNumber121) {
RecordEnumeration e = rs.enumerateRecords();
int found = -1;
while (e.hasMoreElements()) {
int id = e.nextRecordId();
String next = new String(e.nextRecord());
if (next.startsWidth(accNumber121)) {
found = id;
}
}
if (found == -1) {
System.out.println("not found!");
} else {
rs.deleteRecord(found);
}
}

Resources