Merge branch 'draganddrop'
authorRichard Fairhurst <richard@systemeD.net>
Sun, 25 Mar 2012 10:17:54 +0000 (11:17 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sun, 25 Mar 2012 10:17:54 +0000 (11:17 +0100)
1  2 
net/systemeD/potlatch2/TagViewer.mxml

index 354dada03e467c9e1a71e34e54fca19b53bff3f2,a3a2e75743872e952cce34e10b73dd80217f4a46..1994ce22b2353077cb89e3f4a22efa465bbe28a6
  
  <mx:ViewStack id="sidebar" width="100%" height="100%" creationPolicy="all">
  
-   <!-- Drag & drop icon panel -->
-   <mx:VBox id="dndPanel" width="100%" height="100%" horizontalScrollPolicy="off" styleName="dndPanelVbox">
-     <mx:Text id="dndPanelText" text="{dndPrompt}" width="100%" styleName="helpInfo" />
-       <mx:Repeater id="dndRep" dataProvider="{MapFeatures.getInstance().getCategoriesForType('point')}" styleName="dndRepeater">
-               <mx:HBox width="100%" styleName="dndPanelCategory">
-                       <mx:Label text="{dndRep.currentItem.name}:" styleName="dndPanelCategoryLabel"/>
-               </mx:HBox>
-               <mx:TileList dataProvider="{dndRep.currentItem.getFeaturesForType('point', true)}" width="100%" height="1"
-                                    rowHeight="32" columnWidth="32" updateComplete="resizePOIGrid(event)" styleName="dndPanelTileList">
-                       <mx:itemRenderer>
-                               <fx:Component>
-                                       <mx:VBox toolTip="{data.name}">
-                                               <fx:Script><![CDATA[
-                                                       import mx.events.DragEvent;
-                                                       import mx.managers.DragManager;
-                                                       import mx.core.DragSource;
-                                                       private function dragPOI(event:MouseEvent, tags:Array):void {
-                                                               if (outerDocument.controller.map.dragstate==outerDocument.controller.map.DRAGGING) return;
-                                                               // Get the drag initiator component from the event object.
-                                                               var dragInitiator:Image = event.currentTarget as Image;
-                                                               var dragSource:DragSource = new DragSource();
-                                                               dragSource.addData(tags, 'tags');
-                                                               dragSource.addData(event.target.parent.parent.parent.parent, 'container');
-                                                               var dragProxy:Image = new Image();
-                                                               dragProxy.source = dragInitiator.source;
-                                                               dragProxy.width = dragInitiator.width;   // must set width and height explicitly
-                                                               dragProxy.height = dragInitiator.height; // for non-embedded images
-                                                               DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);
-                                                       }
-                                               ]]></fx:Script>
-                                               <mx:Image id="foo" source="{data.dndimage}" height="24" width="24" mouseMove="dragPOI(event, data.tags)" toolTip="{data.name}" />
-                                       </mx:VBox>
-                               </fx:Component>
-                       </mx:itemRenderer>
-               </mx:TileList>
-       </mx:Repeater>
-   </mx:VBox>
+   <sidepanel:DragAndDropPanel id="dndPanel" />
  
    <!-- Standard tagging panel -->
  
        private var tabIcons:Object= { Basic:tabIconBasic, Details:tabIconDetails, Address:tabIconAddress, Walk:tabIconWalk, Cycle:tabIconCycle, 
                                         Transport:tabIconTransport, Restrictions:tabIconRestrictions};
  
-       [Bindable]
-       public var dndPrompt:String="Add new points by dragging them onto the map";
        private var editorStackTabNavigator:TabNavigator;
        private var editorStackAccordion:Accordion;
        [Bindable] private var editorStack:Container;
        private var connection:Connection;
        private var currentCategorySelector:CategorySelector;
        private var categorySelectors:Object = {};      // hash of categorySelectors for each limitType
 +      private var categorySelectorEntity:Entity;      // entity used to draw the categorySelector
        private var feature:Feature = null;
  
        private var rowData:Object;             // relation membership reference, needed so it's accessible from relation actions menu
                if (entities.length==0) {
                        // Nothing selected, so show drag-and-drop panel
                        sidebar.selectedChild = dndPanel;
 +                      selectedEntity=null;
  
                } else if (entities.length==1) {
                        // Single entity selected, so show tag panel
 +                      if (firstSelected!=null && selectedEntity!=firstSelected) { 
 +                              firstSelected.addEventListener(Connection.TAG_CHANGED, tagChanged, false, 0, true);
 +                      }
                        selectedEntity=firstSelected;
                        connection=firstSelected.connection;
 -                      if (selectedEntity!=null) { selectedEntity.addEventListener(Connection.TAG_CHANGED, tagChanged); }
                        if (advancedID!=null) { setupAdvanced(firstSelected); }
                        if (firstSelected is Relation) { stack.addChild(membersVBox); }
              if (selectedEntity is Marker && connection is BugConnection) {
                        && xor(!controller.map.getLayerForEntity(entities[0]).isBackground, !controller.map.getLayerForEntity(entities[1]).isBackground) ) {
              backgroundMergePanelContents.init(entities);
              sidebar.selectedChild = backgroundMergePanel;
 +                      // ** FIXME: do we need to set selectedEntity here?
  
                } else if(isMultipleEditable(entities)) {
                        selectedEntity = new EntityCollection(entities);
 -                      selectedEntity.addEventListener(Connection.TAG_CHANGED, tagChanged);
 +                      selectedEntity.addEventListener(Connection.TAG_CHANGED, tagChanged, false, 0, true);
              sidebar.selectedChild = multiplePanel;
                        setupMultiAdvanced(selectedEntity);
                        connection=entities[0].connection;
                } else {
                        //The selection contains elements which can't be edited all together.
                        sidebar.selectedChild = multipleInvalidPanel;
 +                      selectedEntity=null;
                }
                UIComponent.resumeBackgroundProcessing();
        }
  
        private function refreshFeatureIcon():void {
            var oldFeature:Feature = feature;
 +          var oldEntity:Entity = categorySelectorEntity;
 +
            feature = selectedEntity == null ? null : mapFeatures.findMatchingFeature(selectedEntity);
 -          if ( feature != oldFeature ) {
 -              if ( oldFeature != null )
 -                  oldFeature.removeEventListener("imageChanged", featureImageChanged);
 -              if ( feature != null )
 -                  feature.addEventListener("imageChanged", featureImageChanged);
 +          if (oldFeature==feature && categorySelectorEntity==selectedEntity) {
 +              updateCategoryImageAndText(selectedEntity,feature);
 +              return;
            }
 -          setCategorySelector(selectedEntity, feature);
 +
 +          categorySelectorEntity=selectedEntity;
 +          if ( oldFeature != null ) { oldFeature.removeEventListener("imageChanged", featureImageChanged); }
 +          if ( feature != null )    { feature.addEventListener("imageChanged", featureImageChanged); }
 +                setCategorySelector(selectedEntity, feature);
        }
  
        private function featureImageChanged(event:Event):void {
            setCategorySelector(selectedEntity, feature);
        }
  
 +
        /** Set the icon, categorySelector and help text for the current entity. */
        private function setCategorySelector(entity:Entity, feature:Feature):void {
                        // Remove the "user has selected something" event listener from previous categorySelector,
                        currentCategorySelector=categorySelectors[lt];
                        currentCategorySelector.addEventListener("selectedType", changeFeatureType, false, 0, true);
  
 -                      // Update surrounding icon/text display
 +                      updateCategoryImageAndText(entity,feature);
 +                      currentCategorySelector.setSelectedFeature(feature);
 +
 +                      // Set it as the popup, and make sure it's visible
 +                      popupChange.popUp=currentCategorySelector;
 +                      currentCategorySelector.visible=true;
 +      }
 +
 +      private function updateCategoryImageAndText(entity:Entity, feature:Feature):void {
                        if (feature) {
                                iconImage.source = feature.image;
                                iconText.htmlText = feature.htmlDetails(entity);
                                popupChange.label = feature.name;
                                helpLabel.visible = feature.hasHelpURL();
 -                              currentCategorySelector.setSelectedFeature(feature);
                        } else {
                                iconImage.source = null;
                                popupChange.label = "unknown";
                                } else {
                                        iconText.htmlText = "<b>No tags set</b><br/><font size='10pt'>Please use the menu below to define what this "+entity.getType()+" is</font>";
                                }
 -                              currentCategorySelector.setSelectedFeature(null);
                        }
 -
 -                      // Set it as the popup, and make sure it's visible
 -                      popupChange.popUp=currentCategorySelector;
 -                      currentCategorySelector.visible=true;
 -      }
 +        }
  
          private function isMultipleEditable(entities:Array):Boolean {
                for each(var entity:Entity in entities) {
            UIComponent.resumeBackgroundProcessing();
        }
  
-       private function resizePOIGrid(event:Event):void {
-               var rows:Number=event.target.dataProvider.length/event.target.columnCount;
-               if (rows!=Math.floor(rows)) { rows=Math.floor(rows+1); }
-               event.target.height=rows*(event.target.rowHeight+1);
-       }
    ]]></fx:Script>
  </mx:VBox>