Search in sources :

Example 1 with MetadataEditor

use of org.apache.hop.ui.core.metadata.MetadataEditor 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 MetadataEditor

use of org.apache.hop.ui.core.metadata.MetadataEditor in project hop by apache.

the class MetadataPerspective method remove.

@Override
public boolean remove(IHopFileTypeHandler typeHandler) {
    if (typeHandler instanceof MetadataEditor) {
        MetadataEditor<?> editor = (MetadataEditor<?>) typeHandler;
        if (editor.isCloseable()) {
            editors.remove(editor);
            for (CTabItem item : tabFolder.getItems()) {
                if (editor.equals(item.getData())) {
                    item.dispose();
                }
            }
            // Refresh tree to remove bold
            // 
            this.refresh();
            // 
            if (tabFolder.getItemCount() == 0) {
                HopGui.getInstance().handleFileCapabilities(new EmptyFileType(), false, false, false);
            }
        }
    }
    return false;
}
Also used : EmptyFileType(org.apache.hop.ui.hopgui.file.empty.EmptyFileType) MetadataEditor(org.apache.hop.ui.core.metadata.MetadataEditor)

Example 3 with MetadataEditor

use of org.apache.hop.ui.core.metadata.MetadataEditor in project hop by apache.

the class MetadataPerspective method onTabClose.

protected void onTabClose(CTabFolderEvent event) {
    CTabItem tabItem = (CTabItem) event.item;
    MetadataEditor<?> editor = (MetadataEditor<?>) tabItem.getData();
    if (editor.isCloseable()) {
        editors.remove(editor);
        tabItem.dispose();
        // Refresh tree to remove bold
        // 
        this.refresh();
        // 
        if (tabFolder.getItemCount() == 0) {
            HopGui.getInstance().handleFileCapabilities(new EmptyFileType(), false, false, false);
        }
    } else {
        // Ignore event if canceled
        event.doit = false;
    }
}
Also used : EmptyFileType(org.apache.hop.ui.hopgui.file.empty.EmptyFileType) MetadataEditor(org.apache.hop.ui.core.metadata.MetadataEditor)

Aggregations

MetadataEditor (org.apache.hop.ui.core.metadata.MetadataEditor)3 EmptyFileType (org.apache.hop.ui.hopgui.file.empty.EmptyFileType)2 ArrayList (java.util.ArrayList)1 HopException (org.apache.hop.core.exception.HopException)1 AuditList (org.apache.hop.history.AuditList)1 AuditState (org.apache.hop.history.AuditState)1 AuditStateMap (org.apache.hop.history.AuditStateMap)1 IHopMetadata (org.apache.hop.metadata.api.IHopMetadata)1 IHopFileTypeHandler (org.apache.hop.ui.hopgui.file.IHopFileTypeHandler)1 IHopPerspective (org.apache.hop.ui.hopgui.perspective.IHopPerspective)1 TabItemHandler (org.apache.hop.ui.hopgui.perspective.TabItemHandler)1