Search in sources :

Example 1 with IHopFileTypeHandler

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

the class HopNeo4jPerspective method openTransform.

private void openTransform(Session session, String name, String type, String id) {
    LogChannel.UI.logDetailed("Open transform : " + id + ", name : " + name + ", type: " + type);
    Map<String, Object> params = new HashMap<>();
    params.put("subjectName", name);
    params.put("subjectType", type);
    params.put("subjectId", id);
    StringBuilder cypher = new StringBuilder();
    cypher.append(// TRANSFORM
    "MATCH(e:Execution { name : $subjectName, type : $subjectType, id : $subjectId } )");
    cypher.append(// Transform
    "-[:EXECUTION_OF_TRANSFORM]->(t:Transform { name : $subjectName } )");
    cypher.append("-[:TRANSFORM_OF_PIPELINE]->(p:Pipeline) ");
    cypher.append("RETURN p.filename, t.name ");
    String[] names = session.readTransaction(tx -> {
        Result statementResult = tx.run(cypher.toString(), params);
        if (!statementResult.hasNext()) {
            statementResult.consume();
            // No file found
            return null;
        }
        Record record = statementResult.next();
        statementResult.consume();
        String filename = LoggingCore.getStringValue(record, 0);
        String transformName = LoggingCore.getStringValue(record, 1);
        return new String[] { filename, transformName };
    });
    if (names == null) {
        return;
    }
    String filename = names[0];
    String transformName = names[1];
    if (StringUtils.isEmpty(filename)) {
        return;
    }
    try {
        hopGui.fileDelegate.fileOpen(filename);
        if (StringUtils.isEmpty(transformName)) {
            return;
        }
        HopDataOrchestrationPerspective perspective = HopGui.getDataOrchestrationPerspective();
        IHopFileTypeHandler typeHandler = perspective.getActiveFileTypeHandler();
        if (typeHandler == null || !(typeHandler instanceof HopGuiPipelineGraph)) {
            return;
        }
        HopGuiPipelineGraph graph = (HopGuiPipelineGraph) typeHandler;
        PipelineMeta pipelineMeta = graph.getPipelineMeta();
        TransformMeta transformMeta = pipelineMeta.findTransform(transformName);
        if (transformMeta == null) {
            return;
        }
        pipelineMeta.unselectAll();
        transformMeta.setSelected(true);
        graph.editTransform(pipelineMeta, transformMeta);
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "Neo4jPerspectiveDialog.OpeningTransform.Dialog.Header"), BaseMessages.getString(PKG, "Neo4jPerspectiveDialog.OpeningTransform.Dialog.Message"), e);
    }
}
Also used : IHopFileTypeHandler(org.apache.hop.ui.hopgui.file.IHopFileTypeHandler) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) HopException(org.apache.hop.core.exception.HopException) HopConfigException(org.apache.hop.core.exception.HopConfigException) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) HopDataOrchestrationPerspective(org.apache.hop.ui.hopgui.perspective.dataorch.HopDataOrchestrationPerspective) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) HopGuiPipelineGraph(org.apache.hop.ui.hopgui.file.pipeline.HopGuiPipelineGraph)

Example 2 with IHopFileTypeHandler

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

the class TestingGuiPlugin method getActivePipelineMeta.

/**
 * Get the active pipeline. If we don't have an active one, return null
 *
 * @return The active pipeline or null
 */
public static final PipelineMeta getActivePipelineMeta() {
    IHopFileTypeHandler handler = HopGui.getInstance().getActiveFileTypeHandler();
    // 
    if (handler == null || handler.getSubject() == null) {
        return null;
    }
    Object subject = handler.getSubject();
    if (!(subject instanceof PipelineMeta)) {
        return null;
    }
    // On with the program
    // 
    PipelineMeta pipelineMeta = (PipelineMeta) subject;
    return pipelineMeta;
}
Also used : IHopFileTypeHandler(org.apache.hop.ui.hopgui.file.IHopFileTypeHandler) PipelineMeta(org.apache.hop.pipeline.PipelineMeta)

Example 3 with IHopFileTypeHandler

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

the class HopGuiFileDelegate method fileSave.

public void fileSave() {
    try {
        IHopFileTypeHandler typeHandler = getActiveFileTypeHandler();
        IHopFileType fileType = typeHandler.getFileType();
        if (fileType.hasCapability(IHopFileType.CAPABILITY_SAVE)) {
            // 
            if (StringUtils.isEmpty(typeHandler.getFilename()) && !fileType.hasCapability(IHopFileType.CAPABILITY_HANDLE_METADATA)) {
                // Ask for the filename: saveAs
                // 
                fileSaveAs();
            } else {
                typeHandler.save();
            }
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), "Error", "Error saving file", e);
    }
}
Also used : IHopFileType(org.apache.hop.ui.hopgui.file.IHopFileType) IHopFileTypeHandler(org.apache.hop.ui.hopgui.file.IHopFileTypeHandler) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) HopException(org.apache.hop.core.exception.HopException)

Example 4 with IHopFileTypeHandler

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

the class HopGuiFileDelegate method fileClose.

public boolean fileClose() {
    try {
        IHopPerspective perspective = hopGui.getActivePerspective();
        IHopFileTypeHandler typeHandler = getActiveFileTypeHandler();
        IHopFileType fileType = typeHandler.getFileType();
        if (fileType.hasCapability(IHopFileType.CAPABILITY_CLOSE)) {
            perspective.remove(typeHandler);
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), "Error", "Error saving/closing file", e);
    }
    return false;
}
Also used : IHopFileType(org.apache.hop.ui.hopgui.file.IHopFileType) IHopFileTypeHandler(org.apache.hop.ui.hopgui.file.IHopFileTypeHandler) IHopPerspective(org.apache.hop.ui.hopgui.perspective.IHopPerspective) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) HopException(org.apache.hop.core.exception.HopException)

Example 5 with IHopFileTypeHandler

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

the class HopGuiFileDelegate method fileSaveAs.

/**
 * We need to figure out which file is open at the given time so we can save it.
 * To do this we see which is the active perspective.
 * Then we ask the perspective for the shown/active file.
 * We then know the filter extension and name so we can show a dialog.
 * We can then also have the {@link IHopFileType to save the file.
 *
 * @return The original filename, not having any variables replaced.  It returns null if no file was saved
 */
public String fileSaveAs() {
    try {
        IHopFileTypeHandler typeHandler = getActiveFileTypeHandler();
        IHopFileType fileType = typeHandler.getFileType();
        if (!fileType.hasCapability(IHopFileType.CAPABILITY_SAVE_AS)) {
            return null;
        }
        String filename = BaseDialog.presentFileDialog(true, hopGui.getShell(), fileType.getFilterExtensions(), fileType.getFilterNames(), true);
        if (filename == null) {
            return null;
        }
        filename = hopGui.getVariables().resolve(filename);
        typeHandler.saveAs(filename);
        // Also save the state of Hop GUI
        // 
        hopGui.auditDelegate.writeLastOpenFiles();
        return filename;
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), "Error", "Error saving file", e);
        return null;
    }
}
Also used : IHopFileType(org.apache.hop.ui.hopgui.file.IHopFileType) IHopFileTypeHandler(org.apache.hop.ui.hopgui.file.IHopFileTypeHandler) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) HopException(org.apache.hop.core.exception.HopException)

Aggregations

IHopFileTypeHandler (org.apache.hop.ui.hopgui.file.IHopFileTypeHandler)22 HopException (org.apache.hop.core.exception.HopException)10 TabItemHandler (org.apache.hop.ui.hopgui.perspective.TabItemHandler)8 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)7 IHopPerspective (org.apache.hop.ui.hopgui.perspective.IHopPerspective)6 IHopFileType (org.apache.hop.ui.hopgui.file.IHopFileType)4 HopDataOrchestrationPerspective (org.apache.hop.ui.hopgui.perspective.dataorch.HopDataOrchestrationPerspective)4 ArrayList (java.util.ArrayList)3 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)3 HopConfigException (org.apache.hop.core.exception.HopConfigException)2 AuditList (org.apache.hop.history.AuditList)2 AuditState (org.apache.hop.history.AuditState)2 AuditStateMap (org.apache.hop.history.AuditStateMap)2 HopGuiPipelineGraph (org.apache.hop.ui.hopgui.file.pipeline.HopGuiPipelineGraph)2 HopGuiWorkflowGraph (org.apache.hop.ui.hopgui.file.workflow.HopGuiWorkflowGraph)2 Stack (java.util.Stack)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 HopExtensionPoint (org.apache.hop.core.extension.HopExtensionPoint)1 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)1 ISearchable (org.apache.hop.core.search.ISearchable)1