Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

On Profile Change read schema URL

  • Loading branch information...
commit 2d3b7a29108fcc68c5ec1f40384e524e0f82326e 1 parent d4d2785
@eddiemoore authored
View
BIN  bin-debug/StructureCreator.swf
Binary file not shown
View
4 src/com/structurecreator/MainContext.as
@@ -2,6 +2,7 @@ package com.structurecreator
{
import com.structurecreator.controller.DatabaseCommand;
import com.structurecreator.controller.FileCommand;
+ import com.structurecreator.controller.ProfileChangeCommand;
import com.structurecreator.controller.ProfileCommand;
import com.structurecreator.events.CustomVarsEvent;
import com.structurecreator.events.FileEvent;
@@ -16,6 +17,7 @@ package com.structurecreator
import com.structurecreator.services.DatabaseService;
import com.structurecreator.services.FileCreateService;
import com.structurecreator.services.MicrosoftXFileService;
+ import com.structurecreator.services.ProfileService;
import com.structurecreator.view.CreateButtonMediator;
import com.structurecreator.view.CreateButtonView;
import com.structurecreator.view.CustomVariablesMediator;
@@ -64,6 +66,7 @@ package com.structurecreator
injector.mapSingleton(StructureCreatorModel);
injector.mapSingleton(CustomVariableModel);
injector.mapSingleton(DatabaseService);
+ injector.mapSingleton(ProfileService);
/* Setup File Creation Services */
injector.mapClass(FileCreateService, FileCreateService);
@@ -86,6 +89,7 @@ package com.structurecreator
commandMap.mapEvent(FileEvent.START_CREATION, FileCommand, FileEvent);
commandMap.mapEvent(StructureCreatorEvent.APP_STARTED, DatabaseCommand, StructureCreatorEvent);
commandMap.mapEvent(ProfileEvent.SAVE_PROFILE, ProfileCommand, ProfileEvent);
+ commandMap.mapEvent(ProfileEvent.PROFILE_SELECTED, ProfileChangeCommand, ProfileEvent);
/* Listen for creation complete event */
eventDispatcher.addEventListener(StructureCreatorEvent.CREATION_COMPLETE, onCreationComplete);
View
34 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));
+ }
+ }
+}
View
2  src/com/structurecreator/controller/ProfileCommand.as
@@ -24,7 +24,7 @@ package com.structurecreator.controller
override public function execute():void
{
trace("Add the profile");
- service.addProfile(event.name);
+ service.addProfile(event.name, event.schema_url);
}
}
}
View
29 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;
+ }
+
+ }
+}
View
13 src/com/structurecreator/events/ProfileEvent.as
@@ -6,15 +6,19 @@ package com.structurecreator.events
{
public static const OPEN_SAVE_WINDOW:String = 'openSaveWindow';
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';
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);
_name = name;
+ trace("Event", schema_url);
+ _schema_url = schema_url;
}
override public function clone():Event
@@ -26,5 +30,10 @@ package com.structurecreator.events
{
return _name;
}
+
+ public function get schema_url():String
+ {
+ return _schema_url;
+ }
}
}
View
23 src/com/structurecreator/model/SchemaModel.as
@@ -10,17 +10,13 @@ package com.structurecreator.model
public class SchemaModel extends Actor
{
private var _schemaFile:File = File.documentsDirectory;
+ private var _schemaURL:String = '';
public function SchemaModel()
{
}
- public function get schemaFile():File
- {
- return _schemaFile;
- }
-
/**
* Open file select to select schema file
*/
@@ -35,7 +31,24 @@ package com.structurecreator.model
*/
protected function onSchemaSelected(event:Event):void
{
+ _schemaURL = _schemaFile.url;
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;
+ }
+
}
}
View
7 src/com/structurecreator/services/DatabaseService.as
@@ -55,10 +55,11 @@ package com.structurecreator.services
/**
* 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 + "');");
- trace("Add Profile " + name);
+ //addStatement("INSERT INTO profiles (name, schema_file) SELECT '" + name +"', '" + schema_url + "' WHERE NOT EXISTS (SELECT 1 FROM profiles WHERE name = '" + name + "');");
+ addStatement("INSERT INTO profiles (name, schema_file) VALUES('" + name + "', '" + schema_url + "');");
+ trace("Add Profile " + name, " : " + schema_url);
execute();
eventDispatcher.dispatchEvent(new DatabaseEvent(DatabaseEvent.DATABASE_UPDATED));
}
View
17 src/com/structurecreator/services/ProfileService.as
@@ -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
+ }
+ }
}
}
View
2  src/com/structurecreator/view/ProfileSelectMediator.as
@@ -69,7 +69,7 @@ package com.structurecreator.view
protected function onChange(event:IndexChangeEvent):void
{
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)));
}
}
}
View
16 src/com/structurecreator/view/SchemaSelectMediator.as
@@ -1,5 +1,7 @@
package com.structurecreator.view
{
+ import com.structurecreator.events.ProfileChangeEvent;
+ import com.structurecreator.events.ProfileEvent;
import com.structurecreator.events.SchemaEvent;
import com.structurecreator.model.SchemaModel;
@@ -24,6 +26,20 @@ package com.structurecreator.view
{
eventMap.mapListener(view.browse, MouseEvent.CLICK, onClick);
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;
}
/**
View
41 src/com/structurecreator/view/editprofile/EditProfileMediator.as
@@ -2,10 +2,12 @@ package com.structurecreator.view.editprofile
{
import com.structurecreator.events.DatabaseEvent;
import com.structurecreator.services.DatabaseService;
+ import com.structurecreator.services.ProfileService;
import flash.events.MouseEvent;
import mx.collections.ArrayCollection;
+ import mx.controls.Alert;
import org.robotlegs.mvcs.Mediator;
@@ -17,6 +19,9 @@ package com.structurecreator.view.editprofile
[Inject]
public var model:DatabaseService;
+ [Inject]
+ public var profileService:ProfileService;
+
[Bindable]
private var provider:ArrayCollection;
@@ -34,11 +39,17 @@ package com.structurecreator.view.editprofile
getAllProfiles();
}
+ /**
+ * When database is updated, update view
+ */
private function onDatabaseUpdated(e:DatabaseEvent):void
{
getAllProfiles();
}
+ /**
+ * Get all the Profiles
+ */
private function getAllProfiles():void
{
var profiles:Array = model.selectAllProfiles();
@@ -61,17 +72,39 @@ package com.structurecreator.view.editprofile
view.profileList.dataProvider = provider;
}
+ /**
+ * Export Button Clicked
+ */
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
{
//get selected item from list
- var selected:Object = provider[view.profileList.selectedIndex];
-
- model.deleteProfile(selected.data);
+ if (view.profileList.selectedIndex > -1)
+ {
+ 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);
}
}
View
7 src/com/structurecreator/view/saveprofile/SaveProfileWindowMediator.as
@@ -1,6 +1,8 @@
package com.structurecreator.view.saveprofile
{
import com.structurecreator.events.ProfileEvent;
+ import com.structurecreator.model.SchemaModel;
+ import com.structurecreator.view.SchemaSelectView;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
@@ -13,6 +15,9 @@ package com.structurecreator.view.saveprofile
[Inject]
public var view:SaveProfileWindow;
+ [Inject]
+ public var schemaModel:SchemaModel;
+
public function SaveProfileWindowMediator()
{
@@ -45,7 +50,7 @@ package com.structurecreator.view.saveprofile
if (view.profile_name.text != '')
{
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));
}
}
}

0 comments on commit 2d3b7a2

Please sign in to comment.
Something went wrong with that request. Please try again.