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;
}
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;
}
}
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));
}
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);
}
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 + "')");
}
}
Aggregations