How to configure intellij vaadin import settings? - java

I am trying to develop a vaadin application with maven in idea, but all listener methods calls its own object like above
Button btn = new Button("click!");
btn.addClickListener(new **Button**.ClickListener() {
#Override
public void buttonClick(**Button**.ClickEvent clickEvent) {
Notification.show("ok!");
}
});
i want to looks like that
Button btn = new Button("click!");
btn.addClickListener(new ClickListener() {
#Override
public void buttonClick(ClickEvent clickEvent) {
Notification.show("ok!");
}
});
how can i modify idea settings?

On Settings->Editor->Code Style->Java, select the "Insert imports for inner classes" check box (off by default). Then IntelliJ IDEA will automatically add static imports for Button.ClickListener and Button.ClickEvent.

Related

JavaFX button not responding on first click

public void handle(){
submit.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
LoginConnection login = new LoginConnection();
boolean pass = login.login(usernameField.getText(), passwordField.getText());
if(pass)
flip(SceneNames.Main);
else
invalLoginMessage.setOpacity(1.00);
}
});
register.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
flip(SceneNames.Register);
}
});
}
When i click on submit or register, it takes two click for it to do anything. How do i fix this?
What happens is that on first click it adds the handlers specified in the method and on second and consecutive clicks, it uses the handlers. To fix it just create separate methods to add through fxml or scene builder.

GWT Tree: selection Listener

I'm trying to add a SelectionListener<TreeItem> on my Tree using the addSelectionHadler() method.
For my proof on onSelection(SelectionEvent<TreeIterm> event) I put a simple Windows.alert() but it don't do anything: when I select a treeItem that color change but doesn't open the window.
I write the Handler but if you want more code tell me.
Thank you.
class SelHand implements SelectionHandler<TreeItem> {
#Override
public void onSelection(SelectionEvent<TreeItem> event) {
Window.alert(event.getSelectedItem().getText());
}
}
SelHand selezionatore = new SelHand();
tree.addSelectionHandler(selezionatore);
Use the straightforward:
tree.addSelectionHandler(new SelectionHandler<TreeItem>() {
#Override
public void onSelection(SelectionEvent<TreeItem> event) {
Window.alert(event.getSelectedItem().getText());
}
});

How to click on a javafx slider

I have a question.
I am creating an audiplayer, almost everything is finished, but I have a small problem.
I can use the slider, but I can only slide it, clicking doesn't work.
How can i fix this, i have seen some solutions for JavaFX but not for a javaFX application which uses FXML (I am using FXML).
Thank you very much!
Slider has a method setOnMouseReleased(EventHandler<? super MouseEvent> value), which means you can easily add a MouseEvent handler for clicking the slider:
mySlider.setOnMouseReleased((MouseEvent event) -> {
// do whatever has to be done
});
Something like this:
timeSlider.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
timeSlider.setValueChanging(true);
double value = (event.getX()/timeSlider.getWidth())*timeSlider.getMax();
timeSlider.setValue(value);
timeSlider.setValueChanging(false);
}
});
This would also cause your value property listener to fire if you have any registered. You can register one like this:
timeSlider.valueProperty().addListener(new InvalidationListener() {
public void invalidated(Observable ov) {
if (timeSlider.isValueChanging()) {
//do something here
}
}
}

How to save selected view highlighted in rcp application?

I have an Eclipse RCP application. In a perspective there are four views and I want to highlight respective views whenever I click on them. Is it possible to do it?
i have tried following code:
private void addFocusBackgroundOnSelectingView() {
viewer.getControl().addListener(SWT.MouseEnter, new Listener() {
#Override
public void handleEvent(Event event) {
viewer.getControl().setBackground(
PlatformUI.getWorkbench().getDisplay()
.getSystemColor(SWT.COLOR_GRAY));
}
});
viewer.getControl().addListener(SWT.MouseExit, new Listener() {
#Override
public void handleEvent(Event event) {
viewer.getControl().setBackground(
PlatformUI.getWorkbench().getDisplay()
.getSystemColor(SWT.COLOR_WHITE));
}
});
}
I want to save the selection even i mouse hover out if that view is already had selected.
The Eclipse PartService keeps track of which part (Editors, Views etc...) is currently active. You can add a listener to the service via the PlatfomUI class:
IPartListener partListener = ...;
IPartService partService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService();
partService.addPartListener(listener);
The IPartListener interface has partActivated and partDeactivated methods where you can do your highlighting.

How to create an onclick event handler for MainNavBar from the SpiffyUI framework

I'm trying to figure out how to make it so that my navigation menu, when clicked, will open appropriate panels within my GWT page.
Here's a part of my code:
#Override
public void onModuleLoad()
{
MainNavBar nb = new MainNavbar();
NavItem i = new NavItem("1", "TestNavItem");
nb.add(i);
i = new NavItem("2", "TestNavItem2");
nb.add(i);
}
So when I run the project, I see that I have a menu on the test site:
So my question is, how can I have an event handler such that when either one of those are clicked, the panel to the right will be changed to something else?
Thanks!
create an actionListener class,
public class listen implements actionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource() == ObjectName){
// Your code goes here....
}
}
}
then create an object of this class e.g
listen listener = new listen();
YourObjectName.addActionListener(listener);
Don't forget to make the imports, hope this helps...

Categories