ToggleGroup.selectToggle bug? - toggle

When calling ToggleGroup.selectToggle(Toggle toggle) for a RadioButton that is actually already selected, then this RadioButton becomes unselected. I feel this is a bug, anyone can confirm this?
toggle.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<VBox prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml" fx:controller="com.example.ToggleDemoController">
<children>
<RadioButton mnemonicParsing="false" selected="true" text="First RadioButton">
<toggleGroup>
<ToggleGroup fx:id="myToggleGroup" />
</toggleGroup>
</RadioButton>
<RadioButton mnemonicParsing="false" text="Second RadioButton" toggleGroup="$myToggleGroup" />
</children>
</VBox>
ToggleDemoController:
package com.example;
import javafx.fxml.FXML;
import javafx.scene.control.ToggleGroup;
public class ToggleDemoController
{
#FXML
private ToggleGroup myToggleGroup;
// Implementing Initializable Interface no longer required according to
// http://docs.oracle.com/javafx/2/fxml_get_started/whats_new2.htm
#SuppressWarnings("unused") // only called by FXMLLoader
#FXML
private void initialize()
{
// Select the currently selected toggle (that is the first RadioButton) again.
// This unselects the first RadioButton, while one would expect it to stay selected.
myToggleGroup.selectToggle(myToggleGroup.getSelectedToggle());
}
}
Code also available at http://codestefan.googlecode.com/svn/trunk/ToggleDemo
Thanks for any hint!
Update:
Here's a workaround I figured out:
Instead of
myToggleGroup.selectToggle(myToggleGroup.getSelectedToggle());
use
Toggle selectedToggle = myToggleGroup.getSelectedToggle();
int selectedToggleIndex = myToggleGroup.getToggles().indexOf(selectedToggle);
myToggleGroup.getToggles().get(selectedToggleIndex).setSelected(true);
or in other words: Instead of ToggleGroup.selectToggle use Toggle.setSelected. Guess one doesn't need all the index stuff in that case, but given an index stored in a database I need to select a Toggle on restoring my application, so this is adjusted to my case.
Probably(!) workaround 2:
Acess the control behind the Toggle, e.g. a RadioButton, and unselect that one programmatically. See Link between Toggle and e.g. the RadioButton behind it?.

Yes. You have found a bug.
File it against the runtime project at: http://javafx-jira.kenai.com
Make sure you include a link back to this case which provides some reproducible sample code as it seems some similar issues have already been closed because the developers were unable to reproduce the issue.
Here is a some sample code which replicates the bug using just Java and no FXML - the behaviour with JavaFX 2.2.5 and Java8b76 is strange and buggy IMO:
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.*;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class ToggleTest extends Application {
#Override public void start(Stage primaryStage) {
final ToggleGroup tg = new ToggleGroup();
RadioButton radio1 = new RadioButton("1");
radio1.setId("1");
radio1.setToggleGroup(tg);
RadioButton radio2 = new RadioButton("2");
radio2.setId("2");
radio2.setToggleGroup(tg);
tg.selectToggle(radio1);
// radio1.setSelected(true);
Button button = new Button("Select 1");
button.setOnAction(new EventHandler<ActionEvent>() {
#Override public void handle(ActionEvent t) {
System.out.println("Selected Toggle Before Select: " + tg.getSelectedToggle() + " isSelected? " + tg.getSelectedToggle().isSelected());
tg.selectToggle(tg.getSelectedToggle());
System.out.println("Selected Toggle After Select: " + tg.getSelectedToggle() + " isSelected? " + tg.getSelectedToggle().isSelected());
}
});
VBox layout = new VBox(10);
layout.getChildren().addAll(radio1, radio2, button);
layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;");
primaryStage.setScene(new Scene(layout));
primaryStage.show();
}
public static void main(String[] args) { launch(args); }
}
Program output after repeated button presses:
Selected Toggle Before Select: RadioButton[id=1, styleClass=radio-button] isSelected? true
Selected Toggle After Select: RadioButton[id=1, styleClass=radio-button] isSelected? false
Selected Toggle Before Select: RadioButton[id=1, styleClass=radio-button] isSelected? false
Selected Toggle After Select: RadioButton[id=1, styleClass=radio-button] isSelected? false
Selected Toggle Before Select: RadioButton[id=1, styleClass=radio-button] isSelected? false
Selected Toggle After Select: RadioButton[id=1, styleClass=radio-button] isSelected? false

Related

Unable to hold on an element on mouse hover

There is a mouse hover drop-down where the drop-down appears on hover and disappears if the mouse pointer is moved way from the drop-down. I tried using "Actions" class to hover on the drop-down element but i cannot see the drop-down after the mouse hover is performed. The drop-down doesn't stay till the next action is performed.
Is there any way where there is a wait after the hover is performed so that the drop-down appears for a longer time in order to select/click elements from the drop-down?
Code:
driver= new ChromeDriver();
driver.get("w3schools.com/howto/howto_css_dropdown.asp");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
WebElement element = driver.findElement(By.xpath(".//*#id='main']/div[3]/button")‌​);
Actions action= new Actions(driver);
action.moveToElement(element).perform();
Thread.sleep(5000);
Environment:
Chrome version: 56.0.2924.87 (64-bit)
Chrome driver: 2.27
Use same code that you wrote for mouse hover action and try following solution before mouse hover action.
Keep mouse cursor on task bar.
OR
Move mouse cursor at (0, 0) browser location.
After perform() you need to traverse through the elements.
Here is the working code:
package demo;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class MouseHoverDemo_w3school {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.w3schools.com/howto/howto_css_dropdown.asp");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement ele = driver.findElement(By.xpath(".//div[#class='dropdown dropdown2']/button"));
Actions act = new Actions(driver);
act.moveToElement(ele).perform();
List<WebElement> links = driver.findElements(By.xpath(".//div[#class='dropdown-content']/a"));
int total_count = links.size();
for (int i=0; i<total_count; i++)
{
WebElement element = links.get(i);
String text = element.getAttribute("innerHTML");
System.out.println("Link Name is : "+text);
}
driver.quit();
}
}
Let me know if this answers your question.

When using JavaFX with Scala for-loops and map cause FXML-Binding to fail

I'm using JavaFX + FXML together with Scala to build a GUI but I get a NullPointerException in the Controller for all Controls from the FXML-file when I use a for-loop or a mapping (of a Scala Collection).
Info: I programmed the exact same example completely in Java and used a for-loop and it worked. It only fails with Scala.
I constructed a very simple FXML + Controller so you can reproduce the Failure (you need to out-comment one of the loops to test it).
Here's my simple FXML (example.fxml):
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.GridPane?>
<GridPane fx:id="grid" prefHeight="289.0" prefWidth="473.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="application.Controller2">
</GridPane>
and here's the Controller2.scala:
package application
import javafx.fxml.FXML
import javafx.scene.layout.{ GridPane, ColumnConstraints }
import javafx.scene.shape.Rectangle;
class Controller2 {
#FXML private var grid: GridPane = _
#FXML def initialize = {
println(grid)
// doesn't work
for (i <- 0 until 100) {
grid.getColumnConstraints().add(new ColumnConstraints(100));
grid.add(new Rectangle(10, 10), i, 0);
}
// works
var i = 0
while (i < 100) {
grid.getColumnConstraints().add(new ColumnConstraints(100));
grid.add(new Rectangle(10, 10), i, 0);
i = i + 1
}
}
}
Any insight into this matter would be highly appreciated

Alfresco - Approve task in a workflow

I'm integrating an applet on a workflow in the Alfresco. I created a new button org/alfresco/components/form/controls/workflow/activiti-transitions.ftl here
...
<button onclick="changePDF(); this.disabled=true; return false;"> Change </button>
<div id="pdfTexto" style="width:1000px;height:1000px"></div>
<div class="applet">
<script type="text/javascript">
deploy();
</script>
</div>
</#if>
And this button change (through the javascript of the applet) calls the functionality of the applet that is make changes in the file of the respective workflow. After this, I want to put "Approved" like the button accept standard does. But, I only want to make this after the changes make effect. My applet returns a "ok" when the changes are completed (the POST request is completed), after this, I want to put "Approved" and redirect to the same page that "accept" button redirects. In resume, after "ok", make what the accept button does.
My applet updates the content of an exiting document with:
http://localhost:8080/share/proxy/alfresco/api/upload ...
How can I make this? Any hints for a better solution then the below?
Evolution:
I'm trying to make this:
var form = new FormData();
form.append("prop_wf_reviewOutcome","Approve");
form.append("prop_bpm_comment","good");
form.append("prop_transitions","Next");
var requestTask = new XMLHttpRequest();
requestTask[Alfresco.util.CSRFPolicy.getHeader()] = Alfresco.util.CSRFPolicy.getToken();
requestTask.open("POST", "http://localhost:8080/share/proxy/alfresco/api/task/"+ taskidVar+ "/formprocessor" + "?" + Alfresco.util.CSRFPolicy.getParameter() + "=" + encodeURIComponent(Alfresco.util.CSRFPolicy.getToken()));
requestTask.send(form);
But lack redirect the page as the "Approve" button.
First of all, you need to define your behaviour:
package com.someco.alfresco.policy;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.ContentServicePolicies;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class DocumentUpdatePolicy implements ContentServicePolicies.OnContentUpdatePolicy {
private final Log logger = LogFactory.getLog(getClass());
private PolicyComponent policyComponent;
private NodeService nodeService;
public void init() {
this.policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onContentUpdate"),
ContentModel.TYPE_CONTENT,
new JavaBehaviour(this, "onContentUpdate", Behaviour.NotificationFrequency.EVERY_EVENT));
}
#Override
public void onContentUpdate(NodeRef nodeRef, boolean newContent) {
logger.debug("Called on: " + nodeRef);
if (null == nodeRef || !nodeService.exists(nodeRef)) {
logger.error("Wrong nodeRef");
/* This can happen in some circumstances */
/* Do you want to just ignore it or do something ? You decide */
return;
}
/* Here goes the code to update the task */
}
public void setPolicyComponent(final PolicyComponent policyComponent) {
this.policyComponent = policyComponent;
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
}
Than you need to initialise it in your custom Spring context:
<bean id="onDocumentUpdatePolicy" class="com.someco.alfresco.policy.DocumentUpdatePolicy">
<property name="policyComponent">
<ref bean="policyComponent" />
</property>
<property name="nodeService">
<ref bean="NodeService" />
</property>
</bean>

Adding combo box on toolbar of eclipse using Eclipse plug-in development API

I want to add a combo box to the toolbar (coolbar) of eclipse using Eclipse Plug-in development API (not an RCP application). This combo box items should be dynamically added/removed.
I know that in RCP applications it is possible by following the link : http://www.thedeveloperspoint.com/?p=140
but I am looking at Eclipse plugin API.
Any help would be greatly appreciated.
Thanks Syam
This can be done by using 2 steps.
STEP 1: By using extension point mechanism create/add toolbar to the global toolbar (using locationURI as "toolbar:org.eclipse.ui.main.toolbar")
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="com.company.module.toolbar"
label="Sample">
<control
class="com.company.module.ui.ComboToolbarContribution"
id="ratata">
</control>
</toolbar>
</menuContribution>
</extension>
STEP 2: Implement the ComboToolbarContribution as follows.
package com.company.module.ui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
public class ComboToolbarContribution extends
WorkbenchWindowControlContribution {
private Combo mReader;
public ComboToolbarContribution() {
}
#Override
protected Control createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
GridLayout glContainer = new GridLayout(1, false);
glContainer.marginTop = -1;
glContainer.marginHeight = 0;
glContainer.marginWidth = 0;
container.setLayout(glContainer);
GridData glReader = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
glReader.widthHint = 280;
mReader = new Combo(container, SWT.BORDER | SWT.READ_ONLY
| SWT.DROP_DOWN);
mReader.setLayoutData(glReader);
return container;
}
#Override
protected int computeWidth(Control control) {
return 300;
} }
With the above 2 steps a combo box will be added to the global toolbar and user need to provide the global access to the combo box.
To avoid headaches.. if anybody is facing the issue that eclipse only draws 7px height of the control I want to point to a workaround:
https://www.eclipse.org/forums/index.php/t/1076367/
Add another contribution with an icon to the same toolbar (i.e. com.company.module.toolbar) to reserve enough space.
As #Jonny mentioned above it may be necessary to reserve some space.
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar id="new">
<control
class="org.xy.composite.NewComposite"
id="org.xy.composite.newcomposite.id">
</control>
<command
commandId="newcomposite"
icon="resources/nothing.png"
label="nix"/>
</toolbar>
</menuContribution>
And with the command this is possible

Windows 7 SWT COMBO Issue

I am facing an issue with the SWT Combo in my eclipse RCP application.
I will try explaining my issue with a use case for better understanding.
I have a combo box in a Eclipse RCP View with values say "A", "B","C","D" and i have a submit button beside it & a SWT table right below it.
Once the value is changed in the Combo and submit button is clicked, records would be displayed in the table.
Let us suppose "A" is selected by default and records of A are displayed in the table on view invocation.
Now I select "B" from the drop down and click submit. I see only the records of "A" in the table although the combo shows "B".
ONLY if I select "B" again from the combo and then click submit, "B"'s records gets displayed.
Now if I select C from the combo , only "B"'s records gets displayed.
Later, If i select D from the Combo , "C"'s records are displayed.
It seems that only the previous selections is processed and displayed rather than the current selection.
I am not facing this issue in Windows XP or prev versions of windows. I recently shifted to Windows 7 64-bit OS where I faced this issue.
Is this a known issue? Any help would be appreciated.
You use a drop down listener for storing the selected index. The drop down listener is triggered when the combo list drops down. At this time, the old selection is stored. If you select a new item in the list, the listener will not be triggered again. Though you always get the previous selected item index if you press the submit button later on.
To get what you want, you must use a selection listener instead of the drop down listener and all works fine. The selection listener is called when you select an item in the drop down list. Just replace SWT.DropDown with SWT.Selection.
filter.addListener(SWT.Selection, new Listener() {...});
Please find the sample code below
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
public class TestCombo {
private static String[] filterByText = new String[] {"A","B","C","D"};
static int index = 0;
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Composite comp = new Composite(shell, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
GridData gridData = new GridData(SWT.FILL,SWT.FILL,true,false);
comp.setLayout(layout);
comp.setLayoutData(gridData);
final Combo filter = new Combo (comp, SWT.READ_ONLY);
filter.setItems (filterByText );
filter.setText (filterByText[0]);
filter.setVisibleItemCount( filterByText.length );
filter.addListener(SWT.DROP_DOWN, new Listener() {
#Override
public void handleEvent(Event event) {
index = filter.getSelectionIndex();
}
});
Button submit = new Button (comp, SWT.PUSH);
submit.setText ("Submit");
GridData data = new GridData();
data.widthHint = 80;
submit.setLayoutData(data);
submit.addSelectionListener (new SelectionAdapter () {
public void widgetSelected(SelectionEvent e) {
System.out.println("The index is ==> "+index);
}
});
comp.pack();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}