Search in sources :

Example 16 with SQLPatternItem

use of org.talend.core.model.properties.SQLPatternItem in project tdi-studio-se by Talend.

the class SaveAsSQLPatternAction method run.

@Override
public void run() {
    SaveAsSQLPatternWizard processWizard = new SaveAsSQLPatternWizard(editorPart);
    WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), processWizard);
    if (dlg.open() == Window.OK) {
        try {
            SQLPatternItem sqlpatternItem = processWizard.getSQLPatternItem();
            // get the IFile
            ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
            // only for talend java version
            ISQLPatternSynchronizer sqlPatternSynchronizer = service.getSQLPatternSynchronizer();
            IFile file = sqlPatternSynchronizer.getSQLPatternFile(sqlpatternItem);
            if (file == null) {
                return;
            }
            // Set readonly to false since created job will always be editable.
            RepositoryEditorInput repositoryEditorInput = new RepositoryEditorInput(file, sqlpatternItem);
            IWorkbenchPage page = getActivePage();
            IRepositoryNode repositoryNode = RepositoryNodeUtilities.getRepositoryNode(repositoryEditorInput.getItem().getProperty().getId(), false);
            repositoryEditorInput.setRepositoryNode(repositoryNode);
            // here really do the normal save as function
            IDocumentProvider provider = ((StandAloneTalendJavaEditor) this.editorPart).getDocumentProvider();
            provider.aboutToChange(repositoryEditorInput);
            provider.saveDocument(null, repositoryEditorInput, provider.getDocument(this.editorPart.getEditorInput()), true);
            provider.changed(repositoryEditorInput);
            // copy back from the *.java file to *.item file.
            // @see:StandAloneTalendJavaEditor.doSave(IProgressMonitor monitor)
            ByteArray byteArray = sqlpatternItem.getContent();
            byteArray.setInnerContentFromFile(repositoryEditorInput.getFile());
            IProxyRepositoryFactory repFactory = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
            repFactory.save(sqlpatternItem);
            // close the old editor
            page.closeEditor(this.editorPart, false);
            // open the new editor, because at the same time, there will update the jobSetting/componentSetting view
            page.openEditor(repositoryEditorInput, StandAloneTalendJavaEditor.ID, true);
        } catch (Exception e) {
            MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", "SQLTemplate could not be saved" + " : " + e.getMessage());
            ExceptionHandler.process(e);
        }
    }
}
Also used : SaveAsSQLPatternWizard(org.talend.designer.core.ui.wizards.SaveAsSQLPatternWizard) IFile(org.eclipse.core.resources.IFile) RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ISQLPatternSynchronizer(org.talend.designer.codegen.ISQLPatternSynchronizer) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) StandAloneTalendJavaEditor(org.talend.designer.core.ui.editor.StandAloneTalendJavaEditor) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ByteArray(org.talend.core.model.properties.ByteArray) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 17 with SQLPatternItem

use of org.talend.core.model.properties.SQLPatternItem in project tdi-studio-se by Talend.

the class ComponentChooseDialog method createSQLPattern.

private void createSQLPattern(List<Object> sourceList) {
    if (sourceList.size() == 0) {
        return;
    }
    NodeContainerPart nodePart = (NodeContainerPart) getTargetEditPart();
    Object model = nodePart.getModel();
    if (model instanceof NodeContainer) {
        Node node = ((NodeContainer) model).getNode();
        IElementParameter sqlPatternValue = node.getElementParameter(EParameterName.SQLPATTERN_VALUE.getName());
        if (sqlPatternValue != null) {
            boolean created = false;
            for (Object source : sourceList) {
                if (source instanceof RepositoryNode) {
                    RepositoryNode sourceNode = (RepositoryNode) source;
                    Item item = sourceNode.getObject().getProperty().getItem();
                    if (item instanceof SQLPatternItem) {
                        SQLPatternItem pattern = (SQLPatternItem) item;
                        Property property = pattern.getProperty();
                        String propertyId = property.getId();
                        String propertyLabel = property.getLabel();
                        List<Map> values = (List<Map>) sqlPatternValue.getValue();
                        Map<String, String> patternMap = new HashMap<String, String>();
                        boolean contains = false;
                        for (Map map : values) {
                            String compoundId = (String) map.get(SQLPatternUtils.SQLPATTERNLIST);
                            String id = compoundId.split(SQLPatternUtils.ID_SEPARATOR)[0];
                            String name = compoundId.split(SQLPatternUtils.ID_SEPARATOR)[1];
                            if (id.equals(propertyId) && name.equals(propertyLabel)) {
                                contains = true;
                                break;
                            }
                        }
                        if (!contains) {
                            patternMap.put(SQLPatternUtils.SQLPATTERNLIST, propertyId + SQLPatternUtils.ID_SEPARATOR + propertyLabel);
                            values.add(patternMap);
                            sqlPatternValue.setValue(values);
                            created = true;
                        }
                    }
                }
            }
            if (created) {
                RepositoryPlugin.getDefault().getDesignerCoreService().switchToCurComponentSettingsView();
            }
        }
    }
}
Also used : NodeContainerPart(org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart) HashMap(java.util.HashMap) 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) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) 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) IElementParameter(org.talend.core.model.process.IElementParameter) 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) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) Property(org.talend.core.model.properties.Property) Map(java.util.Map) HashMap(java.util.HashMap)

Example 18 with SQLPatternItem

use of org.talend.core.model.properties.SQLPatternItem in project tdi-studio-se by Talend.

the class ComponentChooseDialog method containsSQLPatternSource.

private boolean containsSQLPatternSource(List<Object> source) {
    if (source.size() == 0) {
        return false;
    }
    for (Object object : source) {
        if (object instanceof RepositoryNode) {
            RepositoryNode sourceNode = (RepositoryNode) object;
            Item item = sourceNode.getObject().getProperty().getItem();
            if (item instanceof SQLPatternItem) {
                return true;
            }
        }
    }
    return false;
}
Also used : 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) 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) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Example 19 with SQLPatternItem

use of org.talend.core.model.properties.SQLPatternItem in project tdi-studio-se by Talend.

the class SQLPatternComposite method refreshCode.

/**
     * yzhang Comment method "refreshCode".
     * 
     * @param element
     * @return
     */
private List<Map> refreshCode(Element element) {
    IElementParameter sqlPatternValue = element.getElementParameter(EParameterName.SQLPATTERN_VALUE.getName());
    if (sqlPatternValue != null) {
        List<Map> values = (List<Map>) sqlPatternValue.getValue();
        if (firstTimeLoad) {
            List<Map> unusedValues = new ArrayList<Map>();
            for (Map map : values) {
                String compoundId = (String) map.get(SQLPatternUtils.SQLPATTERNLIST);
                String id = compoundId.split(SQLPatternUtils.ID_SEPARATOR)[0];
                IRepositoryViewObject repositoryObject = SQLPatternUtils.getLastVersionRepositoryObjectById(id);
                String name = compoundId.split(SQLPatternUtils.ID_SEPARATOR)[1];
                SQLPatternItem item = null;
                if (repositoryObject == null && (item = SQLPatternUtils.getSQLPatternItem(element, name)) == null) {
                    unusedValues.add(map);
                }
            }
            values.removeAll(unusedValues);
            firstTimeLoad = false;
        }
        return values;
    }
    return new ArrayList();
}
Also used : ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) Map(java.util.Map) HashMap(java.util.HashMap) BidiMap(org.apache.commons.collections.BidiMap)

Example 20 with SQLPatternItem

use of org.talend.core.model.properties.SQLPatternItem in project tdi-studio-se by Talend.

the class ComponentChooseDialog method dragOver.

@Override
public void dragOver(DropTargetEvent event) {
    // multi-drag for job,context, sqlPattern.
    IStructuredSelection selection = getSelection();
    if (selection.size() > 1) {
        boolean allowed = true;
        Item temItem = null;
        Iterator iter = selection.iterator();
        while (iter.hasNext()) {
            Object next = iter.next();
            if (next instanceof RepositoryNode) {
                RepositoryNode sourceNode = (RepositoryNode) next;
                IRepositoryViewObject object = sourceNode.getObject();
                if (object != null) {
                    Item selectItem = object.getProperty().getItem();
                    if (temItem == null) {
                        temItem = selectItem;
                        continue;
                    }
                    if (selectItem instanceof ProcessItem && !(temItem instanceof ProcessItem)) {
                        allowed = false;
                    } else if (selectItem instanceof ContextItem && !(temItem instanceof ContextItem)) {
                        allowed = false;
                    } else if (selectItem instanceof SQLPatternItem && !(temItem instanceof SQLPatternItem)) {
                        allowed = false;
                    }
                }
            }
        }
        if (!allowed) {
            event.detail = DND.DROP_NONE;
        }
    } else {
        CreateRequest req = ((CreateRequest) getTargetRequest());
        Object o = null;
        try {
            o = req.getNewObject();
        } catch (Exception e) {
            return;
        }
        if (!(o instanceof Node)) {
            return;
        }
        RootEditPart rep = editor.getViewer().getRootEditPart().getRoot();
        Point viewOriginalPosition = new Point();
        if (rep instanceof ScalableFreeformRootEditPart) {
            ScalableFreeformRootEditPart root = (ScalableFreeformRootEditPart) rep;
            Viewport viewport = (Viewport) root.getFigure();
            viewOriginalPosition = viewport.getViewLocation();
        }
        org.eclipse.swt.graphics.Point swtLocation = new org.eclipse.swt.graphics.Point(event.x + viewOriginalPosition.x, event.y + viewOriginalPosition.y);
        Canvas canvas = (Canvas) editor.getViewer().getControl();
        swtLocation = canvas.toControl(swtLocation);
        // System.out.println("topLeft:" + topLeftpoint + " / event:" + swtLocation);
        org.eclipse.draw2d.geometry.Point draw2dPosition = new org.eclipse.draw2d.geometry.Point(swtLocation.x, swtLocation.y);
        double zoom = 1.0;
        if (editor.getViewer().getRootEditPart() instanceof TalendScalableFreeformRootEditPart) {
            ZoomManager zoomManager = ((TalendScalableFreeformRootEditPart) editor.getViewer().getRootEditPart()).getZoomManager();
            zoom = zoomManager.getZoom();
        }
        List<ConnectionPart> connectionParts = CreateComponentOnLinkHelper.getConnectionParts(editor.getProcessPart(), draw2dPosition, (Node) o);
        double minDistance = 1000000000;
        for (ConnectionPart part : connectionParts) {
            if (part.getFigure() instanceof PolylineConnection) {
                PolylineConnection connection = (PolylineConnection) part.getFigure();
                double distance = CreateComponentOnLinkHelper.getDistanceOrthogonal(draw2dPosition.x, draw2dPosition.y, connection, zoom);
                if (distance < minDistance) {
                    selectedConnectionPart = part;
                    minDistance = Math.min(distance, minDistance);
                }
            }
        }
        if (selectedConnectionPart != null && minDistance < 15) {
            for (Object child : editor.getProcessPart().getChildren()) {
                if (child instanceof SubjobContainerPart) {
                    CreateComponentOnLinkHelper.unselectAllConnections((SubjobContainerPart) child);
                }
            }
            CreateComponentOnLinkHelper.selectConnection(selectedConnectionPart);
        } else {
            if (selectedConnectionPart != null) {
                CreateComponentOnLinkHelper.unselectConnection(selectedConnectionPart);
            }
            selectedConnectionPart = null;
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) CreateRequest(org.eclipse.gef.requests.CreateRequest) 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) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) 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) Iterator(java.util.Iterator) Point(org.eclipse.draw2d.geometry.Point) Canvas(org.eclipse.swt.widgets.Canvas) Viewport(org.eclipse.draw2d.Viewport) Point(org.eclipse.draw2d.geometry.Point) ConnectionPart(org.talend.designer.core.ui.editor.connections.ConnectionPart) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) PersistenceException(org.talend.commons.exception.PersistenceException) PolylineConnection(org.eclipse.draw2d.PolylineConnection) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) AnimatableZoomManager(org.talend.commons.ui.gmf.draw2d.AnimatableZoomManager) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) 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) TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) RootEditPart(org.eclipse.gef.RootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart)

Aggregations

SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)24 PersistenceException (org.talend.commons.exception.PersistenceException)11 Item (org.talend.core.model.properties.Item)11 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)11 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)8 PartInitException (org.eclipse.ui.PartInitException)7 ConnectionItem (org.talend.core.model.properties.ConnectionItem)7 RepositoryNode (org.talend.repository.model.RepositoryNode)7 IRepositoryNode (org.talend.repository.model.IRepositoryNode)6 RoutineItem (org.talend.core.model.properties.RoutineItem)5 RepositoryEditorInput (org.talend.core.repository.ui.editor.RepositoryEditorInput)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ArrayList (java.util.ArrayList)4 CoreException (org.eclipse.core.runtime.CoreException)4 Project (org.talend.core.model.general.Project)4 IElementParameter (org.talend.core.model.process.IElementParameter)4 FileItem (org.talend.core.model.properties.FileItem)4 ProcessItem (org.talend.core.model.properties.ProcessItem)4 Property (org.talend.core.model.properties.Property)4 HashMap (java.util.HashMap)3