Search in sources :

Example 1 with IHopFileType

use of org.apache.hop.ui.hopgui.file.IHopFileType 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 2 with IHopFileType

use of org.apache.hop.ui.hopgui.file.IHopFileType 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 3 with IHopFileType

use of org.apache.hop.ui.hopgui.file.IHopFileType 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)

Example 4 with IHopFileType

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

the class ExplorerPerspective method loadTypeImages.

private void loadTypeImages(Composite parentComposite) {
    typeImageMap = new HashMap<>();
    int iconSize = (int) (PropsUi.getInstance().getZoomFactor() * 16);
    for (IHopFileType fileType : fileTypes) {
        String imageFilename = fileType.getFileTypeImage();
        if (imageFilename != null) {
            try {
                SvgCacheEntry svgCacheEntry = SvgCache.loadSvg(new SvgFile(imageFilename, fileType.getClass().getClassLoader()));
                SwtUniversalImageSvg imageSvg = new SwtUniversalImageSvg(new SvgImage(svgCacheEntry.getSvgDocument()));
                Image image = imageSvg.getAsBitmapForSize(hopGui.getDisplay(), iconSize, iconSize);
                typeImageMap.put(fileType.getName(), image);
            } catch (Exception e) {
                hopGui.getLog().logError("Error loading image : '" + imageFilename + "' for type '" + fileType.getName() + "'", e);
            }
        }
    }
    // Properly dispose images when done...
    // 
    parentComposite.addListener(SWT.Dispose, e -> {
        for (Image image : typeImageMap.values()) {
            image.dispose();
        }
    });
}
Also used : IHopFileType(org.apache.hop.ui.hopgui.file.IHopFileType) SvgCacheEntry(org.apache.hop.core.svg.SvgCacheEntry) SwtUniversalImageSvg(org.apache.hop.core.SwtUniversalImageSvg) SvgImage(org.apache.hop.core.svg.SvgImage) SvgImage(org.apache.hop.core.svg.SvgImage) Image(org.eclipse.swt.graphics.Image) SvgFile(org.apache.hop.core.svg.SvgFile) HopGuiExtensionPoint(org.apache.hop.ui.hopgui.HopGuiExtensionPoint) HopException(org.apache.hop.core.exception.HopException)

Example 5 with IHopFileType

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

the class HopGuiWorkflowGraph method loadReferencedObject.

protected void loadReferencedObject(ActionMeta actionCopy, int index) {
    try {
        IHasFilename referencedMeta = actionCopy.getAction().loadReferencedObject(index, hopGui.getMetadataProvider(), variables);
        if (referencedMeta == null) {
            // Sorry, nothing loaded
            return;
        }
        IHopFileType fileTypeHandler = hopGui.getPerspectiveManager().findFileTypeHandler(referencedMeta);
        fileTypeHandler.openFile(hopGui, referencedMeta.getFilename(), hopGui.getVariables());
    } catch (Exception e) {
        new ErrorDialog(hopShell(), BaseMessages.getString(PKG, "HopGuiWorkflowGraph.ErrorDialog.FileNotLoaded.Header"), BaseMessages.getString(PKG, "HopGuiWorkflowGraph.ErrorDialog.FileNotLoaded.Message"), e);
    }
}
Also used : IHopFileType(org.apache.hop.ui.hopgui.file.IHopFileType) IHasFilename(org.apache.hop.core.file.IHasFilename) HopException(org.apache.hop.core.exception.HopException)

Aggregations

IHopFileType (org.apache.hop.ui.hopgui.file.IHopFileType)11 HopException (org.apache.hop.core.exception.HopException)10 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)4 IHopFileTypeHandler (org.apache.hop.ui.hopgui.file.IHopFileTypeHandler)4 GuiKeyboardShortcut (org.apache.hop.core.gui.plugin.key.GuiKeyboardShortcut)2 GuiOsxKeyboardShortcut (org.apache.hop.core.gui.plugin.key.GuiOsxKeyboardShortcut)2 GuiToolbarElement (org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)2 IPlugin (org.apache.hop.core.plugins.IPlugin)2 PluginRegistry (org.apache.hop.core.plugins.PluginRegistry)2 HopGuiExtensionPoint (org.apache.hop.ui.hopgui.HopGuiExtensionPoint)2 HopFileTypeRegistry (org.apache.hop.ui.hopgui.file.HopFileTypeRegistry)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 FileObject (org.apache.commons.vfs2.FileObject)1 SwtUniversalImageSvg (org.apache.hop.core.SwtUniversalImageSvg)1 GuiContextAction (org.apache.hop.core.action.GuiContextAction)1 GuiContextActionFilter (org.apache.hop.core.action.GuiContextActionFilter)1 HopPluginException (org.apache.hop.core.exception.HopPluginException)1 IHasFilename (org.apache.hop.core.file.IHasFilename)1 GuiRegistry (org.apache.hop.core.gui.plugin.GuiRegistry)1