@Override public void show() { super.show(tree); if (!tree.getRootNodes().isEmpty()) { tree.getSelectionModel().select(tree.getRootNodes().get(0), false); } }
private void acceptButtonClicked() { List<Node> nodes = tree.getSelectionModel().getSelectedNodes(); if (nodes.isEmpty()) { return; } Node selectedNode = nodes.get(0); delegate.setSelectedPath(((HasStorablePath) selectedNode).getStorablePath()); hide(); }
@Inject public SelectPathViewImpl(CoreLocalizationConstant locale, SelectPathViewImplUiBinder uiBinder) { setTitle(locale.selectPathWindowTitle()); Widget widget = uiBinder.createAndBindUi(this); setWidget(widget); UniqueKeyProvider<Node> uniqueKeyProvider = new NodeUniqueKeyProvider() { @NotNull @Override public String getKey(@NotNull Node item) { if (item instanceof HasStorablePath) { return ((HasStorablePath) item).getStorablePath(); } else { return String.valueOf(item.hashCode()); } } }; FolderNodeInterceptor interceptor = new FolderNodeInterceptor(); Set<NodeInterceptor> interceptors = new HashSet<>(); interceptors.add(interceptor); NodeLoader loader = new NodeLoader(interceptors); NodeStorage nodeStorage = new NodeStorage(uniqueKeyProvider); tree = new Tree(nodeStorage, loader); tree.setAutoSelect(true); tree.getSelectionModel().setSelectionMode(SINGLE); treeContainer.add(tree); KeyboardNavigationHandler handler = new KeyboardNavigationHandler() { @Override public void onEnter(NativeEvent evt) { evt.preventDefault(); acceptButtonClicked(); } }; handler.bind(tree); cancelButton = createButton( locale.cancel(), "select-path-cancel-button", new ClickHandler() { @Override public void onClick(ClickEvent event) { hide(); } }); acceptButton = createPrimaryButton( locale.ok(), "select-path-ok-button", new ClickHandler() { @Override public void onClick(ClickEvent event) { acceptButtonClicked(); } }); addButtonToFooter(acceptButton); addButtonToFooter(cancelButton); }