Skip to content

Commit

Permalink
step-11 Context Selections
Browse files Browse the repository at this point in the history
* Creating an ISelectionContext with a selection() getter function
* Creating another Context which listens and responds to changes on the
ISelectionContext via a contextSelectionValidator
  • Loading branch information
robsilv committed Jul 3, 2014
1 parent defceae commit efdce47
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/helloWorld/contexts/HelloWorldContext.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@ package helloWorld.contexts
{
import helloWorld.ui.views.HelloWorldView;
import flash.display.DisplayObject;

import core.appEx.core.contexts.ISelectionContext;
import core.appEx.core.contexts.IVisualContext;
import core.appEx.events.ContextSelectionValidatorEvent;
import core.appEx.validators.ContextSelectionValidator;
import core.editor.CoreEditor;

public class HelloWorldContext implements IVisualContext
{
private var _view :HelloWorldView;
private var contextSelectionValidator :ContextSelectionValidator;

public function HelloWorldContext()
{
_view = new HelloWorldView();
_view.text = "Hello World";

contextSelectionValidator = new ContextSelectionValidator(CoreEditor.contextManager, ISelectionContext, String);
contextSelectionValidator.addEventListener(ContextSelectionValidatorEvent.VALID_SELECTION_CHANGED, selectionChangeHandler);
}

public function get view():DisplayObject
Expand All @@ -21,7 +30,20 @@ package helloWorld.contexts

public function dispose():void
{

contextSelectionValidator.removeEventListener(ContextSelectionValidatorEvent.VALID_SELECTION_CHANGED, selectionChangeHandler);
contextSelectionValidator.dispose();
}

private function selectionChangeHandler(event:ContextSelectionValidatorEvent):void
{
_view.text = "";

var selection:Array = contextSelectionValidator.getValidSelection();
for ( var i:int = 0; i < selection.length; i++ )
{
var item:String = selection[i];
_view.text += item + "\n";
}
}
}
}
16 changes: 15 additions & 1 deletion src/helloWorld/contexts/StringListContext.as
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package helloWorld.contexts
import core.app.entities.URI;
import core.app.operations.ReadFileAndDeserializeOperation;
import core.appEx.core.contexts.IOperationManagerContext;
import core.appEx.core.contexts.ISelectionContext;
import core.appEx.events.OperationManagerEvent;
import core.appEx.managers.OperationManager;
import core.appEx.operations.SerializeAndWriteFileOperation;
Expand All @@ -19,11 +20,12 @@ package helloWorld.contexts

[Event( type="flash.events.Event", name="change" )]

public class StringListContext extends EventDispatcher implements IEditorContext, IOperationManagerContext
public class StringListContext extends EventDispatcher implements IEditorContext, IOperationManagerContext, ISelectionContext
{
private var _view :StringListView;

private var _dataProvider :ArrayCollection;
private var _selection :ArrayCollection;

private var _operationManager :OperationManager;

Expand All @@ -40,6 +42,9 @@ package helloWorld.contexts

_operationManager = new OperationManager();
_operationManager.addEventListener(OperationManagerEvent.CHANGE, changeOperationManagerHandler);

_selection = new ArrayCollection();
_view.addEventListener(Event.CHANGE, listChangeHandler);
}

public function get view():DisplayObject
Expand All @@ -51,6 +56,13 @@ package helloWorld.contexts
{
_operationManager.removeEventListener(OperationManagerEvent.CHANGE, changeOperationManagerHandler);
_operationManager.dispose();

_view.removeEventListener(Event.CHANGE, listChangeHandler);
}

private function listChangeHandler( event:Event ):void
{
_selection.source = _view.selectedItems;
}

public function enable():void
Expand Down Expand Up @@ -130,5 +142,7 @@ package helloWorld.contexts
public function get dataProvider():ArrayCollection { return _dataProvider; }

public function get operationManager():OperationManager { return _operationManager; }

public function get selection():ArrayCollection { return _selection; }
}
}

0 comments on commit efdce47

Please sign in to comment.