Search in sources :

Example 11 with BusinessAssignment

use of org.talend.designer.business.model.business.BusinessAssignment 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)

Example 12 with BusinessAssignment

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

the class RepositoryFactoryProxyLabelProvider method getColumnImage.

@Override
public Image getColumnImage(Object object, int columnIndex) {
    Image image = super.getColumnImage(object, columnIndex);
    BusinessAssignment assignment = (BusinessAssignment) object;
    try {
        if (columnIndex == 0) {
            IRepositoryViewObject lastVersion = getLastVersion(object);
            if (lastVersion == null) {
                MetadataTable table = MetadataToolHelper.getMetadataTableFromRepository(assignment.getTalendItem().getId());
                if (table != null) {
                    return image;
                }
                Query query = MetadataToolHelper.getQueryFromRepository(assignment.getTalendItem().getId());
                if (query != null) {
                    return image;
                }
                SAPFunctionUnit function = MetadataToolHelper.getSAPFunctionFromRepository(assignment.getTalendItem().getId());
                if (function != null) {
                    return image;
                }
                TalendItem item = assignment.getTalendItem();
                if (item instanceof SQLPattern) {
                    List<IRepositoryViewObject> list = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.SQLPATTERNS);
                    for (IRepositoryViewObject obj : list) {
                        if (item.getLabel().equals(obj.getLabel())) {
                            return image;
                        }
                    }
                } else if (item instanceof Routine) {
                    List<IRepositoryViewObject> list = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.ROUTINES);
                    for (IRepositoryViewObject obj : list) {
                        if (item.getLabel().equals(obj.getLabel())) {
                            return image;
                        }
                    }
                }
                return new OverlayImage(image, ImageProvider.getImageDesc(ECoreImage.DELETED_OVERLAY), EPosition.BOTTOM_RIGHT).createImage();
            } else if (isDeleted(lastVersion)) {
                return new OverlayImage(image, ImageProvider.getImageDesc(ECoreImage.RECYCLE_BIN_OVERLAY), EPosition.BOTTOM_RIGHT).createImage();
            }
        }
    } catch (PersistenceException e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
    return image;
}
Also used : SQLPattern(org.talend.designer.business.model.business.SQLPattern) BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) Query(org.talend.core.model.metadata.builder.connection.Query) SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) Routine(org.talend.designer.business.model.business.Routine) Image(org.eclipse.swt.graphics.Image) OverlayImage(org.talend.commons.ui.runtime.image.OverlayImage) ECoreImage(org.talend.commons.ui.runtime.image.ECoreImage) OverlayImage(org.talend.commons.ui.runtime.image.OverlayImage) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) PersistenceException(org.talend.commons.exception.PersistenceException) List(java.util.List) TalendItem(org.talend.designer.business.model.business.TalendItem)

Example 13 with BusinessAssignment

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

the class RepositoryFactoryProxyLabelProvider method getColumnText.

@Override
public String getColumnText(Object object, int columnIndex) {
    String columnText = super.getColumnText(object, columnIndex);
    BusinessAssignment assignment = (BusinessAssignment) object;
    IRepositoryViewObject lastVersion = getLastVersion(object);
    try {
        if (columnIndex == 0) {
            if (lastVersion == null) {
                MetadataTable table = MetadataToolHelper.getMetadataTableFromRepository(assignment.getTalendItem().getId());
                if (table != null) {
                    if (SubItemHelper.isDeleted(table)) {
                        //$NON-NLS-1$
                        columnText += Messages.getString("RepositoryFactoryProxyLabelProvider.Deleted");
                    }
                    return columnText;
                }
                Query query = MetadataToolHelper.getQueryFromRepository(assignment.getTalendItem().getId());
                if (query != null) {
                    if (SubItemHelper.isDeleted(query)) {
                        //$NON-NLS-1$
                        columnText += Messages.getString("RepositoryFactoryProxyLabelProvider.Deleted");
                    }
                    return columnText;
                }
                SAPFunctionUnit function = MetadataToolHelper.getSAPFunctionFromRepository(assignment.getTalendItem().getId());
                if (function != null) {
                    if (SubItemHelper.isDeleted(function)) {
                        //$NON-NLS-1$
                        columnText += Messages.getString("RepositoryFactoryProxyLabelProvider.Deleted");
                    }
                    return columnText;
                }
                TalendItem item = assignment.getTalendItem();
                if (item instanceof SQLPattern) {
                    List<IRepositoryViewObject> list = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.SQLPATTERNS);
                    for (IRepositoryViewObject obj : list) {
                        if (item.getLabel().equals(obj.getLabel())) {
                            return columnText;
                        }
                    }
                } else if (item instanceof Routine) {
                    List<IRepositoryViewObject> list = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.ROUTINES);
                    for (IRepositoryViewObject obj : list) {
                        if (item.getLabel().equals(obj.getLabel())) {
                            return columnText;
                        }
                    }
                }
                //$NON-NLS-1$
                columnText += Messages.getString("RepositoryFactoryProxyLabelProvider.NotFound");
            } else if (isDeleted(lastVersion)) {
                //$NON-NLS-1$
                columnText += Messages.getString("RepositoryFactoryProxyLabelProvider.Deleted");
            }
        }
    } catch (PersistenceException e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
    if (columnIndex == 1) {
        if (lastVersion != null) {
            String label = lastVersion.getProperty().getLabel();
            if (!label.equals(columnText)) {
                ChangeTalendItemLabelCommand command = new ChangeTalendItemLabelCommand(((BusinessAssignment) object).getTalendItem(), label);
                try {
                    command.execute(null, null);
                } catch (ExecutionException e) {
                }
                return label;
            }
        }
    }
    return columnText;
}
Also used : SQLPattern(org.talend.designer.business.model.business.SQLPattern) BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) Query(org.talend.core.model.metadata.builder.connection.Query) SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) ChangeTalendItemLabelCommand(org.talend.designer.business.diagram.custom.commands.ChangeTalendItemLabelCommand) Routine(org.talend.designer.business.model.business.Routine) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) PersistenceException(org.talend.commons.exception.PersistenceException) List(java.util.List) TalendItem(org.talend.designer.business.model.business.TalendItem) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 14 with BusinessAssignment

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

the class ElementHelper method updateTooltipFigure.

/**
     * DOC Administrator Comment method "getTooltipFigure".
     * 
     * @param figure
     */
public void updateTooltipFigure(Figure figure, BusinessTooltipFigure tooltipFigure, EditPart editPart) {
    EObject element = ((View) editPart.getModel()).getElement();
    if (element instanceof BusinessItem) {
        List assignements = ((BusinessItem) element).getAssignments();
        BusinessItemProviderAdapterFactory adapterFactory = new BusinessItemProviderAdapterFactory();
        BusinessAssignmentItemProvider provider = (BusinessAssignmentItemProvider) adapterFactory.createBusinessAssignmentAdapter();
        Image img = null;
        Label label = null;
        List<Label> labels = new ArrayList();
        try {
            for (Object assignment : assignements) {
                if (assignment instanceof BusinessAssignment) {
                    TalendItem talendItem = ((BusinessAssignment) assignment).getTalendItem();
                    if (talendItem != null) {
                        IRepositoryViewObject obj = CorePlugin.getDefault().getProxyRepositoryFactory().getLastVersion(talendItem.getId());
                        if (obj != null) {
                            ERepositoryObjectType type = obj.getRepositoryObjectType();
                            Item item = obj.getProperty().getItem();
                            if (item instanceof JobletProcessItem) {
                                JobletProcessItem jobletItem = (JobletProcessItem) item;
                                Image jobletCustomIcon = RepositoryLabelProvider.getJobletCustomIcon(jobletItem.getProperty());
                                if (jobletCustomIcon != null) {
                                    img = ImageUtils.scale(jobletCustomIcon, ICON_SIZE.ICON_16);
                                }
                            } else {
                                img = CoreImageProvider.getImage(type);
                            }
                            //$NON-NLS-1$ //$NON-NLS-2$
                            label = new Label(obj.getLabel() + " (" + provider.getColumnText(assignment, 0) + ")", img);
                            labels.add(label);
                        } else {
                            MetadataTable table = MetadataToolHelper.getMetadataTableFromRepository(talendItem.getId());
                            Query query = MetadataToolHelper.getQueryFromRepository(talendItem.getId());
                            SAPFunctionUnit function = MetadataToolHelper.getSAPFunctionFromRepository(talendItem.getId());
                            if (table != null) {
                                img = ImageDescriptor.createFromFile(ECoreImage.class, ECoreImage.METADATA_TABLE_ICON.getPath()).createImage();
                                label = new Label(talendItem.getLabel() + " (" + provider.getColumnText(assignment, 0) + ")", //$NON-NLS-1$ //$NON-NLS-2$
                                img);
                                labels.add(label);
                            } else if (query != null) {
                                img = ImageDescriptor.createFromFile(ECoreImage.class, ECoreImage.METADATA_QUERY_ICON.getPath()).createImage();
                                label = new Label(talendItem.getLabel() + " (" + provider.getColumnText(assignment, 0) + ")", //$NON-NLS-1$ //$NON-NLS-2$
                                img);
                                labels.add(label);
                            } else if (talendItem instanceof SQLPattern) {
                                List<IRepositoryViewObject> list = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.SQLPATTERNS);
                                for (IRepositoryViewObject object : list) {
                                    if (talendItem.getLabel().equals(object.getLabel())) {
                                        img = ImageDescriptor.createFromFile(ECoreImage.class, ECoreImage.METADATA_SQLPATTERN_ICON.getPath()).createImage();
                                        label = new Label(//$NON-NLS-1$
                                        talendItem.getLabel() + " (" + provider.getColumnText(assignment, 0) + ")", //$NON-NLS-1$
                                        img);
                                        labels.add(label);
                                    }
                                }
                            } else if (talendItem instanceof Routine) {
                                List<IRepositoryViewObject> list = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.ROUTINES);
                                for (IRepositoryViewObject object : list) {
                                    if (talendItem.getLabel().equals(object.getLabel())) {
                                        img = ImageDescriptor.createFromFile(ECoreImage.class, ECoreImage.ROUTINE_ICON.getPath()).createImage();
                                        label = new Label(//$NON-NLS-1$
                                        talendItem.getLabel() + " (" + provider.getColumnText(assignment, 0) + ")", //$NON-NLS-1$
                                        img);
                                        labels.add(label);
                                    }
                                }
                            } else if (function != null) {
                                img = ImageDescriptor.createFromFile(ECoreImage.class, ECoreImage.METADATA_SAPCONNECTION_ICON.getPath()).createImage();
                                label = new Label(talendItem.getLabel() + " (" + provider.getColumnText(assignment, 0) + ")", //$NON-NLS-1$ //$NON-NLS-2$
                                img);
                                labels.add(label);
                            } else {
                                img = (Image) provider.getImage(assignment);
                                img = new OverlayImage(img, ImageProvider.getImageDesc(ECoreImage.DELETED_OVERLAY), EPosition.BOTTOM_RIGHT).createImage();
                                String text = provider.getText(assignment) + " (" + provider.getColumnText(assignment, 0) + //$NON-NLS-1$ //$NON-NLS-2$
                                ")";
                                label = new Label(text, img);
                                labels.add(label);
                            }
                        }
                    }
                }
            }
            if (tooltipFigure == null) {
                tooltipFigure = new BusinessTooltipFigure();
            }
            if (labels.size() == 0) {
                figure.setToolTip(null);
            } else {
                tooltipFigure.buildFigures(labels);
                figure.setToolTip(tooltipFigure);
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) Query(org.talend.core.model.metadata.builder.connection.Query) SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) Label(org.eclipse.draw2d.Label) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) OverlayImage(org.talend.commons.ui.runtime.image.OverlayImage) ECoreImage(org.talend.commons.ui.runtime.image.ECoreImage) BusinessItem(org.talend.designer.business.model.business.BusinessItem) Item(org.talend.core.model.properties.Item) TalendItem(org.talend.designer.business.model.business.TalendItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) BusinessItemProviderAdapterFactory(org.talend.designer.business.model.business.provider.BusinessItemProviderAdapterFactory) BusinessAssignmentItemProvider(org.talend.designer.business.model.business.provider.BusinessAssignmentItemProvider) EObject(org.eclipse.emf.ecore.EObject) OverlayImage(org.talend.commons.ui.runtime.image.OverlayImage) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ECoreImage(org.talend.commons.ui.runtime.image.ECoreImage) ArrayList(java.util.ArrayList) List(java.util.List) TalendItem(org.talend.designer.business.model.business.TalendItem) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) SQLPattern(org.talend.designer.business.model.business.SQLPattern) BusinessTooltipFigure(org.talend.designer.business.diagram.custom.figures.BusinessTooltipFigure) Routine(org.talend.designer.business.model.business.Routine) View(org.eclipse.gmf.runtime.notation.View) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) EObject(org.eclipse.emf.ecore.EObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) BusinessItem(org.talend.designer.business.model.business.BusinessItem)

Example 15 with BusinessAssignment

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

the class BusinessAssignmentComposite method createPopupMenu.

private void createPopupMenu() {
    //$NON-NLS-1$
    MenuManager menuMgr = new MenuManager("#PopUp");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager mgr) {
            BusinessAssignment businessAssignment = getBusinessAssignment(tableViewer.getSelection());
            if (businessAssignment != null) {
                repositoryNode = createRepositoryNode(businessAssignment);
                if (repositoryNode != null) {
                    List<ITreeContextualAction> contextualsActions = ActionsHelper.getRepositoryContextualsActions();
                    for (ITreeContextualAction action : contextualsActions) {
                        if (action.isReadAction() || action.isEditAction() || action.isPropertiesAction()) {
                            action.init(null, new StructuredSelection(repositoryNode));
                            if (action.isVisible()) {
                                ((AContextualAction) action).setAvoidUnloadResources(true);
                                mgr.add(action);
                            }
                        }
                    }
                    if (ProjectManager.getInstance().isInCurrentMainProject(repositoryNode)) {
                        CorePlugin.getDefault().getDiagramModelService().addDeleteAssignmentAction(mgr, tableViewer.getSelection());
                    }
                }
            }
        }
    });
    Menu menu = menuMgr.createContextMenu(tableViewer.getControl());
    tableViewer.getControl().setMenu(menu);
}
Also used : BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) List(java.util.List) IMenuManager(org.eclipse.jface.action.IMenuManager) ITreeContextualAction(org.talend.commons.ui.swt.actions.ITreeContextualAction) Menu(org.eclipse.swt.widgets.Menu) IMenuListener(org.eclipse.jface.action.IMenuListener)

Aggregations

BusinessAssignment (org.talend.designer.business.model.business.BusinessAssignment)16 List (java.util.List)9 TalendItem (org.talend.designer.business.model.business.TalendItem)8 ArrayList (java.util.ArrayList)6 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)6 BusinessItem (org.talend.designer.business.model.business.BusinessItem)6 Routine (org.talend.designer.business.model.business.Routine)5 SQLPattern (org.talend.designer.business.model.business.SQLPattern)5 Iterator (java.util.Iterator)4 EObject (org.eclipse.emf.ecore.EObject)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 PersistenceException (org.talend.commons.exception.PersistenceException)4 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)4 SAPFunctionUnit (org.talend.core.model.metadata.builder.connection.SAPFunctionUnit)4 View (org.eclipse.gmf.runtime.notation.View)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 Query (org.talend.core.model.metadata.builder.connection.Query)3 RepositoryNode (org.talend.repository.model.RepositoryNode)3 HashMap (java.util.HashMap)2 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2