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();
}
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;
}
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);
}
}
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;
}
}
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);
}
}
Aggregations