Search in sources :

Example 96 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project dbeaver by serge-rider.

the class PropertyDescriptor method extractProperties.

public static List<DBPPropertyDescriptor> extractProperties(IConfigurationElement config) {
    String category = NAME_UNDEFINED;
    if (TAG_PROPERTY_GROUP.equals(config.getName())) {
        category = config.getAttribute(ATTR_LABEL);
        if (CommonUtils.isEmpty(category)) {
            category = NAME_UNDEFINED;
        }
    }
    List<DBPPropertyDescriptor> properties = new ArrayList<>();
    IConfigurationElement[] propElements = config.getChildren(PropertyDescriptor.TAG_PROPERTY);
    for (IConfigurationElement prop : propElements) {
        properties.add(new PropertyDescriptor(category, prop));
    }
    return properties;
}
Also used : DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor) ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)

Example 97 with IConfigurationElement

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

the class DBTreeActionGroup method getContextActions.

/**
     * Loop through all extensions and add the appropriate actions.
     * 
     * Actions are selected by database product name, node type and
     * availability.
     * 
     * @param nodes currently selected nodes
     * @return array of actions
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private IAction[] getContextActions(INode[] nodes) {
    String databaseProductName = nodes[0].getSession().getRoot().getDatabaseProductName().toLowerCase().trim();
    String nodeType = nodes[0].getType().toLowerCase().trim();
    List actions = new ArrayList();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    //$NON-NLS-1$ //$NON-NLS-2$
    IExtensionPoint point = registry.getExtensionPoint("net.sourceforge.sqlexplorer", "nodeContextAction");
    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 {
                boolean isValidProduct = false;
                boolean isValidNodeType = false;
                //$NON-NLS-1$
                String id = ces[j].getAttribute("id");
                //$NON-NLS-1$ //$NON-NLS-2$
                String[] validProducts = ces[j].getAttribute("database-product-name").split(",");
                //$NON-NLS-1$ //$NON-NLS-2$
                String[] validNodeTypes = ces[j].getAttribute("node-type").split(",");
                //$NON-NLS-1$
                String imagePath = ces[j].getAttribute("icon");
                // check if action is valid for current database product
                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;
                }
                // check if action is valid for current node type
                for (int k = 0; k < validNodeTypes.length; k++) {
                    String type = validNodeTypes[k].toLowerCase().trim();
                    if (type.length() == 0) {
                        continue;
                    }
                    if (type.equals("*")) {
                        //$NON-NLS-1$
                        isValidNodeType = true;
                        break;
                    }
                    //$NON-NLS-1$
                    String regex = TextUtil.replaceChar(type, '*', ".*");
                    if (nodeType.matches(regex)) {
                        isValidNodeType = true;
                        break;
                    }
                }
                if (!isValidNodeType) {
                    continue;
                }
                // check if the action thinks it is suitable..
                //$NON-NLS-1$
                AbstractDBTreeContextAction action = (AbstractDBTreeContextAction) ces[j].createExecutableExtension("class");
                action.setSelectedNodes(nodes);
                action.setTreeViewer(pTreeViewer);
                action.setView(pView);
                String fragmentId = id.substring(0, id.indexOf('.', END_INDEX));
                if (imagePath != null && imagePath.trim().length() != 0) {
                    action.setImageDescriptor(ImageUtil.getFragmentDescriptor(fragmentId, imagePath));
                }
                if (action.isAvailable()) {
                    actions.add(action);
                }
            } catch (Throwable ex) {
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("DBTreeActionGroup.logMessage"), ex);
            }
        }
    }
    return (IAction[]) actions.toArray(new IAction[] {});
}
Also used : IAction(org.eclipse.jface.action.IAction) ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtension(org.eclipse.core.runtime.IExtension) AbstractDBTreeContextAction(org.talend.sqlbuilder.dbstructure.actions.AbstractDBTreeContextAction) ArrayList(java.util.ArrayList) List(java.util.List) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 98 with IConfigurationElement

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

the class SchemaNode method findExtensionNode.

/**
     * Location extenstion nodes for a given tableType.
     * 
     * @param tableType for which to find extension node
     * @return INode or null if no extensions found
     */
private INode findExtensionNode(String tableType) {
    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;
                }
                // check if it is the correct type
                //$NON-NLS-1$
                String type = ces[j].getAttribute("table-type").trim();
                if (!type.equalsIgnoreCase(tableType)) {
                    continue;
                }
                //$NON-NLS-1$
                AbstractNode childNode = (AbstractNode) ces[j].createExecutableExtension("class");
                childNode.setParent(this);
                childNode.setSession(psessionNode);
                return childNode;
            } catch (Throwable ex) {
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("SchemaNode.logMessage2"), ex);
            }
        }
    }
    return null;
}
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)

Example 99 with IConfigurationElement

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

the class ESBService method addExtensionRepositoryNodes.

private void addExtensionRepositoryNodes(List<ERepositoryObjectType> arraysList) {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IConfigurationElement[] configurationElements = registry.getConfigurationElementsFor("org.talend.core.repository.repository_node_provider");
    for (IConfigurationElement element : configurationElements) {
        String type = element.getAttribute("type");
        ERepositoryObjectType repositoryNodeType = ERepositoryObjectType.valueOf(ERepositoryObjectType.class, type);
        if (repositoryNodeType != null) {
            arraysList.add(repositoryNodeType);
        }
    }
}
Also used : ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 100 with IConfigurationElement

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

the class DataSetTableActionGroup method fillContextMenu.

/**
     * Fill the context menu with all the correct actions.
     * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
     */
public void fillContextMenu(IMenuManager menu) {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    //$NON-NLS-1$ //$NON-NLS-2$
    IExtensionPoint point = registry.getExtensionPoint("net.sourceforge.sqlexplorer", "dataSetTableContextAction");
    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 {
                //$NON-NLS-1$
                String group = ces[j].getAttribute("group");
                if (group == null || !group.equalsIgnoreCase("export")) {
                    //$NON-NLS-1$
                    // check if the action thinks it is suitable..
                    AbstractDataSetTableContextAction action = (AbstractDataSetTableContextAction) ces[j].createExecutableExtension(//$NON-NLS-1$
                    "class");
                    action.setTable(ptable);
                    action.setTableCursor(pcursor);
                    if (action.isAvailable()) {
                        menu.add(action);
                    }
                }
            } catch (Throwable ex) {
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("DataSetTableActionGroup.logMessage1"), ex);
            }
        }
    }
    menu.add(new Separator());
    // add export options
    //$NON-NLS-1$
    MenuManager subMenu = new MenuManager(Messages.getString("DataSetTable.Actions.ExportSubMenu"));
    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 {
                //$NON-NLS-1$
                String group = ces[j].getAttribute("group");
                if (group != null && group.equalsIgnoreCase("export")) {
                    //$NON-NLS-1$
                    // check if the action thinks it is suitable..
                    AbstractDataSetTableContextAction action = (AbstractDataSetTableContextAction) ces[j].createExecutableExtension(//$NON-NLS-1$
                    "class");
                    action.setTable(ptable);
                    action.setTableCursor(pcursor);
                    if (action.isAvailable()) {
                        subMenu.add(action);
                    }
                }
            } catch (Throwable ex) {
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("DataSetTableActionGroup.logMessage1"), ex);
            }
        }
    }
    menu.add(subMenu);
    menu.add(new Separator());
    menu.add(pcopyTableAction);
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtension(org.eclipse.core.runtime.IExtension) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) AbstractDataSetTableContextAction(org.talend.sqlbuilder.dataset.actions.AbstractDataSetTableContextAction) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) Separator(org.eclipse.jface.action.Separator) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Aggregations

IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)189 CoreException (org.eclipse.core.runtime.CoreException)75 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)64 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)50 ArrayList (java.util.ArrayList)39 IExtension (org.eclipse.core.runtime.IExtension)30 IStatus (org.eclipse.core.runtime.IStatus)24 Status (org.eclipse.core.runtime.Status)24 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)16 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)11 List (java.util.List)9 Map (java.util.Map)9 Platform (org.eclipse.core.runtime.Platform)9 File (java.io.File)8 Collection (java.util.Collection)8 Stream (java.util.stream.Stream)8 LinkedList (java.util.LinkedList)7 Optional (java.util.Optional)5 IFile (org.eclipse.core.resources.IFile)5