|
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.
|