Modify a css animation property? - gwt

Is there a way to programatically define and start a css animation? I'd like to animate a div from one absolute position to another. Something like:
FlowPanel fp = new FlowPanel();
fp.getElement().getStyle().setPosition(Position.ABSOLUTE);
fp.getElement().getStyle().setLeft(50, Style.Unit.PX);
fp.getElement().getStyle().setTop(50, Style.Unit.PX);
...
// something like:
fp.setAnimation("top: 300px");
I saw that we could define a css animation in our css file, and changing the name of the div's style will trigger the animation. But I don't know if we can programatically modify an animation defined in css. For example:
// css file
.testAnimation {
top: 500px;
transition-property: top;
transition-duration: 1s;
}
...
// But we can't modify the "top" attribute here depending on runtime needs?:
fp.setStyleName("testAnimation"); // I may want "top" to be some other value here.
Thanks

You have several approaches
1) GWT Animation - http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwAnimation
2) Jquery Approach - via GWTQuery - https://groups.google.com/forum/?fromgroups=#!topic/google-web-toolkit/6kOSm0HBP4A
3) JSNI In GWT - How to add CSS AnimationEnd event handler to GWT widget?

You can use getElement().getStyle().setProperty( property, value ) to set any css property. But this is not the right way of doing it. Suggested way is to do via css.
This Link might help you

Related

How to zoom a GtkTreeView

I want to zoom a GtkTreeView. Initially I thought I simply could use transform to do that, but it seems like GTK CSS currently does not support transform.
So reading up on the CSS docs, it seems my only chance would be to set font-size.
Now naively I tried to set font-size to 200% in GtkStyleContext.
All I get then is
g_object_set_is_valid_property: object class 'GtkStyleContext' has no property named 'font-size'
So how is one supposed to set font-size in code?
You can start with this:
css_provider = Gtk.CssProvider()
css = b"""treeview.view {font-size: 200%;}"""
css_provider.load_from_data(css)
style_context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
But, this will set 200% to all treeviews.
If you want (and you probably do) a custom style class which you can attach to any widget, it should look something like
.my_style_class { font-size: 200%; }
And you add this class to specific widget's StyleContext:
widget.get_style_context().add_class("my_style_class")

How to set width of a control inside a function for QUnit test?

I have a scrollContainer which I need to set the width of. However, i'm not sure how to access the width inside my test file.
I can access the controller through
this.oViewStub = new Control()
var oScrollContainer = new sap.m.ScrollContainer()
this.oViewStub.byId returns oScrollContainer <-- pseudocode
This is the code i'm trying to reach in my test file:
this.getView().byId("scrollContainer").$().parent().parent().width().
So I have this.getView().byId("scrollContainer") covered as it returns oScrollContainer but i'm unable to set/get the width of it. How do I fix this?
1) Create a CSS file and define a class with the width that you want;
2) this.getView().byId("scrollContainer").addStyleClass("yourClass");
3) If it still doesn't work, probably the SAPUI5 standard code is overwriting your CSS. In this case you can specify a more precise path to reach your scroll container in the CSS file, but one thing that should work is to include the property !important when you set the with in your CSS file:
.yourClass {
width: 7rem !important;
}
something like sinon.stub($.prototype, 'width').returns(900) will work

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...

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

Change GWT SubMenu Popup Location

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).