Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reordered Asset Removal and Event Trigger in ManageAssetsDialog #4444

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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