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();
}
}
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);
}
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);
}
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>());
}
}
}
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);
}
Aggregations