| 1 | //  Copyright 2004-2007 Jean-Francois Poilpret | 
| 2 | // | 
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
| 4 | // you may not use this file except in compliance with the License. | 
| 5 | // You may obtain a copy of the License at | 
| 6 | // | 
| 7 | //     http://www.apache.org/licenses/LICENSE-2.0 | 
| 8 | // | 
| 9 | // Unless required by applicable law or agreed to in writing, software | 
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, | 
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| 12 | // See the License for the specific language governing permissions and | 
| 13 | // limitations under the License. | 
| 14 |   | 
| 15 | package net.sourceforge.hiveboard.view; | 
| 16 |   | 
| 17 | import org.jvnet.substance.SubstanceDefaultTableCellRenderer; | 
| 18 |   | 
| 19 | import net.sourceforge.hiveboard.Account; | 
| 20 | import net.sourceforge.hiveboard.model.AccountRepository; | 
| 21 |   | 
| 22 | public abstract class AbstractAccountRenderer extends SubstanceDefaultTableCellRenderer | 
| 23 | { | 
| 24 |         protected AbstractAccountRenderer(AccountRepository repository) | 
| 25 |         { | 
| 26 |                 _repository = repository; | 
| 27 |         } | 
| 28 |          | 
| 29 |         @Override protected void setValue(Object value) | 
| 30 |         { | 
| 31 |                 Account account = convert(value); | 
| 32 |                 String text = nullValue(); | 
| 33 |                 if (account != null) | 
| 34 |                 { | 
| 35 |                         text = renderAccount(account); | 
| 36 |                 } | 
| 37 |                 setText(text); | 
| 38 |         } | 
| 39 |   | 
| 40 |         protected Account        convert(Object value) | 
| 41 |         { | 
| 42 |                 if (value instanceof Account) | 
| 43 |                 { | 
| 44 |                         return (Account) value; | 
| 45 |                 } | 
| 46 |                 else if (value instanceof Integer) | 
| 47 |                 { | 
| 48 |                         return _repository.getAccount((Integer) value); | 
| 49 |                 } | 
| 50 |                 else | 
| 51 |                 { | 
| 52 |                         return null; | 
| 53 |                 } | 
| 54 |         } | 
| 55 |   | 
| 56 |         protected String        nullValue() | 
| 57 |         { | 
| 58 |                 return "?"; | 
| 59 |         }         | 
| 60 |   | 
| 61 |         protected abstract String        renderAccount(Account account); | 
| 62 |   | 
| 63 |         private final AccountRepository        _repository; | 
| 64 | } |