Search in sources :

Example 1 with AuditList

use of org.apache.hop.history.AuditList in project hop by apache.

the class HopGuiAuditDelegate method writeLastOpenFiles.

/**
 * Remember all the open files per perspective
 */
public void writeLastOpenFiles() {
    if (!hopGui.getProps().openLastFile()) {
        return;
    }
    List<IHopPerspective> perspectives = hopGui.getPerspectiveManager().getPerspectives();
    for (IHopPerspective perspective : perspectives) {
        IHopFileTypeHandler activeFileTypeHandler = perspective.getActiveFileTypeHandler();
        List<TabItemHandler> tabItems = perspective.getItems();
        if (tabItems != null) {
            // This perspective has the ability to handle multiple files.
            // Lets's save the files in the given order...
            // 
            AuditStateMap auditStateMap = new AuditStateMap();
            List<String> files = new ArrayList<>();
            for (TabItemHandler tabItem : tabItems) {
                IHopFileTypeHandler typeHandler = tabItem.getTypeHandler();
                String filename = typeHandler.getFilename();
                String name = typeHandler.getName();
                if (StringUtils.isNotEmpty(filename)) {
                    // Regular filename
                    // 
                    files.add(filename);
                    // Also save the state : active, zoom, ...
                    // 
                    Map<String, Object> stateProperties = typeHandler.getStateProperties();
                    boolean active = activeFileTypeHandler != null && activeFileTypeHandler.getFilename() != null && activeFileTypeHandler.getFilename().equals(filename);
                    stateProperties.put(STATE_PROPERTY_ACTIVE, active);
                    auditStateMap.add(new AuditState(filename, stateProperties));
                } else if (typeHandler instanceof MetadataEditor<?>) {
                    // 
                    if (StringUtils.isNotEmpty(name)) {
                        // Metadata saved by name
                        // We also need to store the metadata type...
                        // 
                        MetadataEditor<?> metadataEditor = (MetadataEditor<?>) typeHandler;
                        IHopMetadata metadata = metadataEditor.getMetadata();
                        Class<? extends IHopMetadata> metadataClass = metadata.getClass();
                        // Save as METADATA:className:name
                        // 
                        files.add(METADATA_FILENAME_PREFIX + metadataClass.getName() + ":" + name);
                    }
                }
            }
            AuditList auditList = new AuditList(files);
            try {
                AuditManager.getActive().storeList(HopNamespace.getNamespace(), perspective.getId(), auditList);
                AuditManager.getActive().saveAuditStateMap(HopNamespace.getNamespace(), perspective.getId(), auditStateMap);
            } catch (Exception e) {
                hopGui.getLog().logError("Error writing audit list of perspective " + perspective.getId(), e);
            }
        }
    }
}
Also used : IHopFileTypeHandler(org.apache.hop.ui.hopgui.file.IHopFileTypeHandler) IHopMetadata(org.apache.hop.metadata.api.IHopMetadata) ArrayList(java.util.ArrayList) TabItemHandler(org.apache.hop.ui.hopgui.perspective.TabItemHandler) HopException(org.apache.hop.core.exception.HopException) IHopPerspective(org.apache.hop.ui.hopgui.perspective.IHopPerspective) AuditList(org.apache.hop.history.AuditList) AuditState(org.apache.hop.history.AuditState) MetadataEditor(org.apache.hop.ui.core.metadata.MetadataEditor) AuditStateMap(org.apache.hop.history.AuditStateMap)

Example 2 with AuditList

use of org.apache.hop.history.AuditList in project hop by apache.

the class AuditManagerGuiUtil method addLastUsedValue.

public static final void addLastUsedValue(String type, String value) {
    if (StringUtil.isEmpty(value)) {
        // Not storing empty values
        return;
    }
    IAuditManager auditManager = AuditManager.getActive();
    try {
        AuditList list = auditManager.retrieveList(HopNamespace.getNamespace(), type);
        if (list == null) {
            list = new AuditList();
        }
        List<String> names = list.getNames();
        // Move the value to the start of the list if it exists
        // 
        int index = names.indexOf(value);
        if (index >= 0) {
            names.remove(index);
        }
        names.add(0, value);
        // 
        while (list.getNames().size() > 50) {
            list.getNames().remove(list.getNames().size() - 1);
        }
        auditManager.storeList(HopNamespace.getNamespace(), type, list);
    } catch (Exception e) {
        LogChannel.UI.logError("Unable to store list using audit manager with type: " + type + " in group " + HopNamespace.getNamespace(), e);
    }
}
Also used : IAuditManager(org.apache.hop.history.IAuditManager) AuditList(org.apache.hop.history.AuditList)

Example 3 with AuditList

use of org.apache.hop.history.AuditList in project hop by apache.

the class HopGuiAuditDelegate method openLastFiles.

public void openLastFiles() {
    if (!hopGui.getProps().openLastFile()) {
        return;
    }
    // Open the last files for each perspective...
    // 
    List<IHopPerspective> perspectives = hopGui.getPerspectiveManager().getPerspectives();
    for (IHopPerspective perspective : perspectives) {
        List<TabItemHandler> tabItems = perspective.getItems();
        IHopFileTypeHandler activeFileTypeHandler = null;
        if (tabItems != null) {
            // This perspective has the ability to handle multiple files.
            // Let's load the files in the previously saved order...
            // 
            AuditList auditList;
            try {
                auditList = AuditManager.getActive().retrieveList(HopNamespace.getNamespace(), perspective.getId());
            } catch (Exception e) {
                hopGui.getLog().logError("Error reading audit list of perspective " + perspective.getId(), e);
                auditList = new AuditList();
            }
            AuditStateMap auditStateMap;
            try {
                auditStateMap = AuditManager.getActive().loadAuditStateMap(HopNamespace.getNamespace(), perspective.getId());
            } catch (HopException e) {
                hopGui.getLog().logError("Error loading audit state map of perspective " + perspective.getId(), e);
                auditStateMap = new AuditStateMap();
            }
            for (String filename : auditList.getNames()) {
                try {
                    if (StringUtils.isNotEmpty(filename)) {
                        if (filename.startsWith(METADATA_FILENAME_PREFIX)) {
                            // Metadata tab information
                            // 
                            int colonIndex = filename.indexOf(":", METADATA_FILENAME_PREFIX.length() + 1);
                            if (colonIndex > 0) {
                                String className = filename.substring(METADATA_FILENAME_PREFIX.length(), colonIndex);
                                String name = filename.substring(colonIndex + 1);
                                openMetadataObject(className, name);
                            }
                        } else {
                            // Regular filename
                            IHopFileTypeHandler fileTypeHandler = hopGui.fileDelegate.fileOpen(filename);
                            if (fileTypeHandler != null) {
                                // Restore zoom, scroll and so on
                                AuditState auditState = auditStateMap.get(filename);
                                if (auditState != null && fileTypeHandler != null) {
                                    fileTypeHandler.applyStateProperties(auditState.getStateMap());
                                    Boolean bActive = (Boolean) auditState.getStateMap().get(STATE_PROPERTY_ACTIVE);
                                    if (bActive != null && bActive.booleanValue()) {
                                        activeFileTypeHandler = fileTypeHandler;
                                    }
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    new ErrorDialog(hopGui.getShell(), "Error", "Error opening file '" + filename + "'", e);
                }
            }
            // 
            if (activeFileTypeHandler != null) {
                perspective.setActiveFileTypeHandler(activeFileTypeHandler);
            }
        }
    }
}
Also used : IHopFileTypeHandler(org.apache.hop.ui.hopgui.file.IHopFileTypeHandler) HopException(org.apache.hop.core.exception.HopException) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) TabItemHandler(org.apache.hop.ui.hopgui.perspective.TabItemHandler) HopException(org.apache.hop.core.exception.HopException) IHopPerspective(org.apache.hop.ui.hopgui.perspective.IHopPerspective) AuditList(org.apache.hop.history.AuditList) AuditState(org.apache.hop.history.AuditState) AuditStateMap(org.apache.hop.history.AuditStateMap)

Example 4 with AuditList

use of org.apache.hop.history.AuditList in project hop by apache.

the class HopVfsFileDialog method dispose.

private void dispose() {
    instance = null;
    try {
        AuditManager.getActive().storeList(usedNamespace, BOOKMARKS_AUDIT_TYPE, new AuditList(navigationHistory));
    } catch (Exception e) {
        LogChannel.GENERAL.logError("Error storing navigation history", e);
    }
    props.setScreen(new WindowProperty(shell));
    // We no longer need the toolbar or the objects it used to listen to the buttons
    // 
    bookmarksToolbarWidgets.dispose();
    browserToolbarWidgets.dispose();
    shell.dispose();
}
Also used : WindowProperty(org.apache.hop.ui.core.gui.WindowProperty) AuditList(org.apache.hop.history.AuditList) HopException(org.apache.hop.core.exception.HopException) FileSystemException(org.apache.commons.vfs2.FileSystemException)

Aggregations

AuditList (org.apache.hop.history.AuditList)4 HopException (org.apache.hop.core.exception.HopException)3 AuditState (org.apache.hop.history.AuditState)2 AuditStateMap (org.apache.hop.history.AuditStateMap)2 IHopFileTypeHandler (org.apache.hop.ui.hopgui.file.IHopFileTypeHandler)2 IHopPerspective (org.apache.hop.ui.hopgui.perspective.IHopPerspective)2 TabItemHandler (org.apache.hop.ui.hopgui.perspective.TabItemHandler)2 ArrayList (java.util.ArrayList)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 IAuditManager (org.apache.hop.history.IAuditManager)1 IHopMetadata (org.apache.hop.metadata.api.IHopMetadata)1 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)1 WindowProperty (org.apache.hop.ui.core.gui.WindowProperty)1 MetadataEditor (org.apache.hop.ui.core.metadata.MetadataEditor)1