Skip to content

Commit

Permalink
Merge pull request #4444 from IllianiCBT/finances_removeAssetsBug
Browse files Browse the repository at this point in the history
Reordered Asset Removal and Event Trigger in ManageAssetsDialog
  • Loading branch information
IllianiCBT authored Jul 23, 2024
2 parents 7172ff1 + f80a68f commit da2d208
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions MekHQ/src/mekhq/gui/dialog/ManageAssetsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,15 @@ private void editAsset() {
}

private void deleteAsset() {
campaign.getFinances().getAssets().remove(assetTable.getSelectedRow());
MekHQ.triggerEvent(new AssetRemovedEvent(assetModel.getAssetAt(assetTable.getSelectedRow())));
campaign.getFinances().getAssets().remove(assetTable.getSelectedRow());
refreshTable();
}

private void refreshTable() {
int selectedRow = assetTable.getSelectedRow();
assetModel.setData(campaign.getFinances().getAssets());

if (selectedRow != -1) {
if (assetTable.getRowCount() > 0) {
if (assetTable.getRowCount() == selectedRow) {
Expand Down Expand Up @@ -208,18 +209,13 @@ public int getColumnCount() {

@Override
public String getColumnName(int column) {
switch (column) {
case COL_NAME:
return "Name";
case COL_VALUE:
return "Value";
case COL_SCHEDULE:
return "Pay Frequency";
case COL_INCOME:
return "Income";
default:
return "?";
}
return switch (column) {
case COL_NAME -> "Name";
case COL_VALUE -> "Value";
case COL_SCHEDULE -> "Pay Frequency";
case COL_INCOME -> "Income";
default -> "?";
};
}

@Override
Expand Down Expand Up @@ -255,30 +251,22 @@ public Asset getAssetAt(int row) {
}

public int getColumnWidth(int c) {
switch (c) {
default:
return 10;
}
return 10;
}

public int getAlignment(int col) {
switch (col) {
case COL_NAME:
return SwingConstants.LEFT;
default:
return SwingConstants.RIGHT;
if (col == COL_NAME) {
return SwingConstants.LEFT;
}
return SwingConstants.RIGHT;
}

public String getTooltip(int row, int col) {
switch (col) {
default:
return null;
}
return null;
}

public AssetTableModel.Renderer getRenderer() {
return new AssetTableModel.Renderer();
public Renderer getRenderer() {
return new Renderer();
}

public class Renderer extends DefaultTableCellRenderer {
Expand Down

0 comments on commit da2d208

Please sign in to comment.