Skip to content
Permalink
Browse files
HOP-2917 Create folder from explorer perspective
  • Loading branch information
nadment committed May 30, 2021
1 parent ce25b91 commit b29670b308eeca4d2dc79bcf2ceb7c33ecc0561c
Showing 2 changed files with 59 additions and 2 deletions.
@@ -41,6 +41,7 @@
import org.apache.hop.i18n.BaseMessages;
import org.apache.hop.ui.core.ConstUi;
import org.apache.hop.ui.core.PropsUi;
import org.apache.hop.ui.core.dialog.EnterStringDialog;
import org.apache.hop.ui.core.dialog.ErrorDialog;
import org.apache.hop.ui.core.gui.GuiResource;
import org.apache.hop.ui.core.gui.GuiToolbarWidgets;
@@ -111,10 +112,11 @@ public class ExplorerPerspective implements IHopPerspective {
public static final String GUI_PLUGIN_TOOLBAR_PARENT_ID = "ExplorerPerspective-Toolbar";

public static final String TOOLBAR_ITEM_OPEN = "ExplorerPerspective-Toolbar-10000-Open";
public static final String TOOLBAR_ITEM_CREATE_FOLDER = "ExplorerPerspective-Toolbar-10050-CreateFolder";
public static final String TOOLBAR_ITEM_DELETE = "ExplorerPerspective-Toolbar-10100-Delete";
public static final String TOOLBAR_ITEM_RENAME = "ExplorerPerspective-Toolbar-10200-Rename";
public static final String TOOLBAR_ITEM_REFRESH = "ExplorerPerspective-Toolbar-10300-Refresh";

private static ExplorerPerspective instance;

public static ExplorerPerspective getInstance() {
@@ -754,6 +756,55 @@ public void openFile() {
openFile(selection[0]);
}

@GuiToolbarElement(
root = GUI_PLUGIN_TOOLBAR_PARENT_ID,
id = TOOLBAR_ITEM_CREATE_FOLDER,
toolTip = "i18n::ExplorerPerspective.ToolbarElement.CreateFolder.Tooltip",
image = "ui/images/folder-add.svg")
public void createFolder() {

TreeItem[] selection = tree.getSelection();
if (selection == null || selection.length == 0) {
return;
}
TreeItem item = selection[0];
TreeItemFolder tif = treeItemFolderMap.get(ConstUi.getTreePath(selection[0], 0));
EnterStringDialog dialog =
new EnterStringDialog(
getShell(),
"",
BaseMessages.getString(PKG, "ExplorerPerspective.CreateFolder.Header"),
BaseMessages.getString(PKG, "ExplorerPerspective.CreateFolder.Message", tif.path));
String folder = dialog.open();
if (folder != null) {
String newPath = tif.path;
if (!newPath.endsWith("/") && !newPath.endsWith("\\")) {
newPath += "/";
}
newPath += folder;
try {
FileObject newFolder = HopVfs.getFileObject(newPath);
newFolder.createFolder();

refresh();
updateSelection();

// IHopFileType fileType = getFileType(newPath);
// TreeItem folderItem = new TreeItem(item, SWT.NONE);
// folderItem.setText(folder);
// setItemImage(folderItem, fileType);
// callPaintListeners(tree, item, newPath, folder, fileType);
// addToFolderMap(item, newPath, folder, fileType);
} catch (Throwable e) {
new ErrorDialog(
getShell(),
BaseMessages.getString(PKG, "ExplorerPerspective.Error.CreateFolder.Header"),
BaseMessages.getString(PKG, "ExplorerPerspective.Error.CreateFolder.Message", newPath),
e);
}
}
}

@GuiToolbarElement(
root = GUI_PLUGIN_TOOLBAR_PARENT_ID,
id = TOOLBAR_ITEM_DELETE,
@@ -934,7 +985,8 @@ public void updateSelection() {

toolBarWidgets.enableToolbarItem(TOOLBAR_ITEM_OPEN, tif != null);
toolBarWidgets.enableToolbarItem(TOOLBAR_ITEM_DELETE, tif != null);
toolBarWidgets.enableToolbarItem(TOOLBAR_ITEM_RENAME, tif != null);
toolBarWidgets.enableToolbarItem(TOOLBAR_ITEM_RENAME, tif != null);
toolBarWidgets.enableToolbarItem(TOOLBAR_ITEM_CREATE_FOLDER, tif != null && tif.fileType instanceof FolderFileType);

for (IExplorerSelectionListener listener : selectionListeners) {
listener.fileSelected();
@@ -29,7 +29,12 @@ ExplorerPerspective.ToolbarElement.Open.Tooltip=Open selected file
ExplorerPerspective.ToolbarElement.Delete.Tooltip=Delete selected file (DEL)
ExplorerPerspective.ToolbarElement.Rename.Tooltip=Rename the selected file (F2)
ExplorerPerspective.ToolbarElement.Refresh.Tooltip=Refresh
ExplorerPerspective.ToolbarElement.CreateFolder.Tooltip=Create folder
ExplorerPerspective.Error.DeleteFile.Header=Error
ExplorerPerspective.Error.DeleteFile.Message=Error deleting file
ExplorerPerspective.Error.RenameFile.Header=Error
ExplorerPerspective.Error.RenameFile.Message=Error renaming file
ExplorerPerspective.CreateFolder.Header=Create directory
ExplorerPerspective.CreateFolder.Message=Please enter name of the folder to create in: ''{0}''
ExplorerPerspective.Error.CreateFolder.Header=Error
ExplorerPerspective.Error.CreateFolder.Message=Error creating folder: ''{0}''

0 comments on commit b29670b

Please sign in to comment.