Search in sources :

Example 1 with IComponentsLocalProviderService

use of org.talend.core.ui.services.IComponentsLocalProviderService in project tdi-studio-se by Talend.

the class Component method getNodeFormatIdWithoutFormatType.

private String getNodeFormatIdWithoutFormatType(String nodeLabel, String nodeFamily) {
    String ids = null;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsLocalProviderService.class)) {
        IComponentsLocalProviderService service = (IComponentsLocalProviderService) GlobalServiceRegister.getDefault().getService(IComponentsLocalProviderService.class);
        if (service != null) {
            ids = service.getPreferenceStore().getString(IComponentsLocalProviderService.FORMAT_IDS);
        }
    }
    String[] idArray = null;
    if (!StringUtils.isBlank(ids)) {
        idArray = ids.split(IComponentsLocalProviderService.IDS_SEPARATOR);
        String label = nodeLabel + IComponentsLocalProviderService.PALETTE_ENTRY_TYPE;
        for (String id : idArray) {
            if (id.contains(label)) {
                return nodeLabel + IComponentsLocalProviderService.PALETTE_ENTRY_TYPE;
            }
        }
        label = nodeFamily + IComponentsLocalProviderService.PALETTE_CONTAINER_TYPE;
        for (String id : idArray) {
            if (id.contains(label)) {
                return nodeFamily + IComponentsLocalProviderService.PALETTE_CONTAINER_TYPE;
            }
        }
        label = IComponentsLocalProviderService.PREFERENCE_TYPE_LABEL;
        for (String id : idArray) {
            if (id.contains(label)) {
                return IComponentsLocalProviderService.PREFERENCE_TYPE_LABEL;
            }
        }
        label = IComponentsLocalProviderService.PREFERENCE_TYPE_HINT;
        for (String id : idArray) {
            if (id.contains(label)) {
                return IComponentsLocalProviderService.PREFERENCE_TYPE_HINT;
            }
        }
        label = IComponentsLocalProviderService.PREFERENCE_TYPE_CONNECTION;
        for (String id : idArray) {
            if (id.contains(label)) {
                return IComponentsLocalProviderService.PREFERENCE_TYPE_CONNECTION;
            }
        }
        if (nodeFamily.contains("/")) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            String rootFamily = nodeFamily.split("/")[0];
            label = rootFamily + IComponentsLocalProviderService.PALETTE_CONTAINER_TYPE;
            for (String id : idArray) {
                if (id.contains(label)) {
                    return rootFamily + IComponentsLocalProviderService.PALETTE_CONTAINER_TYPE;
                }
            }
        }
    }
    return null;
}
Also used : IComponentsLocalProviderService(org.talend.core.ui.services.IComponentsLocalProviderService)

Example 2 with IComponentsLocalProviderService

use of org.talend.core.ui.services.IComponentsLocalProviderService in project tdi-studio-se by Talend.

the class NodePart method performRequest.

@Override
public void performRequest(Request req) {
    Node node = (Node) getModel();
    IExternalData oldExternalData = node.getExternalData();
    if (req.getType().equals(RequestConstants.REQ_OPEN)) {
        IExternalNode externalNode = null;
        if (node.isExternalNode()) {
            IElementParameter externalParam = node.getElementParameterFromField(EParameterFieldType.EXTERNAL);
            if (externalParam != null && externalParam.isShow(node.getElementParameters())) {
                externalNode = ExternalUtilities.getExternalNodeReadyToOpen(node);
            }
        }
        IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        if (externalNode != null && (part instanceof AbstractMultiPageTalendEditor)) {
            boolean isOriginalNode = false;
            ITestContainerProviderService testContainerService = null;
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
                testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
                if (testContainerService != null) {
                    isOriginalNode = testContainerService.isOriginalNode(node);
                    if (isOriginalNode) {
                        testContainerService.renameConnection(node, true);
                    }
                }
            }
            int returnValue = externalNode.open(getViewer().getControl().getShell());
            if (!node.isReadOnly()) {
                if (returnValue == SWT.OK) {
                    Command cmd = new ExternalNodeChangeCommand(node, externalNode, oldExternalData);
                    CommandStack cmdStack = (CommandStack) part.getAdapter(CommandStack.class);
                    cmdStack.execute(cmd);
                } else {
                    externalNode.setExternalData(oldExternalData);
                }
            }
            if (isOriginalNode && (testContainerService != null)) {
                testContainerService.renameConnection(node, false);
            }
        } else {
            // add for feature 13361
            boolean isJoblet = false;
            if (PluginChecker.isJobLetPluginLoaded()) {
                AbstractProcessProvider jobletProcessProvider = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
                final IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                boolean isAvoidShowJobletAfterDoubleClick = false;
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsLocalProviderService.class)) {
                    IComponentsLocalProviderService componentService = (IComponentsLocalProviderService) GlobalServiceRegister.getDefault().getService(IComponentsLocalProviderService.class);
                    if (componentService != null) {
                        isAvoidShowJobletAfterDoubleClick = componentService.isAvoidToShowJobletAfterDoubleClick();
                    }
                }
                if (service != null && service.isJobletComponent(node) && !isAvoidShowJobletAfterDoubleClick) {
                    isJoblet = true;
                    String version = (String) node.getPropertyValue(EParameterName.PROCESS_TYPE_VERSION.getName());
                    final Item jobletItem = jobletProcessProvider.getJobletItem(node, version);
                    RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>("", this) {

                        @Override
                        protected void run() throws LoginException, PersistenceException {
                            if (jobletItem != null) {
                                service.openJobletItem((JobletProcessItem) jobletItem);
                            }
                        }
                    };
                    repositoryWorkUnit.setAvoidUnloadResources(true);
                    CoreRuntimePlugin.getInstance().getProxyRepositoryFactory().executeRepositoryWorkUnit(repositoryWorkUnit);
                }
            }
            if (!isJoblet) {
                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                String processName = (String) node.getPropertyValue(EParameterName.PROCESS_TYPE_PROCESS.getName());
                String version = (String) node.getPropertyValue(EParameterName.PROCESS_TYPE_VERSION.getName());
                boolean isAvoidShowJobAfterDoubleClick = false;
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsLocalProviderService.class)) {
                    IComponentsLocalProviderService service = (IComponentsLocalProviderService) GlobalServiceRegister.getDefault().getService(IComponentsLocalProviderService.class);
                    if (service != null) {
                        isAvoidShowJobAfterDoubleClick = service.isAvoidToShowJobAfterDoubleClick();
                    }
                }
                // bug 20796
                boolean isSelectUseDynamic = false;
                Object useDynamicJobValue = node.getPropertyValue(EParameterName.USE_DYNAMIC_JOB.getName());
                if (useDynamicJobValue != null && useDynamicJobValue instanceof Boolean) {
                    isSelectUseDynamic = (Boolean) useDynamicJobValue;
                }
                if (processName != null && !"".equals(processName) && !isAvoidShowJobAfterDoubleClick && !isSelectUseDynamic) {
                    //$NON-NLS-1$
                    ItemCacheManager.clearCache();
                    ProcessItem processItem = ItemCacheManager.getProcessItem(processName, version);
                    if (processItem == null) {
                        return;
                    }
                    Property updatedProperty = null;
                    try {
                        updatedProperty = ProxyRepositoryFactory.getInstance().getLastVersion(new Project(ProjectManager.getInstance().getProject(processItem)), processName).getProperty();
                    } catch (PersistenceException e) {
                        CommonExceptionHandler.process(e);
                    }
                    // update the property of the node repository object
                    // node.getObject().setProperty(updatedProperty);
                    processItem = (ProcessItem) updatedProperty.getItem();
                    final ProcessItem item = processItem;
                    RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>("", this) {

                        @Override
                        protected void run() throws LoginException, PersistenceException {
                            try {
                                if (item != null) {
                                    ERepositoryObjectType repObjType = ERepositoryObjectType.getItemType(item);
                                    IJobEditorHandler editorInputFactory = JobEditorHandlerManager.getInstance().extractEditorInputFactory(repObjType.getType());
                                    editorInputFactory.openJobEditor(editorInputFactory.createJobEditorInput(item, true));
                                }
                            } catch (PartInitException e) {
                                MessageBoxExceptionHandler.process(e);
                            }
                        }
                    };
                    repositoryWorkUnit.setAvoidUnloadResources(true);
                    CoreRuntimePlugin.getInstance().getProxyRepositoryFactory().executeRepositoryWorkUnit(repositoryWorkUnit);
                } else {
                    try {
                        // modified for feature 2454.
                        page.showView(ComponentSettingsView.ID);
                    } catch (PartInitException e) {
                        CommonExceptionHandler.process(e);
                    }
                }
            }
        }
    }
    super.performRequest(req);
}
Also used : IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) AbstractProcessProvider(org.talend.designer.core.model.process.AbstractProcessProvider) IComponentsLocalProviderService(org.talend.core.ui.services.IComponentsLocalProviderService) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IElementParameter(org.talend.core.model.process.IElementParameter) PartInitException(org.eclipse.ui.PartInitException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) IExternalNode(org.talend.core.model.process.IExternalNode) CommandStack(org.eclipse.gef.commands.CommandStack) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) IJobEditorHandler(org.talend.core.ui.editor.IJobEditorHandler) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) Point(org.eclipse.draw2d.geometry.Point) ExternalNodeChangeCommand(org.talend.designer.core.ui.editor.cmd.ExternalNodeChangeCommand) IJobletProviderService(org.talend.core.ui.IJobletProviderService) Project(org.talend.core.model.general.Project) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ExternalNodeChangeCommand(org.talend.designer.core.ui.editor.cmd.ExternalNodeChangeCommand) Command(org.eclipse.gef.commands.Command) PersistenceException(org.talend.commons.exception.PersistenceException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IExternalData(org.talend.core.model.process.IExternalData)

Example 3 with IComponentsLocalProviderService

use of org.talend.core.ui.services.IComponentsLocalProviderService in project tdi-studio-se by Talend.

the class Component method addViewParameters.

public void addViewParameters(final List<ElementParameter> listParam, INode node) {
    ElementParameter param;
    IPreferenceStore localComponentProviderStore = null;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsLocalProviderService.class)) {
        IComponentsLocalProviderService service = (IComponentsLocalProviderService) GlobalServiceRegister.getDefault().getService(IComponentsLocalProviderService.class);
        if (service != null) {
            localComponentProviderStore = service.getPreferenceStore();
        }
    }
    String formatId = getNodeFormatIdWithoutFormatType(getName(), getTranslatedFamilyName());
    param = new ElementParameter(node);
    param.setName(EParameterName.LABEL.getName());
    param.setDisplayName(EParameterName.LABEL.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.VIEW);
    param.setNumRow(1);
    param.setReadOnly(false);
    param.setRequired(false);
    param.setShow(true);
    if (formatId != null) {
        if (localComponentProviderStore != null) {
            String label = localComponentProviderStore.getString(IComponentsLocalProviderService.PREFERENCE_TYPE_LABEL);
            if (!"".equals(label)) {
                //$NON-NLS-1$
                param.setValue(label);
            }
        }
    } else {
        // in case label/format is not set in the preferences.
        String label = DesignerPlugin.getDefault().getPreferenceStore().getString(TalendDesignerPrefConstants.DEFAULT_LABEL);
        if (!"".equals(label)) {
            //$NON-NLS-1$
            param.setValue(label);
        }
    }
    param.setDefaultValue(param.getValue());
    listParam.add(param);
    param = new ElementParameter(node);
    param.setName(EParameterName.HINT.getName());
    param.setDisplayName(EParameterName.HINT.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.VIEW);
    param.setNumRow(2);
    param.setReadOnly(false);
    param.setRequired(false);
    param.setShow(true);
    if (formatId != null) {
        if (localComponentProviderStore != null) {
            String label = localComponentProviderStore.getString(IComponentsLocalProviderService.PREFERENCE_TYPE_HINT);
            if (!"".equals(label)) {
                //$NON-NLS-1$
                param.setValue(label);
            }
        }
    } else {
        // in case hint/format is not set in the preferences.
        String label = DesignerPlugin.getDefault().getPreferenceStore().getString(TalendDesignerPrefConstants.DEFAULT_HINT);
        if (!"".equals(label)) {
            //$NON-NLS-1$
            param.setValue(label);
        }
    }
    param.setDefaultValue(param.getValue());
    listParam.add(param);
    param = new ElementParameter(node);
    param.setName(EParameterName.CONNECTION_FORMAT.getName());
    param.setDisplayName(EParameterName.CONNECTION_FORMAT.getDisplayName());
    param.setFieldType(EParameterFieldType.TEXT);
    param.setCategory(EComponentCategory.VIEW);
    param.setNumRow(3);
    param.setReadOnly(false);
    param.setRequired(false);
    param.setShow(true);
    if (formatId != null) {
        if (localComponentProviderStore != null) {
            String label = localComponentProviderStore.getString(IComponentsLocalProviderService.PREFERENCE_TYPE_CONNECTION);
            if (!"".equals(label)) {
                //$NON-NLS-1$
                param.setValue(label);
            }
        }
    }
    param.setDefaultValue(param.getValue());
    listParam.add(param);
}
Also used : IComponentsLocalProviderService(org.talend.core.ui.services.IComponentsLocalProviderService) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 4 with IComponentsLocalProviderService

use of org.talend.core.ui.services.IComponentsLocalProviderService in project tdi-studio-se by Talend.

the class ComponentInstaller method unzip.

/**
     * Unzip the component file to user folder.
     * 
     * @param zipFile The component zip file
     * @param targetFolder The user folder
     * @return
     * @throws Exception
     */
@SuppressWarnings("unchecked")
public static File unzip(String zipFile, String targetFolder) throws Exception {
    ZipFile zip = new ZipFile(zipFile);
    // folder that contains all the unzipped files
    File rootFolder = getRootFolder(zip, targetFolder);
    if (rootFolder == null) {
        // the zip does not have any directory, fix it
        String fileName = new File(zip.getName()).getName();
        // remove extension
        fileName = fileName.substring(0, fileName.lastIndexOf('.'));
        Pattern pattern = Pattern.compile("^([\\w]*)");
        Matcher matcher = pattern.matcher(fileName);
        if (matcher.find()) {
            fileName = matcher.group(1);
        }
        rootFolder = new File(targetFolder, fileName);
        targetFolder = targetFolder + File.separatorChar + fileName;
    }
    if (rootFolder.exists()) {
        // we have installed older revision, delete it
        FileUtils.deleteDirectory(rootFolder);
    }
    rootFolder.mkdir();
    // move some common use codes for unzipping file to FilesUtils
    FilesUtils.unzip(zipFile, targetFolder);
    boolean valid = false;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsLocalProviderService.class)) {
        IComponentsLocalProviderService service = (IComponentsLocalProviderService) GlobalServiceRegister.getDefault().getService(IComponentsLocalProviderService.class);
        if (service != null) {
            valid = service.validateComponent(rootFolder.getAbsolutePath(), LanguageManager.getCurrentLanguage());
        }
    }
    if (!valid) {
        if (rootFolder.exists() && rootFolder.isDirectory()) {
            for (File f : rootFolder.listFiles()) {
                f.delete();
            }
            rootFolder.delete();
        }
        return null;
    }
    return rootFolder;
}
Also used : Pattern(java.util.regex.Pattern) IComponentsLocalProviderService(org.talend.core.ui.services.IComponentsLocalProviderService) ZipFile(java.util.zip.ZipFile) Matcher(java.util.regex.Matcher) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

IComponentsLocalProviderService (org.talend.core.ui.services.IComponentsLocalProviderService)4 IElementParameter (org.talend.core.model.process.IElementParameter)2 File (java.io.File)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ZipFile (java.util.zip.ZipFile)1 Point (org.eclipse.draw2d.geometry.Point)1 Command (org.eclipse.gef.commands.Command)1 CommandStack (org.eclipse.gef.commands.CommandStack)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1 PartInitException (org.eclipse.ui.PartInitException)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 Project (org.talend.core.model.general.Project)1 IExternalData (org.talend.core.model.process.IExternalData)1 IExternalNode (org.talend.core.model.process.IExternalNode)1 INode (org.talend.core.model.process.INode)1 Item (org.talend.core.model.properties.Item)1 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)1