Skip to content

Commit

Permalink
Using activateModules for download as well as activate buttons. Makin…
Browse files Browse the repository at this point in the history
…g the activateModules more stateless
  • Loading branch information
Jaroslav Tulach committed Apr 5, 2020
1 parent 0401f36 commit 66a6ca3
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 67 deletions.
2 changes: 1 addition & 1 deletion ergonomics/ide.ergonomics/java.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -93,7 +89,7 @@ public ConfigurationPanel(final Callable<JComponent> callable) {
public void setInfo(FeatureInfo info, String displayName, Collection<UpdateElement> toInstall,
Collection<FeatureInfo.ExtraModuleInfo> missingModules,
Map<FeatureInfo.ExtraModuleInfo, FeatureInfo> extrasMap, boolean required) {
this.extrasFilter = new HashSet<FeatureInfo.ExtraModuleInfo>();
this.extrasFilter = new HashSet<>();
this.featureInfo = info;
this.featureInstall = toInstall;
boolean activateNow = toInstall.isEmpty() && missingModules.isEmpty();
Expand Down Expand Up @@ -306,60 +302,64 @@ public void actionPerformed(ActionEvent evt) {
);
}// </editor-fold>//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<InstallSupport> 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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,34 +77,51 @@ public ModulesInstaller (Collection<UpdateElement> modules, FindComponentModules
}
}

static boolean success = false;
public static boolean installModules (
ProgressMonitor monitor, FeatureInfo info, Collection<UpdateElement> alreadyOffered, Set<FeatureInfo.ExtraModuleInfo> filter
static boolean activateModules(
boolean askForInstall, ProgressMonitor monitor, FeatureInfo info,
Collection<UpdateElement> alreadyOffered, Set<FeatureInfo.ExtraModuleInfo> filter
) {
assert ! SwingUtilities.isEventDispatchThread () : "Cannot run in EQ!";

Function<FindComponentModules,Collection<UpdateElement>> toInstall = (state) -> {
Collection<UpdateElement> tmp = new LinkedHashSet<>(state.getModulesForInstall());
tmp.removeAll(alreadyOffered);
return tmp;
};
Function<FindComponentModules,Collection<UpdateElement>> toEnable = (state) -> {
return state.getModulesForEnable();
};

FindComponentModules findModules = new FindComponentModules(info, filter);
Collection<UpdateElement> toInstall = findModules.getModulesForInstall();
toInstall.removeAll(alreadyOffered);
Collection<UpdateElement> toEnable = findModules.getModulesForEnable();
if (toInstall != null && !toInstall.isEmpty()) {
ModulesInstaller installer = new ModulesInstaller(toInstall, findModules, monitor);
if (askForInstall && !toInstall.apply(findModules).isEmpty()) {
OperationContainer<InstallSupport> 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) {
Expand Down

0 comments on commit 66a6ca3

Please sign in to comment.