/** * */ package org.nightlabs.jfire.reporting.trade.ui.accounting.currency; import java.util.ArrayList; import java.util.Collection; import java.util.List; import javax.jdo.JDOHelper; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.nightlabs.base.ui.job.Job; import org.nightlabs.base.ui.table.AbstractTableComposite; import org.nightlabs.jfire.accounting.Currency; import org.nightlabs.jfire.accounting.dao.CurrencyDAO; import org.nightlabs.jfire.accounting.id.CurrencyID; import org.nightlabs.jfire.reporting.parameter.config.ValueProviderConfig; import org.nightlabs.jfire.reporting.parameter.id.ValueProviderID; import org.nightlabs.jfire.reporting.trade.ReportingTradeConstants; import org.nightlabs.jfire.reporting.trade.ui.resource.Messages; import org.nightlabs.jfire.reporting.ui.parameter.AbstractValueProviderGUI; import org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUI; import org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUIFactory; import org.nightlabs.jfire.trade.ui.currency.CurrencyTable; import org.nightlabs.progress.ProgressMonitor; /** * @author Alexander Bieber <!-- alex [AT] nightlabs [DOT] de --> * */ public class ValueProviderGUICurrencies extends AbstractValueProviderGUI<Collection<CurrencyID>> { public static class Factory implements IValueProviderGUIFactory { /* (non-Javadoc) * @see org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUIFactory#createValueProviderGUI() */ public IValueProviderGUI<Collection<CurrencyID>> createValueProviderGUI(ValueProviderConfig valueProviderConfig, boolean isScheduledReportParameterConfig) { return new ValueProviderGUICurrencies(valueProviderConfig); } /* (non-Javadoc) * @see org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUIFactory#getValueProviderID() */ public ValueProviderID getValueProviderID() { return ReportingTradeConstants.VALUE_PROVIDER_ID_ACCOUNTING_MODE_OF_PAYMENT_FLAVOUR; } /* (non-Javadoc) * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object) */ public void setInitializationData(IConfigurationElement arg0, String arg1, Object arg2) throws CoreException { } } private CurrencyTable currencyTable; public ValueProviderGUICurrencies(ValueProviderConfig valueProviderConfig) { super(valueProviderConfig); } /* (non-Javadoc) * @see org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUI#createGUI(org.eclipse.swt.widgets.Composite) */ public Control createGUI(Composite wrapper) { Group group = new Group(wrapper, SWT.NONE); group.setLayoutData(new GridData(GridData.FILL_BOTH)); group.setLayout(new GridLayout()); group.setText(getValueProviderConfig().getMessage().getText()); currencyTable = new CurrencyTable(group, SWT.NONE, AbstractTableComposite.DEFAULT_STYLE_MULTI_BORDER); currencyTable.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { notifyOutputChanged(); } }); currencyTable.setLoadingMessage(Messages.getString("org.nightlabs.jfire.reporting.trade.ui.accounting.currency.ValueProviderGUICurrencies.loadingMessage")); //$NON-NLS-1$ Job job = new Job(Messages.getString("org.nightlabs.jfire.reporting.trade.ui.accounting.currency.ValueProviderGUICurrencies.jobName")) { //$NON-NLS-1$ @Override protected IStatus run(ProgressMonitor monitor) throws Exception { final List<Currency> currencies = CurrencyDAO.sharedInstance().getCurrencies(monitor); Display.getDefault().asyncExec(new Runnable() { public void run() { currencyTable.setInput(currencies); } }); return Status.OK_STATUS; } }; job.schedule(); return group; } /* (non-Javadoc) * @see org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUI#getOutputValue() */ public Collection<CurrencyID> getOutputValue() { Collection<Currency> currencies = currencyTable.getSelectedElements(); if (currencies.size() == 0) return null; List<CurrencyID> result = new ArrayList<CurrencyID>(currencies.size()); for (Currency currency : currencies) { result.add((CurrencyID) JDOHelper.getObjectId(currency)); } return result; } /* (non-Javadoc) * @see org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUI#isAcquisitionComplete() */ public boolean isAcquisitionComplete() { return getOutputValue() != null || getValueProviderConfig().isAllowNullOutputValue(); } /* (non-Javadoc) * @see org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUI#setInputParameterValue(java.lang.String, java.lang.Object) */ public void setInputParameterValue(String parameterID, final Object value) { } }