Show+remove (but not add) entity at specific relation indexes
authorAndy Allan <gravitystorm@gmail.com>
Sat, 9 Jan 2010 19:23:20 +0000 (19:23 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Sat, 9 Jan 2010 19:23:20 +0000 (19:23 +0000)
net/systemeD/halcyon/connection/Relation.as
net/systemeD/potlatch2/TagViewer.mxml

index f1838ce..7d804d6 100644 (file)
@@ -29,6 +29,16 @@ package net.systemeD.halcyon.connection {
             }
             return -1;
         }
+
+        public function findEntityMemberIndexes(entity:Entity):Array {
+            var indexes:Array = [];
+            for (var index:uint = 0; index < members.length; index++) {
+                var member:RelationMember = members[index];
+                if ( member.entity == entity )
+                    indexes.push(index);
+            }
+            return indexes;
+        }
         
         public function getMember(index:uint):RelationMember {
             return members[index];
index 449c05f..e6053fd 100644 (file)
@@ -33,7 +33,7 @@
     </mx:DataGrid>
 
     <mx:HBox horizontalAlign="right" width="100%">
-      <mx:LinkButton label="Delete" click="removeTag()"/>
+      <mx:LinkButton label="Delete" click="removeTag()" enabled="{advancedTagGrid.selectedItem != null? true : false}"/>
       <mx:LinkButton label="Add" click="addNewTag()"/>
     </mx:HBox>
     
@@ -48,7 +48,8 @@
     </mx:DataGrid>
 
     <mx:HBox horizontalAlign="right" width="100%">
-      <mx:LinkButton label="Remove from" click="removeFromRelation()"/>
+      <mx:LinkButton label="Remove from" click="removeFromRelation(relationsGrid.selectedItem.id, relationsGrid.selectedItem.index)" 
+                      enabled="{relationsGrid.selectedItem != null? true : false}"/>
       <mx:LinkButton label="Add to" click="addToRelation()"/>
     </mx:HBox>
 
           } else {
               var relations:Array = [];
               for each( var rel:Relation in entity.parentRelations ) {
-                  var props:Object = {};
-                  props["relation"] = rel;
-                  props["id"] = rel.id;
-                  var memberIndex:uint = rel.findEntityMemberIndex(entity);
-                  props["role"] = rel.getMember(memberIndex).role;
-                  props["description"] = rel.getDescription();
-                  
-                  relations.push(props);
+                  for each( var memberIndex:int in rel.findEntityMemberIndexes(entity)) {
+                    var props:Object = {};
+                    props["relation"] = rel;
+                    props["id"] = rel.id;
+                    props["index"] = memberIndex;
+                    props["role"] = rel.getMember(memberIndex).role;
+                    props["description"] = rel.getDescription();
+                    
+                    relations.push(props);
+                  }
               }
               relationsGrid.dataProvider = relations;
           }
           new RelationSelectPanel().init(selectedEntity);        
       }
       
-      public function removeFromRelation():void {
+      public function removeFromRelation(id:Number, index:int):void {
+          Connection.getConnectionInstance().getRelation(id).removeMemberByIndex(index);
       }
       
       public function initFeatureBox():void {