Skip to content

Commit

Permalink
Issue 25: Rename Selection to SelectionModel to avoid name conflicts …
Browse files Browse the repository at this point in the history
…with dart:html's Selection
  • Loading branch information
tomyeh committed May 14, 2013
1 parent b299f46 commit bdcc19c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 36 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#Rikulo Changes

##0.6.7

* Issue 25: rename Selection to SelectionModel, Disables to DisablesModel, Opens to OpensModel, and AbstractSelectionModel to AbstractDataModel

##0.6.6

*Upgrade Notes*
Expand Down
8 changes: 4 additions & 4 deletions lib/src/model/DataEvent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,25 @@ class DataEvents {
Stream<DataEvent> get structure => _structureEvent.forTarget(_owner);
/** Identifies the selection of the lists has changed.
*
* It is applicable only if the model supports [Selection].
* It is applicable only if the model supports [SelectionModel].
* The event is an instance of [DataEvent].
*/
Stream<DataEvent> get select => _selectEvent.forTarget(_owner);
/** Identified the change of whether the model allows mutiple selection.
*
* It is applicable only if the model supports [Selection].
* It is applicable only if the model supports [SelectionModel].
* The event is an instance of [DataEvent].
*/
Stream<DataEvent> get multiple => _multipleEvent.forTarget(_owner);
/** Identifies the list of disabled objects has changed.
*
* It is applicable only if the model supports [Disables].
* It is applicable only if the model supports [DisablesModel].
* The event is an instance of [DataEvent].
*/
Stream<DataEvent> get disable => _disableEvent.forTarget(_owner);
/** Identifies the change of the open statuses.
*
* It is applicable only if the model supports [Opens].
* It is applicable only if the model supports [OpensModel].
* The event is an instance of [DataEvent].
*/
Stream<DataEvent> get open => _openEvent.forTarget(_owner);
Expand Down
20 changes: 10 additions & 10 deletions lib/src/model/DataModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ModelError implements Error {
* Indicates a model that allows to open some of the objects.
* It is a supplymental interface used with other models, such as [TreeModel].
*/
abstract class Opens<T> {
abstract class OpensModel<T> {
/**
* Returns the current list of nodes that are opened.
* It is readonly. Don't modify it directly. Otherwise, UI won't be
Expand Down Expand Up @@ -114,7 +114,7 @@ abstract class Opens<T> {
* Indicates a model that allows to disable some of the objects.
* It is a supplymental interface used with other models, such as [ListModel].
*/
abstract class Disables<T> {
abstract class DisablesModel<T> {
/**
* Returns the current list of disabled objects.
* It is readonly. Don't modify it directly. Otherwise, UI won't be
Expand Down Expand Up @@ -159,7 +159,7 @@ abstract class Disables<T> {
* Indicates a model that allows selection.
* It is a supplymental interface used with other models, such as [ListModel].
*/
abstract class Selection<T> {
abstract class SelectionModel<T> {
/**
* Returns the first selected value, or null if none is selected.
*/
Expand Down Expand Up @@ -213,10 +213,10 @@ abstract class Selection<T> {
}

/**
* A skeletal implementation of [DataModel], [Selection] and [Disables].
* A skeletal implementation of [DataModel], [SelectionModel] and [DisablesModel].
*/
class AbstractSelectionModel<T> extends DataModel
implements Selection<T>, Disables<T> {
class AbstractDataModel<T> extends DataModel
implements SelectionModel<T>, DisablesModel<T> {
Set<T> _selection, _disables;
bool _multiple = false;
/** Constructor.
Expand All @@ -226,7 +226,7 @@ implements Selection<T>, Disables<T> {
* + [disables]: if not null, it will be used to hold the list of disabled items.
* Unlike [set disables], it won't make a copy.
*/
AbstractSelectionModel({Set<T> selection, Set<T> disables, bool multiple:false}) {
AbstractDataModel({Set<T> selection, Set<T> disables, bool multiple:false}) {
_selection = selection != null ? selection: new Set();
_disables = disables != null ? disables: new Set();
_multiple = multiple;
Expand All @@ -240,7 +240,7 @@ implements Selection<T>, Disables<T> {
sendEvent(new DataEvent(this, 'disable'));
}

//Selection//
//SelectionModel//
T get selectedValue => _selection.isEmpty ? null: _selection.first;
Set<T> get selection => _selection;

Expand Down Expand Up @@ -303,7 +303,7 @@ implements Selection<T>, Disables<T> {
}
}

//Disables//
//DisablesModel//
Set<T> get disables => _disables;
void set disables(Iterable<T> disables) {
if (!_equals(_disables, disables)) {
Expand Down Expand Up @@ -355,7 +355,7 @@ implements Selection<T>, Disables<T> {
}

bool operator==(other) {
return (other is AbstractSelectionModel) && multiple == other.multiple
return (other is AbstractDataModel) && multiple == other.multiple
&& _selection == other._selection && _disables == other._disables;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/model/ListModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ListDataEvent<T> extends DataEvent {
* A data model representing a list of data.
*
* Instead of implementing this interface, you can use [DefaultListModel]. It
* is a concrete class that implements [ListModel], [Selection] and [Disables].
* is a concrete class that implements [ListModel], [SelectionModel] and [DisablesModel].
*
* Instead of implementing this interface from scratch, it is suggested
* to extend from [AbstractListModel].
Expand All @@ -51,9 +51,9 @@ class Foo extends ListModel {
}
/**
* A skeletal implementation of [ListModel].
* It handles the data events ([ListDataEvent]) and the selection ([Selection]).
* It handles the data events ([ListDataEvent]) and the selection ([SelectionModel]).
*/
abstract class AbstractListModel<T> extends AbstractSelectionModel<T>
abstract class AbstractListModel<T> extends AbstractDataModel<T>
implements ListModel<T> {
/** Constructor.
*
Expand Down
12 changes: 6 additions & 6 deletions lib/src/model/TreeModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ class TreeDataEvent<T> extends DataEvent {
* On the other hand, [DefaultTreeModel] and [TreeNode] do
* provide `getPath()` to retrieve the path of any given node.
*
* ##Selection
* ##SelectionModel
*
* If you'd like to use [TreeModel] with a UI object that allows the user to select the data,
* such as [DropDownList]. You have to implement `Selection<T>`.
* such as [DropDownList]. You have to implement [SelectionModel].
* Both [DefaultTreeModel] and [AbstractTreeModel] implements it, so you need to implement
* it only if you implement [TreeModel] from scratch.
*
* ##Opens
* ##OpensModel
*
* A tree model maintains a list of opened nodes ([Opens]). If a tree node matches
* A tree model maintains a list of opened nodes ([OpensModel]). If a tree node matches
* one of the open nodes, the tree node will be opened, i.e., the child views
* will be visible to the user.
*/
Expand Down Expand Up @@ -113,8 +113,8 @@ abstract class TreeModel<T> extends DataModel {
* To extend from this class, you have to implement [getChild], [getChildCount]
* and [isLeaf]. This class provides a default implementation for all other methods.
*/
abstract class AbstractTreeModel<T> extends AbstractSelectionModel<T>
implements TreeModel<T>, Opens<T> {
abstract class AbstractTreeModel<T> extends AbstractDataModel<T>
implements TreeModel<T>, OpensModel<T> {
T _root;
Set<T> _opens;

Expand Down
24 changes: 12 additions & 12 deletions lib/src/view/DropDownList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class DropDownList<T> extends View {
*/
void set model(DataModel model) {
if (model != null) {
if (model is! Selection)
throw new UIError("Selection required, $model");
if (model is! SelectionModel)
throw new UIError("SelectionModel required, $model");
if (model is! ListModel && model is! TreeModel)
throw new UIError("Only ListModel or TreeModel allowed, not $model");
}
Expand All @@ -96,7 +96,7 @@ class DropDownList<T> extends View {

if (_model != null) {
_subAll = _model.on.all.listen(_initDataListener());
_selectNode.multiple = (_model as Selection).multiple;
_selectNode.multiple = (_model as SelectionModel).multiple;
}

modelRenderer.queue(this); //queue even if _model is null (since cleanup is a bit tricky)
Expand Down Expand Up @@ -124,7 +124,7 @@ class DropDownList<T> extends View {
_dataListener = (event) {
switch (event.type) {
case 'multiple':
(node as SelectElement).multiple = (_model as Selection).multiple;
(node as SelectElement).multiple = (_model as SelectionModel).multiple;
sendEvent(new ViewEvent("render")); //send it since the look might be changed
return; //no need to rerender
case 'select':
Expand All @@ -133,7 +133,7 @@ class DropDownList<T> extends View {
if (_model is ListModel) { //not easy/worth to optimize handling of TreeModel
final options = (node as SelectElement).options;
final ListModel<T> model = _model as ListModel;
final Selection<T> selmodel = _model as Selection;
final SelectionModel<T> selmodel = _model as SelectionModel;
final bool multiple = selmodel.multiple;
for (int i = 0, len = model.length; i < len; ++i) {
final bool seled = (options[i] as OptionElement).selected = selmodel.isSelected(model[i]);
Expand Down Expand Up @@ -190,7 +190,7 @@ class DropDownList<T> extends View {
final SelectElement n = node;
selIndex = n.selectedIndex;
final ListModel model = _model is ListModel ? _model: null;
if ((_model as Selection).multiple) {
if ((_model as SelectionModel).multiple) {
for (OptionElement opt in n.options) {
if (opt.selected) {
if (model != null) {
Expand All @@ -212,7 +212,7 @@ class DropDownList<T> extends View {

_modelSelUpdating = true;
try {
(_model as Selection).selection = selValues;
(_model as SelectionModel).selection = selValues;
} finally {
_modelSelUpdating = false;
}
Expand All @@ -231,12 +231,12 @@ class DropDownList<T> extends View {
final renderer = _renderer != null ? _renderer: _defRenderer;
if (_model is ListModel) {
final ListModel<T> model = _model;
final Selection<T> selmodel = _model as Selection;
final SelectionModel<T> selmodel = _model as SelectionModel;
final multiple = selmodel.multiple;
for (int i = 0, len = model.length; i < len; ++i) {
final obj = model[i];
final selected = selmodel.isSelected(obj);
final disabled = _model is Disables && (_model as Disables).isDisabled(obj);
final disabled = _model is DisablesModel && (_model as DisablesModel).isDisabled(obj);
var ret = renderer(new RenderContext(this, _model, obj, selected, disabled, i));
if (ret == null) ret = "";
OptionElement opt;
Expand All @@ -260,17 +260,17 @@ class DropDownList<T> extends View {
}

//Update DOM tree
if ((_model as Selection).isSelectionEmpty)
if ((_model as SelectionModel).isSelectionEmpty)
(node as SelectElement).selectedIndex = -1;
}
void _renderTree(Element parent, TreeModel<T> model,
Renderer renderer, var parentData, int parentIndex) {
final Selection<T> selmodel = _model as Selection;
final SelectionModel<T> selmodel = _model as SelectionModel;
final bool multiple = selmodel.multiple;
for (int i = 0, len = model.getChildCount(parentData); i < len; ++i) {
final T child = model.getChild(parentData, i);
final bool selected = selmodel.isSelected(child);
final bool disabled = _model is Disables && (_model as Disables).isDisabled(child);
final bool disabled = _model is DisablesModel && (_model as DisablesModel).isDisabled(child);
var ret = renderer(new RenderContext(this, _model, child, selected, disabled, i));
if (ret == null) ret = "";
if (model.isLeaf(child)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//Feb. 04, 2012
library rikulo_view;

import 'dart:html' hide Selection;
import 'dart:html';
import 'dart:math';
import 'dart:collection';
import 'dart:async' show StreamSubscription, Timer;
Expand Down

0 comments on commit bdcc19c

Please sign in to comment.