package org.nightlabs.jfire.reporting.trade.ui.articlecontainer.invoice; import java.util.Collection; import javax.jdo.FetchPlan; 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.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.nightlabs.base.ui.job.Job; import org.nightlabs.jdo.NLJDOHelper; import org.nightlabs.jdo.query.QueryCollection; import org.nightlabs.jfire.accounting.Invoice; import org.nightlabs.jfire.accounting.InvoiceLocal; import org.nightlabs.jfire.accounting.dao.InvoiceDAO; import org.nightlabs.jfire.accounting.id.InvoiceID; import org.nightlabs.jfire.jbpm.graph.def.State; import org.nightlabs.jfire.jbpm.graph.def.StateDefinition; 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.ui.parameter.AbstractValueProviderGUI; import org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUI; import org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUIFactory; import org.nightlabs.jfire.trade.LegalEntity; import org.nightlabs.jfire.trade.query.InvoiceQuery; import org.nightlabs.jfire.trade.ui.overview.invoice.InvoiceListComposite; import org.nightlabs.jfire.trade.ui.resource.Messages; import org.nightlabs.jfire.transfer.id.AnchorID; import org.nightlabs.progress.ProgressMonitor; /** * @author Alexander Bieber <!-- alex [AT] nightlabs [DOT] de --> * */ public class ValueProviderGUIInvoiceByCustomer extends AbstractValueProviderGUI<InvoiceID> { public static final String[] FETCH_GROUPS_INVOICES = new String[] { FetchPlan.DEFAULT, Invoice.FETCH_GROUP_THIS_INVOICE, State.FETCH_GROUP_STATE_DEFINITION, StateDefinition.FETCH_GROUP_NAME, LegalEntity.FETCH_GROUP_PERSON, InvoiceLocal.FETCH_GROUP_THIS_INVOICE_LOCAL }; public static class Factory implements IValueProviderGUIFactory { /* (non-Javadoc) * @see org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUIFactory#createValueProviderGUI() */ public IValueProviderGUI<InvoiceID> createValueProviderGUI(ValueProviderConfig valueProviderConfig, boolean isScheduledReportParameterConfig) { return new ValueProviderGUIInvoiceByCustomer(valueProviderConfig); } /* (non-Javadoc) * @see org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUIFactory#getValueProviderID() */ public ValueProviderID getValueProviderID() { return ReportingTradeConstants.VALUE_PROVIDER_ID_TRADE_DOCUMENTS_INVOICE_BY_CUSTOMER; } /* (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 InvoiceListComposite invoiceListComposite; public ValueProviderGUIInvoiceByCustomer(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) { invoiceListComposite = new InvoiceListComposite(wrapper, SWT.NONE); invoiceListComposite.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent arg0) { notifyOutputChanged(); } }); return invoiceListComposite; } /* (non-Javadoc) * @see org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUI#getOutputValue() */ public InvoiceID getOutputValue() { if (invoiceListComposite.getSelectedElements().size() >= 1) return (InvoiceID) JDOHelper.getObjectId(invoiceListComposite.getSelectedElements().iterator().next()); return null; } /* (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) { Job loadJob = new Job(Messages.getString("org.nightlabs.jfire.trade.ui.overview.invoice.report.ValueProviderGUIInvoiceByCustomer.loadInvoicesJob.name")) { //$NON-NLS-1$ @Override protected IStatus run(ProgressMonitor monitor) { InvoiceQuery query = new InvoiceQuery(); query.setCustomerID((AnchorID) value); QueryCollection<InvoiceQuery> qs = new QueryCollection<InvoiceQuery>(Invoice.class); qs.add(query); final Collection<Invoice> invoices = InvoiceDAO.sharedInstance().getInvoices( qs, FETCH_GROUPS_INVOICES, NLJDOHelper.MAX_FETCH_DEPTH_NO_LIMIT, monitor); Display.getDefault().asyncExec(new Runnable() { public void run() { invoiceListComposite.setInput(invoices); } }); return Status.OK_STATUS; } }; loadJob.schedule(); } }