Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- History.addValueChangeHandler(new ValueChangeHandler<String>() {
- public void onValueChange(ValueChangeEvent<String> historyChangeEvent) {
- String path = historyChangeEvent.getValue();
- System.out.println("History request: " + path);
- List<String> viewIdNames = path.equals("") ? Collections.<String>emptyList() : Arrays.asList(path.split("\\/"));
- String currentPath = CoreGUI.this.currentView.getId().getPath();
- List<String> currentViewIdNames = currentPath.equals("") ? Collections.<String>emptyList() : Arrays.asList(currentPath.split("\\/"));
- int commonBasePathSize = 0;
- for (int i = 0; i < viewIdNames.size() && i < currentViewIdNames.size(); i++) {
- String name = viewIdNames.get(i);
- String currentName = currentViewIdNames.get(i);
- if (name.equals(currentName)) {
- commonBasePathSize++;
- } else {
- break;
- }
- }
- int startIndex;
- View parentView;
- if (commonBasePathSize > 0) {
- // The requested path shares a common base path with the current view, so skip rendering of
- // views corresponding to this common base path. For example, if the current view is
- // Resource/10001/Summary/Overview and Resource/10001/Monitor/Graphs is requested, call renderView()
- // only on for the Monitor and Graphs components of the path.
- startIndex = commonBasePathSize;
- int subViewsToRenderPathSize = viewIdNames.size() - commonBasePathSize;
- parentView = CoreGUI.this.currentView;
- for (int i = 0; i < subViewsToRenderPathSize; i++) {
- parentView = parentView.getParent();
- }
- } else {
- // Otherwise, start at the root view (i.e. call renderView() for every component in the path).
- startIndex = 0;
- parentView = CoreGUI.this.rootView;
- }
- System.out.println("Starting parent view: " + parentView);
- ViewRenderer viewRenderer = parentView.getDescendantViewRenderer();
- try {
- for (int i = startIndex, viewIdNamesSize = viewIdNames.size(); i < viewIdNamesSize; i++) {
- String viewIdName = viewIdNames.get(i);
- // See if the parent view provided a view renderer to use for its descendants. If not,
- // continue using the view renderer that renderer the parent view.
- ViewRenderer descendantViewRenderer = parentView.getDescendantViewRenderer();
- if (descendantViewRenderer != null) {
- viewRenderer = descendantViewRenderer;
- }
- ViewId viewId = new ViewId(viewIdName, parentView.getId());
- boolean lastNode = (i == (viewIdNamesSize - 1));
- View view = viewRenderer.renderView(viewId, lastNode);
- view.setParent(parentView);
- parentView = view;
- }
- } catch (UnknownViewException e) {
- // Abort the for-loop, since once we hit an unknown name, we don't care about any remaining names
- // in the list. The breadcrumbs list will contain breadcrumbs for only the names that were
- // recognized.
- System.err.println(e.getMessage());
- // TODO: Should we add a new token to the History to point to the valid location
- // we ended up at?
- }
- CoreGUI.this.currentView = parentView;
- // Update the breadcrumb trail.
- List<Breadcrumb> breadcrumbs = new LinkedList<Breadcrumb>();
- while (parentView.getParent() != null) {
- breadcrumbs.add(0, parentView.getBreadcrumb());
- parentView = parentView.getParent();
- }
- System.out.println("Breadcrumbs: " + breadcrumbs);
- breadCrumbTrailPane.setBreadcrumbs(breadcrumbs);
- breadCrumbTrailPane.refresh();
- }
- });
- History.fireCurrentHistoryState();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement