Search in sources :

Example 11 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project tdi-studio-se by Talend.

the class JSONShadowProcessHelper method createPreview.

/**
     * DOC amaumont Comment method "createPreview".
     * 
     * @param configurationElements
     * @return
     * @throws CoreException
     */
private static IPreview createPreview(String type) throws CoreException {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    // use the org.talend.repository.filepreview_provider
    IConfigurationElement[] configurationElements = registry.getConfigurationElementsFor(//$NON-NLS-1$
    "org.talend.core.runtime.filepreview_provider");
    // When start a new preview. need stop before preview.
    forceStopPreview();
    IPreview preview = null;
    if (configurationElements.length > 0) {
        //$NON-NLS-1$
        preview = (IPreview) configurationElements[0].createExecutableExtension("class");
    }
    for (IConfigurationElement configurationElement : configurationElements) {
        //$NON-NLS-1$
        String fileType = configurationElement.getAttribute("type");
        // to do this just make sure the code behaviour is same like before
        if (type == null && fileType != null) {
            // current type(null value, means should use the default)
            continue;
        } else if (type != null) {
            // want to create a specified previewer for a specified type
            if (fileType == null) {
                // means this is a gereral previewer, not good for a specified type
                continue;
            } else if (!fileType.equals(type)) {
                continue;
            }
        }
        //$NON-NLS-1$
        IPreview pre = (IPreview) configurationElement.createExecutableExtension("class");
        if (!PluginChecker.isOnlyTopLoaded() && !pre.isTopPreview()) {
            preview = pre;
        }
    }
    if (preview == null) {
        log.error(//$NON-NLS-1$
        Messages.getString("ShadowProcessHelper.logError.previewIsNull01") + //$NON-NLS-1$
        Messages.getString("ShadowProcessHelper.logError.previewIsNull02"));
    }
    currentPreview = preview;
    return preview;
}
Also used : IPreview(org.talend.core.repository.model.preview.IPreview) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 12 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project tdi-studio-se by Talend.

the class ProjectSettingDialog method getNodeManager.

/**
     * get all projectsettingPage node dynamic. need get the different result each time. because the tester will calc
     * dymamic.
     * 
     * @return PreferenceManager
     */
private PreferenceManager getNodeManager() {
    // PreferenceManager manager = new PreferenceManager(WorkbenchPlugin.PREFERENCE_PAGE_CATEGORY_SEPARATOR);
    PreferenceManager manager = new PreferenceManager('/');
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IConfigurationElement[] configurationElements = registry.getConfigurationElementsFor(//$NON-NLS-1$
    "org.talend.repository.projectsetting_page");
    Map<String, List<IPreferenceNode>> hasCategoriesNodes = new HashMap<String, List<IPreferenceNode>>();
    for (IConfigurationElement element : configurationElements) {
        ProjectSettingNode node = new ProjectSettingNode(element);
        try {
            //$NON-NLS-1$
            IPreferencePage page = (IPreferencePage) element.createExecutableExtension("class");
            node.setPage(page);
            //$NON-NLS-1$
            String id = element.getAttribute("id");
            IConfigurationElement[] testers = element.getChildren("tester");
            if (testers != null && testers.length == 1) {
                // currently, only one tester is supported.
                try {
                    IProjectSettingPageTester pageTester = (IProjectSettingPageTester) testers[0].createExecutableExtension("class");
                    if (pageTester != null) {
                        if (!pageTester.valid(element, node)) {
                            // don't add this page node.
                            continue;
                        }
                    }
                } catch (CoreException ex) {
                    // can't create the tester
                    log.log(Level.WARN, "can't create the project setting tester for " + id, ex);
                }
            }
            //$NON-NLS-1$
            page.setDescription(element.getAttribute("description"));
            //$NON-NLS-1$
            page.setTitle(element.getAttribute("title"));
        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
        // add all into root.
        manager.addToRoot(node);
        // has category
        String category = node.getCategory();
        if (category != null && category.length() > 0) {
            List<IPreferenceNode> list = hasCategoriesNodes.get(category);
            if (list == null) {
                list = new ArrayList<IPreferenceNode>();
                hasCategoriesNodes.put(category, list);
            }
            list.add(node);
        }
    }
    // add the speciall node for maven custom
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IMavenUIService.class)) {
        IMavenUIService mavenUIService = (IMavenUIService) GlobalServiceRegister.getDefault().getService(IMavenUIService.class);
        IPreferenceNode mavenCostomSetup = manager.find("projectsetting.MavenCustomSetup");
        mavenUIService.addCustomMavenSettingChildren(mavenCostomSetup);
    }
    // find parent nodes for category
    Map<String, IPreferenceNode> parentNodesMap = new HashMap<String, IPreferenceNode>();
    for (String category : hasCategoriesNodes.keySet()) {
        IPreferenceNode parent = manager.find(category);
        if (parent != null) {
            parentNodesMap.put(category, parent);
        }
    }
    // process children nodes
    for (String category : hasCategoriesNodes.keySet()) {
        List<IPreferenceNode> list = hasCategoriesNodes.get(category);
        if (list != null) {
            IPreferenceNode parent = parentNodesMap.get(category);
            Collections.sort(list, COMPARATOR);
            for (IPreferenceNode node : list) {
                // if the parent is not valid or not existed. the node won't show also.
                // remove from root node.
                manager.remove(node);
                if (parent != null) {
                    // the parent existed.
                    parent.add(node);
                }
            }
        }
    }
    // sort the root nodes
    List<IPreferenceNode> rootSubNodesList = new ArrayList<IPreferenceNode>(Arrays.asList(manager.getRootSubNodes()));
    Collections.sort(rootSubNodesList, COMPARATOR);
    // clean all to re-add for order
    manager.removeAll();
    // add the sorted list to manager
    for (IPreferenceNode rootSubNode : rootSubNodesList) {
        manager.addToRoot(rootSubNode);
    }
    return manager;
}
Also used : ProjectSettingNode(org.talend.repository.model.ProjectSettingNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode) PreferenceManager(org.eclipse.jface.preference.PreferenceManager) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) CoreException(org.eclipse.core.runtime.CoreException) IPreferencePage(org.eclipse.jface.preference.IPreferencePage) ArrayList(java.util.ArrayList) List(java.util.List) IMavenUIService(org.talend.core.runtime.services.IMavenUIService) IProjectSettingPageTester(org.talend.core.runtime.preference.IProjectSettingPageTester) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 13 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project tdi-studio-se by Talend.

the class ModuleListController method createCommand.

public Command createCommand(Button button) {
    Node node = (Node) elem;
    IExternalNode externalNode = ExternalUtilities.getExternalNodeReadyToOpen(node);
    if (externalNode != null && externalNode.getUniqueName().contains("tBRMS_")) {
        IConfigurationElement[] elems = Platform.getExtensionRegistry().getConfigurationElementsFor("org.talend.designer.core.brms_provider");
        String propertyName = (String) button.getData(PARAMETER_NAME);
        for (IConfigurationElement conElem : elems) {
            IBrmsExtension createExecutableExtension;
            try {
                createExecutableExtension = (IBrmsExtension) conElem.createExecutableExtension("class");
                createExecutableExtension.initialize(node, propertyName, hashCurControls);
                BrmsDialog brmsDialog = createExecutableExtension.createBrmsDialog(composite.getShell());
                String file = brmsDialog.getFile();
                if (file != null && !file.equals("")) {
                    String lastSegment = TalendTextUtils.addQuotes(Path.fromOSString(file).lastSegment());
                    try {
                        CorePlugin.getDefault().getLibrariesService().deployLibrary(Path.fromOSString(file).toFile().toURL());
                    } catch (Exception e) {
                        ExceptionHandler.process(e);
                    }
                    // update the combo current value
                    CCombo combo = (CCombo) hashCurControls.get(propertyName);
                    if (combo != null && !combo.isDisposed()) {
                        combo.setText(Path.fromOSString(file).lastSegment());
                    }
                    return new PropertyChangeCommand(elem, propertyName, lastSegment);
                }
            } catch (CoreException e) {
                ExceptionHandler.process(e);
            }
        }
    } else {
        FileDialog dial = new FileDialog(composite.getShell(), SWT.NONE);
        dial.setFilterExtensions(FilesUtils.getAcceptJARFilesSuffix());
        String file = dial.open();
        if (file != null && !file.equals("")) {
            //$NON-NLS-1$
            String propertyName = (String) button.getData(PARAMETER_NAME);
            String lastSegment = TalendTextUtils.addQuotes(Path.fromOSString(file).lastSegment());
            try {
                CorePlugin.getDefault().getLibrariesService().deployLibrary(Path.fromOSString(file).toFile().toURL());
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
            if (!elem.getPropertyValue(propertyName).equals(lastSegment)) {
                // update the combo current value
                CCombo combo = (CCombo) hashCurControls.get(propertyName);
                if (combo != null && !combo.isDisposed()) {
                    combo.setText(Path.fromOSString(file).lastSegment());
                }
                return new PropertyChangeCommand(elem, propertyName, lastSegment);
            }
        }
    }
    return null;
}
Also used : CCombo(org.eclipse.swt.custom.CCombo) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) CoreException(org.eclipse.core.runtime.CoreException) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) BrmsDialog(org.talend.designer.core.ui.dialog.BrmsDialog) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) FileDialog(org.eclipse.swt.widgets.FileDialog) IBrmsExtension(org.talend.designer.core.ui.dialog.IBrmsExtension) CoreException(org.eclipse.core.runtime.CoreException) IExternalNode(org.talend.core.model.process.IExternalNode)

Example 14 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project tdi-studio-se by Talend.

the class AbstractProcessProvider method findAllProcessProviders.

public static Collection<AbstractProcessProvider> findAllProcessProviders() {
    if (providerMap.isEmpty()) {
        IConfigurationElement[] elems = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
        for (IConfigurationElement elem : elems) {
            String pid = elem.getAttribute(ATTR_PID);
            try {
                Object provider = elem.createExecutableExtension(ATTR_CLASS);
                if (provider instanceof AbstractProcessProvider) {
                    AbstractProcessProvider createExecutableExtension = (AbstractProcessProvider) provider;
                    providerMap.put(pid, createExecutableExtension);
                }
            } catch (CoreException ex) {
                ExceptionHandler.process(ex);
            }
        }
    }
    return providerMap.values();
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 15 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project tdi-studio-se by Talend.

the class SchemaNode method addExtensionNodes.

/**
     * Add Extension nodes.
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private void addExtensionNodes() {
    String databaseProductName = getSession().getRoot().getDatabaseProductName().toLowerCase().trim();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    //$NON-NLS-1$ //$NON-NLS-2$
    IExtensionPoint point = registry.getExtensionPoint("net.sourceforge.sqlexplorer", "node");
    IExtension[] extensions = point.getExtensions();
    for (int i = 0; i < extensions.length; i++) {
        IExtension e = extensions[i];
        IConfigurationElement[] ces = e.getConfigurationElements();
        for (int j = 0; j < ces.length; j++) {
            try {
                // include only nodes that are attachted to the schema
                // node..
                //$NON-NLS-1$
                String parent = ces[j].getAttribute("parent-node");
                if (parent.indexOf("schema") == -1) {
                    //$NON-NLS-1$
                    continue;
                }
                boolean isValidProduct = false;
                //$NON-NLS-1$ //$NON-NLS-2$
                String[] validProducts = ces[j].getAttribute("database-product-name").split(",");
                // include only nodes valid for this database
                for (int k = 0; k < validProducts.length; k++) {
                    String product = validProducts[k].toLowerCase().trim();
                    if (product.length() == 0) {
                        continue;
                    }
                    if (product.equals("*")) {
                        //$NON-NLS-1$
                        isValidProduct = true;
                        break;
                    }
                    //$NON-NLS-1$
                    String regex = TextUtil.replaceChar(product, '*', ".*");
                    if (databaseProductName.matches(regex)) {
                        isValidProduct = true;
                        break;
                    }
                }
                if (!isValidProduct) {
                    continue;
                }
                //$NON-NLS-1$
                String imagePath = ces[j].getAttribute("icon");
                //$NON-NLS-1$
                String id = ces[j].getAttribute("id");
                //$NON-NLS-1$
                String type = ces[j].getAttribute("table-type").trim();
                //$NON-NLS-1$
                AbstractNode childNode = (AbstractNode) ces[j].createExecutableExtension("class");
                childNode.setParent(this);
                childNode.setSession(psessionNode);
                childNode.setType(type);
                String fragmentId = id.substring(0, id.indexOf('.', END_INDEX));
                if (imagePath != null && imagePath.trim().length() != 0) {
                    childNode.setImage(ImageUtil.getFragmentImage(fragmentId, imagePath));
                }
                pchildNames.add(childNode.getLabelText());
                if (!isExcludedByFilter(childNode.getLabelText())) {
                    addChildNode(childNode);
                }
            } catch (Throwable ex) {
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("SchemaNode.logMessage1"), ex);
            }
        }
    }
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtension(org.eclipse.core.runtime.IExtension) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Aggregations

IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)62 CoreException (org.eclipse.core.runtime.CoreException)32 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)14 IExtension (org.eclipse.core.runtime.IExtension)12 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)12 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)11 ArrayList (java.util.ArrayList)8 List (java.util.List)5 GridData (org.eclipse.swt.layout.GridData)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 Image (org.eclipse.swt.graphics.Image)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 HeaderClause (aQute.bnd.build.model.clauses.HeaderClause)2 File (java.io.File)2 URL (java.net.URL)2