package com.onaro.sanscreen.client.view.tabular.columns; import javax.swing.table.TableCellRenderer; import org.apache.commons.lang3.ArrayUtils; import org.eclipse.core.runtime.IAdaptable; import com.onaro.client.swing.table.functional.IFunction; import com.onaro.client.swing.table.functional.IFunctionGroup; import com.onaro.client.swing.table.functional.IFunctionManager; import com.onaro.sanscreen.client.view.tabular.AdaptableTabularColumn; import com.onaro.util.jfc.tables.filter.Filter; /** * Column class that combines an {@link AbstractColumnValueRetriever} to retrieve the row value for the column, * and an {@link AbstractColumnValuePresenter} to present the retrieved value. * * @param the type of Value returned for the row by the Retriever * @param

the type of Presentation returned for the Value by the Presenter */ public class CompoundColumn extends AdaptableTabularColumn { private static final long serialVersionUID = 1L; private final AbstractColumnValueRetriever retriever; private final AbstractColumnValuePresenter presenter; private final Object[] ignoreValues; public CompoundColumn(AbstractColumnValueRetriever retriever, AbstractColumnValuePresenter presenter, String id, String name, Object[] ignoreValues) { super(id, presenter.getPresentationType(), name); this.retriever = retriever; this.presenter = presenter; this.ignoreValues = ignoreValues; // Pass access a delegate implementation of the function manager to the retriever for use retriever.setFunctionManager(new FunctionManagerDelegate()); // Allow for the presenter to override the default cell renderer TableCellRenderer customRenderer = presenter.createCustomRenderer(); if (customRenderer != null) { setCellRenderer(customRenderer); } // Allow for the presenter to override the default column filter Filter customFilter = presenter.createCustomFilter(); if (customFilter != null) { setFilter(customFilter); } } @Override public P getValue(IAdaptable rowObj) throws Exception { V retrievedValue = retriever.getValue(rowObj); // Check whether the retrieved value needs to be ignored (null) if (ignoreValues != null && retrievedValue != null && ArrayUtils.contains(ignoreValues, retrievedValue)) { retrievedValue = null; } String identifier = retriever.getIdentifier(rowObj); P presentedValue = presenter.getPresentation(retrievedValue, identifier); return presentedValue; } @Override public void getRequiredFunctions(IFunctionGroup functionGroup) { super.getRequiredFunctions(functionGroup); retriever.getRequiredFunctions(functionGroup); } /** * Class to delegate implementation of IFunctionManager to the column's function manager. * This delegation is necessary because the getFunctionManager() method cannot be called in the * column constructor, because it is only accessible after the column has been added to a * FunctionalTableModel. */ private class FunctionManagerDelegate implements IFunctionManager { @Override public > F getFunction(Class functionInterface) { return getFunctionManager().getFunction(functionInterface); } @Override public > F getFunction(Class functionInterface, Object identifier) { return getFunctionManager().getFunction(functionInterface, identifier); } } }