Search in sources :

Example 11 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)

Example 12 with LastUsedFile

use of org.pentaho.di.core.LastUsedFile in project pentaho-kettle by pentaho.

the class Spoon method lastFileSelect.

public void lastFileSelect(String id) {
    int idx = Integer.parseInt(id);
    List<LastUsedFile> lastUsedFiles = props.getLastUsedFiles();
    lastFileSelect(lastUsedFiles.get(idx));
}
Also used : Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) LastUsedFile(org.pentaho.di.core.LastUsedFile)

Example 13 with LastUsedFile

use of org.pentaho.di.core.LastUsedFile in project pentaho-kettle by pentaho.

the class PropsUI method loadLastUsedRepoFiles.

public void loadLastUsedRepoFiles() {
    lastUsedRepoFiles = new LinkedHashMap<>();
    int nr = Const.toInt(properties.getProperty("lastrepofiles"), 0);
    for (int i = 0; i < nr; i++) {
        String fileType = properties.getProperty("repofiletype" + (i + 1), LastUsedFile.FILE_TYPE_TRANSFORMATION);
        String filename = properties.getProperty("repolastfile" + (i + 1), "");
        String directory = properties.getProperty("repolastdir" + (i + 1), "");
        boolean sourceRepository = YES.equalsIgnoreCase(properties.getProperty("repolasttype" + (i + 1), NO));
        String repositoryName = properties.getProperty("repolastrepo" + (i + 1));
        String username = properties.getProperty("repolastuser" + (i + 1));
        boolean isOpened = YES.equalsIgnoreCase(properties.getProperty("repolastopened" + (i + 1), NO));
        int openItemTypes = Const.toInt(properties.getProperty("repolastopentypes" + (i + 1), "0"), 0);
        Date lastOpened = null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            String repoLastDate = properties.getProperty("repolastdate" + (i + 1));
            if (repoLastDate != null) {
                lastOpened = simpleDateFormat.parse(repoLastDate);
            }
        } catch (ParseException pe) {
        // Default of null is acceptable
        }
        List<LastUsedFile> lastUsedFiles = lastUsedRepoFiles.getOrDefault(repositoryName + ":" + username, new ArrayList<>());
        lastUsedFiles.add(new LastUsedFile(fileType, filename, directory, sourceRepository, repositoryName, username, isOpened, openItemTypes, lastOpened));
        lastUsedRepoFiles.put(repositoryName + ":" + username, lastUsedFiles);
    }
}
Also used : ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Point(org.pentaho.di.core.gui.Point) Date(java.util.Date) LastUsedFile(org.pentaho.di.core.LastUsedFile)

Example 14 with LastUsedFile

use of org.pentaho.di.core.LastUsedFile in project pentaho-kettle by pentaho.

the class PropsUI method setLastFiles.

public void setLastFiles() {
    properties.setProperty("lastfiles", "" + lastUsedFiles.size());
    for (int i = 0; i < lastUsedFiles.size(); i++) {
        LastUsedFile lastUsedFile = lastUsedFiles.get(i);
        properties.setProperty("filetype" + (i + 1), Const.NVL(lastUsedFile.getFileType(), LastUsedFile.FILE_TYPE_TRANSFORMATION));
        properties.setProperty("lastfile" + (i + 1), Const.NVL(lastUsedFile.getFilename(), ""));
        properties.setProperty("lastdir" + (i + 1), Const.NVL(lastUsedFile.getDirectory(), ""));
        properties.setProperty("lasttype" + (i + 1), lastUsedFile.isSourceRepository() ? YES : NO);
        properties.setProperty("lastrepo" + (i + 1), Const.NVL(lastUsedFile.getRepositoryName(), ""));
        properties.setProperty("lastuser" + (i + 1), Const.NVL(lastUsedFile.getUsername(), ""));
    }
}
Also used : Point(org.pentaho.di.core.gui.Point) LastUsedFile(org.pentaho.di.core.LastUsedFile)

Example 15 with LastUsedFile

use of org.pentaho.di.core.LastUsedFile in project pentaho-kettle by pentaho.

the class PropsUI method addLastRepoFile.

private void addLastRepoFile(LastUsedFile lastUsedFile) {
    String repositoryName = lastUsedFile.getRepositoryName();
    String username = lastUsedFile.getUsername() != null ? lastUsedFile.getUsername() : "";
    if (!Utils.isEmpty(repositoryName)) {
        List<LastUsedFile> lastUsedFiles = lastUsedRepoFiles.getOrDefault(repositoryName + ":" + username, new ArrayList<>());
        int idx = lastUsedFiles.indexOf(lastUsedFile);
        if (idx >= 0) {
            lastUsedFiles.remove(idx);
        }
        lastUsedFiles.add(0, lastUsedFile);
        lastUsedRepoFiles.put(repositoryName + ":" + username, lastUsedFiles);
        // If we have more than Const.MAX_FILE_HIST, top it off
        while (lastUsedFiles.size() > 12) {
            lastUsedFiles.remove(lastUsedRepoFiles.get(repositoryName + ":" + username).size() - 1);
        }
    }
}
Also used : LastUsedFile(org.pentaho.di.core.LastUsedFile) Point(org.pentaho.di.core.gui.Point)

Aggregations

LastUsedFile (org.pentaho.di.core.LastUsedFile)25 Point (org.pentaho.di.core.gui.Point)17 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)4 Date (java.util.Date)3 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Calendar (java.util.Calendar)2 PropsUI (org.pentaho.di.ui.core.PropsUI)2 ArrayList (java.util.ArrayList)1 ResourceBundle (java.util.ResourceBundle)1 Action (org.eclipse.jface.action.Action)1 FontData (org.eclipse.swt.graphics.FontData)1 RGB (org.eclipse.swt.graphics.RGB)1 KettleException (org.pentaho.di.core.exception.KettleException)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1 TransAction (org.pentaho.di.core.undo.TransAction)1 IUser (org.pentaho.di.repository.IUser)1 Repository (org.pentaho.di.repository.Repository)1 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)1 RepositoryMeta (org.pentaho.di.repository.RepositoryMeta)1