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());
}
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();
}
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);
}
}
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);
}
}
}
}
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);
}
}
}
Aggregations