Search in sources :

Example 1 with MapperComponent

use of org.talend.designer.mapper.MapperComponent in project tdi-studio-se by Talend.

the class MapperUI method createWindow.

/**
     * DOC amaumont Comment method "createUI".
     * 
     * @param display
     */
public Shell createWindow(final Display display, MapperModel model) {
    Shell activeShell = display.getActiveShell();
    Shell mapperShell = null;
    int style = SWT.DIALOG_TRIM | SWT.MIN | SWT.MAX | SWT.APPLICATION_MODAL | SWT.RESIZE;
    if (activeShell == null) {
        mapperShell = new Shell(mapperShell, style);
    } else {
        mapperShell = new Shell(activeShell, style);
    }
    this.mapperUIParent = mapperShell;
    final Shell mapperShellFinal = mapperShell;
    mapperShell.addShellListener(new ShellListener() {

        public void shellActivated(ShellEvent e) {
        }

        public void shellClosed(ShellEvent e) {
            UIManager uiManager = mapperManager.getUiManager();
            if (uiManager.getMapperResponse() == SWT.NONE) {
                for (DataMapTableView dataMapTableView : uiManager.getInputsTablesView()) {
                    dataMapTableView.notifyFocusLost();
                }
                for (DataMapTableView dataMapTableView : uiManager.getOutputsTablesView()) {
                    dataMapTableView.notifyFocusLost();
                }
                for (DataMapTableView dataMapTableView : uiManager.getVarsTablesView()) {
                    dataMapTableView.notifyFocusLost();
                }
                uiManager.setMapperResponse(SWT.CANCEL);
                uiManager.prepareClosing(uiManager.getMapperResponse());
            }
            if (!mapperManager.componentIsReadOnly() && mapperManager.isDataChanged() && !mapperManager.getUiManager().isCloseWithoutPrompt()) {
                boolean closeWindow = MessageDialog.openConfirm(mapperShellFinal, //$NON-NLS-1$
                Messages.getString("MapperUI.CancelWithoutSaveModifications.Title"), //$NON-NLS-1$
                Messages.getString("MapperUI.CancelWithoutSaveModifications.Message"));
                if (!closeWindow) {
                    e.doit = false;
                } else {
                    mapperManager.getAbstractMapComponent().setExternalData(mapperManager.getOriginalExternalData());
                    mapperManager.getUiManager().prepareClosing(SWT.CANCEL);
                }
            }
        }

        public void shellDeactivated(ShellEvent e) {
        }

        public void shellDeiconified(ShellEvent e) {
        }

        public void shellIconified(ShellEvent e) {
        }
    });
    MapperComponent component = (MapperComponent) mapperManager.getAbstractMapComponent();
    ExternalMapperUiProperties uiProperties = mapperManager.getUiManager().getUiProperties();
    mapperShell.setImage(CoreImageProvider.getComponentIcon(component.getComponent(), ICON_SIZE.ICON_32));
    IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
    String productName = brandingService.getFullProductName();
    mapperShell.setText(Messages.getString("MapperMain.ShellTitle", productName, component.getComponent().getName(), //$NON-NLS-1$
    component.getUniqueName()));
    Rectangle boundsMapper = uiProperties.getBoundsMapper();
    if (uiProperties.isShellMaximized()) {
        mapperShell.setMaximized(uiProperties.isShellMaximized());
    } else {
        if (uiProperties.getBoundsMapper().equals(ExternalMapperUiProperties.DEFAULT_BOUNDS_MAPPER)) {
            mapperShell.setMaximized(true);
        // boundsMapper = display.getBounds(); //no need this, will cause the full problems.
        } else {
            // // move shell at outer of display zone to avoid visual effect on loading
            // Rectangle tmpBoundsMapper = new Rectangle(-boundsMapper.width, boundsMapper.y, boundsMapper.width,
            // boundsMapper.height);
            // shell.setBounds(tmpBoundsMapper);
            boundsMapper = uiProperties.getBoundsMapper();
            if (boundsMapper.x < 0) {
                boundsMapper.x = 0;
            }
            if (boundsMapper.y < 0) {
                boundsMapper.y = 0;
            }
            mapperShell.setBounds(boundsMapper);
        }
    }
    createCompositeContent(model);
    mapperShell.open();
    return mapperShell;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ExternalMapperUiProperties(org.talend.designer.mapper.external.data.ExternalMapperUiProperties) ShellListener(org.eclipse.swt.events.ShellListener) Rectangle(org.eclipse.swt.graphics.Rectangle) ShellEvent(org.eclipse.swt.events.ShellEvent) UIManager(org.talend.designer.mapper.managers.UIManager) OutputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.OutputDataMapTableView) InputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.InputDataMapTableView) VarsDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.VarsDataMapTableView) DataMapTableView(org.talend.designer.mapper.ui.visualmap.table.DataMapTableView) IBrandingService(org.talend.core.ui.branding.IBrandingService) MapperComponent(org.talend.designer.mapper.MapperComponent)

Example 2 with MapperComponent

use of org.talend.designer.mapper.MapperComponent in project tdi-studio-se by Talend.

the class ProblemsAnalyser method checkProblems.

public List<Problem> checkProblems(ExternalMapperData externalData) {
    problems.clear();
    if (externalData != null) {
        checkLookupTablesKeyProblems(externalData);
        ICodeProblemsChecker codeChecker = LanguageProvider.getCurrentLanguage().getCodeChecker();
        if (mapperManager.isCheckSyntaxEnabled()) {
            List<ExternalMapperTable> extInputTables = new ArrayList<ExternalMapperTable>(externalData.getInputTables());
            List<ExternalMapperTable> extVarTables = new ArrayList<ExternalMapperTable>(externalData.getVarsTables());
            List<ExternalMapperTable> extOutputTables = new ArrayList<ExternalMapperTable>(externalData.getOutputTables());
            checkExpressionSyntaxProblems(extInputTables, codeChecker);
            checkExpressionSyntaxProblems(extVarTables, codeChecker);
            checkExpressionSyntaxProblems(extOutputTables, codeChecker);
            List<? extends IConnection> incomingConnections = new ArrayList<IConnection>(this.mapperManager.getAbstractMapComponent().getIncomingConnections());
            ExternalDataConverter converter = new ExternalDataConverter(mapperManager);
            MapperMain mapperMain = ((MapperComponent) mapperManager.getAbstractMapComponent()).getMapperMain();
            ArrayList<IOConnection> inputsIOConnections = mapperMain.createIOConnections(incomingConnections);
            ArrayList<InputTable> inputTables = converter.prepareInputTables(inputsIOConnections, externalData);
            checkKeysProblems(inputTables);
            checkOutputTablesProblems(extOutputTables);
        }
    }
    return getProblems();
}
Also used : ExternalDataConverter(org.talend.designer.mapper.external.converter.ExternalDataConverter) InputTable(org.talend.designer.mapper.model.table.InputTable) IOConnection(org.talend.designer.mapper.external.connection.IOConnection) ArrayList(java.util.ArrayList) ICodeProblemsChecker(org.talend.core.language.ICodeProblemsChecker) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) MapperMain(org.talend.designer.mapper.MapperMain) MapperComponent(org.talend.designer.mapper.MapperComponent)

Example 3 with MapperComponent

use of org.talend.designer.mapper.MapperComponent in project tdi-studio-se by Talend.

the class ProblemsAnalyserTest method testGetLookupTableProblem.

@Test
public void testGetLookupTableProblem() {
    MapperComponent mapperComponent = createMapperComponent();
    ExternalMapperData externalData = (ExternalMapperData) mapperComponent.getExternalData();
    MapperManager mapperManager = mapperComponent.getMapperMain().getMapperManager();
    ExternalDataConverter converter = new ExternalDataConverter(mapperManager);
    MapperMain mapperMain = ((MapperComponent) mapperManager.getAbstractMapComponent()).getMapperMain();
    List<? extends IConnection> incomingConnections = new ArrayList<IConnection>(mapperManager.getAbstractMapComponent().getIncomingConnections());
    ArrayList<IOConnection> inputsIOConnections = mapperMain.createIOConnections(incomingConnections);
    ArrayList<InputTable> inputTables = converter.prepareInputTables(inputsIOConnections, externalData);
    InputTable lookupTable = inputTables.get(1);
    ProblemsAnalyser analyser = new ProblemsAnalyser(mapperManager);
    // match mode:Unique Match +no expression
    lookupTable.setMatchingMode(TMAP_MATCHING_MODE.UNIQUE_MATCH);
    analyser.getLookupTableProblem(lookupTable, mapperManager.isTableHasAtLeastOneHashKey(lookupTable));
    List<Problem> problems = analyser.getProblems();
    Assert.assertEquals(problems.size(), 1);
    Assert.assertEquals(problems.get(0).getDescription(), "The lookup table 'row2' should have at least one expression key filled.");
    // match mode:All Row +expression
    lookupTable.setMatchingMode(TMAP_MATCHING_MODE.ALL_ROWS);
    lookupTable.getColumnEntries().get(0).setExpression("row1.newColumn1");
    analyser = new ProblemsAnalyser(mapperComponent.getMapperMain().getMapperManager());
    analyser.getLookupTableProblem(lookupTable, mapperManager.isTableHasAtLeastOneHashKey(lookupTable));
    problems = analyser.getProblems();
    Assert.assertEquals(problems.size(), 1);
    Assert.assertEquals(problems.get(0).getDescription(), "The expression key can't be used in lookup table 'row2' with match mode 'All Rows'.");
}
Also used : ExternalDataConverter(org.talend.designer.mapper.external.converter.ExternalDataConverter) MapperManager(org.talend.designer.mapper.managers.MapperManager) ArrayList(java.util.ArrayList) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData) InputTable(org.talend.designer.mapper.model.table.InputTable) IOConnection(org.talend.designer.mapper.external.connection.IOConnection) Problem(org.talend.core.model.process.Problem) MapperMain(org.talend.designer.mapper.MapperMain) MapperComponent(org.talend.designer.mapper.MapperComponent) Test(org.junit.Test)

Example 4 with MapperComponent

use of org.talend.designer.mapper.MapperComponent in project tdi-studio-se by Talend.

the class ProblemsAnalyserTest method testCheckLookupTablesKeyProblems.

@Test
public void testCheckLookupTablesKeyProblems() {
    MapperComponent mapperComponent = createMapperComponent();
    ProblemsAnalyser analyser = new ProblemsAnalyser(mapperComponent.getMapperMain().getMapperManager());
    IExternalData externalData = mapperComponent.getExternalData();
    ExternalMapperTable lookupTable = (ExternalMapperTable) externalData.getInputTables().get(1);
    // match mode:Unique Match +no expression
    lookupTable.setMatchingMode(TMAP_MATCHING_MODE.UNIQUE_MATCH.name());
    analyser.checkLookupTablesKeyProblems((ExternalMapperData) externalData);
    List<Problem> problems = analyser.getProblems();
    Assert.assertEquals(problems.size(), 1);
    Assert.assertEquals(problems.get(0).getDescription(), "The lookup table 'row2' should have at least one expression key filled.");
    // match mode:All Row +expression
    lookupTable.setMatchingMode(TMAP_MATCHING_MODE.ALL_ROWS.name());
    lookupTable.getMetadataTableEntries().get(0).setExpression("row1.newColumn1");
    analyser = new ProblemsAnalyser(mapperComponent.getMapperMain().getMapperManager());
    analyser.checkLookupTablesKeyProblems((ExternalMapperData) externalData);
    problems = analyser.getProblems();
    Assert.assertEquals(problems.size(), 1);
    Assert.assertEquals(problems.get(0).getDescription(), "The expression key can't be used in lookup table 'row2' with match mode 'All Rows'.");
}
Also used : Problem(org.talend.core.model.process.Problem) IExternalData(org.talend.core.model.process.IExternalData) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) MapperComponent(org.talend.designer.mapper.MapperComponent) Test(org.junit.Test)

Example 5 with MapperComponent

use of org.talend.designer.mapper.MapperComponent in project tdi-studio-se by Talend.

the class ProblemsAnalyserTest method createMapperComponent.

private MapperComponent createMapperComponent() {
    IComponent tMysqlComponent = ComponentsFactoryProvider.getInstance().get("tMysqlInput", ComponentCategory.CATEGORY_4_DI.getName());
    IComponent tMapComponent = ComponentsFactoryProvider.getInstance().get("tMap", ComponentCategory.CATEGORY_4_DI.getName());
    Property property1 = PropertiesFactory.eINSTANCE.createProperty();
    //$NON-NLS-1$
    property1.setId("property1");
    //$NON-NLS-1$
    property1.setVersion("0.1");
    //$NON-NLS-1$
    property1.setLabel("test1");
    Process process = new Process(property1);
    Node tMysqlInput_1 = new Node(tMysqlComponent, process);
    IMetadataTable tMysqlInput_1_table = tMysqlInput_1.getMetadataTable("tMysqlInput_1");
    createMetadataColumns(tMysqlInput_1_table, 2);
    Node tMysqlInput_2 = new Node(tMysqlComponent, process);
    IMetadataTable tMysqlInput_2_table = tMysqlInput_2.getMetadataTable("tMysqlInput_2");
    createMetadataColumns(tMysqlInput_2_table, 2);
    Node tMap_1 = new Node(tMapComponent, process);
    Connection row1 = new Connection(tMysqlInput_1, tMap_1, EConnectionType.FLOW_MAIN, EConnectionType.FLOW_MAIN.getName(), "tMysqlInput_1", "row1", "row1", false);
    Connection row2 = new Connection(tMysqlInput_2, tMap_1, EConnectionType.FLOW_REF, EConnectionType.FLOW_MAIN.getName(), "tMysqlInput_1", "row2", "row2", false);
    tMap_1.getExternalNode().initialize();
    MapperComponent mapperComponent = (MapperComponent) tMap_1.getExternalNode();
    ExternalMapperData externalData = (ExternalMapperData) mapperComponent.getExternalData();
    ExternalMapperTable externalTable = prepareExternalData(tMysqlInput_1_table);
    externalTable.setName(row1.getName());
    externalData.getInputTables().add(externalTable);
    externalTable = prepareExternalData(tMysqlInput_2_table);
    externalTable.setName(row2.getName());
    externalData.getInputTables().add(externalTable);
    return mapperComponent;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) IConnection(org.talend.core.model.process.IConnection) IOConnection(org.talend.designer.mapper.external.connection.IOConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) Process(org.talend.designer.core.ui.editor.process.Process) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) ExternalMapperData(org.talend.designer.mapper.external.data.ExternalMapperData) Property(org.talend.core.model.properties.Property) MapperComponent(org.talend.designer.mapper.MapperComponent)

Aggregations

MapperComponent (org.talend.designer.mapper.MapperComponent)5 IOConnection (org.talend.designer.mapper.external.connection.IOConnection)3 ExternalMapperTable (org.talend.designer.mapper.external.data.ExternalMapperTable)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Problem (org.talend.core.model.process.Problem)2 MapperMain (org.talend.designer.mapper.MapperMain)2 ExternalDataConverter (org.talend.designer.mapper.external.converter.ExternalDataConverter)2 ExternalMapperData (org.talend.designer.mapper.external.data.ExternalMapperData)2 InputTable (org.talend.designer.mapper.model.table.InputTable)2 ShellEvent (org.eclipse.swt.events.ShellEvent)1 ShellListener (org.eclipse.swt.events.ShellListener)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 Shell (org.eclipse.swt.widgets.Shell)1 ICodeProblemsChecker (org.talend.core.language.ICodeProblemsChecker)1 IComponent (org.talend.core.model.components.IComponent)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 IConnection (org.talend.core.model.process.IConnection)1 IExternalData (org.talend.core.model.process.IExternalData)1 Property (org.talend.core.model.properties.Property)1