001: package org.airtodo.headers;
002:
003: import java.awt.Component;
004:
005: import javax.swing.Icon;
006: import javax.swing.JLabel;
007: import javax.swing.JProgressBar;
008: import javax.swing.table.DefaultTableCellRenderer;
009:
010: import org.air.framework.core.ColumnDecorations;
011: import org.air.framework.core.Header;
012: import org.air.framework.core.Registry;
013: import org.air.framework.core.Utils;
014: import org.air.framework.gui.lookup.LookupObject;
015: import org.air.framework.gui.table_view.table.Table;
016: import org.air.framework.properties.Icons;
017: import org.airtodo.db.types.Freezed;
018: import org.airtodo.db.types.Period;
019: import org.airtodo.db.types.PeriodUtils;
020: import org.airtodo.db.types.Progress;
021: import org.airtodo.gui_common.components.lookup_data.LookupDataPriority;
022: import org.airtodo.gui_common.components.lookup_data.LookupDataPriorityCustomer;
023: import org.airtodo.gui_common.components.lookup_data.LookupDataPriorityProject;
024: import org.airtodo.gui_common.components.lookup_data.LookupDataStage;
025: import org.airtodo.records.Customers;
026: import org.airtodo.records.Projects;
027:
028: public class Project extends Header {
029: public Project() {
030: put(Projects.NAME, new ColumnDecorations(true, 300));
031: put(Projects.PRIORITY, new ColumnDecorations(true, 60));
032: put(Projects.STAGE, new ColumnDecorations(true, 100));
033: put(Projects.DATE_START, new ColumnDecorations(false, 100));
034: put(Projects.DATE_END, new ColumnDecorations(false, 100));
035: put(Projects.PERIOD, new ColumnDecorations(false, 100));
036: put(Projects.FREEZED, new ColumnDecorations(true, 55));
037: put(Projects.REMAIN, new ColumnDecorations(true, 100));
038: put(Projects.PROGRESS, new ColumnDecorations(true, 100));
039: put(Projects.COMMENT, new ColumnDecorations(false, 200));
040: put(Customers.NAME, new ColumnDecorations(false, 300));
041: put(Customers.PRIORITY, new ColumnDecorations(false, 60));
042: put(Customers.ADDRESS, new ColumnDecorations(false, 200));
043: put(Customers.PHONE, new ColumnDecorations(false, 200));
044: put(Customers.EMAIL, new ColumnDecorations(false, 200));
045: put(Customers.COMMENT, new ColumnDecorations(false, 200));
046: }
047:
048: @Override
049: public Class getRecordClass() {
050: return Projects.class;
051: }
052:
053: public Component getCellRendererComponent(
054: DefaultTableCellRenderer defaultTableCellRenderer,
055: Object columnIdentifier, Object recordId, Table table,
056: Object value, boolean isSelected, int row, int column) {
057: if (value == null)
058: return null;
059: if (columnIdentifier.equals(Utils
060: .getColumnIdentifier(Projects.NAME))) {
061: defaultTableCellRenderer
062: .setHorizontalAlignment(JLabel.LEFT);
063: Object defaultId = Registry.getDefaultId().get(
064: getRecordClass());
065: Icon icon;
066: if (defaultId != null && recordId.equals(defaultId))
067: icon = Icons.CIRCLE_BLUE;
068: else
069: icon = Icons.CIRCLE_WHITE;
070: defaultTableCellRenderer.setIcon(icon);
071: } else if (columnIdentifier.equals(Utils
072: .getColumnIdentifier(Projects.REMAIN))) {
073: Period period = (Period) value;
074: PeriodUtils.remainPeriodDecorator(defaultTableCellRenderer,
075: period);
076: defaultTableCellRenderer
077: .setHorizontalAlignment(JLabel.LEFT);
078: return defaultTableCellRenderer;
079: } else if (columnIdentifier.equals(Utils
080: .getColumnIdentifier(Projects.PROGRESS))) {
081: JProgressBar bar = new JProgressBar();
082: bar.setValue(((Progress) value).getValue());
083: bar.setOpaque(false);
084: bar.setStringPainted(true);
085: bar.setBorderPainted(false);
086: return bar;
087: } else if (columnIdentifier.equals(Utils
088: .getColumnIdentifier(Projects.PRIORITY))) {
089: int intValue = ((LookupObject) value).getValue();
090: LookupDataPriority lookupData = new LookupDataPriorityProject();
091: Icon icon = (Icon) lookupData.getTextsAndIcons()[intValue][1];
092: defaultTableCellRenderer.setIcon(icon);
093: defaultTableCellRenderer
094: .setHorizontalAlignment(JLabel.CENTER);
095: return defaultTableCellRenderer;
096: } else if (columnIdentifier.equals(Utils
097: .getColumnIdentifier(Projects.STAGE))) {
098: int intValue = ((LookupObject) value).getValue();
099: LookupDataStage lookupData = new LookupDataStage();
100: String text = (String) lookupData.getTextsAndIcons()[intValue][0];
101: Icon icon = (Icon) lookupData.getTextsAndIcons()[intValue][1];
102: defaultTableCellRenderer.setIcon(icon);
103: defaultTableCellRenderer.setText(text);
104: defaultTableCellRenderer
105: .setHorizontalAlignment(JLabel.LEFT);
106: return defaultTableCellRenderer;
107: } else if (columnIdentifier.equals(Utils
108: .getColumnIdentifier(Projects.PERIOD))) {
109: defaultTableCellRenderer.setText(((Period) value)
110: .toString());
111: defaultTableCellRenderer
112: .setHorizontalAlignment(JLabel.RIGHT);
113: return defaultTableCellRenderer;
114: } else if (columnIdentifier.equals(Utils
115: .getColumnIdentifier(Projects.FREEZED))) {
116: boolean freezed = ((Freezed) value).getValue();
117: if (freezed) {
118: defaultTableCellRenderer
119: .setHorizontalAlignment(JLabel.CENTER);
120: defaultTableCellRenderer.setIcon(Icons.STOP);
121: }
122: return defaultTableCellRenderer;
123: } else if (columnIdentifier.equals(Utils
124: .getColumnIdentifier(Customers.PRIORITY))) {
125: int intValue = ((LookupObject) value).getValue();
126: LookupDataPriority lookupData = new LookupDataPriorityCustomer();
127: Icon icon = (Icon) lookupData.getTextsAndIcons()[intValue][1];
128: defaultTableCellRenderer.setIcon(icon);
129: defaultTableCellRenderer
130: .setHorizontalAlignment(JLabel.CENTER);
131: return defaultTableCellRenderer;
132: }
133:
134: return null;
135: }
136: }
|