I have two buttons "Next element" and "Previous element" and some custom widget containing CellList.
On button clicks I call to my widget's method which changeselection in CellList by calling it's SelectionModel:
selectionModel.setSelected(value, true);
When I refresh CellList's contents, the buttons work just fine, but when I select element in list by clicking on it, this behavior happens:
For example, I have elements {0, 1, 2, 3, 4, ..} on the list. I click on element 1, then press "Next element" button two times. These SelectionChangeEvent occurs:
Change selection from 1 -> 2 (on first button press)
2 -> 3 (on second press)
3 -> 1
But after step 2 if I press "Previous" it correctly go back to element 1. So element that I clicked with mouse doesn't let selection go more than 1 step around it.
I have no idea where the third event is coming from. My only guess is that manual selection event continues pending after firing, but I don't know how to check that.
Anybody knows the reason of this problem?
upd:
I found confirmation that selection by clicking event continues to hanging there somewhere in the EventBus: when I change search filters I access SelectionModel the same way as on button clicks and set selection to first element. But if there was user click on CellList before that the same thing happens: first, selection changes to 0, second, it goes back to previously selected if new selection of data contains that element.
upd (for Ümit's question):
nextButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
/* Omitting checks that there are elements on the list,
some element is selected and isn't last */
T value = dataProvider.getList().get(currentIndex() + 1);
singleSelectionModel.setSelected(value, true);
singleSelectionModel.isSelected(value);
Element rowElement = cellList.getRowElement(index);
rowElement.scrollIntoView();
}
}
upd: Found what was causing this problem: http://code.google.com/p/google-web-toolkit/issues/detail?id=6310
It seems you need to use HandlerRegistration. So multiple click event is not called.
Refer to:
GWT Handler Registratin
and
related link
Related
jsfiddle: http://jsbin.com/wamunoside/1/edit?html,output
jsfiddle
This is taken from the example given on the Bootstrap 4 docs site:
just adding a 2nd dropdown to this example below the 1st dropdown found here:
https://v4-alpha.getbootstrap.com/components/navbar/#navbarNavDropdown
So in the jsfiddle this is how you cause the issue:
1.) reduce the width of the output tab so that it shows the menu for mobile (991px or less)
2.) You will see two 'dropdown link', click on the top one which expands the submenu.
3.) click on the other 'dropdown link' below the currently expanded one.
Notice both dropdowns are now closed - should have opened the 2nd dropdown.
ended up issue being my code...
I added the following if event.type == "mouseleave" and that seems to have fixed the issue reasonably well, still not perfect (for desktop):
http://jsbin.com/yiyohatequ/edit?html,css,js,output
I'm basically struggling with the best way to get dropdown-menu to appear 'on hover' for desktop and dropdown to appear 'on click' for tablet/mobile. so that is why I wrote this code in the 1st place.
/* Prevent more than 1 dropdown showing up at once*/
$('.nav-link').hover(function (event) {
//breaks mobile if this fires on "mouseenter". so only fire on "mouseleave"
if (event.type == "mouseleave") {
var hovered = this.nextElementSibling;//.dropdown-menu
var navdropdowns = $('.dropdown-menu');
navdropdowns.each(function (a, b) {
if (hovered != b) {
$(b).removeClass('show');
}
});
}
})
In Eclipse E4 (Luna), using the application model to create parts, handlers, commands, handled menu items etc, (these are not created programatically). I have a toolbar. This contains a sub-Menu item called "Filter" that contains another sub-menu of two filters. The two filters are two Handled Menu Items which are set up as "Radio" Buttons.
When I select the appropriate in the UI of my running app from the selection, the Radio button switches just fine to the selected Item. However I would like this selection to update (deselecting one Radio button and selecting the appropriate radio button of the handled menu item) when my ViewPart changes through other UI selection. Currently my ViewPart updates, but the Radio buttons are on the same previous selection through the UI.
Is there a way in which I get access both Handled Menu Item's IDs and set the selection (one to false, the other to true) when the viewer is updated.
Image of design is attached below:
Hierarchy of the application model is as follows:
Thanks in advance,
Marv
You can use the model service to find menu items. Use something like:
#Inject
EModelService modelService;
#Inject
MApplication app;
List<MMenuItem> items = modelService.findElements(app, "menu item id", MMenuItem.class, Collections.emptyList(), EModelService.IN_MAIN_MENU);
Once you have the MMenuItem you can call the setSelected(boolean) method to change the selection.
To find a menu item which is in a Part menu use:
modelService.findElements(app, "menu item id", MMenuItem.class, Collections.emptyList(), EModelService.IN_PART);
(IN_PART argument instead of IN_MAIN_MENU).
You could also specify the MPart rather than the Application as the first argument to findElements which may speed up the search.
For menus as a child of a Tool Bar Item it appears that the model services cannot find these directly. However you can find the Tool Bar Item and look at the menu yourself:
List<MToolItem> items = modelService.findElements(app, "tool bar item id", MToolItem.class, Collections.emptyList(), EModelService.IN_PART);
MToolItem item = items.get(0);
MMenu menu = item.getMenu();
List<MMenuElement> children = menu.getChildren();
... search menu elements
I solved this by starting with MPart PartID and drilling down to the HandledMenuItems on which I wanted to set the Radio Button selections, then setting the selection property for each individual HandledMenuItem.
This can probably be refactored to be more concise, but I've left the code with each step to have the solution easier to read.
BTW, in every instance / combination of the EModelService methods, the list returned a size of 0. So I'm not certain if that will work for what I'm trying to achieve. The following does work, although I'm not certain it is the most efficient means.
I hope this helps others.
// Get view part
MPart viewPart = _partService.findPart("part_id");
// get list of all menu items from the Part
List<MMenu> viewPartMenu = viewPart.getMenus();
// Get list of ViewMenus from viewPartMenu there is only one View Menu so it will be index 0
MMenu viewMenu = viewPartMenu .get(0);
// Get list of MMenuElements from the viewMenu - the children in the view menu
List<MMenuElement> viewMenuElements = viewMenu.getChildren();
// This gets me to the 2 HandledMenuItems
// Upper Most HandledMenuItem Radio Button is at viewMenuElements index 0. This is cast to MHandledMenuItem
MHandledMenuItem upperHandledMenuItem = (MHandledMenuItem) viewMenuElements.get(0);
// Set Selection
upperHandledMenuItem.setSelected(false);
// Lower Most HandledMenuItem Radio Button is at viewMenuElements index 1. This is cast to MHandledMenuItem
MHandledMenuItem lowerHandledMenuItem = (MHandledMenuItem) viewMenuElements.get(1);
// Set selection
lowerHandledMenuItem.setSelected(true);
This is more of algorithms question. I have 3 buttons:
button1 button2 button3
They can each be in clicked or not-clicked state. When the first is clicked, it goes into clicked state, but if I click it again, it goes back into non-clicked state.
I want to keep a global variable that answers if ANY of the buttons is clicked.
Knowing when to set global variable to clicked is pretty easy:
When I click button1 I can set variable clicked to true.
When I click button2 I can set variable clicked to true.
When I click button3 I can set variable clicked to true.
Now the difficult part is to set global variable to non-clicked:
When I click button1 again it becomes non-clicked, but button2 or button3 can be still clicked, so I can't just set variable to non-clicked.
When I click button2 again it becomes non-clicked, but button1 or button3 can be still clicked, so I can't just set variable to non-clicked.
When I click button3 again it becomes non-clicked, but button1 or button2 can be still clicked, so I can't just set variable to non-clicked.
It's difficult to keep state of non-clicked global status of all buttons.
Any ideas how to solve this problem? Should I somehow use xor? Or some other logical operation?
Set and clear a different bit in the word per button. That way if the word is non-zero, one or more of the buttons is pressed, and you can detect which one(s) by examining the bits.
Hard to see the point.
I figured out answer to my own question.
The answer is to keep global variable with value 0 in it:
int button_counter = 0;
When any button is clicked the following operation is performed:
button_counter = button_counter + 1;
When any button is unclicked the following operation is performed:
button_counter = button_counter - 1;
Now if value of button_counter is 0, then all buttons are unclicked.
If value of button_counter is 1, 2 or 3, then either one, two or three buttons are clicked and they are not all unclicked.
Here's how to check if they're all unclicked:
if (button_counter == 0) {
// all buttons are unclicked
}
else {
// at least 1 button is clicked
}
Thank you all for help!
I want a Text Field to appear when a certain item is chosen from a drop-down list. I'm using a change event.
if(this.rawValue == 1){
Tolerance.presence = "visible";
}
else{
Tolerance.presence = "hidden";
}
The problem is that the Text Field presence does not change immediately when a selection is made, but only after I go back to the list box and select again (any value, not just the same one).
The new value of the dropdown only registers after the change event. This means this.rawValue points to the old value of the dropdown in a change event.
Either move your script dropdown exit event or make use of the event.newText in the if conditional in the change event.
This seems like a really easy question, but I can't seem to find the answer.
Now that toggle() is deprecated for click events, how would I have say a button add DOM elements on the first click, then remove those same DOM elements on the second click?
Also.... how do I remove contents from a div I have inserted content into (using load()) without removing the div itself? Using remove() removes the div.
use empty() to clear an elements inner html
As for the toggle issue, you can toggle a class on the element and test for that class:
$('#myDiv').on('click', function(){
if(! $(this).hasClass('clicked') ){
/* code for first click*/
}else{
/* code for second click*/
}
$(this).toggleClass('clicked')
})
your click would first check for the presence of the dom elements that get added (use an id perhaps).
if $('div#id of the stuff you add')
$('element exists...').remove();
else
$('div#id of where you want to add stuff').add( new code );
You can clear a div contents with:
divSomeDiv.html("");
or
divSomeDiv.empty();