Fix up the logic for showing and using the aft/fore match diameter switches.
This commit is contained in:
parent
8b9ead892c
commit
a9bbe0f642
@ -60,33 +60,28 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
public ComponentPresetChooserDialog(Window owner, RocketComponent component) {
|
public ComponentPresetChooserDialog(Window owner, RocketComponent component) {
|
||||||
super(owner, trans.get("title"), Dialog.ModalityType.APPLICATION_MODAL);
|
super(owner, trans.get("title"), Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
this.component = component;
|
this.component = component;
|
||||||
|
this.presets = Application.getComponentPresetDao().listForType(component.getPresetType());
|
||||||
|
|
||||||
final TypedKey<?>[] columnKeys = component.getPresetType().getDisplayedColumns();
|
List<TypedKey<?>> displayedColumnKeys = Arrays.<TypedKey<?>>asList(component.getPresetType().getDisplayedColumns());
|
||||||
|
{
|
||||||
presets = Application.getComponentPresetDao().listForType(component.getPresetType());
|
final List<TypedKey<?>> columnKeys = ComponentPreset.orderedKeyList;
|
||||||
|
int i=0; // We start at 0 but use preincrement because the first column is favorite.
|
||||||
for (int i = 0; i < columnKeys.length; i++) {
|
for (final TypedKey<?> key : columnKeys) {
|
||||||
final TypedKey<?> key = columnKeys[i];
|
// Note the increment early in the loop. This really means that initial loop i=1
|
||||||
if ( key == ComponentPreset.OUTER_DIAMETER ) {
|
// we do it here so the continue below doesn't mess up the counting.
|
||||||
// magic +1 is because we have inserted the column for favorites above.
|
i++;
|
||||||
aftDiameterColumnIndex = i+1;
|
// Don't allow the matching filters if the column is not part of the default set for
|
||||||
|
// this kind of preset.
|
||||||
|
if ( ! displayedColumnKeys.contains(key) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( key == ComponentPreset.OUTER_DIAMETER || key == ComponentPreset.AFT_OUTER_DIAMETER ) {
|
||||||
|
aftDiameterColumnIndex = i;
|
||||||
|
}
|
||||||
|
if ( key == ComponentPreset.OUTER_DIAMETER || key == ComponentPreset.FORE_OUTER_DIAMETER ) {
|
||||||
|
foreDiameterColumnIndex = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ( key == ComponentPreset.FORE_OUTER_DIAMETER ) {
|
|
||||||
// magic +1 is because we have inserted the column for favorites above.
|
|
||||||
foreDiameterColumnIndex = i+1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* perhaps there is a better way for this.
|
|
||||||
*
|
|
||||||
* This check basically says that if a component does not have a fore diameter, use the
|
|
||||||
* outer_diameter when filtering. The problem this introduced is when this dialog is
|
|
||||||
* created for nose cones (which are aft of a body tube), you will be given the option
|
|
||||||
* to filter based on matching fore diameter.
|
|
||||||
*/
|
|
||||||
if ( foreDiameterColumnIndex < 0 ) {
|
|
||||||
foreDiameterColumnIndex = aftDiameterColumnIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -151,10 +146,15 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
|
|
||||||
RocketComponent previousComponent = component.getPreviousComponent();
|
RocketComponent previousComponent = component.getPreviousComponent();
|
||||||
/* hide the fore diameter filter if it is not applicable */
|
/* hide the fore diameter filter if it is not applicable */
|
||||||
if ( foreDiameterColumnIndex < 0 || previousComponent == null ) {
|
if ( foreDiameterColumnIndex < 0 ) {
|
||||||
if ( !(previousComponent instanceof ExternalComponent) && !(previousComponent instanceof InternalComponent) )
|
|
||||||
foreDiameterFilterCheckBox.setVisible(false);
|
foreDiameterFilterCheckBox.setVisible(false);
|
||||||
}
|
}
|
||||||
|
if ( previousComponent == null ) {
|
||||||
|
foreDiameterFilterCheckBox.setVisible(false);
|
||||||
|
} else {
|
||||||
|
if ( !(previousComponent instanceof ExternalComponent) && !(previousComponent instanceof InternalComponent) )
|
||||||
|
foreDiameterFilterCheckBox.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add filter by aft diameter
|
* Add filter by aft diameter
|
||||||
@ -169,12 +169,18 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
RocketComponent nextComponent = component.getNextComponent();
|
||||||
/* hide the aft diameter filter if it is not applicable */
|
/* hide the aft diameter filter if it is not applicable */
|
||||||
if ( aftDiameterColumnIndex < 0 || component.getNextComponent() == null ) {
|
if ( aftDiameterColumnIndex < 0 ) {
|
||||||
|
aftDiameterFilterCheckBox.setVisible(false);
|
||||||
|
}
|
||||||
|
if ( nextComponent == null ) {
|
||||||
|
aftDiameterFilterCheckBox.setVisible(false);
|
||||||
|
} else if ( !(nextComponent instanceof ExternalComponent) && !(nextComponent instanceof InternalComponent)) {
|
||||||
aftDiameterFilterCheckBox.setVisible(false);
|
aftDiameterFilterCheckBox.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentSelectionTable = new ComponentPresetTable( presets, Arrays.<TypedKey<?>>asList(columnKeys) );
|
componentSelectionTable = new ComponentPresetTable( presets, displayedColumnKeys );
|
||||||
|
|
||||||
JScrollPane scrollpane = new JScrollPane();
|
JScrollPane scrollpane = new JScrollPane();
|
||||||
scrollpane.setViewportView(componentSelectionTable);
|
scrollpane.setViewportView(componentSelectionTable);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user