Search in sources :

Example 21 with LastUsedFile

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

the class RepositoryBrowserController method getRecentFiles.

public List<RepositoryFile> getRecentFiles() {
    PropsUI props = PropsUI.getInstance();
    List<RepositoryFile> repositoryFiles = new ArrayList<>();
    IUser userInfo = Spoon.getInstance().rep.getUserInfo();
    String repoAndUser = Spoon.getInstance().rep.getName() + ":" + (userInfo != null ? userInfo.getLogin() : "");
    List<LastUsedFile> lastUsedFiles = props.getLastUsedRepoFiles().getOrDefault(repoAndUser, Collections.emptyList());
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -30);
    Date dateBefore = calendar.getTime();
    for (int i = 0; i < lastUsedFiles.size(); i++) {
        LastUsedFile lastUsedFile = lastUsedFiles.get(i);
        if (lastUsedFile.getLastOpened().before(dateBefore)) {
            continue;
        }
        if (lastUsedFile.getRepositoryName() != null && lastUsedFile.getRepositoryName().equals(Spoon.getInstance().rep.getName())) {
            RepositoryFile repositoryFile = new RepositoryFile();
            final String index = String.valueOf(i);
            repositoryFile.setObjectId(() -> index);
            repositoryFile.setType(lastUsedFile.isTransformation() ? TRANSFORMATION : JOB);
            repositoryFile.setName(lastUsedFile.getFilename());
            repositoryFile.setPath(lastUsedFile.getDirectory());
            repositoryFile.setDate(lastUsedFile.getLastOpened());
            repositoryFile.setRepository(lastUsedFile.getRepositoryName());
            repositoryFile.setUsername(lastUsedFile.getUsername());
            repositoryFiles.add(repositoryFile);
        }
    }
    return repositoryFiles;
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) IUser(org.pentaho.di.repository.IUser) RepositoryFile(org.pentaho.repo.model.RepositoryFile) LastUsedFile(org.pentaho.di.core.LastUsedFile) Date(java.util.Date) PropsUI(org.pentaho.di.ui.core.PropsUI)

Example 22 with LastUsedFile

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

the class Spoon method recentRepoFileExists.

/**
 * Returns true if the {@link LastUsedFile} at the given {@code index} within the {@link
 * PropsUI#getLastUsedRepoFiles()} collection exists within the given {@code repo} {@link Repository},
 * and false otherwise.
 *
 * @param repo     the {@link Repository} containing the file
 * @param indexStr the String index of the file within the last used repo file collection
 * @return true if the {@link LastUsedFile} at the given {@code index} within the {@link
 * PropsUI#getLastUsedRepoFiles()} collection exists within the given {@code repo} {@link Repository},
 * and false otherwise
 * @throws KettleException
 */
public boolean recentRepoFileExists(String repo, String indexStr) {
    final LastUsedFile lastUsedFile = getLastUsedRepoFile(repo, indexStr);
    // this should never happen when used on a repo file, but we check just to be safe
    if (lastUsedFile == null) {
        return false;
    }
    // again, should never happen, since the file being selected is a valid repo file in this repo
    if (!lastUsedFile.isSourceRepository() || !rep.getName().equalsIgnoreCase(lastUsedFile.getRepositoryName())) {
        return false;
    }
    try {
        final RepositoryDirectoryInterface rdi = rep.findDirectory(lastUsedFile.getDirectory());
        if (rdi == null) {
            return false;
        }
        final RepositoryObjectType fileType = lastUsedFile.isJob() ? RepositoryObjectType.JOB : RepositoryObjectType.TRANSFORMATION;
        return rep.exists(lastUsedFile.getFilename(), rdi, fileType);
    } catch (final KettleException ke) {
        // log
        return false;
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) LastUsedFile(org.pentaho.di.core.LastUsedFile)

Example 23 with LastUsedFile

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

the class Spoon method lastRepoFileSelect.

public void lastRepoFileSelect(String repo, String id) {
    int idx = Integer.parseInt(id);
    List<LastUsedFile> lastUsedFiles = props.getLastUsedRepoFiles().getOrDefault(repo, Collections.emptyList());
    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 24 with LastUsedFile

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

the class Spoon method getLastUsedRepoFile.

public LastUsedFile getLastUsedRepoFile(String repo, String indexStr) {
    // this should never happen when used on a repo file, but we check just to be safe
    if (rep == null) {
        return null;
    }
    final int idx = Integer.parseInt(indexStr);
    final List<LastUsedFile> lastUsedFiles = props.getLastUsedRepoFiles().getOrDefault(repo, Collections.emptyList());
    return 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 25 with LastUsedFile

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

the class Spoon method addMenuLast.

public void addMenuLast() {
    org.pentaho.ui.xul.dom.Document doc = mainSpoonContainer.getDocumentRoot();
    JfaceMenupopup recentFilesPopup = (JfaceMenupopup) doc.getElementById("file-open-recent-popup");
    recentFilesPopup.removeChildren();
    // Previously loaded files...
    List<LastUsedFile> lastUsedFiles = props.getLastUsedFiles();
    for (int i = 0; i < lastUsedFiles.size(); i++) {
        final LastUsedFile lastUsedFile = lastUsedFiles.get(i);
        char chr = (char) ('1' + i);
        String accessKey = "ctrl-" + chr;
        String accessText = "CTRL-" + chr;
        String text = lastUsedFile.toString();
        String id = "last-file-" + i;
        if (i > 8) {
            accessKey = null;
            accessText = null;
        }
        final String lastFileId = Integer.toString(i);
        Action action = new Action("open-last-file-" + (i + 1), Action.AS_DROP_DOWN_MENU) {

            @Override
            public void run() {
                lastFileSelect(lastFileId);
            }
        };
        // shorten the filename if necessary
        int targetLength = 40;
        if (text.length() > targetLength) {
            int lastSep = text.replace('\\', '/').lastIndexOf('/');
            if (lastSep != -1) {
                String fileName = "..." + text.substring(lastSep);
                if (fileName.length() < targetLength) {
                    // add the start of the file path
                    int leadSize = targetLength - fileName.length();
                    text = text.substring(0, leadSize) + fileName;
                } else {
                    text = fileName;
                }
            }
        }
        JfaceMenuitem miFileLast = new JfaceMenuitem(null, recentFilesPopup, mainSpoonContainer, text, 0, action);
        miFileLast.setLabel(text);
        miFileLast.setId(id);
        if (accessText != null && accessKey != null) {
            miFileLast.setAcceltext(accessText);
            miFileLast.setAccesskey(accessKey);
        }
        if (lastUsedFile.isTransformation()) {
            miFileLast.setImage(GUIResource.getInstance().getImageTransGraph());
        } else if (lastUsedFile.isJob()) {
            miFileLast.setImage(GUIResource.getInstance().getImageJobGraph());
        }
        miFileLast.setCommand("spoon.lastFileSelect('" + i + "')");
    }
}
Also used : TransAction(org.pentaho.di.core.undo.TransAction) Action(org.eclipse.jface.action.Action) JfaceMenuitem(org.pentaho.ui.xul.jface.tags.JfaceMenuitem) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) JfaceMenupopup(org.pentaho.ui.xul.jface.tags.JfaceMenupopup) LastUsedFile(org.pentaho.di.core.LastUsedFile) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

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