Search in sources :

Example 1 with OpenItemEditorAction

use of org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction in project tdq-studio-se by Talend.

the class DQEditorLinkHelper method activateEditor.

public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
    IRepositoryNode repNode = (IRepositoryNode) aSelection.getFirstElement();
    OpenItemEditorAction openEditorAction = new OpenItemEditorAction(new IRepositoryNode[] { repNode });
    // MOD msjian TDQ-4209 2012-2-7 : modify to IEditorInput type
    try {
        IEditorInput absEditorInput = openEditorAction.computeEditorInput(repNode, false);
        if (absEditorInput != null) {
            aPage.bringToTop(aPage.findEditor(absEditorInput));
        }
    } catch (BusinessException e) {
        ExceptionHandler.process(e, Level.FATAL);
    }
// TDQ-4209~
}
Also used : BusinessException(org.talend.commons.exception.BusinessException) IRepositoryNode(org.talend.repository.model.IRepositoryNode) OpenItemEditorAction(org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction) IEditorInput(org.eclipse.ui.IEditorInput)

Example 2 with OpenItemEditorAction

use of org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction in project tdq-studio-se by Talend.

the class OpenItemEditorProvider method fillContextMenu.

@Override
public void fillContextMenu(IMenuManager menu) {
    if (!isSelectionSameType()) {
        return;
    }
    Object[] array = ((TreeSelection) this.getContext().getSelection()).toArray();
    List<IRepositoryNode> selectedItemsList = new ArrayList<IRepositoryNode>();
    for (Object obj : array) {
        if (obj instanceof IRepositoryNode) {
            IRepositoryNode node = (IRepositoryNode) obj;
            if (RepositoryNodeHelper.canOpenEditor(node) && !(node instanceof ReportRepNode)) {
                selectedItemsList.add((IRepositoryNode) obj);
            }
        }
    }
    if (!selectedItemsList.isEmpty()) {
        menu.add(new OpenItemEditorAction(selectedItemsList.toArray(new IRepositoryNode[selectedItemsList.size()])));
    }
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) ReportRepNode(org.talend.dq.nodes.ReportRepNode) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ArrayList(java.util.ArrayList) OpenItemEditorAction(org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction)

Example 3 with OpenItemEditorAction

use of org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction in project tdq-studio-se by Talend.

the class UDIUtils method createIndicatorUnit.

public static IndicatorUnit[] createIndicatorUnit(IndicatorDefinition udid, ModelElementIndicator meIndicator, Analysis analysis) throws Throwable {
    List<IndicatorUnit> addIndicatorUnits = new ArrayList<IndicatorUnit>();
    // can't add the same user defined indicator
    for (Indicator indicator : meIndicator.getIndicators()) {
        // MOD xwang 2011-08-01 bug TDQ-2730
        if (udid.getName().equals(indicator.getName()) && indicator instanceof UserDefIndicator) {
            // $NON-NLS-1$
            MessageUI.openWarning(DefaultMessagesImpl.getString("UDIUtils.UDISelected", udid.getName()));
            return null;
        }
    }
    Indicator udi = UDIFactory.createUserDefIndicator(udid);
    udi.setIndicatorDefinition(udid);
    // MOD mzhao feature 11128, Handle Java User Defined Indicator.
    Indicator judi = UDIHelper.adaptToJavaUDI(udi);
    if (judi != null) {
        udi = judi;
    }
    IEditorPart activeEditor = CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor == null || !(activeEditor instanceof AnalysisEditor)) {
        return null;
    }
    ExecutionLanguage executionLanguage = ((AnalysisEditor) activeEditor).getUIExecuteEngin();
    boolean isJavaEngin = ExecutionLanguage.JAVA.equals(executionLanguage);
    DbmsLanguage dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(analysis, executionLanguage);
    Expression returnExpression = dbmsLanguage.getExpression(udi);
    String executeType = isJavaEngin ? executionLanguage.getName() : dbmsLanguage.getDbmsName();
    // MOD qiongli 2013.5.22 TDQ-7282.if don't find a valid java expression for JUDI,should also pop this dialog.
    boolean finddExpression = true;
    if (isJavaEngin && judi == null || !isJavaEngin && returnExpression == null) {
        finddExpression = false;
    }
    if (!finddExpression) {
        // open the editor
        boolean openUDI = MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DefaultMessagesImpl.getString("PatternUtilities.Warning"), // $NON-NLS-1$ //$NON-NLS-2$
        DefaultMessagesImpl.getString("UDIUtils.NoExpression", executeType));
        if (openUDI) {
            RepositoryNode node = RepositoryNodeHelper.recursiveFind(udid);
            if (RepositoryNodeHelper.canOpenEditor(node)) {
                new OpenItemEditorAction(new IRepositoryNode[] { node }).run();
            }
        }
        return null;
    }
    // dbmsLanguage
    IndicatorParameters parameters = udi.getParameters();
    if (parameters == null) {
        parameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
        udi.setParameters(parameters);
    }
    Domain indicatorValidDomain = parameters.getIndicatorValidDomain();
    if (indicatorValidDomain == null) {
        // $NON-NLS-1$
        indicatorValidDomain = DomainHelper.createDomain("JAVA_UDI_PARAMETERS");
        parameters.setIndicatorValidDomain(indicatorValidDomain);
    }
    List<IndicatorDefinitionParameter> indicatorDefs = udid.getIndicatorDefinitionParameter();
    for (IndicatorDefinitionParameter idp : indicatorDefs) {
        JavaUDIIndicatorParameter judip = DomainHelper.createJavaUDIIndicatorParameter(idp.getKey(), idp.getValue());
        indicatorValidDomain.getJavaUDIIndicatorParameter().add(judip);
    }
    IndicatorEnum indicatorType = IndicatorEnum.findIndicatorEnum(udi.eClass());
    addIndicatorUnits.add(meIndicator.addSpecialIndicator(indicatorType, udi));
    DependenciesHandler.getInstance().setUsageDependencyOn(analysis, udid);
    return addIndicatorUnits.toArray(new IndicatorUnit[addIndicatorUnits.size()]);
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) IndicatorEnum(org.talend.dq.nodes.indicator.type.IndicatorEnum) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) ArrayList(java.util.ArrayList) JavaUDIIndicatorParameter(org.talend.dataquality.domain.JavaUDIIndicatorParameter) ExecutionLanguage(org.talend.dataquality.analysis.ExecutionLanguage) IEditorPart(org.eclipse.ui.IEditorPart) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) OpenItemEditorAction(org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Indicator(org.talend.dataquality.indicators.Indicator) DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) TdExpression(org.talend.cwm.relational.TdExpression) Expression(orgomg.cwm.objectmodel.core.Expression) IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter) AnalysisEditor(org.talend.dataprofiler.core.ui.editor.analysis.AnalysisEditor) Domain(org.talend.dataquality.domain.Domain) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator)

Example 4 with OpenItemEditorAction

use of org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction in project tdq-studio-se by Talend.

the class WorkbenchUtils method closeAndOpenEditor.

/**
 * close and open the editors same method {@link CorePlugin}.getDefault().itemIsOpening() MOD TDQ-8360 20140410
 * yyin: will only operate the analysis who is related and has opened (by its observer --added when opening)
 *
 * @param iEditorReference
 */
private static void closeAndOpenEditor(List<IEditorReference> iEditorReference) {
    // Refresh current opened editors.
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IWorkbenchPartReference activePartReference = activePage.getActivePartReference();
    // MOD qiongli 2011-9-8 TDQ-3317.when focucs on DI perspective,don't refresh the open editors
    DQRespositoryView findView = (DQRespositoryView) activePage.findView(DQRespositoryView.ID);
    if (findView == null) {
        return;
    }
    if (iEditorReference.size() > 0) {
        try {
            for (IEditorReference editorRef : iEditorReference) {
                IEditorInput editorInput = editorRef.getEditorInput();
                if (editorInput instanceof AbstractItemEditorInput) {
                    AbstractItemEditorInput anaItemEditorInput = (AbstractItemEditorInput) editorInput;
                    // close the editor
                    activePage.closeEditor(editorRef.getEditor(false), false);
                    // reopen the analysis
                    new OpenItemEditorAction(new IRepositoryNode[] { anaItemEditorInput.getRepNode() }).run();
                }
            }
        } catch (PartInitException e) {
            log.error(e);
        }
    }
    activePage.activate(activePartReference.getPart(false));
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) AbstractItemEditorInput(org.talend.dataprofiler.core.ui.editor.AbstractItemEditorInput) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) OpenItemEditorAction(org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction) DQRespositoryView(org.talend.dataprofiler.core.ui.views.DQRespositoryView) IEditorInput(org.eclipse.ui.IEditorInput)

Example 5 with OpenItemEditorAction

use of org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction in project tdq-studio-se by Talend.

the class DQRespositoryView method createPartControl.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.navigator.CommonNavigator#createPartControl(org.eclipse .swt.widgets.Composite)
     */
@Override
public void createPartControl(Composite parent) {
    parent.setLayout(new BorderLayout());
    Composite topComp = new Composite(parent, SWT.NONE);
    topComp.setFont(parent.getFont());
    topComp.setLayoutData(BorderLayout.NORTH);
    Composite bottomComp = new Composite(parent, SWT.NONE);
    bottomComp.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    bottomComp.setFont(parent.getFont());
    bottomComp.setLayoutData(BorderLayout.CENTER);
    topComp.setLayout(new BorderLayout());
    FillLayout bottomLayout = new FillLayout(SWT.VERTICAL);
    bottomComp.setLayout(bottomLayout);
    createTreeFilter(topComp);
    super.createPartControl(bottomComp);
    // For removing the popup menu of DQRepositoryView.
    // $NON-NLS-1$
    MenuManager menuMgr = new MenuManager("org.talend.dataprofiler.core.ui.views.DQRespositoryView");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager menuManager) {
            ISelection selection = getCommonViewer().getSelection();
            getNavigatorActionService().setContext(new ActionContext(selection));
            getNavigatorActionService().fillContextMenu(menuManager);
        }
    });
    Menu menu = menuMgr.createContextMenu(getCommonViewer().getTree());
    getCommonViewer().getTree().setMenu(menu);
    this.addViewerFilter(EMFObjFilter.FILTER_ID);
    this.addViewerFilter(ReportingFilter.FILTER_ID);
    this.addViewerFilter(FolderObjFilter.FILTER_ID);
    adjustFilter();
    activateContext();
    getCommonViewer().setSorter(null);
    getCommonViewer().getTree().addTreeListener(new TreeAdapter() {

        @Override
        public void treeExpanded(TreeEvent e) {
            TreeItem item = (TreeItem) e.item;
            if (!item.getText().endsWith(")")) {
                // $NON-NLS-1$
                Object obj = item.getData();
                if (obj instanceof TableFolderNode || obj instanceof ViewFolderNode || obj instanceof ColumnFolderNode) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    item.setText(item.getText() + "(" + item.getItemCount() + ")");
                }
            }
            super.treeExpanded(e);
        }
    });
    getCommonViewer().getTree().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            boolean superDoubleClick = true;
            Tree tree = (Tree) e.getSource();
            Point point = new Point(e.x, e.y);
            final TreeItem item = tree.getItem(point);
            if (item != null) {
                Object obj = item.getData();
                if (obj instanceof AbstractFolderNode) {
                    AbstractFolderNode node = (AbstractFolderNode) obj;
                    node.loadChildren();
                    Object[] children = node.getChildren();
                    if (children != null) {
                        if (item.getText().indexOf("(") > 0) {
                            // $NON-NLS-1$
                            item.setText(// $NON-NLS-1$ //$NON-NLS-2$
                            item.getText().substring(0, item.getText().indexOf("(")) + "(" + children.length + // $NON-NLS-1$
                            ")");
                        } else {
                            // $NON-NLS-1$ //$NON-NLS-2$
                            item.setText(item.getText() + "(" + children.length + ")");
                        }
                    }
                }
                if (obj instanceof IndicatorDefinition) {
                    IndicatorDefinition indicatorDefinition = (IndicatorDefinition) obj;
                    // reload object
                    indicatorDefinition = DefinitionHandler.getInstance().getIndicatorDefinition(indicatorDefinition.getLabel());
                    IndicatorEditorInput input = new IndicatorEditorInput(indicatorDefinition);
                    try {
                        CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, IndicatorEditor.class.getName());
                    } catch (PartInitException e1) {
                        log.error(e1, e1);
                    }
                }
                if (obj instanceof DQRepositoryNode) {
                    if (obj instanceof ReportFileRepNode) {
                        new OpenItemEditorAction(new IRepositoryNode[] { (IRepositoryNode) obj }).run();
                    } else if (obj instanceof DFConnectionRepNode) {
                        new EditFileDelimitedAction((IRepositoryNode) obj).run();
                    } else if (obj instanceof HadoopClusterConnectionRepNode && HadoopClusterUtils.getDefault().isServiceInstalled()) {
                        new EditHadoopClusterAction((IRepositoryNode) obj).run();
                    } else if (obj instanceof HDFSOfHCConnectionNode && HadoopClusterUtils.getDefault().isServiceInstalled()) {
                        new EditHDFSConnectionAction((IRepositoryNode) obj).run();
                    } else if (obj instanceof DFTableRepNode) {
                        new EditDFTableAction((IRepositoryNode) obj).run();
                    } else if (obj instanceof ContextRepNode) {
                        new DQEditContextAction((ContextRepNode) obj, false).run();
                    } else {
                        DQRepositoryNode repoNode = (DQRepositoryNode) obj;
                        if (RepositoryNodeHelper.canOpenEditor(repoNode)) {
                            OpenItemEditorAction openItemEditorAction = new OpenItemEditorAction(new IRepositoryNode[] { repoNode });
                            openItemEditorAction.run();
                        }
                        if (repoNode instanceof AnalysisRepNode || repoNode instanceof ReportRepNode || repoNode instanceof SysIndicatorDefinitionRepNode || repoNode instanceof PatternRepNode || repoNode instanceof RuleRepNode) {
                            superDoubleClick = false;
                        }
                    }
                }
            }
            if (superDoubleClick) {
                super.mouseDoubleClick(e);
            }
        }
    });
    getCommonViewer().getTree().addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
                Tree tree = (Tree) e.getSource();
                TreeItem[] selection = tree.getSelection();
                for (TreeItem item : selection) {
                    Object data = item.getData();
                    DQRepositoryNode repoNode = (DQRepositoryNode) data;
                    if (RepositoryNodeHelper.canOpenEditor(repoNode)) {
                        OpenItemEditorAction openItemEditorAction = new OpenItemEditorAction(new IRepositoryNode[] { repoNode });
                        openItemEditorAction.run();
                    }
                }
            }
        }

        public void keyReleased(KeyEvent e) {
        // do nothing here until now
        }
    });
    // ~ADD mzhao for feature 6233 Load columns when selecting a table (or
    // view) in DQ Repository view
    getCommonViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            TreeSelection selection = (TreeSelection) event.getSelection();
            Iterator<?> iterator = selection.iterator();
            while (iterator.hasNext()) {
                Object selectedElement = iterator.next();
                if (selectedElement instanceof DBTableRepNode || selectedElement instanceof DBViewRepNode) {
                    ((RepositoryNode) selectedElement).getChildren().get(0).getChildren();
                }
            }
        }
    });
    // MOD mzhao 2011-03-10 bug 19147: filter MDM entries.
    getCommonViewer().addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof IProject) {
                return false;
            }
            return true;
        }
    });
// ~
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) HDFSOfHCConnectionNode(org.talend.dq.nodes.hadoopcluster.HDFSOfHCConnectionNode) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) Viewer(org.eclipse.jface.viewers.Viewer) TreeAdapter(org.eclipse.swt.events.TreeAdapter) TableFolderNode(org.talend.dataprofiler.core.model.nodes.foldernode.TableFolderNode) TreeEvent(org.eclipse.swt.events.TreeEvent) IndicatorEditorInput(org.talend.dataprofiler.core.ui.editor.indicator.IndicatorEditorInput) ReportFileRepNode(org.talend.dq.nodes.ReportFileRepNode) BorderLayout(org.talend.dataprofiler.core.ui.views.layout.BorderLayout) ReportRepNode(org.talend.dq.nodes.ReportRepNode) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Tree(org.eclipse.swt.widgets.Tree) PatternRepNode(org.talend.dq.nodes.PatternRepNode) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FillLayout(org.eclipse.swt.layout.FillLayout) OpenItemEditorAction(org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction) ViewFolderNode(org.talend.dataprofiler.core.model.nodes.foldernode.ViewFolderNode) DQEditContextAction(org.talend.dataprofiler.core.ui.action.actions.DQEditContextAction) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) ColumnFolderNode(org.talend.dataprofiler.core.model.nodes.foldernode.ColumnFolderNode) EditDFTableAction(org.talend.dataprofiler.core.ui.action.actions.EditDFTableAction) AbstractViewerFilter(org.talend.dataprofiler.core.ui.filters.AbstractViewerFilter) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) AbstractFolderNode(org.talend.dq.nodes.foldernode.AbstractFolderNode) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) KeyEvent(org.eclipse.swt.events.KeyEvent) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) ISelection(org.eclipse.jface.viewers.ISelection) EditHDFSConnectionAction(org.talend.dataprofiler.core.ui.action.actions.EditHDFSConnectionAction) SysIndicatorDefinitionRepNode(org.talend.dq.nodes.SysIndicatorDefinitionRepNode) Iterator(java.util.Iterator) DFTableRepNode(org.talend.dq.nodes.DFTableRepNode) Menu(org.eclipse.swt.widgets.Menu) PartInitException(org.eclipse.ui.PartInitException) DBViewRepNode(org.talend.dq.nodes.DBViewRepNode) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) IRepositoryNode(org.talend.repository.model.IRepositoryNode) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.eclipse.swt.graphics.Point) ActionContext(org.eclipse.ui.actions.ActionContext) RuleRepNode(org.talend.dq.nodes.RuleRepNode) IMenuListener(org.eclipse.jface.action.IMenuListener) IProject(org.eclipse.core.resources.IProject) EditFileDelimitedAction(org.talend.dataprofiler.core.ui.action.actions.EditFileDelimitedAction) DBTableRepNode(org.talend.dq.nodes.DBTableRepNode) AnalysisRepNode(org.talend.dq.nodes.AnalysisRepNode) DFConnectionRepNode(org.talend.dq.nodes.DFConnectionRepNode) EditHadoopClusterAction(org.talend.dataprofiler.core.ui.action.actions.EditHadoopClusterAction) KeyListener(org.eclipse.swt.events.KeyListener) IMenuManager(org.eclipse.jface.action.IMenuManager) HadoopClusterConnectionRepNode(org.talend.dq.nodes.hadoopcluster.HadoopClusterConnectionRepNode) ContextRepNode(org.talend.dq.nodes.ContextRepNode)

Aggregations

OpenItemEditorAction (org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction)6 IRepositoryNode (org.talend.repository.model.IRepositoryNode)6 ArrayList (java.util.ArrayList)2 TreeSelection (org.eclipse.jface.viewers.TreeSelection)2 IEditorInput (org.eclipse.ui.IEditorInput)2 IEditorPart (org.eclipse.ui.IEditorPart)2 PartInitException (org.eclipse.ui.PartInitException)2 ModelElementIndicator (org.talend.dataprofiler.core.model.ModelElementIndicator)2 Iterator (java.util.Iterator)1 IProject (org.eclipse.core.resources.IProject)1 IMenuListener (org.eclipse.jface.action.IMenuListener)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 ColumnViewer (org.eclipse.jface.viewers.ColumnViewer)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1