org.jboss.hal.core.finder.ResourceDescriptionPreview.java Source code

Java tutorial

Introduction

Here is the source code for org.jboss.hal.core.finder.ResourceDescriptionPreview.java

Source

/*
 * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jboss.hal.core.finder;

import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import elemental2.dom.HTMLElement;
import org.jboss.hal.core.subsystem.SubsystemMetadata;
import org.jboss.hal.dmr.Operation;
import org.jboss.hal.dmr.dispatch.Dispatcher;

import static org.jboss.gwt.elemento.core.Elements.section;
import static org.jboss.hal.dmr.ModelDescriptionConstants.DESCRIPTION;

/** Preview which shows the description of a {@code :read-resource-description} operation. */
public class ResourceDescriptionPreview extends PreviewContent<SubsystemMetadata> {

    public ResourceDescriptionPreview(String header, Dispatcher dispatcher, Operation rrd) {
        super(header);
        HTMLElement content = section().get();
        previewBuilder().add(content);
        dispatcher.execute(rrd, result -> {
            if (result.hasDefined(DESCRIPTION)) {
                SafeHtml html = SafeHtmlUtils.fromSafeConstant(result.get(DESCRIPTION).asString());
                content.innerHTML = html.asString();
            }
        });
    }
}