Sunday, February 23, 2014

Re: CssResource inheritance and avoiding rule repetition on injection, possibility of an @Require?



On Monday, February 24, 2014 12:27:18 AM UTC+1, Jens wrote:
Just to get things right. Even in your complete example the usage of @Import in the case of InitButtonCSS is useless. Its useless because the css class initButton2 will be a unique name anyways and thus it doesn't really make sense to define the css rule as .global-genButton.initButton2.

Unless one of these is dynamically added/removed.
 
@Import is usually used the other way around. That means you have some sort of a parent container widget and you want to change the default style of its child widgets. In that case you would @Import the css of the child widget into the parent widget css and then define css rules like .parent .childwidget-header { ... } to change the header of the child widget if this child widget will be put into that specific parent container.

It's also useful the other way around. I've used @Import to show/hide elements in cells when a CellTable row is hovered:
.gwt-CellTable-cellTableCell .hiddenAction {
  visibility: hidden;
}

.gwt-CellTable-cellTableHoveredRowCell .hiddenAction {
  visibility: visible;
}

or showing some kind of label as red when put in an "error panel":

.label {
  width: 200px;
}
.global-hasError .label {
  color: red;
}

 
@Shared works best when you generalize some common state like focus / selected / disabled / enabled. For example you could have some sort of a SecurityManager that enables/disables widgets based on permissions. Such a SecurityManager would use a minimal CssResource like

@Shared
interface HasEnabledDisabledStateCss extends CssResource {
  String enabled();
  String disabled();
}

Then any widget can inherit this minimal CssResource and define on its own how it will look like in enabled / disabled state (= you would not add enableddisabled.css to the various widgets @Source annotation although you extend HasEnabledDisabledStateCss).

+1, a @Shared interface would generally not have a CSS file and would only be used in "extends" (never as return type of a ClientBundle resource)
 



So either @Shared nor @Import do not really fit into your example above. If you delete all these annotations then you example will work without issues and it will look like the short snippet I posted earlier.


-- J.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment