/** * */ package org.nightlabs.jfire.reporting.trade.ui.accounting.account; import java.util.ArrayList; import java.util.Collection; import javax.jdo.JDOHelper; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; 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.Group; import org.nightlabs.jfire.accounting.Account; 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.ui.overview.account.AccountEntryFactory; import org.nightlabs.jfire.trade.ui.overview.account.AccountEntryViewer; import org.nightlabs.jfire.transfer.Anchor; import org.nightlabs.jfire.transfer.id.AnchorID; /** * @author Alexander Bieber <!-- alex [AT] nightlabs [DOT] de --> * */ public class ValueProviderGUIAccounts extends AbstractValueProviderGUI<Collection<AnchorID>> { public static class Factory implements IValueProviderGUIFactory { /* (non-Javadoc) * @see org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUIFactory#createValueProviderGUI() */ public IValueProviderGUI<Collection<AnchorID>> createValueProviderGUI(ValueProviderConfig valueProviderConfig, boolean isScheduledReportParameterConfig) { return new ValueProviderGUIAccounts(valueProviderConfig); } /* (non-Javadoc) * @see org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUIFactory#getValueProviderID() */ public ValueProviderID getValueProviderID() { return ReportingTradeConstants.VALUE_PROVIDER_ID_ACCOUNTING_ACCOUNT_IDS; } /* (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 AccountEntryViewer accountEntryViewer; public ValueProviderGUIAccounts(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()); accountEntryViewer = new AccountEntryViewer(new AccountEntryFactory().createEntry(), false); Composite composite = accountEntryViewer.createComposite(group); accountEntryViewer.getListComposite().addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { notifyOutputChanged(); } }); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); return group; } /* (non-Javadoc) * @see org.nightlabs.jfire.reporting.ui.parameter.IValueProviderGUI#getOutputValue() */ public Collection<AnchorID> getOutputValue() { Collection<Account> anchors = accountEntryViewer.getListComposite().getSelectedElements(); if (anchors != null && anchors.size() > 0) { Collection<AnchorID> result = new ArrayList<AnchorID>(anchors.size()); for (Anchor anchor : anchors) { result.add((AnchorID) JDOHelper.getObjectId(anchor)); } return result; } 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) { } }