Search in sources :

Example 1 with AuditState

use of org.apache.hop.history.AuditState 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 AuditState

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

the class ContextDialog method recallToolbarSettings.

private void recallToolbarSettings() {
    Button categoriesCheckBox = getCategoriesCheckBox();
    if (categoriesCheckBox != null) {
        String strUseCategories = HopConfig.getGuiProperty(AUDIT_TYPE_TOOLBAR_SHOW_CATEGORIES);
        categoriesCheckBox.setSelection("Y".equalsIgnoreCase(Const.NVL(strUseCategories, "Y")));
    }
    Button fixedWidthCheckBox = getFixedWidthCheckBox();
    if (fixedWidthCheckBox != null) {
        String strUseFixedWidth = HopConfig.getGuiProperty(AUDIT_TYPE_TOOLBAR_FIXED_WIDTH);
        fixedWidthCheckBox.setSelection("Y".equalsIgnoreCase(Const.NVL(strUseFixedWidth, "Y")));
    }
    AuditState auditState = AuditManager.retrieveState(LogChannel.UI, HopNamespace.getNamespace(), AUDIT_TYPE_CONTEXT_DIALOG, AUDIT_NAME_CATEGORY_STATES);
    if (auditState != null) {
        Map<String, Object> states = auditState.getStateMap();
        for (CategoryAndOrder category : categories) {
            Object expanded = states.get(category.getCategory());
            if (expanded == null) {
                category.setCollapsed(false);
            } else {
                category.setCollapsed("N".equalsIgnoreCase(expanded.toString()));
            }
        }
    }
}
Also used : AuditState(org.apache.hop.history.AuditState)

Example 3 with AuditState

use of org.apache.hop.history.AuditState 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)

Aggregations

AuditState (org.apache.hop.history.AuditState)3 HopException (org.apache.hop.core.exception.HopException)2 AuditList (org.apache.hop.history.AuditList)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 IHopMetadata (org.apache.hop.metadata.api.IHopMetadata)1 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)1 MetadataEditor (org.apache.hop.ui.core.metadata.MetadataEditor)1