Skip to content

Commit

Permalink
On Profile Change read schema URL
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiemoore committed Apr 13, 2012
1 parent d4d2785 commit 2d3b7a2
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 18 deletions.
Binary file modified bin-debug/StructureCreator.swf
Binary file not shown.
4 changes: 4 additions & 0 deletions src/com/structurecreator/MainContext.as
Expand Up @@ -2,6 +2,7 @@ package com.structurecreator
{ {
import com.structurecreator.controller.DatabaseCommand; import com.structurecreator.controller.DatabaseCommand;
import com.structurecreator.controller.FileCommand; import com.structurecreator.controller.FileCommand;
import com.structurecreator.controller.ProfileChangeCommand;
import com.structurecreator.controller.ProfileCommand; import com.structurecreator.controller.ProfileCommand;
import com.structurecreator.events.CustomVarsEvent; import com.structurecreator.events.CustomVarsEvent;
import com.structurecreator.events.FileEvent; import com.structurecreator.events.FileEvent;
Expand All @@ -16,6 +17,7 @@ package com.structurecreator
import com.structurecreator.services.DatabaseService; import com.structurecreator.services.DatabaseService;
import com.structurecreator.services.FileCreateService; import com.structurecreator.services.FileCreateService;
import com.structurecreator.services.MicrosoftXFileService; import com.structurecreator.services.MicrosoftXFileService;
import com.structurecreator.services.ProfileService;
import com.structurecreator.view.CreateButtonMediator; import com.structurecreator.view.CreateButtonMediator;
import com.structurecreator.view.CreateButtonView; import com.structurecreator.view.CreateButtonView;
import com.structurecreator.view.CustomVariablesMediator; import com.structurecreator.view.CustomVariablesMediator;
Expand Down Expand Up @@ -64,6 +66,7 @@ package com.structurecreator
injector.mapSingleton(StructureCreatorModel); injector.mapSingleton(StructureCreatorModel);
injector.mapSingleton(CustomVariableModel); injector.mapSingleton(CustomVariableModel);
injector.mapSingleton(DatabaseService); injector.mapSingleton(DatabaseService);
injector.mapSingleton(ProfileService);


/* Setup File Creation Services */ /* Setup File Creation Services */
injector.mapClass(FileCreateService, FileCreateService); injector.mapClass(FileCreateService, FileCreateService);
Expand All @@ -86,6 +89,7 @@ package com.structurecreator
commandMap.mapEvent(FileEvent.START_CREATION, FileCommand, FileEvent); commandMap.mapEvent(FileEvent.START_CREATION, FileCommand, FileEvent);
commandMap.mapEvent(StructureCreatorEvent.APP_STARTED, DatabaseCommand, StructureCreatorEvent); commandMap.mapEvent(StructureCreatorEvent.APP_STARTED, DatabaseCommand, StructureCreatorEvent);
commandMap.mapEvent(ProfileEvent.SAVE_PROFILE, ProfileCommand, ProfileEvent); commandMap.mapEvent(ProfileEvent.SAVE_PROFILE, ProfileCommand, ProfileEvent);
commandMap.mapEvent(ProfileEvent.PROFILE_SELECTED, ProfileChangeCommand, ProfileEvent);


/* Listen for creation complete event */ /* Listen for creation complete event */
eventDispatcher.addEventListener(StructureCreatorEvent.CREATION_COMPLETE, onCreationComplete); eventDispatcher.addEventListener(StructureCreatorEvent.CREATION_COMPLETE, onCreationComplete);
Expand Down
34 changes: 34 additions & 0 deletions src/com/structurecreator/controller/ProfileChangeCommand.as
@@ -0,0 +1,34 @@
package com.structurecreator.controller
{
import com.structurecreator.events.ProfileChangeEvent;
import com.structurecreator.events.ProfileEvent;
import com.structurecreator.services.DatabaseService;

import org.robotlegs.mvcs.Command;

public class ProfileChangeCommand extends Command
{
[Inject]
public var event:ProfileEvent;

[Inject]
public var service:DatabaseService;

public function ProfileChangeCommand()
{
//super();
}

/**
* Initialises the creation of a new file
*/
override public function execute():void
{
//trace("Add the profile");
//service.addProfile(event.name, event.schema_url);
trace(int(event.name));
var profile:Array = service.selectProfile(int(event.name));
eventDispatcher.dispatchEvent(new ProfileChangeEvent(ProfileChangeEvent.PROFILE_CHANGED, profile));
}
}
}
2 changes: 1 addition & 1 deletion src/com/structurecreator/controller/ProfileCommand.as
Expand Up @@ -24,7 +24,7 @@ package com.structurecreator.controller
override public function execute():void override public function execute():void
{ {
trace("Add the profile"); trace("Add the profile");
service.addProfile(event.name); service.addProfile(event.name, event.schema_url);
} }
} }
} }
29 changes: 29 additions & 0 deletions src/com/structurecreator/events/ProfileChangeEvent.as
@@ -0,0 +1,29 @@
package com.structurecreator.events
{
import flash.events.Event;

public class ProfileChangeEvent extends Event
{
public static const PROFILE_CHANGED:String = 'profileChanged';

private var _profile:Array;

public function ProfileChangeEvent(type:String, profile:Array)
{
super(type);
_profile = profile;
}

override public function clone():Event
{
return new ProfileChangeEvent(type, _profile);
}


public function get profile():Array
{
return _profile;
}

}
}
13 changes: 11 additions & 2 deletions src/com/structurecreator/events/ProfileEvent.as
Expand Up @@ -6,15 +6,19 @@ package com.structurecreator.events
{ {
public static const OPEN_SAVE_WINDOW:String = 'openSaveWindow'; public static const OPEN_SAVE_WINDOW:String = 'openSaveWindow';
public static const SAVE_PROFILE:String = 'saveProfile'; public static const SAVE_PROFILE:String = 'saveProfile';
public static const PROFILE_CHANGED:String = 'profileChanged'; public static const PROFILE_SELECTED:String = 'profileSelected';
public static const EDIT_PROFILES:String = 'editProfile'; public static const EDIT_PROFILES:String = 'editProfile';


private var _name:String; private var _name:String;
private var _schema_url:String;



public function ProfileEvent(type:String, name:String='') public function ProfileEvent(type:String, name:String='', schema_url:String='')
{ {
super(type); super(type);
_name = name; _name = name;
trace("Event", schema_url);
_schema_url = schema_url;
} }


override public function clone():Event override public function clone():Event
Expand All @@ -26,5 +30,10 @@ package com.structurecreator.events
{ {
return _name; return _name;
} }

public function get schema_url():String
{
return _schema_url;
}
} }
} }
23 changes: 18 additions & 5 deletions src/com/structurecreator/model/SchemaModel.as
Expand Up @@ -10,17 +10,13 @@ package com.structurecreator.model
public class SchemaModel extends Actor public class SchemaModel extends Actor
{ {
private var _schemaFile:File = File.documentsDirectory; private var _schemaFile:File = File.documentsDirectory;
private var _schemaURL:String = '';


public function SchemaModel() public function SchemaModel()
{ {


} }


public function get schemaFile():File
{
return _schemaFile;
}

/** /**
* Open file select to select schema file * Open file select to select schema file
*/ */
Expand All @@ -35,7 +31,24 @@ package com.structurecreator.model
*/ */
protected function onSchemaSelected(event:Event):void protected function onSchemaSelected(event:Event):void
{ {
_schemaURL = _schemaFile.url;
eventDispatcher.dispatchEvent(new SchemaEvent(SchemaEvent.SCHEMA_SELECTED)); eventDispatcher.dispatchEvent(new SchemaEvent(SchemaEvent.SCHEMA_SELECTED));
} }

public function get schemaFile():File
{
return _schemaFile;
}

public function get schemaURL():String
{
return _schemaURL;
}

public function set schemaURL(value:String):void
{
_schemaURL = value;
}

} }
} }
7 changes: 4 additions & 3 deletions src/com/structurecreator/services/DatabaseService.as
Expand Up @@ -55,10 +55,11 @@ package com.structurecreator.services
/** /**
* Insert a new profile into database * Insert a new profile into database
*/ */
public function addProfile(name:String = ''):void public function addProfile(name:String = '', schema_url:String=''):void
{ {
addStatement("INSERT INTO profiles (name) SELECT '" + name +"' WHERE NOT EXISTS (SELECT 1 FROM profiles WHERE name = '" + name + "');"); //addStatement("INSERT INTO profiles (name, schema_file) SELECT '" + name +"', '" + schema_url + "' WHERE NOT EXISTS (SELECT 1 FROM profiles WHERE name = '" + name + "');");
trace("Add Profile " + name); addStatement("INSERT INTO profiles (name, schema_file) VALUES('" + name + "', '" + schema_url + "');");
trace("Add Profile " + name, " : " + schema_url);
execute(); execute();
eventDispatcher.dispatchEvent(new DatabaseEvent(DatabaseEvent.DATABASE_UPDATED)); eventDispatcher.dispatchEvent(new DatabaseEvent(DatabaseEvent.DATABASE_UPDATED));
} }
Expand Down
17 changes: 16 additions & 1 deletion src/com/structurecreator/services/ProfileService.as
Expand Up @@ -11,6 +11,21 @@ package com.structurecreator.services
{ {
} }


//public functio public function exportProfile(id:int):void
{
var profile:Array = db.selectProfile(id);
var custVars:Array = db.selectAllCustomVars(id);

trace(profile);
for (var i:int =0; i < profile.length; i++)
{
trace(profile[i].name);
//name
trace(profile[i].schema_file);
//schema_file
trace(profile[i].isDefault);
//isDefault
}
}
} }
} }
2 changes: 1 addition & 1 deletion src/com/structurecreator/view/ProfileSelectMediator.as
Expand Up @@ -69,7 +69,7 @@ package com.structurecreator.view
protected function onChange(event:IndexChangeEvent):void protected function onChange(event:IndexChangeEvent):void
{ {
trace("Profile Select Box Change"); trace("Profile Select Box Change");
eventDispatcher.dispatchEvent(new ProfileEvent(ProfileEvent.PROFILE_CHANGED, String(view.selectedItem.data))); eventDispatcher.dispatchEvent(new ProfileEvent(ProfileEvent.PROFILE_SELECTED, String(view.selectedItem.data)));
} }
} }
} }
16 changes: 16 additions & 0 deletions src/com/structurecreator/view/SchemaSelectMediator.as
@@ -1,5 +1,7 @@
package com.structurecreator.view package com.structurecreator.view
{ {
import com.structurecreator.events.ProfileChangeEvent;
import com.structurecreator.events.ProfileEvent;
import com.structurecreator.events.SchemaEvent; import com.structurecreator.events.SchemaEvent;
import com.structurecreator.model.SchemaModel; import com.structurecreator.model.SchemaModel;


Expand All @@ -24,6 +26,20 @@ package com.structurecreator.view
{ {
eventMap.mapListener(view.browse, MouseEvent.CLICK, onClick); eventMap.mapListener(view.browse, MouseEvent.CLICK, onClick);
eventMap.mapListener(eventDispatcher, SchemaEvent.SCHEMA_SELECTED, onSchemaSelected); eventMap.mapListener(eventDispatcher, SchemaEvent.SCHEMA_SELECTED, onSchemaSelected);

eventDispatcher.addEventListener(ProfileChangeEvent.PROFILE_CHANGED, onProfileChanged);
}

private function onProfileChanged(e:ProfileChangeEvent):void
{
//trace("Schema URL", e.schema_url);
for (var i:int=0; i < e.profile.length; i++)
{
view.schemaTI.text = e.profile[i].schema_file;
model.schemaURL = e.profile[i].schema_file;
}
//view.schemaTI.text = model.schemaURL;
//model.schemaURL = e.schema_url;
} }


/** /**
Expand Down
41 changes: 37 additions & 4 deletions src/com/structurecreator/view/editprofile/EditProfileMediator.as
Expand Up @@ -2,10 +2,12 @@ package com.structurecreator.view.editprofile
{ {
import com.structurecreator.events.DatabaseEvent; import com.structurecreator.events.DatabaseEvent;
import com.structurecreator.services.DatabaseService; import com.structurecreator.services.DatabaseService;
import com.structurecreator.services.ProfileService;


import flash.events.MouseEvent; import flash.events.MouseEvent;


import mx.collections.ArrayCollection; import mx.collections.ArrayCollection;
import mx.controls.Alert;


import org.robotlegs.mvcs.Mediator; import org.robotlegs.mvcs.Mediator;


Expand All @@ -17,6 +19,9 @@ package com.structurecreator.view.editprofile
[Inject] [Inject]
public var model:DatabaseService; public var model:DatabaseService;


[Inject]
public var profileService:ProfileService;

[Bindable] [Bindable]
private var provider:ArrayCollection; private var provider:ArrayCollection;


Expand All @@ -34,11 +39,17 @@ package com.structurecreator.view.editprofile
getAllProfiles(); getAllProfiles();
} }


/**
* When database is updated, update view
*/
private function onDatabaseUpdated(e:DatabaseEvent):void private function onDatabaseUpdated(e:DatabaseEvent):void
{ {
getAllProfiles(); getAllProfiles();
} }


/**
* Get all the Profiles
*/
private function getAllProfiles():void private function getAllProfiles():void
{ {
var profiles:Array = model.selectAllProfiles(); var profiles:Array = model.selectAllProfiles();
Expand All @@ -61,17 +72,39 @@ package com.structurecreator.view.editprofile
view.profileList.dataProvider = provider; view.profileList.dataProvider = provider;
} }


/**
* Export Button Clicked
*/
private function onExportBtnClick(e:MouseEvent):void private function onExportBtnClick(e:MouseEvent):void
{ {

if (view.profileList.selectedIndex > -1)
{
var selected:Object = provider[view.profileList.selectedIndex];

profileService.exportProfile(selected.data);
}
else
{
Alert.show("Please select a profile to export", "Error", 4, view);
}
} }


/**
* Delete Button Clicked
*/
private function onDeleteBtnClick(e:MouseEvent):void private function onDeleteBtnClick(e:MouseEvent):void
{ {
//get selected item from list //get selected item from list
var selected:Object = provider[view.profileList.selectedIndex]; if (view.profileList.selectedIndex > -1)

{
model.deleteProfile(selected.data); var selected:Object = provider[view.profileList.selectedIndex];

model.deleteProfile(selected.data);
}
else
{
Alert.show("Please select a profile to delete", "Error", 4, view);
}
//trace(selected); //trace(selected);
} }
} }
Expand Down
@@ -1,6 +1,8 @@
package com.structurecreator.view.saveprofile package com.structurecreator.view.saveprofile
{ {
import com.structurecreator.events.ProfileEvent; import com.structurecreator.events.ProfileEvent;
import com.structurecreator.model.SchemaModel;
import com.structurecreator.view.SchemaSelectView;


import flash.events.KeyboardEvent; import flash.events.KeyboardEvent;
import flash.events.MouseEvent; import flash.events.MouseEvent;
Expand All @@ -13,6 +15,9 @@ package com.structurecreator.view.saveprofile
[Inject] [Inject]
public var view:SaveProfileWindow; public var view:SaveProfileWindow;


[Inject]
public var schemaModel:SchemaModel;

public function SaveProfileWindowMediator() public function SaveProfileWindowMediator()
{ {


Expand Down Expand Up @@ -45,7 +50,7 @@ package com.structurecreator.view.saveprofile
if (view.profile_name.text != '') if (view.profile_name.text != '')
{ {
trace("dispatch profile name"); trace("dispatch profile name");
eventDispatcher.dispatchEvent(new ProfileEvent(ProfileEvent.SAVE_PROFILE, view.profile_name.text)); eventDispatcher.dispatchEvent(new ProfileEvent(ProfileEvent.SAVE_PROFILE, view.profile_name.text, schemaModel.schemaURL));
} }
} }
} }
Expand Down

0 comments on commit 2d3b7a2

Please sign in to comment.