Search in sources :

Example 1 with HopMetadata

use of org.apache.hop.metadata.api.HopMetadata in project hop by apache.

the class SerializableMetadataProvider method toJson.

public String toJson() throws HopException {
    JSONObject jStore = new JSONObject();
    // 
    for (Class<IHopMetadata> metadataClass : getMetadataClasses()) {
        IHopMetadataSerializer<IHopMetadata> serializer = getSerializer(metadataClass);
        HopMetadata hopMetadata = metadataClass.getAnnotation(HopMetadata.class);
        if (hopMetadata == null) {
            throw new HopException("Error: class " + metadataClass + " is not annotated with " + HopMetadata.class.getName());
        }
        String classKey = hopMetadata.key();
        JSONArray jClass = new JSONArray();
        JsonMetadataParser parser = new JsonMetadataParser(metadataClass, this);
        // 
        for (String name : serializer.listObjectNames()) {
            Object object = serializer.load(name);
            JSONObject jObject = parser.getJsonObject((IHopMetadata) object);
            jClass.add(jObject);
        }
        jStore.put(classKey, jClass);
    }
    return jStore.toJSONString();
}
Also used : JSONObject(org.json.simple.JSONObject) JsonMetadataParser(org.apache.hop.metadata.serializer.json.JsonMetadataParser) IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) HopException(org.apache.hop.core.exception.HopException) JSONArray(org.json.simple.JSONArray) HopMetadata(org.apache.hop.metadata.api.HopMetadata) IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) JSONObject(org.json.simple.JSONObject)

Example 2 with HopMetadata

use of org.apache.hop.metadata.api.HopMetadata in project hop by apache.

the class MemoryMetadataProvider method getSerializer.

@Override
public <T extends IHopMetadata> IHopMetadataSerializer<T> getSerializer(Class<T> managedClass) throws HopException {
    IHopMetadataSerializer<IHopMetadata> serializer = serializerMap.get(managedClass.getName());
    if (serializer == null) {
        HopMetadata hopMetadata = managedClass.getAnnotation(HopMetadata.class);
        String description = managedClass.getSimpleName();
        if (hopMetadata != null) {
            description = hopMetadata.name();
        }
        serializer = (IHopMetadataSerializer<IHopMetadata>) new MemoryMetadataSerializer<>(this, managedClass, variables, description);
        serializerMap.put(managedClass.getName(), serializer);
    }
    return (IHopMetadataSerializer<T>) serializer;
}
Also used : IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) HopMetadata(org.apache.hop.metadata.api.HopMetadata) IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) IHopMetadataSerializer(org.apache.hop.metadata.api.IHopMetadataSerializer)

Example 3 with HopMetadata

use of org.apache.hop.metadata.api.HopMetadata in project hop by apache.

the class MetadataExplorerDialog method refreshTree.

@GuiToolbarElement(root = GUI_PLUGIN_TOOLBAR_PARENT_ID, id = TOOLBAR_ITEM_REFRESH, toolTip = "Refresh", image = "ui/images/refresh.svg")
public void refreshTree() {
    try {
        tree.removeAll();
        IHopMetadataProvider metadataProvider = HopGui.getInstance().getMetadataProvider();
        // top level: object key
        // 
        List<Class<IHopMetadata>> metadataClasses = metadataProvider.getMetadataClasses();
        for (Class<IHopMetadata> metadataClass : metadataClasses) {
            HopMetadata hopMetadata = HopMetadataUtil.getHopMetadataAnnotation(metadataClass);
            Image image = SwtSvgImageUtil.getImage(shell.getDisplay(), metadataClass.getClassLoader(), hopMetadata.image(), ConstUi.ICON_SIZE, ConstUi.ICON_SIZE);
            TreeItem elementTypeItem = new TreeItem(tree, SWT.NONE);
            elementTypeItem.setImage(image);
            elementTypeItem.setText(0, Const.NVL(hopMetadata.key(), ""));
            elementTypeItem.setText(1, Const.NVL(hopMetadata.name(), ""));
            // level 1: object names
            // 
            IHopMetadataSerializer<IHopMetadata> serializer = metadataProvider.getSerializer(metadataClass);
            List<String> names = serializer.listObjectNames();
            Collections.sort(names);
            for (final String name : names) {
                TreeItem elementItem = new TreeItem(elementTypeItem, SWT.NONE);
                elementItem.setText(1, Const.NVL(name, ""));
                elementItem.addListener(SWT.Selection, event -> log.logBasic("Selected : " + name));
                elementItem.setFont(GuiResource.getInstance().getFontBold());
            }
        }
        TreeUtil.setOptimalWidthOnColumns(tree);
        TreeMemory.setExpandedFromMemory(tree, METADATA_EXPLORER_DIALOG_TREE);
    } catch (Exception e) {
        new ErrorDialog(shell, "Error", "Error refreshing metadata tree", e);
    }
}
Also used : IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) Image(org.eclipse.swt.graphics.Image) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) HopMetadata(org.apache.hop.metadata.api.HopMetadata) IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Example 4 with HopMetadata

use of org.apache.hop.metadata.api.HopMetadata in project hop by apache.

the class MetadataManager method editMetadata.

/**
 * edit an element
 *
 * @return True if anything was changed
 */
public boolean editMetadata() {
    HopGui hopGui = HopGui.getInstance();
    try {
        List<String> names = getNames();
        // Plugin details from the managed class...
        // 
        HopMetadata hopMetadata = HopMetadataUtil.getHopMetadataAnnotation(managedClass);
        // Show an action dialog...
        // 
        List<GuiAction> actions = new ArrayList<>();
        for (final String name : names) {
            GuiAction action = new GuiAction(name, GuiActionType.Modify, name, name + " : " + hopMetadata.description(), hopMetadata.image(), (shiftAction, controlAction, t) -> editMetadata(name));
            action.setClassLoader(getClassLoader());
            actions.add(action);
        }
        return GuiContextUtil.getInstance().handleActionSelection(hopGui.getShell(), "Select the " + hopMetadata.name() + " to edit", new GuiContextHandler("HopGuiMetadataContext", actions));
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), "Error", "Error editing metadata", e);
        return false;
    }
}
Also used : GuiAction(org.apache.hop.core.gui.plugin.action.GuiAction) GuiContextHandler(org.apache.hop.ui.hopgui.context.GuiContextHandler) ArrayList(java.util.ArrayList) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) HopMetadata(org.apache.hop.metadata.api.HopMetadata) IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) HopException(org.apache.hop.core.exception.HopException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HopGui(org.apache.hop.ui.hopgui.HopGui)

Example 5 with HopMetadata

use of org.apache.hop.metadata.api.HopMetadata in project hop by apache.

the class MetadataManager method editWithEditor.

public void editWithEditor(String name) {
    if (name == null) {
        return;
    }
    HopGui hopGui = HopGui.getInstance();
    try {
        HopMetadata annotation = HopMetadataUtil.getHopMetadataAnnotation(managedClass);
        MetadataPerspective perspective = MetadataPerspective.getInstance();
        MetadataEditor<?> editor = perspective.findEditor(annotation.key(), name);
        if (editor == null) {
            // Load the metadata element from the metadata
            // 
            IHopMetadataSerializer<T> serializer = metadataProvider.getSerializer(managedClass);
            T element = serializer.load(name);
            if (element == null) {
                // 
                throw new HopException("Unable to find element '" + name + "' in the metadata");
            }
            initializeElementVariables(element);
            perspective.addEditor(createEditor(element));
        } else {
            perspective.setActiveEditor(editor);
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), "Error", "Error editing metadata", e);
    }
}
Also used : SWT(org.eclipse.swt.SWT) HopException(org.apache.hop.core.exception.HopException) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) HopMetadata(org.apache.hop.metadata.api.HopMetadata) IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) MetadataPerspective(org.apache.hop.ui.hopgui.perspective.metadata.MetadataPerspective) HopException(org.apache.hop.core.exception.HopException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HopGui(org.apache.hop.ui.hopgui.HopGui)

Aggregations

HopMetadata (org.apache.hop.metadata.api.HopMetadata)13 IHopMetadata (org.apache.hop.metadata.api.IHopMetadata)13 HopException (org.apache.hop.core.exception.HopException)6 ArrayList (java.util.ArrayList)5 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 GuiAction (org.apache.hop.core.gui.plugin.action.GuiAction)3 HopGui (org.apache.hop.ui.hopgui.HopGui)3 GuiToolbarElement (org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)2 IHopMetadataProvider (org.apache.hop.metadata.api.IHopMetadataProvider)2 JsonMetadataParser (org.apache.hop.metadata.serializer.json.JsonMetadataParser)2 GuiContextHandler (org.apache.hop.ui.hopgui.context.GuiContextHandler)2 Image (org.eclipse.swt.graphics.Image)2 JSONObject (org.json.simple.JSONObject)2 FileObject (org.apache.commons.vfs2.FileObject)1 GuiKeyboardShortcut (org.apache.hop.core.gui.plugin.key.GuiKeyboardShortcut)1 GuiOsxKeyboardShortcut (org.apache.hop.core.gui.plugin.key.GuiOsxKeyboardShortcut)1 IPlugin (org.apache.hop.core.plugins.IPlugin)1 IRowMeta (org.apache.hop.core.row.IRowMeta)1 RowMeta (org.apache.hop.core.row.RowMeta)1