Search in sources :

Example 1 with LastUsedFile

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());
}
Also used : LastUsedFile(org.pentaho.di.core.LastUsedFile) Date(java.util.Date) RecentFile(org.pentaho.di.plugins.fileopensave.providers.recents.model.RecentFile) Test(org.junit.Test)

Example 2 with LastUsedFile

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());
}
Also used : LastUsedFile(org.pentaho.di.core.LastUsedFile) Date(java.util.Date) RecentFile(org.pentaho.di.plugins.fileopensave.providers.recents.model.RecentFile) Test(org.junit.Test)

Example 3 with LastUsedFile

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;
}
Also used : LastUsedFile(org.pentaho.di.core.LastUsedFile) Date(java.util.Date) BaseFileProvider(org.pentaho.di.plugins.fileopensave.api.providers.BaseFileProvider) PropsUI(org.pentaho.di.ui.core.PropsUI) Tree(org.pentaho.di.plugins.fileopensave.api.providers.Tree) File(org.pentaho.di.plugins.fileopensave.api.providers.File) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) FileException(org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException) List(java.util.List) RecentTree(org.pentaho.di.plugins.fileopensave.providers.recents.model.RecentTree) Calendar(java.util.Calendar) RecentFile(org.pentaho.di.plugins.fileopensave.providers.recents.model.RecentFile) Collections(java.util.Collections) InputStream(java.io.InputStream) RecentTree(org.pentaho.di.plugins.fileopensave.providers.recents.model.RecentTree) Date(java.util.Date) LastUsedFile(org.pentaho.di.core.LastUsedFile) PropsUI(org.pentaho.di.ui.core.PropsUI)

Example 4 with LastUsedFile

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);
    }
}
Also used : RepositoryObject(org.pentaho.di.repository.RepositoryObject) RepositoryOpenSaveDialog(org.pentaho.repo.dialog.RepositoryOpenSaveDialog) LastUsedFile(org.pentaho.di.core.LastUsedFile) FileDialogOperation(org.pentaho.di.ui.core.FileDialogOperation) PropsUI(org.pentaho.di.ui.core.PropsUI)

Example 5 with LastUsedFile

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;
}
Also used : Calendar(java.util.Calendar) Date(java.util.Date) LastUsedFile(org.pentaho.di.core.LastUsedFile)

Aggregations

LastUsedFile (org.pentaho.di.core.LastUsedFile)31 Point (org.pentaho.di.core.gui.Point)17 Date (java.util.Date)9 RecentFile (org.pentaho.di.plugins.fileopensave.providers.recents.model.RecentFile)5 Calendar (java.util.Calendar)4 Test (org.junit.Test)4 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)4 PropsUI (org.pentaho.di.ui.core.PropsUI)4 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 IUser (org.pentaho.di.repository.IUser)2 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collections (java.util.Collections)1 List (java.util.List)1 PropertyResourceBundle (java.util.PropertyResourceBundle)1 ResourceBundle (java.util.ResourceBundle)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1