When the OK button in the component preset dialog is pressed without selecting an...
[debian/openrocket] / core / src / net / sf / openrocket / gui / dialogs / preset / ComponentPresetChooserDialog.java
index b74bd827182dec2e0613f812b2e08808eec3772f..9efa3675e7a789c022b9ccfc809516ba02b46d41 100644 (file)
@@ -59,6 +59,7 @@ public class ComponentPresetChooserDialog extends JDialog {
        int foreDiameterColumnIndex = -1;
        
        private List<ComponentPreset> presets;
+       private ComponentPreset.Type presetType;
        
        private boolean okClicked = false;
        
@@ -66,6 +67,7 @@ public class ComponentPresetChooserDialog extends JDialog {
        public ComponentPresetChooserDialog(Window owner, RocketComponent component) {
                super(owner, trans.get("title"), Dialog.ModalityType.APPLICATION_MODAL);
                this.component = component;
+               this.presetType = component.getPresetType();
                this.presets = Application.getComponentPresetDao().listForType(component.getPresetType());
                
                List<TypedKey<?>> displayedColumnKeys = Arrays.asList(component.getPresetType().getDisplayedColumns());
@@ -125,8 +127,7 @@ public class ComponentPresetChooserDialog extends JDialog {
                
                panel.add(getFilterCheckboxes(), "wrap para");
                
-               
-               componentSelectionTable = new ComponentPresetTable(presets, displayedColumnKeys);
+               componentSelectionTable = new ComponentPresetTable(presetType, presets, displayedColumnKeys);
                //              GUIUtil.setAutomaticColumnTableWidths(componentSelectionTable, 20);
                int w = componentSelectionTable.getRowHeight() + 4;
                TableColumn tc = componentSelectionTable.getColumnModel().getColumn(0);
@@ -237,6 +238,10 @@ public class ComponentPresetChooserDialog extends JDialog {
                if (!okClicked)
                        return null;
                int row = componentSelectionTable.getSelectedRow();
+               if ( row < 0 ) {
+                       // Nothing selected.
+                       return null;
+               }
                row = componentSelectionTable.convertRowIndexToModel(row);
                return presets.get(row);
        }