From: <fd...@us...> - 2007-04-15 21:22:29
|
Revision: 3166 http://jnode.svn.sourceforge.net/jnode/?rev=3166&view=rev Author: fduminy Date: 2007-04-15 14:22:28 -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/controller/MainController.java Removed Paths: ------------- trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java 2007-04-15 21:20:05 UTC (rev 3165) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java 2007-04-15 21:22:28 UTC (rev 3166) @@ -1,58 +0,0 @@ -package org.jnode.apps.jpartition.controller; - -import javax.naming.NameNotFoundException; - -import org.apache.log4j.Logger; -import org.jnode.apps.jpartition.model.DevicePartitions; -import org.jnode.apps.jpartition.model.DevicePartitionsList; -import org.jnode.apps.jpartition.view.DevicePartitionsFrame; -import org.jnode.apps.jpartition.view.DevicePartitionsUI; -import org.jnode.driver.Device; -import org.jnode.driver.DeviceListener; -import org.jnode.driver.DeviceUtils; - -public class DevicePartitionsController implements DeviceListener -{ - private static final Logger log = Logger.getLogger(DevicePartitionsController.class); - - private DevicePartitionsList model; - private DevicePartitionsFrame view; - - public DevicePartitionsController(DevicePartitionsList model, - DevicePartitionsFrame view) - { - this.model = model; - this.view = view; - - try { - DeviceUtils.getDeviceManager().addListener(this); - } catch (NameNotFoundException e) { - log.error(e); - } - } - - public void deviceStarted(Device device) { - System.err.println("deviceStarted..."); - DevicePartitions devPart = new DevicePartitions(device); - model.add(devPart); - view.getDevPartsUI().deviceAdded(devPart); - } - - public void deviceStop(Device device) { - System.err.println("deviceStop..."); - DevicePartitions devPartsToRemove = null; - for(DevicePartitions devParts : model) - { - if(device.equals(devParts.getDevice())) - { - devPartsToRemove = devParts; - break; - } - } - if(devPartsToRemove != null) - { - model.remove(devPartsToRemove); - view.getDevPartsUI().deviceRemoved(devPartsToRemove); - } - } -} Added: trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java 2007-04-15 21:22:28 UTC (rev 3166) @@ -0,0 +1,92 @@ +package org.jnode.apps.jpartition.controller; + +import it.battlehorse.stamps.Dispatcher; +import it.battlehorse.stamps.factories.DispatcherRegistry; +import it.battlehorse.stamps.factories.TransformerRegistry; + +import org.jnode.apps.jpartition.ViewFactory; +import org.jnode.apps.jpartition.model.CommandProcessorModel; +import org.jnode.apps.jpartition.model.DeviceModel; +import org.jnode.apps.jpartition.model.FileDeviceModel; +import org.jnode.apps.jpartition.swingview.MainView; + +public class MainController +{ + final private DeviceModel deviceModel; + final private FileDeviceModel fileDeviceModel; + final private CommandProcessorModel cmdProcessorModel; + + public MainController(ViewFactory viewFactory) throws Exception + { + TransformerRegistry.getInstance().loadTransformers(); + Dispatcher dispatcher = DispatcherRegistry.getInstance().getBasicDispatcher(); + + // FileDevice + this.fileDeviceModel = new FileDeviceModel(); + Object fileDeviceView = viewFactory.createFileDeviceView(this); + + dispatcher.registerModel("FileDeviceModel",fileDeviceModel); + dispatcher.registerView("FileDeviceModel",fileDeviceView,true); + + // CommandProcessor + this.cmdProcessorModel = new CommandProcessorModel(); + Object cmdProcessorView = viewFactory.createCommandProcessorView(this); + + dispatcher.registerModel("CommandProcessorModel",cmdProcessorModel); + dispatcher.registerView("CommandProcessorModel",cmdProcessorView,true); + + // Device + this.deviceModel = new DeviceModel(); + Object deviceView = viewFactory.createDeviceView(this, fileDeviceView, cmdProcessorView); + + dispatcher.registerModel("DeviceModel",deviceModel); + dispatcher.registerView("DeviceModel",deviceView,true); + } + +/* + final private DeviceModel model; + + public DeviceController(DeviceModel model) + { + this.model = model; + } + + + public static DeviceModel getDevicePartitions() + { + DeviceModel devParts = new DeviceModel(); + try { + org.jnode.driver.DeviceManager devMan = org.jnode.driver.DeviceUtils.getDeviceManager(); + Collection<Device> devices = devMan.getDevicesByAPI(PartitionableBlockDeviceAPI.class); + for(Device device : devices) + { + devParts.add(new DeviceModel((IDEDevice) device)); + } + } catch (NameNotFoundException e) { + log.error(e); + } + return devParts; + } +*/ + + + public void userAddFakeDisk() { + fileDeviceModel.addFakeDisk(); + } + + public void userAddVMWareDisk() { + fileDeviceModel.addVMWareDisk(); + } + + public void userRemoveFileDevice(Object device) { + fileDeviceModel.removeFileDevice(device); + } + + public void userProcessCommands() { + cmdProcessorModel.processCommands(); + } + + public void userSelectDevice(Object device) { + deviceModel.setDevice(device); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |