svg-images を gwt にロードする方法を知っています:最後の回答はこちら
これで、「SvgImage」クラスを作成しようとしています。gwt の image(url) のように動作するはずです。読み込み状態とは無関係に画像を追加でき、読み込みが完了するとすぐに画像が表示されます。これを達成する方法は?
または、一般的に、特定の URL を介してコンテンツをロードするウィジェットを作成するための良いアプローチは何ですか?
私はgwt画像ソースを少し掘り下げて、「replaceElement(Node)」があることを発見しました-特に画像用に作成された保護されたメソッドですが、このメソッドはに基づいています
Widget.getElement().replaceChild(newElement, oldElement);
これが私の完全な SvgWidget クラスです。
public class SvgWidget implements IsWidget {
    private String svgUrl;
    private ADBTexte strings;
    private IsWidget thisW;
    private Loading loadingWidget;
    @Inject
    private SvgWidget(@Assisted final String svgUrl, final ADBTexte strings, final Loading loadingWidget) {
        this.svgUrl = svgUrl;
        this.strings = strings;
        this.loadingWidget = loadingWidget;
    }
    @Override
    public Widget asWidget() {
        thisW = new SimplePanel(loadingWidget);
        RequestBuilder rB = new RequestBuilder(RequestBuilder.GET, svgUrl);
        rB.setCallback(new RequestCallback() {
            @Override
            public void onResponseReceived(final Request request, final Response response) {
                Widget result = new HTML(response.getText());
                thisW.asWidget()
                     .getElement()
                     .replaceChild(result.getElement(), thisW.asWidget().getElement().getChild(0));
            }
            @Override
            public void onError(final Request request, final Throwable exception) {
                Widget result = new Label(strings.chartError());
                thisW.asWidget()
                     .getElement()
                     .replaceChild(result.getElement(), thisW.asWidget().getElement().getChild(0));
                GWT.log("Error on loading chart: ", exception);
            }
        });
        try {
            rB.send();
        } catch (RequestException e) {
            Widget result = new Label(strings.chartError());
            thisW.asWidget().getElement().replaceChild(result.getElement(), thisW.asWidget().getElement().getChild(0));
            GWT.log("Error on sending request for chart: ", e);
        }
        return thisW.asWidget();
    }
    /**
     * Use this to get an instance of {@link SvgWidget}.
     * 
     */
    public interface Factory {
        /**
         * 
         * @param svgUrl
         *            url for svg graphic
         * @return instance of {@link SvgWidget} displaying the svg accessible via the given url
         */
        SvgWidget get(@Assisted String svgUrl);
    }
}
関連するものは asWidget() にあります。しかし、これが良い/最善の解決策であるかどうかはわかりません:
(依存性注入 (gin を使用) を知らない場合: すべての不明な注釈とファクトリ インターフェイスを無視してください)