Search in sources :

Example 41 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class ComponentChooseDialog method createNewComponent.

public void createNewComponent(DropTargetEvent event1) {
    boolean quickCreateInput = event1.detail == DND.DROP_LINK;
    boolean quickCreateOutput = event1.detail == DND.DROP_COPY;
    Iterator iterator = getSelection().iterator();
    List<TempStore> list = new ArrayList<TempStore>();
    List<IComponent> components = new ArrayList<IComponent>();
    while (iterator.hasNext()) {
        Object obj = iterator.next();
        if (obj instanceof RepositoryNode) {
            RepositoryNode sourceNode = (RepositoryNode) obj;
            if (equalsJobInCurrentEditor(sourceNode)) {
                continue;
            }
            Item item = sourceNode.getObject().getProperty().getItem();
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
                ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
                if (testContainerService != null && testContainerService.isTestContainerItem(item)) {
                    continue;
                }
            }
            ERepositoryObjectType type = sourceNode.getObjectType();
            if (!(item instanceof ConnectionItem) && !(item instanceof ProcessItem) && !(item instanceof JobletProcessItem) && !(item instanceof RulesItem) && !(item instanceof LinkRulesItem)) {
                // RulesItem
                return;
            }
            {
            /**
                     * Remove this limitation for feature: TDI-32362, I think it should be ok, don't know why adding
                     * this limitation to forbid to d&d salseforce connection, I keep those code in case this behavior
                     * will cause some bugs when d&d salseforce connection, then maybe need to review
                     */
            // if (item instanceof SalesforceSchemaConnectionItem && type ==
            // ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA) {
            // return;
            // }
            }
            TempStore store = new TempStore();
            store.seletetedNode = sourceNode;
            getAppropriateComponent(item, quickCreateInput, quickCreateOutput, store, type);
            if (store.component != null) {
                list.add(store);
            } else {
                MessageDialog.openInformation(editor.getEditorSite().getShell(), //$NON-NLS-1$
                Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.title"), //$NON-NLS-1$
                Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.content"));
            }
        }
        org.eclipse.swt.graphics.Point swtLocation = new org.eclipse.swt.graphics.Point(event1.x, event1.y);
        Canvas canvas = (Canvas) editor.getViewer().getControl();
        /*
             * translate to Canvas coordinate
             */
        swtLocation = canvas.toControl(swtLocation);
        org.eclipse.swt.graphics.Point size = canvas.getSize();
        /*
             * translate to Viewport coordinate with zoom
             */
        org.eclipse.draw2d.geometry.Point draw2dPosition = new org.eclipse.draw2d.geometry.Point(swtLocation.x, swtLocation.y);
        /*
             * calcule the view port position. Take into acounte the scroll position
             */
        ProcessPart part = (ProcessPart) editor.getViewer().getRootEditPart().getRoot().getChildren().get(0);
        IFigure targetFigure = part.getFigure();
        translateAbsolateToRelative(targetFigure, draw2dPosition);
        //$NON-NLS-1$
        String lastUniqname = "";
        // creates every node
        for (TempStore store : list) {
            RepositoryNode selectedNode = store.seletetedNode;
            IComponent element = store.component;
            if (!components.contains(element)) {
                components.add(element);
            }
            Node node = new Node(element);
            // for bug4564(metadata label format)
            // IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
            // if (preferenceStore.getBoolean(TalendDesignerPrefConstants.USE_REPOSITORY_NAME)) {
            // node.setPropertyValue(EParameterName.LABEL.getName(), selectedNode.getObject().getLabel());
            // }
            IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
            if (preferenceStore.getBoolean(TalendDesignerPrefConstants.USE_REPOSITORY_NAME)) {
                String LabelValue = null;
                RepositoryNode repositoryNode = null;
                repositoryNode = (RepositoryNode) getSelection().getFirstElement();
                // dnd a table
                IElementParameter dbTableParam = node.getElementParameterFromField(EParameterFieldType.DBTABLE);
                boolean hasDbTableField = dbTableParam != null;
                if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE && repositoryNode.getObject() != null && repositoryNode.getObject().getProperty().getItem() instanceof DatabaseConnectionItem && hasDbTableField) {
                    LabelValue = DesignerUtilities.getParameterVar(dbTableParam.getName());
                } else if (repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS || repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS_MR || repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS_STORM) {
                    // dnd a job
                    LabelValue = DesignerUtilities.getParameterVar(EParameterName.PROCESS);
                } else if (repositoryNode.getObjectType() == ERepositoryObjectType.JOBLET || repositoryNode.getObjectType() == ERepositoryObjectType.SPARK_JOBLET || repositoryNode.getObjectType() == ERepositoryObjectType.SPARK_STREAMING_JOBLET) {
                    LabelValue = element.getName();
                } else if (CorePlugin.getDefault().getDesignerCoreService().getPreferenceStore(TalendDesignerPrefConstants.DEFAULT_LABEL).equals(node.getPropertyValue(EParameterName.LABEL.getName()))) {
                    // dnd a default
                    LabelValue = selectedNode.getObject().getLabel();
                }
                if (LabelValue != null) {
                    node.setPropertyValue(EParameterName.LABEL.getName(), LabelValue);
                }
            }
            processSpecificDBTypeIfSameProduct(store.componentName, node);
            NodeContainer nc = ((Process) node.getProcess()).loadNodeContainer(node, false);
            ;
            // create component on link
            boolean executed = false;
            if (getSelection().size() == 1 && getTargetEditPart() instanceof SubjobContainerPart) {
                executed = createComponentOnLink(node, draw2dPosition);
            }
            if (!executed) {
                // create the node on the design sheet
                execCommandStack(new CreateNodeContainerCommand((Process) editor.getProcess(), nc, draw2dPosition));
            }
            // initialize the propertiesView
            CompoundCommand cc = new CompoundCommand();
            createRefreshingPropertiesCommand(cc, selectedNode, node);
            execCommandStack(cc);
            // for (Command command : commands) {
            // }
            propaHadoopCfgChanges(selectedNode);
            draw2dPosition = draw2dPosition.getCopy();
            draw2dPosition.x += TalendEditor.GRID_SIZE;
            draw2dPosition.y += TalendEditor.GRID_SIZE;
            node.checkNode();
            lastUniqname = node.getUniqueName();
        }
    // setselecte(part, lastUniqname);
    }
// Shell shell = Display.getCurrent().getActiveShell();
// ModulesInstallerUtil.installModules(new Shell(shell), components);
}
Also used : IComponent(org.talend.core.model.components.IComponent) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) XMLFileNode(org.talend.core.model.metadata.builder.connection.XMLFileNode) MapperExternalNode(org.talend.core.model.process.node.MapperExternalNode) ArrayList(java.util.ArrayList) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) IProcess(org.talend.core.model.process.IProcess) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) RulesItem(org.talend.core.model.properties.RulesItem) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) RulesItem(org.talend.core.model.properties.RulesItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) FileItem(org.talend.core.model.properties.FileItem) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) Iterator(java.util.Iterator) IElementParameter(org.talend.core.model.process.IElementParameter) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IFigure(org.eclipse.draw2d.IFigure) Point(org.eclipse.draw2d.geometry.Point) Canvas(org.eclipse.swt.widgets.Canvas) Point(org.eclipse.draw2d.geometry.Point) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) SAPFunctionRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) SAPIDocRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPIDocRepositoryObject) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 42 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class ComponentChooseDialog method extractComponents.

/**
     * Extracts the components which have the same palette type as process. Added by Marvin Wang on Feb 27, 2013.
     *
     * @param neededComponents
     * @return
     */
protected List<IComponent> extractComponents(List<IComponent> neededComponents) {
    if (neededComponents != null && neededComponents.size() > 0) {
        Iterator<IComponent> componentsIterator = neededComponents.iterator();
        while (componentsIterator.hasNext()) {
            IComponent component = componentsIterator.next();
            String compType = component.getPaletteType();
            if (compType != null && !compType.equals(editor.getProcess().getComponentsType())) {
                componentsIterator.remove();
            }
        }
    }
    return neededComponents;
}
Also used : IComponent(org.talend.core.model.components.IComponent)

Example 43 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class ConvertRepositoryNodeToProcessNode method convertToProcessNode.

public void convertToProcessNode(ConnectionItem connectionItem, String tableName) throws ProcessorException {
    EDatabaseComponentName name = EDatabaseComponentName.getCorrespondingComponentName(connectionItem, ERepositoryObjectType.METADATA_CONNECTIONS);
    String componentName = null;
    componentName = name.getDefaultComponentName();
    IComponent dbInputComponent = ComponentsFactoryProvider.getInstance().get(componentName, ComponentCategory.CATEGORY_4_DI.getName());
    Process process = new Process(GuessSchemaProcess.getNewmockProperty());
    node = new Node(dbInputComponent, process);
    selectedContext = node.getProcess().getContextManager().getDefaultContext();
    // TDI-20011
    IMetadataTable table = UpdateRepositoryUtils.getTableByName(connectionItem, tableName);
    if (table == null) {
        table = new MetadataTable();
        table.setTableName(tableName);
        table.setLabel(tableName);
    }
    IElementParameter propertyParam = ((Node) node).getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
    IElementParameter schemaParam = ((Node) node).getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
    if (schemaParam == null) {
        schemaParam = ((Node) node).getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE);
    }
    String propertyId = connectionItem.getProperty().getId();
    String schema = databaseConnection.getUiSchema();
    String dbType = databaseConnection.getDatabaseType();
    //$NON-NLS-1$
    String value = connectionItem.getProperty().getId() + " - " + table.getLabel();
    CompoundCommand cc = new CompoundCommand();
    // inital parameters command
    ChangeValuesFromRepository changeValueCommand = new ChangeValuesFromRepository(node, databaseConnection, propertyParam.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), //$NON-NLS-1$
    propertyId);
    changeValueCommand.ignoreContextMode(true);
    cc.add(changeValueCommand);
    // change metadata command
    RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) node, //$NON-NLS-1$
    schemaParam.getName() + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName(), value, table, null, null);
    cc.add(changeMetadataCommand);
    // guess query command
    QueryGuessCommand queryGuessCommand = new QueryGuessCommand(node, node.getMetadataList().get(0), schema, dbType, databaseConnection);
    cc.add(queryGuessCommand);
    // execute the commands
    cc.execute();
    //$NON-NLS-1$
    IElementParameter query = node.getElementParameter("QUERY");
    //
    memoSQL = query.getValue().toString();
    String memoSQLTemp = TalendTextUtils.removeQuotesIfExist(memoSQL);
    if ((memoSQLTemp == null || memoSQLTemp.equals("")) && tableName != null && !tableName.equals("")) {
        //$NON-NLS-1$
        boolean check = !Pattern.matches("^\\w+$", tableName);
        boolean isJDBCForMysql = databaseConnection.getURL() == null ? false : databaseConnection.getURL().startsWith("jdbc:mysql");
        if ((dbType.equals(EDatabaseTypeName.MYSQL.getDisplayName()) || isJDBCForMysql) && check) {
            tableName = TalendQuoteUtils.addQuotes(tableName, TalendQuoteUtils.ANTI_QUOTE);
        }
        memoSQL = "select * from " + tableName;
        memoSQL = TalendTextUtils.addSQLQuotes(memoSQL);
    }
}
Also used : RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) QueryGuessCommand(org.talend.designer.core.ui.editor.cmd.QueryGuessCommand) GuessSchemaProcess(org.talend.designer.core.ui.editor.properties.controllers.GuessSchemaProcess) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 44 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class ComponentChooseDialog method chooseOneComponent.

/**
     * Let the user choose which component he would like to create.
     *
     * @param neededComponents
     * @param name
     * @param quickCreateInput
     * @param quickCreateOutput
     */
private IComponent chooseOneComponent(List<IComponent> neededComponents, IComponentName name, boolean quickCreateInput, boolean quickCreateOutput) {
    if (neededComponents.isEmpty()) {
        return null;
    }
    if (neededComponents.size() == 1) {
        return neededComponents.get(0);
    }
    IComponent inputComponent = getComponentByName(name.getInputComponentName(), quickCreateInput, neededComponents);
    if (inputComponent != null) {
        return inputComponent;
    }
    IComponent outputComponent = getComponentByName(name.getOutPutComponentName(), quickCreateOutput, neededComponents);
    if (outputComponent != null) {
        return outputComponent;
    }
    ComponentChooseDialog dialog = new ComponentChooseDialog(editor.getSite().getShell(), neededComponents);
    IComponent defaultComponent = getComponentByName(name.getDefaultComponentName(), true, neededComponents);
    if (defaultComponent != null) {
        dialog.setInitialSelections(new Object[] { defaultComponent });
    } else {
        dialog.setInitialSelections(new Object[] { neededComponents.get(0) });
    }
    if (dialog.open() == IDialogConstants.OK_ID) {
        return dialog.getResultComponent();
    }
    //$NON-NLS-1$
    throw new OperationCanceledException(Messages.getString("TalendEditorDropTargetListener.cancelOperation"));
}
Also used : IComponent(org.talend.core.model.components.IComponent) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException)

Example 45 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class ComponentChooseDialog method getAppropriateComponent.

private void getAppropriateComponent(Item item, boolean quickCreateInput, boolean quickCreateOutput, TempStore store, ERepositoryObjectType type) {
    IComponentName rcSetting = RepositoryComponentManager.getSetting(item, type);
    // For handler, need check for esb
    if (rcSetting == null) {
        for (IDragAndDropServiceHandler handler : DragAndDropManager.getHandlers()) {
            rcSetting = handler.getCorrespondingComponentName(item, type);
            if (rcSetting != null) {
                break;
            }
        }
        if (rcSetting == null) {
            return;
        }
    }
    boolean isCurrentProject = true;
    String projectName = null;
    if (store.seletetedNode.getObject() != null) {
        projectName = store.seletetedNode.getObject().getProjectLabel();
        isCurrentProject = projectName.equals(ProjectManager.getInstance().getCurrentProject().getLabel());
    }
    List<IComponent> neededComponents = RepositoryComponentManager.filterNeededComponents(item, store.seletetedNode, type, isCurrentProject, projectName);
    for (IDragAndDropServiceHandler handler : DragAndDropManager.getHandlers()) {
        List<IComponent> comList = handler.filterNeededComponents(item, store.seletetedNode, type);
        if (comList != null) {
            for (IComponent handlerComp : comList) {
                if (!neededComponents.contains(handlerComp) && !handlerComp.isTechnical()) {
                    neededComponents.add(handlerComp);
                }
            }
        }
    }
    // special handle hbase to support tpigLoad
    String hbaseName = EDatabaseTypeName.HBASE.getDisplayName().toUpperCase();
    if (rcSetting != null && (hbaseName).equals(rcSetting.toString())) {
        IComponentsService service = (IComponentsService) GlobalServiceRegister.getDefault().getService(IComponentsService.class);
        String componentProductname = null;
        Set<IComponent> components = service.getComponentsFactory().getComponents();
        for (IComponent component : components) {
            componentProductname = component.getRepositoryType();
            if (componentProductname != null && componentProductname.contains(hbaseName) && !neededComponents.contains(component) && !component.isTechnical()) {
                neededComponents.add(component);
            }
        }
    }
    neededComponents = (List<IComponent>) ComponentUtilities.filterVisibleComponents(neededComponents);
    // Check if the components in the list neededComponents have the same category that is required by Process.
    IComponent component = chooseOneComponent(extractComponents(neededComponents), rcSetting, quickCreateInput, quickCreateOutput);
    store.component = component;
    store.componentName = rcSetting;
}
Also used : IComponentsService(org.talend.core.model.components.IComponentsService) IDragAndDropServiceHandler(org.talend.core.model.utils.IDragAndDropServiceHandler) IComponent(org.talend.core.model.components.IComponent) IComponentName(org.talend.core.model.utils.IComponentName)

Aggregations

IComponent (org.talend.core.model.components.IComponent)146 Node (org.talend.designer.core.ui.editor.nodes.Node)54 ArrayList (java.util.ArrayList)47 IElementParameter (org.talend.core.model.process.IElementParameter)36 Process (org.talend.designer.core.ui.editor.process.Process)36 Test (org.junit.Test)35 INode (org.talend.core.model.process.INode)33 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)22 List (java.util.List)15 Property (org.talend.core.model.properties.Property)15 FakePropertyImpl (org.talend.core.model.repository.FakePropertyImpl)15 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)13 IComponentsFactory (org.talend.core.model.components.IComponentsFactory)12 Connection (org.talend.designer.core.ui.editor.connections.Connection)12 HashMap (java.util.HashMap)11 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)10 DataNode (org.talend.designer.core.model.process.DataNode)10 HashSet (java.util.HashSet)9 IConnection (org.talend.core.model.process.IConnection)9 Rectangle (org.eclipse.swt.graphics.Rectangle)8