Change GWT SubMenu Popup Location - gwt

In menubar, normally submenu gets displayed on the right hand side. I want to change to Left hand side. Can anyone please let me know, how can I do it ?

Popup location of Sub menu is defined by CSS elements at rendering based on position of menu items.
Looking Via Firebug On Main Menu It produced:
element.style {
clip: rect(auto, auto, auto, auto);
left: 337px; // Change this to left:35px;
overflow: visible;
position: absolute;
top: 319px;
visibility: visible;
}
// This is main CSS for popup
.gwt-MenuBarPopup{
}
So, Give it a try by using setStyleName("css goes here") from code

I again advise you to override the default styles GWT:) I used this method on my project when I had to change some standard view of GWT-elements.

I was able to implement a solution by changing the css as well. Perhaps this isn't the most elegant way, but it works. Using a little help from GwtQuery's closest() method, here is a short example.
menuBar.addAttachHandler(new AttachEvent.Handler() {
#Override
public void onAttachOrDetach(AttachEvent event) {
if(event.isAttached()){
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
#Override
public void execute() {
Element e = $(menuBar).closest(".gwt-MenuBarPopup").get(0);
e.getStyle().setLeft(parentMenuBar.getAbsoluteLeft()-menuBar.getOffsetWidth() , Unit.PX);
}
});
}
}
});
So the idea being when the child sub menu is attached, you want to change the css. I use a deferred command so that it will change the css after GWT's default MenuBar implementation sets it.
This line, "$(menuBar).closest(".gwt-MenuBarPopup").get(0);" will search up the DOM tree until it finds the element with the class .gwt-MenuBarPopup, which is the one you want to change.

My solution is somewhat of a hybrid of those posted so far here, but I think it is cleaner/simpler than any of them.
Each vertical subMenu is itself a MenuBar, added as an item to the top-level
MenuBar. For whichever subMenu you want to drop to the left instead of the right, add a style class name to it using .addStyleName("myLeftDropDownStyleName") on that MenuBar Widget.
Define the selector rule for that style like this (these are the minimum attributes that were necessary for me to get the left dropping):
.myLeftDropDownStyleName{
position: absolute;
right: 0px;
}
Absolute positions relative to the first parent element with a position other than static; for my case at least, that parent position seemed to be horizontal place where the dropdown otherwise has its left edge without this solution. I wouldn't be suprised if Relative position might work better in some other people's cases.
The Right offset of 0px tells the absolute position's right to be at that horizontal place I mentioned above. And of course the pixel size can be > 0 to push further to the left by that much, or even < 0 to pull it back to the right by that much.
This works perfectly for me, is simple & clean, and does not force all of your MenuBars to have this style (as I think would be the case if you overrode one of the GWT MenuBar styles themself).

Related

GWT CellTable-How to Move the Sorting Arrow from Left to Right side

I Would like to move the sorting arrow from left to right side in the cell table header which is shown in below image
Any Suggestion?
It took me a while to find, but the solution is very easy. Cell table uses default header builder which has an option to render sort icon on left or right side.
DefaultHeaderOrFooterBuilder<Contact> headerBuilder = new DefaultHeaderOrFooterBuilder<>(table, false);
headerBuilder.setSortIconStartOfLine(false);
table.setHeaderBuilder(headerBuilder);
Cheers!
I think I have some raw ideas you could play with and see if they help:
Get a handle on the div containing the arrow img, to add a style classname that will be used in a CSS selector [2. below] that styles the right-alignment you want... Maybe something like this would work:
CellTable.getTableHeadElement().addClassName( "myTableHeadersClassname" );
If 1. succeeded in getting "myTableHeadersClassname" classname on the CellTable's thead element, then I think we are in good shape. I think this CSS selector will then work:
.myTableHeadersClassName div div:nth-child(1){
left: auto;
right: 0 px;
}
I'm not sure if 1. will work, so that might be the hard part. But the idea is to add a classname somewhere in the CellTable DOM hierarchy to then create the CSS selector out of. As long as you can apply that classname and make the selector, you should be just faced with fiddling with that selector's style (although I think the style inside the selector in 2. should work at that point). If 1. doesn't work, I think you could always just put a classname on the top-level CellTable itself, and then have this slightly more complex selector:
.myCellTableClassname thead div div:nth-child(1)
Whichever selector route you go, the left style should be overriding CellTable's inlined style; if what I wrote does not do that, then just add more specificity to the selector until it does.
Hope some of this helps...

GWT : MenuBar Submenu position / Z index

Im trying to display a Submenu when im hover a menuitem but my Submenu is on a wrong position and it is under my Menu.
how can I set the Position of my Submenu or change the z index of the Sumenu (popup)
As long as your submenu class extends the com.google.gwt.user.client.ui.UIObject class, you can give it a style name. (All widgets do this). And then you can set the z-index of that style in a css file:
Java:
MySubMenuClass submenu = new MySubMenuClass();
submenu.addStyleName("subMenuStyle");
CSS:
.subMenuStyle{
z-index: 50; // or any other value > 0
}
Alternatively, you can hardcode the z-index in java (not recommended, because for every change to the value of your z-index you will have to recompile your entire GWT application instead of simply exchanging the CSS file and refreshing). The submenu class still needs to extend UIObject for this to work.
Java:
submenu.getElement().getStyle().setZIndex( 50 );

LayoutPanel with right alignment

I'm using a layout panel with some layers. One of the layers is quite simple but I want it to have a float: right on the element. But this is actually not working because subwidgets are styled with style="postition: absolute; left: 0px; ..." which overrides the styling and so the subpanels/widgets will always be placed on the left. Any workaround for this?
After adding your element to your layout container, did you try setWidgetHorizontalPosition ?
If above method does not work and you want to use float right, maybe you can use a non-layout system with FlowPanel maybe. Otherwise you will have to fix the position and width/height of your components but you may loose responsive design.
Last trick : If you really need to change the absolute style. In your component do something like this (do this after your component has been added to the dom)
this.getElement().getParent().getStyle().set.....
You can reset whatever property you want but this might break your layout

GWTQuery Drag Drop - Drag between nodes in cell tree

I am using the wonderful GWTQuery library to add drag drop support to my GWT cell widgets.
I have a CellTable, and a CellTree both in different modules of my application (I am using GWTP, so everything is decoupled). Neither of these widgets are allowed to know about each other, they simply accept draggables/droppables, check the underlying datatype and then handle them appropriately.
The problem I am having is that I need to support dragging "in between" my cell tree nodes. IE: The typical functionality where if you drag directly over an element in the tree, it drops into that element, BUT if you drag just slightly below or above, you are given a visual indicator (usually a horizontal line) that indicates to the user they can drag the current item in between nodes as well.
And here-in lies the problem, thus far I have no found a way to provide this functionality becuase the setOnDrag() method does not tell me anything about detected droppables, and setOnOver only fires once when it first encounters a droppable.
So far as I can tell this leaves me with only two options:
1.) Add extra "invisible" nodes into my CellTree which are also droppable and sit in between my other nodes.
2.) Implement some custom event handler which I attach to the helper draggable before drag start and use to compare positions of the helper and the droppable once the draggable is actually over the droppable.
Option 1 is really unsavory because it seriously mucks up my CellTree design, and potentially impacts efficiency pretty badly.
Option 2 is really unsavory because it requires a lot of extra code and hacks to get it to work just right.
So I am hoping there is an Option 3 which I might not have though of, any help would be much appreciated.
Cheers,
Casey
I think I have found a solution although it may not be the best, but it is working for me at the moment. In the setOnDrag method, I determine where the item is being dragged at which point I can either add a line before or after the element, or put some css on the element to denote that I am dropping the dragged item on top. I create a GQuery place holder to show the before/after line, and putting a border around element with css for dropping on top.
To know which element I am dropping on top of, I set a global variable in the setOnOver method. Here is a simple mock up:
private GQuery placeHolder = $("<div id='cellPlaceHolder' style=' outline: thin dashed #B5D5FF; height: 2px; background:#B5D5FF;'></div> ");
private Element oldEl = null;
options.setOnOver(new DroppableFunction() {
#Override
public void f(DragAndDropContext context) {
oldEl = context.getDroppable();
}
});
options.setOnDrag(new DragFunction() {
#Override
public void f(DragContext context) {
if (oldEl != null) {
int difference = Math.abs(oldEl.getAbsoluteTop() - context.getHelperPosition().top);
if (difference > 0 && difference < 16) {
/* dragging on top edge, so insert place holder */
oldEl.getFirstChildElement().getStyle().clearProperty("border");
placeHolder.insertBefore(oldEl.getFirstChildElement());
} else if (difference > 26 && difference < 53) {
/* dragging on bottom edge, so insert place holder */
oldEl.getFirstChildElement().getStyle().clearProperty("border");
placeHolder.insertAfter(oldEl.getFirstChildElement());
}else if (difference > 15 && difference < 27) {
/* dragging in middle so add border */
placeHolder.remove();
oldEl.getFirstChildElement().getStyle().setProperty("border", "2px solid red");
}
}
}
});
This way uses several global variables, but it seems to be the best method I have found since the drag options do not include info about the droppable element. And you will have to add the logic to know if it is being dropped before/after/or on and do what you want with it at that point.

How do I get jscrollpane to co-exist with a jquery accordion script?

I have a site that uses a accordion script, and I want to place a scrollbox inside one of the accordion tabs. However, the scrollbox works just fine, but breaks the accordion script. Is there a way around this conflict?
This is the site with just the accordion script:
http://www.namibiaonline.net/sandbox/NBAA/index9.html
And this is the broken one with jscrollpane and the accordion script:
(for some reason I'm only allowed to paste one hyperlink, so to get to the broken one, just replace /index9.html with /scroll_test.html)
Any help would be much appreciated :)
Ash
This should fix your problem. Try the beta:
http://groups.google.com/group/jscrollpane/browse_thread/thread/c1bc1bf63e3f80d8
and I believe this is where your issue lied:
http://jscrollpane.kelvinluck.com/auto_reinitialise.html
I had the same problem and this is how I almost solved it:
jQuery(document).ready(function() {
scrollPane = jQuery(".scroll-pane").jScrollPane({
showArrows: true
});
var api = scrollPane.data('jsp');
jQuery("#accordion").accordion({
changestart: function(event, ui) {
api.reinitialise()
}
});
}
Be sure that you define the correct width height for the containers which have the scroll-pane class. In my case I have created 3 containers like this:
<div class="scroll-pane">
.scroll-pane {
overflow: auto;
height: 134px;
width: 420px;
}
The class scroll-pane is where I defined the overflow, height and width. If I do in the parent container, the scroll is not shown because it takes all the height and also if I do in a child container, a non stylized scroll is shown.
But I still having an issue with the first pane. It is correctly shown the first time the page is loaded, but when I move to another accordion tab and then come back to the first one, the width of this element is set to 0. It only happens with the first one the others work fine.