|
From: <fd...@us...> - 2007-04-15 19:46:32
|
Revision: 3162
http://jnode.svn.sourceforge.net/jnode/?rev=3162&view=rev
Author: fduminy
Date: 2007-04-15 12:46:31 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/jpartition/model/AbstractModel.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/CommandProcessorModel.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceModel.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/FileDeviceModel.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/PartitionModel.java
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/AbstractModel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/AbstractModel.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/AbstractModel.java 2007-04-15 19:46:31 UTC (rev 3162)
@@ -0,0 +1,32 @@
+package org.jnode.apps.jpartition.model;
+
+import it.battlehorse.stamps.Model;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
+abstract public class AbstractModel implements Model
+{
+ final protected PropertyChangeSupport propSupport;
+
+ /**
+ * Creates a new instance of the class
+ */
+ public AbstractModel() {
+ propSupport = new PropertyChangeSupport(this);
+ }
+
+ //
+ // This method will be invoked by the dispatcher on model registration
+ //
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ propSupport.addPropertyChangeListener(listener);
+ }
+
+ //
+ // This method will be invoked by the dispatcher on model deregistration
+ //
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ propSupport.removePropertyChangeListener(listener);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/CommandProcessorModel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/CommandProcessorModel.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/CommandProcessorModel.java 2007-04-15 19:46:31 UTC (rev 3162)
@@ -0,0 +1,53 @@
+package org.jnode.apps.jpartition.model;
+
+import org.apache.log4j.Logger;
+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.apps.jpartition.swingview.ErrorReporter;
+
+public class CommandProcessorModel extends AbstractModel
+ implements CommandProcessorListener
+{
+ private static final Logger log = Logger.getLogger(CommandProcessorModel.class);
+
+ private final CommandProcessor commandProcessor;
+
+ public CommandProcessorModel()
+ {
+ commandProcessor = new CommandProcessor();
+ commandProcessor.addListener(this);
+ }
+
+ public void processCommands()
+ {
+ try
+ {
+ commandProcessor.process();
+ }
+ catch(Throwable t)
+ {
+ ErrorReporter.reportError(log, this, t);
+ }
+ finally
+ {
+ propSupport.firePropertyChange("commandsProcessed", null, this);
+ }
+ }
+
+ public void commandAdded(CommandProcessor processor, Command command) {
+ propSupport.firePropertyChange("commandAdded", null, command);
+ }
+
+ public void commandStarted(CommandProcessor processor, Command command) {
+ propSupport.firePropertyChange("commandStarted", command, command);
+ }
+
+ public void commandFinished(CommandProcessor processor, Command command) {
+ propSupport.firePropertyChange("commandFinished", command, command);
+ }
+
+ public void commandRemoved(CommandProcessor processor, Command command) {
+ propSupport.firePropertyChange("commandRemoved", command, command);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceModel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceModel.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceModel.java 2007-04-15 19:46:31 UTC (rev 3162)
@@ -0,0 +1,106 @@
+package org.jnode.apps.jpartition.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.NameNotFoundException;
+
+import org.apache.log4j.Logger;
+import org.jnode.driver.Device;
+import org.jnode.driver.DeviceListener;
+import org.jnode.driver.DeviceUtils;
+import org.jnode.driver.block.PartitionableBlockDeviceAPI;
+import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.partitions.PartitionTableEntry;
+import org.jnode.partitions.command.PartitionHelper;
+import org.jnode.partitions.ibm.IBMPartitionTableEntry;
+
+public class DeviceModel extends AbstractModel
+ implements DeviceListener
+{
+ private static final Logger log = Logger.getLogger(DeviceModel.class);
+
+ private final List<PartitionModel> partitions = new ArrayList<PartitionModel>();
+
+ public DeviceModel()
+ {
+ try {
+ DeviceUtils.getDeviceManager().addListener(this);
+ } catch (NameNotFoundException e) {
+ log.error(e);
+ }
+ }
+
+ public void setDevice(Object device) {
+ propSupport.firePropertyChange("deviceSelected", null, device);
+ try {
+ addPartitions((IDEDevice) device);
+ } catch (Exception e) {
+ log.error(e);
+ }
+ }
+
+ protected void addPartitions(IDEDevice device) throws Exception
+ {
+ PartitionHelper helper = new PartitionHelper(device);
+
+ log.debug("addPartitions");
+ if(device.implementsAPI(PartitionableBlockDeviceAPI.class))
+ {
+ log.debug("implementsAPI");
+ partitions.clear();
+ PartitionableBlockDeviceAPI<?> api = device.getAPI(PartitionableBlockDeviceAPI.class);
+ for(PartitionTableEntry e : api.getPartitionTable())
+ {
+ log.debug("PartitionTableEntry");
+ addPartition(e);
+ }
+ }
+ }
+
+ public void addPartition(PartitionTableEntry e)
+ {
+ if(e instanceof IBMPartitionTableEntry)
+ {
+ IBMPartitionTableEntry pte = (IBMPartitionTableEntry) e;
+ addPartition(new PartitionModel(pte));
+ }
+ else
+ {
+ log.warn("found non-IBMPartitionTableEntry");
+ }
+ }
+
+ public void addPartition(PartitionModel partition)
+ {
+ propSupport.fireIndexedPropertyChange("partitionAdded", partitions.size(), null, partition);
+ partitions.add(partition);
+ }
+
+ public void removePartition(PartitionModel partition)
+ {
+ int index = partitions.indexOf(partition);
+ propSupport.fireIndexedPropertyChange("partitionRemoved", index, null, partition);
+ partitions.remove(partition);
+ }
+
+ //
+ // DeviceListener interface
+ //
+ public void deviceStarted(Device device) {
+ if(device instanceof IDEDevice)
+ {
+ log.debug("deviceStarted...");
+ propSupport.firePropertyChange("deviceStarted", null, device);
+ }
+ }
+
+ public void deviceStop(Device device) {
+ log.debug("deviceStop...");
+ propSupport.firePropertyChange("deviceStop", null, device);
+ }
+
+ //
+ //
+ //
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/FileDeviceModel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/FileDeviceModel.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/FileDeviceModel.java 2007-04-15 19:46:31 UTC (rev 3162)
@@ -0,0 +1,36 @@
+package org.jnode.apps.jpartition.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jnode.apps.jpartition.utils.device.DeviceUtils;
+import org.jnode.driver.bus.ide.IDEDevice;
+
+public class FileDeviceModel extends AbstractModel {
+ private List<IDEDevice> fileDevices = new ArrayList<IDEDevice>();
+
+ public void addFakeDisk() {
+ addDevice(DeviceUtils.createFakeDevice());
+ }
+
+ public void addVMWareDisk() {
+ addDevice(DeviceUtils.createVMWareDevice());
+ }
+
+ public void addDevice(IDEDevice device)
+ {
+ if(device != null)
+ {
+ fileDevices.add(device);
+ propSupport.firePropertyChange("deviceAdded", null, device);
+ }
+ }
+
+ public void removeFileDevice(Object device) {
+ if(device != null)
+ {
+ fileDevices.remove(device);
+ propSupport.firePropertyChange("deviceRemoved", null, device);
+ }
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/PartitionModel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/PartitionModel.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/PartitionModel.java 2007-04-15 19:46:31 UTC (rev 3162)
@@ -0,0 +1,110 @@
+package org.jnode.apps.jpartition.model;
+
+import it.battlehorse.stamps.annotations.Refreshable;
+
+import org.jnode.partitions.ibm.IBMPartitionTableEntry;
+import org.jnode.partitions.ibm.IBMPartitionTypes;
+
+
+public class PartitionModel extends AbstractModel
+{
+ private boolean empty;
+ private boolean bootable;
+ private IBMPartitionTypes type;
+ private long start;
+ private long size;
+
+ private IBMPartitionTableEntry pte;
+
+ public PartitionModel(IBMPartitionTableEntry pte)
+ {
+ this.pte = pte;
+
+ //TODO remove these fake values
+ this.empty = false;
+ this.bootable = true;
+ this.type = IBMPartitionTypes.PARTTYPE_WIN95_FAT32;
+ this.start = 0;
+ this.size = 1024;
+ }
+
+ @Refreshable
+ public boolean isEmpty() {
+ return empty;
+ }
+ public void setEmpty(boolean empty) {
+ propSupport.firePropertyChange("empty", this.empty, empty);
+ this.empty = empty;
+ }
+
+ @Refreshable
+ public boolean isBootable() {
+ return bootable;
+ }
+ public void setBootable(boolean bootable) {
+ propSupport.firePropertyChange("bootable", this.bootable, bootable);
+ this.bootable = bootable;
+ }
+
+ @Refreshable
+ public IBMPartitionTypes getType() {
+ return type;
+ }
+ public void setType(IBMPartitionTypes type) {
+ propSupport.firePropertyChange("type", this.type, type);
+ this.type = type;
+ }
+
+ @Refreshable
+ public long getStart() {
+ return start;
+ }
+ public void setStart(long start) {
+ propSupport.firePropertyChange("start", this.start, start);
+ this.start = start;
+ }
+
+ @Refreshable
+ public long getSize() {
+ return size;
+ }
+ public void setSize(long size) {
+ propSupport.firePropertyChange("size", this.size, size);
+ this.size = size;
+ }
+
+
+/*
+ private final IBMPartitionTableEntry pte;
+
+ public PartitionModel(IBMPartitionTableEntry pte)
+ {
+ this.pte = pte;
+ }
+
+ public boolean isEmpty()
+ {
+ return pte.isEmpty();
+ }
+
+ public boolean isBootable()
+ {
+ return pte.getBootIndicator();
+ }
+
+ public IBMPartitionTypes getType()
+ {
+ return pte.getSystemIndicator();
+ }
+
+ public long getStart()
+ {
+ return pte.getStartLba();
+ }
+
+ public long getSize()
+ {
+ return pte.getNrSectors() * IDEConstants.SECTOR_SIZE;
+ }
+*/
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 21:05:18
|
Revision: 3163
http://jnode.svn.sourceforge.net/jnode/?rev=3163&view=rev
Author: fduminy
Date: 2007-04-15 14:05:11 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Removed Paths:
-------------
trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitions.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitionsList.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitions.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitions.java 2007-04-15 19:46:31 UTC (rev 3162)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitions.java 2007-04-15 21:05:11 UTC (rev 3163)
@@ -1,73 +0,0 @@
-package org.jnode.apps.jpartition.model;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.jnode.driver.ApiNotFoundException;
-import org.jnode.driver.Device;
-import org.jnode.driver.block.PartitionableBlockDeviceAPI;
-import org.jnode.partitions.PartitionTableEntry;
-import org.jnode.partitions.ibm.IBMPartitionTableEntry;
-
-public class DevicePartitions
-{
- private static final Logger log = Logger.getLogger(DevicePartitions.class);
-
- private final Device device;
- private final List<Partition> partitions = new ArrayList<Partition>();
-
- public DevicePartitions(Device device)
- {
- this.device = device;
- try {
- addPartitions(device);
- } catch (Exception e) {
- log.error(e);
- }
- }
-
- public List<Partition> getPartitions()
- {
- return partitions;
- }
-
- protected void addPartitions(Device device) throws Exception
- {
- System.err.println("addPartitions");
- if(device.implementsAPI(PartitionableBlockDeviceAPI.class))
- {
- System.err.println("implementsAPI");
- partitions.clear();
- PartitionableBlockDeviceAPI<?> api = device.getAPI(PartitionableBlockDeviceAPI.class);
- for(PartitionTableEntry e : api.getPartitionTable())
- {
- System.err.println("PartitionTableEntry");
- addPartition(e);
- }
- }
- }
-
- public void addPartition(PartitionTableEntry e)
- {
- if(e instanceof IBMPartitionTableEntry)
- {
- IBMPartitionTableEntry pte = (IBMPartitionTableEntry) e;
- partitions.add(new Partition(pte));
- }
- else
- {
- log.warn("found non-IBMPartitionTableEntry");
- }
- }
-
- public String toString()
- {
- return device.getId();
- }
-
- public Device getDevice() {
- return device;
- }
-}
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitionsList.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitionsList.java 2007-04-15 19:46:31 UTC (rev 3162)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitionsList.java 2007-04-15 21:05:11 UTC (rev 3163)
@@ -1,7 +0,0 @@
-package org.jnode.apps.jpartition.model;
-
-import java.util.ArrayList;
-
-public class DevicePartitionsList extends ArrayList<DevicePartitions>
-{
-}
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java 2007-04-15 19:46:31 UTC (rev 3162)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java 2007-04-15 21:05:11 UTC (rev 3163)
@@ -1,40 +0,0 @@
-package org.jnode.apps.jpartition.model;
-
-import org.jnode.driver.bus.ide.IDEConstants;
-import org.jnode.partitions.ibm.IBMPartitionTableEntry;
-import org.jnode.partitions.ibm.IBMPartitionTypes;
-
-public class Partition
-{
- private final IBMPartitionTableEntry pte;
-
- public Partition(IBMPartitionTableEntry pte)
- {
- this.pte = pte;
- }
-
- public boolean isEmpty()
- {
- return pte.isEmpty();
- }
-
- public boolean isBootable()
- {
- return pte.getBootIndicator();
- }
-
- public IBMPartitionTypes getType()
- {
- return pte.getSystemIndicator();
- }
-
- public long getStart()
- {
- return pte.getStartLba();
- }
-
- public long getSize()
- {
- return pte.getNrSectors() * IDEConstants.SECTOR_SIZE;
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2008-01-24 22:20:38
|
Revision: 3736
http://jnode.svn.sourceforge.net/jnode/?rev=3736&view=rev
Author: fduminy
Date: 2008-01-24 14:20:29 -0800 (Thu, 24 Jan 2008)
Log Message:
-----------
fixed compilation error
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java
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-24 21:20:22 UTC (rev 3735)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java 2008-01-24 22:20:29 UTC (rev 3736)
@@ -9,12 +9,12 @@
import org.jnode.driver.ApiNotFoundException;
import org.jnode.driver.DeviceListener;
import org.jnode.driver.DeviceManager;
-import org.jnode.driver.DeviceNotFoundException;
import org.jnode.driver.DeviceUtils;
import org.jnode.driver.block.PartitionableBlockDeviceAPI;
import org.jnode.driver.bus.ide.IDEConstants;
import org.jnode.driver.bus.ide.IDEDevice;
import org.jnode.driver.bus.ide.IDEDeviceAPI;
+import org.jnode.fs.FileSystem;
import org.jnode.partitions.PartitionTableEntry;
import org.jnode.partitions.ibm.IBMPartitionTableEntry;
@@ -90,18 +90,18 @@
private Device createDevice(org.jnode.driver.Device dev)
{
Device device = null;
- List<IBMPartitionTableEntry> partitions = getPartitions(dev);
+ List<IBMPartitionTableEntry> partitions = getPartitions(dev);
if(partitions != null) // null if not supported
{
- List<Partition> devPartitions = new ArrayList<Partition>(partitions.size());
+ List<Partition> devPartitions = new ArrayList<Partition>(partitions.size());
Partition prevPartition = null;
-
+
for(IBMPartitionTableEntry e : partitions)
{
IBMPartitionTableEntry pte = (IBMPartitionTableEntry) e;
long start = pte.getStartLba();
long size = pte.getNrSectors() * IDEConstants.SECTOR_SIZE;
-
+
if(pte.isEmpty())
{
if((prevPartition != null) && !prevPartition.isUsed())
@@ -115,9 +115,9 @@
devPartitions.add(new Partition(start, size, false));
}
}
- else
+ else
{
- // current partition is not empty
+ // current partition is not empty
devPartitions.add(new Partition(start, size, true));
}
}
@@ -131,17 +131,17 @@
} 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>();
-
+ boolean supported = false;
+ List<IBMPartitionTableEntry> partitions = new ArrayList<IBMPartitionTableEntry>();
+
try {
if (dev.implementsAPI(IDEDeviceAPI.class)) {
if (dev.implementsAPI(PartitionableBlockDeviceAPI.class)) {
@@ -155,7 +155,7 @@
supportedPartitions = false;
break;
}
-
+
partitions.add((IBMPartitionTableEntry) e);
}
@@ -169,7 +169,31 @@
// TODO Auto-generated catch block
e.printStackTrace();
}
-
+
return supported ? partitions : null;
}
+
+
+ private FileSystem<?> getFileSystem(org.jnode.driver.Device dev, PartitionTableEntry pte)
+ {
+/*
+ DeviceManager devMan = InitialNaming.lookup(DeviceManager.NAME);
+ FileSystemService fss = InitialNaming.lookup(FileSystemService.NAME);
+ Collection<Device> devices = devMan.getDevices();
+ FileSystem fs = null;
+
+ for (Device device : devices) {
+ if (device instanceof IDEDiskPartitionDevice) {
+ IDEDiskPartitionDevice partition = (IDEDiskPartitionDevice)device;
+ if ((partition.getParent() == dev) && (partition.getPartitionTableEntry() == pte)) {
+ //fs = fss.getFileSystem(device).get;
+ break;
+ }
+ }
+ }
+
+ return fs;
+*/
+ return null;//TODO
+ }
}
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-24 21:20:22 UTC (rev 3735)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java 2008-01-24 22:20:29 UTC (rev 3736)
@@ -138,8 +138,8 @@
checkSelectedDevice();
Partition newPart = selectedDevice.addPartition(start, size);
- cmdProcessor.addCommand(new CreatePartitionCommand((IDEDevice) selectedDevice.getDevice(), start, size));
-
+ cmdProcessor.addCommand(new CreatePartitionCommand((IDEDevice) selectedDevice.getDevice(), 0, start, size));
+
return newPart;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|