I have a JTabbedPane in Java (Swing Layout) with 3 tabs with a table on each tab. I also added a ChangeListener(stateChanged) to remove the table filter when the tab is changed by the user. No my problem is, that I want to remove the filter on the tab I am leaving, so I need the index of my previous tab or perform the action right before the moment the tab is changed.
Now my question is there a possibility to get the tab Index of the previous selected tab? I only get the newly selected tab by using the ChangeListener(stateChanged)?
Below my code:
tabPane.addChangeListener(
new ChangeListener() {
// Reset Search and Filter when tab is changed
public void stateChanged(ChangeEvent e) {
tabPane.getSelectedComponent().requestFocusInWindow();
clearFilter(tabPane.getSelectedIndex())
}
});
I tried to store the previous selected tab in a variable but it did not work.
Related
There are 3 categories of users: Authorized, Non-Authorized and Total Users. Users can be created through UI and by default the users will be displayed in the Non-Authorized section. There is a Toggle button available for users on each of the 3 page sections. When user clicks on the toggle button for a user from Non-Authorized section the user entry goes in the Authorized page.
Automation Requirement is to click on every toggle button of the user, check if all the buttons are clicked and then navigate to page users to check if all users are added.
The problem is that the when the toggle button is clicked of any user the top/bottom record HTML position gets replaced with the preceeding one.
eg: if the path of the 1st toggle button is //[#id='xyz']/td1 and user clicks on this toggle button the next user records toggle buttons path now becomes same as above i.e//[#id='xyz']/td1
Below is the html code of the toggle switch:
<span class="bootstrap-switch-handle-off bootstrap-switch-default" style="width: 20px;"></span>
I have tried to add Thread.sleep() after every toggle button click so that there is a delay and then my code can click on the next toggle switch using the same path but was wondering if there is a optimized way to handle this scenario.
Any Suggestions?
Try to click first toggle and wait until it disappears inside while loop with any toggle exists condition:
WebDriverWait wait = new WebDriverWait(driver, 10);
while (driver.findElements(By.cssSelector(".bootstrap-switch-handle-off")).size() > 0) {
WebElement toggle =
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".bootstrap-switch-handle-off")));
toggle.click();
//wait.until(ExpectedConditions.invisibilityOf(toggle));
wait.until(d -> {
try {
return !toggle.isDisplayed();
} catch (StaleElementReferenceException ignored) {
return true;
}
});
}
I need to create drag and drop for my app.
I have a tree in the left part of the window and empty editor area in the right part of the window. I want to drag an element from the tree and drop to the right part.
Editor tab should opens after that.
What I have already done:
I created the button to open editor of selected tree item and it works. When I drag item and drop it to the existed editor a new editor opens.
But I can't to do the same when I don't have any editor (only empty editor area)
Please tell me what should I do or what should I specify like target for drop action. Thanks in advance!
In your RCP's worbench window advisor class you need to set up the editor area drag/drop transfer types and the drop adapter in the preWindowOpen method.
For example Eclipse itself uses:
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.addEditorAreaTransfer(EditorInputTransfer.getInstance());
configurer.addEditorAreaTransfer(ResourceTransfer.getInstance());
configurer.addEditorAreaTransfer(FileTransfer.getInstance());
configurer.addEditorAreaTransfer(MarkerTransfer.getInstance());
configurer.configureEditorAreaDropListener(new EditorAreaDropAdapter(
configurer.getWindow()));
Note that EditorAreaDropAdapter is an internal class so you can't use it, you will have to write your own drop adapter. This is likely to end up calling IWorbenchPage.openEditor
I've created a suggest box and generated HTML page with huge text, so I can scroll.
1. Show suggest list
2. Scroll page
The popup box with suggestion list moves with scrolled page, but I want that it will neither hide when page scrolls nor move with page.
As I understand that suggest popup has absolute position. But is there some non css solution.
Answer to:
I've tried add scroll handler to Window, but I've found out that handle only event when I have and right of them moves, only in this case. If I have one scroll to scroll page like in case with large text - nothing invokes
When constructing a SuggestBox you can provide your own SuggestOracle, TextBox and SuggestionDisplay. DefaultSuggestionDisplay can be used to hide suggestion list. You can do it in Window.scrollHandler.
Here is the code:
MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
oracle.add("one");
oracle.add("two");
oracle.add("three");
TextBox box = new TextBox();
final DefaultSuggestionDisplay display = new DefaultSuggestionDisplay();
SuggestBox suggestBox = new SuggestBox(oracle, box, display);
Window.addWindowScrollHandler(new ScrollHandler() {
#Override
public void onWindowScroll(ScrollEvent event) {
display.hideSuggestions();
}
});
Note, that you need to use DefaultSuggestionDisplay - see documentation on deprecated hideSuggestionList method.
I hope that the example explains it all.
I've also checked that if you don't use own SuggestionDisplay it uses DefaultSuggestionDisplay anyway. So you can do it even simpler.
((DefaultSuggestionDisplay) suggestBox.getSuggestionDisplay()).hideSuggestions();
EDIT:
If not the whole window is scrolled but only content of some panel, you can add a ScrollHandler to the panel:
panel.addDomHandler(new ScrollHandler() {
#Override
public void onScroll(ScrollEvent event) {
((DefaultSuggestionDisplay) suggestBox.getSuggestionDisplay()).hideSuggestions();
}
}, ScrollEvent.getType());
Please look into the attached screenshot
I need to select all the data in 1st box at one time.Currently it allows me to select First name and then click on Arrow and then i need to click on Middle name and click on Arrow to move to box 2.I need to do individually for all the data in Box1 to move to Box2.Also i tried drag and drop Its not working Even manually also its not allowing to drag/drop from Box1 to Box2
Can we select all the elements in the box 1 at a time and then click on arrow to move to box2?Please help me out with this issue..
(Note : Below is the Html code for the Box 1)
`
As per provided comment xpath
/html/body/div[4]/div/div[2]/div[2]/div/form/table/tbody/tr[1]/td[1]/select/option
will retrieve list of all options nothing but list of webelements. so use findElements here and collect that list
List<WebElement> elements = driver.findElements(By.xpath("/html/body/div[4]/div/div[2]/div[2]/div/form/table/tbody/tr[1]/td[1]/select/option"));
//use loop here
System.out.println(elements .size());
for(int i=0;i<=elements .size();i++) {
//use click on option
driver.findElement(By.xpath("/html/body/div[4]/div/div[2]/div[2]/div/form/table/tbody/tr[1]/td[1]/select/option")).click(); //it will click first option by default
//write command to click on arrow
//so it will loop upto list size nothing number of options and always select first and clicks on >>
}
thank you,
Murali
You can achieve this solution very easy by Jquery.
the following code very useful to you.
$().ready(function()
{
$('#right_arrow_id').click(function()
{
return
!$('#firstboxid_here option:selected').clone(true).appendTo('#second_box_id_here');
});
for removing options from second box.
$('#left_arrow_id_here').click(function()
{
$('#second_box_id_here option:selected').remove();
});
});
By looking at the first xpath "/html/body/div[4]/div/div[2]/div[2]/div/form/table/tbody/tr[1]/td[1]/select/option[i]", I understood that it is implemented like a dropdown. Hence, you can use "Select" class in selenium. Please find the below code for the same.
// Initializing the Select class
Select names = new Select(driver);
// Retrieving all the options in the dropdown
List<WebElement> allNamesList = names.getOptions();
// Looping through the list
for(WebElement eachName : allNamesList) {
// Clicking on each element in the first box
eachName.click();
// Your Code to click on Arrow button
}
Hope this helps.
I m a newbie in Vaadin and I am using a TabSheet where I attach some tabs. I was wondering if I could get some more functionality from their captions.
For instance, when a tab is selected and the user clicks its caption then a dropdown menu can appear.
I have already experimented with the existing listeners of TabSheet and I concluded that I have to make a custom listener. The thing is that I cannot find a way to fire the event when I click on the selected tab caption...
You could use SelectedTabChangeListener on a TabSheet. It would fire the event when the caption is clicked, and you could reselect your current tab, etc.. It would be cumbersome.
Why not use the MenuBar? Isn't it exactly what you want? https://demo.vaadin.com/valo-theme/#!menubars
I had the same problem (Vaadin 7.4), what you can do is you can surround the tab caption with a <div onclick="...">captionText</div> and add a JavaScript callback function:
final TabSheet sheet = new TabSheet();
sheet.setTabCaptionsAsHtml(true); // don't forget this!
// This is the callback
JavaScript.getCurrent().addFunction("clickedTab", new JavaScriptFunction() {
#Override
public void call(JsonArray arguments) {
LOGGER.info(arguments.getString(0)); // this is 'some identifier'
}
});
final TabSheet.Tab tab = sheet.addTab(component, "<div onclick=\"clickedTab('some identifier');\">captionText/div>");