====== File System ======
**File System** is a [[SOLoist Sample Applications|SOLoist sample application]] that represents a web-based [[wp>Orthodox_file_manager#Orthodox_file_managers | Orthodox File Manager]], with a personalized directory structure and standard file operations. It shows how a traditional concept of a file system can be implemented using the object paradigm with UML modeling and SOLoist UI.
Each object of //Person// has an associated file system that starts with a root folder. When an object of //Person// is selected in the topmost suggestion box, the file system associated to that object is browsed in two parallel windows.
A new file or folder can be created. Files or folders can be moved or copied, renamed, and deleted. Any of these commands (except renaming) can be performed on multiple items by selecting them from the list, or using the //Select all// checkbox. Selections are persisted, and every change in the folder structure is reflected immediately in the opposite window (if it is currently showing the same folder). Breadcrumbs are clickable, so one can return to any of the parent folders in one click.
==== Live example ====
[[http://soloistdemo.org/SampleApplications/filesystem.html]]\\
[[http://soloistdemo.org/SampleApplications/oql?q=SELECT+d%2C+d.title%2C+d.description%2C+d.isPublic%2C+d.submitted%2C+d.date%2C+d.superItem%0AFROM+Document+d&hide=0 | OQL Query: Documents]]
|{{screen:filesystem.png?350}}|
===== UML Model =====
{{filesystem.png}}
===== Business Logic Code =====
@Override
protected void execute() throws CommandPreconditionsException {
Document d = document.val();
d.rename(newTitle.val());
}
@Override
public boolean checkInputPinsCoverage()
{
if (document.val() == null)
{
throw new CommandPreconditionsException("Please, select document.");
}
if (newTitle.val() == null || (newTitle.val() != null && newTitle.val().isEmpty()))
{
throw new CommandPreconditionsException("Please, select new title.");
}
return true;
}
public void execute()
// -------------
// -------------
{
// ---------
Folder f = in.val();
f.createFolder(title.val());
// ---------
}
// -------------
@Override
public boolean checkInputPinsCoverage()
{
if (in.val() == null)
{
throw new CommandPreconditionsException("Please, select input.");
}
return true;
}
// -------------
public void execute()
// -------------
// -------------
{
// ---------
Folder f = in.val();
f.createRegularDoc(title.val());
// ---------
}
// -------------
@Override
public boolean checkInputPinsCoverage()
{
if (in.val() == null)
{
throw new CommandPreconditionsException("Please, select input.");
}
return true;
}
// -------------
public void execute()
// -------------
// -------------
{
// ---------
Folder source = from.val();
if (source.selected.size() == 0)
{
throw new CommandPreconditionsException("Please, select what to copy.");
}
Folder dest = to.val();
if (source.equals(dest))
{
throw new CommandPreconditionsException("Please, select different folders.");
}
for (Document d : source.selected.read()) {
if (d instanceof Folder)
if (((Folder) d).isParent(dest))
throw new CommandPreconditionsException("Destination folder is sub folder.");
}
source.copy(dest);
// ---------
}
// -------------
@Override
public boolean checkInputPinsCoverage()
{
if (from.val() == null)
{
throw new CommandPreconditionsException("Please, select source.");
}
if (to.val() == null)
{
throw new CommandPreconditionsException("Please, select destination.");
}
return true;
}
// -------------
public void execute()
// -------------
// -------------
{
// ---------
Folder source = from.val();
if (source.selected.size() == 0)
{
throw new CommandPreconditionsException("Select item to move!");
}
Folder dest = to.val();
if (source.equals(dest))
{
throw new CommandPreconditionsException("Select different folders.");
}
for (Document d : source.selected.read()) {
if (d instanceof Folder)
if (((Folder) d).isParent(dest))
throw new CommandPreconditionsException("Destination folder is subfolder!");
}
source.move(dest);
// ---------
}
public void execute()
// -------------
// -------------
{
// ---------
Folder f = from.val();
if (f.selected.size() == 0)
{
throw new CommandPreconditionsException("Please, select what to delete.");
}
f.deleteSelected();
// ---------
}
// -------------
@Override
public boolean checkInputPinsCoverage()
{
if (from.val() == null)
{
throw new CommandPreconditionsException("Please, select source.");
}
return true;
}
public void execute()
// -------------
// -------------
{
// ---------
Folder f = from.val();
f.clearSelection();
// ---------
}
// -------------
@Override
public boolean checkInputPinsCoverage()
{
if (from.val() == null)
{
throw new CommandPreconditionsException("Please, select source.");
}
return true;
}
public void execute()
// -------------
// -------------
{
// ---------
Folder f = from.val();
f.selectAll();
// ---------
}
// -------------
@Override
public boolean checkInputPinsCoverage()
{
if (from.val() == null)
{
throw new CommandPreconditionsException("Please, select source.");
}
return true;
}
// -------------
public void rename(Text newTitle)
// -------------
// -------------
{
// ---------
if (newTitle != null && !newTitle.isEmpty())
{
title.set(newTitle);
Folder parent = superItem.val();
if (parent != null)
{
parent.sort();
}
}
// ---------
}
public void createFolder(Text title)
// -------------
// -------------
{
// ---------
Folder f = new Folder();
if (title != null && !title.isEmpty())
{
f.title.set(title);
}
else
{
f.title.set(Text.fromString("NewFolder"));
}
subItems.add(f);
sort();
// ---------
}
public void createRegularDoc(Text title)
// -------------
// -------------
{
// ---------
RegularDocument file = new RegularDocument();
if (title != null && !title.isEmpty())
{
file.title.set(title);
}
else
{
file.title.set(Text.fromString("NewFile"));
}
subItems.add(file);
sort();
// ---------
}
public void copy(Folder to)
// -------------
// -------------
{
// ---------
if (this.equals(to)) {
throw new RuntimeException("Cannot copy to myself!");
}
for (Document selectedDoc : selected.read())
{
Document copy = TwoPassCloneManager.clone(selectedDoc, true);
to.subItems.add(copy);
}
to.sort();
// ---------
}
public void move(Folder to)
// -------------
// -------------
{
// ---------
if (this.equals(to)) {
throw new RuntimeException("Cannot move to myself!");
}
for (Document selectedDoc : selected.read())
{
this.selected.remove(selectedDoc);
this.subItems.remove(selectedDoc);
to.subItems.add(selectedDoc);
}
to.sort();
// ---------
}
public void deleteSelected()
// -------------
// -------------
{
// ---------
List toDelete = selected.read();
selected.clear();
for (Document document : toDelete)
{
document.destroy();
}
sort();
// ---------
}
public void clearSelection()
// -------------
// -------------
{
// ---------
selected.clear();
// ---------
}
public void selectAll()
// -------------
// -------------
{
// ---------
List initiallySelected = selected.read();
for (Document subItem : subItems.read())
{
if (!initiallySelected.contains(subItem))
{
selected.add(subItem);
}
}
// ---------
}
public void sort()
// -------------
// -------------
{
// ---------
List folders = new ArrayList();
List files = new ArrayList();
for (Document document : subItems.read()) {
if (document instanceof Folder) {
folders.add(document);
} else {
files.add(document);
}
}
Document.DocumentComparator comparator = new Document.DocumentComparator();
Collections.sort(folders, comparator);
Collections.sort(files, comparator);
List allDocuments = folders;
allDocuments.addAll(files);
subItems.set(allDocuments);
// ---------
}
// -------------
public boolean isParent(Document d)
{
for (Document subItem : subItems.read())
{
if (subItem.equals(d))
{
return true;
}
if (subItem instanceof Folder)
{
Folder subFolder = (Folder)subItem;
if (subFolder.isParent(d))
{
return true;
}
}
}
return false;
}
/**
* In megabytes.
* @return
*/
public double getSize()
{
return getSizeInBytes() / (1024.*1024.);
}
/**
* In bytes.
* @return
*/
public long getSizeInBytes()
{
long total = 0;
for (Document subItem : subItems.read())
{
if (subItem instanceof RegularDocument)
{
RegularDocument rd = (RegularDocument)subItem;
File file = rd.file.val();
if (file != null)
{
total = total + file.getFileSize();
}
}
else if (subItem instanceof PictureFromGallery)
{
PictureFromGallery pfg = (PictureFromGallery)subItem;
Picture picture = pfg.picture.val();
if (picture != null)
{
total = total + picture.getFileSize();
}
}
else if (subItem instanceof Folder)
{
Folder f = (Folder)subItem;
total = total + f.getSizeInBytes();
}
}
return total;
}
// -------------
===== GUI Code =====
package rs.sol.sampleapps;
import rs.sol.sampleapps.commands.ClearSelection;
import rs.sol.sampleapps.commands.Copy;
import rs.sol.sampleapps.commands.CreateFolder;
import rs.sol.sampleapps.commands.CreateRegularDocument;
import rs.sol.sampleapps.commands.DeleteSelectedItems;
import rs.sol.sampleapps.commands.Move;
import rs.sol.sampleapps.commands.RenameDocument;
import rs.sol.sampleapps.commands.SelectAll;
import rs.sol.sampleapps.gui.GUIBreadCrumbsSample;
import rs.sol.sampleapps.gui.GUIFileSystemSample;
import rs.sol.soloist.helpers.init.DefaultContextInit;
import rs.sol.soloist.helpers.init.Initializer;
import rs.sol.soloist.helpers.init.InitializerFailedException;
import rs.sol.soloist.server.builtindomains.builtindatatypes.Boolean;
import rs.sol.soloist.server.builtindomains.builtindatatypes.Text;
import rs.sol.soloist.server.guiconfiguration.components.GUIApplicationComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIButtonComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUICommandComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIContainerComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUILabelComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIPanelComponent;
import rs.sol.soloist.server.guiconfiguration.components.PerformImmediately;
import rs.sol.soloist.server.guiconfiguration.construction.GUIComponent;
import rs.sol.soloist.server.guiconfiguration.construction.GUIComponentBinding;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIElementComponent;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIInput;
import rs.sol.soloist.server.guiconfiguration.nonvisualcompoments.GUIBooleanFilter;
import rs.sol.soloist.server.guiconfiguration.nonvisualcompoments.GUIBufferComponent;
import rs.sol.soloist.server.guiconfiguration.nonvisualcompoments.GUIFindAllInstancesSAPComponent;
import rs.sol.soloist.server.guiconfiguration.nonvisualcompoments.GUINullFilter;
import rs.sol.soloist.server.guiconfiguration.nonvisualcompoments.GUITransformerComponent;
import rs.sol.soloist.server.guiconfiguration.style.GUIContext;
import rs.sol.soloist.server.guiconfiguration.style.GUIObjectSetting;
import rs.sol.soloist.server.guiconfiguration.style.GUITextFeature;
import rs.sol.soloist.server.server.SoloistServiceServlet;
import rs.sol.soloist.server.uml.concepts.IElement;
import rs.sol.soloist.server.uml.concepts.runtime.ISlot;
public enum FileSystem implements Initializer{
INSTANCE;
public static Copy copy;
public static Move move;
public static DeleteSelectedItems deleteSelectedItems;
public static ClearSelection clearSelection;
public static SelectAll selectAll;
public static CreateFolder createFolder;
public static CreateRegularDocument createRegularDocument;
public static RenameDocument rename;
@Override
public void init() throws InitializerFailedException
{
GUIApplicationComponent page = new GUIApplicationComponent();
page.setName("FileSystem");
SoloistServiceServlet.registerApplication(page);
GUIContext context = createContextAndStyles();
page.setContext(context);
GUIPanelComponent root = GUIPanelComponent.createFlow(page);
GUILabelComponent title = GUILabelComponent.create(root, "File System");
title.setStyle("titleStyle");
GUIPanelComponent topPanel = GUIPanelComponent.createFlow(root);
topPanel.setStyle("topPanel");
GUIFindAllInstancesSAPComponent allPersons = GUIFindAllInstancesSAPComponent.create(root, Person.CLASSIFIER);
GUILabelComponent.create(topPanel, "Choose person:").setStyle("margin3");
GUIInput suggestBox = GUIInput.createSuggest(topPanel);
suggestBox.setStyle("margin3");
GUIComponentBinding.create(allPersons.opValue(), suggestBox.ipCollection());
copy = new Copy();
move = new Move();
deleteSelectedItems = new DeleteSelectedItems();
clearSelection = new ClearSelection();
selectAll = new SelectAll();
createFolder = new CreateFolder();
createRegularDocument = new CreateRegularDocument();
rename = new RenameDocument();
GUIPanelComponent fileSystemPanel = GUIPanelComponent.createFlow(topPanel);
fileSystemPanel.setStyle("fileSystemRootPanel");
GUITransformerComponent gtc = GUITransformerComponent.createSlotValue(fileSystemPanel, Person.PROPERTIES.rootFolder);
GUIComponentBinding.create(suggestBox.opValue(), gtc.ipInput());
GUIBufferComponent leftBufferWithRootFolder = GUIBufferComponent.create(fileSystemPanel, false, (IElement)null); // initially empty
GUIBufferComponent rightBufferWithRootFolder = GUIBufferComponent.create(fileSystemPanel, false, (IElement)null); // initially empty
GUIComponentBinding.create(gtc.opOutput(), leftBufferWithRootFolder.ipInput()); // first fill the buffer
GUIComponentBinding.create(gtc.opOutput(), rightBufferWithRootFolder.ipInput()); // first fill the buffer
GUIComponentBinding.create(gtc.opOutput(), leftBufferWithRootFolder.ipSend()); // then tell it to send
GUIComponentBinding.create(gtc.opOutput(), rightBufferWithRootFolder.ipSend()); // then tell it to send
GUIPanelComponent left = GUIPanelComponent.createFlow(fileSystemPanel);
left.setStyle("floatL");
GUIPanelComponent buttonColumn = GUIPanelComponent.createFlow(fileSystemPanel);
buttonColumn.setStyle("buttonColumn");
GUIPanelComponent right = GUIPanelComponent.createFlow(fileSystemPanel);
right.setStyle("floatR");
GUIBreadCrumbsSample leftBread = new GUIBreadCrumbsSample();
left.add(leftBread);
GUIFileSystemSample leftBrowser = new GUIFileSystemSample();
leftBrowser.isLeft.set(Boolean.TRUE);
fileBrowserHeadingFragment(left, leftBread.opRelay1());
left.add(leftBrowser);
GUIComponentBinding.create(leftBufferWithRootFolder.opOutput(), leftBread.ipElement());
GUIComponentBinding.create(leftBufferWithRootFolder.opOutput(), leftBrowser.ipElement());
GUIComponentBinding.create(leftBread.opRelay2(), leftBrowser.ipElement());
GUIComponentBinding.create(leftBrowser.opRelay2(), leftBread.ipElement());
GUIComponentBinding.create(left.opRelay2(), leftBrowser.ipRefreshContents());
GUIBreadCrumbsSample rightBread = new GUIBreadCrumbsSample();
right.add(rightBread);
GUIFileSystemSample rightBrowser = new GUIFileSystemSample();
rightBrowser.isLeft.set(Boolean.FALSE);
fileBrowserHeadingFragment(right, rightBread.opRelay1());
right.add(rightBrowser);
GUIComponentBinding.create(rightBufferWithRootFolder.opOutput(), rightBread.ipElement());
GUIComponentBinding.create(rightBufferWithRootFolder.opOutput(), rightBrowser.ipElement());
GUIComponentBinding.create(rightBread.opRelay2(), rightBrowser.ipElement());
GUIComponentBinding.create(rightBrowser.opRelay2(), rightBread.ipElement());
GUIComponentBinding.create(right.opRelay2(), rightBrowser.ipRefreshContents());
GUIComponentBinding.create(right.opRelay2(), leftBrowser.ipRefreshContents());
GUIComponentBinding.create(left.opRelay2(), rightBrowser.ipRefreshContents());
// connecting browsers
GUIComponentBinding.create(leftBrowser.opRelay2(), leftBrowser.ipElement());
GUIComponentBinding.create(rightBrowser.opRelay2(), rightBrowser.ipElement());
GUIComponentBinding.create(leftBread.opRelay2(), leftBread.ipElement());
GUIComponentBinding.create(rightBread.opRelay2(), rightBread.ipElement());
// end connecting browsers
GUIButtonComponent copyLTR = GUIButtonComponent.create(buttonColumn, " ", new Copy());
copyLTR.setTooltip("Copy left to right");
copyLTR.setStyle("copyLTR");
GUIComponentBinding.create(leftBread.opRelay1(), copyLTR, Copy.PROPERTIES.from);
GUIComponentBinding.create(rightBread.opRelay1(), copyLTR, Copy.PROPERTIES.to);
GUIButtonComponent moveLTR = GUIButtonComponent.create(buttonColumn, " ", new Move());
moveLTR.setTooltip("Move left to right");
moveLTR.setStyle("moveLTR");
GUIComponentBinding.create(leftBread.opRelay1(), moveLTR, Move.PROPERTIES.from);
GUIComponentBinding.create(rightBread.opRelay1(), moveLTR, Move.PROPERTIES.to);
GUIButtonComponent copyRTL = GUIButtonComponent.create(buttonColumn, " ", new Copy());
copyRTL.setTooltip("Copy right to left");
copyRTL.setStyle("copyRTL");
GUIComponentBinding.create(rightBread.opRelay1(), copyRTL, Copy.PROPERTIES.from);
GUIComponentBinding.create(leftBread.opRelay1(), copyRTL, Copy.PROPERTIES.to);
GUIButtonComponent moveRTL = GUIButtonComponent.create(buttonColumn, " ", new Move());
moveRTL.setTooltip("Move right to left");
moveRTL.setStyle("moveRTL");
GUIComponentBinding.create(rightBread.opRelay1(), moveRTL, Move.PROPERTIES.from);
GUIComponentBinding.create(leftBread.opRelay1(), moveRTL, Move.PROPERTIES.to);
GUIComponentBinding.create(copyLTR.opCommandExecuted(), leftBrowser.ipRefreshContents());
GUIComponentBinding.create(copyLTR.opCommandExecuted(), rightBrowser.ipRefreshContents());
GUIComponentBinding.create(moveLTR.opCommandExecuted(), leftBrowser.ipRefreshContents());
GUIComponentBinding.create(moveLTR.opCommandExecuted(), rightBrowser.ipRefreshContents());
GUIComponentBinding.create(copyRTL.opCommandExecuted(), leftBrowser.ipRefreshContents());
GUIComponentBinding.create(copyRTL.opCommandExecuted(), rightBrowser.ipRefreshContents());
GUIComponentBinding.create(moveRTL.opCommandExecuted(), leftBrowser.ipRefreshContents());
GUIComponentBinding.create(moveRTL.opCommandExecuted(), rightBrowser.ipRefreshContents());
GUINullFilter leftNullFilter = GUINullFilter.create(fileSystemPanel);
GUIComponentBinding.create(leftBread.opRelay1(), leftNullFilter.ipInput());
GUINullFilter rightNullFilter = GUINullFilter.create(fileSystemPanel);
GUIComponentBinding.create(rightBread.opRelay1(), rightNullFilter.ipInput());
GUIComponentBinding.create(leftNullFilter.opYes(), leftBufferWithRootFolder.ipSend());
GUIComponentBinding.create(rightNullFilter.opYes(), rightBufferWithRootFolder.ipSend());
GUIComponentBinding.create(leftBrowser.opRelay1(), leftBrowser.ipRefreshContents());
GUIComponentBinding.create(leftBrowser.opRelay1(), rightBrowser.ipRefreshContents());
GUIComponentBinding.create(rightBrowser.opRelay1(), rightBrowser.ipRefreshContents());
GUIComponentBinding.create(rightBrowser.opRelay1(), leftBrowser.ipRefreshContents());
}
private void fileBrowserHeadingFragment(GUIPanelComponent rootPanel, ISlot> folder)
{
//heading
GUIPanelComponent heading = GUIPanelComponent.createFlow(rootPanel);
heading.setStyle("fileBrowserHeading");
GUIInput selectionCheckbox = GUIInput.createField(heading, Boolean.CLASSIFIER);
selectionCheckbox.addInitialValue(Boolean.FALSE);
selectionCheckbox.setLowerBound(1);
selectionCheckbox.setTooltip("Select/Deselect All");
GUICommandComponent selectCmd = GUICommandComponent.create(heading, FileSystem.selectAll, PerformImmediately.NOTHING);
GUICommandComponent clearSelectionCmd = GUICommandComponent.create(heading, FileSystem.clearSelection, PerformImmediately.NOTHING);
GUIComponentBinding.create(folder, selectCmd, SelectAll.PROPERTIES.from);
GUIComponentBinding.create(folder, clearSelectionCmd, ClearSelection.PROPERTIES.from);
GUIBooleanFilter gbf = GUIBooleanFilter.create(heading);
FileSystem.missFirstValueLogic(heading, selectionCheckbox, gbf, gbf.ipInput());
GUIComponentBinding.create(gbf.opYes(), selectCmd.ipClick());
GUIComponentBinding.create(gbf.opNo(), clearSelectionCmd.ipClick());
GUIButtonComponent delete = GUIButtonComponent.create(heading, " ", FileSystem.deleteSelectedItems);
delete.setTooltip("Delete");
delete.setStyle("delBtn");
delete.setConfirmationRequired(true);
delete.setConfirmationMessage("Delete?");
GUIComponentBinding.create(folder, delete, DeleteSelectedItems.PROPERTIES.from);
GUIButtonComponent newDocument = GUIButtonComponent.create(heading, " ", FileSystem.createRegularDocument);
newDocument.setTooltip("Create new file");
newDocument.setStyle("multiUploadAddMoreBtn");
GUIComponentBinding.create(folder, newDocument, CreateRegularDocument.PROPERTIES.in);
GUIButtonComponent newFolder = GUIButtonComponent.create(heading, " ", FileSystem.createFolder);
newFolder.setTooltip("Create new folder");
newFolder.setStyle("addFolder");
GUIComponentBinding.create(folder, newFolder, CreateFolder.PROPERTIES.in);
GUIInput newName = GUIInput.createField(heading, Text.CLASSIFIER);
newName.setTooltip("Name");
GUIComponentBinding.create(newName.opValue(), newDocument, CreateRegularDocument.PROPERTIES.title);
GUIComponentBinding.create(newName.opValue(), newFolder, CreateFolder.PROPERTIES.title);
GUIComponentBinding.create(delete.opCommandExecuted(), rootPanel.ipRelay2());
GUIComponentBinding.create(newFolder.opCommandExecuted(), rootPanel.ipRelay2());
GUIComponentBinding.create(newDocument.opCommandExecuted(), rootPanel.ipRelay2());
}
private GUIContext createContextAndStyles()
{
GUIContext context = new GUIContext();
DefaultContextInit.getRoot().addContext(context);
GUIObjectSetting folder = GUIObjectSetting.create(context, Folder.CLASSIFIER);
GUITextFeature.createFixedName(folder, "");
GUIObjectSetting regularDocument = GUIObjectSetting.create(context, RegularDocument.CLASSIFIER);
GUITextFeature.createFixedName(regularDocument, "");
return context;
}
public static void missFirstValueLogic(GUIContainerComponent panelForNonVisuals, GUIElementComponent source, GUIComponent destComp, ISlot> destSlot)
{
destComp.setEnabled(false);
GUIComponentBinding.create(source.opValue(), destSlot); // fisrt
GUIBufferComponent enableBuffer = GUIBufferComponent.create(panelForNonVisuals, false, Boolean.TRUE);
GUIComponentBinding.create(enableBuffer.opOutput(), destComp.ipEnabled());
GUIComponentBinding.create(source.opValue(), enableBuffer.ipSend()); // second
}
}
@Override
protected GUIContainerComponent getDynamicContents(IElement el)
{
GUIPanelComponent rootPanel = GUIPanelComponent.createFlow(null);
rootPanel.setStyle("fileBrowser");
Folder folder = (Folder) el;
if (folder == null)
return rootPanel;
try
{
folder.title.val(); // We first check whether this object exist.
}
catch(GeneralActionExecutionException gaee)
{
return rootPanel; // If the object does not exist, we just return empty panel.
}
GUIBufferComponent folderBuf = GUIBufferComponent.create(rootPanel, true, folder);
//Items
GUIPanelComponent itemsTable = GUIPanelComponent.createTable(rootPanel);
int row = 0;
for (Document item : folder.subItems.read()) {
int col = 0;
GUIBufferComponent itemBuf = GUIBufferComponent.create(rootPanel, true, item);
GUIEdit select = GUIEdit.createList(itemsTable, Folder.PROPERTIES.selected);
select.setLayoutData(TableLayoutData.create(row, col++));
GUIComponentBinding.create(itemBuf.opOutput(), select.ipCollection());
GUIComponentBinding.create(folderBuf.opOutput(), select.ipElement());
GUIButtonComponent edit = GUIButtonComponent.create(itemsTable, " ", TableLayoutData.create(row, col++));
edit.setStyle("editName");
edit.setTooltip("Rename");
GUIPanelComponent nameWrap = GUIPanelComponent.createFlow(itemsTable);
if (item instanceof Folder)
nameWrap.setRowColumn(row, col++, 1, 4); //chrome likes colspan 4
else
nameWrap.setRowColumn(row, col++);
GUIButtonComponent buttonLink = GUIButtonComponent.createLink(nameWrap, item.title.val().toString());
if (item instanceof RegularDocument)
buttonLink.setStyle("#fileLink");
else
buttonLink.setStyle("#folderLink");
if (item instanceof Folder) // Only for folders we will do navigation through the hierarchy and folder size.
{
GUIBufferComponent b1 = GUIBufferComponent.create(rootPanel, false, item);
GUIComponentBinding.create(b1.opOutput(), this.ipRelay2());
GUIComponentBinding.create(buttonLink.opClick(), b1.ipSend());
GUILabelComponent.create(nameWrap, FormattingUtility.formatReal(Real.valueOf(((Folder)item).getSize())) + "MB");
}
GUIInput nameInput = GUIInput.createField(nameWrap, Text.CLASSIFIER);
nameInput.addInitialValue(item.title.val());
nameInput.setStyle("gwt-TextBox-invisible");
GUICommandComponent rename = GUICommandComponent.create(nameWrap, FileSystem.rename, PerformImmediately.NOTHING);
GUIComponentBinding.create(itemBuf.opOutput(), rename, RenameDocument.PROPERTIES.document);
GUIComponentBinding.create(nameInput.opValue(), rename, RenameDocument.PROPERTIES.newTitle);
GUIRelayComponent clickRelay = GUIRelayComponent.create(nameWrap);
FileSystem.missFirstValueLogic(nameWrap, nameInput, clickRelay, clickRelay.ipRelay());
GUIComponentBinding.create(clickRelay.opRelay(), rename.ipClick());
GUIBufferComponent nullBuffer = GUIBufferComponent.create(rootPanel, false, (IElement)null);
GUIComponentBinding.create(nullBuffer.opOutput(), this.ipRelay1());
GUIComponentBinding.create(rename.opCommandExecuted(), nullBuffer.ipSend());
GUIBufferComponent showEditor = GUIBufferComponent.create(nameWrap, false, Text.fromString("invisible"));
GUIBufferComponent showLink = GUIBufferComponent.create(nameWrap, false, Text.fromString("invisible"));
GUIComponentBinding.create(edit.opClick(), showEditor.ipSend());
GUIComponentBinding.create(rename.opCommandExecuted(), showLink.ipSend());
GUIComponentBinding.create(showEditor.opOutput(), nameInput.ipRemoveStyle());
GUIComponentBinding.create(showEditor.opOutput(), buttonLink.ipAddStyle());
GUIComponentBinding.create(showLink.opOutput(), nameInput.ipAddStyle());
GUIComponentBinding.create(showLink.opOutput(), buttonLink.ipRemoveStyle());
if (item instanceof RegularDocument) {
GUIPanelComponent fileUploader = GUIEdit.createFile(itemsTable, RegularDocument.PROPERTIES.file, true, true);
GUIComponentBinding.create(itemBuf.opOutput(), fileUploader.ipRelay1());
fileUploader.setRowColumn(row, col++);
GUIEdit.getBrowseButton(fileUploader).setStyle("#browse" + (isLeft.val().toBoolean() ? "L" : "R") + row);
GUIHTMLComponent browse = GUIHTMLComponent.create(itemsTable, "");
browse.setLayoutData(TableLayoutData.create(row, col++));
browse.setTooltip("Browse");
}
row++;
}
return rootPanel;
}
@Override
protected GUIContainerComponent getDynamicContents(IElement el)
{
GUIPanelComponent rootPanel = GUIPanelComponent.createFlow(null);
rootPanel.setStyle("filesystem_breadcrumb");
Folder f = (Folder)el;
if (f == null)
{
return rootPanel;
}
try
{
f.title.val(); // We first check whether this object exist.
}
catch(GeneralActionExecutionException gaee)
{
GUIBufferComponent nullBuffer = GUIBufferComponent.create(rootPanel, true, (IElement)null);
GUIComponentBinding.create(nullBuffer.opOutput(), this.ipRelay1());
return rootPanel; // If the object does not exist, we just return empty panel.
}
GUILabelComponent thisFolder = GUILabelComponent.create(rootPanel, getFolderName(f));
thisFolder.setStyle("displayInline");
Folder current = f.superItem.val();
while (current != null)
{
GUILabelComponent separator = new GUILabelComponent();
separator.setLabel("/");
separator.setStyle("displayInline");
rootPanel.addFirst(separator);
GUIButtonComponent link = new GUIButtonComponent();
link.setDisplayAsLink(true);
link.setText(getFolderName(current));
link.setStyle("displayInline");
rootPanel.addFirst(link);
GUIBufferComponent buffer = GUIBufferComponent.create(rootPanel, false, current);
GUIComponentBinding.create(buffer.opOutput(), this.ipRelay2());
GUIComponentBinding.create(link.opClick(), buffer.ipSend());
current = current.superItem.val();
}
GUIBufferComponent currentFolderBuffer = GUIBufferComponent.create(rootPanel, true, f);
GUIComponentBinding.create(currentFolderBuffer.opOutput(), this.ipRelay1());
return rootPanel;
}
private String getFolderName(Folder f)
{
return f.superItem.val() == null ? getRootFolderName(f) : f.title.val().toString();
}
private String getRootFolderName(Folder f)
{
if (f.owner.val() != null)
{
return f.owner.val().name.val().toString();
}
return ""; // this shuold never happen
}
function triggerBrowse(id) {
var doc = document.getElementById(id);
var file = doc.getElementsByTagName("input").item(0);
file.click();
}