package cane.brothers.e4.commander.pathTable.data;

import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;

public class PathColumnPropertyAccessor implements IColumnPropertyAccessor<PathFixture> {


	/** use list instead of set because indexes */
	private List<String> propertyNames;
	
	private Path parentPath;
	
	private static final String parentPathStr = "../".intern();
	

	private static final String pathDirSizeStr = "<DIR>".intern();
	
	/**
	 * Constructor
	 * 
	 * @param propertyToLabels
	 */
	public PathColumnPropertyAccessor(Map<String, String> propertyToLabels, Path rootPath) {
		this.propertyNames = new ArrayList<String>(propertyToLabels.keySet());
		this.parentPath = rootPath.getParent();
	}
	
	@Override
	public Object getDataValue(PathFixture rowObject, int columnIndex) {
		switch (columnIndex) {
		case 0:
			if(parentPath.equals(rowObject.getPath())) {
				return parentPathStr;
			} else {
				return rowObject.getName();
			}
		case 1:
			if(Files.isDirectory(rowObject.getPath(), LinkOption.NOFOLLOW_LINKS)) {
				return pathDirSizeStr;
			} else {
				return rowObject.getSize();
			}
		case 2:
			return rowObject.getAttributes();
		}
		return null;
	}

	@Override
	public void setDataValue(PathFixture rowObject, int columnIndex,
			Object newValue) {
		new UnsupportedOperationException("none");
	}

	@Override
	public int getColumnCount() {
		return 3;
	}

	@Override
	public String getColumnProperty(int columnIndex) {
		return propertyNames.get(columnIndex);
	}

	@Override
	public int getColumnIndex(String propertyName) {
		return propertyNames.indexOf(propertyName);
	}

}

@@ -292,16 +292,74 @@
 sor;%0D%0A%0D%0A
+import cane.brothers.e4.commander.pathTable.IRootPath;%0D%0A%0D%0A
 public c
@@ -437,16 +437,27 @@
 Fixture%3E
+, IRootPath
  %7B%0D%0A%0D%0A%0D%0A
@@ -1627,16 +1627,30 @@
 %22none%22);
+ //$NON-NLS-1$
 %0D%0A%09%7D%0D%0A%0D%0A
@@ -1941,11 +1941,144 @@
 %0D%0A%09%7D%0D%0A%0D%0A
+%09@Override%0D%0A%09public void setRootPath(Path newPath) %7B%0D%0A%09%09if(newPath != null) %7B%0D%0A%09%09%09this.parentPath = newPath.getParent();%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A
 %7D%0D%0A

implement initial navigation Task-Url: http://github.com/webcane/EclipseCommander/issues/issue/16 set root path