Search in sources :

Example 1 with HopGuiWorkflowGraph

use of org.apache.hop.ui.hopgui.file.workflow.HopGuiWorkflowGraph in project hop by apache.

the class ActionWorkflowGuiPlugin method copyAsActionToClipboard.

@GuiContextAction(id = "workflow-graph-workflow-copy-action", parentId = HopGuiWorkflowContext.CONTEXT_ID, type = GuiActionType.Modify, name = "Copy as workflow action", tooltip = "Copy this workflow as an action so you can paste it in another workflow", image = "ui/images/copy.svg", category = "Basic", categoryOrder = "1")
public void copyAsActionToClipboard(HopGuiWorkflowContext context) {
    WorkflowMeta workflowMeta = context.getWorkflowMeta();
    HopGuiWorkflowGraph workflowGraph = context.getWorkflowGraph();
    HopGui hopGui = workflowGraph.getHopGui();
    IVariables variables = workflowGraph.getVariables();
    ActionWorkflow actionWorkflow = new ActionWorkflow(workflowMeta.getName());
    HopGuiFileOpenedExtension ext = new HopGuiFileOpenedExtension(null, variables, workflowMeta.getFilename());
    // 
    try {
        ExtensionPointHandler.callExtensionPoint(LogChannel.UI, variables, HopGuiExtensionPoint.HopGuiFileOpenedDialog.id, ext);
    } catch (Exception xe) {
        LogChannel.UI.logError("Error handling extension point 'HopGuiFileOpenDialog'", xe);
    }
    actionWorkflow.setFileName(ext.filename);
    // 
    try {
        IHopMetadataProvider metadataProvider = workflowGraph.getHopGui().getMetadataProvider();
        IHopMetadataSerializer<WorkflowRunConfiguration> serializer = metadataProvider.getSerializer(WorkflowRunConfiguration.class);
        List<String> configNames = serializer.listObjectNames();
        if (!configNames.isEmpty()) {
            if (configNames.size() == 1) {
                actionWorkflow.setRunConfiguration(configNames.get(0));
            } else {
                EnterSelectionDialog dialog = new EnterSelectionDialog(workflowGraph.getShell(), configNames.toArray(new String[0]), "Select run configuration", "Select the workflow run configuration to use in the action:");
                String configName = dialog.open();
                if (configName != null) {
                    actionWorkflow.setRunConfiguration(configName);
                }
            }
        }
    } catch (Exception e) {
        new ErrorDialog(workflowGraph.getShell(), "Error", "Error selecting workflow run configurations", e);
    }
    ActionMeta actionMeta = new ActionMeta(actionWorkflow);
    StringBuilder xml = new StringBuilder(5000).append(XmlHandler.getXmlHeader());
    xml.append(XmlHandler.openTag(HopGuiWorkflowClipboardDelegate.XML_TAG_WORKFLOW_ACTIONS)).append(Const.CR);
    xml.append(XmlHandler.openTag(HopGuiWorkflowClipboardDelegate.XML_TAG_ACTIONS)).append(Const.CR);
    xml.append(actionMeta.getXml());
    xml.append(XmlHandler.closeTag(HopGuiWorkflowClipboardDelegate.XML_TAG_ACTIONS)).append(Const.CR);
    xml.append(XmlHandler.closeTag(HopGuiWorkflowClipboardDelegate.XML_TAG_WORKFLOW_ACTIONS)).append(Const.CR);
    workflowGraph.workflowClipboardDelegate.toClipboard(xml.toString());
}
Also used : ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) WorkflowRunConfiguration(org.apache.hop.workflow.config.WorkflowRunConfiguration) HopGuiWorkflowGraph(org.apache.hop.ui.hopgui.file.workflow.HopGuiWorkflowGraph) ActionMeta(org.apache.hop.workflow.action.ActionMeta) IVariables(org.apache.hop.core.variables.IVariables) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) HopGuiFileOpenedExtension(org.apache.hop.ui.hopgui.delegates.HopGuiFileOpenedExtension) 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 HopGuiWorkflowGraph

use of org.apache.hop.ui.hopgui.file.workflow.HopGuiWorkflowGraph in project hop by apache.

the class HopGuiFileDelegate method exportToSvg.

public void exportToSvg() {
    try {
        String svgXml = null;
        IVariables variables = null;
        String proposedName = null;
        HopGuiPipelineGraph pipelineGraph = HopGui.getActivePipelineGraph();
        if (pipelineGraph != null) {
            PipelineMeta pipelineMeta = pipelineGraph.getPipelineMeta();
            variables = pipelineGraph.getVariables();
            svgXml = PipelineSvgPainter.generatePipelineSvg(pipelineMeta, 1.0f, pipelineGraph.getVariables());
            proposedName = pipelineMeta.getName() + ".svg";
        }
        HopGuiWorkflowGraph workflowGraph = HopGui.getActiveWorkflowGraph();
        if (workflowGraph != null) {
            WorkflowMeta workflowMeta = workflowGraph.getWorkflowMeta();
            variables = workflowGraph.getVariables();
            svgXml = WorkflowSvgPainter.generateWorkflowSvg(workflowMeta, 1.0f, workflowGraph.getVariables());
            proposedName = workflowMeta.getName() + ".svg";
        }
        if (svgXml != null) {
            String proposedFilename = variables.getVariable("user.home") + File.separator + proposedName;
            FileObject proposedFile = HopVfs.getFileObject(proposedFilename);
            String filename = BaseDialog.presentFileDialog(true, hopGui.getShell(), null, variables, proposedFile, new String[] { "*.svg" }, new String[] { "SVG Files" }, true);
            if (filename != null) {
                String realFilename = variables.resolve(filename);
                FileObject file = HopVfs.getFileObject(realFilename);
                if (file.exists()) {
                    MessageBox box = new MessageBox(hopGui.getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
                    box.setText("File exists");
                    box.setMessage("This file already exists. Do you want to overwrite it?");
                    int answer = box.open();
                    if ((answer & SWT.YES) == 0) {
                        return;
                    }
                }
                OutputStream outputStream = null;
                try {
                    outputStream = HopVfs.getOutputStream(file, false);
                    outputStream.write(svgXml.getBytes(Const.XML_ENCODING));
                } finally {
                    if (outputStream != null) {
                        outputStream.close();
                    }
                }
            }
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), "Error", "Error exporting to SVG", e);
    }
}
Also used : HopGuiWorkflowGraph(org.apache.hop.ui.hopgui.file.workflow.HopGuiWorkflowGraph) IVariables(org.apache.hop.core.variables.IVariables) OutputStream(java.io.OutputStream) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) FileObject(org.apache.commons.vfs2.FileObject) HopGuiPipelineGraph(org.apache.hop.ui.hopgui.file.pipeline.HopGuiPipelineGraph) HopException(org.apache.hop.core.exception.HopException) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 3 with HopGuiWorkflowGraph

use of org.apache.hop.ui.hopgui.file.workflow.HopGuiWorkflowGraph in project hop by apache.

the class HopDataOrchestrationPerspective method addWorkflow.

/**
 * Add a new workflow tab to the tab folder...
 *
 * @param workflowMeta
 * @return The file type handler
 */
public IHopFileTypeHandler addWorkflow(HopGui hopGui, WorkflowMeta workflowMeta, HopWorkflowFileType workflowFile) throws HopException {
    CTabItem tabItem = new CTabItem(tabFolder, SWT.CLOSE);
    tabItem.setImage(GuiResource.getInstance().getImageWorkflow());
    HopGuiWorkflowGraph workflowGraph = new HopGuiWorkflowGraph(tabFolder, hopGui, tabItem, this, workflowMeta, workflowFile);
    tabItem.setControl(workflowGraph);
    // Update the internal variables (file specific) in the workflow graph variables
    // 
    workflowMeta.setInternalHopVariables(workflowGraph.getVariables());
    // Update the variables using the list of parameters
    // 
    hopGui.setParametersAsVariablesInUI(workflowMeta, workflowGraph.getVariables());
    // Set the tab name
    // 
    updateTabLabel(tabItem, workflowMeta.getFilename(), workflowMeta.getName());
    // Switch to the tab
    tabFolder.setSelection(tabItem);
    activeItem = new TabItemHandler(tabItem, workflowGraph);
    items.add(activeItem);
    // 
    while (tabSelectionHistory.size() - 1 > tabSelectionIndex) {
        tabSelectionHistory.pop();
    }
    int tabIndex = tabFolder.indexOf(tabItem);
    tabSelectionHistory.add(tabIndex);
    tabSelectionIndex = tabSelectionHistory.size() - 1;
    try {
        ExtensionPointHandler.callExtensionPoint(hopGui.getLog(), workflowGraph.getVariables(), HopExtensionPoint.HopGuiNewWorkflowTab.id, workflowGraph);
    } catch (Exception e) {
        throw new HopException("Error calling extension point plugin for plugin id " + HopExtensionPoint.HopGuiNewWorkflowTab.id + " trying to handle a new workflow tab", e);
    }
    workflowGraph.setFocus();
    return workflowGraph;
}
Also used : HopGuiWorkflowGraph(org.apache.hop.ui.hopgui.file.workflow.HopGuiWorkflowGraph) HopException(org.apache.hop.core.exception.HopException) TabItemHandler(org.apache.hop.ui.hopgui.perspective.TabItemHandler) CTabItem(org.eclipse.swt.custom.CTabItem) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint) HopException(org.apache.hop.core.exception.HopException)

Example 4 with HopGuiWorkflowGraph

use of org.apache.hop.ui.hopgui.file.workflow.HopGuiWorkflowGraph in project hop by apache.

the class HopGui method getActiveWorkflowGraph.

public static HopGuiWorkflowGraph getActiveWorkflowGraph() {
    IHopPerspective activePerspective = HopGui.getInstance().getActivePerspective();
    if (!(activePerspective instanceof HopDataOrchestrationPerspective)) {
        return null;
    }
    HopDataOrchestrationPerspective perspective = (HopDataOrchestrationPerspective) activePerspective;
    IHopFileTypeHandler typeHandler = perspective.getActiveFileTypeHandler();
    if (!(typeHandler instanceof HopGuiWorkflowGraph)) {
        return null;
    }
    return (HopGuiWorkflowGraph) typeHandler;
}
Also used : IHopFileTypeHandler(org.apache.hop.ui.hopgui.file.IHopFileTypeHandler) HopGuiWorkflowGraph(org.apache.hop.ui.hopgui.file.workflow.HopGuiWorkflowGraph) HopDataOrchestrationPerspective(org.apache.hop.ui.hopgui.perspective.dataorch.HopDataOrchestrationPerspective) IHopPerspective(org.apache.hop.ui.hopgui.perspective.IHopPerspective)

Example 5 with HopGuiWorkflowGraph

use of org.apache.hop.ui.hopgui.file.workflow.HopGuiWorkflowGraph in project hop by apache.

the class ActionLogIconClickedExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, HopGuiWorkflowGraphExtension extension) throws HopException {
    HopGuiWorkflowGraph workflowGraph = extension.getWorkflowGraph();
    AreaOwner areaOwner = extension.getAreaOwner();
    if (areaOwner == null) {
        return;
    }
    if (areaOwner.getAreaType() == AreaOwner.AreaType.CUSTOM) {
        if (areaOwner.getOwner() == null) {
            return;
        }
        if (areaOwner.getOwner() instanceof String) {
            String message = (String) areaOwner.getOwner();
            if (message.startsWith(DrawAsyncLoggingIconExtensionPoint.STRING_AREA_OWNER_PREFIX)) {
                String serviceName = message.substring(DrawAsyncLoggingIconExtensionPoint.STRING_AREA_OWNER_PREFIX.length());
                if (StringUtils.isNotEmpty(serviceName)) {
                    MultiMetadataProvider metadataProvider = workflowGraph.getHopGui().getMetadataProvider();
                    IHopMetadataSerializer<AsyncWebService> serializer = metadataProvider.getSerializer(AsyncWebService.class);
                    if (serializer.exists(serviceName)) {
                        MetadataManager<AsyncWebService> manager = new MetadataManager<>(workflowGraph.getVariables(), metadataProvider, AsyncWebService.class);
                        manager.editMetadata(serviceName);
                        extension.setPreventingDefault(true);
                    }
                }
            }
        }
    }
}
Also used : HopGuiWorkflowGraph(org.apache.hop.ui.hopgui.file.workflow.HopGuiWorkflowGraph) MetadataManager(org.apache.hop.ui.core.metadata.MetadataManager) AreaOwner(org.apache.hop.core.gui.AreaOwner) AsyncWebService(org.apache.hop.www.async.AsyncWebService) MultiMetadataProvider(org.apache.hop.metadata.serializer.multi.MultiMetadataProvider)

Aggregations

HopGuiWorkflowGraph (org.apache.hop.ui.hopgui.file.workflow.HopGuiWorkflowGraph)6 HopException (org.apache.hop.core.exception.HopException)3 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)3 WorkflowMeta (org.apache.hop.workflow.WorkflowMeta)3 IVariables (org.apache.hop.core.variables.IVariables)2 IHopFileTypeHandler (org.apache.hop.ui.hopgui.file.IHopFileTypeHandler)2 ActionMeta (org.apache.hop.workflow.action.ActionMeta)2 OutputStream (java.io.OutputStream)1 FileObject (org.apache.commons.vfs2.FileObject)1 GuiContextAction (org.apache.hop.core.action.GuiContextAction)1 HopConfigException (org.apache.hop.core.exception.HopConfigException)1 HopExtensionPoint (org.apache.hop.core.extension.HopExtensionPoint)1 AreaOwner (org.apache.hop.core.gui.AreaOwner)1 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)1 IHopMetadataProvider (org.apache.hop.metadata.api.IHopMetadataProvider)1 MultiMetadataProvider (org.apache.hop.metadata.serializer.multi.MultiMetadataProvider)1 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)1 EnterSelectionDialog (org.apache.hop.ui.core.dialog.EnterSelectionDialog)1 MetadataManager (org.apache.hop.ui.core.metadata.MetadataManager)1 HopGui (org.apache.hop.ui.hopgui.HopGui)1