Search in sources :

Example 6 with EUpdateItemType

use of org.talend.core.model.update.EUpdateItemType in project tdi-studio-se by Talend.

the class UpdateManagerUtils method executeUpdate.

private static void executeUpdate(UpdateResult result, IProgressMonitor monitor, boolean updateAllJobs) {
    if (result.isReadOnlyProcess()) {
        return;
    }
    // update
    Command command = null;
    IUpdateItemType updateType = result.getUpdateType();
    if (updateType instanceof EUpdateItemType) {
        switch((EUpdateItemType) updateType) {
            case NODE_PROPERTY:
            case NODE_SCHEMA:
            case NODE_QUERY:
            case NODE_SAP_IDOC:
            case NODE_SAP_FUNCTION:
            case NODE_VALIDATION_RULE:
                command = new UpdateNodeParameterCommand(result);
                break;
            case JOB_PROPERTY_EXTRA:
            case JOB_PROPERTY_STATS_LOGS:
            case JOB_PROPERTY_HEADERFOOTER:
            case JOB_PROPERTY_STORM:
            case JOB_PROPERTY_MAPREDUCE:
                command = new UpdateMainParameterCommand(result);
                break;
            case CONTEXT:
                command = executeContextUpdates(result);
                break;
            case CONTEXT_GROUP:
                command = executeContextGroupUpdates(result);
                break;
            case JOBLET_RENAMED:
            case JOBLET_SCHEMA:
            case RELOAD:
                command = executeJobletNodesUpdates(result);
                break;
            case JUNIT_RELOAD:
                command = executeJunitNodesUpdates(result);
                break;
            // break;
            case MAP_PATH:
                command = new UpdateNodePathCommand(result);
                break;
            default:
                break;
        }
    }
    if (command != null) {
        SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1 * UpdatesConstants.SCALE, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
        subMonitor.beginTask(UpdatesConstants.EMPTY, 1);
        subMonitor.subTask(getResultTaskInfor(result));
        //
        Object job = result.getJob();
        boolean executed = false;
        if (job != null && job instanceof IGEFProcess) {
            IDesignerCoreUIService designerCoreUIService = CoreUIPlugin.getDefault().getDesignerCoreUIService();
            if (designerCoreUIService != null) {
                executed = designerCoreUIService.executeCommand((IGEFProcess) job, command);
            }
        }
        if (!executed) {
            command.execute();
        }
        subMonitor.worked(1);
    }
    // from extension point
    UpdateManagerProviderDetector.INSTANCE.doUpdate(monitor, result);
}
Also used : UpdateNodeParameterCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateNodeParameterCommand) UpdateContextParameterCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateContextParameterCommand) UpdateNodePathCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateNodePathCommand) Command(org.eclipse.gef.commands.Command) UpdateMainParameterCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateMainParameterCommand) UpdateJobletNodeCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateJobletNodeCommand) UpdateNodeParameterCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateNodeParameterCommand) UpdateJunitNodeCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateJunitNodeCommand) UpdateMainParameterCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateMainParameterCommand) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) UpdateNodePathCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateNodePathCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IDesignerCoreUIService(org.talend.core.ui.services.IDesignerCoreUIService) EUpdateItemType(org.talend.core.model.update.EUpdateItemType) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IGEFProcess(org.talend.core.ui.process.IGEFProcess)

Example 7 with EUpdateItemType

use of org.talend.core.model.update.EUpdateItemType in project tdi-studio-se by Talend.

the class UpdateNodePathCommand method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.commands.Command#execute()
     */
@Override
public void execute() {
    IUpdateItemType updateType = result.getUpdateType();
    if (result == null || updateType == null) {
        return;
    }
    Object updateObject = result.getUpdateObject();
    if (updateObject == null || (!(updateObject instanceof Node))) {
        return;
    }
    // instance of node before might not be good (loaded while check updates needed)
    // so get the instance of the node of the current job in this object.
    IProcess process = (IProcess) result.getJob();
    for (INode node : process.getGraphicalNodes()) {
        if (node.getUniqueName().equals(((Node) updateObject).getUniqueName())) {
            updateObject = node;
            result.setUpdateObject(updateObject);
            break;
        }
    }
    Node node = (Node) updateObject;
    if (updateType instanceof EUpdateItemType) {
        switch((EUpdateItemType) updateType) {
            case MAP_PATH:
                Object parameter = result.getParameter();
                if (!(parameter instanceof List)) {
                    return;
                }
                List<Object> params = (List<Object>) parameter;
                if (params.size() != 3) {
                    return;
                }
                IElementParameter param = (IElementParameter) params.get(0);
                if (param == null) {
                    return;
                }
                String oldPath = (String) params.get(1);
                String newPath = (String) params.get(2);
                String relativeNewPath = new Path(newPath).removeFirstSegments(2).removeFileExtension().toPortableString();
                String fullOldPath = new Path(oldPath).removeFileExtension().toPortableString();
                String relativeOldPath = new Path(oldPath).removeFirstSegments(2).removeFileExtension().toPortableString();
                Object value = TalendTextUtils.removeQuotes(String.valueOf(param.getValue()));
                if (!fullOldPath.equals(value) && !relativeOldPath.equals(value)) {
                    return;
                }
                if (fullOldPath.equals(value)) {
                    String newValue = TalendTextUtils.addQuotes(new Path(newPath).removeFileExtension().toPortableString());
                    param.setValue(newValue);
                } else if (relativeOldPath.equals(value)) {
                    param.setValue(TalendTextUtils.addQuotes(relativeNewPath));
                }
                break;
            default:
        }
    }
    if (node.getProcess() instanceof IProcess2) {
        PropertyChangeCommand pcc = new PropertyChangeCommand(node, EParameterName.UPDATE_COMPONENTS.getName(), Boolean.TRUE);
        boolean executed = false;
        if (process instanceof IGEFProcess) {
            IDesignerCoreUIService designerCoreUIService = CoreUIPlugin.getDefault().getDesignerCoreUIService();
            if (designerCoreUIService != null) {
                executed = designerCoreUIService.executeCommand((IGEFProcess) process, pcc);
            }
        }
        if (!executed) {
            pcc.execute();
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) INode(org.talend.core.model.process.INode) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) IDesignerCoreUIService(org.talend.core.ui.services.IDesignerCoreUIService) EUpdateItemType(org.talend.core.model.update.EUpdateItemType) IGEFProcess(org.talend.core.ui.process.IGEFProcess) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IProcess2(org.talend.core.model.process.IProcess2) IElementParameter(org.talend.core.model.process.IElementParameter) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) List(java.util.List) IProcess(org.talend.core.model.process.IProcess)

Example 8 with EUpdateItemType

use of org.talend.core.model.update.EUpdateItemType in project tdi-studio-se by Talend.

the class UpdateLabelProvider method getColumnImage.

@Override
public Image getColumnImage(Object element, int columnIndex) {
    // try to use extension first.
    Object image = UpdateManagerProviderDetector.INSTANCE.getDisplayImage(element, columnIndex);
    if (image == null && columnIndex == 0) {
        if (element instanceof Job) {
            Job job = (Job) element;
            if (job.isJoblet()) {
                image = ECoreImage.JOBLET_ICON;
            } else if (job.isSparkJoblet()) {
                image = ECoreImage.PROCESS_BATCH_SPARK_ICON;
            } else if (job.isSparkStreamingJoblet()) {
                image = ECoreImage.PROCESS_STREAMING_SPARK_ICON;
            } else {
                org.talend.core.model.properties.Item item = job.getModelItem();
                if (item != null) {
                    image = CoreImageProvider.getIcon(item);
                } else {
                    if (job.isMR() || job.isStreaming()) {
                        for (ERepositoryObjectType type : (ERepositoryObjectType[]) ERepositoryObjectType.values()) {
                            String alias = type.getAlias();
                            if (alias != null && alias.equals("HC")) {
                                image = CoreImageProvider.getIcon(type);
                            }
                        }
                    } else {
                        image = ECoreImage.PROCESS_ICON;
                    }
                }
            }
        } else if (element instanceof Category) {
            Category category = (Category) element;
            IUpdateItemType type = category.getType();
            if (type != null) {
                if (type instanceof EUpdateItemType) {
                    switch((EUpdateItemType) type) {
                        case JOB_PROPERTY_EXTRA:
                        case JOB_PROPERTY_STATS_LOGS:
                        case JOB_PROPERTY_HEADERFOOTER:
                            image = ECoreImage.PROCESS_ICON;
                            break;
                        case CONTEXT:
                        case CONTEXT_GROUP:
                            // case JOBLET_CONTEXT:
                            image = ECoreImage.CONTEXT_ICON;
                            break;
                        case NODE_PROPERTY:
                        case NODE_SCHEMA:
                        case NODE_QUERY:
                        case NODE_SAP_IDOC:
                        case NODE_SAP_FUNCTION:
                        case NODE_VALIDATION_RULE:
                        case JOBLET_SCHEMA:
                        case JOBLET_RENAMED:
                        case JUNIT_RELOAD:
                        case RELOAD:
                        case MAP_PATH:
                            image = getImageFromNode(category.getNode());
                            break;
                        case JOB_PROPERTY_STORM:
                        case JOB_PROPERTY_MAPREDUCE:
                            for (ERepositoryObjectType etype : (ERepositoryObjectType[]) ERepositoryObjectType.values()) {
                                String alias = etype.getAlias();
                                if (alias != null && alias.equals("HC")) {
                                    image = CoreImageProvider.getImage(etype);
                                }
                            }
                            break;
                        default:
                    }
                } else {
                    // try to git image via type
                    image = UpdateManagerProviderDetector.INSTANCE.getDisplayImage(type, columnIndex);
                }
            }
        } else if (element instanceof Item) {
            Item item = (Item) element;
            IUpdateItemType updateType = item.getResultObject().getUpdateType();
            if (updateType instanceof EUpdateItemType) {
                switch((EUpdateItemType) updateType) {
                    case NODE_QUERY:
                        image = ECoreImage.METADATA_QUERY_ICON;
                        break;
                    case NODE_SCHEMA:
                    case JOBLET_SCHEMA:
                        image = ECoreImage.METADATA_TABLE_ICON;
                        break;
                    case NODE_PROPERTY:
                    case NODE_VALIDATION_RULE:
                    case JOB_PROPERTY_EXTRA:
                    case JOB_PROPERTY_STATS_LOGS:
                    case JOB_PROPERTY_STORM:
                    case JOB_PROPERTY_MAPREDUCE:
                        ERepositoryObjectType type = RepositoryUpdateManager.getTypeFromSource(item.getRemark());
                        if (type != null) {
                            image = CoreImageProvider.getIcon(type);
                        }
                    case JOBLET_RENAMED:
                    case RELOAD:
                    // return ImageProvider.getImage(ECoreImage.TALEND_PICTO);
                    case CONTEXT:
                    case CONTEXT_GROUP:
                    // return ImageProvider.getImage(ECoreImage.CONTEXT_ICON);
                    default:
                }
            } else {
                // try to git image via type
                image = UpdateManagerProviderDetector.INSTANCE.getDisplayImage(updateType, columnIndex);
            }
        }
    }
    if (image != null) {
        ECoreImage warnOverlay = ECoreImage.WARN_OVERLAY;
        EPosition position = EPosition.BOTTOM_RIGHT;
        if (image instanceof IImage) {
            if (checkElementForUpdate(element)) {
                return OverlayImageProvider.getImageForOverlay((IImage) image, warnOverlay, position);
            }
            return ImageProvider.getImage((IImage) image);
        } else if (image instanceof Image) {
            if (checkElementForUpdate(element)) {
                return OverlayImageProvider.getImageForOverlay((Image) image, warnOverlay, position);
            }
            return (Image) image;
        }
    }
    return null;
}
Also used : EUpdateItemType(org.talend.core.model.update.EUpdateItemType) IImage(org.talend.commons.ui.runtime.image.IImage) Image(org.eclipse.swt.graphics.Image) ECoreImage(org.talend.commons.ui.runtime.image.ECoreImage) EPosition(org.talend.commons.ui.runtime.image.OverlayImage.EPosition) ECoreImage(org.talend.commons.ui.runtime.image.ECoreImage) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) IImage(org.talend.commons.ui.runtime.image.IImage) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 9 with EUpdateItemType

use of org.talend.core.model.update.EUpdateItemType in project tdi-studio-se by Talend.

the class UpdateJunitNodeCommand method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.commands.Command#execute()
     */
@Override
public void execute() {
    Object job = result.getJob();
    if (job == null) {
        return;
    }
    if (job instanceof IProcess2) {
        Item item = ((IProcess2) job).getProperty().getItem();
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
            ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
            if (testContainerService != null) {
                boolean isTestContainer = testContainerService.isTestContainerItem(item);
                if (!isTestContainer) {
                    return;
                }
                IUpdateItemType updateType = result.getUpdateType();
                if (updateType instanceof EUpdateItemType) {
                    switch((EUpdateItemType) updateType) {
                        case JUNIT_RELOAD:
                            List<Node> junitsNodes = (List<Node>) result.getUpdateObject();
                            if (junitsNodes != null && !junitsNodes.isEmpty()) {
                                for (Node node : junitsNodes) {
                                    testContainerService.reloadJunitsNodes(node);
                                }
                            }
                        default:
                    }
                }
            }
        }
    }
}
Also used : Item(org.talend.core.model.properties.Item) Node(org.talend.designer.core.ui.editor.nodes.Node) IProcess2(org.talend.core.model.process.IProcess2) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) List(java.util.List) EUpdateItemType(org.talend.core.model.update.EUpdateItemType) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService)

Aggregations

EUpdateItemType (org.talend.core.model.update.EUpdateItemType)9 IUpdateItemType (org.talend.core.model.update.IUpdateItemType)8 List (java.util.List)6 INode (org.talend.core.model.process.INode)5 IProcess (org.talend.core.model.process.IProcess)5 Node (org.talend.designer.core.ui.editor.nodes.Node)5 IProcess2 (org.talend.core.model.process.IProcess2)4 PropertyChangeEvent (java.beans.PropertyChangeEvent)3 IElementParameter (org.talend.core.model.process.IElementParameter)3 Item (org.talend.core.model.properties.Item)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 IGEFProcess (org.talend.core.ui.process.IGEFProcess)3 IDesignerCoreUIService (org.talend.core.ui.services.IDesignerCoreUIService)3 ArrayList (java.util.ArrayList)2 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)2 Process (org.talend.designer.core.ui.editor.process.Process)2 Collection (java.util.Collection)1 Map (java.util.Map)1 Path (org.eclipse.core.runtime.Path)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1