This is an old revision of the document!


File System Sample

This is the most complex sample presented here. It is web based Orthodox File Manager application.

Live example

UML Model

Business Logic Code

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