use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory in project pentaho-kettle by pentaho.
the class RepositoryLockController method repositoryDirectoryHasLockedObject.
private boolean repositoryDirectoryHasLockedObject(DropEvent event, UIRepositoryDirectory dir) throws KettleException {
if (areAnyRepositoryObjectsLocked(event, dir.getRepositoryObjects())) {
return true;
}
for (UIRepositoryObject ro : dir.getChildren()) {
if (ro instanceof UIRepositoryDirectory) {
UIRepositoryDirectory directory = (UIRepositoryDirectory) ro;
repositoryDirectoryHasLockedObject(event, directory);
}
}
return false;
}
use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory in project pentaho-kettle by pentaho.
the class RevisionController method createBindings.
private void createBindings() {
// $NON-NLS-1$
filePropertiesTabbox = (XulTabbox) document.getElementById("file-properties-tabs");
// $NON-NLS-1$
historyTab = (XulTab) document.getElementById("history");
// $NON-NLS-1$
revisionTable = (XulTree) document.getElementById("revision-table");
// $NON-NLS-1$
folderTree = (XulTree) document.getElementById("folder-tree");
// $NON-NLS-1$
fileTable = (XulTree) document.getElementById("file-table");
// Hide the history tab if versioning is off
historyTab.setVisible(false);
bf.setBindingType(Binding.Type.ONE_WAY);
BindingConvertor<int[], Boolean> forButtons = new BindingConvertor<int[], Boolean>() {
@Override
public Boolean sourceToTarget(int[] value) {
return value != null && !(value.length <= 0);
}
@Override
public int[] targetToSource(Boolean value) {
return null;
}
};
Binding openButtonBinding = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
bf.createBinding(revisionTable, "selectedRows", OPEN_REVISION_BUTTON, "!disabled", forButtons);
Binding restoreButtonBinding = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
bf.createBinding(revisionTable, "selectedRows", RESTORE_REVISION_BUTTON, "!disabled", forButtons);
bf.setBindingType(Binding.Type.ONE_WAY);
// $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(folderTree, "selectedItems", this, "historyTabVisibility");
// $NON-NLS-1$ //$NON-NLS-2$
revisionBinding = bf.createBinding(this, "revisionObjects", revisionTable, "elements");
revisionBinding = // $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
browseController, // $NON-NLS-1$ //$NON-NLS-2$
"repositoryItems", // $NON-NLS-1$ //$NON-NLS-2$
this, // $NON-NLS-1$ //$NON-NLS-2$
"revisionObjects", new BindingConvertor<List<UIRepositoryObject>, UIRepositoryObjectRevisions>() {
private void disableButtons() {
document.getElementById(OPEN_REVISION_BUTTON).setDisabled(true);
document.getElementById(RESTORE_REVISION_BUTTON).setDisabled(true);
}
@Override
public UIRepositoryObjectRevisions sourceToTarget(List<UIRepositoryObject> ro) {
if (ro == null || ro.isEmpty() || !masterVersioningEnabled) {
return new UIRepositoryObjectRevisions();
}
if (ro.get(0) instanceof UIRepositoryDirectory) {
historyTab.setVisible(false);
filePropertiesTabbox.setSelectedIndex(0);
disableButtons();
return null;
}
UIRepositoryObjectRevisions revisions = null;
try {
UIRepositoryContent rc = (UIRepositoryContent) ro.get(0);
if (rc instanceof IRevisionObject) {
Boolean versioningEnabled = ((IRevisionObject) rc).getVersioningEnabled();
// Show/hide the Verison History tab
historyTab.setVisible(versioningEnabled);
if (!versioningEnabled) {
return new UIRepositoryObjectRevisions();
}
Boolean versionCommentEnabled = ((IRevisionObject) rc).getVersionCommentEnabled();
// Show/Hide the version comment column
setRevisionTableColumns(versionCommentEnabled);
revisions = ((IRevisionObject) rc).getRevisions();
} else {
throw new IllegalStateException(BaseMessages.getString(PKG, // $NON-NLS-1$
"RevisionsController.RevisionsNotSupported"));
}
} catch (KettleException e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
// convert to runtime exception so it bubbles up through the UI
throw new RuntimeException(e);
}
}
return revisions;
}
@Override
public List<UIRepositoryObject> targetToSource(UIRepositoryObjectRevisions elements) {
return null;
}
});
try {
openButtonBinding.fireSourceChanged();
restoreButtonBinding.fireSourceChanged();
revisionBinding.fireSourceChanged();
} catch (Exception e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
// convert to runtime exception so it bubbles up through the UI
throw new RuntimeException(e);
}
}
}
use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory in project pentaho-kettle by pentaho.
the class BrowseController method onDrop.
public void onDrop(DropEvent event) {
boolean result = false;
try {
List<Object> dirList = new ArrayList<Object>();
List<UIRepositoryObject> moveList = new ArrayList<UIRepositoryObject>();
UIRepositoryDirectory targetDirectory = null;
if (event.getDropParent() != null && event.getDropParent() instanceof UIRepositoryDirectory) {
targetDirectory = (UIRepositoryDirectory) event.getDropParent();
if (event.getDataTransfer().getData().size() > 0) {
for (Object o : event.getDataTransfer().getData()) {
if (o instanceof UIRepositoryObject) {
moveList.add((UIRepositoryObject) o);
// Make sure only Folders are copied to the Directory Tree
if (o instanceof UIRepositoryDirectory) {
dirList.add(o);
}
result = true;
}
}
}
}
if (result == true) {
List<UIRepositoryObject> collisionObjects = new ArrayList<UIRepositoryObject>();
// Check for overwriting
for (UIRepositoryObject newChild : moveList) {
for (UIRepositoryObject currChild : targetDirectory.getRepositoryObjects()) {
if ((currChild instanceof UIRepositoryDirectory) && (newChild instanceof UIRepositoryDirectory) && (currChild.getName().equalsIgnoreCase(newChild.getName()))) {
messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
messageBox.setMessage(BaseMessages.getString(PKG, "BrowseController.UnableToMove.DirectoryAlreadyExists", currChild.getPath()));
messageBox.open();
result = false;
break;
} else if (!(currChild instanceof UIRepositoryDirectory) && (currChild.getType().equalsIgnoreCase(newChild.getType())) && (currChild.getName().equalsIgnoreCase(newChild.getName()))) {
collisionObjects.add(currChild);
}
}
if (!result) {
break;
}
}
// Prompt to overwrite
if (result && collisionObjects.size() > 0) {
FileOverwriteDialogController fileOverwriteDialog = FileOverwriteDialogController.getInstance(getXulDomContainer().getOuterContext() instanceof Shell ? (Shell) getXulDomContainer().getOuterContext() : null, collisionObjects);
fileOverwriteDialog.show();
if (fileOverwriteDialog.isOverwriteFiles()) {
// Delete the files before moving
for (UIRepositoryObject o : collisionObjects) {
o.delete();
}
} else {
// We are not moving the files
result = false;
}
}
// Make sure we are still moving the files
if (result) {
moveFiles(moveList, targetDirectory);
// Set UI objects to appear in folder directory
event.getDataTransfer().setData(dirList);
}
}
} catch (Exception e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
result = false;
event.setAccepted(false);
messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
messageBox.setMessage(BaseMessages.getString(PKG, "BrowseController.UnableToMove", e.getLocalizedMessage()));
messageBox.open();
}
}
event.setAccepted(result);
}
use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory in project pentaho-kettle by pentaho.
the class BrowseController method renameContent.
public void renameContent() throws Exception {
try {
Collection<UIRepositoryContent> content = fileTable.getSelectedItems();
UIRepositoryObject contentToRename = content.iterator().next();
renameRepositoryObject(contentToRename);
if (contentToRename instanceof UIRepositoryDirectory) {
directoryBinding.fireSourceChanged();
}
selectedItemsBinding.fireSourceChanged();
} catch (Throwable th) {
if (mainController == null || !mainController.handleLostRepository(th)) {
messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
messageBox.setMessage(BaseMessages.getString(PKG, th.getLocalizedMessage()));
messageBox.open();
}
}
}
use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory in project pentaho-kettle by pentaho.
the class BrowseController method createBindings.
protected void createBindings() {
shell = ((SwtDialog) document.getElementById("repository-explorer-dialog")).getShell();
folderTree = (XulTree) document.getElementById("folder-tree");
fileTable = (XulTree) document.getElementById("file-table");
if (!repositoryDirectory.isVisible()) {
folderTree.setHiddenrootnode(true);
} else {
folderTree.setHiddenrootnode(false);
}
BindingConvertor<List<?>, Boolean> checkIfMultipleItemsAreSelected = new BindingConvertor<List<?>, Boolean>() {
@Override
public Boolean sourceToTarget(List<?> value) {
return value != null && value.size() == 1 && value.get(0) != null;
}
@Override
public List<?> targetToSource(Boolean value) {
return null;
}
};
bf.setBindingType(Binding.Type.ONE_WAY);
bf.createBinding(fileTable, "selectedItems", "file-context-rename", "!disabled", checkIfMultipleItemsAreSelected);
bf.createBinding(fileTable, "selectedItems", this, "selectedFileItems");
// begin PDI-3326 hack
PropertyChangeListener childrenListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
fireRepositoryDirectoryChange();
}
};
repositoryDirectory.addPropertyChangeListener("children", childrenListener);
// end PDI-3326 hack
directoryBinding = createDirectoryBinding();
// Bind the selected index from the folder tree to the list of repository objects in the file table.
bf.setBindingType(Binding.Type.ONE_WAY);
bf.createBinding(folderTree, "selectedItems", this, "selectedFolderItems");
bf.setBindingType(Binding.Type.ONE_WAY);
selectedItemsBinding = bf.createBinding(this, "selectedRepoDirChildren", fileTable, "elements");
// bindings can be added here in subclasses
doCreateBindings();
try {
// Fires the population of the repository tree of folders.
directoryBinding.fireSourceChanged();
} catch (Exception e) {
// convert to runtime exception so it bubbles up through the UI
throw new RuntimeException(e);
}
try {
// Set the initial selected directory as the users home directory
RepositoryDirectoryInterface homeDir = repository.getUserHomeDirectory();
int currentDir = 0;
String[] homePath = homeDir == null ? null : homeDir.getPathArray();
if (homePath != null) {
UIRepositoryDirectory tempRoot = repositoryDirectory;
// Check to see if the first item in homePath is the root directory
if (homePath.length > 0 && tempRoot.getName().equalsIgnoreCase(homePath[currentDir])) {
if (homePath.length == 1) {
// The home directory is home root
setSelectedFolderItems(Arrays.asList(tempRoot));
}
// We have used the first element. Increment to the next
currentDir++;
}
// Traverse the tree until we find our destination
for (; currentDir < homePath.length; currentDir++) {
for (UIRepositoryObject uiObj : tempRoot) {
if (uiObj instanceof UIRepositoryDirectory) {
if (uiObj.getName().equalsIgnoreCase(homePath[currentDir])) {
// We have a match. Let's move on to the next
tempRoot = (UIRepositoryDirectory) uiObj;
break;
}
}
}
}
// If we have traversed as many directories as there are in the path, we have found the directory
if (homePath.length == currentDir) {
setSelectedFolderItems(Arrays.asList(tempRoot));
folderTree.setSelectedItems(this.selectedFolderItems);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations