Search in sources :

Example 51 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class WComponentRenderPerfTest method runRenderTest.

/**
 * Runs the render test.
 */
private static void runRenderTest() {
    UIContextImpl uic = new UIContextImpl();
    PrintWriter printWriter = new PrintWriter(new NullWriter());
    RenderContext renderContext = new WebXmlRenderContext(printWriter);
    WComponent component = null;
    long baseLineMemory = getHeapUsed();
    try {
        component = (WComponent) Class.forName(CLASS_TO_TEST).newInstance();
    } catch (Exception e) {
        String msg = "Unable to instantiate test component: " + CLASS_TO_TEST;
        LOG.error(LINE_PREFIX + msg);
        throw new SystemException(msg, e);
    }
    long memBeforePaint = getHeapUsed() - baseLineMemory;
    // Set up velocity etc. to obtain a memory reading, and
    // so that the performance results aren't skewed too much
    UIContextHolder.pushContext(uic);
    try {
        component.paint(renderContext);
        long memAfterOnePaint = getHeapUsed() - baseLineMemory;
        long startTime = System.currentTimeMillis();
        // Figure out the loop overhead
        for (int i = 0; i < NUM_RENDERS; i++) {
        }
        long loopOverhead = System.currentTimeMillis() - startTime;
        startTime = System.currentTimeMillis();
        // Now run the render test
        for (int i = 0; i < NUM_RENDERS; i++) {
            component.paint(renderContext);
        }
        long elapsedTime = System.currentTimeMillis() - startTime - loopOverhead;
        long memAfterAllPaints = getHeapUsed() - baseLineMemory;
        LOG.info(LINE_PREFIX + "Memory use before paint: " + memBeforePaint);
        LOG.info(LINE_PREFIX + "Memory use after 1 paint: " + memAfterOnePaint);
        LOG.info(LINE_PREFIX + "Memory use after " + NUM_RENDERS + " paints: " + memAfterAllPaints);
        LOG.info(LINE_PREFIX + "Render time: " + (elapsedTime / (double) NUM_RENDERS) + "ms");
        Object[] treeAndSession = new Object[] { component, uic };
        ObjectGraphNode root = ObjectGraphDump.dump(treeAndSession);
        LOG.info(LINE_PREFIX + "Component mem use: " + ((ObjectGraphNode) root.getChildAt(0)).getSize());
        LOG.info(LINE_PREFIX + "UIC mem use: " + ((ObjectGraphNode) root.getChildAt(1)).getSize());
    } finally {
        UIContextHolder.popContext();
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) IOException(java.io.IOException) SystemException(com.github.bordertech.wcomponents.util.SystemException) WComponent(com.github.bordertech.wcomponents.WComponent) SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) ObjectGraphNode(com.github.bordertech.wcomponents.util.ObjectGraphNode) PrintWriter(java.io.PrintWriter)

Example 52 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class ExampleSection method selectExample.

/**
 * Selects an example.
 *
 * @param example the example to select.
 * @param exampleName the name of the example being selected.
 */
public void selectExample(final WComponent example, final String exampleName) {
    WComponent currentExample = container.getChildAt(0).getParent();
    if (currentExample != null && currentExample.getClass().equals(example.getClass())) {
        // Same example selected, do nothing
        return;
    }
    resetExample();
    container.removeAll();
    this.getDecoratedLabel().setBody(new WText(exampleName));
    WApplication app = WebUtilities.getAncestorOfClass(WApplication.class, this);
    if (app != null) {
        app.setTitle(exampleName);
    }
    if (example instanceof ErrorComponent) {
        tabset.getTab(0).setText("Error");
        source.setSource(null);
    } else {
        String className = example.getClass().getName();
        WDefinitionList list = new WDefinitionList(WDefinitionList.Type.COLUMN);
        container.add(list);
        list.addTerm("Example path", new WText(className.replaceAll("\\.", " / ")));
        list.addTerm("Example JavaDoc", new JavaDocText(getSource(className)));
        container.add(new WHorizontalRule());
        tabset.getTab(0).setText(example.getClass().getSimpleName());
        source.setSource(getSource(className));
    }
    container.add(example);
    example.setLocked(true);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WText(com.github.bordertech.wcomponents.WText) WApplication(com.github.bordertech.wcomponents.WApplication) WDefinitionList(com.github.bordertech.wcomponents.WDefinitionList) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule)

Example 53 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class SafetyContainer method resetContent.

/**
 * Resets the contents.
 */
public void resetContent() {
    for (int i = 0; i < shim.getChildCount(); i++) {
        WComponent child = shim.getChildAt(i);
        child.reset();
    }
    removeAttribute(SafetyContainer.ERROR_KEY);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent)

Example 54 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class SelectExampleAction method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute(final ActionEvent event) {
    ExampleData data = (ExampleData) event.getActionObject();
    WComponent source = (WComponent) event.getSource();
    TreePicker picker = WebUtilities.getAncestorOfClass(TreePicker.class, source);
    picker.selectExample(data);
    MenuPanel panel = WebUtilities.getAncestorOfClass(MenuPanel.class, source);
    if (panel != null) {
        WTree tree = panel.getTree();
        if (tree != null) {
            // null);
            tree.setSelectedRows(new HashSet<String>());
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WTree(com.github.bordertech.wcomponents.WTree)

Example 55 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class SimplePicker method displaySelection.

/**
 * Get the example picker to display the given selected component.
 *
 * @param selectedComponent the wcomponent to be displayed.
 */
public void displaySelection(final WComponent selectedComponent) {
    WComponent currentComponent = getCurrentComponent();
    if (selectedComponent == currentComponent) {
        // We are already displaying this component, so nothing to do.
        return;
    }
    // We have a new selection so display it.
    container.removeAll();
    container.add(selectedComponent);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent)

Aggregations

WComponent (com.github.bordertech.wcomponents.WComponent)107 Test (org.junit.Test)35 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)30 UIContext (com.github.bordertech.wcomponents.UIContext)20 SystemException (com.github.bordertech.wcomponents.util.SystemException)16 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)14 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)8 WApplication (com.github.bordertech.wcomponents.WApplication)8 WLabel (com.github.bordertech.wcomponents.WLabel)8 AbstractWComponent (com.github.bordertech.wcomponents.AbstractWComponent)7 IOException (java.io.IOException)6 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)5 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)5 PrintWriter (java.io.PrintWriter)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 Size (com.github.bordertech.wcomponents.Size)4 WRepeater (com.github.bordertech.wcomponents.WRepeater)4 WText (com.github.bordertech.wcomponents.WText)4 WTextField (com.github.bordertech.wcomponents.WTextField)4