import com.intellij.ide.IdeBundle;
import com.intellij.ide.plugins.PluginManagerMain;
+import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
-import com.intellij.openapi.util.Ref;
import com.intellij.ui.TableUtil;
-import com.intellij.util.Consumer;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
*/
class PluginUpdateInfoDialog extends AbstractUpdateDialog {
private final Collection<PluginDownloader> myUploadedPlugins;
+ private final boolean myPlatformUpdate;
public PluginUpdateInfoDialog(Collection<PluginDownloader> uploadedPlugins, boolean enableLink) {
super(enableLink);
myUploadedPlugins = uploadedPlugins;
+ myPlatformUpdate = false;
init();
}
- protected PluginUpdateInfoDialog(Component parent, @NotNull Collection<PluginDownloader> updatePlugins, boolean enableLink) {
- super(parent, enableLink);
+ /**
+ * Used from {@link UpdateInfoDialog} when both platform and plugin updates are available.
+ */
+ PluginUpdateInfoDialog(Component parent, @NotNull Collection<PluginDownloader> updatePlugins) {
+ super(parent, false);
myUploadedPlugins = updatePlugins;
+ myPlatformUpdate = true;
init();
}
@Override
protected String getOkButtonText() {
- return IdeBundle.message("update.plugins.update.action");
- }
-
- @NotNull
- @Override
- protected Action[] createActions() {
- return new Action[]{getOKAction(), getCancelAction()};
+ if (!myPlatformUpdate) {
+ return IdeBundle.message("update.plugins.update.action");
+ }
+ else {
+ boolean canRestart = ApplicationManager.getApplication().isRestartCapable();
+ return IdeBundle.message(canRestart ? "update.restart.plugins.update.action" : "update.shutdown.plugins.update.action");
+ }
}
@Override
protected void doOKAction() {
super.doOKAction();
- final Ref<Boolean> result = new Ref<Boolean>();
- final Consumer<ProgressIndicator> runnable = new Consumer<ProgressIndicator>() {
+
+ ProgressManager.getInstance().run(new Task.Modal(null, IdeBundle.message("progress.downloading.plugins"), true) {
@Override
- public void consume(@NotNull ProgressIndicator indicator) {
+ public void run(@NotNull ProgressIndicator indicator) {
UpdateChecker.saveDisabledToUpdatePlugins();
- result.set(UpdateChecker.installPluginUpdates(myUploadedPlugins, indicator));
- }
- };
-
- final String progressTitle = "Download plugins...";
- if (downloadModal()) {
- ProgressManager.getInstance().run(new Task.Modal(null, progressTitle, true) {
- @Override
- public void run(@NotNull ProgressIndicator indicator) {
- runnable.consume(indicator);
- }
- });
- }
- else {
- ProgressManager.getInstance().run(new Task.Backgroundable(null, progressTitle, true) {
- @Override
- public void run(@NotNull ProgressIndicator indicator) {
- runnable.consume(indicator);
- }
-
- @Override
- public void onSuccess() {
- final Boolean installed = result.get();
- if (installed != null && installed.booleanValue()) {
- final String pluginName;
- if (myUploadedPlugins.size() == 1) {
- final PluginDownloader firstItem = ContainerUtil.getFirstItem(myUploadedPlugins);
- pluginName = firstItem != null ? firstItem.getPluginName() : null;
+ boolean updated = UpdateChecker.installPluginUpdates(myUploadedPlugins, indicator);
+ if (updated && !myPlatformUpdate) {
+ String pluginName = null;
+ if (myUploadedPlugins.size() == 1) {
+ PluginDownloader plugin = ContainerUtil.getFirstItem(myUploadedPlugins);
+ if (plugin != null) {
+ pluginName = plugin.getPluginName();
}
- else {
- pluginName = null;
- }
- PluginManagerMain.notifyPluginsWereInstalled(pluginName, null);
}
+ PluginManagerMain.notifyPluginsWereInstalled(pluginName, null);
}
- });
- }
- }
-
- protected boolean downloadModal() {
- return false;
+ }
+ });
}
private class PluginUpdateInfoPanel {
List<Action> actions = ContainerUtil.newArrayList();
if (myPatch != null) {
- final boolean canRestart = ApplicationManager.getApplication().isRestartCapable();
+ boolean canRestart = ApplicationManager.getApplication().isRestartCapable();
String button = IdeBundle.message(canRestart ? "updates.download.and.restart.button" : "updates.download.and.install.button");
actions.add(new AbstractAction(button) {
{
@Override
public void actionPerformed(ActionEvent e) {
- downloadPatch(canRestart);
+ downloadPatch();
}
});
}
return IdeBundle.message("updates.remind.later.button");
}
- private void downloadPatch(final boolean canRestart) {
- final UpdateChecker.DownloadPatchResult result = UpdateChecker.installPlatformUpdate(myPatch, myLatestBuild.getNumber(), myForceHttps);
+ private void downloadPatch() {
+ UpdateChecker.DownloadPatchResult result = UpdateChecker.installPlatformUpdate(myPatch, myLatestBuild.getNumber(), myForceHttps);
if (result == UpdateChecker.DownloadPatchResult.SUCCESS) {
if (myUpdatedPlugins != null && !myUpdatedPlugins.isEmpty()) {
- new PluginUpdateInfoDialog(getContentPanel(), myUpdatedPlugins, true){
- @Override
- protected boolean downloadModal() {
- return true;
- }
-
- @Override
- protected String getOkButtonText() {
- return IdeBundle.message(canRestart ? "update.restart.plugins.update.action" : "update.shutdown.plugins.update.action");
- }
- }.show();
+ new PluginUpdateInfoDialog(getContentPanel(), myUpdatedPlugins).show();
}
restart();
}