mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Error message is printed at the bottom of the dialog
This commit is contained in:
parent
6f5f9bedb4
commit
357d5954c3
@ -28,19 +28,19 @@
|
||||
*/
|
||||
package cc.arduino.libraries.contributions.ui;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.util.Collection;
|
||||
|
||||
import cc.arduino.libraries.contributions.ContributedLibrary;
|
||||
import cc.arduino.libraries.contributions.LibrariesIndexer;
|
||||
import cc.arduino.packages.contributions.ui.InstallerJDialogUncaughtExceptionHandler;
|
||||
import cc.arduino.ui.FilteredAbstractTableModel;
|
||||
import cc.arduino.ui.InstallerJDialog;
|
||||
import cc.arduino.ui.InstallerTableCell;
|
||||
import cc.arduino.utils.Progress;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Collection;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class LibraryManagerUI extends InstallerJDialog {
|
||||
|
||||
@ -48,7 +48,7 @@ public class LibraryManagerUI extends InstallerJDialog {
|
||||
protected FilteredAbstractTableModel createContribModel() {
|
||||
return new LibrariesIndexTableModel();
|
||||
}
|
||||
|
||||
|
||||
private LibrariesIndexTableModel getContribModel() {
|
||||
return (LibrariesIndexTableModel) contribModel;
|
||||
}
|
||||
@ -125,12 +125,15 @@ public class LibraryManagerUI extends InstallerJDialog {
|
||||
|
||||
@Override
|
||||
protected void onCancelPressed() {
|
||||
if (installerThread != null)
|
||||
super.onUpdatePressed();
|
||||
if (installerThread != null) {
|
||||
installerThread.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onUpdatePressed() {
|
||||
super.onUpdatePressed();
|
||||
installerThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -145,10 +148,12 @@ public class LibraryManagerUI extends InstallerJDialog {
|
||||
}
|
||||
}
|
||||
});
|
||||
installerThread.setUncaughtExceptionHandler(new InstallerJDialogUncaughtExceptionHandler(this));
|
||||
installerThread.start();
|
||||
}
|
||||
|
||||
public void onInstallPressed(final ContributedLibrary lib, final ContributedLibrary replaced) {
|
||||
clearErrorMessage();
|
||||
installerThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -164,10 +169,12 @@ public class LibraryManagerUI extends InstallerJDialog {
|
||||
}
|
||||
}
|
||||
});
|
||||
installerThread.setUncaughtExceptionHandler(new InstallerJDialogUncaughtExceptionHandler(this));
|
||||
installerThread.start();
|
||||
}
|
||||
|
||||
public void onRemovePressed(final ContributedLibrary lib) {
|
||||
clearErrorMessage();
|
||||
installerThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -183,6 +190,7 @@ public class LibraryManagerUI extends InstallerJDialog {
|
||||
}
|
||||
}
|
||||
});
|
||||
installerThread.setUncaughtExceptionHandler(new InstallerJDialogUncaughtExceptionHandler(this));
|
||||
installerThread.start();
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,6 @@
|
||||
*/
|
||||
package cc.arduino.packages.contributions.ui;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
import cc.arduino.packages.contributions.ContributedPlatform;
|
||||
import cc.arduino.packages.contributions.ContributionInstaller;
|
||||
import cc.arduino.packages.contributions.ContributionsIndexer;
|
||||
@ -40,6 +39,8 @@ import cc.arduino.utils.Progress;
|
||||
import java.awt.*;
|
||||
import java.util.Collection;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class ContributionManagerUI extends InstallerJDialog {
|
||||
|
||||
@ -122,6 +123,7 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
|
||||
@Override
|
||||
public void onCancelPressed() {
|
||||
super.onCancelPressed();
|
||||
if (installerThread != null) {
|
||||
installerThread.interrupt();
|
||||
}
|
||||
@ -129,6 +131,7 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
|
||||
@Override
|
||||
public void onUpdatePressed() {
|
||||
super.onUpdatePressed();
|
||||
installerThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -143,11 +146,12 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
}
|
||||
}
|
||||
});
|
||||
installerThread.setUncaughtExceptionHandler(new ContributionUncaughtExceptionHandler(this));
|
||||
installerThread.setUncaughtExceptionHandler(new InstallerJDialogUncaughtExceptionHandler(this));
|
||||
installerThread.start();
|
||||
}
|
||||
|
||||
public void onInstallPressed(final ContributedPlatform platformToInstall, final ContributedPlatform platformToRemove) {
|
||||
clearErrorMessage();
|
||||
installerThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -165,11 +169,12 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
}
|
||||
}
|
||||
});
|
||||
installerThread.setUncaughtExceptionHandler(new ContributionUncaughtExceptionHandler(this));
|
||||
installerThread.setUncaughtExceptionHandler(new InstallerJDialogUncaughtExceptionHandler(this));
|
||||
installerThread.start();
|
||||
}
|
||||
|
||||
public void onRemovePressed(final ContributedPlatform platform) {
|
||||
clearErrorMessage();
|
||||
installerThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -184,7 +189,7 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
}
|
||||
}
|
||||
});
|
||||
installerThread.setUncaughtExceptionHandler(new ContributionUncaughtExceptionHandler(this));
|
||||
installerThread.setUncaughtExceptionHandler(new InstallerJDialogUncaughtExceptionHandler(this));
|
||||
installerThread.start();
|
||||
}
|
||||
|
||||
|
@ -1,22 +0,0 @@
|
||||
package cc.arduino.packages.contributions.ui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
public class ContributionUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
|
||||
|
||||
private final Component parent;
|
||||
|
||||
public ContributionUncaughtExceptionHandler(Component parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uncaughtException(Thread t, Throwable e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(parent, _(e.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package cc.arduino.packages.contributions.ui;
|
||||
|
||||
import cc.arduino.ui.InstallerJDialog;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
public class InstallerJDialogUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
|
||||
|
||||
private final InstallerJDialog parent;
|
||||
|
||||
public InstallerJDialogUncaughtExceptionHandler(InstallerJDialog parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uncaughtException(Thread t, final Throwable e) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
parent.setErrorMessage(_(e.getMessage().substring(e.getMessage().indexOf(":") + 2)));
|
||||
}
|
||||
|
||||
}
|
@ -35,14 +35,12 @@ import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.event.TableModelEvent;
|
||||
import javax.swing.event.TableModelListener;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableColumnModel;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import static cc.arduino.packages.contributions.ui.ContributionIndexTableModel.DESCRIPTION_COL;
|
||||
@ -91,6 +89,7 @@ public abstract class InstallerJDialog extends JDialog {
|
||||
protected ProgressJProgressBar progressBar;
|
||||
protected Box progressBox;
|
||||
protected Box updateBox;
|
||||
private final JLabel errorMessage;
|
||||
|
||||
protected InstallerTableCell cellEditor;
|
||||
|
||||
@ -170,6 +169,10 @@ public abstract class InstallerJDialog extends JDialog {
|
||||
progressBar.setString(" ");
|
||||
progressBar.setVisible(true);
|
||||
|
||||
errorMessage = new JLabel("");
|
||||
errorMessage.setForeground(Color.RED);
|
||||
errorMessage.setVisible(false);
|
||||
|
||||
{
|
||||
JButton cancelButton = new JButton(_("Cancel"));
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
@ -194,6 +197,8 @@ public abstract class InstallerJDialog extends JDialog {
|
||||
|
||||
updateBox = Box.createHorizontalBox();
|
||||
updateBox.add(Box.createHorizontalGlue());
|
||||
updateBox.add(errorMessage);
|
||||
updateBox.add(Box.createHorizontalGlue());
|
||||
updateBox.add(updateButton);
|
||||
}
|
||||
|
||||
@ -219,6 +224,16 @@ public abstract class InstallerJDialog extends JDialog {
|
||||
});
|
||||
}
|
||||
|
||||
public void setErrorMessage(String message) {
|
||||
errorMessage.setText(message);
|
||||
errorMessage.setVisible(true);
|
||||
}
|
||||
|
||||
public void clearErrorMessage() {
|
||||
errorMessage.setText("");
|
||||
errorMessage.setVisible(false);
|
||||
}
|
||||
|
||||
public void setProgressVisible(boolean visible, String status) {
|
||||
progressBox.setVisible(visible);
|
||||
|
||||
@ -258,14 +273,14 @@ public abstract class InstallerJDialog extends JDialog {
|
||||
* Action performed when the Cancel button is pressed.
|
||||
*/
|
||||
protected void onCancelPressed() {
|
||||
// Empty
|
||||
clearErrorMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Action performed when the "Update List" button is pressed.
|
||||
*/
|
||||
protected void onUpdatePressed() {
|
||||
// Empty
|
||||
clearErrorMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user