Search in sources :

Example 6 with AnalysisItemEditorInput

use of org.talend.dataprofiler.core.ui.editor.analysis.AnalysisItemEditorInput in project tdq-studio-se by Talend.

the class OpenItemEditorAction method computeEditorInput.

/**
 * get the ItemEditorInput according to the repNode, if there no ItemEditorInput return null.
 *
 * @param repNode
 * @param isOpenItemEditorAction
 * @return IEditorInput
 * @throws PersistenceException
 */
public IEditorInput computeEditorInput(IRepositoryNode repNode, boolean isOpenItemEditorAction) throws BusinessException {
    // TDQ-12499 msjian add : when click the node under recyclebin, no need to find a EditorInput
    if (repNode != null && !isOpenItemEditorAction) {
        IRepositoryNode currentNode = repNode;
        do {
            RepositoryNode parentNode = currentNode.getParent();
            if (parentNode != null && parentNode instanceof RecycleBinRepNode) {
                return null;
            }
            currentNode = parentNode;
        } while (currentNode != null);
    }
    // TDQ-12499~
    IEditorInput result = null;
    IRepositoryViewObject repViewObj = repNode.getObject();
    if (repViewObj != null) {
        // Connection editor
        String key = repViewObj.getRepositoryObjectType().getKey();
        Item item = repViewObj.getProperty().getItem();
        if (item instanceof TDQItem && !(item instanceof TDQFileItem)) {
            ModelElement modelElement = PropertyHelper.getModelElement(repViewObj.getProperty());
            if (modelElement.eIsProxy() && repNode != null) {
                modelElement = (ModelElement) EObjectHelper.resolveObject(modelElement);
                item = repViewObj.getProperty().getItem();
            }
            if (modelElement == null || modelElement.eResource() == null) {
                throw ExceptionFactory.getInstance().createBusinessException(((TDQItem) item).getFilename());
            }
        }
        if (ERepositoryObjectType.METADATA_CONNECTIONS.getKey().equals(key) || ConnectionUtils.isTcompJdbc(key)) {
            result = new ConnectionItemEditorInput(repNode);
            Connection connection = ((ConnectionItem) item).getConnection();
            if (connection == null || connection.getDataPackage().size() == 0) {
                throw ExceptionFactory.getInstance().createBusinessException(repViewObj);
            }
            editorID = ConnectionEditor.class.getName();
        } else if (ERepositoryObjectType.TDQ_ANALYSIS_ELEMENT.getKey().equals(key)) {
            result = new AnalysisItemEditorInput(repNode);
            Analysis analysis = ((TDQAnalysisItem) item).getAnalysis();
            if (analysis == null || analysis.getContext() == null) {
                throw ExceptionFactory.getInstance().createBusinessException(repViewObj);
            }
            EList<ModelElement> analysedElements = analysis.getContext().getAnalysedElements();
            RepositoryNode connectionRepositoryNode = null;
            if (!analysedElements.isEmpty()) {
                Connection connection = null;
                ModelElement modelElement = analysedElements.get(0);
                if (modelElement instanceof Connection) {
                    connection = (Connection) modelElement;
                } else if (modelElement instanceof Catalog) {
                    Catalog catalog = SwitchHelpers.CATALOG_SWITCH.caseCatalog((Catalog) modelElement);
                    connection = ConnectionHelper.getConnection(catalog);
                } else if (modelElement instanceof Schema) {
                    Schema schema = SwitchHelpers.SCHEMA_SWITCH.caseSchema((Schema) modelElement);
                    if (schema != null) {
                        connection = ConnectionHelper.getConnection(schema);
                    }
                } else if (modelElement instanceof TdTable) {
                    TdTable tdTable = SwitchHelpers.TABLE_SWITCH.caseTdTable((TdTable) modelElement);
                    connection = ConnectionHelper.getConnection(tdTable);
                } else if (modelElement instanceof TdView) {
                    TdView tdView = SwitchHelpers.VIEW_SWITCH.caseTdView((TdView) modelElement);
                    connection = ConnectionHelper.getConnection(tdView);
                } else if (modelElement instanceof TdColumn) {
                    TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.caseTdColumn((TdColumn) modelElement);
                    connection = ConnectionHelper.getConnection(tdColumn);
                } else if (modelElement instanceof MetadataColumn) {
                    MetadataColumn mColumn = SwitchHelpers.METADATA_COLUMN_SWITCH.doSwitch(modelElement);
                    connection = ConnectionHelper.getTdDataProvider(mColumn);
                }
                connectionRepositoryNode = RepositoryNodeHelper.recursiveFind(connection);
            }
            ((AnalysisItemEditorInput) result).setConnectionNode(connectionRepositoryNode);
            if (analysis.getParameters() != null && analysis.getParameters().getAnalysisType().equals(AnalysisType.MATCH_ANALYSIS)) {
                editorID = MatchAnalysisEditor.class.getName();
            } else {
                editorID = AnalysisEditor.class.getName();
            }
        } else if (ERepositoryObjectType.TDQ_INDICATOR_ELEMENT.getKey().equals(key)) {
            result = new IndicatorDefinitionItemEditorInput(repNode);
            TDQIndicatorDefinitionItem definitionItem = (TDQIndicatorDefinitionItem) item;
            if (definitionItem.getIndicatorDefinition().eResource() == null) {
                throw ExceptionFactory.getInstance().createBusinessException(definitionItem.getFilename());
            }
            if (UDIHelper.getUDICategory(definitionItem.getIndicatorDefinition()) == null) {
                throw ExceptionFactory.getInstance().createBusinessException(definitionItem.getFilename());
            }
            editorID = IndicatorEditor.class.getName();
        } else if (ERepositoryObjectType.TDQ_RULES_SQL.getKey().equals(key) || ERepositoryObjectType.TDQ_RULES_PARSER.getKey().equals(key) || ERepositoryObjectType.TDQ_RULES_MATCHER.getKey().equals(key)) {
            result = new BusinessRuleItemEditorInput(repNode);
            editorID = DQRuleEditor.class.getName();
        } else if (ERepositoryObjectType.TDQ_PATTERN_ELEMENT.getKey().equals(key)) {
            result = new PatternItemEditorInput(repNode);
            TDQPatternItem patternItem = (TDQPatternItem) item;
            if (patternItem.getPattern() == null || patternItem.getPattern().eResource() == null) {
                throw ExceptionFactory.getInstance().createBusinessException(patternItem.getFilename());
            }
            editorID = PatternEditor.class.getName();
        } else if (ERepositoryObjectType.TDQ_REPORT_ELEMENT.getKey().equals(key)) {
            result = new ReportItemEditorInput(repNode);
            TDQReportItem reportItem = (TDQReportItem) item;
            if (!(reportItem.getReport() instanceof TdReport)) {
                throw ExceptionFactory.getInstance().createBusinessException(reportItem.getFilename());
            }
            for (AnalysisMap anaMap : ((TdReport) reportItem.getReport()).getAnalysisMap()) {
                Analysis analysis = anaMap.getAnalysis();
                if (analysis.eResource() == null) {
                    throw ExceptionFactory.getInstance().createBusinessException(reportItem.getFilename());
                }
            }
            // $NON-NLS-1$
            editorID = "org.talend.dataprofiler.core.tdq.ui.editor.report.ReportEditror";
        } else if (ERepositoryObjectType.TDQ_SOURCE_FILE_ELEMENT.getKey().equals(key) || ERepositoryObjectType.TDQ_JRAXML_ELEMENT.getKey().equals(key)) {
            IPath append = WorkbenchUtils.getFilePath(repViewObj.getRepositoryNode());
            DQRepositoryNode node = (DQRepositoryNode) repViewObj.getRepositoryNode();
            file = ResourceManager.getRoot().getProject(node.getProject().getTechnicalLabel()).getFile(append);
            if (!file.exists()) {
                throw ExceptionFactory.getInstance().createBusinessException(repViewObj);
            }
            if (ERepositoryObjectType.TDQ_SOURCE_FILE_ELEMENT.getKey().equals(key)) {
                editorID = SqlExplorerUtils.SQLEDITOR_ID;
            } else {
                editorID = TDQFileEditorInput.DEFAULT_EDITOR_ID;
            }
            result = new TDQFileEditorInput(file);
            // Added TDQ-7143 yyin 20130531
            ((TDQFileEditorInput) result).setFileItem(item);
            CorePlugin.getDefault().refreshDQView(repNode);
        // ~
        }
        // ADD msjian TDQ-4209 2012-2-7 : return the editorInput of *.jrxml and *.sql files
        if (!isOpenItemEditorAction) {
            if (ERepositoryObjectType.TDQ_JRAXML_ELEMENT.getKey().equals(key) || ERepositoryObjectType.TDQ_SOURCE_FILE_ELEMENT.getKey().equals(key)) {
                // if there don't found the correct ItemEditorInput, try to open it as a File
                result = new FileEditorInput(file);
                editorID = FileEditorInput.class.getName();
            }
        }
    // TDQ-4209~
    }
    return result;
}
Also used : TDQFileItem(org.talend.dataquality.properties.TDQFileItem) ConnectionEditor(org.talend.dataprofiler.core.ui.editor.connection.ConnectionEditor) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Schema(orgomg.cwm.resource.relational.Schema) BusinessRuleItemEditorInput(org.talend.dataprofiler.core.ui.editor.dqrules.BusinessRuleItemEditorInput) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) Item(org.talend.core.model.properties.Item) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) TDQItem(org.talend.core.model.properties.TDQItem) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) TDQFileItem(org.talend.dataquality.properties.TDQFileItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) TdView(org.talend.cwm.relational.TdView) AnalysisMap(org.talend.dataquality.reports.AnalysisMap) TDQFileEditorInput(org.talend.dataprofiler.core.ui.editor.TDQFileEditorInput) AnalysisItemEditorInput(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisItemEditorInput) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) ReportItemEditorInput(org.talend.dataprofiler.core.ui.editor.report.ReportItemEditorInput) ConnectionItemEditorInput(org.talend.dataprofiler.core.ui.editor.connection.ConnectionItemEditorInput) TdTable(org.talend.cwm.relational.TdTable) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IPath(org.eclipse.core.runtime.IPath) TdReport(org.talend.dataquality.reports.TdReport) Connection(org.talend.core.model.metadata.builder.connection.Connection) PatternItemEditorInput(org.talend.dataprofiler.core.ui.editor.pattern.PatternItemEditorInput) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RecycleBinRepNode(org.talend.dq.nodes.RecycleBinRepNode) Catalog(orgomg.cwm.resource.relational.Catalog) EList(org.eclipse.emf.common.util.EList) TdColumn(org.talend.cwm.relational.TdColumn) PatternEditor(org.talend.dataprofiler.core.ui.editor.pattern.PatternEditor) Analysis(org.talend.dataquality.analysis.Analysis) IndicatorEditor(org.talend.dataprofiler.core.ui.editor.indicator.IndicatorEditor) TDQFileEditorInput(org.talend.dataprofiler.core.ui.editor.TDQFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TDQItem(org.talend.core.model.properties.TDQItem) IndicatorDefinitionItemEditorInput(org.talend.dataprofiler.core.ui.editor.indicator.IndicatorDefinitionItemEditorInput) IEditorInput(org.eclipse.ui.IEditorInput)

Example 7 with AnalysisItemEditorInput

use of org.talend.dataprofiler.core.ui.editor.analysis.AnalysisItemEditorInput in project tdq-studio-se by Talend.

the class RunAnalysisAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.cheatsheets.ICheatSheetAction#run(java.lang.String[], org.eclipse.ui.cheatsheets.ICheatSheetManager)
     */
public void run(String[] params, ICheatSheetManager manager) {
    // ADD mzhao 2009-02-03 If there is no active editor opened, run
    // analysis action from cheat sheets will do nothing.
    IEditorPart activateEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activateEditor == null || !(activateEditor instanceof AnalysisEditor)) {
        return;
    }
    // MOD TDQ-8117 20131008 yyin: find the analysis item from the editor
    IEditorInput editorInput = activateEditor.getEditorInput();
    if (editorInput instanceof AnalysisItemEditorInput) {
        setAnalysisItems(new TDQAnalysisItem[] { ((TDQAnalysisItem) ((AnalysisItemEditorInput) editorInput).getItem()) });
    }
    AbstractAnalysisMetadataPage masterPage = ((AnalysisEditor) activateEditor).getMasterPage();
    listener = masterPage;
    // ~
    run();
}
Also used : AbstractAnalysisMetadataPage(org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage) IEditorPart(org.eclipse.ui.IEditorPart) AnalysisItemEditorInput(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisItemEditorInput) AnalysisEditor(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisEditor) IEditorInput(org.eclipse.ui.IEditorInput) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Example 8 with AnalysisItemEditorInput

use of org.talend.dataprofiler.core.ui.editor.analysis.AnalysisItemEditorInput in project tdq-studio-se by Talend.

the class CreateDuplicatesAnalysisAction method run.

@Override
public void run() {
    ReturnCode success = new ReturnCode(true);
    if (this.getColumnsMap() == null || this.getColumnsMap().isEmpty() || this.getConnection() == null) {
        return;
    }
    try {
        Set<ColumnSet> keySet = this.getColumnsMap().keySet();
        for (ColumnSet cs : keySet) {
            List<TdColumn> columns = this.getColumnsMap().get(cs);
            // create the analysis
            Analysis analysis = null;
            AnalysisBuilder analysisBuilder = new AnalysisBuilder();
            boolean analysisInitialized = analysisBuilder.initializeAnalysis(getAnalysisName(cs), AnalysisType.MULTIPLE_COLUMN);
            if (analysisInitialized) {
                analysis = analysisBuilder.getAnalysis();
            }
            fillMetadataToAnalysis(analysis, createDefaultAnalysisParameter(cs));
            // add Connection into the Analysis Context
            analysis.getContext().setConnection(this.getConnection());
            for (TdColumn theColumn : columns) {
                // add TdColumn into the Analysis Context
                analysis.getContext().getAnalysedElements().add(theColumn);
                // create Row Count Indicator
                RowCountIndicator rcIndicator = IndicatorsFactory.eINSTANCE.createRowCountIndicator();
                rcIndicator.setAnalyzedElement(theColumn);
                DefinitionHandler.getInstance().setDefaultIndicatorDefinition(rcIndicator);
                analysis.getResults().getIndicators().add(rcIndicator);
                // create Duplicate Count Indicator
                DuplicateCountIndicator dcIndicator = IndicatorsFactory.eINSTANCE.createDuplicateCountIndicator();
                dcIndicator.setAnalyzedElement(theColumn);
                DefinitionHandler.getInstance().setDefaultIndicatorDefinition(dcIndicator);
                analysis.getResults().getIndicators().add(dcIndicator);
            }
            // create dependencies
            DependenciesHandler.getInstance().setDependencyOn(analysis, this.getConnection());
            // set the domain
            for (Domain domain : analysis.getParameters().getDataFilter()) {
                domain.setName(analysis.getName());
            }
            // set execution language
            analysis.getParameters().setExecutionLanguage(ExecutionLanguage.SQL);
            // save the analysis
            RepositoryNode analysisRepNode = (RepositoryNode) RepositoryNodeHelper.getDataProfilingFolderNode(EResourceConstant.ANALYSIS);
            IFolder folder = WorkbenchUtils.getFolder(analysisRepNode);
            AnalysisWriter analysisWriter = ElementWriterFactory.getInstance().createAnalysisWrite();
            TypedReturnCode<Object> create = analysisWriter.create(analysis, folder);
            if (create.isOk()) {
                // refresh the RepositoryView
                CorePlugin.getDefault().refreshDQView(analysisRepNode);
                // open the editor
                AnalysisRepNode anaRepNode = RepositoryNodeHelper.recursiveFindAnalysis(analysis);
                AnalysisItemEditorInput analysisEditorInput = new AnalysisItemEditorInput(anaRepNode);
                IRepositoryNode connectionRepNode = RepositoryNodeHelper.recursiveFind(this.getConnection());
                analysisEditorInput.setConnectionNode(connectionRepNode);
                CorePlugin.getDefault().openEditor(analysisEditorInput, AnalysisEditor.class.getName());
            } else {
                success.setOk(false);
                success.setMessage(create.getMessage());
            }
        }
    // for
    } catch (Exception e) {
        success.setOk(false);
        success.setMessage(e.getMessage());
    }
    if (!success.isOk()) {
        MessageUI.openError(success.getMessage());
    }
}
Also used : DuplicateCountIndicator(org.talend.dataquality.indicators.DuplicateCountIndicator) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) TdColumn(org.talend.cwm.relational.TdColumn) AnalysisRepNode(org.talend.dq.nodes.AnalysisRepNode) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisBuilder(org.talend.dq.analysis.AnalysisBuilder) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) AnalysisItemEditorInput(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisItemEditorInput) Domain(org.talend.dataquality.domain.Domain) AnalysisEditor(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisEditor) AnalysisWriter(org.talend.dq.writer.impl.AnalysisWriter) IFolder(org.eclipse.core.resources.IFolder)

Example 9 with AnalysisItemEditorInput

use of org.talend.dataprofiler.core.ui.editor.analysis.AnalysisItemEditorInput in project tdq-studio-se by Talend.

the class FunctionDependencyWizard method openEditor.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.dataprofiler.core.ui.wizard.analysis.AbstractAnalysisWizard#openEditor(org.talend.repository.model.IRepositoryNode
     * )
     */
@Override
public void openEditor(IRepositoryNode repNode) {
    AnalysisItemEditorInput itemEditorInput = new AnalysisItemEditorInput(repNode);
    CorePlugin.getDefault().openEditor(itemEditorInput, AnalysisEditor.class.getName());
}
Also used : AnalysisItemEditorInput(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisItemEditorInput) AnalysisEditor(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisEditor)

Aggregations

AnalysisItemEditorInput (org.talend.dataprofiler.core.ui.editor.analysis.AnalysisItemEditorInput)9 AnalysisEditor (org.talend.dataprofiler.core.ui.editor.analysis.AnalysisEditor)6 Analysis (org.talend.dataquality.analysis.Analysis)4 IEditorInput (org.eclipse.ui.IEditorInput)3 IRepositoryNode (org.talend.repository.model.IRepositoryNode)3 IEditorPart (org.eclipse.ui.IEditorPart)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 TdColumn (org.talend.cwm.relational.TdColumn)2 ReportItemEditorInput (org.talend.dataprofiler.core.ui.editor.report.ReportItemEditorInput)2 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)2 RepositoryNode (org.talend.repository.model.RepositoryNode)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IFolder (org.eclipse.core.resources.IFolder)1 IPath (org.eclipse.core.runtime.IPath)1 EList (org.eclipse.emf.common.util.EList)1 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 DropTarget (org.eclipse.swt.dnd.DropTarget)1 DropTargetAdapter (org.eclipse.swt.dnd.DropTargetAdapter)1