Search in sources :

Example 1 with GuiContextActionFilter

use of org.apache.hop.core.action.GuiContextActionFilter in project hop by apache.

the class AsyncGuiPlugin method filterAsyncActions.

/**
 * We're filtering out the actions which are not a Pipeline action and which are already
 * enabled/disabled.
 *
 * @param contextActionId
 * @param context
 * @return True if the action should be shown and false otherwise.
 */
@GuiContextActionFilter(parentId = HopGuiWorkflowActionContext.CONTEXT_ID)
public boolean filterAsyncActions(String contextActionId, HopGuiWorkflowActionContext context) {
    ActionMeta actionMeta = context.getActionMeta();
    boolean isPipeline = actionMeta.isPipeline();
    Map<String, String> asyncMap = actionMeta.getAttributesMap().get(Defaults.ASYNC_STATUS_GROUP);
    boolean enabled = false;
    if (asyncMap != null) {
        enabled = asyncMap.get(Defaults.ASYNC_ACTION_PIPELINE_SERVICE_NAME) != null;
    }
    // 
    if (contextActionId.equals(ACTION_ID_WORKFLOW_GRAPH_ENABLE_ASYNC_LOGGING)) {
        return isPipeline && !enabled;
    }
    if (contextActionId.equals(ACTION_ID_WORKFLOW_GRAPH_DISABLE_ASYNC_LOGGING)) {
        return isPipeline && enabled;
    }
    return true;
}
Also used : ActionMeta(org.apache.hop.workflow.action.ActionMeta) GuiContextActionFilter(org.apache.hop.core.action.GuiContextActionFilter)

Example 2 with GuiContextActionFilter

use of org.apache.hop.core.action.GuiContextActionFilter in project hop by apache.

the class HopGuiEnvironment method initGuiPlugins.

/**
 * Look for GuiWidgetElement annotated fields in all the GuiPlugins. Put them in the Gui registry
 *
 * @throws HopException
 */
public static void initGuiPlugins() throws HopException {
    try {
        GuiRegistry guiRegistry = GuiRegistry.getInstance();
        PluginRegistry pluginRegistry = PluginRegistry.getInstance();
        List<IPlugin> guiPlugins = pluginRegistry.getPlugins(GuiPluginType.class);
        for (IPlugin guiPlugin : guiPlugins) {
            ClassLoader classLoader = pluginRegistry.getClassLoader(guiPlugin);
            Class<?>[] typeClasses = guiPlugin.getClassMap().keySet().toArray(new Class<?>[0]);
            String guiPluginClassName = guiPlugin.getClassMap().get(typeClasses[0]);
            Class<?> guiPluginClass = classLoader.loadClass(guiPluginClassName);
            // Component widgets are defined on fields
            // 
            List<Field> fields = findDeclaredFields(guiPluginClass);
            for (Field field : fields) {
                GuiWidgetElement guiElement = field.getAnnotation(GuiWidgetElement.class);
                if (guiElement != null) {
                    // Add the GUI Element to the registry...
                    // 
                    guiRegistry.addGuiWidgetElement(guiPluginClassName, guiElement, field);
                }
            }
            // Menu and toolbar items are defined on methods
            // 
            List<Method> methods = findDeclaredMethods(guiPluginClass);
            for (Method method : methods) {
                GuiMenuElement menuElement = method.getAnnotation(GuiMenuElement.class);
                if (menuElement != null) {
                    guiRegistry.addGuiWidgetElement(guiPluginClassName, menuElement, method, classLoader);
                }
                GuiToolbarElement toolbarElement = method.getAnnotation(GuiToolbarElement.class);
                if (toolbarElement != null) {
                    guiRegistry.addGuiToolbarElement(guiPluginClassName, toolbarElement, method, classLoader);
                }
                GuiKeyboardShortcut shortcut = method.getAnnotation(GuiKeyboardShortcut.class);
                if (shortcut != null) {
                    // RAP does not support ESC as a shortcut key.
                    if (EnvironmentUtils.getInstance().isWeb() && shortcut.key() == SWT.ESC) {
                        continue;
                    }
                    guiRegistry.addKeyboardShortcut(guiPluginClassName, method, shortcut);
                }
                GuiOsxKeyboardShortcut osxShortcut = method.getAnnotation(GuiOsxKeyboardShortcut.class);
                if (osxShortcut != null) {
                    // RAP does not support ESC as a shortcut key.
                    if (EnvironmentUtils.getInstance().isWeb() && osxShortcut.key() == SWT.ESC) {
                        continue;
                    }
                    guiRegistry.addKeyboardShortcut(guiPluginClassName, method, osxShortcut);
                }
                GuiContextAction contextAction = method.getAnnotation(GuiContextAction.class);
                if (contextAction != null) {
                    guiRegistry.addGuiContextAction(guiPluginClassName, method, contextAction, classLoader);
                }
                GuiContextActionFilter actionFilter = method.getAnnotation(GuiContextActionFilter.class);
                if (actionFilter != null) {
                    guiRegistry.addGuiActionFilter(guiPluginClassName, method, actionFilter, classLoader);
                }
                GuiCallback guiCallback = method.getAnnotation(GuiCallback.class);
                if (guiCallback != null) {
                    guiRegistry.registerGuiCallback(guiPluginClass, method, guiCallback);
                }
            }
        }
        // Sort all GUI elements once.
        // 
        guiRegistry.sortAllElements();
        // Now populate the HopFileTypeRegistry
        // 
        // Get all the file handler plugins
        // 
        PluginRegistry registry = PluginRegistry.getInstance();
        List<IPlugin> plugins = registry.getPlugins(HopFileTypePluginType.class);
        for (IPlugin plugin : plugins) {
            try {
                IHopFileType hopFileTypeInterface = registry.loadClass(plugin, IHopFileType.class);
                HopFileTypeRegistry.getInstance().registerHopFile(hopFileTypeInterface);
            } catch (HopPluginException e) {
                throw new HopException("Unable to load plugin with ID '" + plugin.getIds()[0] + "' and type : " + plugin.getPluginType().getName(), e);
            }
        }
    } catch (Exception e) {
        throw new HopException("Error looking for Elements in GUI Plugins ", e);
    }
}
Also used : IPlugin(org.apache.hop.core.plugins.IPlugin) Field(java.lang.reflect.Field) GuiOsxKeyboardShortcut(org.apache.hop.core.gui.plugin.key.GuiOsxKeyboardShortcut) GuiContextActionFilter(org.apache.hop.core.action.GuiContextActionFilter) GuiWidgetElement(org.apache.hop.core.gui.plugin.GuiWidgetElement) HopException(org.apache.hop.core.exception.HopException) GuiCallback(org.apache.hop.core.gui.plugin.callback.GuiCallback) HopPluginException(org.apache.hop.core.exception.HopPluginException) Method(java.lang.reflect.Method) HopPluginException(org.apache.hop.core.exception.HopPluginException) HopException(org.apache.hop.core.exception.HopException) GuiContextAction(org.apache.hop.core.action.GuiContextAction) GuiMenuElement(org.apache.hop.core.gui.plugin.menu.GuiMenuElement) IHopFileType(org.apache.hop.ui.hopgui.file.IHopFileType) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) GuiKeyboardShortcut(org.apache.hop.core.gui.plugin.key.GuiKeyboardShortcut) GuiRegistry(org.apache.hop.core.gui.plugin.GuiRegistry)

Aggregations

GuiContextActionFilter (org.apache.hop.core.action.GuiContextActionFilter)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 GuiContextAction (org.apache.hop.core.action.GuiContextAction)1 HopException (org.apache.hop.core.exception.HopException)1 HopPluginException (org.apache.hop.core.exception.HopPluginException)1 GuiRegistry (org.apache.hop.core.gui.plugin.GuiRegistry)1 GuiWidgetElement (org.apache.hop.core.gui.plugin.GuiWidgetElement)1 GuiCallback (org.apache.hop.core.gui.plugin.callback.GuiCallback)1 GuiKeyboardShortcut (org.apache.hop.core.gui.plugin.key.GuiKeyboardShortcut)1 GuiOsxKeyboardShortcut (org.apache.hop.core.gui.plugin.key.GuiOsxKeyboardShortcut)1 GuiMenuElement (org.apache.hop.core.gui.plugin.menu.GuiMenuElement)1 GuiToolbarElement (org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)1 IPlugin (org.apache.hop.core.plugins.IPlugin)1 PluginRegistry (org.apache.hop.core.plugins.PluginRegistry)1 IHopFileType (org.apache.hop.ui.hopgui.file.IHopFileType)1 ActionMeta (org.apache.hop.workflow.action.ActionMeta)1