GWT CSS资源定制
我正在使用UIBinder和MVP编写一个GWT小部件。小部件的默认样式在WidgetView.ui.xml中定义:GWT CSS资源定制,gwt,mvp,uibinder,cssresource,Gwt,Mvp,Uibinder,Cssresource,我正在使用UIBinder和MVP编写一个GWT小部件。小部件的默认样式在WidgetView.ui.xml中定义: <ui:style type="com.widgetlib.spinner.display.TheWidgetView.MyStyle"> .textbox { border: 1px solid #red; } .important { font-weight: bold; } </ui:styl
<ui:style type="com.widgetlib.spinner.display.TheWidgetView.MyStyle">
.textbox {
border: 1px solid #red;
}
.important {
font-weight: bold;
}
</ui:style>
public class TheWidgetView extends HorizontalPanel implements TheWidgetPresenter.Display {
// ... some code
@UiField MyStyle style;
public interface MyStyle extends CssResource {
String textbox();
String important();
}
// ... more code
}
<ui:style type="com.consumer.MyExample.MyStyle">
.textbox {
border: 2px solid #black;
}
</ui:style>
public class MyExample extends Composite {
// ... some code
@UiField MyStyle style;
interface MyStyle extends TheWidgetView.MyStyle{
String textbox();
}
// ... more code
}
我希望此小部件的消费者能够自定义小部件的部分样式,并在其MyExample.ui.xml中使用此样式:
<ui:style type="com.widgetlib.spinner.display.TheWidgetView.MyStyle">
.textbox {
border: 1px solid #red;
}
.important {
font-weight: bold;
}
</ui:style>
public class TheWidgetView extends HorizontalPanel implements TheWidgetPresenter.Display {
// ... some code
@UiField MyStyle style;
public interface MyStyle extends CssResource {
String textbox();
String important();
}
// ... more code
}
<ui:style type="com.consumer.MyExample.MyStyle">
.textbox {
border: 2px solid #black;
}
</ui:style>
public class MyExample extends Composite {
// ... some code
@UiField MyStyle style;
interface MyStyle extends TheWidgetView.MyStyle{
String textbox();
}
// ... more code
}
有没有一种方法可以使我的小部件具有默认样式,但小部件的使用者可以覆盖其中一种样式?当接口扩展WidgetView.MyStyle时,小部件使用者的用户需要定义该父接口中列出的所有样式。我看到一些小部件库将小部件的构造函数作为ClientBundle的参数,我认为这可以应用于CssResource。尽管如此,我不确定如何在UIBinder调用的构造函数中传递此样式对象
非常感谢 为了使我的应用程序可皮肤化,我已经尝试了类似的东西。我将首先查看任何单元格小部件的源代码。它们似乎将资源作为构造函数,但是如果没有提供资源,它们也有使用GWT.create(resources.class)来创建资源的构造函数。至于您关于将此模板用于UIBinder的问题,这里提到了3个选项。但是,当您试图在UIBinder中定义样式时,可能会遇到鸡和蛋的问题 您在使用其他代码时遇到的问题是,您的两个不同的样式实现是因为uibinder创建了自己的资源包,而不引用父级的css。有3种解决方案: 1) 将css从ui活页夹文件中撕下放到它自己的文件中,并使用ui:with与提供的字段或uifactory结合使用您自己的资源活页夹注入样式,您可以在其中合成源(即@Source({DEFAULT_css,“myCss.css”})) 2) 您的另一个选择是查看生成的代码,并使用它们用于引用uibinder文件中css的语法,但是您必须克服两个问题:鸡和蛋的问题,以及google可以在不告诉您的情况下更改这一点并破坏您的东西的事实。以下是从我的一个文件生成的客户端包的示例:
@Source("uibinder:com.foo.gwt.client.workspace.select.SelectWorkspaceViewImpl_SelectWorkspaceViewImplUiBinderImpl_GenCss_style.css")
SelectWorkspaceViewImpl_SelectWorkspaceViewImplUiBinderImpl_GenCss_style style();
3) 最后一种解决方案是使用延迟绑定替换默认样式
<replace-with class="com.foo.gwt.laf.mpe.resource.CellTableResources">
<when-type-is class="com.google.gwt.user.cellview.client.CellTable.Resources" />
<when-property-is name="laf" value="MPE" />
</replace-with>
有人使用过CssResource'@eval'吗?这可能有用吗?这似乎不适用于UIBinder/MVP