@@ -67,7 +67,7 @@ public class MainController implements API {
6767
6868 protected History history = new History ();
6969 protected JComponent currentPage = null ;
70- protected ScheduledExecutorService executor = Executors .newSingleThreadScheduledExecutor ( );
70+ protected ScheduledExecutorService executor = Executors .newScheduledThreadPool ( 2 );
7171 protected ArrayList <IndexesChangeListener > containerChangeListeners = new ArrayList <>();
7272
7373 @ SuppressWarnings ("unchecked" )
@@ -111,7 +111,7 @@ public MainController(Configuration configuration) {
111111 file -> openFile ((File )file ));
112112 });
113113 }
114-
114+
115115 // --- Show GUI --- //
116116 @ SuppressWarnings ("unchecked" )
117117 public void show (List <File > files ) {
@@ -132,9 +132,6 @@ public void show(List<File> files) {
132132 IndexerService .getInstance ();
133133 TreeNodeFactoryService .getInstance ();
134134 TypeFactoryService .getInstance ();
135- PasteHandlerService .getInstance ();
136- PreferencesPanelService .getInstance ();
137- ContextualActionsFactoryService .getInstance ();
138135
139136 SwingUtil .invokeLater (() -> {
140137 // Populate recent files menu
@@ -159,6 +156,11 @@ public void show(List<File> files) {
159156 new JLayer ();
160157 });
161158 }, 400 , TimeUnit .MILLISECONDS );
159+
160+ PasteHandlerService .getInstance ();
161+ PreferencesPanelService .getInstance ();
162+ ContextualActionsFactoryService .getInstance ();
163+ SourceSaverService .getInstance ();
162164 }
163165
164166 // --- Actions --- //
@@ -312,13 +314,13 @@ protected void onFindNext() {
312314 }
313315
314316 protected void onOpenType () {
315- openTypeController .show (getCollectionOfIndexes (), uri -> openURI (uri ));
317+ openTypeController .show (getCollectionOfFutureIndexes (), uri -> openURI (uri ));
316318 }
317319
318320 protected void onOpenTypeHierarchy () {
319321 if (currentPage instanceof FocusedTypeGettable ) {
320322 FocusedTypeGettable ftg = (FocusedTypeGettable )currentPage ;
321- openTypeHierarchyController .show (getCollectionOfIndexes (), ftg .getEntry (), ftg .getFocusedTypeName (), uri -> openURI (uri ));
323+ openTypeHierarchyController .show (getCollectionOfFutureIndexes (), ftg .getEntry (), ftg .getFocusedTypeName (), uri -> openURI (uri ));
322324 }
323325 }
324326
@@ -330,7 +332,7 @@ protected void onGoTo() {
330332 }
331333
332334 protected void onSearch () {
333- searchInConstantPoolsController .show (getCollectionOfIndexes (), uri -> openURI (uri ));
335+ searchInConstantPoolsController .show (getCollectionOfFutureIndexes (), uri -> openURI (uri ));
334336 }
335337
336338 protected void onFindPrevious () {
@@ -380,32 +382,32 @@ protected void onAbout() {
380382
381383 protected void onCurrentPageChanged (JComponent page ) {
382384 currentPage = page ;
383- checkIndexesChange (page );
384385 checkPreferencesChange (page );
386+ checkIndexesChange (page );
385387 }
386388
387- protected void checkIndexesChange (JComponent page ) {
388- if (page instanceof IndexesChangeListener ) {
389- Collection < Indexes > collectionOfIndexes = getCollectionOfIndexes ();
390- Integer currentHashcode = Integer .valueOf (collectionOfIndexes .hashCode ());
391- Integer lastHashcode = (Integer )page .getClientProperty ("collectionOfIndexes-stamp " );
389+ protected void checkPreferencesChange (JComponent page ) {
390+ if (page instanceof PreferencesChangeListener ) {
391+ Map < String , String > preferences = configuration . getPreferences ();
392+ Integer currentHashcode = Integer .valueOf (preferences .hashCode ());
393+ Integer lastHashcode = (Integer )page .getClientProperty ("preferences-hashCode " );
392394
393395 if (!currentHashcode .equals (lastHashcode )) {
394- ((IndexesChangeListener )page ).indexesChanged ( collectionOfIndexes );
395- page .putClientProperty ("collectionOfIndexes-stamp " , currentHashcode );
396+ ((PreferencesChangeListener )page ).preferencesChanged ( preferences );
397+ page .putClientProperty ("preferences-hashCode " , currentHashcode );
396398 }
397399 }
398400 }
399401
400- protected void checkPreferencesChange (JComponent page ) {
401- if (page instanceof PreferencesChangeListener ) {
402- Map < String , String > preferences = configuration . getPreferences ();
403- Integer currentHashcode = Integer .valueOf (preferences .hashCode ());
404- Integer lastHashcode = (Integer )page .getClientProperty ("preferences-stamp " );
402+ protected void checkIndexesChange (JComponent page ) {
403+ if (page instanceof IndexesChangeListener ) {
404+ Collection < Future < Indexes >> collectionOfFutureIndexes = getCollectionOfFutureIndexes ();
405+ Integer currentHashcode = Integer .valueOf (collectionOfFutureIndexes .hashCode ());
406+ Integer lastHashcode = (Integer )page .getClientProperty ("collectionOfFutureIndexes-hashCode " );
405407
406408 if (!currentHashcode .equals (lastHashcode )) {
407- ((PreferencesChangeListener )page ).preferencesChanged ( preferences );
408- page .putClientProperty ("preferences-stamp " , currentHashcode );
409+ ((IndexesChangeListener )page ).indexesChanged ( collectionOfFutureIndexes );
410+ page .putClientProperty ("collectionOfFutureIndexes-hashCode " , currentHashcode );
409411 }
410412 }
411413 }
@@ -516,12 +518,12 @@ public void componentResized(ComponentEvent e) {
516518 protected void panelClosed () {
517519 SwingUtil .invokeLater (() -> {
518520 // Fire 'indexesChanged' event
519- Collection <Indexes > collectionOfIndexes = getCollectionOfIndexes ();
521+ Collection <Future < Indexes >> collectionOfFutureIndexes = getCollectionOfFutureIndexes ();
520522 for (IndexesChangeListener listener : containerChangeListeners ) {
521- listener .indexesChanged (collectionOfIndexes );
523+ listener .indexesChanged (collectionOfFutureIndexes );
522524 }
523525 if (currentPage instanceof IndexesChangeListener ) {
524- ((IndexesChangeListener )currentPage ).indexesChanged (collectionOfIndexes );
526+ ((IndexesChangeListener )currentPage ).indexesChanged (collectionOfFutureIndexes );
525527 }
526528 });
527529 }
@@ -556,15 +558,15 @@ public boolean openURI(int x, int y, Collection<Container.Entry> entries, String
556558 if (entries .size () == 1 ) {
557559 // Open the single entry uri
558560 Container .Entry entry = entries .iterator ().next ();
559- return openURI (UriUtil .createURI (this , getCollectionOfIndexes (), entry , query , fragment ));
561+ return openURI (UriUtil .createURI (this , getCollectionOfFutureIndexes (), entry , query , fragment ));
560562 } else {
561563 // Multiple entries -> Open a "Select location" popup
562- Collection <Indexes > collectionOfIndexes = getCollectionOfIndexes ();
564+ Collection <Future < Indexes >> collectionOfFutureIndexes = getCollectionOfFutureIndexes ();
563565 selectLocationController .show (
564566 new Point (x +(16 +2 ), y +2 ),
565567 entries ,
566- entry -> openURI (UriUtil .createURI (this , collectionOfIndexes , entry , query , fragment )), // entry selected closure
567- () -> {}); // popup close closure
568+ entry -> openURI (UriUtil .createURI (this , collectionOfFutureIndexes , entry , query , fragment )), // entry selected closure
569+ () -> {}); // popup close closure
568570 return true ;
569571 }
570572 }
@@ -586,40 +588,25 @@ public <T extends JComponent & UriGettable> void addPanel(String title, Icon ico
586588 mainView .addMainPanel (title , icon , tip , component );
587589
588590 if (component instanceof ContentIndexable ) {
589- Future <Indexes > futureIndexes = executor .submit (() -> ((ContentIndexable )component ).index (this ));
590- Indexes indexes = new Indexes () {
591- @ Override public void waitIndexers () {
592- try {
593- futureIndexes .get ();
594- } catch (Exception e ) {
595- assert ExceptionUtil .printStackTrace (e );
591+ Future <Indexes > futureIndexes = executor .submit (() -> {
592+ Indexes indexes = ((ContentIndexable )component ).index (this );
593+
594+ SwingUtil .invokeLater (() -> {
595+ // Fire 'indexesChanged' event
596+ Collection <Future <Indexes >> collectionOfFutureIndexes = getCollectionOfFutureIndexes ();
597+ for (IndexesChangeListener listener : containerChangeListeners ) {
598+ listener .indexesChanged (collectionOfFutureIndexes );
596599 }
597- }
598- @ Override public Map <String , Collection > getIndex (String name ) {
599- try {
600- return futureIndexes .get ().getIndex (name );
601- } catch (Exception e ) {
602- assert ExceptionUtil .printStackTrace (e );
603- return null ;
600+ if (currentPage instanceof IndexesChangeListener ) {
601+ ((IndexesChangeListener ) currentPage ).indexesChanged (collectionOfFutureIndexes );
604602 }
605- }
606- };
607-
608- component .putClientProperty ("indexes" , indexes );
603+ });
609604
610- SwingUtil .invokeLater (() -> {
611- // Fire 'indexesChanged' event
612- Collection <Indexes > collectionOfIndexes = getCollectionOfIndexes ();
613- for (IndexesChangeListener listener : containerChangeListeners ) {
614- listener .indexesChanged (collectionOfIndexes );
615- }
616- if (currentPage instanceof IndexesChangeListener ) {
617- ((IndexesChangeListener )currentPage ).indexesChanged (collectionOfIndexes );
618- }
605+ return indexes ;
619606 });
620- }
621607
622- checkIndexesChange (currentPage );
608+ component .putClientProperty ("indexes" , futureIndexes );
609+ }
623610 }
624611
625612 @ Override public Collection <Action > getContextualActions (Container .Entry entry , String fragment ) { return ContextualActionsFactoryService .getInstance ().get (this , entry , fragment ); }
@@ -642,16 +629,35 @@ public <T extends JComponent & UriGettable> void addPanel(String title, Icon ico
642629
643630 @ Override public Map <String , String > getPreferences () { return configuration .getPreferences (); }
644631
632+ @ Override
645633 @ SuppressWarnings ("unchecked" )
646- public Collection <Indexes > getCollectionOfIndexes () {
634+ public Collection <Future < Indexes >> getCollectionOfFutureIndexes () {
647635 List <JComponent > mainPanels = mainView .getMainPanels ();
648- ArrayList <Indexes > list = new ArrayList <>(mainPanels .size ());
636+ ArrayList <Future <Indexes >> list = new ArrayList <Future <Indexes >>(mainPanels .size ()) {
637+ @ Override
638+ public int hashCode () {
639+ int hashCode = 1 ;
649640
650- for (JComponent panel : mainPanels ) {
651- Indexes indexes = (Indexes )panel .getClientProperty ("indexes" );
641+ try {
642+ for (Future <Indexes > futureIndexes : this ) {
643+ hashCode *= 31 ;
652644
653- if (indexes != null ) {
654- list .add (indexes );
645+ if (futureIndexes .isDone ()) {
646+ hashCode += futureIndexes .get ().hashCode ();
647+ }
648+ }
649+ } catch (Exception e ) {
650+ assert ExceptionUtil .printStackTrace (e );
651+ }
652+
653+ return hashCode ;
654+ }
655+ };
656+
657+ for (JComponent panel : mainPanels ) {
658+ Future <Indexes > futureIndexes = (Future <Indexes >)panel .getClientProperty ("indexes" );
659+ if (futureIndexes != null ) {
660+ list .add (futureIndexes );
655661 }
656662 }
657663
0 commit comments