I am developing a application in GWT using the decorated tab panel. I have implemented a close option for the tabs. Now my problem is that when I close one tab and try to add some data in the other tab it is taking the wrong index.
For example: I have 4 tabs and close the third one. I open 4th tab and try to add something there, but its index is showing as 3 instead of 4 as there are only 3.
How can I reset the tab index in the program, or else any solution where I can read the correct index of tab as it was before removing it?
This is where i am adding the new tab and the close event.
HorizontalPanel horizontalPanel = new HorizontalPanel();
Image image = new Image();
Label label = new Label("New Report: " + k);
label.setWordWrap(false);
horizontalPanel.add(label);
horizontalPanel.add(image);
image.setUrl("images/1305803163_close.png");
tabpanel.add(newTab[k], horizontalPanel);
tabindexx[k] = k;
image.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
tabpanel.remove(tabpanel.getTabBar().getSelectedTab());
}
});
and in some part of the code I am accessing the tab index like this
int selectedtab = tabpanel.getTabBar().getSelectedTab();
Of course this will return an index based on the number of tabs present at that particular moment, so I need to store them somewhere or else I have to reset the tab index after I close.
That will happen because the index number is the index for the current set of tabs. (if one closes, it obviously impacts the others).
I am a little rusty with GWT now, but i believe the only way to remove or select tabs is using index.
One solution could be to manage a List of tab representatives (some tab identifier) in your code, and do a mirror remove in that list when a delete occurs in your code. Then you can lookup the new index of the tab that you want to update after the delete and get the right index. (Tab identifier can be as simple as the original index of the tab when you started before any deletes)
Related
I would like to programmatically open an MPart in a new MWindow.
Similar to as if I would create the part in a partstack somewhere in the existing window and then manually drag it away with the mouse.
So, one way would be to create a non-rendered window which contains this part. And once it should be shown, we can set it to being rendered. But: once we close this window, we cannot bring it back?!
This approach worked for me:
Define an empty window in the e4xmi which is set to not be rendered
Once we want to display the part, we create it (if it is not open already) and add it to the window
MUIElement window = modelService.find(myWindowId, app);
MPart part = (MPart) modelService.find(myPartId, application);
if (part == null) {
part = MBasicFactory.INSTANCE.createPart();
part.setLabel(ProcedureFlowChartPart.PART_TITLE);
part.setContributionURI("bundleclass://MyPartPath");
part.setElementId(myPartId);
((MWindow) window).getChildren().add(part);
}
partService.showPart(part, PartState.ACTIVATE);
window.setToBeRendered(true);
modelService.bringToTop(window);
I have downloaded familyTree project and it doesn't have the ability to search for an specific family member!
I have added a search button to it, and in the handler method section, I need the code that searches for a member that has the specified socialID , and select it (scroll it to the sight, and make it blue (selected)). But I don't know how to programmatically select a treeItem, and make it visible and selected?
My code:
#FXML
private void btnSearch_click(ActionEvent event){
for(TreeItem<FamilyMember> treeItem:root.getChildren()){
if(treeItem.getValue().getNationality().toString()=="22"){
// treeView.setSelectionModel(item);
treeView.getSelectionModel().select(treeItem);
//it still doesnt select the item with nationality=="22"
break;
}
}
}
You can select the item with
treeView.getSelectionModel().select(item);
and if you still need to scroll (I think selecting it might automatically scroll to it), do
treeView.scrollTo(treeView.getRow(item));
A couple of notes:
I do not understand the for loop. Why are you doing
TreeItem<FamilyMember> item = root.getChildren().get(i);
and why are you creating the index i? What is wrong with the treeItem variable you already defined in the loop syntax? Isn't this necessarily exactly the same thing as item?
You need to read How do I compare strings in Java?
In my winfom program I have a function that change the tabpage when I hit a key.
On tabcontrol indexchanged I check for some parametre and if they are not correct I change the tabpage to the first tab.
If I click on the page with the mouse the tabpage changed to the first tab with the correct content.
If I click a key and run this code "tcOrdre.SelectedTab = tpOrdre;" it changes the tab back to the first but still showing the content of the selected one.
In SelectedIndexChanged is use this code:
MessageBox.Show("Der skal vælges en ordre først"); // Show a messagebox
tcOrdre.SelectedTab = tpOrdreListe; // change tap to first
If I use the mouse then SelectIndexChanged get called when I run:
tcOrdre.SelectedTab = tpOrdreListe; // change tap to first
the SelectedIndexChanged function is called again and the content is okay.
But if I use the key to change index the SelectedIndexChanged does not get called Again and the content never change. Only the tab in the top change to the first one.
I hope someone can help me.
I found the solution.
All I have to do is call this line.
this.BeginInvoke(new Action(() => tcOrdre.SelectTab(0)));
and not tcOrdre.SelectedTab = tpOrdreListe;
And everything Works fine.
I am working in PyQt. The existing code (extremely long and sources almost all the org.'s s/w) has sections which is responsible for creating tabs and textboxes. But, being a newbie to PyQt, I am not clear on how it all works. For my part, I need to do the following:
(1) Create a TAB titled 'xyz' within the row of all the other tabs.
(2) Create 6 textboxes with individual labels in the page displyed by the created TAB where the user can enter data and save it.
These are the two immediate problems I have to deal with now. Later,
The data entered in the textboxes will replace the data in bar-graphs (in another window) as soon as the data in the textboxes is entered and saved. This is to be done afterwards but first I need to solve the 2 issues listed above. The imports are all there in the (longish) code and I have to insert my new code within that code - perhaps by creating a new class. Can you help? Thanks. And, please let me know if you need any information to work on this.
EDIT::::::::::: Have inserted the image below. As you can see, at the top of the left pane, there are multiple tabs in a row (all made in PyQt). I need to create a tab like the last one (here, titled-Incentives) with a blank page like the one shown below the tab. Within the page, I need to create 2 sets of textboxes, 3 textboxes in each set with labels for the set(s) and the individual textboxes. Data entered in the boxes will be integers(20) and the data will then go on to populate/update a dynamic stacked bar graph. At this point, I want to ask another question. When the data updates the graph, should it be first saved in the DB (the DB which is primarily responsible for the initial figures in the graph) and then routed to the graph or should the data update the graph directly, bypassing the DB and if so, won't the graph revert to its earlier values and forget the data from the textboxes once it is reset. Thank you.
OK. Here you have a code that you can use as a starting point for your own development. It creates a QTabWidget with two tabs. The "Tab 1" tab contains a vertical layout with two groupboxes. Groupboxes contain labels and textboxes arranged in a grid. The other tab is empty.
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class MyMainWindow(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
# Create the tabbed widget
self.central = QTabWidget(self)
self.setCentralWidget(self.central)
# Create a new tab
self.tab1 = QWidget()
# Tab has a vertical layout
self.vbox = QVBoxLayout(self.tab1)
# Tab children: two groups containing a grid of labels and textboxes
self.group1 = QGroupBox("Group 1")
self.textBox1 = QLineEdit(self.group1)
self.textBox2 = QLineEdit(self.group1)
self.fillGroup(self.group1, self.textBox1, self.textBox2)
self.group2 = QGroupBox("Group 2")
self.textBox3 = QLineEdit(self.group2)
self.textBox4 = QLineEdit(self.group2)
self.fillGroup(self.group2, self.textBox3, self.textBox4)
# Add tab children to the tab layout
self.vbox.addWidget(self.group1)
self.vbox.addWidget(self.group2)
# Append tab to the tabbed widget
self.central.addTab(self.tab1, "Tab 1")
# Create a new tab and append it to the tabbed widget
self.tab2 = QWidget()
self.central.addTab(self.tab2, "Tab 2")
def fillGroup(self, group, box1, box2) :
"""Arrange the groupbox content in a grid layout"""
grid = QGridLayout(group)
label1 = QLabel("Input 1:", group)
grid.addWidget(label1, 0, 0)
grid.addWidget(box1, 0, 1)
label2 = QLabel("Input 2:", self.group1)
grid.addWidget(label2, 1, 0)
grid.addWidget(box2, 1, 1)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
ui = MyMainWindow()
ui.show()
sys.exit(app.exec_())
Please notice that for my convenience I've used a QMainWindow as a parent for the tabbed widget. Obiously you can use other widgets as parent if you need it.
Hope it helps.
I am using GWT 2.4's new DataGrid in a project. I configured the DataGrid with a pagesize of 50.
The available screen is not big enough to display all items and thus a vertical scrollbar is shown (this is actually the main purpose for using a DataGrid in the first place).
I attached a SingleSelectionModel to the DataGrid in order to be able to select items.
This works fine so far.
However I also have another widget with which the user can interact. Based on that user action a item from the DataGrid should be selected.
Sometimes the selected item is not in the visible screen region and the user has to scroll down in the DataGrid to see it.
Is there any way to automatically or manually scroll down, so that the selected item is visible?
I checked the JavaDocs of the DataGrid and found no appropriate method or function for doing that.
Don't know if this works, but you could try to get the row element for the selection and use the scrollIntoView Method.
Example Code:
dataGrid.getRowElement(INDEX_OF_SELECTED_ITEM).scrollIntoView();
The answer above works pretty well, though if the grid is wider than your window and has a horizontal scroll bar, it also scrolls all the way to the right which is pretty annoying. I was able to get it to scroll down and stay scrolled left by getting the first cell in the selected row and then having it scroll that into view.
dataGrid.getRowElement(dataGrid.getVisibleItems().indexOf(object)).getCells().getItem(0).scrollIntoView();
Don't have time to try it out, but DataGrid implements the interface HasRows, and HasRows has, among other things, a method called setVisibleRange. You just need to figure out the row number of the item that you want to focus on, and then set the visible range from that number n to n+50. That way the DataGrid will reset to put that item at the top (or near the top if it is in the last 50 elements of the list backing the DataGrid). Don't forget to redraw your DataGrid.
Have you already looked at this? If so, I'd be surprised that it didn't work.
Oh, and since this is one widget talking to another, you probably have some messaging set up and some message handlers so that when the user interacts with that second widget and "selects" the item, the message fires on the EventBus and a handler for that message fixes up the DataGrid along the lines I've described. I think you'll have to do this wiring yourself.
My solution, a little better:
dataGrid.getRow(model).scrollIntoView();
I got a Out of bounds exception doing the above.
I solved it getting the ScrollPanel in the DataGrid and used .scrollToTop() and so on on the ScrollPanel. However, to access the ScrollPanel in the DataGrid I had to use this comment:
http://code.google.com/p/google-web-toolkit/issues/detail?id=6865
As Kem pointed out, it's annoying the "scrollToRight" effect after the scrollIntoView. After me, Kem's solution gives a better behaviour than the base one as usually the first columns in a table are the more meaningful.
I improved a bit his approach, which scrolls horizontally to the first column of the row we want to be visible, by calculating the first visible column on the left before applying the scroll and then scrolling to it.
A final note: Columns absolute left is tested against "51". This is a value I found "experimentally" by looking the JS values in the browser's developer tool, I think it depends on the table's style, you may need to change/calculate it.
Below the code:
public void scrollIntoView(T next) {
int index = datagrid.getVisibleItems().indexOf(next);
NodeList<TableCellElement> cells = datagrid.getRowElement(index).getCells();
int firstVisibleIndex = -1;
for(int i=0; i<cells.getLength() && firstVisibleIndex<0;i++)
if(UIObject.isVisible(cells.getItem(i)) && (cells.getItem(i).getAbsoluteLeft() > 51) && (cells.getItem(i).getAbsoluteTop() > 0))
firstVisibleIndex = i;
cells.getItem(firstVisibleIndex>=0? firstVisibleIndex : 0).scrollIntoView();
}