Search in sources :

Example 1 with IBrandingService

use of org.talend.core.ui.branding.IBrandingService in project tdi-studio-se by Talend.

the class ComponentsFactory method getComponentsLocation.

private File getComponentsLocation(String folder, AbstractComponentsProvider provider) {
    File file = null;
    try {
        if (provider != null) {
            file = provider.getInstallationFolder();
        } else {
            String componentsPath = IComponentsFactory.COMPONENTS_LOCATION;
            Bundle b = Platform.getBundle(componentsPath);
            IBrandingService breaningService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
            if (breaningService.isPoweredOnlyCamel()) {
                componentsPath = IComponentsFactory.CAMEL_COMPONENTS_LOCATION;
            }
            URL url = FileLocator.find(b, new Path(folder), null);
            if (url == null) {
                return null;
            }
            URL fileUrl = FileLocator.toFileURL(url);
            file = new File(fileUrl.getPath());
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return file;
}
Also used : Path(org.eclipse.core.runtime.Path) ComponentBundleToPath(org.talend.designer.core.model.components.ComponentBundleToPath) Bundle(org.osgi.framework.Bundle) ResourceBundle(java.util.ResourceBundle) IBrandingService(org.talend.core.ui.branding.IBrandingService) File(java.io.File) URL(java.net.URL) FileNotFoundException(java.io.FileNotFoundException) BusinessException(org.talend.commons.exception.BusinessException) IOException(java.io.IOException)

Example 2 with IBrandingService

use of org.talend.core.ui.branding.IBrandingService in project tdi-studio-se by Talend.

the class ComponentsFactory method loadComponentsFromFolder.

private void loadComponentsFromFolder(String pathSource, AbstractComponentsProvider provider) {
    boolean isCustom = false;
    if ("org.talend.designer.components.model.UserComponentsProvider".equals(provider.getId()) || "org.talend.designer.components.exchange.ExchangeComponentsProvider".equals(provider.getId())) {
        isCustom = true;
    }
    File source;
    try {
        source = provider.getInstallationFolder();
    } catch (IOException e1) {
        ExceptionHandler.process(e1);
        return;
    }
    File[] childDirectories;
    FileFilter fileFilter = new FileFilter() {

        @Override
        public boolean accept(final File file) {
            return file.isDirectory() && file.getName().charAt(0) != '.' && !file.getName().equals(IComponentsFactory.EXTERNAL_COMPONENTS_INNER_FOLDER);
        }
    };
    if (source == null) {
        //$NON-NLS-1$
        ExceptionHandler.process(new Exception(Messages.getString("ComponentsFactory.componentNotFound") + pathSource));
        return;
    }
    childDirectories = source.listFiles(fileFilter);
    IBrandingService service = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
    // String[] availableComponents = service.getBrandingConfiguration().getAvailableComponents();
    FileFilter skeletonFilter = new FileFilter() {

        @Override
        public boolean accept(final File file) {
            String fileName = file.getName();
            return file.isFile() && fileName.charAt(0) != '.' && (fileName.endsWith(SKELETON_SUFFIX) || fileName.endsWith(INCLUDEFILEINJET_SUFFIX));
        }
    };
    // Changed by Marvin Wang on Feb.22 for bug TDI-19166, caz the test ConnectionManagerTest maybe get the null
    // context.
    BundleContext context = null;
    if (Platform.getProduct() != null) {
        final Bundle definingBundle = Platform.getProduct().getDefiningBundle();
        if (definingBundle != null) {
            context = definingBundle.getBundleContext();
        }
    }
    if (context == null) {
        context = CodeGeneratorActivator.getDefault().getBundle().getBundleContext();
    }
    ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
    PackageAdmin admin = (PackageAdmin) context.getService(sref);
    String bundleName;
    if (!isCustom) {
        bundleName = admin.getBundle(provider.getClass()).getSymbolicName();
    } else {
        bundleName = IComponentsFactory.COMPONENTS_LOCATION;
    }
    if (childDirectories != null) {
        if (monitor != null) {
            this.subMonitor = SubMonitor.convert(monitor, Messages.getString("ComponentsFactory.load.components"), //$NON-NLS-1$
            childDirectories.length);
        }
        if (skeletonList != null) {
            // to optimize the size of the array
            skeletonList.ensureCapacity(childDirectories.length);
            for (File currentFolder : childDirectories) {
                // get the skeleton files first, then XML config files later.
                File[] skeletonFiles = currentFolder.listFiles(skeletonFilter);
                if (skeletonFiles != null) {
                    for (File file : skeletonFiles) {
                        // path
                        skeletonList.add(file.getAbsolutePath());
                    }
                }
                try {
                    File xmlMainFile = new File(currentFolder, ComponentFilesNaming.getInstance().getMainXMLFileName(currentFolder.getName(), getCodeLanguageSuffix()));
                    if (!xmlMainFile.exists()) {
                        // if not a component folder, ignore it.
                        continue;
                    }
                    String currentXmlSha1 = null;
                    try {
                        currentXmlSha1 = SHA1Util.calculateFromTextStream(new FileInputStream(xmlMainFile));
                    } catch (FileNotFoundException e) {
                    // nothing since exceptions are directly in the check bellow
                    }
                    // Need to check if this component is already in the cache or not.
                    // if yes, then we compare the sha1... and if different we reload the component
                    // if component is not in the cache, of course just load it!
                    ComponentsCache cache = ComponentManager.getComponentCache();
                    boolean foundComponentIsSame = false;
                    ComponentInfo existingComponentInfoInCache = null;
                    if (cache.getComponentEntryMap().containsKey(currentFolder.getName())) {
                        EList<ComponentInfo> infos = cache.getComponentEntryMap().get(currentFolder.getName());
                        for (ComponentInfo info : infos) {
                            if (StringUtils.equals(bundleName, info.getSourceBundleName())) {
                                existingComponentInfoInCache = info;
                                if (StringUtils.equals(info.getSha1(), currentXmlSha1)) {
                                    foundComponentIsSame = true;
                                }
                                // found component, no matter changed or not
                                break;
                            }
                        }
                    }
                    if (foundComponentIsSame) {
                        // it should go here mainly for commandline or if use like ctrl+shift+f3
                        if (componentsCache.containsKey(xmlMainFile.getAbsolutePath())) {
                            IComponent componentFromThisProvider = null;
                            for (IComponent component : componentsCache.get(xmlMainFile.getAbsolutePath()).values()) {
                                if (component instanceof EmfComponent) {
                                    if (bundleName.equals(((EmfComponent) component).getSourceBundleName())) {
                                        componentFromThisProvider = component;
                                        break;
                                    }
                                }
                            }
                            if (componentFromThisProvider != null) {
                                // In headless mode, we assume the components won't change and we will use a cache
                                componentList.add(componentFromThisProvider);
                                if (isCustom) {
                                    customComponentList.add(componentFromThisProvider);
                                }
                                continue;
                            }
                        }
                    }
                    if (!foundComponentIsSame) {
                        ComponentFileChecker.checkComponentFolder(currentFolder, getCodeLanguageSuffix());
                    }
                    String pathName = xmlMainFile.getAbsolutePath();
                    String applicationPath = ComponentBundleToPath.getPathFromBundle(bundleName);
                    // pathName = C:\myapp\plugins\myplugin\components\mycomponent\mycomponent.xml
                    pathName = (new Path(pathName)).toPortableString();
                    // pathName = C:/myapp/plugins/myplugin/components/mycomponent/mycomponent.xml
                    //$NON-NLS-1$
                    pathName = pathName.replace(applicationPath, "");
                    // pathName = /components/mycomponent/mycomponent.xml
                    // if not already in memory, just load the component from cache.
                    // if the component is already existing in cache and if it's the same, it won't reload all (cf
                    // flag: foundComponentIsSame)
                    EmfComponent currentComp = new EmfComponent(pathName, bundleName, xmlMainFile.getParentFile().getName(), pathSource, cache, foundComponentIsSame, provider);
                    if (!foundComponentIsSame) {
                        // force to call some functions to update the cache. (to improve)
                        currentComp.isVisibleInComponentDefinition();
                        currentComp.isTechnical();
                        currentComp.getOriginalFamilyName();
                        currentComp.getTranslatedFamilyName();
                        currentComp.getPluginExtension();
                        currentComp.getVersion();
                        currentComp.getModulesNeeded(null);
                        currentComp.getPluginDependencies();
                        // end of force cache update.
                        EList<ComponentInfo> componentsInfo = cache.getComponentEntryMap().get(currentFolder.getName());
                        for (ComponentInfo cInfo : componentsInfo) {
                            if (cInfo.getSourceBundleName().equals(bundleName)) {
                                cInfo.setSha1(currentXmlSha1);
                                break;
                            }
                        }
                        // this will force to save the cache later.
                        ComponentManager.setModified(true);
                    }
                    boolean hiddenComponent = false;
                    Collection<IComponentFactoryFilter> filters = ComponentsFactoryProviderManager.getInstance().getProviders();
                    for (IComponentFactoryFilter filter : filters) {
                        if (!filter.isAvailable(currentComp.getName())) {
                            hiddenComponent = true;
                            break;
                        }
                    }
                    // just don't load it
                    if (hiddenComponent && !(currentComp.getOriginalFamilyName().contains("Technical") || currentComp.isTechnical())) {
                        continue;
                    }
                    componentToProviderMap.put(currentComp, provider);
                    // hide it
                    if (hiddenComponent && (currentComp.getOriginalFamilyName().contains("Technical") || currentComp.isTechnical())) {
                        currentComp.setVisible(false);
                        currentComp.setTechnical(true);
                    }
                    if (provider.getId().contains("Camel")) {
                        currentComp.setPaletteType(ComponentCategory.CATEGORY_4_CAMEL.getName());
                    } else {
                        currentComp.setPaletteType(currentComp.getType());
                    }
                    if (componentList.contains(currentComp)) {
                        //$NON-NLS-1$ //$NON-NLS-2$
                        log.warn("Component " + currentComp.getName() + " already exists. Cannot load user version.");
                    } else {
                        // currentComp.setResourceBundle(getComponentResourceBundle(currentComp, source.toString(),
                        // null,
                        // provider));
                        currentComp.setProvider(provider);
                        componentList.add(currentComp);
                        if (isCustom) {
                            customComponentList.add(currentComp);
                        }
                        if (pathSource != null) {
                            Path userComponent = new Path(pathSource);
                            Path templatePath = new Path(IComponentsFactory.COMPONENTS_INNER_FOLDER + File.separatorChar + IComponentsFactory.EXTERNAL_COMPONENTS_INNER_FOLDER + File.separatorChar + ComponentUtilities.getExtFolder(OLD_COMPONENTS_USER_INNER_FOLDER));
                            if (userComponent.equals(templatePath)) {
                                userComponentList.add(currentComp);
                            }
                        }
                    }
                    // componentsCache only used bellow in case of headless (commandline) or if use like
                    // ctrl+shift+f3
                    String componentName = xmlMainFile.getAbsolutePath();
                    if (!componentsCache.containsKey(componentName)) {
                        componentsCache.put(componentName, new HashMap<String, IComponent>());
                    }
                    componentsCache.get(xmlMainFile.getAbsolutePath()).put(currentComp.getPaletteType(), currentComp);
                } catch (MissingMainXMLComponentFileException e) {
                    //$NON-NLS-1$ //$NON-NLS-2$
                    log.trace(currentFolder.getName() + " is not a " + getCodeLanguageSuffix() + " component", e);
                } catch (BusinessException e) {
                    BusinessException ex = new BusinessException(//$NON-NLS-1$ //$NON-NLS-2$
                    "Cannot load component \"" + currentFolder.getName() + "\": " + e.getMessage(), e);
                    ExceptionHandler.process(ex, Level.ERROR);
                }
                if (this.subMonitor != null) {
                    this.subMonitor.worked(1);
                }
                if (this.monitor != null && this.monitor.isCanceled()) {
                    return;
                }
            }
            // to optimize the size of the array
            skeletonList.trimToSize();
        }
    }
}
Also used : IComponent(org.talend.core.model.components.IComponent) IComponentFactoryFilter(org.talend.core.model.components.filters.IComponentFactoryFilter) FileNotFoundException(java.io.FileNotFoundException) BusinessException(org.talend.commons.exception.BusinessException) FileFilter(java.io.FileFilter) Path(org.eclipse.core.runtime.Path) ComponentBundleToPath(org.talend.designer.core.model.components.ComponentBundleToPath) Bundle(org.osgi.framework.Bundle) ResourceBundle(java.util.ResourceBundle) IOException(java.io.IOException) IBrandingService(org.talend.core.ui.branding.IBrandingService) ComponentsCache(org.talend.core.model.component_cache.ComponentsCache) FileNotFoundException(java.io.FileNotFoundException) BusinessException(org.talend.commons.exception.BusinessException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ServiceReference(org.osgi.framework.ServiceReference) PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) EmfComponent(org.talend.designer.core.model.components.EmfComponent) ComponentInfo(org.talend.core.model.component_cache.ComponentInfo) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 3 with IBrandingService

use of org.talend.core.ui.branding.IBrandingService in project tdi-studio-se by Talend.

the class ComponentsFactory method getComponentResourceBundle.

private ResourceBundle getComponentResourceBundle(IComponent currentComp, String source, String cachedPathSource, AbstractComponentsProvider provider) {
    try {
        AbstractComponentsProvider currentProvider = provider;
        if (currentProvider == null) {
            ComponentsProviderManager componentsProviderManager = ComponentsProviderManager.getInstance();
            Collection<AbstractComponentsProvider> providers = componentsProviderManager.getProviders();
            for (AbstractComponentsProvider curProvider : providers) {
                String path = new Path(curProvider.getInstallationFolder().toString()).toPortableString();
                if (source.startsWith(path)) {
                    // fix for TDI-19889 and TDI-20507 to get the correct component provider
                    if (cachedPathSource != null) {
                        if (path.contains(cachedPathSource)) {
                            currentProvider = curProvider;
                            break;
                        }
                    } else {
                        currentProvider = curProvider;
                        break;
                    }
                }
            }
        }
        String installPath = currentProvider.getInstallationFolder().toString();
        String label = ComponentFilesNaming.getInstance().getBundleName(currentComp.getName(), installPath.substring(installPath.lastIndexOf(IComponentsFactory.COMPONENTS_INNER_FOLDER)));
        if (currentProvider.isUseLocalProvider()) {
            // if the component use local provider as storage (for user / ecosystem components)
            // then get the bundle resource from the current main component provider.
            // note: code here to review later, service like this shouldn't be used...
            ResourceBundle bundle = null;
            IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
            if (brandingService.isPoweredOnlyCamel()) {
                bundle = currentProvider.getResourceBundle(label);
            } else {
                ITisLocalProviderService service = (ITisLocalProviderService) GlobalServiceRegister.getDefault().getService(ITisLocalProviderService.class);
                bundle = service.getResourceBundle(label);
            }
            return bundle;
        } else {
            ResourceBundle bundle = ResourceBundle.getBundle(label, Locale.getDefault(), new ResClassLoader(currentProvider.getClass().getClassLoader()));
            return bundle;
        }
    } catch (IOException e) {
        ExceptionHandler.process(e);
    }
    return null;
}
Also used : AbstractComponentsProvider(org.talend.core.model.components.AbstractComponentsProvider) Path(org.eclipse.core.runtime.Path) ComponentBundleToPath(org.talend.designer.core.model.components.ComponentBundleToPath) ResClassLoader(org.talend.designer.core.ITisLocalProviderService.ResClassLoader) ITisLocalProviderService(org.talend.designer.core.ITisLocalProviderService) ResourceBundle(java.util.ResourceBundle) IBrandingService(org.talend.core.ui.branding.IBrandingService) IOException(java.io.IOException)

Example 4 with IBrandingService

use of org.talend.core.ui.branding.IBrandingService in project tdi-studio-se by Talend.

the class ComponentsProviderManager method loadComponentsProvidersFromExtension.

private void loadComponentsProvidersFromExtension() {
    if (providers == null) {
        providers = new ArrayList<AbstractComponentsProvider>();
        IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
        //$NON-NLS-1$
        IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint("org.talend.core.components_provider");
        IExtension[] extensions = extensionPoint.getExtensions();
        for (IExtension extension : extensions) {
            IConfigurationElement[] configurationElements = extension.getConfigurationElements();
            for (IConfigurationElement configurationElement : configurationElements) {
                //$NON-NLS-1$
                String id = configurationElement.getAttribute("id");
                //$NON-NLS-1$
                String folderName = configurationElement.getAttribute("folderName");
                String contributerName = configurationElement.getContributor().getName();
                IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
                if (!brandingService.isPoweredOnlyCamel() && id.equals("org.talend.designer.camel.components.localprovider.CamelLocalComponentsProvider")) {
                    folderName = "camel";
                }
                try {
                    AbstractComponentsProvider componentsProvider = (AbstractComponentsProvider) configurationElement.createExecutableExtension(//$NON-NLS-1$
                    "class");
                    componentsProvider.setId(id);
                    componentsProvider.setFolderName(folderName);
                    componentsProvider.setContributer(contributerName);
                    providers.add(componentsProvider);
                } catch (CoreException e) {
                    //$NON-NLS-1$
                    log.error(Messages.getString("ComponentsProviderManager.unableLoad") + id, e);
                }
            }
        }
    }
}
Also used : AbstractComponentsProvider(org.talend.core.model.components.AbstractComponentsProvider) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) IExtension(org.eclipse.core.runtime.IExtension) IBrandingService(org.talend.core.ui.branding.IBrandingService) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 5 with IBrandingService

use of org.talend.core.ui.branding.IBrandingService in project tdi-studio-se by Talend.

the class ExchangeLoginTask method run.

/* (non-Javadoc)
     * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
     */
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    if (!PluginChecker.isExchangeSystemLoaded() || TalendPropertiesUtil.isHideExchange()) {
        return;
    }
    Job job = new //$NON-NLS-1$
    Job(//$NON-NLS-1$
    "Check Exchange") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            // check for Talendforge
            IPreferenceStore prefStore = PlatformUI.getPreferenceStore();
            boolean checkTisVersion = prefStore.getBoolean(ITalendCorePrefConstants.EXCHANGE_CHECK_TIS_VERSION);
            IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
            if (!checkTisVersion && brandingService.isPoweredbyTalend()) {
                int count = prefStore.getInt(TalendForgeDialog.LOGINCOUNT);
                if (count < 0) {
                    count = 1;
                }
                ExchangeUser exchangeUser = ProjectManager.getInstance().getCurrentProject().getExchangeUser();
                //$NON-NLS-1$
                boolean isExchangeLogon = exchangeUser.getLogin() != null && !exchangeUser.getLogin().equals("");
                boolean isUserPassRight = true;
                if (isExchangeLogon) {
                    IExchangeService service = (IExchangeService) GlobalServiceRegister.getDefault().getService(IExchangeService.class);
                    if (service.checkUserAndPass(exchangeUser.getUsername(), exchangeUser.getPassword()) != null) {
                        isUserPassRight = false;
                    }
                }
                if (!isExchangeLogon || !isUserPassRight) {
                    if ((count + 1) % 4 == 0) {
                        // if (Platform.getOS().equals(Platform.OS_LINUX)) {
                        // TalendForgeDialog tfDialog = new TalendForgeDialog(this.getShell(), project);
                        // tfDialog.open();
                        // } else {
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                Project project = ProjectManager.getInstance().getCurrentProject();
                                String userEmail = null;
                                if (project.getAuthor() != null) {
                                    userEmail = project.getAuthor().getLogin();
                                }
                                TalendForgeDialog tfDialog = new TalendForgeDialog(DisplayUtils.getDefaultShell(), userEmail);
                                tfDialog.setBlockOnOpen(true);
                                tfDialog.open();
                            }
                        });
                    }
                    prefStore.setValue(TalendForgeDialog.LOGINCOUNT, count + 1);
                }
            }
            return org.eclipse.core.runtime.Status.OK_STATUS;
        }
    };
    job.setSystem(true);
    job.setUser(false);
    job.setPriority(Job.INTERACTIVE);
    // start as soon as possible
    job.schedule();
}
Also used : IBrandingService(org.talend.core.ui.branding.IBrandingService) ExchangeUser(org.talend.core.model.properties.ExchangeUser) Project(org.talend.core.model.general.Project) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IExchangeService(org.talend.core.service.IExchangeService) Job(org.eclipse.core.runtime.jobs.Job) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) TalendForgeDialog(org.talend.registration.wizards.register.TalendForgeDialog)

Aggregations

IBrandingService (org.talend.core.ui.branding.IBrandingService)49 GridData (org.eclipse.swt.layout.GridData)11 GridLayout (org.eclipse.swt.layout.GridLayout)10 Composite (org.eclipse.swt.widgets.Composite)9 File (java.io.File)8 Button (org.eclipse.swt.widgets.Button)7 Shell (org.eclipse.swt.widgets.Shell)7 Path (org.eclipse.core.runtime.Path)6 URL (java.net.URL)5 Point (org.eclipse.swt.graphics.Point)5 Rectangle (org.eclipse.swt.graphics.Rectangle)5 Bundle (org.osgi.framework.Bundle)5 Project (org.talend.core.model.general.Project)5 CoreException (org.eclipse.core.runtime.CoreException)4 Text (org.eclipse.swt.widgets.Text)4 BusinessException (org.talend.commons.exception.BusinessException)4 IComponent (org.talend.core.model.components.IComponent)4 ConnectionBean (org.talend.core.model.general.ConnectionBean)4 IOException (java.io.IOException)3 ResourceBundle (java.util.ResourceBundle)3