Search in sources :

Example 1 with MetadataManager

use of org.apache.hop.ui.core.metadata.MetadataManager in project hop by apache.

the class LocationMouseDoubleClickExtensionPoint method openDataSet.

private void openDataSet(String dataSetName) {
    HopGui hopGui = HopGui.getInstance();
    MetadataManager<DataSet> manager = new MetadataManager<>(hopGui.getVariables(), hopGui.getMetadataProvider(), DataSet.class);
    manager.editMetadata(dataSetName);
}
Also used : MetadataManager(org.apache.hop.ui.core.metadata.MetadataManager) DataSet(org.apache.hop.testing.DataSet) HopGui(org.apache.hop.ui.hopgui.HopGui)

Example 2 with MetadataManager

use of org.apache.hop.ui.core.metadata.MetadataManager in project hop by apache.

the class TestingGuiPlugin method createDataSetFromTransform.

/**
 * Create a new data set with the output from
 */
@GuiContextAction(id = "pipeline-graph-transform-20400-create-data-set-from-transform", parentId = HopGuiPipelineTransformContext.CONTEXT_ID, type = GuiActionType.Delete, name = "i18n::TestingGuiPlugin.ContextAction.CreateDataset.Name", tooltip = "i18n::TestingGuiPlugin.ContextAction.CreateDataset.Tooltip", image = "create-dataset.svg", category = "i18n::TestingGuiPlugin.Category", categoryOrder = "8")
public void createDataSetFromTransform(HopGuiPipelineTransformContext context) {
    HopGui hopGui = HopGui.getInstance();
    IHopMetadataProvider metadataProvider = hopGui.getMetadataProvider();
    IVariables variables = context.getPipelineGraph().getVariables();
    TransformMeta transformMeta = context.getTransformMeta();
    PipelineMeta pipelineMeta = context.getPipelineMeta();
    try {
        DataSet dataSet = new DataSet();
        IRowMeta rowMeta = pipelineMeta.getTransformFields(variables, transformMeta);
        for (int i = 0; i < rowMeta.size(); i++) {
            IValueMeta valueMeta = rowMeta.getValueMeta(i);
            String setFieldName = valueMeta.getName();
            DataSetField field = new DataSetField(setFieldName, valueMeta.getType(), valueMeta.getLength(), valueMeta.getPrecision(), valueMeta.getComments(), valueMeta.getFormatMask());
            dataSet.getFields().add(field);
        }
        MetadataManager<DataSet> manager = new MetadataManager<>(hopGui.getVariables(), hopGui.getMetadataProvider(), DataSet.class);
        if (manager.newMetadata(dataSet) != null) {
            PipelineUnitTest unitTest = getCurrentUnitTest(pipelineMeta);
            if (unitTest == null) {
                return;
            }
            // Now that the data set is created and we have an active unit test, perhaps the user wants
            // to use it on the transform?
            // 
            MessageBox box = new MessageBox(hopGui.getShell(), SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
            box.setText(BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.CreateDataset.DatasetType.Header"));
            box.setMessage(BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.CreateDataset.DatasetType.Message", dataSet.getName(), transformMeta.getName()) + Const.CR + BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.CreateDataset.DatasetType.Answer1") + Const.CR + BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.CreateDataset.DatasetType.Answer2") + Const.CR + BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.CreateDataset.DatasetType.Answer3") + Const.CR);
            int answer = box.open();
            if ((answer & SWT.YES) != 0) {
                // set the new data set as an input
                // 
                setInputDataSetOnTransform(variables, metadataProvider, pipelineMeta, transformMeta, unitTest, dataSet);
            }
            if ((answer & SWT.NO) != 0) {
                setGoldenDataSetOnTransform(variables, metadataProvider, pipelineMeta, transformMeta, unitTest, dataSet);
            }
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.CreateDataset.Error.Header"), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.CreateDataset.Error.Message"), e);
    }
}
Also used : IRowMeta(org.apache.hop.core.row.IRowMeta) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) WriteToDataSetExtensionPoint(org.apache.hop.testing.xp.WriteToDataSetExtensionPoint) 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) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) MessageBox(org.eclipse.swt.widgets.MessageBox) IValueMeta(org.apache.hop.core.row.IValueMeta) 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) HopGui(org.apache.hop.ui.hopgui.HopGui) GuiContextAction(org.apache.hop.core.action.GuiContextAction)

Example 3 with MetadataManager

use of org.apache.hop.ui.core.metadata.MetadataManager in project hop by apache.

the class TestingGuiPlugin method editPipelineUnitTest.

@GuiToolbarElement(root = HopGuiPipelineGraph.GUI_PLUGIN_TOOLBAR_PARENT_ID, id = ID_TOOLBAR_UNIT_TESTS_LABEL, type = GuiToolbarElementType.LABEL, label = "i18n::TestingGuiPlugin.ToolbarElement.UnitTest.Label", toolTip = "i18n::TestingGuiPlugin.ToolbarElement.UnitTest.Tooltip", separator = true)
public void editPipelineUnitTest() {
    HopGui hopGui = HopGui.getInstance();
    Combo combo = getUnitTestsCombo();
    if (combo == null) {
        return;
    }
    String unitTestName = combo.getText();
    try {
        MetadataManager<PipelineUnitTest> manager = new MetadataManager<>(hopGui.getVariables(), hopGui.getMetadataProvider(), PipelineUnitTest.class);
        if (manager.editMetadata(unitTestName)) {
            refreshUnitTestsList();
            selectUnitTestInList(unitTestName);
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "TestingGuiPlugin.ToolbarElement.UnitTest.Error.Header"), BaseMessages.getString(PKG, "TestingGuiPlugin.ToolbarElement.UnitTest.Error.Message", unitTestName), e);
    }
}
Also used : MetadataManager(org.apache.hop.ui.core.metadata.MetadataManager) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) Combo(org.eclipse.swt.widgets.Combo) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) 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) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Example 4 with MetadataManager

use of org.apache.hop.ui.core.metadata.MetadataManager in project hop by apache.

the class TestingGuiPlugin method createUnitTest.

@GuiToolbarElement(root = HopGuiPipelineGraph.GUI_PLUGIN_TOOLBAR_PARENT_ID, id = ID_TOOLBAR_ITEM_UNIT_TESTS_CREATE, toolTip = "i18n::TestingGuiPlugin.ToolbarElement.UnitTest.Create.Tooltip", image = "Test_tube_icon_create.svg", separator = true)
public void createUnitTest() {
    HopGui hopGui = HopGui.getInstance();
    PipelineMeta pipelineMeta = getActivePipelineMeta();
    if (pipelineMeta == null) {
        return;
    }
    MetadataManager<PipelineUnitTest> manager = new MetadataManager<>(hopGui.getVariables(), hopGui.getMetadataProvider(), PipelineUnitTest.class);
    PipelineUnitTest test = manager.newMetadata();
    if (test != null) {
        // Activate the test
        refreshUnitTestsList();
        selectUnitTest(pipelineMeta, test);
    }
}
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 5 with MetadataManager

use of org.apache.hop.ui.core.metadata.MetadataManager 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

MetadataManager (org.apache.hop.ui.core.metadata.MetadataManager)12 IHopMetadataProvider (org.apache.hop.metadata.api.IHopMetadataProvider)7 HopGui (org.apache.hop.ui.hopgui.HopGui)7 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)6 HopException (org.apache.hop.core.exception.HopException)5 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)5 IHopMetadata (org.apache.hop.metadata.api.IHopMetadata)4 GuiContextAction (org.apache.hop.core.action.GuiContextAction)3 GuiToolbarElement (org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)3 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)3 MetadataPerspective (org.apache.hop.ui.hopgui.perspective.metadata.MetadataPerspective)3 MessageBox (org.eclipse.swt.widgets.MessageBox)3 HopPluginException (org.apache.hop.core.exception.HopPluginException)2 HopTransformException (org.apache.hop.core.exception.HopTransformException)2 HopValueException (org.apache.hop.core.exception.HopValueException)2 IRowMeta (org.apache.hop.core.row.IRowMeta)2 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)2 IVariables (org.apache.hop.core.variables.IVariables)2 HopMetadata (org.apache.hop.metadata.api.HopMetadata)2 EnterSelectionDialog (org.apache.hop.ui.core.dialog.EnterSelectionDialog)2