use of org.pentaho.di.ui.core.FileDialogOperation 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);
}
}
use of org.pentaho.di.ui.core.FileDialogOperation in project pentaho-kettle by pentaho.
the class Spoon method saveToRepository.
public boolean saveToRepository(EngineMetaInterface meta, boolean ask_name) throws KettleException {
if (log.isDetailed()) {
// "Save to repository..."
//
log.logDetailed(BaseMessages.getString(PKG, "Spoon.Log.SaveToRepository"));
}
if (rep != null) {
// If the repository directory is root then get the default save directory
if (meta.getRepositoryDirectory() == null || meta.getRepositoryDirectory().isRoot()) {
meta.setRepositoryDirectory(rep.getDefaultSaveDirectory(meta));
}
if (ask_name) {
try {
String fileType = meta.getFileType().equals(LastUsedFile.FILE_TYPE_TRANSFORMATION) ? FileDialogOperation.TRANSFORMATION : FileDialogOperation.JOB;
FileDialogOperation fileDialogOperation = new FileDialogOperation(FileDialogOperation.SAVE, FileDialogOperation.ORIGIN_SPOON);
fileDialogOperation.setFileType(fileType);
fileDialogOperation.setStartDir(meta.getRepositoryDirectory().getPath());
// Set the filename so it can be used as the default filename in the save dialog
fileDialogOperation.setFilename(meta.getFilename());
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonOpenSaveRepository.id, fileDialogOperation);
if (fileDialogOperation.getRepositoryObject() != null) {
RepositoryObject repositoryObject = (RepositoryObject) fileDialogOperation.getRepositoryObject();
meta.setRepositoryDirectory(repositoryObject.getRepositoryDirectory());
meta.setName(repositoryObject.getName());
delegates.tabs.renameTabs();
return saveToRepositoryConfirmed(meta);
}
} catch (KettleException ke) {
// Ignore
}
} else {
return saveToRepositoryConfirmed(meta);
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
// "There is no repository connection available."
mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.NoRepositoryConnection.Message"));
// "No repository available."
mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.NoRepositoryConnection.Title"));
mb.open();
}
return false;
}
use of org.pentaho.di.ui.core.FileDialogOperation in project pentaho-kettle by pentaho.
the class JobEntryExportRepositoryDialog method displaydirectoryList.
private void displaydirectoryList() {
RepositoriesMeta repositoriesMeta = null;
RepositoryMeta repositoryMeta = null;
Repository repos = null;
try {
repositoriesMeta = new RepositoriesMeta();
repositoriesMeta.readData();
repositoryMeta = repositoriesMeta.findRepository(jobMeta.environmentSubstitute(wRepositoryname.getText()));
if (repositoryMeta == null) {
// Can not find repository
displayMsg(BaseMessages.getString(PKG, "JobExportRepository.Error.CanNotFindRep"), BaseMessages.getString(PKG, "JobExportRepository.Error.CanNotFindRepMsg", wRepositoryname.getText()), true);
}
repos = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
repos.init(repositoryMeta);
try {
repos.connect(jobMeta.environmentSubstitute(wUserName.getText()), jobMeta.environmentSubstitute(wPassword.getText()));
} catch (Exception e) {
displayMsg(BaseMessages.getString(PKG, "JobExportRepository.Error.CanNotConnect"), BaseMessages.getString(PKG, "JobExportRepository.Error.CanNotConnectMsg", wRepositoryname.getText()), true);
}
if (repos.isConnected()) {
try {
FileDialogOperation fileDialogOperation = new FileDialogOperation(FileDialogOperation.SELECT_FOLDER, FileDialogOperation.ORIGIN_SPOON);
fileDialogOperation.setTitle(BaseMessages.getString(PKG, "JobExportRepository.SelectDirectoryDialog.Title"));
fileDialogOperation.setFilter(null);
fileDialogOperation.setRepository(repos);
if (!Utils.isEmpty(wFoldername.getText())) {
fileDialogOperation.setStartDir(wFoldername.getText());
}
ExtensionPointHandler.callExtensionPoint(null, KettleExtensionPoint.SpoonOpenSaveRepository.id, fileDialogOperation);
if (fileDialogOperation.getRepositoryObject() != null) {
String path = ((RepositoryObject) fileDialogOperation.getRepositoryObject()).getRepositoryDirectory().getPath();
wFoldername.setText(path);
}
} catch (KettleException e) {
// Do Nothing
}
}
} catch (Exception e) {
displayMsg(BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "JobExportRepository.ErrorGettingFolderds.DialogMessage") + Const.CR + ":" + e.getMessage(), true);
} finally {
if (repos != null) {
repos.disconnect();
repos = null;
}
if (repositoryMeta != null) {
repositoryMeta = null;
}
repositoriesMeta.clear();
}
}
use of org.pentaho.di.ui.core.FileDialogOperation in project pentaho-kettle by pentaho.
the class DialogHelper method selectRepositoryObject.
public static RepositoryObject selectRepositoryObject(String filter, LogChannel log) {
try {
FileDialogOperation fileDialogOperation = new FileDialogOperation(FileDialogOperation.OPEN, FileDialogOperation.ORIGIN_OTHER);
if (!Utils.isEmpty(filter)) {
fileDialogOperation.setFilter(filter);
}
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonOpenSaveRepository.id, fileDialogOperation);
return (RepositoryObject) fileDialogOperation.getRepositoryObject();
} catch (KettleException ke) {
// Ignore
}
return null;
}
use of org.pentaho.di.ui.core.FileDialogOperation in project pentaho-kettle by pentaho.
the class Spoon method openFile.
public void openFile(boolean importfile) {
try {
SpoonPerspective activePerspective = SpoonPerspectiveManager.getInstance().getActivePerspective();
//
if (!importfile) {
if (activePerspective instanceof SpoonPerspectiveOpenSaveInterface) {
((SpoonPerspectiveOpenSaveInterface) activePerspective).open();
return;
}
}
String activePerspectiveId = activePerspective.getId();
boolean etlPerspective = activePerspectiveId.equals(MainSpoonPerspective.ID);
if (rep == null || importfile || !etlPerspective) {
// Load from XML
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
LinkedHashSet<String> extensions = new LinkedHashSet<>();
LinkedHashSet<String> extensionNames = new LinkedHashSet<>();
StringBuilder allExtensions = new StringBuilder();
for (FileListener l : fileListeners) {
for (String ext : l.getSupportedExtensions()) {
extensions.add("*." + ext);
allExtensions.append("*.").append(ext).append(";");
}
Collections.addAll(extensionNames, l.getFileTypeDisplayNames(Locale.getDefault()));
}
extensions.add("*");
extensionNames.add(BaseMessages.getString(PKG, "Spoon.Dialog.OpenFile.AllFiles"));
String[] exts = new String[extensions.size() + 1];
exts[0] = allExtensions.toString();
System.arraycopy(extensions.toArray(new String[extensions.size()]), 0, exts, 1, extensions.size());
String[] extNames = new String[extensionNames.size() + 1];
extNames[0] = BaseMessages.getString(PKG, "Spoon.Dialog.OpenFile.AllTypes");
System.arraycopy(extensionNames.toArray(new String[extensionNames.size()]), 0, extNames, 1, extensionNames.size());
dialog.setFilterExtensions(exts);
setFilterPath(dialog);
String filename = dialog.open();
if (filename != null) {
if (importfile) {
if (activePerspective instanceof SpoonPerspectiveOpenSaveInterface) {
((SpoonPerspectiveOpenSaveInterface) activePerspective).importFile(filename);
return;
}
}
lastDirOpened = dialog.getFilterPath();
openFile(filename, importfile);
}
} else {
try {
FileDialogOperation fileDialogOperation = new FileDialogOperation(FileDialogOperation.OPEN, FileDialogOperation.ORIGIN_SPOON);
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonOpenSaveRepository.id, fileDialogOperation);
if (fileDialogOperation.getRepositoryObject() != null) {
RepositoryObject repositoryObject = (RepositoryObject) fileDialogOperation.getRepositoryObject();
loadObjectFromRepository(repositoryObject.getObjectId(), repositoryObject.getObjectType(), null);
}
} catch (Exception e) {
// Ignore
}
}
} catch (KettleRepositoryLostException krle) {
new ErrorDialog(getShell(), BaseMessages.getString(PKG, "Spoon.Error"), krle.getPrefaceMessage(), krle);
this.closeRepository();
}
}
Aggregations