Java-gnome (GTK): why is my TreeView displayed empty? - java

I'm trying to display a list of strings (filenames, to be pedant) inside a GtkTreeView. I'm creating a single column and trying to fill it with a CellRenderText.
//Setup listview
TreeView imageList = (TreeView)gladeBuilder.getObject("imageListTreeView");
TreeViewColumn column = imageList.appendColumn();
DataColumnString imageColumnString = new DataColumnString();
//Fill listview
ListStore listStore = new ListStore(new DataColumnString[]{imageColumnString});
File[] imageFiles = new File("/path/to/files").listFiles();
// For each file:
for (File file : imageFiles) {
TreeIter row = listStore.appendRow(); //add a row
listStore.setValue(row, imageColumnString, file.getName());
}
CellRendererText cellRendererText = new CellRendererText(column);
cellRendererText.setText(imageColumnString);
The program compiles and run without errors, but the list is displayed empty. Someone can help me to find the error(s)?

Add imageList.set_model (listStore) which actually associates your view with the model. This is required or the view will stay empty as it has no model associate unless you specified it in the builder file which I can only guess at this point.

Related

How parse this excel? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 10 months ago.
Improve this question
I have an excel file, i have to parse to list of objects:
excel:
excel
my pojo:
my service:
public List<RegisterModel> parse(MultipartFile file) throws IOException {
Workbook workbook = new HSSFWorkbook(file.getInputStream());
Sheet worksheet = workbook.getSheetAt(0);
List<RegisterModel> registerModelList = new ArrayList<>();
RegisterModel registerModel = new RegisterModel();
for (int i = 3; i < worksheet.getPhysicalNumberOfRows(); i++) {
Row row = worksheet.getRow(i);
String headers = String.valueOf(row.getCell(0));
String values = String.valueOf(row.getCell(1));
if (headers.equals("OPERDAY")){
registerModel.setDate(values);
}
if (headers.equals("SUIP")){
registerModel.setSuip(values);
}
if (headers.equals("STATE")){
registerModel.setSuip(values);
}
if (headers.equals("NOM_OPER")){
registerModel.setTransactionID(values);
}
registerModelList.add(registerModel);
}
System.out.println(registerModelList);
return registerModelList;
}
but it is not works(
result: values are duplicate
[RegisterModel(date=2022-03-01T23:48:47, suip=Проведён, state=null, transactionID=1888314188),
RegisterModel(date=2022-03-01T23:48:47, suip=Проведён, state=null, transactionID=1888314188),
RegisterModel(date=2022-03-01T23:48:47, suip=Проведён, state=null, transactionID=1888314188)]
The issue is caused by only creating a single instance of registerModel outside of your for loop. You just keep editing that object over and over instead of creating new instances of it. The way to solve this is to create a new instance of registerModel every time a previous object is completed or before a new object is started.
There are multiple ways to achieve this by using nested loops or incrimenting your for loop by 5 at a time (rows in your order) and specifically keeping track of where items are at. However, if we assume that the last bit of data in an order is the "NOM_OPER" row then we can do the following quick and easy solution.
This is the code that has been changed:
if (headers.equals("NOM_OPER")){
registerModel.setTransactionID(values);
//Now that the object is complete we can add it to the list (moved here from below)
registerModelList.add(registerModel);
//The lastly we NEED to create a new instance of registerModel for the next order to use
registerModel = new RegisterModel();
}
//Remove the below line after the if statements.
//You should only add the model to the list once the object is complete. Don't add it on every row.
//registerModelList.add(registerModel);
And the complete method looks like this:
public List<RegisterModel> parse(MultipartFile file) throws IOException {
Workbook workbook = new HSSFWorkbook(file.getInputStream());
Sheet worksheet = workbook.getSheetAt(0);
List<RegisterModel> registerModelList = new ArrayList<>();
RegisterModel registerModel = new RegisterModel();
for (int i = 3; i < worksheet.getPhysicalNumberOfRows(); i++) {
Row row = worksheet.getRow(i);
String headers = String.valueOf(row.getCell(0));
String values = String.valueOf(row.getCell(1));
if (headers.equals("OPERDAY")){
registerModel.setDate(values);
}
if (headers.equals("SUIP")){
registerModel.setSuip(values);
}
if (headers.equals("STATE")){
registerModel.setSuip(values);
}
if (headers.equals("NOM_OPER")){
registerModel.setTransactionID(values);
//Now that the object is complete we can add it to the list (moved here from below)
registerModelList.add(registerModel);
//The lastly we NEED to create a new instance of registerModel for the next order to use
registerModel = new RegisterModel();
}
//Remove the below line after the if statements.
//You should only add the model to the list once the object is complete. Don't add it on every row.
//registerModelList.add(registerModel);
}
System.out.println(registerModelList);
return registerModelList;
}

Delete multiple columns in NatTable

I'm using NatTable to display table data, the table can be sorted and filtered. Since the table is quite large I also used GlazedList. I need to be able to remove columns after sorting and filtering. As I tried, I could only remove the content of the table but the header remains there. The column header is nested in many layers and I don't know I could affect or trigger a refresh on it.
My code are mostly from the examples with slight modifications:
set up the layers:
ModelProvider mp = new ModelProvider();
// property names of the Person class
this.propertyNames = new String[this.attributeNames.size() + 1];
this.propertyNames[0] = "Entry";
for (int i = 0; i < this.attributeNames.size(); i++) {
this.propertyNames[i + 1] = this.attributeNames.get(i);
}
// mapping from property to label, needed for column header labels
this.propertyToLabelMap = new HashMap<String, String>();
for (String str : this.propertyNames) {
this.propertyToLabelMap.put(str, str);
}
IColumnPropertyAccessor<GazEntry> columnPropertyAccessor = new GazColumnPropertyAccessor();
final BodyLayerStack<GazEntry> bodyLayerStack = new BodyLayerStack<GazEntry>(
mp.entrylines, columnPropertyAccessor);
IDataProvider columnHeaderDataProvider =
new DefaultColumnHeaderDataProvider(this.propertyNames, this.propertyToLabelMap);
final DataLayer columnHeaderDataLayer =
new DataLayer(columnHeaderDataProvider);
final ColumnHeaderLayer columnHeaderLayer =
new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
SortHeaderLayer<GazEntry> sortHeaderLayer =
new SortHeaderLayer<GazEntry>(
columnHeaderLayer,
new GlazedListsSortModel<GazEntry>(
bodyLayerStack.getSortedList(),
columnPropertyAccessor,
configRegistry,
columnHeaderDataLayer));
// build the column header layer
// Note: The column header layer is wrapped in a filter row composite.
// This plugs in the filter row functionality
FilterRowHeaderComposite<GazEntry> filterRowHeaderLayer = new FilterRowHeaderComposite<GazEntry>(
new DefaultGlazedListsFilterStrategy<GazEntry>(
bodyLayerStack.getFilterList(), columnPropertyAccessor,
configRegistry), sortHeaderLayer,
columnHeaderDataLayer.getDataProvider(), configRegistry);
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(
bodyLayerStack.getBodyDataProvider());
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(
rowHeaderDataProvider);
final ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer,
bodyLayerStack, bodyLayerStack.getSelectionLayer());
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(
columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer,
filterRowHeaderLayer);
IRowDataProvider<GazEntry> bodyDataProvider = (IRowDataProvider<GazEntry>) bodyLayerStack.getBodyDataProvider();
bodyLayerStack.setConfigLabelAccumulator(new CrossValidationLabelAccumulator(
bodyDataProvider));
// DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
bodyLayerStack.registerCommandHandler(new
DeleteRowCommandHandler<GazEntry>(bodyLayerStack.bodyData));
//TODO: register delete column.
bodyLayerStack.registerCommandHandler(new
DeleteColCommandHandler<GazEntry>(bodyLayerStack.bodyData));
and the command handler to delete a column
class DeleteColCommandHandler<T> implements ILayerCommandHandler<DeleteColCommand> {
private List<T> bodyData;
public DeleteColCommandHandler(List<T> bodyData) {
this.bodyData = bodyData;
}
#Override
public Class<DeleteColCommand> getCommandClass() {
return DeleteColCommand.class;
}
//TODO: delete column
#Override
public boolean doCommand(ILayer targetLayer, DeleteColCommand command) {
// convert the transported position to the target layer
if (command.convertToTargetLayer(targetLayer)) {
// remove the element
// this.bodyData.remove(command.getRowPosition());
SelectionLayer slayer = ((BodyLayerStack) targetLayer).getSelectionLayer();
int[] selected = slayer.getSelectedColumnPositions();
for (int index : selected) {
String colName = CopyOf_6031_GlazedListsFilterExample.this.propertyNames[index];
CopyOf_6031_GlazedListsFilterExample.this.attributeNames.remove(colName);
targetLayer.fireLayerEvent(new
ColumnDeleteEvent(targetLayer, index));
}
return true;
}
return false;
}
}
as said, this deletes the column content but leaves the header. Can anyone tell me how I can also remove the column header?
Do you really want to delete a column or do you simply want to hide a column? Because hiding would be much easier. Of course this depends on your use case and if your data model can be modified to really deleting a column.
Nevertheless, the DefaultColumnHeaderDataProvider does not support dynamic adding or removing columns as it is based on an array. For such an use case you need to provide a custom IDataProvider for the column header. The NatTable Examples application contains an example for that under Tutorial Examples -> Data -> DynamicColumnExample.
You simply need to implement an IDataProvider that is based on a List rather than an array, so elements can be removed and the size modified.

Fixing some content at the end of first page aspose words java

I am working with apose words java recently.
In my first page I have a table need to merge, which can grow any size, no fixed number of rows and at the end of my first page, I want to keep some content (for example contact details) to be fixed. (Note: I can't keep contact details in Footer or in foot note section because of some formatting I need to ensure which can't maintain in footer or foot note section)
On growing of table as many rows, My content is going down, But I want to fix it at the end of my first page. if table grows bigger in size, wanted to skip the content and render table in next page.
is there any solution/work around for this?
My expected results are like below....
Page 1 Start
dynamic Table row1
dynamic Table row2
dynamic Table row3
Contact Details ,wanted to fix at the end of my first page
Page 1 end
Page 2 Start
dynamic table row 4
dynamic table row 5
........
For your scenario, ideally the contact details should be set in a footer. It is possible, but very risky.
First create a new document, either in Aspose.Words or MS Word, it will be used as a template.
Add a blank table on top
Add contact details, after the blank table
Add a bookmark, after the contact details
Now, using Aspose.Words, you can check the location of the bookmark, every time you are adding a new row in the table. If bookmark is at page 1, add new row to the first table. If bookmark is at page 2, add new row to the second table. Below is the sample code that adds rows to the table, keeping the contact details fixed on page 1.
Template document: Google drive link
Java source code is given below.
public static void main(String[] args)
{
try
{
String template = Common.DATA_DIR + "Contact Template.docx";
String saveDocument = Common.DATA_DIR + "Contact with tables.docx";
String bookmarkNameContact = "ContactEnd";
// Load the template
com.aspose.words.Document wordDoc = new com.aspose.words.Document(template);
DocumentBuilder builder = new DocumentBuilder(wordDoc);
// Find the contacts bookmark
com.aspose.words.Bookmark bookmarkContact = wordDoc.getRange().getBookmarks().get(bookmarkNameContact);
// Set the table with null
com.aspose.words.Table table = null;
// Add some rows
for (int i = 0; i < 50; i++)
{
// If contacts bookmark is on 1st page, add new rows to first table
if (getBookmarkPage(wordDoc, bookmarkContact) == 1)
{
table = (com.aspose.words.Table) wordDoc.getChild(NodeType.TABLE, 0, true);
} else
{
// If the contacts bookmark is on second page, add rows to second table
table = (com.aspose.words.Table) wordDoc.getChild(NodeType.TABLE, 1, true);
// If there is no second table, create it
if (table == null)
{
table = createNewTable(wordDoc, bookmarkContact);
}
}
// Add rows dynamically to either first or second table
addRow(wordDoc, table, "some text " + i);
}
// Save the document
wordDoc.save(saveDocument);
} catch (Exception ex)
{
System.err.println(ex.getMessage());
}
}
private static com.aspose.words.Table createNewTable(com.aspose.words.Document wordDoc, com.aspose.words.Bookmark bookmarkContact) throws Exception
{
// Get the first table and clone it to create the second one
com.aspose.words.Table firstTable = (com.aspose.words.Table) wordDoc.getChild(NodeType.TABLE, 0, true);
com.aspose.words.Table table = (com.aspose.words.Table) firstTable.deepClone(true);
// Add the second table after the bookmark
bookmarkContact.getBookmarkEnd().getParentNode().getParentNode().appendChild(table);
// Delete all its rows
table.getRows().clear();
return table;
}
// Add a new row to the table
private static void addRow(com.aspose.words.Document wordDoc, com.aspose.words.Table table, String text)
{
// Create a new row
com.aspose.words.Row row = new com.aspose.words.Row(wordDoc);
row.getRowFormat().setAllowBreakAcrossPages(true);
// Add it to the table
table.appendChild(row);
// Add cells to the row
for (int iCell = 0; iCell < 4; iCell++)
{
// Create a new cell and set text inside it
com.aspose.words.Cell cell = new com.aspose.words.Cell(wordDoc);
cell.appendChild(new com.aspose.words.Paragraph(wordDoc));
cell.getFirstParagraph().appendChild(new Run(wordDoc, text));
cell.getFirstParagraph().getParagraphFormat().setSpaceAfter(0);
row.appendChild(cell);
}
}
private static int getBookmarkPage(com.aspose.words.Document wordDoc, com.aspose.words.Bookmark bookmarkContact) throws Exception
{
// Find the page number, where our contacts bookmark is
LayoutCollector collector = new LayoutCollector(wordDoc);
return collector.getStartPageIndex(bookmarkContact.getBookmarkEnd());
}
I work with Aspose as Developer Evangelist.

how to show autocomplete in gwt in tabular format with multiple column?

Following is my code but it shows only one column in autocomplete but i want shows data in tabular foramte with multiple column[In short i want to show suggestion box in tabular formate]. how i can do that?
Thanks in advance Please suggest anything..
FlowPanel panel = new FlowPanel();
initWidget(panel);
final BulletList list = new BulletList();
list.setStyleName("token-input-list-facebook");
final ListItem item = new ListItem();
item.setStyleName("token-input-input-token-facebook");
final TextBox itemBox = new TextBox();
itemBox.getElement().setAttribute( "style", "outline-color: -moz-use-text-color; outline-style: none; outline-width: medium;");
final SuggestBox box = new SuggestBox(getSuggestions(), itemBox);
box.getElement().setId("suggestion_box");
item.add(box);
list.add(item);

Itext unordered list problem

I am generating a PDF file using Itext.
I have to add an unordered list (bullet list).
I am using the following code which works fine.
List unorderedList = new List(List.UNORDERED);
unorderedList.setListSymbol("\u2022");
String lista = desc.split(":");
for (String li : lis) {
if (item.length() > 0) {
unorderedList.add(new ListItem(" " + item, ARIALFONT_SIZE_11));
}
}
PdfPCell items = new PdfPCell(new Phrase("", ARIALFONT_SIZE_11));
items.addElement(unorderedList);
table.addCell(items);
The code works fine.
The question is how I can set the space between lines in the list.
Thanks in advance!
ListItems are Paragraphs - try playing with their spacingBefore and spacingAfter settings.

Categories