Search in sources :

Example 6 with TabItemHandler

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

the class HopWorkflowFileType 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 workflow isn't already open.
        // Other file types we might allow to open more than once but not workflows 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 workflow from file
        // 
        WorkflowMeta workflowMeta = new WorkflowMeta(parentVariableSpace, filename, hopGui.getMetadataProvider());
        // Pass the MetaStore for reference lookups
        // 
        workflowMeta.setMetadataProvider(hopGui.getMetadataProvider());
        // 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, "WorkflowAfterOpen", workflowMeta);
        // 
        return perspective.addWorkflow(hopGui, workflowMeta, this);
    } catch (Exception e) {
        throw new HopException("Error opening workflow file '" + filename + "'", e);
    }
}
Also used : 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) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta)

Example 7 with TabItemHandler

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

the class HopDataOrchestrationPerspective method addPipeline.

/**
 * Add a new pipeline tab to the tab folder...
 *
 * @param pipelineMeta
 * @return
 */
public IHopFileTypeHandler addPipeline(HopGui hopGui, PipelineMeta pipelineMeta, HopPipelineFileType pipelineFile) throws HopException {
    CTabItem tabItem = new CTabItem(tabFolder, SWT.CLOSE);
    tabItem.setImage(GuiResource.getInstance().getImagePipeline());
    HopGuiPipelineGraph pipelineGraph = new HopGuiPipelineGraph(tabFolder, hopGui, tabItem, this, pipelineMeta, pipelineFile);
    tabItem.setControl(pipelineGraph);
    // Set the tab name
    // 
    updateTabLabel(tabItem, pipelineMeta.getFilename(), pipelineMeta.getName());
    // Update the internal variables (file specific) in the pipeline graph variables
    // 
    pipelineMeta.setInternalHopVariables(pipelineGraph.getVariables());
    // Update the variables using the list of parameters
    // 
    hopGui.setParametersAsVariablesInUI(pipelineMeta, pipelineGraph.getVariables());
    // Switch to the tab
    tabFolder.setSelection(tabItem);
    activeItem = new TabItemHandler(tabItem, pipelineGraph);
    items.add(activeItem);
    // 
    while (tabSelectionHistory.size() - 1 > tabSelectionIndex) {
        tabSelectionHistory.pop();
    }
    int tabIndex = tabFolder.indexOf(tabItem);
    tabSelectionHistory.add(tabIndex);
    tabSelectionIndex = tabSelectionHistory.size() - 1;
    try {
        ExtensionPointHandler.callExtensionPoint(hopGui.getLog(), pipelineGraph.getVariables(), HopExtensionPoint.HopGuiNewPipelineTab.id, pipelineGraph);
    } catch (Exception e) {
        throw new HopException("Error calling extension point plugin for plugin id " + HopExtensionPoint.HopGuiNewPipelineTab.id + " trying to handle a new pipeline tab", e);
    }
    pipelineGraph.adjustScrolling();
    pipelineGraph.setFocus();
    return pipelineGraph;
}
Also used : HopException(org.apache.hop.core.exception.HopException) TabItemHandler(org.apache.hop.ui.hopgui.perspective.TabItemHandler) CTabItem(org.eclipse.swt.custom.CTabItem) HopGuiPipelineGraph(org.apache.hop.ui.hopgui.file.pipeline.HopGuiPipelineGraph) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint) HopException(org.apache.hop.core.exception.HopException)

Example 8 with TabItemHandler

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

the class HopDataOrchestrationPerspective method getSearchables.

@Override
public List<ISearchable> getSearchables() {
    List<ISearchable> searchables = new ArrayList<>();
    for (final TabItemHandler item : items) {
        // The type handler is the pipeline or workflow
        // 
        IHopFileTypeHandler typeHandler = item.getTypeHandler();
        searchables.add(new ISearchable() {

            @Override
            public String getLocation() {
                return "Data orchestration perspective in tab : " + item.getTabItem().getText();
            }

            @Override
            public String getName() {
                return typeHandler.getName();
            }

            @Override
            public String getType() {
                return typeHandler.getFileType().getName();
            }

            @Override
            public String getFilename() {
                return typeHandler.getFilename();
            }

            @Override
            public Object getSearchableObject() {
                return typeHandler.getSubject();
            }

            @Override
            public ISearchableCallback getSearchCallback() {
                return (searchable, searchResult) -> {
                    activate();
                    switchToTab(item);
                };
            }
        });
    }
    return searchables;
}
Also used : IHopFileTypeHandler(org.apache.hop.ui.hopgui.file.IHopFileTypeHandler) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TabItemHandler(org.apache.hop.ui.hopgui.perspective.TabItemHandler) ISearchable(org.apache.hop.core.search.ISearchable) ISearchableCallback(org.apache.hop.core.search.ISearchableCallback)

Example 9 with TabItemHandler

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

the class HopDataOrchestrationPerspective method remove.

/**
 * Remove the file type handler from this perspective, from the tab folder. This simply tries to
 * remove the item, does not
 *
 * @param typeHandler The file type handler to remove
 * @return true if the handler was removed from the perspective, false if it wasn't (cancelled,
 *     not possible, ...)
 */
@Override
public boolean remove(IHopFileTypeHandler typeHandler) {
    TabItemHandler tabItemHandler = findTabItemHandler(typeHandler);
    if (tabItemHandler == null) {
        return false;
    }
    if (typeHandler.isCloseable()) {
        // Remove the tab item handler from the list
        // Then close the tab item...
        // 
        items.remove(tabItemHandler);
        CTabItem tabItem = tabItemHandler.getTabItem();
        tabItem.dispose();
        // Also remove the keyboard shortcuts for this handler
        // 
        HopGuiKeyHandler.getInstance().removeParentObjectToHandle(typeHandler);
        hopGui.getMainHopGuiComposite().setFocus();
        if (typeHandler.getSubject() != null) {
            if (typeHandler.getSubject() instanceof PipelineMeta) {
                try {
                    ExtensionPointHandler.callExtensionPoint(hopGui.getLog(), hopGui.getVariables(), HopExtensionPoint.HopGuiPipelineAfterClose.id, typeHandler.getSubject());
                } catch (Exception e) {
                    hopGui.getLog().logError("Error calling extension point 'HopGuiPipelineAfterClose'", e);
                }
            } else if (typeHandler.getSubject() instanceof WorkflowMeta) {
                try {
                    ExtensionPointHandler.callExtensionPoint(hopGui.getLog(), hopGui.getVariables(), HopExtensionPoint.HopGuiWorkflowAfterClose.id, typeHandler.getSubject());
                } catch (Exception e) {
                    hopGui.getLog().logError("Error calling extension point 'HopGuiWorkflowAfterClose'", e);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TabItemHandler(org.apache.hop.ui.hopgui.perspective.TabItemHandler) CTabItem(org.eclipse.swt.custom.CTabItem) HopException(org.apache.hop.core.exception.HopException) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta)

Example 10 with TabItemHandler

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

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