Skip to content
Open
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ of the License, or (at your option) any later version.
import javax.swing.event.TableColumnModelListener;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
Expand All @@ -70,6 +71,7 @@ of the License, or (at your option) any later version.
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -96,6 +98,15 @@ public void applyComponentOrientation(ComponentOrientation o) {
}
};

class DecimalRenderer extends DefaultTableCellRenderer {
private final DecimalFormat myFormatter = new DecimalFormat("#0.00");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format of representing currency values is locale-specific. You want to use NumberFormat::getCurrencyInstance and pass the currently selected locale. GanttLanguage is responsible for such things (and it stores the current locale)


public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
value = myFormatter.format((Number)value);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cast is not necessary. format argument is Object.

return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
}

private GPAction myEditCellAction = new GPAction("tree.edit") {
@Override
public void actionPerformed(ActionEvent e) {
Expand Down Expand Up @@ -926,7 +937,11 @@ private TableCellRenderer createCellRenderer(Class<?> columnClass) {
// renderer = TableCellRenderers.getNewDefaultRenderer(columnClass);
//
// }
return getTreeTable().getDefaultRenderer(columnClass);
if (Double.class.equals(columnClass)){
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way all columns with Double type will be formatted with two decimal digits. It is okay for cost (which is essentially money) but it may not be okay for other columns, including user-defined (imagine e.g. weight measured in tons).

I think that the best way to achieve the goal is to override method newTablecolumnext in GanttTreeTable and check if we are creating exactly COST column. We already use similar approach in ResourceTreeTable.

Also, the same should be done with the editor, no? Otherwise the user will see values with 2 decimal digits, but once he starts editing, he will see something different.

return new DecimalRenderer();
} else {
return getTreeTable().getDefaultRenderer(columnClass);
}
}

private TableCellEditor createCellEditor(Class<?> columnClass) {
Expand Down