use of org.pentaho.di.core.LastUsedFile in project pentaho-kettle by pentaho.
the class RecentUtilsTest method setPathsRepositoryTest.
@Test
public void setPathsRepositoryTest() {
LastUsedFile lastUsedFile = new LastUsedFile(LastUsedFile.FILE_TYPE_TRANSFORMATION, "file", "/home/admin", true, "repo", "admin", true, 1, new Date(), "");
RecentFile recentFile = new RecentFile();
RecentUtils.setPaths(lastUsedFile, recentFile);
Assert.assertEquals("file", recentFile.getName());
Assert.assertEquals("/home/admin", recentFile.getParent());
Assert.assertEquals("/home/admin/file", recentFile.getPath());
Assert.assertEquals("repo", recentFile.getRepository());
Assert.assertEquals("admin", recentFile.getUsername());
}
use of org.pentaho.di.core.LastUsedFile in project pentaho-kettle by pentaho.
the class RecentUtilsTest method setPathsVFSTest.
@Test
public void setPathsVFSTest() {
LastUsedFile lastUsedFile = new LastUsedFile(LastUsedFile.FILE_TYPE_TRANSFORMATION, PVFS_PATH, null, false, null, null, false, 1, new Date(), NAMED_CONNECTION);
RecentFile recentFile = new RecentFile();
RecentUtils.setPaths(lastUsedFile, recentFile);
Assert.assertEquals(PVFS_FILENAME, recentFile.getName());
Assert.assertEquals(PVFS_PARENT, recentFile.getParent());
Assert.assertEquals(PVFS_PATH, recentFile.getPath());
}
use of org.pentaho.di.core.LastUsedFile in project pentaho-kettle by pentaho.
the class RecentFileProvider method getTree.
@Override
public Tree getTree() {
RecentTree recentTree = new RecentTree(NAME);
PropsUI propsUI = getPropsUI();
Date dateThreshold = getDateThreshold();
List<LastUsedFile> lastUsedFiles = propsUI.getLastUsedFiles().stream().filter(lastUsedFile -> !lastUsedFile.getLastOpened().before(dateThreshold)).collect(Collectors.toList());
for (LastUsedFile lastUsedFile : lastUsedFiles) {
recentTree.addChild(RecentFile.create(lastUsedFile));
}
return recentTree;
}
use of org.pentaho.di.core.LastUsedFile in project pentaho-kettle by pentaho.
the class RepositoryOpenSaveExtensionPoint method callExtensionPoint.
@Override
public void callExtensionPoint(LogChannelInterface logChannelInterface, Object o) throws KettleException {
FileDialogOperation fileDialogOperation = (FileDialogOperation) o;
PropsUI propsUI = propsUISupplier.get();
String startingDir = null;
if (fileDialogOperation.getRepository() == null) {
String username = getRepository().getUserInfo() != null ? getRepository().getUserInfo().getLogin() : "";
String repoAndUser = getRepository().getName() + ":" + username;
List<LastUsedFile> lastUsedFileList = propsUI.getLastUsedRepoFiles().getOrDefault(repoAndUser, Collections.emptyList());
startingDir = getStartingDir(fileDialogOperation, lastUsedFileList);
} else {
startingDir = fileDialogOperation.getStartDir();
}
RepositoryOpenSaveDialog repositoryOpenSaveDialog = new RepositoryOpenSaveDialog(spoonSupplier.get().getShell(), WIDTH, HEIGHT);
repositoryOpenSaveDialog.open(fileDialogOperation.getRepository(), startingDir, fileDialogOperation.getCommand(), fileDialogOperation.getTitle(), fileDialogOperation.getFilter(), fileDialogOperation.getOrigin(), fileDialogOperation.getFilename(), fileDialogOperation.getFileType());
if (!Utils.isEmpty(repositoryOpenSaveDialog.getObjectName())) {
RepositoryObject repositoryObject = new RepositoryObject();
repositoryObject.setObjectId(repositoryOpenSaveDialog::getObjectId);
repositoryObject.setName(repositoryOpenSaveDialog.getObjectName());
repositoryObject.setRepositoryDirectory(getRepository().findDirectory(repositoryOpenSaveDialog.getObjectDirectory()));
repositoryObject.setObjectType(repositoryOpenSaveDialog.getObjectType().equals(TRANSFORMATION) ? RepositoryObjectType.TRANSFORMATION : RepositoryObjectType.JOB);
fileDialogOperation.setRepositoryObject(repositoryObject);
}
}
use of org.pentaho.di.core.LastUsedFile in project pentaho-kettle by pentaho.
the class RepositoryOpenSaveExtensionPoint method getStartingDir.
private String getStartingDir(FileDialogOperation fileDialogOperation, List<LastUsedFile> lastUsedFileList) {
String startingDir = fileDialogOperation.getStartDir();
if (!Utils.isEmpty(startingDir)) {
return startingDir;
}
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, DAYS);
Date dateBefore = calendar.getTime();
LastUsedFile lastUsedFile = null;
if (lastUsedFileList.size() > 0 && lastUsedFileList.get(0).getLastOpened().after(dateBefore)) {
lastUsedFile = lastUsedFileList.get(0);
}
return lastUsedFile != null ? lastUsedFile.getDirectory() : null;
}
Aggregations