Search in sources :

Example 1 with FileItem

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

the class StandAloneTalendJavaEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);
    Bundle bundle = FrameworkUtil.getBundle(StandAloneTalendJavaEditor.class);
    lockService = bundle.getBundleContext().registerService(EventHandler.class.getName(), new EventHandler() {

        @Override
        public void handleEvent(Event event) {
            String lockTopic = Constant.REPOSITORY_ITEM_EVENT_PREFIX + Constant.ITEM_LOCK_EVENT_SUFFIX;
            if (lockTopic.equals(event.getTopic())) {
                if (!isEditable) {
                    Object o = event.getProperty(Constant.ITEM_EVENT_PROPERTY_KEY);
                    if (o instanceof FileItem) {
                        boolean isTheCorrectEditor = false;
                        Property property = ((FileItem) o).getProperty();
                        if (property != null) {
                            String eventItemId = property.getId();
                            //$NON-NLS-1$
                            String currentOpenedItemId = "";
                            if (rEditorInput != null) {
                                currentOpenedItemId = rEditorInput.getId();
                            }
                            isTheCorrectEditor = currentOpenedItemId.equals(eventItemId);
                        }
                        if (!isTheCorrectEditor) {
                            return;
                        }
                        item.getProperty().eAdapters().remove(dirtyListener);
                        item = (FileItem) o;
                        item.getProperty().eAdapters().add(dirtyListener);
                        if (isEditable()) {
                            isEditable = true;
                            rEditorInput.getFile().setReadOnly(false);
                            getSite().getShell().getDisplay().asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    setFocus();
                                    ISourceViewer viewer = getViewer();
                                    if (viewer != null) {
                                        StyledText styledText = viewer.getTextWidget();
                                        if (styledText != null) {
                                            styledText.setBackground(bgColorForEditabeItem);
                                            styledText.setDragDetect(true);
                                        }
                                    }
                                }
                            });
                            try {
                                ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
                                if (o instanceof RoutineItem) {
                                    ITalendSynchronizer routineSynchronizer = service.createJavaRoutineSynchronizer();
                                    routineSynchronizer.syncRoutine((RoutineItem) o, true);
                                } else if (o instanceof SQLPatternItem) {
                                    ISQLPatternSynchronizer sqlPatternSynchronizer = service.getSQLPatternSynchronizer();
                                    sqlPatternSynchronizer.syncSQLPattern((SQLPatternItem) o, true);
                                } else {
                                    //$NON-NLS-1$
                                    org.talend.commons.exception.ExceptionHandler.process(new Exception("Uncatched case"));
                                }
                                setName();
                            } catch (Exception e) {
                                org.talend.commons.exception.ExceptionHandler.process(e);
                            }
                        }
                    }
                }
            }
        }
    }, new Hashtable<String, String>(//$NON-NLS-1$
    Collections.singletonMap(EventConstants.EVENT_TOPIC, Constant.REPOSITORY_ITEM_EVENT_PREFIX + "*")));
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) StyledText(org.eclipse.swt.custom.StyledText) Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) ISQLPatternSynchronizer(org.talend.designer.codegen.ISQLPatternSynchronizer) EventHandler(org.osgi.service.event.EventHandler) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) FileItem(org.talend.core.model.properties.FileItem) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) ResourceChangeEvent(org.eclipse.core.internal.events.ResourceChangeEvent) Event(org.osgi.service.event.Event) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Property(org.talend.core.model.properties.Property)

Example 2 with FileItem

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

the class PropertyTypeController method createButtonCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createControl(org.eclipse
     * .swt.widgets.Composite, org.talend.core.model.process.IElementParameter, int, int, int,
     * org.eclipse.swt.widgets.Control)
     */
@Override
protected Command createButtonCommand(Button button) {
    // hwang add for feature 6484
    FileItem repositoryFileItem = null;
    LinkRulesItem linkItem = null;
    Map<String, FileItem> repositoryFileItemMap = null;
    Map<String, LinkRulesItem> repositoryLinkRulesItemMap = null;
    String paramName = (String) button.getData(PARAMETER_NAME);
    IElementParameter param = elem.getElementParameter(paramName);
    Object data = button.getData(NAME);
    if (data != null && data.equals(REPOSITORY_CHOICE)) {
        IElementParameter dbTypeParam = null;
        if (elem instanceof org.talend.designer.core.ui.editor.process.Process || elem instanceof StatsAndLogsElement || elem instanceof ImplicitContextLoadElement) {
            if (EParameterName.PROPERTY_TYPE.getName().equals(paramName)) {
                dbTypeParam = elem.getElementParameter(EParameterName.DB_TYPE.getName());
            } else if (JobSettingsConstants.getExtraParameterName(EParameterName.PROPERTY_TYPE.getName()).equals(paramName)) {
                dbTypeParam = elem.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.DB_TYPE.getName()));
            }
        }
        Item item = null;
        String id = null;
        RepositoryNode selectNode = null;
        if (id == null) {
            RepositoryReviewDialog dialog = null;
            if (dbTypeParam != null) {
                String[] listRepositoryItems = dbTypeParam.getListRepositoryItems();
                dialog = new RepositoryReviewDialog(Display.getCurrent().getActiveShell(), ERepositoryObjectType.METADATA, param.getRepositoryValue(), listRepositoryItems);
            } else {
                // Added TDQ-11688
                ITDQPatternService service = null;
                if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQPatternService.class)) {
                    service = (ITDQPatternService) GlobalServiceRegister.getDefault().getService(ITDQPatternService.class);
                }
                if (service != null && service.isSinglePatternNode(elem)) {
                    return processPattern(elem);
                }
                // ~
                dialog = new RepositoryReviewDialog(Display.getCurrent().getActiveShell(), ERepositoryObjectType.METADATA, elem, param);
            }
            if (dialog.open() == RepositoryReviewDialog.OK) {
                selectNode = dialog.getResult();
                id = selectNode.getObject().getId();
            }
        }
        if (id != null && !"".equals(id)) {
            //$NON-NLS-1$
            IElementParameter repositoryParam = param.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
            //$NON-NLS-1$
            String fullParamName = paramName + ":" + getRepositoryChoiceParamName();
            Connection repositoryConnection = null;
            // Map<String, ConnectionItem> repositoryConnectionItemMap =
            // dynamicProperty.getRepositoryConnectionItemMap();
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            try {
                IRepositoryViewObject repobj = factory.getLastVersion(id);
                if (repobj != null) {
                    Property property = repobj.getProperty();
                    if (property != null) {
                        item = property.getItem();
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
            if (item != null) {
                if (item instanceof ConnectionItem) {
                    repositoryConnection = ((ConnectionItem) item).getConnection();
                }
            } else {
                repositoryConnection = null;
                if (repositoryParam != null) {
                    item = selectNode.getObject().getProperty().getItem();
                    if (item instanceof ConnectionItem) {
                        repositoryConnection = ((ConnectionItem) item).getConnection();
                    }
                }
            }
            if (repositoryConnection != null) {
                CompoundCommand compoundCommand = new CompoundCommand();
                ChangeValuesFromRepository changeValuesFromRepository = null;
                if (selectNode.getObjectType() == ERepositoryObjectType.SERVICESOPERATION && GlobalServiceRegister.getDefault().isServiceRegistered(IESBService.class)) {
                    IESBService service = (IESBService) GlobalServiceRegister.getDefault().getService(IESBService.class);
                    IProcess2 process = (IProcess2) RepositoryPlugin.getDefault().getDesignerCoreService().getCurrentProcess();
                    String currentJobId = process.getProperty().getId();
                    String serviceId = item.getProperty().getId();
                    String portId = selectNode.getParent().getObject().getId();
                    String operationId = selectNode.getObject().getId();
                    changeValuesFromRepository = new ChangeValuesFromRepository(elem, repositoryConnection, param.getName() + ":" + //$NON-NLS-1$
                    EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), //$NON-NLS-1$ //$NON-NLS-2$
                    serviceId + " - " + portId + " - " + operationId);
                    service.deleteOldRelation(currentJobId);
                    //$NON-NLS-1$ //$NON-NLS-2$
                    service.updateOperation((INode) elem, serviceId + " - " + portId + " - " + operationId, selectNode);
                } else {
                    changeValuesFromRepository = new ChangeValuesFromRepository(elem, repositoryConnection, fullParamName, id);
                }
                if (changeValuesFromRepository != null) {
                    compoundCommand.add(changeValuesFromRepository);
                }
                updateDBType(compoundCommand, repositoryConnection);
                return compoundCommand;
            }
            // for ruleItem,hywang add
            if (dynamicProperty instanceof MultipleThreadDynamicComposite) {
                repositoryFileItemMap = ((MultipleThreadDynamicComposite) dynamicProperty).getRepositoryFileItemMap();
                repositoryLinkRulesItemMap = ((MultipleThreadDynamicComposite) dynamicProperty).getRepositoryLinkRulesItemMap();
            }
            if (repositoryFileItemMap.containsKey(id)) {
                repositoryFileItem = repositoryFileItemMap.get(id);
            } else if (repositoryLinkRulesItemMap.containsKey(id)) {
                linkItem = repositoryLinkRulesItemMap.get(id);
            } else {
                if (!repositoryFileItemMap.isEmpty()) {
                    repositoryFileItem = repositoryFileItemMap.values().iterator().next();
                } else {
                    repositoryFileItem = null;
                }
            }
            if (repositoryFileItem == null && item instanceof FileItem) {
                repositoryFileItem = (FileItem) item;
            }
            if (repositoryFileItem != null) {
                CompoundCommand compoundCommand = new CompoundCommand();
                final String showId = repositoryFileItem.getProperty().getId();
                Command command = new PropertyChangeCommand(elem, EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), showId);
                compoundCommand.add(command);
                return compoundCommand;
            }
            if (linkItem != null) {
                CompoundCommand compoundCommand = new CompoundCommand();
                final String showId = linkItem.getProperty().getId();
                Command command = new PropertyChangeCommand(elem, EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), showId);
                compoundCommand.add(command);
                return compoundCommand;
            }
        }
    } else {
        // 1. open wizard
        if (elem instanceof INode) {
            INode node = (INode) elem;
            final IRepositoryService repositoryService = CorePlugin.getDefault().getRepositoryService();
            if (param != null) {
                RepositoryNode realNode = null;
                String repositoryValue = param.getRepositoryValue();
                if (repositoryValue != null && repositoryValue.startsWith(ERepositoryCategoryType.DATABASE.getName())) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_CONNECTIONS);
                } else // file delimited
                if (ERepositoryCategoryType.DELIMITED.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_DELIMITED);
                }
                // file positional
                if (ERepositoryCategoryType.POSITIONAL.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_POSITIONAL);
                }
                // file regexp
                if (ERepositoryCategoryType.REGEX.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_REGEXP);
                }
                // file xml
                if (ERepositoryCategoryType.XML.getName().equals(repositoryValue) || // bug 18012
                repositoryValue.startsWith(ERepositoryCategoryType.XML.getName())) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_XML);
                }
                // file ldif
                if (ERepositoryCategoryType.LDIF.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_LDIF);
                }
                // excel
                if (ERepositoryCategoryType.EXCEL.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_EXCEL);
                }
                // generic schema
                if (ERepositoryCategoryType.GENERIC.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_GENERIC_SCHEMA);
                }
                // ldap
                if (ERepositoryCategoryType.LDAP.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_LDAP_SCHEMA);
                }
                // wsdl
                if (ERepositoryCategoryType.WSDL.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_WSDL_SCHEMA);
                }
                if (ERepositoryCategoryType.WEBSERVICE.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_WSDL_SCHEMA);
                }
                // salesforce
                if (ERepositoryCategoryType.SALESFORCE.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA);
                }
                // ebcdic
                if (ERepositoryCategoryType.EBCDIC.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_EBCDIC);
                }
                // mdm
                if (ERepositoryCategoryType.MDM.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_MDMCONNECTION);
                }
                // sap
                if (ERepositoryCategoryType.SAP.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_SAPCONNECTIONS);
                }
                // sapIDoc
                if (ERepositoryCategoryType.SAPIDOC.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_SAP_IDOC);
                }
                if (ERepositoryCategoryType.HEADERFOOTER.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_HEADER_FOOTER);
                }
                // brms
                if (ERepositoryCategoryType.BRMS.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_BRMS);
                }
                // hl7
                if (ERepositoryCategoryType.HL7.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_HL7);
                }
                // last resort we assume that the repository value was named after the root component type key
                if (realNode == null) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.getTypeFromKey(repositoryValue));
                }
                if (realNode != null) {
                    final IMetadataService metadataService = CorePlugin.getDefault().getMetadataService();
                    if (metadataService != null) {
                        ConnectionItem connItem = metadataService.openMetadataConnection(true, realNode, node);
                        if (connItem != null) {
                            IElementParameter propertyParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
                            propertyParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
                            // 2. commnd
                            Command cmd = new ChangeValuesFromRepository(node, connItem.getConnection(), //$NON-NLS-1$
                            propertyParam.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), connItem.getProperty().getId());
                            executeCommand(cmd);
                            // see bug in feature 5998.refresh repositoryList.
                            if (dynamicProperty instanceof MultipleThreadDynamicComposite) {
                                ((MultipleThreadDynamicComposite) dynamicProperty).updateRepositoryList();
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : INode(org.talend.core.model.process.INode) ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) MultipleThreadDynamicComposite(org.talend.designer.core.ui.views.properties.MultipleThreadDynamicComposite) IRepositoryService(org.talend.repository.model.IRepositoryService) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) FileItem(org.talend.core.model.properties.FileItem) IElementParameter(org.talend.core.model.process.IElementParameter) ITDQPatternService(org.talend.core.ITDQPatternService) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) CDCConnection(org.talend.core.model.metadata.builder.connection.CDCConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) RepositoryNode(org.talend.repository.model.RepositoryNode) RepositoryReviewDialog(org.talend.repository.ui.dialog.RepositoryReviewDialog) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) FileItem(org.talend.core.model.properties.FileItem) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IESBService(org.talend.core.IESBService) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ImplicitContextLoadElement(org.talend.designer.core.ui.projectsetting.ImplicitContextLoadElement) StatsAndLogsElement(org.talend.designer.core.ui.projectsetting.StatsAndLogsElement) IMetadataService(org.talend.repository.model.IMetadataService)

Example 3 with FileItem

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

the class MultipleThreadDynamicComposite method updateRepositoryList.

public void updateRepositoryList() {
    ProgressDialog progressDialog = new ProgressDialog(this.getShell(), 1000) {

        private IProgressMonitor monitorWrap;

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitorWrap = new EventLoopProgressMonitor(monitor);
            IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
            List<IRepositoryViewObject> repositoryObjects = getAllRepositoryMetadata();
            // + elem.getElementParameters().size();
            int total = repositoryObjects.size();
            //$NON-NLS-1$
            monitorWrap.beginTask(Messages.getString("MultipleThreadDynamicComposite.gatherInformation"), total);
            IElementParameter propertyParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, section);
            String repositoryValue = null;
            if (propertyParam != null) {
                repositoryValue = propertyParam.getRepositoryValue();
            }
            if (repositoryObjects != null && (repositoryObjects.size() != 0)) {
                tableIdAndDbTypeMap.clear();
                tableIdAndDbSchemaMap.clear();
                for (IRepositoryViewObject curObject : repositoryObjects) {
                    Item item = curObject.getProperty().getItem();
                    if (item instanceof ConnectionItem) {
                        ConnectionItem connectionItem = (ConnectionItem) item;
                        Connection connection = connectionItem.getConnection();
                        if (connection == null || connection.isReadOnly()) {
                            continue;
                        }
                        for (Object tableObj : ConnectionHelper.getTables(connection)) {
                            org.talend.core.model.metadata.builder.connection.MetadataTable table;
                            table = (org.talend.core.model.metadata.builder.connection.MetadataTable) tableObj;
                            if (factory.getStatus(connectionItem) != ERepositoryStatus.DELETED) {
                                if (!factory.isDeleted(table)) {
                                    IMetadataTable newTable = ConvertionHelper.convert(table);
                                    // newTable);
                                    if (connection instanceof DatabaseConnection) {
                                        String dbType = ((DatabaseConnection) connection).getDatabaseType();
                                        String schema = ((DatabaseConnection) connection).getUiSchema();
                                        tableIdAndDbTypeMap.put(newTable.getId(), dbType);
                                        if (schema != null && !schema.equals("")) {
                                            //$NON-NLS-1$
                                            tableIdAndDbSchemaMap.put(newTable.getId(), schema);
                                        }
                                    }
                                }
                            }
                        }
                        monitorWrap.worked(1);
                    }
                    // hywang add for feature 6484
                    if (item instanceof FileItem) {
                        FileItem FileItem = (FileItem) item;
                        if (repositoryValue != null) {
                            if (repositoryValue.equals("RULE")) {
                                //$NON-NLS-1$
                                repositoryFileItemMap.put(FileItem.getProperty().getId(), FileItem);
                            }
                        }
                        monitorWrap.worked(1);
                    }
                    if (item instanceof LinkRulesItem) {
                        LinkRulesItem linkItem = (LinkRulesItem) item;
                        if (repositoryValue != null) {
                            if (repositoryValue.equals("RULE")) {
                                //$NON-NLS-1$
                                repositoryLinkRulesItemMap.put(linkItem.getProperty().getId(), linkItem);
                            }
                        }
                        monitorWrap.worked(1);
                    }
                }
            }
            monitorWrap.done();
        }
    };
    try {
        progressDialog.executeProcess();
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
        return;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return;
    }
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) FileItem(org.talend.core.model.properties.FileItem) FileItem(org.talend.core.model.properties.FileItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 4 with FileItem

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

the class ControllerRepositoryValueHander method fastRepositoryUpdateProperty.

private void fastRepositoryUpdateProperty(IElementParameter param) {
    if (param != null && param.getValue() != null) {
        IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
        String linkedRepository = (String) param.getValue();
        // value stored is the id, so we can get this item directly
        Item item;
        String displayName = "";
        try {
            IRepositoryViewObject object = factory.getLastVersion(linkedRepository.split(" - ")[0]);
            if (object == null) {
                return;
            }
            item = object.getProperty().getItem();
            // Assert.isTrue(item instanceof ConnectionItem);
            IESBService service = null;
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IESBService.class)) {
                service = (IESBService) GlobalServiceRegister.getDefault().getService(IESBService.class);
            }
            if (service != null && ERepositoryObjectType.getItemType(item) == service.getServicesType()) {
                lastItemUsed = (ConnectionItem) item;
                displayName = "Service:" + service.getServiceLabel(item, linkedRepository);
            } else if (item instanceof ConnectionItem) {
                lastItemUsed = (ConnectionItem) item;
                displayName = //$NON-NLS-1$
                RepositoryObjectHelper.getRepositoryAliasName(lastItemUsed) + ":" + lastItemUsed.getProperty().getLabel();
            }
            if (item instanceof FileItem) {
                // hywang add for 6484
                lastFileItemUsed = (FileItem) item;
                if (lastFileItemUsed instanceof RulesItem) {
                    displayName = //$NON-NLS-1$
                    "Rules:" + lastFileItemUsed.getProperty().getLabel();
                }
            }
            if (item instanceof LinkRulesItem) {
                lastLinkItem = (LinkRulesItem) item;
                displayName = //$NON-NLS-1$
                "Rules:" + lastLinkItem.getProperty().getLabel();
            }
            if (StringUtils.isEmpty(displayName)) {
                ITDQPatternService tdqService = null;
                try {
                    tdqService = (ITDQPatternService) GlobalServiceRegister.getDefault().getService(ITDQPatternService.class);
                    if (tdqService != null) {
                        displayName = tdqService.getPatternDisplayName(item);
                    }
                } catch (RuntimeException e) {
                // nothing to do
                }
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
        param.setListItemsDisplayName(new String[] { displayName });
        param.setListItemsValue(new String[] { (String) param.getValue() });
    }
}
Also used : LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) RulesItem(org.talend.core.model.properties.RulesItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) Item(org.talend.core.model.properties.Item) FileItem(org.talend.core.model.properties.FileItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) FileItem(org.talend.core.model.properties.FileItem) IESBService(org.talend.core.IESBService) ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ITDQPatternService(org.talend.core.ITDQPatternService) RulesItem(org.talend.core.model.properties.RulesItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 5 with FileItem

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

the class ImportItemUtil method resetItemReference.

/**
     * 
     * cLi Comment method "resetItemReference".
     * 
     * resolve the encode some special character(bug 6252), maybe, It's not better to resolve this by manually.
     * 
     * such as, "[" is "%5B", "]" is "%5D", etc.
     */
@SuppressWarnings("unchecked")
private void resetItemReference(ItemRecord itemRecord, Resource resource) {
    Item item = itemRecord.getItem();
    EList<EObject> contents = resource.getContents();
    /*
         * ignore job. no need, because it can't be allowed input special char for name.
         */
    if (item instanceof ProcessItem) {
    // ((ProcessItem) item).setProcess((ProcessType) EcoreUtil.getObjectByType(contents,
    // TalendFilePackage.eINSTANCE
    // .getProcessType()));
    } else /*
         * ignore joblet. no need, because it can't be allowed input special char for name.
         */
    if (item instanceof JobletProcessItem) {
    // JobletProcessItem jobletProcessItem = (JobletProcessItem) item;
    //
    // jobletProcessItem.setJobletProcess((JobletProcess) EcoreUtil.getObjectByType(contents,
    // JobletPackage.eINSTANCE
    // .getJobletProcess()));
    // jobletProcessItem
    // .setIcon((ByteArray) EcoreUtil.getObjectByType(contents, PropertiesPackage.eINSTANCE.getByteArray()));
    } else // connectionItem
    if (item instanceof ConnectionItem) {
        ((ConnectionItem) item).setConnection((Connection) EcoreUtil.getObjectByType(contents, ConnectionPackage.eINSTANCE.getConnection()));
    } else // context
    if (item instanceof ContextItem) {
        EList contexts = ((ContextItem) item).getContext();
        contexts.clear();
        contexts.addAll(EcoreUtil.getObjectsByType(contents, TalendFilePackage.eINSTANCE.getContextType()));
    } else // file
    if (item instanceof FileItem) {
        /*
             * ignore routine, no need, because it can't be allowed input special char for name.
             */
        if (item instanceof RoutineItem) {
            return;
        }
        FileItem fileItem = (FileItem) item;
        fileItem.setContent((ByteArray) EcoreUtil.getObjectByType(contents, PropertiesPackage.eINSTANCE.getByteArray()));
    } else // snippet
    if (item instanceof SnippetItem) {
        EList variables = ((SnippetItem) item).getVariables();
        variables.clear();
        variables.addAll(EcoreUtil.getObjectsByType(contents, PropertiesPackage.eINSTANCE.getSnippetVariable()));
    } else // link doc
    if (item instanceof LinkDocumentationItem) {
        ((LinkDocumentationItem) item).setLink((LinkType) EcoreUtil.getObjectByType(contents, PropertiesPackage.eINSTANCE.getLinkType()));
    } else // business
    if (item instanceof BusinessProcessItem) {
        BusinessProcessItem businessProcessItem = (BusinessProcessItem) item;
        businessProcessItem.setSemantic((BusinessProcess) EcoreUtil.getObjectByType(contents, BusinessPackage.eINSTANCE.getBusinessProcess()));
        businessProcessItem.setNotationHolder((NotationHolder) EcoreUtil.getObjectByType(contents, PropertiesPackage.eINSTANCE.getNotationHolder()));
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) RoutineItem(org.talend.core.model.properties.RoutineItem) NotationHolder(org.talend.core.model.properties.NotationHolder) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) SnippetItem(org.talend.core.model.properties.SnippetItem) Item(org.talend.core.model.properties.Item) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) FolderItem(org.talend.core.model.properties.FolderItem) RoutineItem(org.talend.core.model.properties.RoutineItem) TDQItem(org.talend.core.model.properties.TDQItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) FileItem(org.talend.core.model.properties.FileItem) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) FileItem(org.talend.core.model.properties.FileItem) SnippetItem(org.talend.core.model.properties.SnippetItem) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EObject(org.eclipse.emf.ecore.EObject) BusinessProcess(org.talend.designer.business.model.business.BusinessProcess)

Aggregations

FileItem (org.talend.core.model.properties.FileItem)8 ConnectionItem (org.talend.core.model.properties.ConnectionItem)7 PersistenceException (org.talend.commons.exception.PersistenceException)6 Item (org.talend.core.model.properties.Item)6 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)6 LinkRulesItem (org.talend.core.model.properties.LinkRulesItem)5 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)5 Connection (org.talend.core.model.metadata.builder.connection.Connection)4 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)4 IElementParameter (org.talend.core.model.process.IElementParameter)4 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)4 EList (org.eclipse.emf.common.util.EList)3 Command (org.eclipse.gef.commands.Command)3 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)3 CDCConnection (org.talend.core.model.metadata.builder.connection.CDCConnection)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 EObject (org.eclipse.emf.ecore.EObject)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 IESBService (org.talend.core.IESBService)2