Search in sources :

Example 1 with SemanticDiscoveryAction

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

the class SemanticDiscoveryActionProviderTest method testFillContextMenuIMenuManager.

/**
 * Test method for {@link org.talend.dataprofiler.core.ui.action.provider.SemanticDiscoveryActionProvider#fillContextMenu(org.eclipse.jface.action.IMenuManager)}.
 */
@Test
public void testFillContextMenuIMenuManager() {
    SemanticDiscoveryActionProvider semanticDiscoveryActionProvider = new SemanticDiscoveryActionProvider();
    IRepositoryNode createNewColumnRepNode = createNewColumnRepNode();
    TreePath treePath = new TreePath(new IRepositoryNode[] { createNewColumnRepNode });
    TreeSelection treeSelection = new TreeSelection(new TreePath[] { treePath });
    semanticDiscoveryActionProvider.setContext(new ActionContext(treeSelection));
    MenuManager menuManager = new MenuManager();
    semanticDiscoveryActionProvider.fillContextMenu(menuManager);
    Assert.assertEquals(1, menuManager.getSize());
    // $NON-NLS-1$
    Assert.assertTrue(// $NON-NLS-1$
    "Current action must be SemanticDiscoveryAction", ((ActionContributionItem) menuManager.getItems()[0]).getAction() instanceof SemanticDiscoveryAction);
}
Also used : ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) IRepositoryNode(org.talend.repository.model.IRepositoryNode) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) MenuManager(org.eclipse.jface.action.MenuManager) ActionContext(org.eclipse.ui.actions.ActionContext) SemanticDiscoveryAction(org.talend.dataprofiler.core.ui.action.actions.predefined.SemanticDiscoveryAction) Test(org.junit.Test)

Example 2 with SemanticDiscoveryAction

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

the class SemanticDiscoveryActionProvider method fillContextMenu.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
     */
@Override
public void fillContextMenu(IMenuManager menu) {
    // MOD mzhao user readonly role on svn repository mode.
    if (!isShowMenu()) {
        return;
    }
    TreeSelection currentSelection = ((TreeSelection) this.getContext().getSelection());
    Object firstElement = currentSelection.getFirstElement();
    boolean selectedMoreThanOne = currentSelection.size() > 1;
    // keep all of columns belong to same one table and create SemanticDiscoveryAction.
    if (selectedMoreThanOne || firstElement instanceof ColumnRepNode) {
        Set<String> currentTableSet = new HashSet<String>();
        MetadataTable createTable = ConnectionFactory.eINSTANCE.createMetadataTable();
        List<String> filterNames = new ArrayList<String>();
        Iterator<Object> columnIterator = currentSelection.iterator();
        while (columnIterator.hasNext()) {
            Object columnNode = columnIterator.next();
            MetadataColumn metadataColumn = null;
            if (DBColumnRepNode.class.isInstance(columnNode)) {
                metadataColumn = ((DBColumnRepNode) columnNode).getTdColumn();
                createTable = ColumnHelper.getColumnOwnerAsMetadataTable(metadataColumn);
            } else if (DFColumnRepNode.class.isInstance(columnNode)) {
                metadataColumn = ((DFColumnRepNode) columnNode).getMetadataColumn();
                createTable = ColumnHelper.getColumnOwnerAsMetadataTable(metadataColumn);
            } else {
                // If not all of elements which be selected is columns
                return;
            }
            currentTableSet.add(ResourceHelper.getUUID(createTable));
            // all of columns should come from same table
            if (currentTableSet.size() > 1) {
                return;
            }
            filterNames.add(metadataColumn.getName());
        }
        MetadataTable metadataTableWithFilter = new MetadataTableWithFilter(filterNames, createTable);
        semanticDiscoveryAction = new SemanticDiscoveryAction(metadataTableWithFilter);
    } else {
        // otherwise the selection is valid, only two possible status: only one columnset is select.
        if (firstElement instanceof DBTableRepNode) {
            DBTableRepNode node = (DBTableRepNode) firstElement;
            semanticDiscoveryAction = new SemanticDiscoveryAction(node.getTdTable());
        } else if (firstElement instanceof DBViewRepNode) {
            DBViewRepNode node = (DBViewRepNode) firstElement;
            semanticDiscoveryAction = new SemanticDiscoveryAction(node.getTdView());
        } else if (firstElement instanceof DFTableRepNode) {
            DFTableRepNode node = (DFTableRepNode) firstElement;
            semanticDiscoveryAction = new SemanticDiscoveryAction(node.getMetadataTable());
        }
    }
    menu.add(semanticDiscoveryAction);
}
Also used : DFColumnRepNode(org.talend.dq.nodes.DFColumnRepNode) ColumnRepNode(org.talend.dq.nodes.ColumnRepNode) DBColumnRepNode(org.talend.dq.nodes.DBColumnRepNode) ArrayList(java.util.ArrayList) SemanticDiscoveryAction(org.talend.dataprofiler.core.ui.action.actions.predefined.SemanticDiscoveryAction) DFColumnRepNode(org.talend.dq.nodes.DFColumnRepNode) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) DBTableRepNode(org.talend.dq.nodes.DBTableRepNode) TreeSelection(org.eclipse.jface.viewers.TreeSelection) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) DFTableRepNode(org.talend.dq.nodes.DFTableRepNode) DBViewRepNode(org.talend.dq.nodes.DBViewRepNode) MetadataTableWithFilter(org.talend.dataprofiler.core.model.MetadataTableWithFilter) HashSet(java.util.HashSet)

Aggregations

TreeSelection (org.eclipse.jface.viewers.TreeSelection)2 SemanticDiscoveryAction (org.talend.dataprofiler.core.ui.action.actions.predefined.SemanticDiscoveryAction)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)1 MenuManager (org.eclipse.jface.action.MenuManager)1 TreePath (org.eclipse.jface.viewers.TreePath)1 ActionContext (org.eclipse.ui.actions.ActionContext)1 Test (org.junit.Test)1 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)1 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)1 MetadataTableWithFilter (org.talend.dataprofiler.core.model.MetadataTableWithFilter)1 ColumnRepNode (org.talend.dq.nodes.ColumnRepNode)1 DBColumnRepNode (org.talend.dq.nodes.DBColumnRepNode)1 DBTableRepNode (org.talend.dq.nodes.DBTableRepNode)1 DBViewRepNode (org.talend.dq.nodes.DBViewRepNode)1 DFColumnRepNode (org.talend.dq.nodes.DFColumnRepNode)1 DFTableRepNode (org.talend.dq.nodes.DFTableRepNode)1 IRepositoryNode (org.talend.repository.model.IRepositoryNode)1