This is an old revision of the document!


File System Sample

This is the most complex sample presented in this wiki. It is web based Orthodox File Manager application. File system can be browsed per user (Person), that is, every person has different root folder. You can create new file or folder, move or copy files and folders, rename and delete them. Any of these commands (except renaming) can be performed on multiple items by selecting them from the list, or using “select all” checkbox. Selections are persisted, and every change in folder structure is reflected immediately on opposite panel (if they're showing same folder). Breadcrumbs are clickable, so you could return to any of the parent folders in one click.

Live example

UML Model

Business Logic Code

RenameDocument.java
	@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;
	}
CreateFolder.java
    public void execute() 
    // -------------<SOL id="8e18bf85-cfe0-48d3-87af-91cbba029291:___throw__" />
    // -------------<LOS id="8e18bf85-cfe0-48d3-87af-91cbba029291:___throw__" />
    {
        // ---------<SOL id="8e18bf85-cfe0-48d3-87af-91cbba029291:___body___" />
    	Folder f = in.val();
 
        f.createFolder(title.val());
        // ---------<LOS id="8e18bf85-cfe0-48d3-87af-91cbba029291:___body___" />
    }
 
    // -------------<SOL id="31d4d83c-1416-4a69-9070-df78357687e5:___cend___" />
	@Override
	public boolean checkInputPinsCoverage()
	{
		if (in.val() == null)
		{
			throw new CommandPreconditionsException("Please, select input.");
		}
		return true;
	}
    // -------------<LOS id="31d4d83c-1416-4a69-9070-df78357687e5:___cend___" />
CreateRegularDocument.java
    public void execute() 
    // -------------<SOL id="116b4004-8141-4731-af83-2e12dbebbc8a:___throw__" />
    // -------------<LOS id="116b4004-8141-4731-af83-2e12dbebbc8a:___throw__" />
    {
        // ---------<SOL id="116b4004-8141-4731-af83-2e12dbebbc8a:___body___" />
    	Folder f = in.val();
 
        f.createRegularDoc(title.val());
        // ---------<LOS id="116b4004-8141-4731-af83-2e12dbebbc8a:___body___" />
    }
 
    // -------------<SOL id="7695a4ce-cca4-4aba-8e04-c5635b2823e3:___cend___" />
	@Override
	public boolean checkInputPinsCoverage()
	{
		if (in.val() == null)
		{
			throw new CommandPreconditionsException("Please, select input.");
		}
		return true;
	}
    // -------------<LOS id="7695a4ce-cca4-4aba-8e04-c5635b2823e3:___cend___" />
Copy.java
    public void execute() 
    // -------------<SOL id="86f16d44-83a6-466e-8bc2-eacc21ce4f92:___throw__" />
    // -------------<LOS id="86f16d44-83a6-466e-8bc2-eacc21ce4f92:___throw__" />
    {
        // ---------<SOL id="86f16d44-83a6-466e-8bc2-eacc21ce4f92:___body___" />
    	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);
        // ---------<LOS id="86f16d44-83a6-466e-8bc2-eacc21ce4f92:___body___" />
    }
 
    // -------------<SOL id="ed4ec470-60cf-4353-a47b-dd0198ebfc4e:___cend___" />
	@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;
	}
    // -------------<LOS id="ed4ec470-60cf-4353-a47b-dd0198ebfc4e:___cend___" />
Move.java
    public void execute() 
    // -------------<SOL id="d8568511-9904-44d2-adb7-1198405a813a:___throw__" />
    // -------------<LOS id="d8568511-9904-44d2-adb7-1198405a813a:___throw__" />
    {
        // ---------<SOL id="d8568511-9904-44d2-adb7-1198405a813a:___body___" />
    	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);
        // ---------<LOS id="d8568511-9904-44d2-adb7-1198405a813a:___body___" />
    }
DeleteSelectedItems.java
    public void execute() 
    // -------------<SOL id="821f21b3-fec2-4284-8766-5f6c6fb04ecf:___throw__" />
    // -------------<LOS id="821f21b3-fec2-4284-8766-5f6c6fb04ecf:___throw__" />
    {
        // ---------<SOL id="821f21b3-fec2-4284-8766-5f6c6fb04ecf:___body___" />
    	Folder f = from.val();
        if (f.selected.size() == 0)
        {
        	throw new CommandPreconditionsException("Please, select what to delete.");
        }
 
        f.deleteSelected();
        // ---------<LOS id="821f21b3-fec2-4284-8766-5f6c6fb04ecf:___body___" />
    }
 
    // -------------<SOL id="0f053b85-f495-44a4-a67e-46789b1de0e0:___cend___" />
	@Override
	public boolean checkInputPinsCoverage()
	{
		if (from.val() == null)
		{
			throw new CommandPreconditionsException("Please, select source.");
		}
		return true;
	}
ClearSelection.java
    public void execute() 
    // -------------<SOL id="75819bb8-dd41-4afa-9079-5754c5754c52:___throw__" />
    // -------------<LOS id="75819bb8-dd41-4afa-9079-5754c5754c52:___throw__" />
    {
        // ---------<SOL id="75819bb8-dd41-4afa-9079-5754c5754c52:___body___" />
    	Folder f = from.val();
 
        f.clearSelection();
        // ---------<LOS id="75819bb8-dd41-4afa-9079-5754c5754c52:___body___" />
    }
 
    // -------------<SOL id="e8667dbc-7a12-4cb0-a211-8c7e20164168:___cend___" />
	@Override
	public boolean checkInputPinsCoverage()
	{
		if (from.val() == null)
		{
			throw new CommandPreconditionsException("Please, select source.");
		}
		return true;
	}
SelectAll.java
    public void execute() 
    // -------------<SOL id="2d4d42a8-18e7-47e4-9e33-6df9eab93ce8:___throw__" />
    // -------------<LOS id="2d4d42a8-18e7-47e4-9e33-6df9eab93ce8:___throw__" />
    {
        // ---------<SOL id="2d4d42a8-18e7-47e4-9e33-6df9eab93ce8:___body___" />
    	Folder f = from.val();
 
        f.selectAll();
        // ---------<LOS id="2d4d42a8-18e7-47e4-9e33-6df9eab93ce8:___body___" />
    }
 
    // -------------<SOL id="f3ef4fb9-baee-4571-88bf-541954bd3aea:___cend___" />
	@Override
	public boolean checkInputPinsCoverage()
	{
		if (from.val() == null)
		{
			throw new CommandPreconditionsException("Please, select source.");
		}
		return true;
	}
    // -------------<LOS id="f3ef4fb9-baee-4571-88bf-541954bd3aea:___cend___" />
Document.java
    public void rename(Text newTitle) 
    // -------------<SOL id="e6dcc7eb-36a0-49a3-bef1-c1d0ad4aedfd:___throw__" />
    // -------------<LOS id="e6dcc7eb-36a0-49a3-bef1-c1d0ad4aedfd:___throw__" />
    {
        // ---------<SOL id="e6dcc7eb-36a0-49a3-bef1-c1d0ad4aedfd:___body___" />
    	if (newTitle != null && !newTitle.isEmpty())
        {
        	title.set(newTitle);
        	Folder parent = superItem.val();
        	if (parent != null)
        	{
        		parent.sort();
        	}
        }
        // ---------<LOS id="e6dcc7eb-36a0-49a3-bef1-c1d0ad4aedfd:___body___" />
    }
Folder.java
    public void createFolder(Text title) 
    // -------------<SOL id="ae431ac7-2f22-4b1c-aa7a-41c254dac592:___throw__" />
    // -------------<LOS id="ae431ac7-2f22-4b1c-aa7a-41c254dac592:___throw__" />
    {
        // ---------<SOL id="ae431ac7-2f22-4b1c-aa7a-41c254dac592:___body___" />
    	Folder f = new Folder();
        if (title != null && !title.isEmpty())
        {
        	f.title.set(title);
        }
        else
        {
        	f.title.set(Text.fromString("NewFolder"));
        }
        subItems.add(f);
 
        sort();
        // ---------<LOS id="ae431ac7-2f22-4b1c-aa7a-41c254dac592:___body___" />
    }
 
 
    public void createRegularDoc(Text title) 
    // -------------<SOL id="321f23ed-cc68-4ee9-92de-7c2a9785b981:___throw__" />
    // -------------<LOS id="321f23ed-cc68-4ee9-92de-7c2a9785b981:___throw__" />
    {
        // ---------<SOL id="321f23ed-cc68-4ee9-92de-7c2a9785b981:___body___" />
    	RegularDocument file = new RegularDocument();
        if (title != null && !title.isEmpty())
        {
        	file.title.set(title);
        }
        else
        {
        	file.title.set(Text.fromString("NewFile"));
        }
        subItems.add(file);
 
        sort();
        // ---------<LOS id="321f23ed-cc68-4ee9-92de-7c2a9785b981:___body___" />
    }
 
 
    public void copy(Folder to) 
    // -------------<SOL id="12b7a4b0-502a-44b8-b52f-6833cbbeca58:___throw__" />
    // -------------<LOS id="12b7a4b0-502a-44b8-b52f-6833cbbeca58:___throw__" />
    {
        // ---------<SOL id="12b7a4b0-502a-44b8-b52f-6833cbbeca58:___body___" />
    	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();
        // ---------<LOS id="12b7a4b0-502a-44b8-b52f-6833cbbeca58:___body___" />
    }
 
 
    public void move(Folder to) 
    // -------------<SOL id="619ebdc5-80ff-4fcc-8d0f-fbcce8bc567b:___throw__" />
    // -------------<LOS id="619ebdc5-80ff-4fcc-8d0f-fbcce8bc567b:___throw__" />
    {
        // ---------<SOL id="619ebdc5-80ff-4fcc-8d0f-fbcce8bc567b:___body___" />
    	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();
        // ---------<LOS id="619ebdc5-80ff-4fcc-8d0f-fbcce8bc567b:___body___" />
    }
 
 
    public void deleteSelected() 
    // -------------<SOL id="846993a8-efb5-4fc4-8fbe-c770f18e9f9c:___throw__" />
    // -------------<LOS id="846993a8-efb5-4fc4-8fbe-c770f18e9f9c:___throw__" />
    {
        // ---------<SOL id="846993a8-efb5-4fc4-8fbe-c770f18e9f9c:___body___" />
    	List<Document> toDelete = selected.read();
    	selected.clear();
    	for (Document document : toDelete)
    	{
			document.destroy();
		}
 
		sort();
        // ---------<LOS id="846993a8-efb5-4fc4-8fbe-c770f18e9f9c:___body___" />
    }
 
 
    public void clearSelection() 
    // -------------<SOL id="67c1ba1a-2ed4-4205-8de1-016a7e4237d1:___throw__" />
    // -------------<LOS id="67c1ba1a-2ed4-4205-8de1-016a7e4237d1:___throw__" />
    {
        // ---------<SOL id="67c1ba1a-2ed4-4205-8de1-016a7e4237d1:___body___" />
    	selected.clear();
        // ---------<LOS id="67c1ba1a-2ed4-4205-8de1-016a7e4237d1:___body___" />
    }
 
 
    public void selectAll() 
    // -------------<SOL id="55b2c057-50b4-4884-8528-07c2f09a904f:___throw__" />
    // -------------<LOS id="55b2c057-50b4-4884-8528-07c2f09a904f:___throw__" />
    {
        // ---------<SOL id="55b2c057-50b4-4884-8528-07c2f09a904f:___body___" />
    	List<Document> initiallySelected = selected.read();
        for (Document subItem : subItems.read())
        {
			if (!initiallySelected.contains(subItem))
			{
				selected.add(subItem);
			}
		}
        // ---------<LOS id="55b2c057-50b4-4884-8528-07c2f09a904f:___body___" />
    }
 
 
    public void sort() 
    // -------------<SOL id="41a3b82a-1fda-41fe-8b54-2a3d739b20d2:___throw__" />
    // -------------<LOS id="41a3b82a-1fda-41fe-8b54-2a3d739b20d2:___throw__" />
    {
        // ---------<SOL id="41a3b82a-1fda-41fe-8b54-2a3d739b20d2:___body___" />
    	List<Document> folders = new ArrayList<Document>();
        List<Document> files = new ArrayList<Document>();
		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<Document> allDocuments = folders;
        allDocuments.addAll(files);
        subItems.set(allDocuments);
        // ---------<LOS id="41a3b82a-1fda-41fe-8b54-2a3d739b20d2:___body___" />
    }
 
    // -------------<SOL id="404cd1fd-f92a-4579-9169-3bb45171030d:___cend___" />
	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;
	}
    // -------------<LOS id="404cd1fd-f92a-4579-9169-3bb45171030d:___cend___" />

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.GUICollectionInput;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIElementComponent;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUISuggestWidget;
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.name.set(Text.fromString("FileSystem")); 
		SoloistServiceServlet.registerApplication(page);
		GUIContext context = createContextAndStyles();
		page.context.set(context);
 
		GUIPanelComponent root = GUIPanelComponent.createFlow(page);
 
		GUILabelComponent title = GUILabelComponent.create(root, "File System");
		title.styleName.set(Text.fromString("titleStyle"));
 
		GUIPanelComponent topPanel = GUIPanelComponent.createFlow(root);
		topPanel.styleName.set(Text.fromString("topPanel"));
 
		GUIFindAllInstancesSAPComponent allPersons = GUIFindAllInstancesSAPComponent.create(root, Person.FQ_TYPE_NAME);
		GUILabelComponent.create(topPanel, "Choose person:").styleName.set(Text.fromString("margin3"));
		GUIElementComponent suggestBox = GUIElementComponent.createInput(topPanel, new GUISuggestWidget(), new GUICollectionInput());
		suggestBox.styleName.set(Text.fromString("margin3"));
		GUIComponentBinding.create(allPersons.value, GUICollectionInput.get(suggestBox).collection);
 
		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.styleName.set(Text.fromString("fileSystemRootPanel"));
 
		GUITransformerComponent gtc = GUITransformerComponent.transformToSlotValue(fileSystemPanel, Person.PROPERTIES.rootFolder);
		GUIComponentBinding.create(suggestBox.value, gtc.input);
 
		GUIBufferComponent leftBufferWithRootFolder = GUIBufferComponent.create(fileSystemPanel, false, (IElement)null); // initially empty
		GUIBufferComponent rightBufferWithRootFolder = GUIBufferComponent.create(fileSystemPanel, false, (IElement)null); // initially empty
		GUIComponentBinding.create(gtc.output, leftBufferWithRootFolder.input); // first fill the buffer
		GUIComponentBinding.create(gtc.output, rightBufferWithRootFolder.input); // first fill the buffer
		GUIComponentBinding.create(gtc.output, leftBufferWithRootFolder.send); // then tell it to send
		GUIComponentBinding.create(gtc.output, rightBufferWithRootFolder.send); // then tell it to send
 
		GUIPanelComponent left = GUIPanelComponent.createFlow(fileSystemPanel);
		left.styleName.set(Text.fromString("floatL"));
		GUIPanelComponent buttonColumn = GUIPanelComponent.createFlow(fileSystemPanel);
		buttonColumn.styleName.set(Text.fromString("buttonColumn"));
		GUIPanelComponent right = GUIPanelComponent.createFlow(fileSystemPanel);
		right.styleName.set(Text.fromString("floatR"));
 
		GUIBreadCrumbsSample leftBread = new GUIBreadCrumbsSample();
		leftBread.parent.set(left);
		GUIFileSystemSample leftBrowser = new GUIFileSystemSample();
		leftBrowser.isLeft.set(Boolean.TRUE);
		fileBrowserHeadingFragment(left, leftBread.input);
		leftBrowser.parent.set(left);
		GUIComponentBinding.create(leftBufferWithRootFolder.output, leftBread.element);
		GUIComponentBinding.create(leftBufferWithRootFolder.output, leftBrowser.element);
		GUIComponentBinding.create(leftBread.output, leftBrowser.element);
		GUIComponentBinding.create(leftBrowser.output, leftBread.element);
		GUIComponentBinding.create(left.output, leftBrowser.refreshContents);
 
		GUIBreadCrumbsSample rightBread = new GUIBreadCrumbsSample();
		rightBread.parent.set(right);
		GUIFileSystemSample rightBrowser = new GUIFileSystemSample();
		rightBrowser.isLeft.set(Boolean.FALSE);
		fileBrowserHeadingFragment(right, rightBread.input);
		rightBrowser.parent.set(right);
		GUIComponentBinding.create(rightBufferWithRootFolder.output, rightBread.element);
		GUIComponentBinding.create(rightBufferWithRootFolder.output, rightBrowser.element);
		GUIComponentBinding.create(rightBread.output, rightBrowser.element);
		GUIComponentBinding.create(rightBrowser.output, rightBread.element);
		GUIComponentBinding.create(right.output, rightBrowser.refreshContents);
		GUIComponentBinding.create(right.output, leftBrowser.refreshContents);
		GUIComponentBinding.create(left.output, rightBrowser.refreshContents);
 
		// connecting browsers
		GUIComponentBinding.create(leftBrowser.output, leftBrowser.element);
		GUIComponentBinding.create(rightBrowser.output, rightBrowser.element);
 
		GUIComponentBinding.create(leftBread.output, leftBread.element);
		GUIComponentBinding.create(rightBread.output, rightBread.element);
		// end connecting browsers
 
		GUIButtonComponent copyLTR = GUIButtonComponent.create(buttonColumn, " ", new Copy());
		copyLTR.tooltip.set(Text.fromString("Copy left to right"));
		copyLTR.styleName.set(Text.fromString("copyLTR"));
		GUIComponentBinding.create(leftBread.input, copyLTR, Copy.PROPERTIES.from);
		GUIComponentBinding.create(rightBread.input, copyLTR, Copy.PROPERTIES.to);
 
		GUIButtonComponent moveLTR = GUIButtonComponent.create(buttonColumn, " ", new Move());
		moveLTR.tooltip.set(Text.fromString("Move left to right"));
		moveLTR.styleName.set(Text.fromString("moveLTR"));
		GUIComponentBinding.create(leftBread.input, moveLTR, Move.PROPERTIES.from);
		GUIComponentBinding.create(rightBread.input, moveLTR, Move.PROPERTIES.to);
 
		GUIButtonComponent copyRTL = GUIButtonComponent.create(buttonColumn, " ", new Copy());
		copyRTL.tooltip.set(Text.fromString("Copy right to left"));
		copyRTL.styleName.set(Text.fromString("copyRTL"));
		GUIComponentBinding.create(rightBread.input, copyRTL, Copy.PROPERTIES.from);
		GUIComponentBinding.create(leftBread.input, copyRTL, Copy.PROPERTIES.to);
 
		GUIButtonComponent moveRTL = GUIButtonComponent.create(buttonColumn, " ", new Move());
		moveRTL.tooltip.set(Text.fromString("Move right to left"));
		moveRTL.styleName.set(Text.fromString("moveRTL"));
		GUIComponentBinding.create(rightBread.input, moveRTL, Move.PROPERTIES.from);
		GUIComponentBinding.create(leftBread.input, moveRTL, Move.PROPERTIES.to);
 
		GUIComponentBinding.create(copyLTR.commandExecuted, leftBrowser.refreshContents);
		GUIComponentBinding.create(copyLTR.commandExecuted, rightBrowser.refreshContents);
		GUIComponentBinding.create(moveLTR.commandExecuted, leftBrowser.refreshContents);
		GUIComponentBinding.create(moveLTR.commandExecuted, rightBrowser.refreshContents);
		GUIComponentBinding.create(copyRTL.commandExecuted, leftBrowser.refreshContents);
		GUIComponentBinding.create(copyRTL.commandExecuted, rightBrowser.refreshContents);
		GUIComponentBinding.create(moveRTL.commandExecuted, leftBrowser.refreshContents);
		GUIComponentBinding.create(moveRTL.commandExecuted, rightBrowser.refreshContents);
 
		GUINullFilter leftNullFilter = GUINullFilter.create(fileSystemPanel, leftBread.input);
		GUINullFilter rightNullFilter = GUINullFilter.create(fileSystemPanel, rightBread.input);
		GUIComponentBinding.create(leftNullFilter.yes, leftBufferWithRootFolder.send);
		GUIComponentBinding.create(rightNullFilter.yes, rightBufferWithRootFolder.send);
 
		GUIComponentBinding.create(leftBrowser.input, leftBrowser.refreshContents);
		GUIComponentBinding.create(leftBrowser.input, rightBrowser.refreshContents);
 
		GUIComponentBinding.create(rightBrowser.input, rightBrowser.refreshContents);
		GUIComponentBinding.create(rightBrowser.input, leftBrowser.refreshContents);
	}
 
	private void fileBrowserHeadingFragment(GUIPanelComponent rootPanel, ISlot<Text> folder)
	{
		//heading
    	GUIPanelComponent heading = GUIPanelComponent.createFlow(rootPanel);
    	heading.styleName.set(Text.fromString("fileBrowserHeading"));
 
    	GUIElementComponent selectionCheckbox = GUIElementComponent.createInputCheckbox(heading, "", "", false);
    	selectionCheckbox.tooltip.set(Text.fromString("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.input);
 
    	GUIComponentBinding.create(gbf.yes, selectCmd.click);
    	GUIComponentBinding.create(gbf.no, clearSelectionCmd.click);
 
    	GUIButtonComponent delete = GUIButtonComponent.create(heading, " ", FileSystem.deleteSelectedItems);
    	delete.tooltip.set(Text.fromString("Delete"));
    	delete.styleName.set(Text.fromString("delBtn"));
    	delete.confirmationRequired.set(Boolean.TRUE);
    	delete.confirmationMessage.set(Text.fromString("Delete?"));
    	GUIComponentBinding.create(folder, delete, DeleteSelectedItems.PROPERTIES.from);
 
    	GUIButtonComponent newDocument = GUIButtonComponent.create(heading, " ", FileSystem.createRegularDocument);
    	newDocument.tooltip.set(Text.fromString("Create new file"));
    	newDocument.styleName.set(Text.fromString("multiUploadAddMoreBtn"));
    	GUIComponentBinding.create(folder, newDocument, CreateRegularDocument.PROPERTIES.in);
    	GUIButtonComponent newFolder = GUIButtonComponent.create(heading, " ", FileSystem.createFolder);
    	newFolder.tooltip.set(Text.fromString("Create new folder"));
    	newFolder.styleName.set(Text.fromString("addFolder"));
    	GUIComponentBinding.create(folder, newFolder, CreateFolder.PROPERTIES.in);
    	GUIElementComponent newName = GUIElementComponent.createInput(heading, "", Text.CLASSIFIER);
    	newName.tooltip.set(Text.fromString("Name"));
    	GUIComponentBinding.create(newName.value, newDocument, CreateRegularDocument.PROPERTIES.title);
    	GUIComponentBinding.create(newName.value, newFolder, CreateFolder.PROPERTIES.title);
 
    	GUIComponentBinding.create(delete.commandExecuted, rootPanel.output);
    	GUIComponentBinding.create(newFolder.commandExecuted, rootPanel.output);
    	GUIComponentBinding.create(newDocument.commandExecuted, rootPanel.output);
	}
 
	private GUIContext createContextAndStyles()
	{
		GUIContext context = new GUIContext();
		context.supercontext.set(DefaultContextInit.getRoot());
 
		GUIObjectSetting folder = GUIObjectSetting.create(context, Folder.CLASSIFIER);
		GUITextFeature.createName(folder, "", true);
 
		GUIObjectSetting regularDocument = GUIObjectSetting.create(context, RegularDocument.CLASSIFIER);
		GUITextFeature.createName(regularDocument, "", true);
 
		return context;
	}
 
	public static void missFirstValueLogic(GUIContainerComponent panelForNonVisuals, GUIElementComponent source, GUIComponent destComp, ISlot<Text> destSlot)
	{
		destComp.enabled.set(Boolean.FALSE);
 
		GUIComponentBinding.create(source.value, destSlot); // fisrt
		GUIBufferComponent enableBuffer = GUIBufferComponent.create(panelForNonVisuals, false, Boolean.TRUE);
		GUIComponentBinding.create(enableBuffer.output, destComp.enabled);
		GUIComponentBinding.create(source.value, enableBuffer.send); // second
	}
}
GUIFileSystemSample.java
@Override
    protected GUIContainerComponent getDynamicContents(IElement el)
    {
    	GUIPanelComponent rootPanel = GUIPanelComponent.createFlow(null);
    	rootPanel.styleName.set(Text.fromString("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);
 
    		GUIElementComponent select = GUIElementComponent.createSlotEditor(itemsTable, Folder.PROPERTIES.selected, new GUIListWidget(), new GUICollectionInput(), row, col++);
    		GUIComponentBinding.create(itemBuf.output, GUICollectionInput.get(select).collection);
    		GUIComponentBinding.create(folderBuf.output, GUISlotEditorKind.get(select).element);
 
    		GUIButtonComponent edit = GUIButtonComponent.create(itemsTable, " ", row, col++);
    		edit.styleName.set(Text.fromString("editName"));
    		edit.tooltip.set(Text.fromString("Rename"));
 
    		GUIPanelComponent nameWrap = GUIPanelComponent.createFlow(itemsTable);
    		if (item instanceof Folder)
    			TableLayoutData.setRowColumn(nameWrap, row, col++, 1, 4); //chrome likes colspan 4 
    		else
    			TableLayoutData.setRowColumn(nameWrap, row, col++);
 
    		GUIButtonComponent buttonLink = GUIButtonComponent.createLink(nameWrap, item.title.val().toString());
    		if (item instanceof RegularDocument) 
    			buttonLink.styleName.set(Text.fromString("#fileLink"));
    		else
    			buttonLink.styleName.set(Text.fromString("#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.output, this.output);
        		GUIComponentBinding.create(buttonLink.click, b1.send);
 
        		GUILabelComponent.create(nameWrap, FormattingUtility.formatReal(Real.valueOf(((Folder)item).getSize())) + "MB");
    		}
 
    		GUIElementComponent nameInput = GUIElementComponent.createInput(nameWrap, "", Text.CLASSIFIER);
    		GUIInputKind.get(nameInput).initialValues.set(ElementDescriptor.create(item.title.val()));
    		nameInput.styleName.set(Text.fromString("gwt-TextBox-invisible"));
    		GUICommandComponent rename = GUICommandComponent.create(nameWrap, FileSystem.rename, PerformImmediately.NOTHING);
    		GUIComponentBinding.create(itemBuf.output, rename, RenameDocument.PROPERTIES.document);
    		GUIComponentBinding.create(nameInput.value, rename, RenameDocument.PROPERTIES.newTitle);
 
    		GUIRelayComponent clickRelay = GUIRelayComponent.create(nameWrap);
    		FileSystem.missFirstValueLogic(nameWrap, nameInput, clickRelay, clickRelay.relay);
    		GUIComponentBinding.create(clickRelay.relay, rename.click);
 
    		GUIBufferComponent nullBuffer = GUIBufferComponent.create(rootPanel, false, (IElement)null);
        	GUIComponentBinding.create(nullBuffer.output, this.input); // Fires null on the input pin (which is used here for output direction) to signal others.
        	GUIComponentBinding.create(rename.commandExecuted, nullBuffer.send);
 
    		GUIBufferComponent showEditor = GUIBufferComponent.create(nameWrap, false, Text.fromString("invisible"));
    		GUIBufferComponent showLink = GUIBufferComponent.create(nameWrap, false, Text.fromString("invisible"));
    		GUIComponentBinding.create(edit.click, showEditor.send);
    		GUIComponentBinding.create(rename.commandExecuted, showLink.send);
    		GUIComponentBinding.create(showEditor.output, nameInput.removeStyle);
    		GUIComponentBinding.create(showEditor.output, buttonLink.addStyle);
    		GUIComponentBinding.create(showLink.output, nameInput.addStyle);
    		GUIComponentBinding.create(showLink.output, buttonLink.removeStyle);
 
    		if (item instanceof RegularDocument) {
    			GUIPanelComponent fileUploader = GUIFactory.createFileComponent(itemsTable, RegularDocument.PROPERTIES.file, true, true);
    			GUIComponentBinding.create(itemBuf.output, fileUploader.input);
    			TableLayoutData.setRowColumn(fileUploader, row, col++);
 
    			GUIFactory.getBrowseButton(fileUploader).styleName.set(Text.fromString("#browse" + (isLeft.val().toBoolean() ? "L" : "R") + row));
    			GUIHTMLComponent browse = GUIHTMLComponent.create(itemsTable, "<input type=\"button\" class=\"gwt-Button browseFolder\" onclick=\"triggerBrowse('browse" + (isLeft.val().toBoolean() ? "L" : "R") + row + "');\">", row, col++);
    			browse.tooltip.set(Text.fromString("Browse"));
    		}
 
    		row++;
    	}
 
    	return rootPanel;
    }
GUIBreadCrumbsSample.java
 @Override
    protected GUIContainerComponent getDynamicContents(IElement el)
    {
    	GUIPanelComponent rootPanel = GUIPanelComponent.createFlow(null);
    	rootPanel.styleName.set(Text.fromString("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.output, this.input); // Fires NULL on the input pin (which is used here for output direction).
    		return rootPanel; // If the object does not exist, we just return empty panel.
    	}
 
    	GUILabelComponent thisFolder = new GUILabelComponent(getFolderName(f));
    	thisFolder.styleName.set(Text.fromString("displayInline"));
		rootPanel.children.addFirst(thisFolder);
 
    	Folder current = f.superItem.val();
    	while (current != null)
    	{
    		GUILabelComponent separator = new GUILabelComponent("/");
    		separator.styleName.set(Text.fromString("displayInline"));
    		rootPanel.children.addFirst(separator);
 
    		GUIButtonComponent link = GUIButtonComponent.createLink(null, getFolderName(current));
    		link.styleName.set(Text.fromString("displayInline"));
    		rootPanel.children.addFirst(link);
 
    		GUIBufferComponent buffer = GUIBufferComponent.create(rootPanel, false, current);
    		GUIComponentBinding.create(buffer.output, this.output);
    		GUIComponentBinding.create(link.click, buffer.send);
 
    		current = current.superItem.val();
    	}
 
    	GUIBufferComponent currentFolderBuffer = GUIBufferComponent.create(rootPanel, true, f);
    	GUIComponentBinding.create(currentFolderBuffer.output, this.input); // Fires current folder on the input pin (which is used here for output direction).
 
    	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
    }
extension.js
function triggerBrowse(id) {
	var doc = document.getElementById(id);
	var file = doc.getElementsByTagName("input").item(0);
	file.click();
}
Print/export