use of elemental.js.dom.JsElement in project che by eclipse.
the class Tree method replaceSubtree.
/**
* Replaces the old node in the tree with data representing the subtree rooted
* where the old node used to be if the old node was rendered.
* <p/>
* <p>{@code oldSubtreeData} and {@code incomingSubtreeData} are allowed to be
* the same node (it will simply get re-rendered).
* <p/>
* <p>This methods also tries to preserve the original expansion state. Any
* path that was expanded before executing this method but could not be
* expanded after replacing the subtree, will be returned in the result array,
* so that it could be expanded later using the {@link #expandPaths} method,
* if needed (for example, if children of the tree are getting populated
* asynchronously).
*
* @param shouldAnimate
* if true, the subtree will animate open if it is still open
* @return array paths that could not be expanded in the new subtree
*/
public List<List<String>> replaceSubtree(D oldSubtreeData, D incomingSubtreeData, boolean shouldAnimate) {
// Gather paths that were expanded in this subtree so that we can restore
// them later after rendering.
List<List<String>> expandedPaths = gatherExpandedPaths(oldSubtreeData);
boolean wasRoot = (oldSubtreeData == getModel().root);
TreeNodeElement<D> oldRenderedNode = null;
TreeNodeElement<D> newRenderedNode = null;
if (wasRoot) {
// We are rendering root! Just render it from the top. We will restore the
// expansion later.
getModel().setRoot(incomingSubtreeData);
renderTree(0);
} else {
oldRenderedNode = getModel().dataAdapter.getRenderedTreeNode(oldSubtreeData);
// If the node does not have a rendered node, then we have nothing to do.
if (oldRenderedNode == null) {
expandedPaths.clear();
return expandedPaths;
}
JsElement parentElem = oldRenderedNode.getParentElement();
// parent, and we're done here.
if (parentElem == null) {
expandedPaths.clear();
return expandedPaths;
}
// Make a new tree node.
newRenderedNode = createNode(incomingSubtreeData);
parentElem.insertBefore(newRenderedNode, oldRenderedNode);
newRenderedNode.updateLeafOffset(parentElem);
// Remove the old rendered node from the tree.
DomUtils.removeFromParent(oldRenderedNode);
}
// If the old node was the root, or if it and its parents were expanded, then we should
// attempt to restore expansion.
boolean shouldExpand = wasRoot;
if (!wasRoot && oldRenderedNode != null) {
shouldExpand = true;
TreeNodeElement<D> curNode = oldRenderedNode;
while (curNode != null) {
if (!curNode.isOpen()) {
// One of the parents is closed, so we should not expand all paths.
shouldExpand = false;
break;
}
D parentData = getModel().dataAdapter.getParent(curNode.getData());
curNode = (parentData == null) ? null : getModel().dataAdapter.getRenderedTreeNode(parentData);
}
}
if (shouldExpand) {
// still be expanded by the call to expandPaths() below.
if (shouldAnimate && newRenderedNode != null) {
expandNode(newRenderedNode, true, true);
}
// But if it is open, we need to attempt to restore the expansion.
expandedPaths = expandPaths(expandedPaths, true);
} else {
expandedPaths.clear();
}
// TODO: Be more surgical about restoring the selection model. We
// are currently recomputing all selected nodes.
List<List<String>> selectedPaths = getModel().selectionModel.computeSelectedPaths();
restoreSelectionModel(selectedPaths);
return expandedPaths;
}
use of elemental.js.dom.JsElement in project che by eclipse.
the class Window method show.
/**
* Displays the {@link Window} popup. The popup will animate into view.
*
* @param selectAndFocusElement
* an {@link Focusable} to select and focus on when the panel is
* shown. If null, no element will be given focus
*/
public void show(@Nullable final Focusable selectAndFocusElement) {
setBlocked(false);
if (isShowing) {
return;
}
isShowing = true;
// Attach the popup to the body.
final JsElement popup = view.popup.getElement().cast();
if (popup.getParentElement() == null) {
// Hide the popup so it can enter its initial state without flickering.
popup.getStyle().setVisibility("hidden");
RootLayoutPanel.get().add(view);
}
// The popup may have been hidden before this timer executes.
if (isShowing) {
popup.getStyle().removeProperty("visibility");
// Start the animation after the element is attached.
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
// The popup may have been hidden before this timer executes.
view.setShowing(true);
if (selectAndFocusElement != null) {
selectAndFocusElement.setFocus(true);
}
}
});
}
}
Aggregations