diff --git a/ergonomics/ide.ergonomics/java.properties b/ergonomics/ide.ergonomics/java.properties index c7c7252c4096..d4041e4dd0ff 100644 --- a/ergonomics/ide.ergonomics/java.properties +++ b/ergonomics/ide.ergonomics/java.properties @@ -20,7 +20,7 @@ project.file.../java.base/share/classes/java/lang/Object.java=org.netbeans.modul projectImporter=Eclipse mainModule=org.netbeans.modules.java.kit -extra.modules=org.netbeans.modules.nbjavac +extra.modules=org.netbeans.modules.nbjavac.* extra.modules.recommended.min.jdk=9 extra.modules.1=org\\.netbeans\\.libs\\.javafx\\.(linux|win|macosx) extra.modules.1.recommended.max.jdk=11 diff --git a/ergonomics/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/ConfigurationPanel.java b/ergonomics/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/ConfigurationPanel.java index be78b576f36a..6d273123607b 100644 --- a/ergonomics/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/ConfigurationPanel.java +++ b/ergonomics/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/ConfigurationPanel.java @@ -42,14 +42,10 @@ import javax.swing.JPanel; import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.SwingUtilities; -import org.netbeans.api.autoupdate.InstallSupport; -import org.netbeans.api.autoupdate.OperationContainer; import org.netbeans.api.autoupdate.UpdateElement; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; -import org.netbeans.modules.autoupdate.ui.api.PluginManager; import org.openide.awt.Mnemonics; -import org.openide.modules.SpecificationVersion; import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor.Task; @@ -65,7 +61,7 @@ * @author Tomas Mysik * @author Pavel Flaska */ -public class ConfigurationPanel extends JPanel implements Runnable { +public class ConfigurationPanel extends JPanel { private static final long serialVersionUID = 27938464212508L; @@ -93,7 +89,7 @@ public ConfigurationPanel(final Callable callable) { public void setInfo(FeatureInfo info, String displayName, Collection toInstall, Collection missingModules, Map extrasMap, boolean required) { - this.extrasFilter = new HashSet(); + this.extrasFilter = new HashSet<>(); this.featureInfo = info; this.featureInstall = toInstall; boolean activateNow = toInstall.isEmpty() && missingModules.isEmpty(); @@ -306,60 +302,64 @@ public void actionPerformed(ActionEvent evt) { ); }// //GEN-END:initComponents - public void run() { - ModulesInstaller.installModules(progressMonitor, featureInfo, featureInstall, extrasFilter); - } - private void activateButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_activateButtonActionPerformed FeatureManager.logUI("ERGO_DOWNLOAD"); activateButton.setEnabled(false); downloadButton.setEnabled(false); - Task task = FeatureManager.getInstance().create(this); - task.addTaskListener(new TaskListener() { - - public void taskFinished(org.openide.util.Task task) { - if (!progressMonitor.error) { - SwingUtilities.invokeLater(new Runnable() { - private String msg; - - public void run() { - ConfigurationPanel.this.removeAll(); - ConfigurationPanel.this.setLayout(new BorderLayout()); - try { - ConfigurationPanel.this.add(callable.call(), BorderLayout.CENTER); - } catch (Exception ex) { - // TODO: add warning panel - Exceptions.printStackTrace(ex); - } - ConfigurationPanel.this.invalidate(); - ConfigurationPanel.this.revalidate(); - ConfigurationPanel.this.repaint(); - if (featureInfo != null && featureInfo.isPresent()) { - msg = NbBundle.getMessage(ConfigurationPanel.class, "MSG_EnableFailed"); - } else { - msg = NbBundle.getMessage(ConfigurationPanel.class, "MSG_DownloadFailed"); - } - setError(msg); - activateButton.setEnabled(true); - progressPanel.removeAll(); - progressPanel.revalidate(); - progressPanel.repaint(); - } - }); - } - } + selectionsPanel.setEnabled(false); + Task task = FeatureManager.getInstance().create(() -> { + ModulesInstaller.activateModules(false, progressMonitor, featureInfo, featureInstall, extrasFilter); }); + task.addTaskListener(onActivationFinished()); task.schedule(0); }//GEN-LAST:event_activateButtonActionPerformed private void downloadButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_downloadButtonActionPerformed - OperationContainer op = OperationContainer.createForInstall(); - op.add(featureInstall); - if (PluginManager.openInstallWizard(op)) { - activateButtonActionPerformed(null); - } + FeatureManager.logUI("ERGO_DOWNLOAD"); + activateButton.setEnabled(false); + downloadButton.setEnabled(false); + selectionsPanel.setEnabled(false); + Task task = FeatureManager.getInstance().create(() -> { + ModulesInstaller.activateModules(true, progressMonitor, featureInfo, Collections.emptyList(), extrasFilter); + }); + task.addTaskListener(onActivationFinished()); + task.schedule(0); }//GEN-LAST:event_downloadButtonActionPerformed + private TaskListener onActivationFinished() { + return (task) -> { + if (!progressMonitor.error) { + SwingUtilities.invokeLater(new Runnable() { + private String msg; + + public void run() { + ConfigurationPanel.this.removeAll(); + ConfigurationPanel.this.setLayout(new BorderLayout()); + try { + ConfigurationPanel.this.add(callable.call(), BorderLayout.CENTER); + } catch (Exception ex) { + // TODO: add warning panel + Exceptions.printStackTrace(ex); + } + ConfigurationPanel.this.invalidate(); + ConfigurationPanel.this.revalidate(); + ConfigurationPanel.this.repaint(); + if (featureInfo != null && featureInfo.isPresent()) { + msg = NbBundle.getMessage(ConfigurationPanel.class, "MSG_EnableFailed"); + } else { + msg = NbBundle.getMessage(ConfigurationPanel.class, "MSG_DownloadFailed"); + } + setError(msg); + activateButton.setEnabled(true); + progressPanel.removeAll(); + progressPanel.revalidate(); + progressPanel.repaint(); + } + }); + } + }; + } + // Variables declaration - do not modify//GEN-BEGIN:variables private JButton activateButton; private JButton downloadButton; @@ -372,7 +372,7 @@ private void downloadButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_d private final class DownloadProgressMonitor implements ProgressMonitor { - private boolean error = false; + boolean error = false; public void onDownload(ProgressHandle progressHandle) { updateProgress(progressHandle); diff --git a/ergonomics/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/ModulesInstaller.java b/ergonomics/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/ModulesInstaller.java index 04ec5c929276..8d65cd7ce245 100644 --- a/ergonomics/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/ModulesInstaller.java +++ b/ergonomics/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/ModulesInstaller.java @@ -23,7 +23,9 @@ import java.awt.event.ActionListener; import java.util.Collection; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; +import java.util.function.Function; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JButton; @@ -75,34 +77,51 @@ public ModulesInstaller (Collection modules, FindComponentModules } } - static boolean success = false; - public static boolean installModules ( - ProgressMonitor monitor, FeatureInfo info, Collection alreadyOffered, Set filter + static boolean activateModules( + boolean askForInstall, ProgressMonitor monitor, FeatureInfo info, + Collection alreadyOffered, Set filter ) { assert ! SwingUtilities.isEventDispatchThread () : "Cannot run in EQ!"; + + Function> toInstall = (state) -> { + Collection tmp = new LinkedHashSet<>(state.getModulesForInstall()); + tmp.removeAll(alreadyOffered); + return tmp; + }; + Function> toEnable = (state) -> { + return state.getModulesForEnable(); + }; FindComponentModules findModules = new FindComponentModules(info, filter); - Collection toInstall = findModules.getModulesForInstall(); - toInstall.removeAll(alreadyOffered); - Collection toEnable = findModules.getModulesForEnable(); - if (toInstall != null && !toInstall.isEmpty()) { - ModulesInstaller installer = new ModulesInstaller(toInstall, findModules, monitor); + if (askForInstall && !toInstall.apply(findModules).isEmpty()) { + OperationContainer op = OperationContainer.createForInstall(); + op.add(toInstall.apply(findModules)); + if (!PluginManager.openInstallWizard(op)) { + return false; + } + findModules = new FindComponentModules(info, filter); + if (!toInstall.apply(findModules).isEmpty()) { + return false; + } + } + if (!toInstall.apply(findModules).isEmpty()) { + ModulesInstaller installer = new ModulesInstaller(toInstall.apply(findModules), findModules, monitor); installer.getInstallTask ().schedule (10); installer.getInstallTask ().waitFinished(); findModules = new FindComponentModules(info, filter); - success = findModules.getModulesForInstall ().isEmpty (); - } else if (toEnable != null && !toEnable.isEmpty()) { - ModulesActivator enabler = new ModulesActivator(toEnable, findModules, monitor); + if (!findModules.getModulesForInstall ().isEmpty ()) { + return false; + } + } + if (!toEnable.apply(findModules).isEmpty()) { + ModulesActivator enabler = new ModulesActivator(toEnable.apply(findModules), findModules, monitor); enabler.getEnableTask ().schedule (100); enabler.getEnableTask ().waitFinished(); - success = true; } - if (success) { - FoDLayersProvider.getInstance().refreshForce(); - } + FoDLayersProvider.getInstance().refreshForce(); - return success; + return true; } public void assignDownloadHandle (ProgressHandle handle) {