Search in sources :

Example 46 with ModelElementIndicator

use of org.talend.dataprofiler.core.model.ModelElementIndicator in project tdq-studio-se by Talend.

the class AnalysisColumnTreeViewer method moveSelectedElements.

/**
 * DOC yyi 7466 2010-03-22 change the order of appearence of indicators.
 *
 * @param newTree
 * @param step
 */
protected void moveSelectedElements(Tree newTree, int step) {
    TreeItem[] selection = newTree.getSelection();
    if (selection != null) {
        // used to set the selected columns focus at last
        List<Object> selectedDataList = new ArrayList<Object>();
        // TDQ-11530 msjian: get all selected data's list first to check how to move
        List<IndicatorUnit> indicatorUnitList = new ArrayList<IndicatorUnit>();
        List<ModelElementIndicator> dataList = new ArrayList<ModelElementIndicator>();
        for (TreeItem item : selection) {
            IndicatorUnit indicatorUnit = (IndicatorUnit) item.getData(INDICATOR_UNIT_KEY);
            if (indicatorUnit != null) {
                indicatorUnitList.add(indicatorUnit);
            } else {
                ModelElementIndicator data = (ModelElementIndicator) item.getData(MODELELEMENT_INDICATOR_KEY);
                dataList.add(data);
            }
        }
        for (TreeItem item : selection) {
            IndicatorUnit indicatorUnit = (IndicatorUnit) item.getData(INDICATOR_UNIT_KEY);
            ModelElementIndicator data = (ModelElementIndicator) item.getData(MODELELEMENT_INDICATOR_KEY);
            if (indicatorUnit != null) {
                TypedReturnCode<IndicatorUnit[]> code = sortIndicatorUnits(data.getIndicatorUnits(), indicatorUnit, step, indicatorUnitList);
                if (code.isOk()) {
                    if (null != code.getObject()) {
                        Indicator[] inds = new Indicator[code.getObject().length];
                        for (int i = 0; i < code.getObject().length; i++) {
                            inds[i] = code.getObject()[i].getIndicator();
                        }
                        data.setIndicators(inds);
                    }
                    selectedDataList.add(indicatorUnit);
                }
            } else {
                int index = ArrayUtils.indexOf(modelElementIndicators, data);
                int changeIndex = index + step;
                if (changeIndex > -1 && changeIndex < modelElementIndicators.length) {
                    ModelElementIndicator tmpElement = modelElementIndicators[changeIndex];
                    // when the changed one is the selected one too, get next one
                    while (dataList.contains(tmpElement)) {
                        tmpElement = modelElementIndicators[++changeIndex];
                    }
                    modelElementIndicators[changeIndex] = modelElementIndicators[index];
                    modelElementIndicators[index] = tmpElement;
                    // after the data changed successfully remove it from the selected list
                    dataList.remove(data);
                    selectedDataList.add(data);
                }
            }
        }
        setElements(modelElementIndicators, true, false);
        for (Object obj : selectedDataList) {
            selectElement(tree.getItems(), obj);
        }
        masterPage.synNagivatorStat();
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) ArrayList(java.util.ArrayList) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) DelimitedFileIndicator(org.talend.dataprofiler.core.model.DelimitedFileIndicator) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Indicator(org.talend.dataquality.indicators.Indicator) CompositeIndicator(org.talend.dataquality.indicators.CompositeIndicator) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) MetadataXmlElementTypeRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataXmlElementTypeRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator)

Example 47 with ModelElementIndicator

use of org.talend.dataprofiler.core.model.ModelElementIndicator in project tdq-studio-se by Talend.

the class AnalysisColumnTreeViewer method addColumnUdi.

/**
 * DOC xqliu Comment method "addColumnUdi". ADD xqliu 2010-02-23 feature 11617
 *
 * @param treeItem
 * @param meIndicator
 * @param columnIndex
 * @return
 */
private TreeEditor addColumnUdi(final TreeItem treeItem, final ModelElementIndicator meIndicator, int columnIndex) {
    TreeEditor addUdiEditor = new TreeEditor(tree);
    // $NON-NLS-1$
    Label addUdiLabl = createTreeItemLabel(tree, ImageLib.ADD_IND_DEFINITION, "AnalysisColumnTreeViewer.addUdi");
    addUdiLabl.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            DataManager dm = getAnalysis().getContext().getConnection();
            if (dm == null) {
                masterPage.doSave(null);
            }
            CheckedTreeSelectionDialog dialog = UDIUtils.createUdiCheckedTreeSelectionDialog(meIndicator);
            if (dialog.open() == Window.OK) {
                // MOD qiongli 2012-10-24 TDQ-6308,just remove some deselected indicatorUnit then set dirty to
                // true,just create new indicatorUnit for some new added UDI then set dirty to true.
                List<IndicatorDefinition> allSelectedIndicatorDefinitions = new ArrayList<IndicatorDefinition>();
                Set<String> allSelectedIndNames = new HashSet<String>();
                for (Object obj : dialog.getResult()) {
                    if (obj instanceof SysIndicatorDefinitionRepNode) {
                        IndicatorDefinition udid = ((SysIndicatorDefinitionRepNode) obj).getIndicatorDefinition();
                        allSelectedIndicatorDefinitions.add(udid);
                        if (udid != null) {
                            allSelectedIndNames.add(udid.getName());
                        }
                    }
                }
                Set<String> oldSelectedIndNames = new HashSet<String>();
                for (IndicatorUnit indicatorUnit : meIndicator.getIndicatorUnits()) {
                    Indicator indicator = indicatorUnit.getIndicator();
                    if (indicator instanceof UserDefIndicator) {
                        if (allSelectedIndNames.contains(indicator.getName())) {
                            oldSelectedIndNames.add(indicator.getName());
                        } else {
                            // remove the UDI from UI need to insert this UDI into removeList
                            deleteIndicatorItems(meIndicator, indicatorUnit);
                            if (!isDirty()) {
                                setDirty(true);
                            }
                        }
                    }
                }
                treeItem.removeAll();
                for (IndicatorDefinition udid : allSelectedIndicatorDefinitions) {
                    if (udid != null && oldSelectedIndNames.contains(udid.getName())) {
                        continue;
                    }
                    IndicatorUnit[] addIndicatorUnits = null;
                    try {
                        addIndicatorUnits = UDIUtils.createIndicatorUnit(udid, meIndicator, getAnalysis());
                    } catch (Throwable e1) {
                        log.warn(e1, e1);
                    }
                    if (addIndicatorUnits != null && addIndicatorUnits.length > 0) {
                        for (IndicatorUnit unit : addIndicatorUnits) {
                            createOneUnit(treeItem, unit);
                        }
                        if (!isDirty()) {
                            setDirty(true);
                        }
                    }
                }
                treeItem.setExpanded(true);
                masterPage.refreshTheTree(masterPage.getCurrentModelElementIndicators());
            }
        }
    });
    addUdiEditor.minimumWidth = addUdiLabl.getImage().getBounds().width;
    addUdiEditor.setEditor(addUdiLabl, treeItem, columnIndex);
    return addUdiEditor;
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Set(java.util.Set) HashSet(java.util.HashSet) TreeEditor(org.eclipse.swt.custom.TreeEditor) CheckedTreeSelectionDialog(org.eclipse.ui.dialogs.CheckedTreeSelectionDialog) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) DelimitedFileIndicator(org.talend.dataprofiler.core.model.DelimitedFileIndicator) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Indicator(org.talend.dataquality.indicators.Indicator) CompositeIndicator(org.talend.dataquality.indicators.CompositeIndicator) SysIndicatorDefinitionRepNode(org.talend.dq.nodes.SysIndicatorDefinitionRepNode) List(java.util.List) ArrayList(java.util.ArrayList) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) MetadataXmlElementTypeRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataXmlElementTypeRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator)

Example 48 with ModelElementIndicator

use of org.talend.dataprofiler.core.model.ModelElementIndicator in project tdq-studio-se by Talend.

the class ModelElementTreeMenuProvider method createColumnAnalysis.

/**
 * DOC qiongli Comment method "createColumnAnalysis".bug 16252.
 *
 * @param newTree
 */
private void createColumnAnalysis(Tree newTree) {
    TreeItem[] items = newTree.getSelection();
    if (items.length > 0) {
        TreePath[] paths = new TreePath[items.length];
        for (int i = 0; i < items.length; i++) {
            // MOD klliu bug 20820 change TDcolum to IRepositoryNode, then solve NPE 2011-04-29
            // $NON-NLS-1$
            ModelElementIndicator data = (ModelElementIndicator) items[i].getData("MODELELEMENT_INDICATOR_KEY");
            IRepositoryNode modelElementRepositoryNode = data.getModelElementRepositoryNode();
            paths[i] = new TreePath(new Object[] { modelElementRepositoryNode });
        }
        CreateColumnAnalysisAction analysisAction = new CreateColumnAnalysisAction();
        analysisAction.setSelection(new TreeSelection(paths));
        analysisAction.run();
    }
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) IRepositoryNode(org.talend.repository.model.IRepositoryNode) TreeItem(org.eclipse.swt.widgets.TreeItem) CreateColumnAnalysisAction(org.talend.dataprofiler.core.ui.action.actions.predefined.CreateColumnAnalysisAction) TreeSelection(org.eclipse.jface.viewers.TreeSelection) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) ISubRepositoryObject(org.talend.core.model.repository.ISubRepositoryObject) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator)

Example 49 with ModelElementIndicator

use of org.talend.dataprofiler.core.model.ModelElementIndicator in project tdq-studio-se by Talend.

the class ModelElementTreeMenuProvider method viewQueryForSelectedElement.

/**
 * DOC mzhao Comment method "viewQueryForSelectedElement".
 *
 * @param newTree
 */
private void viewQueryForSelectedElement(Tree newTree) {
    TreeItem[] selection = newTree.getSelection();
    for (TreeItem item : selection) {
        ModelElementIndicator meIndicator = (ModelElementIndicator) item.getData(AbstractColumnDropTree.MODELELEMENT_INDICATOR_KEY);
        ConnectionItem connItem = (ConnectionItem) meIndicator.getModelElementRepositoryNode().getObject().getProperty().getItem();
        Connection dataprovider = connItem.getConnection();
        IndicatorUnit indicatorUnit = (IndicatorUnit) item.getData(AbstractColumnDropTree.INDICATOR_UNIT_KEY);
        DbmsLanguage dbmsLang = DbmsLanguageFactory.createDbmsLanguage(dataprovider);
        Expression expression = dbmsLang.getInstantiatedExpression(indicatorUnit.getIndicator());
        if (expression == null) {
            MessageDialogWithToggle.openWarning(null, DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.Warn"), // $NON-NLS-1$ //$NON-NLS-2$
            DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.NoQueryDefined"));
            return;
        }
        SqlExplorerUtils.getDefault().runInDQViewer(dataprovider, expression.getBody(), meIndicator.getModelElementRepositoryNode().getObject().getProperty().getLabel());
    }
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) TreeItem(org.eclipse.swt.widgets.TreeItem) Expression(orgomg.cwm.objectmodel.core.Expression) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Connection(org.talend.core.model.metadata.builder.connection.Connection) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) ColumnIndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.ColumnIndicatorUnit) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator)

Example 50 with ModelElementIndicator

use of org.talend.dataprofiler.core.model.ModelElementIndicator in project tdq-studio-se by Talend.

the class ModelElementTreeMenuProvider method getSelectedNode.

/**
 * DOC msjian Comment method "getSelectedNode".
 *
 * @param selection
 * @return
 */
protected RepositoryNode getSelectedNode(TreeItem[] selection) {
    ModelElementIndicator meIndicator = (ModelElementIndicator) selection[0].getData(AbstractColumnDropTree.MODELELEMENT_INDICATOR_KEY);
    ModelElement me = ((ISubRepositoryObject) meIndicator.getModelElementRepositoryNode().getObject()).getModelElement();
    RepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(me);
    if (recursiveFind == null) {
        recursiveFind = RepositoryNodeHelper.createRepositoryNode(me);
    }
    return recursiveFind;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) ISubRepositoryObject(org.talend.core.model.repository.ISubRepositoryObject) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator)

Aggregations

ModelElementIndicator (org.talend.dataprofiler.core.model.ModelElementIndicator)58 IRepositoryNode (org.talend.repository.model.IRepositoryNode)22 ArrayList (java.util.ArrayList)16 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)16 MetadataColumnRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)15 Indicator (org.talend.dataquality.indicators.Indicator)13 IndicatorUnit (org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit)12 TreeItem (org.eclipse.swt.widgets.TreeItem)11 RepositoryNode (org.talend.repository.model.RepositoryNode)10 IndicatorEnum (org.talend.dq.nodes.indicator.type.IndicatorEnum)9 MetadataXmlElementTypeRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataXmlElementTypeRepositoryObject)7 Connection (org.talend.core.model.metadata.builder.connection.Connection)6 CompositeIndicator (org.talend.dataquality.indicators.CompositeIndicator)6 MetadataTableRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)5 TreeEditor (org.eclipse.swt.custom.TreeEditor)4 MouseAdapter (org.eclipse.swt.events.MouseAdapter)4 MouseEvent (org.eclipse.swt.events.MouseEvent)4 Composite (org.eclipse.swt.widgets.Composite)4 Label (org.eclipse.swt.widgets.Label)4