Search in sources :

Example 1 with ICustomerDataset

use of org.talend.dataprofiler.common.ui.editor.preview.ICustomerDataset in project tdq-studio-se by Talend.

the class PatternStatisticsStateTest method testGetCustomerDataset.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.ui.editor.preview.model.states.pattern.PatternStatisticsState#getCustomerDataset()}
 */
@Test
public void testGetCustomerDataset() {
    ICustomerDataset customerDataset = patternStatisticsState.getCustomerDataset();
    ChartDataEntity[] dataEntities = customerDataset.getDataEntities();
    Assert.assertEquals(1, dataEntities.length);
    // $NON-NLS-1$
    Assert.assertEquals("Blank text", dataEntities[0].getLabel());
}
Also used : ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) ICustomerDataset(org.talend.dataprofiler.common.ui.editor.preview.ICustomerDataset) Test(org.junit.Test)

Example 2 with ICustomerDataset

use of org.talend.dataprofiler.common.ui.editor.preview.ICustomerDataset in project tdq-studio-se by Talend.

the class FrequencyDynamicChartEventReceiver method setFrequecyToDataset.

private void setFrequecyToDataset(Object customerdataset, FrequencyExt[] frequencyExt, Indicator indicator) {
    int numOfShown = frequencyExt.length;
    IndicatorParameters parameters = indicator.getParameters();
    if (parameters != null) {
        if (parameters.getTopN() < numOfShown) {
            numOfShown = parameters.getTopN();
        }
    }
    FrequencyExt[] tempFreq = handleFrequency(frequencyExt);
    clearDataEntity(customerdataset);
    boolean withRowCountIndicator = FrequencyTypeStateUtil.isWithRowCountIndicator(indicator);
    // Added TDQ-12870
    List columnKeys = TOPChartUtils.getInstance().getColumnKeys(customerdataset);
    FrequencyExt freqE = tempFreq[0];
    if (!columnKeys.contains(String.valueOf(freqE.getKey()))) {
        // columnKeys.clear();
        TOPChartUtils.getInstance().clearDataset(customerdataset);
        ICustomerDataset customerDataset = TOPChartUtils.getInstance().getCustomerDataset(customerdataset);
        if (customerDataset != null && customerDataset instanceof CustomerDefaultCategoryDataset) {
            ((CustomerDefaultCategoryDataset) customerDataset).clearAll();
        }
    }
    for (int i = 0; i < numOfShown; i++) {
        FrequencyExt freqExt = tempFreq[i];
        String keyLabel = String.valueOf(freqExt.getKey());
        if ("null".equals(keyLabel)) {
            // $NON-NLS-1$
            keyLabel = SpecialValueDisplay.NULL_FIELD;
        }
        if ("".equals(keyLabel)) {
            // $NON-NLS-1$
            keyLabel = SpecialValueDisplay.EMPTY_FIELD;
        }
        ChartDataEntity entity = FrequencyTypeStateUtil.createChartEntity(indicator, freqExt, keyLabel, withRowCountIndicator);
        if (customerdataset instanceof CustomerDefaultCategoryDataset) {
            ((CustomerDefaultCategoryDataset) customerdataset).addDataEntity(entity);
            addValueToDataset(((CustomerDefaultCategoryDataset) customerdataset).getDataset(), freqExt, keyLabel);
        } else {
            ICustomerDataset customerDataset = TOPChartUtils.getInstance().getCustomerDataset(customerdataset);
            if (customerDataset != null && customerDataset instanceof CustomerDefaultCategoryDataset) {
                customerDataset.addDataEntity(entity);
                addValueToDataset(((CustomerDefaultCategoryDataset) customerDataset).getDataset(), freqExt, keyLabel);
            }
        }
    }
}
Also used : IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) ArrayList(java.util.ArrayList) List(java.util.List) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) FrequencyExt(org.talend.dq.indicators.ext.FrequencyExt) CustomerDefaultCategoryDataset(org.talend.dataprofiler.common.ui.editor.preview.CustomerDefaultCategoryDataset) ICustomerDataset(org.talend.dataprofiler.common.ui.editor.preview.ICustomerDataset)

Example 3 with ICustomerDataset

use of org.talend.dataprofiler.common.ui.editor.preview.ICustomerDataset in project tdq-studio-se by Talend.

the class FrequencyDynamicChartEventReceiver method handle.

@Override
public boolean handle(Object value) {
    Object indValue = value;
    if (value == null) {
        indValue = 0;
    }
    if (dataset != null) {
        // no sort needed here
        if (indValue instanceof FrequencyExt[]) {
            FrequencyExt[] frequencyExt = (FrequencyExt[]) indValue;
            setFrequecyToDataset(dataset, frequencyExt, indicator);
        }
    }
    if (tableViewer != null && dataset != null) {
        TableWithData input = (TableWithData) tableViewer.getInput();
        if (input != null) {
            if (this.indicator instanceof ModeIndicator) {
                ChartDataEntity entity = new ChartDataEntity();
                entity.setIndicator(indicator);
                entity.setLabel(this.indicatorName);
                entity.setValue(String.valueOf(indValue));
                // mode indicator has not a chart so that no dataset too
                input.setEntities(new ChartDataEntity[] { entity });
            } else {
                ICustomerDataset customerDataset = TOPChartUtils.getInstance().getCustomerDataset(dataset);
                if (customerDataset != null) {
                    input.setEntities((customerDataset).getDataEntities());
                } else {
                    input.setEntities(((ICustomerDataset) dataset).getDataEntities());
                }
            }
        }
        if (!tableViewer.getTable().isDisposed()) {
            tableViewer.getTable().clearAll();
            tableViewer.setInput(input);
        }
    }
    if (registerChart != TOPChartUtils.getInstance().getChartFromChartComposite(parentChartComposite)) {
        restoreChart();
    }
    // need to refresh the parent composite of the chart to show the changes
    if (!(indicator instanceof ModeIndicator)) {
        EventManager.getInstance().publish(chartComposite, EventEnum.DQ_DYNAMIC_REFRESH_DYNAMIC_CHART, null);
    }
    return true;
}
Also used : TableWithData(org.talend.dataprofiler.core.ui.editor.preview.model.TableWithData) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) ModeIndicator(org.talend.dataquality.indicators.ModeIndicator) FrequencyExt(org.talend.dq.indicators.ext.FrequencyExt) ICustomerDataset(org.talend.dataprofiler.common.ui.editor.preview.ICustomerDataset)

Example 4 with ICustomerDataset

use of org.talend.dataprofiler.common.ui.editor.preview.ICustomerDataset in project tdq-studio-se by Talend.

the class BusinessRuleAnalysisResultPage method createResultDataComposite.

private void createResultDataComposite(final Composite comp, final TableIndicator tableIndicator) {
    if (tableIndicator.getIndicators().length != 0) {
        final NamedColumnSet set = tableIndicator.getColumnSet();
        IRunnableWithProgress rwp = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(DefaultMessagesImpl.getString("TableAnalysisResultPage.createPreview", set.getName()), // $NON-NLS-1$
                IProgressMonitor.UNKNOWN);
                Display.getDefault().asyncExec(new Runnable() {

                    public void run() {
                        Map<EIndicatorChartType, List<TableIndicatorUnit>> indicatorComposite = CompositeIndicator.getInstance().getTableIndicatorComposite(tableIndicator);
                        for (EIndicatorChartType chartType : indicatorComposite.keySet()) {
                            List<TableIndicatorUnit> units = indicatorComposite.get(chartType);
                            if (!units.isEmpty()) {
                                // create UI
                                ExpandableComposite subComp = createSubWholeComposite(comp, chartType);
                                final Composite composite = createCompositeForTableAndChart(subComp);
                                Composite tableTopComp = createTableComposite(composite);
                                Analysis analysis = masterPage.getAnalysisHandler().getAnalysis();
                                ITableTypeStates tableTypeState = TableTypeStatesFactory.getInstance().getTableStateForRule(chartType, units, tableIndicator);
                                // create table for RownCountIndicator
                                createTableViewerForRowCount(chartType, units, tableTopComp, analysis, tableTypeState);
                                // create table for WhereRuleIndicator
                                createTableForWhereRule(chartType, tableTopComp, analysis, tableTypeState, units);
                                Composite chartTopComp = createTableComposite(composite);
                                if (canShowChartForResultPage()) {
                                    createChartsForRules(tableIndicator, chartType, units, analysis, chartTopComp);
                                }
                                subComp.setClient(composite);
                                subComp.addExpansionListener(new ExpansionAdapter() {

                                    @Override
                                    public void expansionStateChanged(ExpansionEvent e) {
                                        form.reflow(true);
                                    }
                                });
                            }
                        }
                    }

                    /**
                     * DOC yyin Comment method "createChartsForRules".
                     *
                     * @param tableIndicator
                     * @param chartType
                     * @param units
                     * @param analysis
                     * @param chartTopComp
                     */
                    private void createChartsForRules(final TableIndicator tableIndicator, EIndicatorChartType chartType, List<TableIndicatorUnit> units, Analysis analysis, Composite chartTopComp) {
                        IChartTypeStates chartTypeState = ChartTypeStatesFactory.getChartStateOfTableAna(chartType, units, tableIndicator);
                        // get all indicator lists separated by chart, and only
                        // WhereRuleStatisticsStateTable can get not-null charts
                        List<List<Indicator>> pagedIndicators = ((WhereRuleStatisticsStateTable) chartTypeState).getPagedIndicators();
                        // Added TDQ-9241: for each list(for each chart), check if the current
                        // list has been registered dynamic event
                        List<Object> datasets = new ArrayList<Object>();
                        for (List<Indicator> oneChart : pagedIndicators) {
                            IEventReceiver event = EventManager.getInstance().findRegisteredEvent(oneChart.get(0), EventEnum.DQ_DYMANIC_CHART, 0);
                            if (event != null) {
                                // get the dataset from the event
                                Object dataset = ((TableDynamicChartEventReceiver) event).getDataset();
                                // one running)
                                if (dataset != null) {
                                    datasets.add(dataset);
                                }
                            }
                        // ~
                        }
                        // create chart
                        List<Object> charts = null;
                        if (datasets.size() > 0) {
                            charts = chartTypeState.getChartList(datasets);
                        } else {
                            charts = chartTypeState.getChartList();
                            datasets = ((WhereRuleStatisticsStateTable) chartTypeState).getTempDatasetList();
                        }
                        if (charts != null) {
                            int index = 0;
                            for (int i = 0; i < charts.size(); i++) {
                                Object chart2 = charts.get(i);
                                Object chartComp = TOPChartUtils.getInstance().createChartCompositeWithSpecialSize(chartTopComp, SWT.NONE, chart2, true, 250, 550);
                                // Added TDQ-8787 20140707 yyin: create and store the dynamic model for
                                // each chart
                                DynamicIndicatorModel dyModel = AnalysisUtils.createDynamicModel(chartType, pagedIndicators.get(index++), chart2);
                                dynamicList.add(dyModel);
                                // ~
                                // one dataset <--> one chart
                                addMenuToChartComp(chartComp, chartTypeState.getDataExplorer(), analysis, ((ICustomerDataset) datasets.get(i)).getDataEntities());
                            }
                        }
                    }

                    /**
                     * DOC yyin Comment method "createTableForWhereRule".
                     *
                     * @param chartType
                     * @param tableTopComp
                     * @param analysis
                     * @param tableTypeState
                     * @param units
                     * @return
                     */
                    private void createTableForWhereRule(EIndicatorChartType chartType, Composite tableTopComp, Analysis analysis, ITableTypeStates tableTypeState, List<TableIndicatorUnit> units) {
                        TableWithData chartData = new TableWithData(chartType, tableTypeState.getDataEntity());
                        TableViewer tableviewer = tableTypeState.getTableForm(tableTopComp);
                        tableviewer.setInput(chartData);
                        ChartTableFactory.addMenuAndTip(tableviewer, tableTypeState.getDataExplorer(), analysis);
                        // Added TDQ-8787 20140707 yyin: create and store the dynamic model
                        List<Indicator> allRules = new ArrayList<Indicator>();
                        List<TableIndicatorUnit> removeRowCountUnit = ((WhereRuleStatisticsTableState) tableTypeState).removeRowCountUnit(units);
                        for (TableIndicatorUnit indUnit : removeRowCountUnit) {
                            allRules.add(indUnit.getIndicator());
                        }
                        DynamicIndicatorModel dyModel = AnalysisUtils.createDynamicModel(chartType, allRules, null);
                        dyModel.setTableViewer(tableviewer);
                        dynamicList.add(dyModel);
                    }

                    /**
                     * DOC yyin Comment method "createTableViewerForRowCount".
                     *
                     * @param chartType
                     * @param units
                     * @param tableTopComp
                     * @param analysis
                     * @param tableTypeState
                     */
                    private void createTableViewerForRowCount(EIndicatorChartType chartType, List<TableIndicatorUnit> units, Composite tableTopComp, Analysis analysis, ITableTypeStates tableTypeState) {
                        WhereRuleStatisticsTableState tableWhereRule = (WhereRuleStatisticsTableState) tableTypeState;
                        TableWithData chartDataRowCount = new TableWithData(chartType, tableWhereRule.getDataEntityOfRowCount());
                        TableViewer tableviewerRowCount = tableWhereRule.getTableFormRowCount(tableTopComp);
                        tableviewerRowCount.setInput(chartDataRowCount);
                        ChartTableFactory.addMenuAndTip(tableviewerRowCount, tableTypeState.getDataExplorer(), analysis);
                        // Added TDQ-8787 20140707 yyin: create and store the dynamic model for row
                        // count's table
                        List<Indicator> rowCount = new ArrayList<Indicator>();
                        rowCount.add(tableWhereRule.getRownCountUnit(units).getIndicator());
                        DynamicIndicatorModel dyModel = AnalysisUtils.createDynamicModel(chartType, rowCount, null);
                        dyModel.setTableViewer(tableviewerRowCount);
                        dynamicList.add(dyModel);
                    }

                    /**
                     * DOC yyin Comment method "createTableComposite".
                     *
                     * @param composite
                     * @return
                     */
                    private Composite createTableComposite(final Composite composite) {
                        Composite tableTopComp = toolkit.createComposite(composite, SWT.NULL);
                        tableTopComp.setLayout(new GridLayout(1, false));
                        tableTopComp.setLayoutData(new GridData(GridData.FILL_BOTH));
                        return tableTopComp;
                    }

                    /**
                     * DOC yyin Comment method "createCompositeForTableAndChart".
                     *
                     * @param subComp
                     * @return
                     */
                    private Composite createCompositeForTableAndChart(ExpandableComposite subComp) {
                        final Composite composite = toolkit.createComposite(subComp, SWT.NULL);
                        composite.setLayout(new GridLayout(2, false));
                        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
                        return composite;
                    }

                    /**
                     * DOC yyin Comment method "createSubWholeComposite".
                     *
                     * @param comp
                     * @param chartType
                     * @return
                     */
                    private ExpandableComposite createSubWholeComposite(final Composite comp, EIndicatorChartType chartType) {
                        ExpandableComposite subComp = toolkit.createExpandableComposite(comp, ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT | ExpandableComposite.EXPANDED);
                        subComp.setText(chartType.getLiteral());
                        subComp.setLayoutData(new GridData(GridData.FILL_BOTH));
                        subComp.setExpanded(EditorPreferencePage.isUnfoldingIndicatorsResultPage());
                        return subComp;
                    }
                });
                monitor.done();
            }
        };
        try {
            new ProgressMonitorDialog(this.getEditorSite().getShell()).run(true, false, rwp);
        } catch (Exception ex) {
            log.error(ex, ex);
        }
    }
}
Also used : IEventReceiver(org.talend.dataprofiler.core.ui.events.IEventReceiver) TableWithData(org.talend.dataprofiler.core.ui.editor.preview.model.TableWithData) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) GridLayout(org.eclipse.swt.layout.GridLayout) TableIndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.TableIndicatorUnit) List(java.util.List) ArrayList(java.util.ArrayList) DynamicIndicatorModel(org.talend.dataprofiler.core.model.dynamic.DynamicIndicatorModel) NamedColumnSet(orgomg.cwm.resource.relational.NamedColumnSet) ICustomerDataset(org.talend.dataprofiler.common.ui.editor.preview.ICustomerDataset) TableIndicator(org.talend.dataprofiler.core.model.TableIndicator) WhereRuleStatisticsTableState(org.talend.dataprofiler.core.ui.editor.preview.model.states.table.WhereRuleStatisticsTableState) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) WhereRuleStatisticsStateTable(org.talend.dataprofiler.core.ui.editor.preview.model.states.WhereRuleStatisticsStateTable) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) CompositeIndicator(org.talend.dataprofiler.core.ui.editor.preview.CompositeIndicator) Indicator(org.talend.dataquality.indicators.Indicator) TableIndicator(org.talend.dataprofiler.core.model.TableIndicator) InvocationTargetException(java.lang.reflect.InvocationTargetException) IChartTypeStates(org.talend.dataprofiler.core.ui.editor.preview.model.states.IChartTypeStates) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITableTypeStates(org.talend.dataprofiler.core.ui.editor.preview.model.states.table.ITableTypeStates) Analysis(org.talend.dataquality.analysis.Analysis) EIndicatorChartType(org.talend.dq.indicators.preview.EIndicatorChartType) GridData(org.eclipse.swt.layout.GridData) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

ICustomerDataset (org.talend.dataprofiler.common.ui.editor.preview.ICustomerDataset)4 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TableWithData (org.talend.dataprofiler.core.ui.editor.preview.model.TableWithData)2 FrequencyExt (org.talend.dq.indicators.ext.FrequencyExt)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 ExpansionAdapter (org.eclipse.ui.forms.events.ExpansionAdapter)1 ExpansionEvent (org.eclipse.ui.forms.events.ExpansionEvent)1 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)1 Test (org.junit.Test)1