Smooth goto-next navigation (without cycling on two recent files) in all files mode. Only interesting events (TC open/close) are handled. BLD200404051800
authorpkuzel@netbeans.org
Mon, 05 Apr 2004 16:12:07 +0000
changeset 4366d2ccdb54536c
parent 4365 66c1dad07a2d
child 4367 0fc39e5a6b4c
Smooth goto-next navigation (without cycling on two recent files) in all files mode. Only interesting events (TC open/close) are handled.
suggestions_framework/src/org/netbeans/modules/tasklist/suggestions/SuggestionsBroker.java
     1.1 --- a/suggestions_framework/src/org/netbeans/modules/tasklist/suggestions/SuggestionsBroker.java	Mon Apr 05 14:26:22 2004 +0000
     1.2 +++ b/suggestions_framework/src/org/netbeans/modules/tasklist/suggestions/SuggestionsBroker.java	Mon Apr 05 16:12:07 2004 +0000
     1.3 @@ -255,7 +255,9 @@
     1.4          LOGGER.info("Starting active suggestions fetching....");  // NOI18N
     1.5  
     1.6          // must be removed in docStop
     1.7 -        env.addTCRegistryListener(getWindowSystemMonitor());
     1.8 +        WindowSystemMonitor monitor = getWindowSystemMonitor();
     1.9 +        monitor.enableOpenCloseEvents();
    1.10 +        env.addTCRegistryListener(monitor);
    1.11          env.addDORegistryListener(getDataSystemMonitor());
    1.12  
    1.13          /* OLD:
    1.14 @@ -920,6 +922,9 @@
    1.15      }
    1.16  
    1.17      private void handleTopComponentClosed(TopComponent tc) {
    1.18 +
    1.19 +        componentsChanged();
    1.20 +
    1.21          DataObject dobj = extractDataObject(tc);
    1.22          if (dobj == null) return;
    1.23  
    1.24 @@ -929,9 +934,14 @@
    1.25          }
    1.26      }
    1.27  
    1.28 +    private void handleTopComponentOpened(TopComponent tc) {
    1.29 +        // XXX assume that tc is currently selected one
    1.30 +        componentsChanged();
    1.31 +    }
    1.32  
    1.33      private WindowSystemMonitor windowSystemMonitor;
    1.34  
    1.35 +    /** See note on {@link WindowSystemMonitor#enableOpenCloseEvents} */
    1.36      private WindowSystemMonitor getWindowSystemMonitor() {
    1.37          if (windowSystemMonitor == null) {
    1.38              windowSystemMonitor = new WindowSystemMonitor();
    1.39 @@ -943,11 +953,22 @@
    1.40  
    1.41          private Set openedSoFar = null;
    1.42  
    1.43 +        private TopComponent shouldBeShown;
    1.44 +
    1.45 +        /**
    1.46 +         * Must be called before adding this listener to environment if in hope that
    1.47 +         * it will provide (initial) open/close events.
    1.48 +         */
    1.49 +        private void enableOpenCloseEvents() {
    1.50 +            List list = Arrays.asList(SuggestionsScanner.openedTopComponents());
    1.51 +            openedSoFar = new HashSet(list);
    1.52 +            shouldBeShown = null;
    1.53 +        }
    1.54 +
    1.55          /** Reacts to changes */
    1.56          public void propertyChange(PropertyChangeEvent ev) {
    1.57              String prop = ev.getPropertyName();
    1.58              if (prop.equals(TopComponent.Registry.PROP_OPENED)) {
    1.59 -                componentsChanged();
    1.60  
    1.61                  if (allOpenedClientsCount > 0) {
    1.62                      // determine what components have been closed, window system does not
    1.63 @@ -957,28 +978,44 @@
    1.64                      Set actual = new HashSet(list);
    1.65  
    1.66                      if (openedSoFar != null) {
    1.67 -                        openedSoFar.removeAll(actual);
    1.68 -
    1.69                          Iterator it = openedSoFar.iterator();
    1.70                          while(it.hasNext()) {
    1.71                              TopComponent tc = (TopComponent) it.next();
    1.72 +                            if (actual.contains(tc) ) continue;
    1.73                              handleTopComponentClosed(tc);
    1.74                          }
    1.75 +
    1.76 +                        Iterator ita = actual.iterator();
    1.77 +                        while(ita.hasNext()) {
    1.78 +                            TopComponent tc = (TopComponent) ita.next();
    1.79 +                            if (openedSoFar.contains(tc)) continue;
    1.80 +                            assert shouldBeShown == null : "Multiple opened TCs in burst without showing them one-by-one is not handled"; // NOI18N
    1.81 +                            // defer actual action to componentShown, We need to assure opened TC is
    1.82 +                            // selected one. At this moment previous one is still selected.
    1.83 +                            shouldBeShown = tc;
    1.84 +                        }
    1.85                      }
    1.86  
    1.87                      openedSoFar = actual;
    1.88                  } else {
    1.89 +                    componentsChanged();
    1.90                      openedSoFar = null;
    1.91                  }
    1.92              }
    1.93          }
    1.94  
    1.95          public void componentShown(ComponentEvent e) {
    1.96 -            // Don't care
    1.97 +            if (shouldBeShown != null) {
    1.98 +                handleTopComponentOpened(shouldBeShown);
    1.99 +                shouldBeShown = null;
   1.100 +            }
   1.101          }
   1.102  
   1.103          public void componentHidden(ComponentEvent e) {
   1.104 -            componentsChanged();
   1.105 +            //XXX it does not support both "current file" and "all opened" clients at same time
   1.106 +            if (allOpenedClientsCount == 0) {
   1.107 +                componentsChanged();
   1.108 +            }
   1.109          }
   1.110  
   1.111          public void componentResized(ComponentEvent e) {