Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.54 KB | None | 0 0
  1. History.addValueChangeHandler(new ValueChangeHandler<String>() {
  2.  
  3.             public void onValueChange(ValueChangeEvent<String> historyChangeEvent) {
  4.                 String path = historyChangeEvent.getValue();
  5.                 System.out.println("History request: " + path);
  6.  
  7.                 List<String> viewIdNames = path.equals("") ? Collections.<String>emptyList() : Arrays.asList(path.split("\\/"));
  8.                 String currentPath = CoreGUI.this.currentView.getId().getPath();
  9.                 List<String> currentViewIdNames = currentPath.equals("") ? Collections.<String>emptyList() : Arrays.asList(currentPath.split("\\/"));
  10.  
  11.                 int commonBasePathSize = 0;
  12.                 for (int i = 0; i < viewIdNames.size() && i < currentViewIdNames.size(); i++) {
  13.                     String name = viewIdNames.get(i);
  14.                     String currentName = currentViewIdNames.get(i);
  15.                     if (name.equals(currentName)) {
  16.                         commonBasePathSize++;
  17.                     } else {
  18.                         break;
  19.                     }
  20.                 }
  21.                 int startIndex;
  22.                 View parentView;
  23.                 if (commonBasePathSize > 0) {
  24.                     // The requested path shares a common base path with the current view, so skip rendering of
  25.                     // views corresponding to this common base path. For example, if the current view is
  26.                     // Resource/10001/Summary/Overview and Resource/10001/Monitor/Graphs is requested, call renderView()
  27.                     // only on for the Monitor and Graphs components of the path.
  28.                     startIndex = commonBasePathSize;
  29.                     int subViewsToRenderPathSize = viewIdNames.size() - commonBasePathSize;
  30.                     parentView = CoreGUI.this.currentView;
  31.                     for (int i = 0; i < subViewsToRenderPathSize; i++) {
  32.                         parentView = parentView.getParent();
  33.                     }
  34.                 } else {
  35.                     // Otherwise, start at the root view (i.e. call renderView() for every component in the path).
  36.                     startIndex = 0;
  37.                     parentView = CoreGUI.this.rootView;
  38.                 }
  39.                 System.out.println("Starting parent view: " + parentView);
  40.  
  41.                 ViewRenderer viewRenderer = parentView.getDescendantViewRenderer();
  42.                 try {
  43.                     for (int i = startIndex, viewIdNamesSize = viewIdNames.size(); i < viewIdNamesSize; i++) {
  44.                         String viewIdName = viewIdNames.get(i);
  45.                         // See if the parent view provided a view renderer to use for its descendants. If not,
  46.                         // continue using the view renderer that renderer the parent view.
  47.                         ViewRenderer descendantViewRenderer = parentView.getDescendantViewRenderer();
  48.                         if (descendantViewRenderer != null) {
  49.                             viewRenderer = descendantViewRenderer;
  50.                         }
  51.                         ViewId viewId = new ViewId(viewIdName, parentView.getId());
  52.                         boolean lastNode = (i == (viewIdNamesSize - 1));
  53.                         View view = viewRenderer.renderView(viewId, lastNode);
  54.                         view.setParent(parentView);
  55.  
  56.                         parentView = view;
  57.                     }
  58.                 } catch (UnknownViewException e) {
  59.                     // Abort the for-loop, since once we hit an unknown name, we don't care about any remaining names
  60.                     // in the list. The breadcrumbs list will contain breadcrumbs for only the names that were
  61.                     // recognized.
  62.                     System.err.println(e.getMessage());
  63.                     // TODO: Should we add a new token to the History to point to the valid location
  64.                     //       we ended up at?
  65.                 }
  66.                 CoreGUI.this.currentView = parentView;
  67.  
  68.                 // Update the breadcrumb trail.
  69.                 List<Breadcrumb> breadcrumbs = new LinkedList<Breadcrumb>();
  70.                 while (parentView.getParent() != null) {
  71.                     breadcrumbs.add(0, parentView.getBreadcrumb());
  72.                     parentView = parentView.getParent();
  73.                 }
  74.                 System.out.println("Breadcrumbs: " + breadcrumbs);
  75.                 breadCrumbTrailPane.setBreadcrumbs(breadcrumbs);
  76.                 breadCrumbTrailPane.refresh();
  77.             }
  78.         });
  79.  
  80.         History.fireCurrentHistoryState();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement