Cancelling ContributionsSelfCheck will prevent indexes from being updated.

Opening boards/libs manager when NotificationPopup is shown will close it
This commit is contained in:
Federico Fissore 2015-08-04 12:00:00 +02:00
parent 2daf330c09
commit 0bb7fd7e8b
3 changed files with 33 additions and 9 deletions

View File

@ -26,6 +26,9 @@ public class ContributionsSelfCheck extends TimerTask {
private final LibraryInstaller libraryInstaller; private final LibraryInstaller libraryInstaller;
private final ProgressListener progressListener; private final ProgressListener progressListener;
private volatile boolean cancelled;
private volatile NotificationPopup notificationPopup;
public ContributionsSelfCheck(Base base, HyperlinkListener hyperlinkListener, ContributionsIndexer contributionsIndexer, ContributionInstaller contributionInstaller, LibrariesIndexer librariesIndexer, LibraryInstaller libraryInstaller) { public ContributionsSelfCheck(Base base, HyperlinkListener hyperlinkListener, ContributionsIndexer contributionsIndexer, ContributionInstaller contributionInstaller, LibrariesIndexer librariesIndexer, LibraryInstaller libraryInstaller) {
this.base = base; this.base = base;
this.hyperlinkListener = hyperlinkListener; this.hyperlinkListener = hyperlinkListener;
@ -34,6 +37,7 @@ public class ContributionsSelfCheck extends TimerTask {
this.librariesIndexer = librariesIndexer; this.librariesIndexer = librariesIndexer;
this.libraryInstaller = libraryInstaller; this.libraryInstaller = libraryInstaller;
this.progressListener = new NoopProgressListener(); this.progressListener = new NoopProgressListener();
this.cancelled = false;
} }
@Override @Override
@ -62,12 +66,29 @@ public class ContributionsSelfCheck extends TimerTask {
text = I18n.format(_("Some {0}boards{1} and some {2}libraries{3} may be updated"), "<a href=\"http://boardsmanager\">", "</a>", "<a href=\"http://librarymanager\">", "</a>"); text = I18n.format(_("Some {0}boards{1} and some {2}libraries{3} may be updated"), "<a href=\"http://boardsmanager\">", "</a>", "<a href=\"http://librarymanager\">", "</a>");
} }
if (cancelled) {
return;
}
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
new NotificationPopup(base.getActiveEditor(), hyperlinkListener, _("Updates available"), text).setVisible(true); notificationPopup = new NotificationPopup(base.getActiveEditor(), hyperlinkListener, _("Updates available"), text);
notificationPopup.setVisible(true);
}); });
} }
@Override
public boolean cancel() {
cancelled = true;
if (notificationPopup != null) {
notificationPopup.close();
}
return super.cancel();
}
private void updateLibrariesIndex() { private void updateLibrariesIndex() {
if (cancelled) {
return;
}
try { try {
libraryInstaller.updateIndex(progressListener); libraryInstaller.updateIndex(progressListener);
} catch (Exception e) { } catch (Exception e) {
@ -76,6 +97,9 @@ public class ContributionsSelfCheck extends TimerTask {
} }
private void updateContributionIndex() { private void updateContributionIndex() {
if (cancelled) {
return;
}
try { try {
contributionInstaller.updateIndex(progressListener); contributionInstaller.updateIndex(progressListener);
} catch (Exception e) { } catch (Exception e) {

View File

@ -98,7 +98,7 @@ public class NotificationPopup extends JDialog {
setLocation(parentX + parent.getWidth() - getWidth(), parentY + parent.getHeight() - getHeight()); setLocation(parentX + parent.getWidth() - getWidth(), parentY + parent.getHeight() - getHeight());
} }
private void close() { public void close() {
if (autoCloseAfterTimeout.isRunning()) { if (autoCloseAfterTimeout.isRunning()) {
autoCloseAfterTimeout.stop(); autoCloseAfterTimeout.stop();
} }

View File

@ -94,7 +94,7 @@ public class Base {
public static Map<String, Object> FIND_DIALOG_STATE = new HashMap<String, Object>(); public static Map<String, Object> FIND_DIALOG_STATE = new HashMap<String, Object>();
private final ContributionInstaller contributionInstaller; private final ContributionInstaller contributionInstaller;
private final LibraryInstaller libraryInstaller; private final LibraryInstaller libraryInstaller;
private Timer selfCheckTimer; private ContributionsSelfCheck contributionsSelfCheck;
// set to true after the first time the menu is built. // set to true after the first time the menu is built.
// so that the errors while building don't show up again. // so that the errors while building don't show up again.
@ -466,8 +466,8 @@ public class Base {
new Thread(new BuiltInCoreIsNewerCheck(this)).start(); new Thread(new BuiltInCoreIsNewerCheck(this)).start();
selfCheckTimer = new Timer(false); contributionsSelfCheck = new ContributionsSelfCheck(this, new UpdatableBoardsLibsFakeURLsHandler(this), BaseNoGui.indexer, contributionInstaller, BaseNoGui.librariesIndexer, libraryInstaller);
selfCheckTimer.schedule(new ContributionsSelfCheck(this, new UpdatableBoardsLibsFakeURLsHandler(this), BaseNoGui.indexer, contributionInstaller, BaseNoGui.librariesIndexer, libraryInstaller), Constants.BOARDS_LIBS_UPDATABLE_CHECK_START_PERIOD); new Timer(false).schedule(contributionsSelfCheck, Constants.BOARDS_LIBS_UPDATABLE_CHECK_START_PERIOD);
} else if (parser.isNoOpMode()) { } else if (parser.isNoOpMode()) {
// Do nothing (intended for only changing preferences) // Do nothing (intended for only changing preferences)
@ -1228,8 +1228,8 @@ public class Base {
} }
public void openLibraryManager(String dropdownItem) { public void openLibraryManager(String dropdownItem) {
if (selfCheckTimer != null) { if (contributionsSelfCheck != null) {
selfCheckTimer.cancel(); contributionsSelfCheck.cancel();
} }
@SuppressWarnings("serial") @SuppressWarnings("serial")
LibraryManagerUI managerUI = new LibraryManagerUI(activeEditor, BaseNoGui.librariesIndexer, libraryInstaller) { LibraryManagerUI managerUI = new LibraryManagerUI(activeEditor, BaseNoGui.librariesIndexer, libraryInstaller) {
@ -1257,8 +1257,8 @@ public class Base {
} }
public void openBoardsManager(final String filterText, String dropdownItem) throws Exception { public void openBoardsManager(final String filterText, String dropdownItem) throws Exception {
if (selfCheckTimer != null) { if (contributionsSelfCheck != null) {
selfCheckTimer.cancel(); contributionsSelfCheck.cancel();
} }
@SuppressWarnings("serial") @SuppressWarnings("serial")
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor, BaseNoGui.indexer, contributionInstaller) { ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor, BaseNoGui.indexer, contributionInstaller) {