Skip to content

Commit 34a866b

Browse files
committed
AP-20220: Allow interrupting the Python package download
AP-20220 (Provide preference page to create folder with packages for offline installation of Python-based extensions)
1 parent c51d81c commit 34a866b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

org.knime.python3.nodes/src/main/java/org/knime/python3/nodes/preferences/PythonExtensionsPreferencePage.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public class PythonExtensionsPreferencePage extends PreferencePage implements IW
106106

107107
private Text m_logTextBox;
108108

109+
private Thread m_downloadThread;
110+
109111
/** Constructor */
110112
public PythonExtensionsPreferencePage() {
111113
super("Python-based Extensions");
@@ -144,6 +146,15 @@ protected Control createContents(final Composite parent) {
144146
return contents;
145147
}
146148

149+
@Override
150+
public boolean performCancel() {
151+
if (m_downloadThread != null) {
152+
// Interrupt the download. If the download is already finished or interrupted this will have no effect
153+
m_downloadThread.interrupt();
154+
}
155+
return true;
156+
}
157+
147158
private void onDownloadClicked() {
148159
chooseDirectory().ifPresent(this::downloadPackages);
149160
}
@@ -170,15 +181,16 @@ private void downloadPackages(final Path target) {
170181
performActionOnWidgetInUiThread(getControl(), () -> setValid(false), false);
171182

172183
// Run the collection and download in a separate thread
173-
new Thread(() -> {
184+
m_downloadThread = new Thread(() -> {
174185
CondaPackageCollectionUtil.collectAndDownloadPackages(target,
175186
l -> performActionOnWidgetInUiThread(m_logTextBox, () -> m_logTextBox.append(l + "\n"), true));
176187

177188
// Done: Reset the UI but leave the log text visible
178189
performActionOnWidgetInUiThread(m_downloadButton, () -> m_downloadButton.setEnabled(true), false);
179190
performActionOnWidgetInUiThread(m_progressBar, () -> m_progressBar.setVisible(false), false);
180191
performActionOnWidgetInUiThread(getControl(), () -> setValid(true), false);
181-
}).start();
192+
});
193+
m_downloadThread.start();
182194
}
183195

184196
private static void createLinkToDocs(final Composite parent) {

0 commit comments

Comments
 (0)