use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.
the class SelectDirectoryDialog method setTreeMenu.
public void setTreeMenu() {
Menu mTree = null;
// use SWT.SINGLE in wTree!!!!
TreeItem[] ti = wTree.getSelection();
if (ti.length == 1) {
mTree = new Menu(wTree);
/*
* NEW Sub-directory
*/
MenuItem miNew = new MenuItem(mTree, SWT.CASCADE);
miNew.setText(BaseMessages.getString(PKG, "SelectDirectoryDialog.PopupMenu.Directory.New"));
miNew.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (!readOnly) {
TreeItem ti = wTree.getSelection()[0];
String[] str = ConstUI.getTreeStrings(ti);
//
// In which directory do we want create a subdirectory?
//
RepositoryDirectoryInterface dir = repositoryTree.findDirectory(str);
if (dir != null) {
//
// What's the name of the new directory?
//
EnterStringDialog etd = new EnterStringDialog(shell, BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.EnterDirectoryName.Title"), BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.EnterDirectoryName.Message"), BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.EnterDirectoryName.Default"));
String newdir = etd.open();
if (newdir != null) {
RepositoryDirectory subdir = new RepositoryDirectory(dir, newdir);
try {
rep.saveRepositoryDirectory(subdir);
dir.addSubdirectory(subdir);
TreeItem tiNew = new TreeItem(ti, SWT.NONE);
tiNew.setText(newdir);
tiNew.setImage(GUIResource.getInstance().getImageFolder());
wTree.setSelection(new TreeItem[] { tiNew });
} catch (Exception exception) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.UnableToCreateDirectory.Message"), BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.UnableToCreateDirectory.Title"), exception);
}
}
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.UnableToLocateDirectory.Message"));
mb.setText(BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.UnableToLocateDirectory.Title"));
mb.open();
}
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.PermissionDenied.Message1") + (rep.getUserInfo() == null ? "" : rep.getUserInfo().getLogin()) + BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.PermissionDenied.Message2"));
mb.setText(BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.PermissionDenied.Title"));
mb.open();
}
}
});
/*
* RENAME directory
*/
MenuItem miRen = new MenuItem(mTree, SWT.CASCADE);
miRen.setText(BaseMessages.getString(PKG, "SelectDirectoryDialog.PopupMenu.Directory.Rename"));
miRen.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (!readOnly) {
TreeItem ti = wTree.getSelection()[0];
String[] str = ConstUI.getTreeStrings(ti);
RepositoryDirectoryInterface dir = repositoryTree.findDirectory(str);
if (dir != null) {
//
// What's the new name of the directory?
//
String oldName = dir.getName();
EnterStringDialog etd = new EnterStringDialog(shell, oldName, BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.EnterDirectoryNewName.Message"), BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.EnterDirectoryNewName.Title"));
String newName = etd.open();
if (newName != null && !newName.equals(oldName)) {
dir.setName(newName);
try {
rep.renameRepositoryDirectory(dir.getObjectId(), dir.getParent(), newName);
ti.setText(newName);
wTree.setSelection(ti);
} catch (Exception exception) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Rename.UnexpectedError.Message1") + oldName + "]" + Const.CR + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Rename.UnexpectedError.Message2"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Rename.UnexpectedError.Title"), exception);
}
}
}
}
}
});
MenuItem miDel = new MenuItem(mTree, SWT.CASCADE);
miDel.setText(BaseMessages.getString(PKG, "SelectDirectoryDialog.PopupMenu.Directory.Delete"));
miDel.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (!readOnly) {
TreeItem ti = wTree.getSelection()[0];
String[] str = ConstUI.getTreeStrings(ti);
RepositoryDirectoryInterface dir = repositoryTree.findDirectory(str);
if (dir != null) {
try {
rep.deleteRepositoryDirectory(dir);
ti.dispose();
} catch (KettleException exception) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Delete.ErrorRemoving.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Directory.Delete.ErrorRemoving.Message1"), exception);
}
}
}
}
});
}
wTree.setMenu(mTree);
}
use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.
the class SelectObjectDialog method refreshTree.
private void refreshTree() {
try {
wTree.removeAll();
TreeItem ti = null;
// display that on the UI otherwise we will hide it
if (directoryTree.isRoot() && directoryTree.isVisible()) {
ti = new TreeItem(wTree, SWT.NONE);
ti.setImage(GUIResource.getInstance().getImageFolder());
ti.setExpanded(true);
RepositoryDirectoryUI.getTreeWithNames(ti, rep, dircolor, sortColumn, includeDeleted, ascending, showTrans, showJobs, directoryTree, filterString, pattern);
} else {
for (int i = 0; i < directoryTree.getNrSubdirectories(); i++) {
RepositoryDirectory subdir = directoryTree.getSubdirectory(i);
ti = new TreeItem(wTree, SWT.NONE);
ti.setImage(GUIResource.getInstance().getImageFolder());
RepositoryDirectoryUI.getTreeWithNames(ti, rep, dircolor, sortColumn, includeDeleted, ascending, showTrans, showJobs, subdir, filterString, pattern);
}
}
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SelectObjectDialog.Dialog.UnexpectedError.Title"), BaseMessages.getString(PKG, "SelectObjectDialog.Dialog.UnexpectedError.Message"), e);
}
}
Aggregations