Search in sources :

Example 1 with IDatabaseJobService

use of org.talend.dataprofiler.core.service.IDatabaseJobService in project tdq-studio-se by Talend.

the class ModelElementTreeMenuProvider method createTreeMenu.

/**
 * DOC qzhang Comment method "createTreeMenu". MOD qiongli bug 16252.Add a param of 'isColumnSetMenu'
 *
 * @param newTree
 * @param containEdit
 */
public void createTreeMenu(boolean isColumnSetMenu) {
    Menu oldMenu = tree.getMenu();
    if (oldMenu != null && !oldMenu.isDisposed()) {
        oldMenu.dispose();
    }
    Menu menu = new Menu(tree);
    if (isSelectedColumn(tree.getSelection())) {
        if (!isMetadataColumnSelected(tree.getSelection())) {
            MenuItem previewMenuItem = new MenuItem(menu, SWT.CASCADE);
            // $NON-NLS-1$
            previewMenuItem.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.previewDQElement"));
            previewMenuItem.setImage(ImageLib.getImage(ImageLib.EXPLORE_IMAGE));
            previewMenuItem.addSelectionListener(new SelectionAdapter() {

                /*
                     * (non-Javadoc)
                     * 
                     * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected (org.eclipse
                     * .swt.events.SelectionEvent)
                     */
                @Override
                public void widgetSelected(SelectionEvent e) {
                    previewSelectedElements(tree);
                }
            });
        }
        if (isColumnSetMenu) {
            MenuItem createColumnAnalysisMenuItem = new MenuItem(menu, SWT.CASCADE);
            // $NON-NLS-1$
            createColumnAnalysisMenuItem.setText(DefaultMessagesImpl.getString("CreateColumnAnalysisAction.columnAnalysis"));
            createColumnAnalysisMenuItem.setImage(ImageLib.getImage(ImageLib.ACTION_NEW_ANALYSIS));
            createColumnAnalysisMenuItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    createColumnAnalysis(tree);
                }
            });
        }
        MenuItem showLocationMenuItem = new MenuItem(menu, SWT.CASCADE);
        // $NON-NLS-1$
        showLocationMenuItem.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.showDQElement"));
        showLocationMenuItem.setImage(ImageLib.getImage(ImageLib.EXPLORE_IMAGE));
        showLocationMenuItem.addSelectionListener(new SelectionAdapter() {

            /*
                 * (non-Javadoc)
                 * 
                 * @seeorg.eclipse.swt.events.SelectionAdapter# widgetSelected(org.eclipse .swt.events.SelectionEvent)
                 */
            @Override
            public void widgetSelected(SelectionEvent e) {
                showSelectedElements(tree);
            }
        });
    }
    if (isSelectedIndicator(tree.getSelection()) && !isMetadataColumnIndicatorSelected(tree.getSelection())) {
        // MOD 2009-01-04 mzhao
        MenuItem showQueryMenuItem = new MenuItem(menu, SWT.CASCADE);
        // $NON-NLS-1$
        showQueryMenuItem.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.viewQuery"));
        showQueryMenuItem.setImage(ImageLib.getImage(ImageLib.EXPLORE_IMAGE));
        showQueryMenuItem.addSelectionListener(new SelectionAdapter() {

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected (org.eclipse .swt.events.SelectionEvent)
                 */
            @Override
            public void widgetSelected(SelectionEvent e) {
                viewQueryForSelectedElement(tree);
            }
        });
    }
    if (isSelectedPatternIndicator(tree.getSelection())) {
        MenuItem editPatternMenuItem = new MenuItem(menu, SWT.CASCADE);
        // $NON-NLS-1$
        editPatternMenuItem.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.editPattern"));
        editPatternMenuItem.setImage(ImageLib.getImage(ImageLib.PATTERN_REG));
        editPatternMenuItem.addSelectionListener(new SelectionAdapter() {

            /*
                 * (non-Javadoc)
                 * 
                 * @seeorg.eclipse.swt.events.SelectionAdapter# widgetSelected(org .eclipse.swt.events.SelectionEvent)
                 */
            @Override
            public void widgetSelected(SelectionEvent e) {
                editPattern(tree);
            }
        });
    }
    // judge to indicator whether is frequency
    if (isSelectedFrequencyIndicator(tree.getSelection()) && PluginChecker.isTDCPLoaded()) {
        MenuItem editPatternMenuItem = new MenuItem(menu, SWT.CASCADE);
        // $NON-NLS-1$
        editPatternMenuItem.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.generateJob"));
        editPatternMenuItem.setImage(ImageLib.getImage(ImageLib.ICON_PROCESS));
        editPatternMenuItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                final IDatabaseJobService service = (IDatabaseJobService) GlobalServiceRegister.getDefault().getService(IJobService.class);
                if (service != null) {
                    service.setIndicator(getSelectedIndicator(tree.getSelection()));
                    IRepositoryNode anaNode = getAnalysis2();
                    Analysis ana;
                    if (anaNode instanceof ReportAnalysisRepNode) {
                        ana = ((ReportAnalysisRepNode) anaNode).getAnalysis();
                    } else {
                        ana = ((AnalysisRepNode) anaNode).getAnalysis();
                    }
                    service.setAnalysis(ana);
                    service.executeJob();
                }
            }
        });
    }
    if (isSelectedUDIndicator(tree.getSelection())) {
        MenuItem editPatternMenuItem = new MenuItem(menu, SWT.CASCADE);
        // $NON-NLS-1$
        editPatternMenuItem.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.editUDIndicator"));
        editPatternMenuItem.setImage(ImageLib.getImage(ImageLib.IND_DEFINITION));
        editPatternMenuItem.addSelectionListener(new SelectionAdapter() {

            /*
                 * (non-Javadoc)
                 * 
                 * @seeorg.eclipse.swt.events.SelectionAdapter# widgetSelected(org .eclipse.swt.events.SelectionEvent)
                 */
            @Override
            public void widgetSelected(SelectionEvent e) {
                editUDIndicator(tree);
            }
        });
    }
    // add common menu to the tree
    MenuItem addTaskItem = new MenuItem(menu, SWT.CASCADE);
    // $NON-NLS-1$
    addTaskItem.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.AddTask"));
    addTaskItem.setImage(ImageLib.getImage(ImageLib.ADD_ACTION));
    addTaskItem.addSelectionListener(new SelectionAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org .eclipse .swt.events.SelectionEvent)
             */
        @Override
        public void widgetSelected(SelectionEvent e) {
            TreeItem[] selection = tree.getSelection();
            if (selection.length > 0) {
                IRepositoryNode ana = getAnalysis2();
                // MOD qiongli 2011-1-12 feature 16796 :handle the case of ModelElement name is null
                (new TdAddTaskAction(tree.getShell(), ana)).run();
            }
        }
    });
    MenuItem deleteMenuItem = new MenuItem(menu, SWT.CASCADE);
    // $NON-NLS-1$
    deleteMenuItem.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.removeElement"));
    deleteMenuItem.setImage(ImageLib.getImage(ImageLib.DELETE_ACTION));
    deleteMenuItem.addSelectionListener(new SelectionAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org .eclipse .swt.events.SelectionEvent)
             */
        @Override
        public void widgetSelected(SelectionEvent e) {
            removeSelectedElements2(tree);
        }
    });
    tree.setMenu(menu);
}
Also used : TdAddTaskAction(org.talend.dataprofiler.core.ui.action.actions.TdAddTaskAction) ReportAnalysisRepNode(org.talend.dq.nodes.ReportAnalysisRepNode) AnalysisRepNode(org.talend.dq.nodes.AnalysisRepNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IDatabaseJobService(org.talend.dataprofiler.core.service.IDatabaseJobService) Analysis(org.talend.dataquality.analysis.Analysis) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) ReportAnalysisRepNode(org.talend.dq.nodes.ReportAnalysisRepNode)

Example 2 with IDatabaseJobService

use of org.talend.dataprofiler.core.service.IDatabaseJobService in project tdq-studio-se by Talend.

the class ChartTableFactory method addJobGenerationMenu.

/**
 * add contextual menu for job generation.
 *
 * @param menu
 * @param analysis
 * @param currentIndicator
 */
public static void addJobGenerationMenu(final Menu menu, final Analysis analysis, final Indicator currentIndicator) {
    Connection tdDataProvider = (Connection) analysis.getContext().getConnection();
    boolean isDelimitedFileAnalysis = ConnectionUtils.isDelimitedFileConnection(tdDataProvider);
    boolean isHiveConnection = ConnectionHelper.isHive(tdDataProvider);
    boolean isVertica = ConnectionHelper.isVertica(tdDataProvider);
    if (PluginChecker.isTDCPLoaded() && !(isDelimitedFileAnalysis || isHiveConnection)) {
        final IDatabaseJobService service = (IDatabaseJobService) GlobalServiceRegister.getDefault().getService(IJobService.class);
        if (service != null) {
            service.setIndicator(currentIndicator);
            service.setAnalysis(analysis);
            MenuItem item = null;
            if (isDUDIndicator(currentIndicator) && AnalysisType.COLUMN_SET != analysis.getParameters().getAnalysisType()) {
                item = new MenuItem(menu, SWT.PUSH);
                // $NON-NLS-1$
                item.setText(DefaultMessagesImpl.getString("ChartTableFactory.RemoveDuplicate"));
            } else if (isPatternMatchingIndicator(currentIndicator) && !isVertica) {
                // TDQ--8864 forbidden the genarate job menu for SQL pattern, remove this after TDQ-8875 is DONE
                if (!isSQLPatternMatchingIndicator(currentIndicator)) {
                    item = new MenuItem(menu, SWT.PUSH);
                    // $NON-NLS-1$
                    item.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.generateJob"));
                }
            } else if (isAllMatchIndicator(currentIndicator)) {
                item = new MenuItem(menu, SWT.PUSH);
                // $NON-NLS-1$
                item.setText(DefaultMessagesImpl.getString("ChartTableFactory.gen_etl_job_row"));
            } else if (isPhonseNumberIndicator(currentIndicator)) {
                item = new MenuItem(menu, SWT.PUSH);
                // $NON-NLS-1$
                item.setText(DefaultMessagesImpl.getString("ChartTableFactory.gen_std_phone_job"));
            } else if (isDqRule(currentIndicator)) {
                item = new MenuItem(menu, SWT.PUSH);
                // $NON-NLS-1$
                item.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.generateJob"));
            }
            if (item != null) {
                item.setImage(ImageLib.getImage(ImageLib.ICON_PROCESS));
                item.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        service.executeJob();
                    }
                });
            }
        }
    }
}
Also used : IDatabaseJobService(org.talend.dataprofiler.core.service.IDatabaseJobService) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) IJobService(org.talend.dataprofiler.core.service.IJobService)

Aggregations

SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2 IDatabaseJobService (org.talend.dataprofiler.core.service.IDatabaseJobService)2 Menu (org.eclipse.swt.widgets.Menu)1 Connection (org.talend.core.model.metadata.builder.connection.Connection)1 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)1 IJobService (org.talend.dataprofiler.core.service.IJobService)1 TdAddTaskAction (org.talend.dataprofiler.core.ui.action.actions.TdAddTaskAction)1 Analysis (org.talend.dataquality.analysis.Analysis)1 AnalysisRepNode (org.talend.dq.nodes.AnalysisRepNode)1 ReportAnalysisRepNode (org.talend.dq.nodes.ReportAnalysisRepNode)1 IRepositoryNode (org.talend.repository.model.IRepositoryNode)1