Search in sources :

Example 1 with PipelineProbeEditor

use of org.apache.hop.reflection.probe.meta.PipelineProbeEditor 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)

Aggregations

GuiContextAction (org.apache.hop.core.action.GuiContextAction)1 HopException (org.apache.hop.core.exception.HopException)1 HopMetadata (org.apache.hop.metadata.api.HopMetadata)1 IHopMetadataProvider (org.apache.hop.metadata.api.IHopMetadataProvider)1 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)1 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)1 PipelineProbe (org.apache.hop.reflection.probe.meta.PipelineProbe)1 PipelineProbeEditor (org.apache.hop.reflection.probe.meta.PipelineProbeEditor)1 EnterSelectionDialog (org.apache.hop.ui.core.dialog.EnterSelectionDialog)1 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)1 MetadataManager (org.apache.hop.ui.core.metadata.MetadataManager)1 HopGui (org.apache.hop.ui.hopgui.HopGui)1 HopGuiExtensionPoint (org.apache.hop.ui.hopgui.HopGuiExtensionPoint)1 MetadataPerspective (org.apache.hop.ui.hopgui.perspective.metadata.MetadataPerspective)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1