use of org.pentaho.di.repository.RepositoryExtended in project pentaho-kettle by pentaho.
the class BrowseController method init.
// end PDI-3326 hack
@SuppressWarnings("deprecation")
public void init(Repository repository) throws ControllerInitializationException {
try {
this.repository = repository;
mainController = (MainController) this.getXulDomContainer().getEventHandler("mainController");
RepositoryDirectoryInterface root;
try {
if (repository instanceof RepositoryExtended) {
root = ((RepositoryExtended) repository).loadRepositoryDirectoryTree("/", "*.ktr|*.kjb", -1, BooleanUtils.isTrue(repository.getUserInfo().isAdmin()), true, true);
} else {
root = repository.loadRepositoryDirectoryTree();
}
this.repositoryDirectory = UIObjectRegistry.getInstance().constructUIRepositoryDirectory(root, null, repository);
} catch (UIObjectCreationException uoe) {
this.repositoryDirectory = new UIRepositoryDirectory(repository.loadRepositoryDirectoryTree(), null, repository);
}
dirMap = new HashMap<ObjectId, UIRepositoryDirectory>();
populateDirMap(repositoryDirectory);
bf = new SwtBindingFactory();
bf.setDocument(this.getXulDomContainer().getDocumentRoot());
messageBox = (XulMessageBox) document.createElement("messagebox");
createBindings();
} catch (Exception e) {
throw new ControllerInitializationException(e);
}
}
use of org.pentaho.di.repository.RepositoryExtended in project pentaho-kettle by pentaho.
the class SelectDirectoryDialog method open.
@SuppressWarnings("deprecation")
public RepositoryDirectoryInterface open() {
dircolor = GUIResource.getInstance().getColorDirectory();
Shell parent = getParent();
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
props.setLook(shell);
shell.setImage(GUIResource.getInstance().getImageSpoon());
shell.setText(BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.Main.Title"));
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
// Tree
wTree = new Tree(shell, SWT.SINGLE | SWT.BORDER);
props.setLook(wTree);
try {
if (rep instanceof RepositoryExtended) {
RepositoryExtended repositoryExtended = (RepositoryExtended) this.rep;
repositoryTree = repositoryExtended.loadRepositoryDirectoryTree("/", null, -1, BooleanUtils.isTrue(repositoryExtended.getUserInfo().isAdmin()), true, false);
} else {
repositoryTree = this.rep.loadRepositoryDirectoryTree();
}
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.ErrorRefreshingDirectoryTree.Title"), BaseMessages.getString(PKG, "SelectDirectoryDialog.Dialog.ErrorRefreshingDirectoryTree.Message"), e);
return null;
}
if (!getData()) {
return null;
}
// Buttons
wOK = new Button(shell, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
wRefresh = new Button(shell, SWT.PUSH);
wRefresh.setText(BaseMessages.getString(PKG, "System.Button.Refresh"));
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
FormData fdTree = new FormData();
FormData fdOK = new FormData();
FormData fdRefresh = new FormData();
FormData fdCancel = new FormData();
int margin = 10;
// To the right of the label
fdTree.left = new FormAttachment(0, 0);
fdTree.top = new FormAttachment(0, 0);
fdTree.right = new FormAttachment(100, 0);
fdTree.bottom = new FormAttachment(100, -50);
wTree.setLayoutData(fdTree);
fdOK.left = new FormAttachment(wTree, 0, SWT.CENTER);
fdOK.bottom = new FormAttachment(100, -margin);
wOK.setLayoutData(fdOK);
fdRefresh.left = new FormAttachment(wOK, 10);
fdRefresh.bottom = new FormAttachment(100, -margin);
wRefresh.setLayoutData(fdRefresh);
fdCancel.left = new FormAttachment(wRefresh, 10);
fdCancel.bottom = new FormAttachment(100, -margin);
wCancel.setLayoutData(fdCancel);
// Add listeners
wCancel.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
dispose();
}
});
// Add listeners
wOK.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
handleOK();
}
});
wTree.addSelectionListener(new SelectionAdapter() {
private String getSelectedPath(SelectionEvent selectionEvent) {
TreeItem treeItem = (TreeItem) selectionEvent.item;
String path;
if (treeItem.getParentItem() == null) {
path = treeItem.getText();
} else {
path = ConstUI.getTreePath(treeItem, 0);
}
return path;
}
private boolean isSelectedPathRestricted(SelectionEvent selectionEvent) {
String path = getSelectedPath(selectionEvent);
boolean isRestricted = isRestrictedPath(path);
return isRestricted;
}
public void widgetDefaultSelected(SelectionEvent selectionEvent) {
if (isSelectedPathRestricted(selectionEvent)) {
return;
}
handleOK();
}
public void widgetSelected(SelectionEvent selectionEvent) {
boolean restricted = isSelectedPathRestricted(selectionEvent);
wOK.setEnabled(!restricted);
}
});
wRefresh.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
getData();
}
});
wTree.addMenuDetectListener(new MenuDetectListener() {
public void menuDetected(MenuDetectEvent e) {
setTreeMenu();
}
});
BaseStepDialog.setSize(shell);
shell.open();
Display display = parent.getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return selection;
}
use of org.pentaho.di.repository.RepositoryExtended in project pentaho-kettle by pentaho.
the class SelectObjectDialog method open.
@SuppressWarnings("deprecation")
public String open() {
Shell parent = getParent();
dircolor = GUIResource.getInstance().getColorDirectory();
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.SHEET | SWT.RESIZE | SWT.MIN | SWT.MAX);
props.setLook(shell);
shell.setImage(GUIResource.getInstance().getImageSpoon());
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
shell.setText(shellText);
int margin = Const.MARGIN;
ToolBar treeTb = new ToolBar(shell, SWT.HORIZONTAL | SWT.FLAT);
props.setLook(treeTb);
wfilter = new ToolItem(treeTb, SWT.SEPARATOR);
searchText = new Text(treeTb, SWT.SEARCH | SWT.CANCEL);
searchText.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Search.FilterString.ToolTip"));
wfilter.setControl(searchText);
wfilter.setWidth(100);
wbRegex = new ToolItem(treeTb, SWT.CHECK);
wbRegex.setImage(GUIResource.getInstance().getImageRegexSmall());
wbRegex.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Search.UseRegex"));
goSearch = new ToolItem(treeTb, SWT.PUSH);
goSearch.setImage(GUIResource.getInstance().getImageSearchSmall());
goSearch.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Search.Run"));
expandAll = new ToolItem(treeTb, SWT.PUSH);
expandAll.setImage(GUIResource.getInstance().getImageExpandAll());
collapseAll = new ToolItem(treeTb, SWT.PUSH);
collapseAll.setImage(GUIResource.getInstance().getImageCollapseAll());
fdexpandAll = new FormData();
fdexpandAll.right = new FormAttachment(100, -margin);
fdexpandAll.top = new FormAttachment(0, margin);
treeTb.setLayoutData(fdexpandAll);
// From step line
wlTree = new Label(shell, SWT.NONE);
wlTree.setText(lineText);
props.setLook(wlTree);
fdlTree = new FormData();
fdlTree.left = new FormAttachment(0, 0);
fdlTree.top = new FormAttachment(0, margin);
wlTree.setLayoutData(fdlTree);
wTree = new Tree(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
wTree.setHeaderVisible(true);
props.setLook(wTree);
// Add some columns to it as well...
nameColumn = new TreeColumn(wTree, SWT.LEFT);
nameColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Name"));
nameColumn.setWidth(350);
nameColumn.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
setSort(0);
}
});
// No sorting on the type column just yet.
typeColumn = new TreeColumn(wTree, SWT.LEFT);
typeColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Type"));
typeColumn.setWidth(100);
typeColumn.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
setSort(1);
}
});
userColumn = new TreeColumn(wTree, SWT.LEFT);
userColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.User"));
userColumn.setWidth(100);
userColumn.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
setSort(2);
}
});
changedColumn = new TreeColumn(wTree, SWT.LEFT);
changedColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Changed"));
changedColumn.setWidth(120);
changedColumn.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
setSort(3);
}
});
descriptionColumn = new TreeColumn(wTree, SWT.LEFT);
descriptionColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Description"));
descriptionColumn.setWidth(120);
descriptionColumn.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
setSort(4);
}
});
props.setLook(wTree);
fdTree = new FormData();
fdTree.left = new FormAttachment(0, 0);
fdTree.right = new FormAttachment(100, 0);
fdTree.top = new FormAttachment(treeTb, margin);
fdTree.bottom = new FormAttachment(100, -30);
wTree.setLayoutData(fdTree);
// Some buttons
wOK = new Button(shell, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
lsOK = new Listener() {
public void handleEvent(Event e) {
ok();
}
};
wOK.addListener(SWT.Selection, lsOK);
wOK.setEnabled(false);
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
lsCancel = new Listener() {
public void handleEvent(Event e) {
cancel();
}
};
wCancel.addListener(SWT.Selection, lsCancel);
BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK, wCancel }, margin, null);
// Add listeners
lsDef = new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
ok();
}
};
wTree.addSelectionListener(lsDef);
wTree.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.character == SWT.CR) {
ok();
}
}
});
wTree.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (wTree.getSelection().length > 0) {
wOK.setEnabled(!Boolean.TRUE.equals(wTree.getSelection()[0].getData("isFolder")));
}
}
});
expandAll.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
expandAllItems(wTree.getItems(), true);
}
});
collapseAll.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
expandAllItems(wTree.getItems(), false);
}
});
goSearch.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
updateFilter();
}
});
searchText.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
updateFilter();
}
});
// Detect [X] or ALT-F4 or something that kills this window...
shell.addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
cancel();
}
});
try {
if (rep instanceof RepositoryExtended) {
RepositoryExtended repositoryExtended = (RepositoryExtended) this.rep;
directoryTree = repositoryExtended.loadRepositoryDirectoryTree("/", "*.kjb|*.ktr", -1, BooleanUtils.isTrue(repositoryExtended.getUserInfo().isAdmin()), true, false);
} else {
directoryTree = this.rep.loadRepositoryDirectoryTree();
}
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SelectObjectDialog.Dialog.ErrorRefreshingDirectoryTree.Title"), BaseMessages.getString(PKG, "SelectObjectDialog.Dialog.ErrorRefreshingDirectoryTree.Message"), e);
}
// catch()
getData();
wTree.setFocus();
BaseStepDialog.setSize(shell);
shell.open();
while (!shell.isDisposed()) {
if (!shell.getDisplay().readAndDispatch()) {
shell.getDisplay().sleep();
}
}
return objectName;
}
use of org.pentaho.di.repository.RepositoryExtended in project pentaho-kettle by pentaho.
the class RepositoryBrowserController method rename.
public ObjectId rename(String id, String path, String newName, String type, String oldName) throws KettleException {
RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(path);
ObjectId objectId = null;
switch(type) {
case JOB:
if (getRepository().exists(newName, repositoryDirectoryInterface, RepositoryObjectType.JOB)) {
throw new KettleObjectExistsException();
}
if (isJobOpened(id, path, oldName)) {
throw new KettleJobException();
}
renameRecent(id, type, newName);
objectId = getRepository().renameJob(() -> id, repositoryDirectoryInterface, newName);
break;
case TRANSFORMATION:
if (getRepository().exists(newName, repositoryDirectoryInterface, RepositoryObjectType.TRANSFORMATION)) {
throw new KettleObjectExistsException();
}
if (isTransOpened(id, path, oldName)) {
throw new KettleTransException();
}
renameRecent(id, type, newName);
objectId = getRepository().renameTransformation(() -> id, repositoryDirectoryInterface, newName);
break;
case FOLDER:
isFileOpenedInFolder(path);
RepositoryDirectoryInterface parent = findDirectory(path).getParent();
if (parent == null) {
parent = findDirectory(path);
}
RepositoryDirectoryInterface child = parent.findChild(newName);
if (child != null) {
throw new KettleObjectExistsException();
}
if (getRepository() instanceof RepositoryExtended) {
objectId = ((RepositoryExtended) getRepository()).renameRepositoryDirectory(() -> id, null, newName, true);
} else {
objectId = getRepository().renameRepositoryDirectory(() -> id, null, newName);
}
break;
}
return objectId;
}
use of org.pentaho.di.repository.RepositoryExtended in project pentaho-kettle by pentaho.
the class RepositoryBrowserController method remove.
public boolean remove(String id, String name, String path, String type) throws KettleException {
try {
switch(type) {
case JOB:
if (isJobOpened(id, path, name)) {
throw new KettleJobException();
}
getRepository().deleteJob(() -> id);
break;
case TRANSFORMATION:
if (isTransOpened(id, path, name)) {
throw new KettleTransException();
}
getRepository().deleteTransformation(() -> id);
break;
case FOLDER:
isFileOpenedInFolder(path);
removeRecentsUsingPath(path);
RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(path);
if (getRepository() instanceof RepositoryExtended) {
((RepositoryExtended) getRepository()).deleteRepositoryDirectory(repositoryDirectoryInterface, true);
} else {
getRepository().deleteRepositoryDirectory(repositoryDirectoryInterface);
}
break;
}
return true;
} catch (KettleTransException | KettleJobException ke) {
throw ke;
} catch (Exception e) {
return false;
}
}
Aggregations