Search in sources :

Example 1 with MetadataPerspective

use of org.apache.hop.ui.hopgui.perspective.metadata.MetadataPerspective in project hop by apache.

the class DataProbeGuiPlugin method addDataProbeForTransform.

@GuiContextAction(id = "pipeline-graph-transform-9000-add-probe", parentId = HopGuiPipelineTransformContext.CONTEXT_ID, type = GuiActionType.Info, name = "Add data probe", tooltip = "Streams the rows to a pipeline defined in a selected pipeline probe", image = "probe.svg", category = "Preview", categoryOrder = "3")
public void addDataProbeForTransform(HopGuiPipelineTransformContext context) {
    PipelineMeta pipelineMeta = context.getPipelineMeta();
    TransformMeta transformMeta = context.getTransformMeta();
    HopGui hopGui = HopGui.getInstance();
    try {
        // Present the user with a list of pipeline probes...
        // 
        IHopMetadataProvider metadataProvider = hopGui.getMetadataProvider();
        IHopMetadataSerializer<PipelineProbe> serializer = metadataProvider.getSerializer(PipelineProbe.class);
        MetadataManager<PipelineProbe> manager = new MetadataManager<>(hopGui.getVariables(), metadataProvider, PipelineProbe.class);
        PipelineProbe pipelineProbe = null;
        List<String> pipelineProbeNames = serializer.listObjectNames();
        if (pipelineProbeNames.isEmpty()) {
            MessageBox box = new MessageBox(hopGui.getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
            box.setText("No probes available");
            box.setMessage("There are no pipeline probe objects defined yet.  Do you want to create one?");
            int answer = box.open();
            if ((answer & SWT.YES) != 0) {
                // Create a new pipeline probe...
                // 
                pipelineProbe = new PipelineProbe();
                addLocation(hopGui.getVariables(), pipelineProbe, pipelineMeta, transformMeta);
                manager.newMetadata(pipelineProbe);
                return;
            } else {
                return;
            }
        } else {
            EnterSelectionDialog dialog = new EnterSelectionDialog(hopGui.getShell(), pipelineProbeNames.toArray(new String[0]), "Select pipeline probe", "Select the pipeline probe to add this pipeline transform to");
            String pipelineProbeName = dialog.open();
            if (pipelineProbeName != null) {
                pipelineProbe = serializer.load(pipelineProbeName);
            }
        }
        if (pipelineProbe != null) {
            // See if it's open in the metadata perspective...
            // 
            MetadataPerspective perspective = (MetadataPerspective) hopGui.getPerspectiveManager().findPerspective(MetadataPerspective.class);
            String key = PipelineProbe.class.getAnnotation(HopMetadata.class).key();
            PipelineProbeEditor editor = (PipelineProbeEditor) perspective.findEditor(key, pipelineProbe.getName());
            if (editor != null) {
                // We're going to change the current metadata and flag it as changed...
                // 
                pipelineProbe = new PipelineProbe();
                editor.getWidgetsContent(pipelineProbe);
                // Add the location
                // 
                addLocation(hopGui.getVariables(), pipelineProbe, pipelineMeta, transformMeta);
                // Replace and refresh the dialog
                // 
                editor.setMetadata(pipelineProbe);
                editor.setWidgetsContent();
                // Set changed...
                // 
                editor.setChanged();
                // Switch to the editor...
                // 
                perspective.activate();
                perspective.setActiveEditor(editor);
                return;
            } else {
                // Not opened in the perspective, simply add the data probe location...
                // 
                addLocation(hopGui.getVariables(), pipelineProbe, pipelineMeta, transformMeta);
                // ... and save the pipeline probe
                // 
                serializer.save(pipelineProbe);
            }
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), "Error", "Error adding pipeline probe to transform '" + transformMeta.getName() + "'", e);
    }
}
Also used : ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) MetadataPerspective(org.apache.hop.ui.hopgui.perspective.metadata.MetadataPerspective) HopGuiExtensionPoint(org.apache.hop.ui.hopgui.HopGuiExtensionPoint) HopException(org.apache.hop.core.exception.HopException) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) MessageBox(org.eclipse.swt.widgets.MessageBox) MetadataManager(org.apache.hop.ui.core.metadata.MetadataManager) PipelineProbeEditor(org.apache.hop.reflection.probe.meta.PipelineProbeEditor) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) PipelineProbe(org.apache.hop.reflection.probe.meta.PipelineProbe) HopMetadata(org.apache.hop.metadata.api.HopMetadata) EnterSelectionDialog(org.apache.hop.ui.core.dialog.EnterSelectionDialog) HopGui(org.apache.hop.ui.hopgui.HopGui) GuiContextAction(org.apache.hop.core.action.GuiContextAction)

Example 2 with MetadataPerspective

use of org.apache.hop.ui.hopgui.perspective.metadata.MetadataPerspective 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)

Example 3 with MetadataPerspective

use of org.apache.hop.ui.hopgui.perspective.metadata.MetadataPerspective in project hop by apache.

the class WebServiceGuiPlugin method addWebServiceForTransform.

@GuiContextAction(id = "pipeline-graph-transform-9000-add-web-serviec", parentId = HopGuiPipelineTransformContext.CONTEXT_ID, type = GuiActionType.Info, name = "Add web service", tooltip = "Use the output of this transform as a web service with Hop Server", image = "ui/images/webservice.svg", category = "Data routing", categoryOrder = "2")
public void addWebServiceForTransform(HopGuiPipelineTransformContext context) {
    PipelineMeta pipelineMeta = context.getPipelineMeta();
    TransformMeta transformMeta = context.getTransformMeta();
    IVariables variables = context.getPipelineGraph().getVariables();
    HopGui hopGui = HopGui.getInstance();
    try {
        // Ask which field should be used...
        // 
        IRowMeta fields = pipelineMeta.getTransformFields(variables, transformMeta);
        EnterSelectionDialog fieldSelectionDialog = new EnterSelectionDialog(hopGui.getShell(), fields.getFieldNames(), "Select the output field", "Please select the field to output when the service is called");
        String fieldName = fieldSelectionDialog.open();
        if (fieldName == null) {
            return;
        }
        // Present the user with a list of pipeline probes...
        // 
        IHopMetadataProvider metadataProvider = hopGui.getMetadataProvider();
        IHopMetadataSerializer<WebService> serializer = metadataProvider.getSerializer(WebService.class);
        MetadataManager<WebService> manager = new MetadataManager<>(hopGui.getVariables(), metadataProvider, WebService.class);
        WebService webService = null;
        List<String> serviceNames = serializer.listObjectNames();
        if (serviceNames.isEmpty()) {
            MessageBox box = new MessageBox(hopGui.getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
            box.setText("No web services available");
            box.setMessage("There are no web service objects defined yet.  Do you want to create one?");
            int answer = box.open();
            if ((answer & SWT.YES) != 0) {
                // Create a new web service...
                // 
                webService = new WebService(pipelineMeta.getName(), true, pipelineMeta.getFilename(), transformMeta.getName(), fieldName, "text/plain", false);
                manager.newMetadata(webService);
                return;
            } else {
                return;
            }
        } else {
            EnterSelectionDialog dialog = new EnterSelectionDialog(hopGui.getShell(), serviceNames.toArray(new String[0]), "Select a web service", "Select the web service to update");
            String pipelineProbeName = dialog.open();
            if (pipelineProbeName != null) {
                webService = serializer.load(pipelineProbeName);
            }
        }
        if (webService != null) {
            // See if it's open in the metadata perspective...
            // 
            MetadataPerspective perspective = (MetadataPerspective) hopGui.getPerspectiveManager().findPerspective(MetadataPerspective.class);
            String key = WebService.class.getAnnotation(HopMetadata.class).key();
            WebServiceEditor editor = (WebServiceEditor) perspective.findEditor(key, webService.getName());
            if (editor != null) {
                // We're going to change the current metadata and flag it as changed...
                // 
                webService = new WebService();
                editor.getWidgetsContent(webService);
                // Update the web service details
                // 
                webService.setFilename(pipelineMeta.getFilename());
                webService.setTransformName(transformMeta.getName());
                webService.setFieldName(fieldName);
                // Replace and refresh the dialog
                // 
                editor.setMetadata(webService);
                editor.setWidgetsContent();
                // Set changed...
                // 
                editor.setChanged();
                // Switch to the editor...
                // 
                perspective.activate();
                perspective.setActiveEditor(editor);
                return;
            } else {
                // Not opened in the perspective, simply set the web service details
                // 
                webService.setFilename(pipelineMeta.getFilename());
                webService.setTransformName(transformMeta.getName());
                webService.setFieldName(fieldName);
                // ... and save the pipeline probe
                // 
                serializer.save(webService);
            }
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), "Error", "Error adding web service for transform '" + transformMeta.getName() + "'", e);
    }
}
Also used : WebService(org.apache.hop.www.service.WebService) IRowMeta(org.apache.hop.core.row.IRowMeta) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) MetadataPerspective(org.apache.hop.ui.hopgui.perspective.metadata.MetadataPerspective) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) MessageBox(org.eclipse.swt.widgets.MessageBox) MetadataManager(org.apache.hop.ui.core.metadata.MetadataManager) IVariables(org.apache.hop.core.variables.IVariables) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) HopMetadata(org.apache.hop.metadata.api.HopMetadata) EnterSelectionDialog(org.apache.hop.ui.core.dialog.EnterSelectionDialog) HopGui(org.apache.hop.ui.hopgui.HopGui) GuiContextAction(org.apache.hop.core.action.GuiContextAction)

Example 4 with MetadataPerspective

use of org.apache.hop.ui.hopgui.perspective.metadata.MetadataPerspective in project hop by apache.

the class HopGuiAuditDelegate method openMetadataObject.

private void openMetadataObject(String className, String name) throws HopException {
    try {
        IHopMetadataProvider metadataProvider = hopGui.getMetadataProvider();
        MetadataPerspective perspective = MetadataPerspective.getInstance();
        // Find the class...
        List<Class<IHopMetadata>> metadataClasses = metadataProvider.getMetadataClasses();
        for (Class<IHopMetadata> metadataClass : metadataClasses) {
            if (metadataClass.getName().equals(className)) {
                // Get the serializer and open it up
                // 
                IHopMetadataSerializer<IHopMetadata> serializer = metadataProvider.getSerializer(metadataClass);
                // 
                if (serializer.exists(name)) {
                    IHopMetadata metadata = serializer.load(name);
                    MetadataManager<IHopMetadata> metadataManager = new MetadataManager<>(HopGui.getInstance().getVariables(), metadataProvider, metadataClass);
                    MetadataEditor<IHopMetadata> editor = metadataManager.createEditor(metadata);
                    // We assume that all tab items are closed so we can just open up a new editor for the
                    // metadata
                    // 
                    perspective.addEditor(editor);
                }
            }
        }
    } catch (Exception e) {
        throw new HopException("Error opening metadata object '" + name + "' of class " + className, e);
    }
}
Also used : MetadataManager(org.apache.hop.ui.core.metadata.MetadataManager) IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) HopException(org.apache.hop.core.exception.HopException) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) MetadataPerspective(org.apache.hop.ui.hopgui.perspective.metadata.MetadataPerspective) HopException(org.apache.hop.core.exception.HopException)

Example 5 with MetadataPerspective

use of org.apache.hop.ui.hopgui.perspective.metadata.MetadataPerspective in project hop by apache.

the class MetadataFileTypeHandler method findTabItemHandler.

private TabItemHandler findTabItemHandler() {
    if (metadata == null) {
        return null;
    }
    MetadataPerspective perspective = MetadataPerspective.getInstance();
    for (TabItemHandler tabItemHandler : perspective.getItems()) {
        CTabItem tabItem = tabItemHandler.getTabItem();
        MetadataEditor editor = (MetadataEditor) tabItem.getData();
        IHopMetadata other = editor.getMetadata();
        if (other.equals(metadata)) {
            return tabItemHandler;
        }
    }
    return null;
}
Also used : IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) MetadataPerspective(org.apache.hop.ui.hopgui.perspective.metadata.MetadataPerspective) TabItemHandler(org.apache.hop.ui.hopgui.perspective.TabItemHandler) CTabItem(org.eclipse.swt.custom.CTabItem)

Aggregations

MetadataPerspective (org.apache.hop.ui.hopgui.perspective.metadata.MetadataPerspective)5 HopException (org.apache.hop.core.exception.HopException)3 HopMetadata (org.apache.hop.metadata.api.HopMetadata)3 IHopMetadata (org.apache.hop.metadata.api.IHopMetadata)3 IHopMetadataProvider (org.apache.hop.metadata.api.IHopMetadataProvider)3 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)3 MetadataManager (org.apache.hop.ui.core.metadata.MetadataManager)3 HopGui (org.apache.hop.ui.hopgui.HopGui)3 GuiContextAction (org.apache.hop.core.action.GuiContextAction)2 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)2 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)2 EnterSelectionDialog (org.apache.hop.ui.core.dialog.EnterSelectionDialog)2 MessageBox (org.eclipse.swt.widgets.MessageBox)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IRowMeta (org.apache.hop.core.row.IRowMeta)1 IVariables (org.apache.hop.core.variables.IVariables)1 PipelineProbe (org.apache.hop.reflection.probe.meta.PipelineProbe)1 PipelineProbeEditor (org.apache.hop.reflection.probe.meta.PipelineProbeEditor)1 HopGuiExtensionPoint (org.apache.hop.ui.hopgui.HopGuiExtensionPoint)1 TabItemHandler (org.apache.hop.ui.hopgui.perspective.TabItemHandler)1