List of usage examples for com.google.gwt.user.cellview.client CellTree addOpenHandler
public HandlerRegistration addOpenHandler(OpenHandler<TreeNode> handler)
From source file:com.google.gwt.sample.showcase.client.Showcase.java
License:Apache License
/** * This is the entry point method.//w w w. jav a 2 s . co m */ public void onModuleLoad() { // Generate the source code and css for the examples GWT.create(GeneratorInfo.class); // Inject global styles. injectThemeStyleSheet(); images.css().ensureInjected(); // Initialize the constants. ShowcaseConstants constants = GWT.create(ShowcaseConstants.class); // Create the application shell. final SingleSelectionModel<ContentWidget> selectionModel = new SingleSelectionModel<ContentWidget>(); final MainMenuTreeViewModel treeModel = new MainMenuTreeViewModel(constants, selectionModel); Set<ContentWidget> contentWidgets = treeModel.getAllContentWidgets(); shell = new ShowcaseShell(treeModel); RootLayoutPanel.get().add(shell); // Prefetch examples when opening the Category tree nodes. final List<Category> prefetched = new ArrayList<Category>(); final CellTree mainMenu = shell.getMainMenu(); mainMenu.addOpenHandler(new OpenHandler<TreeNode>() { public void onOpen(OpenEvent<TreeNode> event) { Object value = event.getTarget().getValue(); if (!(value instanceof Category)) { return; } Category category = (Category) value; if (!prefetched.contains(category)) { prefetched.add(category); Prefetcher.prefetch(category.getSplitPoints()); } } }); // Always prefetch. Prefetcher.start(); // Change the history token when a main menu item is selected. selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { ContentWidget selected = selectionModel.getSelectedObject(); if (selected != null) { History.newItem(getContentWidgetToken(selected), true); } } }); // Setup a history handler to reselect the associate menu item. final ValueChangeHandler<String> historyHandler = new ValueChangeHandler<String>() { public void onValueChange(ValueChangeEvent<String> event) { // Get the content widget associated with the history token. ContentWidget contentWidget = treeModel.getContentWidgetForToken(event.getValue()); if (contentWidget == null) { return; } // Expand the tree node associated with the content. Category category = treeModel.getCategoryForContentWidget(contentWidget); TreeNode node = mainMenu.getRootTreeNode(); int childCount = node.getChildCount(); for (int i = 0; i < childCount; i++) { if (node.getChildValue(i) == category) { node.setChildOpen(i, true, true); break; } } // Select the node in the tree. selectionModel.setSelected(contentWidget, true); // Display the content widget. displayContentWidget(contentWidget); } }; History.addValueChangeHandler(historyHandler); // Show the initial example. if (History.getToken().length() > 0) { History.fireCurrentHistoryState(); } else { // Use the first token available. TreeNode root = mainMenu.getRootTreeNode(); TreeNode category = root.setChildOpen(0, true); ContentWidget content = (ContentWidget) category.getChildValue(0); selectionModel.setSelected(content, true); } // Generate a site map. createSiteMap(contentWidgets); }
From source file:thothbot.parallax.demo.client.Demo.java
License:Open Source License
public void onModuleLoad() { GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() { public void onUncaughtException(Throwable throwable) { Log.error("Uncaught exception", throwable); if (!GWT.isScript()) { String text = "Uncaught exception: "; while (throwable != null) { StackTraceElement[] stackTraceElements = throwable.getStackTrace(); text += throwable.toString() + "\n"; for (int i = 0; i < stackTraceElements.length; i++) text += " at " + stackTraceElements[i] + "\n"; throwable = throwable.getCause(); if (throwable != null) text += "Caused by: "; }/*w w w . j av a 2 s. co m*/ DialogBox dialogBox = new DialogBox(true); DOM.setStyleAttribute(dialogBox.getElement(), "backgroundColor", "#ABCDEF"); text = text.replaceAll(" ", " "); dialogBox.setHTML("<pre>" + text + "</pre>"); dialogBox.center(); } } }); // Generate the source code for examples GWT.create(GenerateSourceSignal.class); // Generate the demo file GWT.create(GenerateFacebookSignal.class); resources.css().ensureInjected(); // Create the application shell. final SingleSelectionModel<ContentWidget> selectionModel = new SingleSelectionModel<ContentWidget>(); final DataModel treeModel = new DataModel(selectionModel); Set<ContentWidget> contentWidgets = treeModel.getAllContentWidgets(); index = new Index(); // Hide loading panel RootPanel.get("loading").getElement().getStyle().setVisibility(Visibility.HIDDEN); // Attach index panel RootLayoutPanel.get().add(index); index.getTabIndex().addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { displayIndex(); } }); indexWidget = new IndexWidget(treeModel); shell = new DemoShell(treeModel, index); // Prefetch examples when opening the Category tree nodes. final List<Category> prefetched = new ArrayList<Category>(); final CellTree mainMenu = shell.getMainMenu(); mainMenu.addOpenHandler(new OpenHandler<TreeNode>() { public void onOpen(OpenEvent<TreeNode> event) { Object value = event.getTarget().getValue(); if (!(value instanceof Category)) return; Category category = (Category) value; if (!prefetched.contains(category)) { prefetched.add(category); Prefetcher.prefetch(category.getSplitPoints()); } } }); // Always prefetch. Prefetcher.start(); // Change the history token when a main menu item is selected. selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { ContentWidget selected = selectionModel.getSelectedObject(); if (selected != null) { index.setContentWidget(shell); History.newItem("!" + selected.getContentWidgetToken(), true); } } }); // Setup a history handler to reselect the associate menu item. final ValueChangeHandler<String> historyHandler = new ValueChangeHandler<String>() { public void onValueChange(ValueChangeEvent<String> event) { // Get the content widget associated with the history token. ContentWidget contentWidget = treeModel .getContentWidgetForToken(event.getValue().replaceFirst("!", "")); if (contentWidget == null) return; // Expand the tree node associated with the content. Category category = treeModel.getCategoryForContentWidget(contentWidget); TreeNode node = mainMenu.getRootTreeNode(); int childCount = node.getChildCount(); for (int i = 0; i < childCount; i++) { if (node.getChildValue(i) == category) { node.setChildOpen(i, true, true); break; } } // Display the content widget. displayContentWidget(contentWidget); //Add GA statistics trackPageview(Window.Location.getHref()); // Select the node in the tree. selectionModel.setSelected(contentWidget, true); } }; History.addValueChangeHandler(historyHandler); // Show the initial example. if (History.getToken().length() > 0) History.fireCurrentHistoryState(); // Use the first token available. else displayIndex(); // Generate a site map. createSiteMap(contentWidgets); }