Lines 24-29
Link Here
|
24 |
import org.openide.cookies.EditorCookie; |
24 |
import org.openide.cookies.EditorCookie; |
25 |
import org.openide.util.RequestProcessor; |
25 |
import org.openide.util.RequestProcessor; |
26 |
import org.openide.filesystems.FileObject; |
26 |
import org.openide.filesystems.FileObject; |
|
|
27 |
import org.openide.ErrorManager; |
27 |
import org.netbeans.modules.tasklist.suggestions.settings.ManagerSettings; |
28 |
import org.netbeans.modules.tasklist.suggestions.settings.ManagerSettings; |
28 |
import org.netbeans.modules.tasklist.core.TLUtils; |
29 |
import org.netbeans.modules.tasklist.core.TLUtils; |
29 |
import org.netbeans.modules.tasklist.core.Task; |
30 |
import org.netbeans.modules.tasklist.core.Task; |
Lines 42-47
Link Here
|
42 |
import java.util.*; |
43 |
import java.util.*; |
43 |
import java.util.List; |
44 |
import java.util.List; |
44 |
import java.util.logging.Logger; |
45 |
import java.util.logging.Logger; |
|
|
46 |
import java.lang.reflect.InvocationTargetException; |
45 |
|
47 |
|
46 |
/** |
48 |
/** |
47 |
* Broker actively monitors environment and provides |
49 |
* Broker actively monitors environment and provides |
Lines 506-546
Link Here
|
506 |
|
508 |
|
507 |
if (ManagerSettings.getDefault().isScanOnShow()) { |
509 |
if (ManagerSettings.getDefault().isScanOnShow()) { |
508 |
if (delayed) { |
510 |
if (delayed) { |
509 |
performRescanInRP(dao, ManagerSettings.getDefault().getShowScanDelay()); |
511 |
performRescanInRP(current, dao, ManagerSettings.getDefault().getShowScanDelay()); |
510 |
} else { |
512 |
} else { |
511 |
performRescanInRP(dao, 0); |
513 |
performRescanInRP(current, dao, 0); |
512 |
} |
514 |
} |
513 |
} |
515 |
} |
514 |
} |
516 |
} |
515 |
|
517 |
|
516 |
private static DataObject extractDataObject(TopComponent topComponent) { |
518 |
private static DataObject extractDataObject(TopComponent topComponent) { |
517 |
Node[] nodes = topComponent.getActivatedNodes(); |
519 |
DataObject dobj = (DataObject) topComponent.getLookup().lookup(DataObject.class); |
518 |
|
520 |
if (dobj != null && dobj.isValid()) { |
519 |
if ((nodes == null) || (nodes.length != 1)) { |
521 |
return dobj; |
520 |
/* |
522 |
} else { |
521 |
if (err.isLoggable(ErrorManager.INFORMATIONAL)) { |
523 |
// System.err.println("[TODO] cannot get DO for " + topComponent); |
522 |
err.log( |
524 |
// Thread.dumpStack(); |
523 |
"Unexpected editor component activated nodes " + // NOI18N |
|
|
524 |
" contents: " + nodes); // NOI18N |
525 |
} |
526 |
*/ |
527 |
return null; |
528 |
} |
529 |
|
530 |
Node node = nodes[0]; |
531 |
|
532 |
final DataObject dao = (DataObject) node.getCookie(DataObject.class); |
533 |
//err.log("Considering data object " + dao); |
534 |
if (dao == null) { |
535 |
return null; |
536 |
} |
537 |
|
538 |
if (!dao.isValid()) { |
539 |
//err.log("The data object is not valid!"); |
540 |
return null; |
525 |
return null; |
541 |
} |
526 |
} |
542 |
|
|
|
543 |
return dao; |
544 |
} |
527 |
} |
545 |
|
528 |
|
546 |
/** |
529 |
/** |
Lines 556-567
Link Here
|
556 |
* Spawns <b>Suggestions Broker thread</b> that finishes actula work |
539 |
* Spawns <b>Suggestions Broker thread</b> that finishes actula work |
557 |
* asynchronously. |
540 |
* asynchronously. |
558 |
* |
541 |
* |
|
|
542 |
* @param tc |
559 |
* @param dataobject The Data Object for the file being opened |
543 |
* @param dataobject The Data Object for the file being opened |
560 |
* @param delay postpone the action by delay miliseconds |
544 |
* @param delay postpone the action by delay miliseconds |
561 |
* |
545 |
* |
562 |
* @return parametrized task that rescans given dataobject in delay miliseconds |
546 |
* @return parametrized task that rescans given dataobject in delay miliseconds |
563 |
*/ |
547 |
*/ |
564 |
private RequestProcessor.Task performRescanInRP(final DataObject dataobject, int delay) { |
548 |
private RequestProcessor.Task performRescanInRP(final TopComponent tc, final DataObject dataobject, int delay) { |
565 |
|
549 |
|
566 |
/* Scan requests are run in a separate "background" thread. |
550 |
/* Scan requests are run in a separate "background" thread. |
567 |
However, what happens if the user switches to a different |
551 |
However, what happens if the user switches to a different |
Lines 608-613
Link Here
|
608 |
return; |
592 |
return; |
609 |
} |
593 |
} |
610 |
|
594 |
|
|
|
595 |
// reassure that Tc was not meanwhile closed. Both current file job |
596 |
// and all opened files job monitors just files opened in editor pane |
597 |
|
598 |
final boolean[] isOpened = new boolean[1]; |
599 |
try { |
600 |
SwingUtilities.invokeAndWait(new Runnable() { |
601 |
public void run() { |
602 |
isOpened[0] = tc.isOpened(); // must be called from AWT |
603 |
} |
604 |
}); |
605 |
} catch (InterruptedException e) { |
606 |
ErrorManager err = ErrorManager.getDefault(); |
607 |
err.annotate(e, "[TODO] ignoring rescan of " + tc.getDisplayName()); // NOI18N |
608 |
err.notify(e); |
609 |
} catch (InvocationTargetException e) { |
610 |
ErrorManager err = ErrorManager.getDefault(); |
611 |
err.annotate(e, "[TODO] ignoring rescan of " + tc.getDisplayName()); // NOI18N |
612 |
err.notify(e); |
613 |
} |
614 |
|
615 |
if (isOpened[0] == false) { |
616 |
// System.err.println("[TODO] ignoring rescan request for " + tc.getDisplayName()); |
617 |
return; |
618 |
} |
619 |
|
611 |
LOGGER.fine("Dispatching rescan() request to providers..."); |
620 |
LOGGER.fine("Dispatching rescan() request to providers..."); |
612 |
|
621 |
|
613 |
setScanning(true); |
622 |
setScanning(true); |
Lines 782-788
Link Here
|
782 |
LOGGER.fine("Scheduled rescan task delayed by " + scanDelay + " ms."); // NOI18N |
791 |
LOGGER.fine("Scheduled rescan task delayed by " + scanDelay + " ms."); // NOI18N |
783 |
} |
792 |
} |
784 |
|
793 |
|
785 |
scheduledRescan = performRescanInRP(dataobject, scanDelay); |
794 |
// trap, randomly triggered by multiview |
|
|
795 |
assert dataobject.equals(extractDataObject(current)) : "DO=" + dataobject + " TC=" + current; |
796 |
scheduledRescan = performRescanInRP(current, dataobject, scanDelay); |
786 |
} |
797 |
} |
787 |
|
798 |
|
788 |
/** An event ocurred during quiet fix period. */ |
799 |
/** An event ocurred during quiet fix period. */ |
Lines 908-925
Link Here
|
908 |
|
919 |
|
909 |
private void handleTopComponentClosed(TopComponent tc) { |
920 |
private void handleTopComponentClosed(TopComponent tc) { |
910 |
|
921 |
|
|
|
922 |
//System.err.println("[TODO] closing: " + tc.getDisplayName()); |
923 |
|
911 |
componentsChanged(); |
924 |
componentsChanged(); |
912 |
|
925 |
|
913 |
DataObject dobj = extractDataObject(tc); |
926 |
DataObject dobj = extractDataObject(tc); |
914 |
if (dobj == null) return; |
927 |
if (dobj == null) { |
|
|
928 |
//System.err.println("[TODO] has no DO: " + tc.getDisplayName()); |
929 |
return; |
930 |
} |
915 |
|
931 |
|
916 |
List previous = (List) openedFilesSuggestionsMap.remove(dobj.getPrimaryFile()); |
932 |
List previous = (List) openedFilesSuggestionsMap.remove(dobj.getPrimaryFile()); |
917 |
if (previous != null) { |
933 |
if (previous != null) { |
|
|
934 |
//System.err.println("[TODO] removing TODOs: " + tc.getDisplayName() + " :" + previous); |
918 |
getAllOpenedSuggestionList().addRemove(null, previous, false, null, null); |
935 |
getAllOpenedSuggestionList().addRemove(null, previous, false, null, null); |
|
|
936 |
} else { |
937 |
//System.err.println("[TODO] has no TODOs: " + tc.getDisplayName()); |
919 |
} |
938 |
} |
920 |
} |
939 |
} |
921 |
|
940 |
|
922 |
private void handleTopComponentOpened(TopComponent tc) { |
941 |
private void handleTopComponentOpened(TopComponent tc) { |
|
|
942 |
//System.err.println("[TODO] opened: " + tc.getDisplayName()); |
923 |
if (tc.isShowing()) { |
943 |
if (tc.isShowing()) { |
924 |
// currently selected one |
944 |
// currently selected one |
925 |
componentsChanged(); |
945 |
componentsChanged(); |
Lines 927-933
Link Here
|
927 |
// it is not selected anymore, it was opened in burst |
947 |
// it is not selected anymore, it was opened in burst |
928 |
DataObject dao = extractDataObject(tc); |
948 |
DataObject dao = extractDataObject(tc); |
929 |
if (dao == null) return; |
949 |
if (dao == null) return; |
930 |
performRescanInRP(dao, ManagerSettings.getDefault().getShowScanDelay()); |
950 |
performRescanInRP(tc, dao, ManagerSettings.getDefault().getShowScanDelay()); |
931 |
} |
951 |
} |
932 |
} |
952 |
} |
933 |
|
953 |
|