Search in sources :

Example 26 with LastUsedFile

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

the class RecentUtilsTest method setPathsUnixTest.

@Test
public void setPathsUnixTest() {
    LastUsedFile lastUsedFile = new LastUsedFile(LastUsedFile.FILE_TYPE_TRANSFORMATION, UNIX_PATH, null, false, null, null, false, 1, new Date(), null);
    RecentFile recentFile = new RecentFile();
    RecentUtils.setPaths(lastUsedFile, recentFile);
    Assert.assertEquals(UNIX_FILENAME, recentFile.getName());
    Assert.assertEquals(UNIX_PARENT, recentFile.getParent());
    Assert.assertEquals(UNIX_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 27 with LastUsedFile

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

the class RecentUtilsTest method setPathsWindowsTest.

@Test
public void setPathsWindowsTest() {
    LastUsedFile lastUsedFile = new LastUsedFile(LastUsedFile.FILE_TYPE_TRANSFORMATION, WINDOWS_PATH, null, false, null, null, false, 1, new Date(), null);
    RecentFile recentFile = new RecentFile();
    RecentUtils.setPaths(lastUsedFile, recentFile);
    Assert.assertEquals(WINDOWS_FILENAME, recentFile.getName());
    Assert.assertEquals(WINDOWS_PARENT, recentFile.getParent());
    Assert.assertEquals(WINDOWS_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 28 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_PUSH_BUTTON) {

            @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)

Example 29 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 30 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)

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