Search in sources :

Example 11 with TabItemHandler

use of org.apache.hop.ui.hopgui.perspective.TabItemHandler in project hop by apache.

the class MetadataFileTypeHandler method close.

@Override
public void close() {
    TabItemHandler tabItemHandler = findTabItemHandler();
    if (tabItemHandler == null) {
        return;
    }
    // Simply close the associated tab
    // 
    CTabItem tabItem = tabItemHandler.getTabItem();
    tabItem.dispose();
    // Also remove it from the perspective
    MetadataPerspective.getInstance().remove(tabItemHandler.getTypeHandler());
}
Also used : TabItemHandler(org.apache.hop.ui.hopgui.perspective.TabItemHandler) CTabItem(org.eclipse.swt.custom.CTabItem)

Example 12 with TabItemHandler

use of org.apache.hop.ui.hopgui.perspective.TabItemHandler in project hop by apache.

the class MetadataFileTypeHandler method isCloseable.

@Override
public boolean isCloseable() {
    TabItemHandler tabItemHandler = findTabItemHandler();
    if (tabItemHandler == null) {
        return true;
    }
    IHopFileTypeHandler typeHandler = tabItemHandler.getTypeHandler();
    return typeHandler.isCloseable();
}
Also used : IHopFileTypeHandler(org.apache.hop.ui.hopgui.file.IHopFileTypeHandler) TabItemHandler(org.apache.hop.ui.hopgui.perspective.TabItemHandler)

Example 13 with TabItemHandler

use of org.apache.hop.ui.hopgui.perspective.TabItemHandler in project hop by apache.

the class HopPipelineFileType method openFile.

@Override
public IHopFileTypeHandler openFile(HopGui hopGui, String filename, IVariables parentVariableSpace) throws HopException {
    try {
        // This file is opened in the data orchestration perspective
        // 
        HopDataOrchestrationPerspective perspective = HopGui.getDataOrchestrationPerspective();
        perspective.activate();
        // See if the same pipeline isn't already open.
        // Other file types we might allow to open more than once but not pipelines for now.
        // 
        TabItemHandler tabItemHandlerWithFilename = perspective.findTabItemHandlerWithFilename(filename);
        if (tabItemHandlerWithFilename != null) {
            // Same file so we can simply switch to it.
            // This will prevent confusion.
            // 
            perspective.switchToTab(tabItemHandlerWithFilename);
            return tabItemHandlerWithFilename.getTypeHandler();
        }
        // Load the pipeline
        // 
        PipelineMeta pipelineMeta = new PipelineMeta(filename, hopGui.getMetadataProvider(), true, parentVariableSpace);
        // Pass the MetaStore for reference lookups
        // 
        pipelineMeta.setMetadataProvider(hopGui.getMetadataProvider());
        // Show it in the perspective
        // 
        IHopFileTypeHandler typeHandler = perspective.addPipeline(hopGui, pipelineMeta, this);
        // Keep track of open...
        // 
        AuditManager.registerEvent(HopNamespace.getNamespace(), "file", filename, "open");
        // Inform those that want to know about it that we loaded a pipeline
        // 
        ExtensionPointHandler.callExtensionPoint(hopGui.getLog(), parentVariableSpace, HopExtensionPoint.PipelineAfterOpen.id, pipelineMeta);
        return typeHandler;
    } catch (Exception e) {
        throw new HopException("Error opening pipeline file '" + filename + "'", e);
    }
}
Also used : IHopFileTypeHandler(org.apache.hop.ui.hopgui.file.IHopFileTypeHandler) HopDataOrchestrationPerspective(org.apache.hop.ui.hopgui.perspective.dataorch.HopDataOrchestrationPerspective) HopException(org.apache.hop.core.exception.HopException) TabItemHandler(org.apache.hop.ui.hopgui.perspective.TabItemHandler) HopException(org.apache.hop.core.exception.HopException) PipelineMeta(org.apache.hop.pipeline.PipelineMeta)

Example 14 with TabItemHandler

use of org.apache.hop.ui.hopgui.perspective.TabItemHandler 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 15 with TabItemHandler

use of org.apache.hop.ui.hopgui.perspective.TabItemHandler in project hop by apache.

the class HopDataOrchestrationPerspective method handleTabCloseEvent.

private void handleTabCloseEvent(CTabFolderEvent event) {
    // A tab is closed.  We need to handle this gracefully.
    // - Look up which tab it is
    // - Look up which file it contains
    // - Save the file if it was changed
    // - Remove the tab and file from the list
    // 
    CTabItem tabItem = (CTabItem) event.item;
    int tabIndex = tabFolder.indexOf(tabItem);
    TabItemHandler tabItemHandler = findTabItemHandler(tabItem);
    if (tabItemHandler == null) {
        hopGui.getLog().logError("Tab item handler not found for tab item " + tabItem.toString());
        return;
    }
    IHopFileTypeHandler typeHandler = tabItemHandler.getTypeHandler();
    boolean isRemoved = remove(typeHandler);
    // Ignore event if canceled
    if (!isRemoved) {
        event.doit = false;
        return;
    }
    // 
    if (tabIndex >= 0) {
        // Remove the index from the tab selection history
        // 
        int historyIndex = tabSelectionHistory.indexOf(tabIndex);
        while (historyIndex >= 0) {
            if (historyIndex <= tabSelectionIndex) {
                tabSelectionIndex--;
            }
            tabSelectionHistory.remove(historyIndex);
            // Search again
            historyIndex = tabSelectionHistory.indexOf(tabIndex);
        }
        // Compress the history: 2 the same files visited after each other become one.
        // 
        Stack<Integer> newHistory = new Stack<>();
        Integer previous = null;
        for (int i = 0; i < tabSelectionHistory.size(); i++) {
            Integer index = tabSelectionHistory.get(i);
            if (previous == null || previous != index) {
                newHistory.add(index);
            } else {
                if (tabSelectionIndex >= i) {
                    tabSelectionIndex--;
                }
            }
            previous = index;
        }
        tabSelectionHistory = newHistory;
        // 
        for (int i = 0; i < tabSelectionHistory.size(); i++) {
            int index = tabSelectionHistory.get(i);
            if (index > tabIndex) {
                tabSelectionHistory.set(i, index--);
            }
        }
        // 
        if (tabSelectionIndex < 0) {
            tabSelectionIndex = 0;
        } else if (tabSelectionIndex >= tabSelectionHistory.size()) {
            tabSelectionIndex = tabSelectionHistory.size() - 1;
        }
        if (!tabSelectionHistory.isEmpty()) {
            Integer activeIndex = tabSelectionHistory.get(tabSelectionIndex);
            if (activeIndex < items.size()) {
                activeItem = items.get(activeIndex);
                tabFolder.setSelection(activeIndex);
                activeItem.getTypeHandler().updateGui();
            }
        }
        // 
        if (tabFolder.getItemCount() == 0) {
            HopGui.getInstance().handleFileCapabilities(new EmptyFileType(), false, false, false);
        }
    }
}
Also used : IHopFileTypeHandler(org.apache.hop.ui.hopgui.file.IHopFileTypeHandler) EmptyFileType(org.apache.hop.ui.hopgui.file.empty.EmptyFileType) TabItemHandler(org.apache.hop.ui.hopgui.perspective.TabItemHandler) CTabItem(org.eclipse.swt.custom.CTabItem) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint) Stack(java.util.Stack)

Aggregations

TabItemHandler (org.apache.hop.ui.hopgui.perspective.TabItemHandler)18 IHopFileTypeHandler (org.apache.hop.ui.hopgui.file.IHopFileTypeHandler)9 HopException (org.apache.hop.core.exception.HopException)8 CTabItem (org.eclipse.swt.custom.CTabItem)7 ArrayList (java.util.ArrayList)4 HopExtensionPoint (org.apache.hop.core.extension.HopExtensionPoint)4 IHopPerspective (org.apache.hop.ui.hopgui.perspective.IHopPerspective)4 HopDataOrchestrationPerspective (org.apache.hop.ui.hopgui.perspective.dataorch.HopDataOrchestrationPerspective)4 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)3 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)3 HopGui (org.apache.hop.ui.hopgui.HopGui)3 WorkflowMeta (org.apache.hop.workflow.WorkflowMeta)3 Stack (java.util.Stack)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 IHasFilename (org.apache.hop.core.file.IHasFilename)2 ISearchable (org.apache.hop.core.search.ISearchable)2 ISearchableCallback (org.apache.hop.core.search.ISearchableCallback)2 AuditList (org.apache.hop.history.AuditList)2 AuditState (org.apache.hop.history.AuditState)2 AuditStateMap (org.apache.hop.history.AuditStateMap)2