use of org.apache.hop.history.AuditStateMap 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);
}
}
}
}
use of org.apache.hop.history.AuditStateMap 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);
}
}
}
}
Aggregations