|
From: <fd...@us...> - 2008-01-24 16:29:00
|
Revision: 3723
http://jnode.svn.sourceforge.net/jnode/?rev=3723&view=rev
Author: fduminy
Date: 2008-01-24 08:28:57 -0800 (Thu, 24 Jan 2008)
Log Message:
-----------
jpartition : work in progress for console view
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BasePartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/RemovePartitionCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/PartitionLabelizer.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/ErrorReporter.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -25,13 +25,16 @@
String msg = (t == null) ? String.valueOf(message) : t.getMessage();
displayError(source, msg);
- if(t != null)
+ if(log != null)
{
- log.error(msg, t);
+ if(t != null)
+ {
+ log.error(msg, t);
+ }
+ else
+ {
+ log.error(msg);
+ }
}
- else
- {
- log.error(msg);
- }
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -1,12 +1,14 @@
package org.jnode.apps.jpartition.commands;
+import java.io.IOException;
+
import org.jnode.apps.jpartition.commands.framework.BaseCommand;
import org.jnode.apps.jpartition.commands.framework.CommandException;
+import org.jnode.driver.ApiNotFoundException;
+import org.jnode.driver.DeviceNotFoundException;
import org.jnode.driver.bus.ide.IDEDevice;
-import org.jnode.partitions.command.FdiskCommand;
+import org.jnode.partitions.command.PartitionHelper;
-import sun.java2d.pipe.NullPipe;
-
abstract public class BaseDeviceCommand extends BaseCommand {
protected final IDEDevice device;
@@ -20,6 +22,19 @@
this.device = device;
}
+
+ final protected PartitionHelper createPartitionHelper() throws CommandException
+ {
+ try {
+ return new PartitionHelper(device);
+ } catch (DeviceNotFoundException e) {
+ throw new CommandException(e);
+ } catch (ApiNotFoundException e) {
+ throw new CommandException(e);
+ } catch (IOException e) {
+ throw new CommandException(e);
+ }
+ }
abstract protected void doExecute() throws CommandException;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BasePartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BasePartitionCommand.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BasePartitionCommand.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -4,7 +4,7 @@
import org.jnode.driver.bus.ide.IDEDevice;
abstract public class BasePartitionCommand extends BaseDeviceCommand {
- private final int partitionNumber;
+ protected final int partitionNumber;
public BasePartitionCommand(String name, IDEDevice device, int partitionNumber)
{
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/CreatePartitionCommand.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -1,17 +1,34 @@
package org.jnode.apps.jpartition.commands;
+import java.io.IOException;
+
import org.jnode.apps.jpartition.commands.framework.CommandException;
import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.partitions.command.PartitionHelper;
public class CreatePartitionCommand extends BasePartitionCommand {
-
- public CreatePartitionCommand(IDEDevice device, int partitionNumber) {
+ final private long start;
+ final private long size;
+
+ public CreatePartitionCommand(IDEDevice device, int partitionNumber, long start, long size) {
super("create partition", device, partitionNumber);
+ this.start = start;
+ this.size = size;
}
@Override
final protected void doExecute() throws CommandException {
- // TODO Auto-generated method stub
-
+// PartitionHelper helper = createPartitionHelper();
+// try {
+//
+// helper.write();
+// } catch (IOException e) {
+// throw new CommandException(e);
+// }
}
+
+ @Override
+ public String toString() {
+ return "create partition [" + start + ", " + (start+size-1) + "] on device " + device.getId();
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/FormatPartitionCommand.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -2,16 +2,24 @@
import org.jnode.apps.jpartition.commands.framework.CommandException;
import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.fs.FileSystem;
+import org.jnode.fs.Formatter;
public class FormatPartitionCommand extends BasePartitionCommand {
-
- public FormatPartitionCommand(IDEDevice device, int partitionNumber) {
+ private final Formatter<? extends FileSystem> formatter;
+
+ public FormatPartitionCommand(IDEDevice device, int partitionNumber, Formatter<? extends FileSystem> formatter) {
super("format partition", device, partitionNumber);
+ this.formatter = formatter;
}
@Override
final protected void doExecute() throws CommandException {
// TODO Auto-generated method stub
-
}
+
+ @Override
+ public String toString() {
+ return "format partition " + partitionNumber + " on device " + device.getId() + " with " + formatter.getFileSystemType().getName();
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/RemovePartitionCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/RemovePartitionCommand.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/RemovePartitionCommand.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -12,6 +12,11 @@
@Override
final protected void doExecute() throws CommandException {
// TODO Auto-generated method stub
-
}
+
+ @Override
+ public String toString() {
+ return "remove partition " + partitionNumber + " on device" + device.getId();
+ }
+
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -23,8 +23,9 @@
this.errorReporter = errorReporter;
}
- public boolean hasChanges() {
- return !commands.isEmpty();
+ public List<Command> getPendingCommands()
+ {
+ return new ArrayList<Command>(commands);
}
public synchronized void process()
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -8,15 +8,14 @@
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.Context;
import org.jnode.apps.jpartition.ErrorReporter;
+import org.jnode.apps.jpartition.commands.framework.Command;
import org.jnode.apps.jpartition.consoleview.components.Component;
-import org.jnode.apps.jpartition.consoleview.components.Labelizer;
import org.jnode.apps.jpartition.consoleview.components.NumberField;
import org.jnode.apps.jpartition.consoleview.components.Options;
import org.jnode.apps.jpartition.consoleview.components.YesNo;
import org.jnode.apps.jpartition.model.Device;
import org.jnode.apps.jpartition.model.Partition;
import org.jnode.apps.jpartition.model.UserFacade;
-import org.jnode.util.NumberUtils;
class ConsoleView extends Component {
private static final Logger log = Logger.getLogger(ConsoleView.class);
@@ -36,8 +35,24 @@
}
println();
- print("selectedPartition="+PartitionLabelizer.INSTANCE.getLabel(selectedPartition));
- print(" on device "+DeviceLabelizer.INSTANCE.getLabel(UserFacade.getInstance().getSelectedDevice()));
+
+ if(selectedPartition == null)
+ {
+ print("selectedPartition=none");
+ }
+ else
+ {
+ print("selectedPartition="+PartitionLabelizer.INSTANCE.getLabel(selectedPartition));
+ }
+
+ if(UserFacade.getInstance().getSelectedDevice() == null)
+ {
+ println(" on no device");
+ }
+ else
+ {
+ println(" on device "+DeviceLabelizer.INSTANCE.getLabel(UserFacade.getInstance().getSelectedDevice()));
+ }
}
private void start() throws Exception
@@ -45,10 +60,18 @@
selectDevice();
selectPartition();
- if(UserFacade.getInstance().hasChanges())
+ List<Command> pendingCommands = UserFacade.getInstance().getPendingCommands();
+ if(!pendingCommands.isEmpty())
{
YesNo yesNo = new YesNo(context);
- boolean apply = yesNo.show("There is pending modifications. Would you like to apply them ?");
+ println();
+ println("The following modifications are pending :");
+ for(Command cmd : pendingCommands)
+ {
+ println("\t"+cmd);
+ }
+
+ boolean apply = yesNo.show("Would you like to apply them ?");
if(apply)
{
UserFacade.getInstance().applyChanges();
@@ -69,56 +92,92 @@
private void selectPartition() throws Exception
{
- selectedPartition = null;
- if(install)
+ List<Partition> partitions = UserFacade.getInstance().getPartitions();
+ if((partitions.size() == 1) && !partitions.get(0).isUsed())
{
- selectedPartition = selectPartitionForInstall();
+ YesNo yesNo = new YesNo(context);
+ boolean create = yesNo.show("There is no partition. Would you like to create one ?");
+ if(create)
+ {
+ selectedPartition = createPartition(partitions.get(0));
+ }
}
if(selectedPartition == null)
{
- selectedPartition = selectPartitionForDevice();
+ partitions = UserFacade.getInstance().getPartitions();
+
+ Options partitionsOpt = new Options(context);
+ int choice = (int) partitionsOpt.show("Select a partition", partitions, PartitionLabelizer.INSTANCE);
+
+ selectedPartition = partitions.get(choice - 1);
}
+
+ if(selectedPartition != null)
+ {
+ if(install)
+ {
+ formatPartition(selectedPartition);
+ }
+ else
+ {
+ modifyPartition(selectedPartition);
+ }
+ }
}
- private Partition selectPartitionForDevice() throws Exception {
- List<Partition> partitions = UserFacade.getInstance().getPartitions();
+ private Partition createPartition(Partition freePart) throws Exception {
+ long size = freePart.getSize();
+ NumberField sizeField = new NumberField(context);
+ size = sizeField.show("Size of the new partition ", size, 1, size);
- Options partitionsOpt = new Options(context);
- int choice = (int) partitionsOpt.show("Select a partition", partitions, PartitionLabelizer.INSTANCE);
-
- return partitions.get(choice - 1);
+ return UserFacade.getInstance().createPartition(freePart.getStart(), size);
}
-
- private Partition selectPartitionForInstall() throws Exception
- {
- List<Partition> partitions = UserFacade.getInstance().getPartitions();
- Partition partition = null;
- if((partitions.size() == 1) && !partitions.get(0).isUsed())
+
+ private void modifyPartition(Partition partition) throws Exception {
+ if(partition.isUsed())
{
- YesNo yesNo = new YesNo(context);
- boolean create = yesNo.show("There is no partition. Would you like to create one ?");
- if(create)
+ final String[] operations = new String[]{"format partition", "remove partition"};
+
+ Options partitionsOpt = new Options(context);
+ int choice = (int) partitionsOpt.show("Select an operation", operations);
+ switch(choice)
{
- partition = createPartition(partitions.get(0));
+ case 0: formatPartition(partition); break;
+ case 1: removePartition(partition); break;
}
}
-
- return partition;
+ else
+ {
+ final String[] operations = new String[]{"add partition"};
+
+ Options partitionsOpt = new Options(context);
+ int choice = (int) partitionsOpt.show("Select an operation", operations);
+ switch(choice)
+ {
+ case 0: createPartition(partition); break;
+ }
+ }
}
- private Partition createPartition(Partition freePart) throws Exception {
- long size = freePart.getSize();
- String space = NumberUtils.toBinaryByte(size);
+ private void removePartition(Partition partition) throws Exception {
YesNo yesNo = new YesNo(context);
- boolean allSpace = yesNo.show("Would you like to use all the free space ("+space+") ?");
+ boolean remove = yesNo.show("Would like you to remove the partition ?");
- if(!allSpace)
+ if(remove)
{
- NumberField sizeField = new NumberField(context);
- size = sizeField.show("Size of the new partition ");
+ UserFacade.getInstance().removePartition(partition.getStart() + 1);
}
+ }
+
+ private void formatPartition(Partition partition) throws Exception {
+ String[] formatters = UserFacade.getInstance().getFormatters();
+ Options partitionsOpt = new Options(context);
+ int choice = (int) partitionsOpt.show("Select a filesystem", formatters);
+ String formatter = formatters[choice];
- return UserFacade.getInstance().createPartition(freePart.getStart(), size);
- }
+ UserFacade.getInstance().selectFormatter(formatter);
+
+ UserFacade.getInstance().formatPartition(partition.getStart() + 1);
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/DeviceLabelizer.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -10,7 +10,13 @@
static final DeviceLabelizer INSTANCE = new DeviceLabelizer();
public String getLabel(Device device) {
+ if(device == null)
+ {
+ throw new NullPointerException("device is null");
+ }
+
StringBuilder sb = new StringBuilder();
+
sb.append(device.getName());
sb.append(" (").append(NumberUtils.toBinaryByte(device.getSize())).append(')');
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/PartitionLabelizer.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/PartitionLabelizer.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/PartitionLabelizer.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -9,7 +9,13 @@
static final PartitionLabelizer INSTANCE = new PartitionLabelizer();
public String getLabel(Partition partition) {
+ if(partition == null)
+ {
+ throw new NullPointerException("partition is null");
+ }
+
StringBuilder sb = new StringBuilder();
+
sb.append('[').append(partition.getStart()).append(',').append(partition.getEnd()).append(']');
sb.append(" (").append(NumberUtils.toBinaryByte(partition.getSize())).append(") ");
String format = partition.isUsed() ? partition.getFormat() : "unused";
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Component.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -2,12 +2,14 @@
import java.io.IOException;
import java.util.Collection;
-import java.util.List;
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.Context;
public class Component {
+ protected static final String TRUE_LONG_STRING = "yes";
+ protected static final String FALSE_LONG_STRING = "no";
+
protected final Context context;
protected Component(Context context) {
@@ -30,40 +32,115 @@
return context.getIn().read();
}
- final protected boolean readBoolean(boolean defaultValue) throws IOException {
+ final protected String getValueStr(boolean value)
+ {
+ return value ? TRUE_LONG_STRING : FALSE_LONG_STRING;
+ }
+
+ final protected Boolean readBoolean(Boolean defaultValue) throws IOException {
String line = context.getIn().readLine();
- boolean value = defaultValue;
- try
+ Boolean value;
+ if((line == null) || (line.trim().length() == 0))
{
- if(defaultValue)
+ value = defaultValue;
+ if(value != null)
{
- value = ("no".equals(line)) ? false : true;
+ print(String.valueOf(defaultValue));
}
- else
- {
- value = ("yes".equals(line)) ? true : false;
- }
}
- catch(Exception e)
+ else
{
- value = defaultValue;
+ try
+ {
+ line = line.trim();
+ if(defaultValue == null)
+ {
+ if(TRUE_LONG_STRING.equals(line))
+ {
+ value = true;
+ }
+ else if(FALSE_LONG_STRING.equals(line))
+ {
+ value = false;
+ }
+ else
+ {
+ value = null;
+ }
+ }
+ else if(defaultValue)
+ {
+ value = getValueStr(defaultValue).equals(line) ? false : true;
+ }
+ else
+ {
+ value = getValueStr(defaultValue).equals(line) ? true : false;
+ }
+ }
+ catch(Exception e)
+ {
+ value = defaultValue;
+ }
}
return value;
}
- final protected long readInt(long defaultValue) throws IOException {
+ final protected Long readInt() throws IOException {
+ return readInt(null, Long.MIN_VALUE, Long.MAX_VALUE);
+ }
+
+ final protected Long readInt(Long defaultValue) throws IOException {
+ return readInt(defaultValue, Long.MIN_VALUE, Long.MAX_VALUE);
+ }
+
+ final protected Long readInt(Long defaultValue, long min, long max) throws IOException {
+ checkInBounds("min", min, "max", max, "defaultValue", defaultValue);
+
String line = context.getIn().readLine();
- long value = defaultValue;
- try
+ Long value;
+ if((line == null) || (line.trim().length() == 0))
{
- value = Long.valueOf(line);
+ value = defaultValue;
+ if(value != null)
+ {
+ print(String.valueOf(defaultValue));
+ }
}
- catch(NumberFormatException e)
+ else
{
- value = defaultValue;
+ line = line.trim();
+ try
+ {
+ value = Long.decode(line);
+ }
+ catch(NumberFormatException e)
+ {
+ reportError("invalid value");
+ value = null;
+ }
+
+ if(value != null)
+ {
+ try {
+ checkInBounds("min", min, "max",
+ max, "value", value);
+ } catch (IllegalArgumentException e) {
+ if(min != max)
+ {
+ reportError("value must be between "+min+" and "+max);
+ }
+ else
+ {
+ reportError("value must be "+min);
+ }
+
+ value = null;
+ }
+ }
}
+
return value;
}
@@ -76,7 +153,12 @@
{
context.getErrorReporter().reportError(log, source, message);
}
-
+
+ final protected void reportError(String message)
+ {
+ context.getErrorReporter().reportError(null, null, message);
+ }
+
final protected void checkNonNull(String paramName, Object param)
{
if(param == null)
@@ -94,5 +176,23 @@
throw new IllegalArgumentException("parameter "+paramName+" can't be empty");
}
}
-
+
+ final protected void checkInBounds(String minName, long min, String maxName,
+ long max, String valueName, Long value) {
+ checkMinMax(minName, min, maxName, max);
+
+ if(value != null)
+ {
+ checkMinMax(minName, min, valueName, value);
+ checkMinMax(valueName, value, maxName, max);
+ }
+ }
+
+ final protected void checkMinMax(String minName, long min, String maxName, long max) {
+ if(min > max)
+ {
+ throw new IllegalArgumentException("parameter "+minName+" must be > parameter "+maxName);
+ }
+ }
+
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/NumberField.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -15,19 +15,27 @@
}
public long show(String question) throws IOException {
- return show(question, Long.MIN_VALUE, Long.MAX_VALUE);
+ return show(question, Long.MIN_VALUE, Long.MIN_VALUE, Long.MAX_VALUE);
}
-
- public long show(String question, long min, long max) throws IOException {
+
+ public long show(String question, Long defaultValue) throws IOException {
+ return show(question, defaultValue, Long.MIN_VALUE, Long.MAX_VALUE);
+ }
+
+ public Long show(String question, Long defaultValue, long min, long max) throws IOException {
checkNonNull("question", question);
+ checkInBounds("min", min, "max", max, "defaultValue", defaultValue);
print(question);
+ if(defaultValue != null)
+ {
+ print(" ["+defaultValue+"]");
+ }
- long value = readInt(-1);
- while((value < min) || (value > max))
+ Long value = readInt(defaultValue, min, max);
+ while((value == null) || (value < min) || (value > max))
{
- reportError(log, null, "invalid choice");
- value = readInt(-1);
+ value = readInt(defaultValue);
}
return value;
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/Options.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -42,6 +42,6 @@
}
NumberField choice = new NumberField(context);
- return choice.show("Choice : ", 1, options.size());
+ return choice.show("Choice : ", null, 1, options.size());
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/components/YesNo.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -15,11 +15,33 @@
}
public boolean show(String question) throws IOException {
+ return show(question, null);
+ }
+
+ public boolean show(String question, Boolean defaultValue) throws IOException {
checkNonNull("question", question);
println();
print(question);
- return readBoolean(false);
+ if(defaultValue != null)
+ {
+ String defaultValueStr = getValueStr(defaultValue);
+ print("["+defaultValueStr+"]");
+ }
+
+ Boolean value;
+ do
+ {
+ value = readBoolean(defaultValue);
+
+ if(value == null)
+ {
+ reportError("invalid value");
+ }
+ }
+ while(value == null);
+
+ return value;
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/Device.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -1,13 +1,10 @@
package org.jnode.apps.jpartition.model;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import org.jnode.driver.ApiNotFoundException;
-import org.jnode.driver.bus.ide.IDEDeviceAPI;
import org.jnode.fs.FileSystem;
import org.jnode.fs.Formatter;
@@ -19,18 +16,14 @@
final private org.jnode.driver.Device device;
Device(String name, long size) {
- this(name, size, null);
+ this(name, size, null, new ArrayList<Partition>());
+ partitions.add(new Partition(0L, size, false));
}
- Device(org.jnode.driver.Device dev) throws ApiNotFoundException, IOException {
- this(dev.getId(), dev.getAPI(IDEDeviceAPI.class).getLength(), dev);
- }
-
- private Device(String name, long size, org.jnode.driver.Device device) {
+ Device(String name, long size, org.jnode.driver.Device device, List<Partition> partitions) {
this.name = name;
this.size = size;
- partitions = new ArrayList<Partition>();
- partitions.add(new Partition(0L, size, false));
+ this.partitions = partitions;
this.device = device;
}
@@ -106,8 +99,7 @@
partitions.add(index, newPart);
// after the new partition
- oldPart.setSize(oldPart.getSize() - size);
- oldPart.setStart(newPart.getEnd() + 1);
+ oldPart.setBounds(newPart.getEnd() + 1, oldPart.getSize() - size);
partitions.set(index + 1, oldPart);
}
else if(end == oldPart.getEnd())
@@ -147,6 +139,7 @@
Partition part = partitions.get(index);
long start = part.getStart();
long size = part.getSize();
+
if(index > 0)
{
Partition partBefore = partitions.get(index - 1);
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -90,29 +90,77 @@
private Device createDevice(org.jnode.driver.Device dev)
{
Device device = null;
- try {
- if(dev.implementsAPI(IDEDeviceAPI.class))
+ List<IBMPartitionTableEntry> partitions = getPartitions(dev);
+ if(partitions != null) // null if not supported
+ {
+ List<Partition> devPartitions = new ArrayList<Partition>(partitions.size());
+ Partition prevPartition = null;
+
+ for(IBMPartitionTableEntry e : partitions)
{
- Device tmpDevice = new Device(dev);
-
- if(dev.implementsAPI(PartitionableBlockDeviceAPI.class))
+ IBMPartitionTableEntry pte = (IBMPartitionTableEntry) e;
+ long start = pte.getStartLba();
+ long size = pte.getNrSectors() * IDEConstants.SECTOR_SIZE;
+
+ if(pte.isEmpty())
{
- PartitionableBlockDeviceAPI<?> api = dev.getAPI(PartitionableBlockDeviceAPI.class);
- for(PartitionTableEntry e : api.getPartitionTable())
+ if((prevPartition != null) && !prevPartition.isUsed())
{
- if(e instanceof IBMPartitionTableEntry)
- {
- IBMPartitionTableEntry pte = (IBMPartitionTableEntry) e;
- if(!pte.isEmpty())
- {
- long size = pte.getNrSectors() * IDEConstants.SECTOR_SIZE;
- tmpDevice.addPartition(pte.getStartLba(), size);
- }
+ // current and previous partitions are empty
+ prevPartition.mergeWithNextPartition(size);
+ }
+ else
+ {
+ // current partition is empty but not the previous one
+ devPartitions.add(new Partition(start, size, false));
+ }
+ }
+ else
+ {
+ // current partition is not empty
+ devPartitions.add(new Partition(start, size, true));
+ }
+ }
+
+ try {
+ long devSize = dev.getAPI(IDEDeviceAPI.class).getLength();
+ device = new Device(dev.getId(), devSize, dev, devPartitions);
+ } catch (ApiNotFoundException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+
+ return device;
+ }
+
+ private List<IBMPartitionTableEntry> getPartitions(org.jnode.driver.Device dev)
+ {
+ boolean supported = false;
+ List<IBMPartitionTableEntry> partitions = new ArrayList<IBMPartitionTableEntry>();
+
+ try {
+ if (dev.implementsAPI(IDEDeviceAPI.class)) {
+ if (dev.implementsAPI(PartitionableBlockDeviceAPI.class)) {
+ PartitionableBlockDeviceAPI<?> api = dev
+ .getAPI(PartitionableBlockDeviceAPI.class);
+ boolean supportedPartitions = true;
+
+ for (PartitionTableEntry e : api.getPartitionTable()) {
+ if (!(e instanceof IBMPartitionTableEntry)) {
+ // non IBM partition tables are not handled for now
+ supportedPartitions = false;
+ break;
}
+
+ partitions.add((IBMPartitionTableEntry) e);
}
+
+ supported = supportedPartitions;
}
-
- device = tmpDevice;
}
} catch (ApiNotFoundException e) {
// TODO Auto-generated catch block
@@ -121,6 +169,7 @@
// TODO Auto-generated catch block
e.printStackTrace();
}
- return device;
+
+ return supported ? partitions : null;
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -1,5 +1,8 @@
package org.jnode.apps.jpartition.model;
+import java.util.ArrayList;
+import java.util.List;
+
import org.jnode.fs.FileSystem;
import org.jnode.fs.Formatter;
@@ -62,13 +65,21 @@
}
return format;
}
+
+ final void setSize(long size) {
+ this.size = size;
+ }
+ void mergeWithNextPartition(long nextPartitionSize) {
+ this.size += nextPartitionSize;
+ }
+
final boolean contains(long offset) {
long start = getStart();
return (offset >= start) && ((offset - start) < size);
}
- final void moveStart(long delta) {
+// final void moveStart(long delta) {
// if((delta < 0) && (previous != null))
// {
// previous.resize(delta);
@@ -80,13 +91,10 @@
// previous.resize(delta);
// }
// }
- }
+// }
- final void setStart(long start) {
+ final void setBounds(long start, long size) {
this.start = start;
- }
-
- final void setSize(long size) {
this.size = size;
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java 2008-01-21 18:44:48 UTC (rev 3722)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java 2008-01-24 16:28:57 UTC (rev 3723)
@@ -15,6 +15,7 @@
import org.jnode.apps.jpartition.commands.CreatePartitionCommand;
import org.jnode.apps.jpartition.commands.FormatPartitionCommand;
import org.jnode.apps.jpartition.commands.RemovePartitionCommand;
+import org.jnode.apps.jpartition.commands.framework.Command;
import org.jnode.apps.jpartition.commands.framework.CommandProcessor;
import org.jnode.apps.jpartition.commands.framework.CommandProcessorListener;
import org.jnode.driver.ApiNotFoundException;
@@ -137,7 +138,7 @@
checkSelectedDevice();
Partition newPart = selectedDevice.addPartition(start, size);
- cmdProcessor.addCommand(new CreatePartitionCommand((IDEDevice) selectedDevice.getDevice(), 0)); //TODO set parameters
+ cmdProcessor.addCommand(new CreatePartitionCommand((IDEDevice) selectedDevice.getDevice(), start, size));
return newPart;
}
@@ -153,8 +154,10 @@
checkSelectedDevice();
checkSelectedFormatter();
- selectedDevice.formatPartition(offset, selectedFormatter.clone());
- cmdProcessor.addCommand(new FormatPartitionCommand((IDEDevice) selectedDevice.getDevice(), 0)); //TODO set parameters
+ Formatter<? extends FileSystem> formatter = selectedFormatter.clone();
+ selectedDevice.formatPartition(offset, formatter);
+ Command cmd = new FormatPartitionCommand((IDEDevice) selectedDevice.getDevice(), 0, formatter); //TODO set parameters
+ cmdProcessor.addCommand(cmd);
}
public void resizePartition(long offset, long size) throws Exception {
@@ -170,8 +173,9 @@
refreshDevicesFromOS();
}
- public boolean hasChanges() {
- return cmdProcessor.hasChanges();
+ public List<Command> getPendingCommands()
+ {
+ return cmdProcessor.getPendingCommands();
}
private void refreshDevicesFromOS()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|