Search in sources :

Example 36 with GuiToolbarElement

use of org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement in project hop by apache.

the class HopVfsFileDialog method addBookmark.

@GuiToolbarElement(root = BOOKMARKS_TOOLBAR_PARENT_ID, id = BOOKMARKS_ITEM_ID_BOOKMARK_ADD, toolTip = "i18n::HopVfsFileDialog.AddBookmark.Tooltip.Message", image = "ui/images/bookmark-add.svg")
public void addBookmark() {
    FileObject selectedFile = getSelectedFileObject();
    if (selectedFile != null) {
        String name = selectedFile.getName().getBaseName();
        EnterStringDialog dialog = new EnterStringDialog(shell, name, BaseMessages.getString(PKG, "HopVfsFileDialog.NameBookmark.Header"), BaseMessages.getString(PKG, "HopVfsFileDialog.NameBookmark.Message"));
        name = dialog.open();
        if (name != null) {
            String path = HopVfs.getFilename(selectedFile);
            bookmarks.put(name, path);
            saveBookmarks();
            refreshBookmarks();
        }
    }
    refreshStates();
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) EnterStringDialog(org.apache.hop.ui.core.dialog.EnterStringDialog) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Example 37 with GuiToolbarElement

use of org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement in project hop by apache.

the class TestingGuiPlugin method editUnitTest.

@GuiToolbarElement(root = HopGuiPipelineGraph.GUI_PLUGIN_TOOLBAR_PARENT_ID, id = ID_TOOLBAR_ITEM_UNIT_TEST_EDIT, toolTip = "i18n::TestingGuiPlugin.ToolbarElement.UnitTest.Edit.Tooltip", image = "Test_tube_icon_edit.svg", separator = true)
public void editUnitTest() {
    HopGui hopGui = HopGui.getInstance();
    PipelineMeta pipelineMeta = getActivePipelineMeta();
    if (pipelineMeta == null) {
        return;
    }
    PipelineUnitTest unitTest = getCurrentUnitTest(pipelineMeta);
    MetadataManager<PipelineUnitTest> manager = new MetadataManager<>(hopGui.getVariables(), hopGui.getMetadataProvider(), PipelineUnitTest.class);
    if (manager.editMetadata(unitTest.getName())) {
        // Activate the test
        refreshUnitTestsList();
        selectUnitTest(pipelineMeta, unitTest);
    }
}
Also used : MetadataManager(org.apache.hop.ui.core.metadata.MetadataManager) HopGui(org.apache.hop.ui.hopgui.HopGui) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Example 38 with GuiToolbarElement

use of org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement in project hop by apache.

the class TestingGuiPlugin method detachUnitTest.

/**
 * Clear the current unit test from the active pipeline...
 */
@GuiToolbarElement(root = HopGuiPipelineGraph.GUI_PLUGIN_TOOLBAR_PARENT_ID, id = ID_TOOLBAR_ITEM_UNIT_TEST_DETACH, toolTip = "i18n::TestingGuiPlugin.ToolbarElement.UnitTest.Detach.Tooltip", image = "Test_tube_icon_detach.svg")
public void detachUnitTest() {
    HopGui hopGui = HopGui.getInstance();
    HopGuiPipelineGraph pipelineGraph = HopGui.getActivePipelineGraph();
    if (pipelineGraph == null) {
        return;
    }
    try {
        PipelineMeta pipelineMeta = getActivePipelineMeta();
        if (pipelineMeta == null) {
            return;
        }
        // Remove
        // 
        Map<String, Object> stateMap = getStateMap(pipelineMeta);
        if (stateMap != null) {
            stateMap.remove(DataSetConst.STATE_KEY_ACTIVE_UNIT_TEST);
        }
        // Clear the combo box
        // 
        Combo combo = getUnitTestsCombo();
        if (combo != null) {
            combo.setText("");
        }
        // Update the GUI
        // 
        pipelineGraph.updateGui();
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "TestingGuiPlugin.ToolbarElement.Detach.Error.Header"), BaseMessages.getString(PKG, "TestingGuiPlugin.ToolbarElement.Detach.Error.Message"), e);
    }
}
Also used : ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) Combo(org.eclipse.swt.widgets.Combo) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) HopGuiPipelineGraph(org.apache.hop.ui.hopgui.file.pipeline.HopGuiPipelineGraph) HopException(org.apache.hop.core.exception.HopException) HopTransformException(org.apache.hop.core.exception.HopTransformException) HopValueException(org.apache.hop.core.exception.HopValueException) HopPluginException(org.apache.hop.core.exception.HopPluginException) HopGui(org.apache.hop.ui.hopgui.HopGui) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Example 39 with GuiToolbarElement

use of org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement 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

GuiToolbarElement (org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)39 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)23 HopException (org.apache.hop.core.exception.HopException)21 HopGui (org.apache.hop.ui.hopgui.HopGui)12 Combo (org.eclipse.swt.widgets.Combo)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ProjectsConfig (org.apache.hop.projects.config.ProjectsConfig)9 IOException (java.io.IOException)8 FileObject (org.apache.commons.vfs2.FileObject)7 ProjectConfig (org.apache.hop.projects.project.ProjectConfig)7 IHopMetadata (org.apache.hop.metadata.api.IHopMetadata)6 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)6 LifecycleEnvironment (org.apache.hop.projects.environment.LifecycleEnvironment)6 FileSystemException (org.apache.commons.vfs2.FileSystemException)5 HopPluginException (org.apache.hop.core.exception.HopPluginException)5 HopTransformException (org.apache.hop.core.exception.HopTransformException)5 HopValueException (org.apache.hop.core.exception.HopValueException)5 GuiKeyboardShortcut (org.apache.hop.core.gui.plugin.key.GuiKeyboardShortcut)5 GuiOsxKeyboardShortcut (org.apache.hop.core.gui.plugin.key.GuiOsxKeyboardShortcut)5 Project (org.apache.hop.projects.project.Project)5