Search in sources :

Example 1 with TalendItem

use of org.talend.designer.business.model.business.TalendItem in project tdi-studio-se by Talend.

the class GmfPastCommand method cloneAssignmentForModel.

private void cloneAssignmentForModel(List<BusinessItem> nodes, List pChildren) {
    if (nodes == null || pChildren == null) {
        return;
    }
    int i = nodes.size();
    for (BusinessItem businessItem : getSortedBusinessItems(nodes)) {
        BusinessItem newItem = (BusinessItem) getEObject(businessItem);
        if (!addNew) {
            newItem.setBusinessProcess(businessItem.getBusinessProcess());
        }
        newItem.setHAlignment(businessItem.getHAlignment());
        newItem.setName(businessItem.getName());
        newItem.setVAlignment(businessItem.getVAlignment());
        List assignments = new ArrayList();
        boolean execute = false;
        int n = 0;
        for (Object object : businessItem.getAssignments()) {
            BusinessAssignment older = (BusinessAssignment) object;
            BusinessAssignment newAssignment = (BusinessAssignment) getEObject(older);
            newAssignment.setBusinessItem(newItem);
            newAssignment.setComment(older.getComment());
            if (!addNew) {
                newAssignment.setTalendItem(older.getTalendItem());
            } else {
                TalendItem item = older.getTalendItem();
                String talendId = null;
                if (item != null) {
                    talendId = item.getId();
                } else {
                    List idList = (List) itemIds.get(businessItem);
                    if (n < idList.size()) {
                        talendId = (String) idList.get(n);
                    }
                    n++;
                }
                RepositoryNode node = null;
                if (talendId.split(" - ").length == 1) {
                    //$NON-NLS-1$
                    node = RepositoryNodeUtilities.getRepositoryNode(talendId);
                } else {
                    node = RepositoryNodeUtilities.getMetadataTableFromConnection(talendId);
                    if (node == null) {
                        node = RepositoryNodeUtilities.getQueryFromConnection(talendId);
                    }
                }
                RepositoryHelper repositoryHelper = new RepositoryHelper();
                Repository repository = process.getLocalRepositoryCopy();
                if (repository == null) {
                    repository = repositoryHelper.createLocalRepositoryCopy(process);
                }
                TalendItem talendItem = repositoryHelper.createTalendItem(repository, node);
                newAssignment.setTalendItem(talendItem);
            }
            assignments.add(newAssignment);
        }
        if (assignments.size() > 0) {
            newItem.getAssignments().addAll(assignments);
        }
        if (i <= pChildren.size()) {
            View node = (View) pChildren.get(pChildren.size() - i);
            node.setElement(newItem);
            i--;
        }
        if (addNew) {
            this.process.getBusinessItems().add(newItem);
        }
    }
}
Also used : BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) ArrayList(java.util.ArrayList) RepositoryNode(org.talend.repository.model.RepositoryNode) View(org.eclipse.gmf.runtime.notation.View) Repository(org.talend.designer.business.model.business.Repository) ArrayList(java.util.ArrayList) List(java.util.List) EObject(org.eclipse.emf.ecore.EObject) TalendItem(org.talend.designer.business.model.business.TalendItem) InputBusinessItem(org.talend.designer.business.model.business.InputBusinessItem) TerminalBusinessItem(org.talend.designer.business.model.business.TerminalBusinessItem) ActorBusinessItem(org.talend.designer.business.model.business.ActorBusinessItem) DatabaseBusinessItem(org.talend.designer.business.model.business.DatabaseBusinessItem) BusinessItem(org.talend.designer.business.model.business.BusinessItem) GearBusinessItem(org.talend.designer.business.model.business.GearBusinessItem) EllipseBusinessItem(org.talend.designer.business.model.business.EllipseBusinessItem) DataBusinessItem(org.talend.designer.business.model.business.DataBusinessItem) DecisionBusinessItem(org.talend.designer.business.model.business.DecisionBusinessItem) DocumentBusinessItem(org.talend.designer.business.model.business.DocumentBusinessItem) ActionBusinessItem(org.talend.designer.business.model.business.ActionBusinessItem) ListBusinessItem(org.talend.designer.business.model.business.ListBusinessItem) RepositoryHelper(org.talend.designer.business.diagram.custom.util.RepositoryHelper)

Example 2 with TalendItem

use of org.talend.designer.business.model.business.TalendItem in project tdi-studio-se by Talend.

the class FindAssignmentAction method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
protected void doRun() {
    RepositoryNode repositoryNode = (RepositoryNode) getFirstSelectedObject();
    IEditorPart activeEditor = getActiveEditor();
    // remove frames draw last time
    for (BusinessItemShapeFigure shapFigure : repaintedFigures) {
        shapFigure.setDrawFrame(false);
        shapFigure.revalidate();
        shapFigure.repaint();
    }
    if (activeEditor instanceof BusinessDiagramEditor) {
        BusinessDiagramEditor businessDiagramEditor = (BusinessDiagramEditor) activeEditor;
        Diagram diagram = (Diagram) businessDiagramEditor.getDiagramEditPart().getModel();
        BusinessProcess businessProcess = (BusinessProcess) diagram.getElement();
        // PTODO mhelleboid use OCL or using a visitor
        List list = new ArrayList();
        for (Iterator iter = businessProcess.getBusinessItems().iterator(); iter.hasNext(); ) {
            BusinessItem businessItem = (BusinessItem) iter.next();
            for (Iterator iterator = businessItem.getAssignments().iterator(); iterator.hasNext(); ) {
                BusinessAssignment businessAssignment = (BusinessAssignment) iterator.next();
                TalendItem talendItem = businessAssignment.getTalendItem();
                IRepositoryViewObject obj = repositoryNode.getObject();
                if (talendItem.getId().equals(repositoryNode.getId())) {
                    list.add(businessItem);
                } else if (talendItem instanceof SQLPattern || talendItem instanceof Routine || talendItem instanceof TableMetadata || talendItem instanceof Query || talendItem instanceof SapFunctionMetadata) {
                    if (talendItem.getLabel().equals(repositoryNode.getProperties(EProperties.LABEL))) {
                        list.add(businessItem);
                    }
                }
            }
        }
        IDiagramGraphicalViewer diagramGraphicalViewer = businessDiagramEditor.getDiagramGraphicalViewer();
        List editParts = new ArrayList();
        for (Iterator iter = list.iterator(); iter.hasNext(); ) {
            BusinessItem businessItem = (BusinessItem) iter.next();
            editParts.addAll(diagramGraphicalViewer.findEditPartsForElement(EMFCoreUtil.getProxyID(businessItem), BaseBusinessItemRelationShipEditPart.class));
            editParts.addAll(diagramGraphicalViewer.findEditPartsForElement(EMFCoreUtil.getProxyID(businessItem), BusinessItemShapeEditPart.class));
        }
        diagramGraphicalViewer.deselectAll();
        // add a frame when use findAassignment
        for (Iterator iter = editParts.iterator(); iter.hasNext(); ) {
            EditPart editPart = (EditPart) iter.next();
            if (editPart instanceof BusinessItemShapeEditPart) {
                BusinessItemShapeEditPart shapEditPart = (BusinessItemShapeEditPart) editPart;
                IFigure figure = shapEditPart.getFigure();
                for (Object child : figure.getChildren()) {
                    if (child instanceof BusinessItemShapeFigure) {
                        BusinessItemShapeFigure shapFigure = (BusinessItemShapeFigure) child;
                        shapFigure.setDrawFrame(true);
                        shapFigure.revalidate();
                        shapFigure.repaint();
                        repaintedFigures.add(shapFigure);
                    }
                }
            }
            diagramGraphicalViewer.getSelectionManager().appendSelection(editPart);
        }
        ZoomManager zoomManager = (ZoomManager) businessDiagramEditor.getAdapter(ZoomManager.class);
        zoomFitSelection(zoomManager, editParts, businessDiagramEditor.getDiagramEditPart(), true);
    }
}
Also used : IDiagramGraphicalViewer(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer) SapFunctionMetadata(org.talend.designer.business.model.business.SapFunctionMetadata) BusinessDiagramEditor(org.talend.designer.business.model.business.diagram.part.BusinessDiagramEditor) BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) Query(org.talend.designer.business.model.business.Query) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) TalendItem(org.talend.designer.business.model.business.TalendItem) IFigure(org.eclipse.draw2d.IFigure) TableMetadata(org.talend.designer.business.model.business.TableMetadata) SQLPattern(org.talend.designer.business.model.business.SQLPattern) BusinessItemShapeEditPart(org.talend.designer.business.diagram.custom.edit.parts.BusinessItemShapeEditPart) DiagramEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) BaseBusinessItemRelationShipEditPart(org.talend.designer.business.diagram.custom.edit.parts.BaseBusinessItemRelationShipEditPart) IEditorPart(org.eclipse.ui.IEditorPart) Routine(org.talend.designer.business.model.business.Routine) RepositoryNode(org.talend.repository.model.RepositoryNode) BaseBusinessItemRelationShipEditPart(org.talend.designer.business.diagram.custom.edit.parts.BaseBusinessItemRelationShipEditPart) Diagram(org.eclipse.gmf.runtime.notation.Diagram) BusinessItemShapeEditPart(org.talend.designer.business.diagram.custom.edit.parts.BusinessItemShapeEditPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) BusinessItemShapeFigure(org.talend.designer.business.diagram.custom.figures.BusinessItemShapeFigure) BusinessItem(org.talend.designer.business.model.business.BusinessItem) BusinessProcess(org.talend.designer.business.model.business.BusinessProcess)

Example 3 with TalendItem

use of org.talend.designer.business.model.business.TalendItem in project tdi-studio-se by Talend.

the class BusinessAssignmentComposite method createSelectionListener.

private void createSelectionListener() {
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            BusinessAssignment businessAssignment = getBusinessAssignment(event.getSelection());
            if (businessAssignment != null) {
                final IRepositoryView repositoryView = getRepositoryView();
                if (repositoryView != null) {
                    IProjectRepositoryNode rootRepositoryNode = repositoryView.getRoot();
                    TalendItem item = businessAssignment.getTalendItem();
                    //
                    if (item instanceof Routine && rootRepositoryNode instanceof ProjectRepositoryNode) {
                        RepositoryNodeUtilities.expandParentNode(getRepositoryView(), ((ProjectRepositoryNode) rootRepositoryNode).getRootRepositoryNode(ERepositoryObjectType.CODE));
                    }
                    selectChild(item, (IRepositoryNode) rootRepositoryNode);
                }
            }
        }

        private void selectChild(TalendItem item, IRepositoryNode rootRepositoryNode) {
            try {
                RepositoryNode curNode = null;
                JobSettingsView viewer = (JobSettingsView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(JobSettingsView.ID);
                IRepositoryViewObject lastVersion = ProxyRepositoryFactory.getInstance().getLastVersion(item.getId());
                if (lastVersion != null) {
                    curNode = RepositoryNodeUtilities.getRepositoryNode(lastVersion);
                    select(viewer, curNode);
                } else if (item instanceof TableMetadata) {
                    MetadataTable table = MetadataToolHelper.getMetadataTableFromRepository(item.getId());
                    if (table != null) {
                        //$NON-NLS-1$
                        String id = item.getId().split(" - ")[0];
                        RepositoryNode node = RepositoryNodeUtilities.getMetadataTableFromConnection(item.getId());
                        IRepositoryView view = getRepositoryView();
                        if (view != null) {
                            RepositoryNodeUtilities.expandParentNode(view, node);
                            select(viewer, node);
                        }
                    }
                } else if (item instanceof Query) {
                    org.talend.core.model.metadata.builder.connection.Query query = MetadataToolHelper.getQueryFromRepository(item.getId());
                    if (query != null) {
                        //$NON-NLS-1$
                        String id = item.getId().split(" - ")[0];
                        IRepositoryView view = getRepositoryView();
                        RepositoryNode node = RepositoryNodeUtilities.getQueryFromConnection(item.getId());
                        RepositoryNodeUtilities.expandParentNode(view, node);
                        select(viewer, node);
                    }
                } else if (item instanceof SAPFunction) {
                    SAPFunctionUnit function = MetadataToolHelper.getSAPFunctionFromRepository(item.getId());
                    if (function != null) {
                        IRepositoryView view = getRepositoryView();
                        RepositoryNode node = RepositoryNodeUtilities.getSAPFunctionFromConnection(item.getId());
                        RepositoryNodeUtilities.expandParentNode(view, node);
                        select(viewer, node);
                    }
                } else {
                    for (IRepositoryNode node : rootRepositoryNode.getChildren()) {
                        RepositoryNode rNode = (RepositoryNode) node;
                        if (item instanceof SQLPattern && rNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.SQLPATTERNS) {
                            if (rNode.getType() == ENodeType.REPOSITORY_ELEMENT) {
                                SQLPatternItem sqlItem = (SQLPatternItem) rNode.getObject().getProperty().getItem();
                                if (sqlItem.isSystem() && item.getLabel().equals(rNode.getObject().getLabel())) {
                                    select(viewer, rNode);
                                }
                            } else {
                                selectChild(item, rNode);
                            }
                        } else if (item instanceof Routine && rNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.ROUTINES) {
                            if (rNode.getType() == ENodeType.REPOSITORY_ELEMENT) {
                                RoutineItem sqlItem = (RoutineItem) rNode.getObject().getProperty().getItem();
                                if (sqlItem.isBuiltIn() && item.getLabel().equals(rNode.getObject().getLabel())) {
                                    select(viewer, rNode);
                                }
                            } else {
                                selectChild(item, rNode);
                            }
                        }
                    }
                }
            } catch (PersistenceException e) {
                // TODO Auto-generated catch block
                // e.printStackTrace();
                ExceptionHandler.process(e);
            }
        }

        private void select(JobSettingsView viewer, RepositoryNode repositoryNode) {
            if (viewer == null) {
                return;
            }
            if (repositoryNode == null) {
                return;
            }
            CorePlugin.getDefault().getRepositoryService().removeRepositoryTreeViewListener(viewer);
            final IRepositoryView repositoryView = getRepositoryView();
            if (repositoryView != null) {
                repositoryView.getViewer().setSelection(new StructuredSelection(repositoryNode));
            }
            CorePlugin.getDefault().getRepositoryService().addRepositoryTreeViewListener(viewer);
        }
    });
}
Also used : JobSettingsView(org.talend.designer.core.ui.views.jobsettings.JobSettingsView) BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) Query(org.talend.designer.business.model.business.Query) SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IRepositoryView(org.talend.repository.ui.views.IRepositoryView) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode) TalendItem(org.talend.designer.business.model.business.TalendItem) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode) TableMetadata(org.talend.designer.business.model.business.TableMetadata) SAPFunction(org.talend.designer.business.model.business.SAPFunction) SQLPattern(org.talend.designer.business.model.business.SQLPattern) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) RoutineItem(org.talend.core.model.properties.RoutineItem) Routine(org.talend.designer.business.model.business.Routine) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 4 with TalendItem

use of org.talend.designer.business.model.business.TalendItem in project tdi-studio-se by Talend.

the class ClipboardActionHandler method saveCut.

private void saveCut(ISelection object) {
    cutItemIds = new HashMap();
    if (object instanceof IStructuredSelection) {
        for (Object obj : ((IStructuredSelection) object).toList()) {
            if (obj instanceof AbstractEditPart) {
                AbstractEditPart editPart = (AbstractEditPart) obj;
                EObject element = ((View) editPart.getModel()).getElement();
                if (element instanceof BusinessItem) {
                    BusinessItem businessItem = (BusinessItem) element;
                    List assignments = new ArrayList();
                    for (Object assignment : businessItem.getAssignments()) {
                        BusinessAssignment ba = (BusinessAssignment) assignment;
                        TalendItem item = ba.getTalendItem();
                        if (item != null) {
                            assignments.add(item.getId());
                        }
                    }
                    cutItemIds.put(businessItem, assignments);
                }
            }
        }
    }
}
Also used : BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) HashMap(java.util.HashMap) AbstractEditPart(org.eclipse.gef.editparts.AbstractEditPart) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TalendItem(org.talend.designer.business.model.business.TalendItem) View(org.eclipse.gmf.runtime.notation.View) BusinessItem(org.talend.designer.business.model.business.BusinessItem)

Example 5 with TalendItem

use of org.talend.designer.business.model.business.TalendItem in project tdi-studio-se by Talend.

the class CreateAssignmentCommand method doExecuteWithResult.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse
     * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
     */
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
    // PTODO mhelleboid check if assignment already exist
    RepositoryHelper repositoryHelper = new RepositoryHelper();
    Repository repository = businessItem.getBusinessProcess().getLocalRepositoryCopy();
    TalendItem talendItem = null;
    if (repository == null) {
        repository = repositoryHelper.createLocalRepositoryCopy(businessItem.getBusinessProcess());
    }
    for (Object item : getItems()) {
        BusinessAssignment assignment = BusinessFactory.eINSTANCE.createBusinessAssignment();
        talendItem = repositoryHelper.getTalendItem(repository, item);
        if (talendItem == null) {
            talendItem = repositoryHelper.createTalendItem(repository, item);
        }
        if (talendItem == null) {
            //$NON-NLS-1$
            return CommandResult.newErrorCommandResult(Messages.getString("CreateAssignmentCommand.CannotAssign"));
        }
        assignment.setBusinessItem(businessItem);
        assignment.setTalendItem(talendItem);
    }
    return CommandResult.newOKCommandResult();
}
Also used : Repository(org.talend.designer.business.model.business.Repository) BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) TalendItem(org.talend.designer.business.model.business.TalendItem) RepositoryHelper(org.talend.designer.business.diagram.custom.util.RepositoryHelper)

Aggregations

TalendItem (org.talend.designer.business.model.business.TalendItem)10 BusinessAssignment (org.talend.designer.business.model.business.BusinessAssignment)8 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)7 List (java.util.List)6 Routine (org.talend.designer.business.model.business.Routine)6 SQLPattern (org.talend.designer.business.model.business.SQLPattern)6 PersistenceException (org.talend.commons.exception.PersistenceException)5 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)5 SAPFunctionUnit (org.talend.core.model.metadata.builder.connection.SAPFunctionUnit)5 RepositoryNode (org.talend.repository.model.RepositoryNode)5 ArrayList (java.util.ArrayList)4 BusinessItem (org.talend.designer.business.model.business.BusinessItem)4 EObject (org.eclipse.emf.ecore.EObject)3 View (org.eclipse.gmf.runtime.notation.View)3 Query (org.talend.core.model.metadata.builder.connection.Query)3 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)3 Query (org.talend.designer.business.model.business.Query)3 TableMetadata (org.talend.designer.business.model.business.TableMetadata)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Image (org.eclipse.swt.graphics.Image)2