text,length,is_long_context,metric_val,label_metric
"////////////////////////////////////////////////////////////////////////////////
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the ""License""); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an ""AS IS"" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package mx.controls
{
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.FocusEvent;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.text.TextLineMetrics;
import flash.ui.Keyboard;
import mx.collections.ArrayCollection;
import mx.collections.CursorBookmark;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
import mx.controls.listClasses.IDropInListItemRenderer;
import mx.controls.listClasses.IListItemRenderer;
import mx.controls.listClasses.ListBase;
import mx.controls.listClasses.ListData;
import mx.core.ClassFactory;
import mx.core.EdgeMetrics;
import mx.core.IDataRenderer;
import mx.core.IFactory;
import mx.core.LayoutDirection;
import mx.core.ScrollPolicy;
import mx.core.UIComponent;
import mx.core.UIComponentGlobals;
import mx.core.mx_internal;
import mx.effects.Tween;
import mx.events.CollectionEvent;
import mx.events.CollectionEventKind;
import mx.events.DropdownEvent;
import mx.events.FlexEvent;
import mx.events.FlexMouseEvent;
import mx.events.InterManagerRequest;
import mx.events.ListEvent;
import mx.events.SandboxMouseEvent;
import mx.events.ScrollEvent;
import mx.events.ScrollEventDetail;
import mx.managers.ISystemManager;
import mx.managers.PopUpManager;
import mx.styles.CSSStyleDeclaration;
import mx.utils.MatrixUtil;
use namespace mx_internal;
//--------------------------------------
// Events
//--------------------------------------
/**
* Dispatched when the ComboBox contents changes as a result of user
* interaction, when the selectedIndex or
* selectedItem property changes, and, if the ComboBox control
* is editable, each time a keystroke is entered in the box.
*
* @eventType mx.events.ListEvent.CHANGE
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Event(name=""change"", type=""mx.events.ListEvent"")]
/**
* Dispatched when the drop-down list is dismissed for any reason such when
* the user:
*
* - selects an item in the drop-down list
* - clicks outside of the drop-down list
* - clicks the drop-down button while the drop-down list is
* displayed
* - presses the ESC key while the drop-down list is displayed
*
*
* @eventType mx.events.DropdownEvent.CLOSE
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Event(name=""close"", type=""mx.events.DropdownEvent"")]
/**
* Dispatched when the data property changes.
*
* When you use a component as an item renderer,
* the data property contains an item from the
* dataProvider.
* You can listen for this event and update the component
* when the data property changes.
*
* @eventType mx.events.FlexEvent.DATA_CHANGE
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Event(name=""dataChange"", type=""mx.events.FlexEvent"")]
/**
* Dispatched if the editable property
* is set to true and the user presses the Enter key
* while typing in the editable text field.
*
* @eventType mx.events.FlexEvent.ENTER
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Event(name=""enter"", type=""mx.events.FlexEvent"")]
/**
* Dispatched when user rolls the mouse out of a drop-down list item.
* The event object's target property contains a reference
* to the ComboBox and not the drop-down list.
*
* @eventType mx.events.ListEvent.ITEM_ROLL_OUT
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Event(name=""itemRollOut"", type=""mx.events.ListEvent"")]
/**
* Dispatched when the user rolls the mouse over a drop-down list item.
* The event object's target property contains a reference
* to the ComboBox and not the drop-down list.
*
* @eventType mx.events.ListEvent.ITEM_ROLL_OVER
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Event(name=""itemRollOver"", type=""mx.events.ListEvent"")]
/**
* Dispatched when the user clicks the drop-down button
* to display the drop-down list. It is also dispatched if the user
* uses the keyboard and types Ctrl-Down to open the drop-down.
*
* @eventType mx.events.DropdownEvent.OPEN
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Event(name=""open"", type=""mx.events.DropdownEvent"")]
/**
* Dispatched when the user scrolls the ComboBox control's drop-down list.
*
* @eventType mx.events.ScrollEvent.SCROLL
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Event(name=""scroll"", type=""mx.events.ScrollEvent"")]
//--------------------------------------
// Styles
//--------------------------------------
include ""../styles/metadata/FocusStyles.as""
include ""../styles/metadata/IconColorStyles.as""
include ""../styles/metadata/LeadingStyle.as""
include ""../styles/metadata/PaddingStyles.as""
include ""../styles/metadata/SkinStyles.as""
include ""../styles/metadata/TextStyles.as""
/**
* The set of BackgroundColors for drop-down list rows in an alternating
* pattern.
* Value can be an Array of two of more colors.
* If undefined then the rows will use the drop-down list's
* backgroundColor style.
*
* @default undefined
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""alternatingItemColors"", type=""Array"", arrayType=""uint"", format=""Color"", inherit=""yes"")]
/**
* Width of the arrow button in pixels.
*
* The default value for the Halo theme is 22.
* The default value for the Spark theme is 18.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""arrowButtonWidth"", type=""Number"", format=""Length"", inherit=""no"")]
/**
* The thickness of the border of the drop-down list, in pixels.
* This value is overridden if you define
* borderThickness when setting the
* dropdownStyleName CSSStyleDeclaration.
*
* @default 1
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""borderThickness"", type=""Number"", format=""Length"", inherit=""no"")]
/**
* The length of the transition when the drop-down list closes, in milliseconds.
* The default transition has the drop-down slide up into the ComboBox.
*
* The default value for the Halo theme is 250.
* The default value for the Spark theme is 50.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""closeDuration"", type=""Number"", format=""Time"", inherit=""no"")]
/**
* An easing function to control the close transition. Easing functions can
* be used to control the acceleration and deceleration of the transition.
*
* @default undefined
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""closeEasingFunction"", type=""Function"", inherit=""no"")]
/**
* The color of the border of the ComboBox. If undefined
* the drop-down list will use its normal borderColor style. This style
* is used by the validators to show the ComboBox in an error state.
*
* @default undefined
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""dropdownBorderColor"", type=""uint"", format=""Color"", inherit=""yes"", theme=""halo"")]
/**
* The name of a CSSStyleDeclaration to be used by the drop-down list. This
* allows you to control the appearance of the drop-down list or its item
* renderers.
*
* [deprecated]
*
* @default ""comboDropDown""
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""dropDownStyleName"", type=""String"", inherit=""no"", deprecatedReplacement=""dropdownStyleName"")]
/**
* The name of a CSSStyleDeclaration to be used by the drop-down list. This
* allows you to control the appearance of the drop-down list or its item
* renderers.
*
* @default ""comboDropdown""
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""dropdownStyleName"", type=""String"", inherit=""no"")]
/**
* Length of the transition when the drop-down list opens, in milliseconds.
* The default transition has the drop-down slide down from the ComboBox.
*
* The default value for the Halo theme is 250.
* The default value for the Spark theme is 0.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""openDuration"", type=""Number"", format=""Time"", inherit=""no"")]
/**
* An easing function to control the open transition. Easing functions can
* be used to control the acceleration and deceleration of the transition.
*
* @default undefined
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""openEasingFunction"", type=""Function"", inherit=""no"")]
/**
* Number of pixels between the control's bottom border
* and the bottom of its content area.
* When the editable property is true,
* paddingTop and paddingBottom affect the size
* of the ComboBox control, but do not affect the position of the editable text field.
*
* The default value for the Halo theme is 0.
* The default value for the Spark theme is -2.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""paddingBottom"", type=""Number"", format=""Length"", inherit=""no"")]
/**
* Number of pixels between the control's top border
* and the top of its content area.
* When the editable property is true,
* paddingTop and paddingBottom affect the size
* of the ComboBox control, but do not affect the position of the editable text field.
*
* The default value for the Halo theme is 0.
* The default value for the Spark theme is -1.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""paddingTop"", type=""Number"", format=""Length"", inherit=""no"")]
/**
* The rollOverColor of the drop-down list.
*
* The default value for the Halo theme is 0xB2E1FF.
* The default value for the Spark theme is 0xCEDBEF.
*
* @see mx.controls.List
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""rollOverColor"", type=""uint"", format=""Color"", inherit=""yes"")]
/**
* The selectionColor of the drop-down list.
*
* The default value for the Halo theme is 0x7FCEFF.
* The default value for the Spark theme is 0xA8C6EE.
*
* @see mx.controls.List
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""selectionColor"", type=""uint"", format=""Color"", inherit=""yes"")]
/**
* The selectionDuration of the drop-down list.
*
* @default 250
*
* @see mx.controls.List
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""selectionDuration"", type=""uint"", format=""Time"", inherit=""no"")]
/**
* The selectionEasingFunction of the drop-down list.
*
* @default undefined
*
* @see mx.controls.List
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""selectionEasingFunction"", type=""Function"", inherit=""no"")]
/**
* The textRollOverColor of the drop-down list.
*
* The default value for the Halo theme is 0x2B333C.
* The default value for the Spark theme is 0x000000.
*
* @see mx.controls.List
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""textRollOverColor"", type=""uint"", format=""Color"", inherit=""yes"")]
/**
* The textSelectedColor of the drop-down list.
*
* The default value for the Halo theme is 0x2B333C.
* The default value for the Spark theme is 0x000000.
*
* @see mx.controls.List
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Style(name=""textSelectedColor"", type=""uint"", format=""Color"", inherit=""yes"")]
//--------------------------------------
// Other metadata
//--------------------------------------
[AccessibilityClass(implementation=""mx.accessibility.ComboBoxAccImpl"")]
[DataBindingInfo(""acceptedTypes"", ""{ dataProvider: { label: "String" } }"")]
[DefaultBindingProperty(source=""selectedItem"", destination=""dataProvider"")]
[DefaultProperty(""dataProvider"")]
[DefaultTriggerEvent(""change"")]
[IconFile(""ComboBox.png"")]
[Alternative(replacement=""spark.components.DropDownList"", since=""4.0"")]
[Alternative(replacement=""spark.components.ComboBox"", since=""4.0"")]
/**
* The ComboBox control contains a drop-down list
* from which the user can select a single value.
* Its functionality is very similar to that of the
* SELECT form element in HTML.
* The ComboBox can be editable, in which case
* the user can type entries into the TextInput portion
* of the ComboBox that are not in the list.
*
* The ComboBox control has the following default sizing
* characteristics:
*
*
* | Characteristic |
* Description |
*
*
* | Default size |
* Wide enough to accommodate the longest entry in the
* drop-down list in the display area of the main
* control, plus the drop-down button. When the
* drop-down list is not visible, the default height
* is based on the label text size.
*
* The default drop-down list height is five rows, or
* the number of entries in the drop-down list, whichever
* is smaller. The default height of each entry in the
* drop-down list is 22 pixels. |
*
*
* | Minimum size |
* 0 pixels. |
*
*
* | Maximum size |
* 5000 by 5000. |
*
*
* | dropdownWidth |
* The width of the ComboBox control. |
*
*
* | rowCount |
* 5 rows. |
*
*
*
* @mxml
*
* The <mx:ComboBox> tag inherits all the tag attributes
* of its superclass, and adds the following tag attributes:
*
*
* <mx:ComboBox
* Properties
* dataProvider=""null""
* dropdownFactory=""ClassFactory that creates an mx.controls.List""
* dropdownWidth=""100 or width of the longest text in the dataProvider""
* itemRenderer=""null""
* labelField=""label""
* labelFunction=""null""
* prompt=""null""
* rowCount=""5""
* selectedIndex=""-1""
* selectedItem=""null""
*
* Styles
* alternatingItemColors=""undefined""
* arrowButtonWidth=""22""
* borderColor=""0xB7BABC""
* borderThickness=""1""
* closeDuration=""250""
* closeEasingFunction=""undefined""
* color=""0x0B333C""
* cornerRadius=""0""
* disabledColor=""0xAAB3B3""
* disabledIconColor=""0x919999""
* dropdownBorderColor=""undefined""
* dropdownStyleName=""comboDropdown""
* fillAlphas=""[0.6,0.4]""
* fillColors=""[0xFFFFFF, 0xCCCCCC]""
* focusAlpha=""0.4""
* focusRoundedCorners=""tl tr bl br""
* fontAntiAliasType=""advanced|normal""
* fontFamily=""Verdana""
* fontGridFitType=""pixel|none|subpixel""
* fontSharpness=""0""
* fontSize=""10""
* fontStyle=""normal|italic""
* fontThickness=""0""
* fontWeight=""normal|bold""
* highlightAlphas=""[0.3,0.0]""
* iconColor=""0x111111""
* leading=""0""
* openDuration=""250""
* openEasingFunction=""undefined""
* paddingTop=""0""
* paddingBottom=""0""
* paddingLeft=""5""
* paddingRight=""5""
* rollOverColor=""Depends on theme color""
* selectionColor=""Depends on theme color""
* selectionDuration=""250""
* selectionEasingFunction=""undefined""
* textAlign=""left|center|right""
* textDecoration=""none|underline""
* textIndent=""0""
* textRollOverColor=""0x2B333C""
* textSelectedColor=""0x2B333C""
*
* Events
* change=""No default""
* close=""No default""
* dataChange=""No default""
* enter=""No default""
* itemRollOut=""No default""
* itemRollOver=""No default""
* open=""No default""
* scroll=""No default""
* />
*
*
* @includeExample examples/SimpleComboBox.mxml
*
* @see mx.controls.List
* @see mx.effects.Tween
* @see mx.managers.PopUpManager
*
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public class ComboBox extends ComboBase
implements IDataRenderer, IDropInListItemRenderer,
IListItemRenderer
{
include ""../core/Version.as"";
//--------------------------------------------------------------------------
//
// Class mixins
//
//--------------------------------------------------------------------------
/**
* @private
* Placeholder for mixin by ComboBoxAccImpl.
*/
mx_internal static var createAccessibilityImplementation:Function;
//--------------------------------------------------------------------------
//
// Constructor
//
//--------------------------------------------------------------------------
/**
* Constructor.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function ComboBox()
{
super();
// It it better to start out with an empty data provider rather than
// an undefined one. Otherwise, code in getDropdown() sets it to []
// later, but via setDataProvider(). This API has side effects like
// setting selectionChanged, which causes the text in an editable
// ComboBox to be lost.
dataProvider = new ArrayCollection();
useFullDropdownSkin = true;
wrapDownArrowButton = false;
addEventListener(""unload"", unloadHandler);
addEventListener(Event.REMOVED_FROM_STAGE, removedFromStageHandler);
}
//--------------------------------------------------------------------------
//
// Variables
//
//--------------------------------------------------------------------------
/**
* @private
* A reference to the internal List that pops up to display a row
* for each dataProvider item.
*/
private var _dropdown:ListBase;
/**
* @private
* A int to track the oldIndex, used when the dropdown is dismissed using the ESC key.
*/
private var _oldIndex:int;
/**
* @private
* The tween used for showing and hiding the drop-down list.
*/
private var tween:Tween = null;
/**
* @private
* A flag to track whether the dropDown tweened up or down.
*/
private var tweenUp:Boolean = false;
/**
* @private
*/
private var preferredDropdownWidth:Number;
/**
* @private
*/
private var dropdownBorderStyle:String = ""solid"";
/**
* @private
* Is the dropdown list currently shown?
*/
private var _showingDropdown:Boolean = false;
/**
* @private
*/
private var _selectedIndexOnDropdown:int = -1;
/**
* @private
*/
private var bRemoveDropdown:Boolean = true;
/**
* @private
*/
private var inTween:Boolean = false;
/**
* @private
*/
private var bInKeyDown:Boolean = false;
/**
* @private
* Flag that will block default data/listData behavior
*/
private var selectedItemSet:Boolean;
/**
* @private
* Event that is causing the dropDown to open or close.
*/
private var triggerEvent:Event;
/**
* @private
* Whether the text property was explicitly set or not
*/
private var explicitText:Boolean;
//--------------------------------------------------------------------------
//
// Overridden properties
//
//--------------------------------------------------------------------------
//----------------------------------
// data
//----------------------------------
/**
* @private
* Storage for the data property.
*/
private var _data:Object;
[Bindable(""dataChange"")]
[Inspectable(environment=""none"")]
/**
* The data property lets you pass a value
* to the component when you use it in an item renderer or item editor.
* You typically use data binding to bind a field of the data
* property to a property of this component.
*
* The ComboBox control uses the listData property and the
* data property as follows. If the ComboBox is in a
* DataGrid control, it expects the dataField property of the
* column to map to a property in the data and sets
* selectedItem to that property. If the ComboBox control is
* in a List control, it expects the labelField of the list
* to map to a property in the data and sets selectedItem to
* that property.
* Otherwise, it sets selectedItem to the data itself.
*
* You do not set this property in MXML.
*
* @see mx.core.IDataRenderer
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get data():Object
{
return _data;
}
/**
* @private
*/
public function set data(value:Object):void
{
var newSelectedItem:*;
_data = value;
if (_listData && _listData is DataGridListData)
newSelectedItem = _data[DataGridListData(_listData).dataField];
else if (_listData is ListData && ListData(_listData).labelField in _data)
newSelectedItem = _data[ListData(_listData).labelField];
else
newSelectedItem = _data;
if (newSelectedItem !== undefined && !selectedItemSet)
{
selectedItem = newSelectedItem;
selectedItemSet = false;
}
dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
}
//----------------------------------
// listData
//----------------------------------
/**
* @private
* Storage for the listData property.
*/
private var _listData:BaseListData;
[Bindable(""dataChange"")]
[Inspectable(environment=""none"")]
/**
* When a component is used as a drop-in item renderer or drop-in item
* editor, Flex initializes the listData property of the
* component with the appropriate data from the List control. The
* component can then use the listData property and the
* data property to display the appropriate information
* as a drop-in item renderer or drop-in item editor.
*
* You do not set this property in MXML or ActionScript; Flex sets it
* when the component
* is used as a drop-in item renderer or drop-in item editor.
*
* @see mx.controls.listClasses.IDropInListItemRenderer
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get listData():BaseListData
{
return _listData;
}
/**
* @private
*/
public function set listData(value:BaseListData):void
{
_listData = value;
}
//----------------------------------
// dataProvider
//----------------------------------
/**
* @private
*/
private var collectionChanged:Boolean = false;
[Bindable(""collectionChange"")]
[Inspectable(category=""Data"", arrayType=""Object"")]
/**
* @inheritDoc
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
override public function set dataProvider(value:Object):void
{
selectionChanged = true;
super.dataProvider = value;
destroyDropdown();
invalidateProperties();
invalidateSize();
}
//----------------------------------
// itemRenderer
//----------------------------------
/**
* @private
* Storage for itemRenderer property.
*/
private var _itemRenderer:IFactory;
[Inspectable(category=""Data"")]
/**
* IFactory that generates the instances that displays the data for the
* drop-down list of the control. You can use this property to specify
* a custom item renderer for the drop-down list.
*
* The control uses a List control internally to create the drop-down
* list.
* The default item renderer for the List control is the ListItemRenderer
* class, which draws the text associated with each item in the list,
* and an optional icon.
*
* @see mx.controls.List
* @see mx.controls.listClasses.ListItemRenderer
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get itemRenderer():IFactory
{
return _itemRenderer;
}
/**
* @private
*/
public function set itemRenderer(value:IFactory):void
{
_itemRenderer = value;
if (_dropdown)
_dropdown.itemRenderer = value;
invalidateSize();
invalidateDisplayList();
dispatchEvent(new Event(""itemRendererChanged""));
}
//----------------------------------
// selectedIndex
//----------------------------------
[Bindable(""change"")]
[Bindable(""collectionChange"")]
[Bindable(""valueCommit"")]
[Inspectable(category=""General"", defaultValue=""0"")]
/**
* Index of the selected item in the drop-down list.
* Setting this property sets the current index and displays
* the associated label in the TextInput portion.
* The default value is -1, but it set to 0
* when a dataProvider is assigned, unless there is a prompt.
* If the control is editable, and the user types in the TextInput portion,
* the value of the selectedIndex property becomes
* -1. If the value of the selectedIndex
* property is out of range, the selectedIndex property is set to the last
* item in the dataProvider.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
override public function set selectedIndex(value:int):void
{
super.selectedIndex = value;
if (value >= 0)
selectionChanged = true;
implicitSelectedIndex = false;
invalidateDisplayList();
// value committed event needs the text to be set
if (textInput && !textChanged && value >= 0)
textInput.text = selectedLabel;
else if (textInput && prompt)
textInput.text = prompt;
// [Matt] setting the text of the textInput should take care of this now
// Send a valueCommit event, which is used by the data model
//dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
}
//----------------------------------
// selectedItem
//----------------------------------
[Bindable(""change"")]
[Bindable(""collectionChange"")]
[Bindable(""valueCommit"")]
/**
* Contains a reference to the selected item in the
* dataProvider.
* If the data is an object or class instance, modifying
* properties in the object or instance modifies the dataProvider
* and thus its views. Setting the selectedItem itself causes the
* ComboBox to select that item (display it in the TextInput portion and set
* the selectedIndex) if it exists in the dataProvider.
* If the ComboBox control is editable, the selectedItem
* property is null if the user types any text
* into the TextInput.
* It has a value only if the user selects an item from the drop-down
* list, or if it is set programmatically.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
override public function set selectedItem(value:Object):void
{
selectedItemSet = true;
// We do not want to apply an implicit default index in this case.
implicitSelectedIndex = false;
super.selectedItem = value;
}
//----------------------------------
// showInAutomationHierarchy
//----------------------------------
/**
* @private
*/
override public function set showInAutomationHierarchy(value:Boolean):void
{
//do not allow value changes
}
//--------------------------------------------------------------------------
//
// Properties
//
//--------------------------------------------------------------------------
//----------------------------------
// dropdown
//----------------------------------
/**
* A reference to the List control that acts as the drop-down in the ComboBox.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get dropdown():ListBase
{
return getDropdown();
}
//----------------------------------
// dropdownFactory
//----------------------------------
/**
* @private
* Storage for the dropdownFactory property.
*/
private var _dropdownFactory:IFactory = new ClassFactory(List);
[Bindable(""dropdownFactoryChanged"")]
/**
* The IFactory that creates a ListBase-derived instance to use
* as the drop-down.
* The default value is an IFactory for List
*
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get dropdownFactory():IFactory
{
return _dropdownFactory;
}
/**
* @private
*/
public function set dropdownFactory(value:IFactory):void
{
_dropdownFactory = value;
dispatchEvent(new Event(""dropdownFactoryChanged""));
}
//----------------------------------
// dropDownStyleFilters
//----------------------------------
/**
* The set of styles to pass from the ComboBox to the dropDown.
* Styles in the dropDownStyleName style will override these styles.
* @see mx.styles.StyleProxy
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
protected function get dropDownStyleFilters():Object
{
return null;
}
//----------------------------------
// dropdownWidth
//----------------------------------
/**
* @private
* Storage for the dropdownWidth property.
*/
private var _dropdownWidth:Number = 100;
[Bindable(""dropdownWidthChanged"")]
[Inspectable(category=""Size"", defaultValue=""100"")]
/**
* Width of the drop-down list, in pixels.
* The default value is 100 or the width of the longest text
* in the dataProvider, whichever is greater.
*
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get dropdownWidth():Number
{
return _dropdownWidth;
}
/**
* @private
*/
public function set dropdownWidth(value:Number):void
{
_dropdownWidth = value;
preferredDropdownWidth = value;
if (_dropdown)
_dropdown.setActualSize(value, _dropdown.height);
dispatchEvent(new Event(""dropdownWidthChanged""));
}
//----------------------------------
// labelField
//----------------------------------
/**
* @private
* Storage for the labelField property.
*/
private var _labelField:String = ""label"";
/**
* @private
*/
private var labelFieldChanged:Boolean;
[Bindable(""labelFieldChanged"")]
[Inspectable(category=""Data"", defaultValue=""label"")]
/**
* Name of the field in the items in the dataProvider
* Array to display as the label in the TextInput portion and drop-down list.
* By default, the control uses a property named label
* on each Array object and displays it.
* However, if the dataProvider items do not contain
* a label property, you can set the labelField
* property to use a different property.
*
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get labelField():String
{
return _labelField;
}
/**
* @private
*/
public function set labelField(value:String):void
{
_labelField = value;
labelFieldChanged = true;
invalidateDisplayList();
dispatchEvent(new Event(""labelFieldChanged""));
}
//----------------------------------
// labelFunction
//----------------------------------
/**
* @private
* Storage for the labelFunction property.
*/
private var _labelFunction:Function;
/**
* @private
*/
private var labelFunctionChanged:Boolean;
[Bindable(""labelFunctionChanged"")]
[Inspectable(category=""Data"")]
/**
* User-supplied function to run on each item to determine its label.
* By default the control uses a property named label
* on each dataProvider item to determine its label.
* However, some data sets do not have a label property,
* or do not have another property that can be used for displaying
* as a label.
* An example is a data set that has lastName and
* firstName fields but you want to display full names.
* You use labelFunction to specify a callback function
* that uses the appropriate fields and return a displayable String.
*
* The labelFunction takes a single argument which is the item
* in the dataProvider and returns a String:
*
* myLabelFunction(item:Object):String
*
*
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get labelFunction():Function
{
return _labelFunction;
}
/**
* @private
*/
public function set labelFunction(value:Function):void
{
_labelFunction = value;
labelFunctionChanged = true;
invalidateDisplayList();
dispatchEvent(new Event(""labelFunctionChanged""));
}
//----------------------------------
// prompt
//----------------------------------
private var promptChanged:Boolean = false;
/**
* @private
* Storage for the prompt property.
*/
private var _prompt:String;
[Inspectable(category=""General"")]
/**
* The prompt for the ComboBox control. A prompt is
* a String that is displayed in the TextInput portion of the
* ComboBox when selectedIndex = -1. It is usually
* a String like ""Select one..."". If there is no
* prompt, the ComboBox control sets selectedIndex to 0
* and displays the first item in the dataProvider.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get prompt():String
{
return _prompt;
}
/**
* @private
*/
public function set prompt(value:String):void
{
_prompt = value;
promptChanged = true;
invalidateProperties();
}
//----------------------------------
// rowCount
//----------------------------------
/**
* @private
* Storage for the rowCount property.
*/
private var _rowCount:int = 5;
[Bindable(""resize"")]
[Inspectable(category=""General"", defaultValue=""5"")]
/**
* Maximum number of rows visible in the ComboBox control list.
* If there are fewer items in the
* dataProvider, the ComboBox shows only as many items as
* there are in the dataProvider.
*
* @default 5
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get rowCount():int
{
return Math.max(1, Math.min(collection.length, _rowCount));
}
/**
* @private
*/
public function set rowCount(value:int):void
{
_rowCount = value;
if (_dropdown)
_dropdown.rowCount = value;
}
//----------------------------------
// selectedLabel
//----------------------------------
/**
* The String displayed in the TextInput portion of the ComboBox. It
* is calculated from the data by using the labelField
* or labelFunction.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function get selectedLabel():String
{
return itemToLabel(selectedItem);
}
//--------------------------------------------------------------------------
//
// Overridden methods: UIComponent
//
//--------------------------------------------------------------------------
/**
* @private
*/
override protected function initializeAccessibility():void
{
if (ComboBox.createAccessibilityImplementation != null)
ComboBox.createAccessibilityImplementation(this);
}
/**
* @private
*/
override public function styleChanged(styleProp:String):void
{
destroyDropdown();
super.styleChanged(styleProp);
}
/**
* Makes sure the control is at least 40 pixels wide,
* and tall enough to fit one line of text
* in the TextInput portion of the control but at least
* 22 pixels high.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
override protected function measure():void
{
super.measure();
// Make sure we're not too small
measuredMinWidth = Math.max(measuredWidth, DEFAULT_MEASURED_MIN_WIDTH);
// Make sure we're tall enough to hold our text.
// Text field height is text height + 4 pixels top/bottom
var textHeight:Number = measureText(""M"").height + 6;
var bm:EdgeMetrics = borderMetrics;
measuredMinHeight = measuredHeight =
Math.max(textHeight + bm.top + bm.bottom, DEFAULT_MEASURED_MIN_HEIGHT);
measuredMinHeight = measuredHeight += getStyle(""paddingTop"") + getStyle(""paddingBottom"");
}
/**
* @private
* Make sure the drop-down width is the same as the rest of the ComboBox
*/
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
// we toss the dropdown when resized
// except if we're opening the dropdown
// then we assume the updateDisplayList() call is spurious
// and will not affect the dropdown size
if (_dropdown && !inTween)
{
// We will not destroy our dropdown if user is actively
// interacting with it, this has been legacy behavior since
// Flex 3.0.
if (!_showingDropdown)
destroyDropdown();
}
else if (_showingDropdown)
{
bRemoveDropdown = false;
}
var ddw:Number = preferredDropdownWidth;
if (isNaN(ddw))
ddw = _dropdownWidth = unscaledWidth;
if (labelFieldChanged)
{
if (_dropdown)
_dropdown.labelField = _labelField;
selectionChanged = true;
if (!explicitText)
textInput.text = selectedLabel;
labelFieldChanged = false;
}
if (labelFunctionChanged)
{
selectionChanged = true;
if (!explicitText)
textInput.text = selectedLabel;
labelFunctionChanged = false;
}
if (selectionChanged)
{
if (!textChanged)
{
if (selectedIndex == -1 && prompt)
textInput.text = prompt;
else if (!explicitText)
textInput.text = selectedLabel;
}
textInput.invalidateDisplayList();
textInput.validateNow();
if (editable)
{
textInput.selectRange(0, textInput.text.length);
textInput.horizontalScrollPosition = 0;
}
if (_dropdown)
_dropdown.selectedIndex = selectedIndex;
selectionChanged = false;
}
// We might need to decrease the number of rows.
if (_dropdown && _dropdown.rowCount != rowCount)
_dropdown.rowCount = rowCount;
}
/**
* @private
*/
override protected function commitProperties():void
{
explicitText = textChanged;
super.commitProperties();
if (collectionChanged)
{
if (selectedIndex == -1 && implicitSelectedIndex && _prompt == null)
selectedIndex = 0;
selectedIndexChanged = true;
collectionChanged = false;
}
if (promptChanged && prompt != null && selectedIndex == -1)
{
promptChanged = false;
textInput.text = prompt;
}
}
//--------------------------------------------------------------------------
//
// Methods
//
//--------------------------------------------------------------------------
/**
* Returns a string representing the item parameter.
*
* This method checks in the following order to find a value to return:
*
*
* - If you have specified a
labelFunction property,
* returns the result of passing the item to the function.
* - If the item is a String, Number, Boolean, or Function, returns
* the item.
* - If the item has a property with the name specified by the control's
*
labelField property, returns the contents of the property.
* - If the item has a label property, returns its value.
*
*
* @param item The object that contains the value to convert to a label.
* If the item is null, this method returns the empty string.
*
* @return A string representing the item parameter.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function itemToLabel(item:Object, ...rest):String
{
// rest args are needed in case dropdown is some other thing like DataGrid
// that has multiple arguments to labelFunction
// we need to check for null explicitly otherwise
// a numeric zero will not get properly converted to a string.
// (do not use !item)
if (item == null)
return """";
if (labelFunction != null)
return labelFunction(item);
if (typeof(item) == ""object"")
{
try
{
if (item[labelField] != null)
item = item[labelField];
}
catch(e:Error)
{
}
}
else if (typeof(item) == ""xml"")
{
try
{
if (item[labelField].length() != 0)
item = item[labelField];
}
catch(e:Error)
{
}
}
if (typeof(item) == ""string"")
return String(item);
try
{
return item.toString();
}
catch(e:Error)
{
}
return "" "";
}
/**
* Displays the drop-down list.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function open():void
{
displayDropdown(true);
}
/**
* Hides the drop-down list.
*
* @param trigger The event to dispatch when the
* drop-down list closes.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function close(trigger:Event = null):void
{
if (_showingDropdown)
{
if (_dropdown && selectedIndex != _dropdown.selectedIndex)
selectedIndex = _dropdown.selectedIndex;
displayDropdown(false, trigger);
dispatchChangeEvent(new Event(""dummy""),
_selectedIndexOnDropdown,
selectedIndex);
}
}
/**
* @private
*/
mx_internal function hasDropdown():Boolean
{
return _dropdown != null;
}
/**
* @private
*/
private function getDropdown():ListBase
{
if (!initialized)
return null;
if (!hasDropdown())
{
var dropDownStyleName:String = getStyle(""dropDownStyleName"");
if (dropDownStyleName == null )
dropDownStyleName = getStyle(""dropdownStyleName"");
_dropdown = dropdownFactory.newInstance();
_dropdown.visible = false;
_dropdown.focusEnabled = false;
_dropdown.owner = this;
if (itemRenderer)
_dropdown.itemRenderer = itemRenderer;
if (dropDownStyleName)
_dropdown.styleName = dropDownStyleName;
PopUpManager.addPopUp(_dropdown, this);
// Don't display a tween when the selection changes.
// The dropdown menu is about to appear anyway,
// and other processing can make the tween look choppy.
_dropdown.setStyle(""selectionDuration"", 0);
// Set up a data provider in case one doesn't yet exist,
// so we can share it with the dropdown listbox.
if (!dataProvider)
dataProvider = new ArrayCollection();
_dropdown.dataProvider = dataProvider;
_dropdown.rowCount = rowCount;
_dropdown.width = _dropdownWidth;
_dropdown.selectedIndex = selectedIndex;
_oldIndex = selectedIndex;
_dropdown.verticalScrollPolicy = ScrollPolicy.AUTO;
_dropdown.labelField = _labelField;
_dropdown.labelFunction = itemToLabel;
_dropdown.allowDragSelection = true;
_dropdown.addEventListener(""change"", dropdown_changeHandler);
_dropdown.addEventListener(ScrollEvent.SCROLL, dropdown_scrollHandler);
_dropdown.addEventListener(ListEvent.ITEM_ROLL_OVER, dropdown_itemRollOverHandler);
_dropdown.addEventListener(ListEvent.ITEM_ROLL_OUT, dropdown_itemRollOutHandler);
// the drop down should close if the user clicks on any item.
// add a handler to detect a click in the list
_dropdown.addEventListener(ListEvent.ITEM_CLICK, dropdown_itemClickHandler);
UIComponentGlobals.layoutManager.validateClient(_dropdown, true);
_dropdown.setActualSize(_dropdownWidth, _dropdown.getExplicitOrMeasuredHeight());
_dropdown.validateDisplayList();
_dropdown.cacheAsBitmap = true;
// weak reference to stage
systemManager.addEventListener(Event.RESIZE, stage_resizeHandler, false, 0, true);
}
var m:Matrix = MatrixUtil.getConcatenatedMatrix(this, systemManager.getSandboxRoot());
_dropdown.scaleX = m.a; //scale x
_dropdown.scaleY = m.d; //scale y
return _dropdown;
}
/**
* @private
*/
private function displayDropdown(show:Boolean, trigger:Event = null, playEffect:Boolean = true):void
{
if (!initialized || show == _showingDropdown)
return;
if (inTween && tween)
tween.endTween();
// Subclasses may extend to do pre-processing
// before the dropdown is displayed
// or override to implement special display behavior
// Show or hide the dropdown
var initY:Number;
var endY:Number;
var duration:Number;
var easingFunction:Function;
var point:Point = new Point(0, unscaledHeight);
point = localToGlobal(point);
var sm:ISystemManager = systemManager.topLevelSystemManager;
var screen:Rectangle = sm.getVisibleApplicationRect(null, true);
//opening the dropdown
if (show)
{
// Store the selectedIndex temporarily so we can tell
// if the value changed when the dropdown is closed
_selectedIndexOnDropdown = selectedIndex;
getDropdown();
_dropdown.addEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE, dropdown_mouseOutsideHandler);
_dropdown.addEventListener(FlexMouseEvent.MOUSE_WHEEL_OUTSIDE, dropdown_mouseOutsideHandler);
_dropdown.addEventListener(SandboxMouseEvent.MOUSE_DOWN_SOMEWHERE, dropdown_mouseOutsideHandler);
_dropdown.addEventListener(SandboxMouseEvent.MOUSE_WHEEL_SOMEWHERE, dropdown_mouseOutsideHandler);
if (_dropdown.parent == null) // was popped up then closed
PopUpManager.addPopUp(_dropdown, this);
else
PopUpManager.bringToFront(_dropdown);
// if we donot have enough space in the bottom display the dropdown
// at the top. But if the space there is also less than required
// display it below.
if (point.y + _dropdown.height > screen.bottom &&
point.y > screen.top + _dropdown.height)
{
// Dropdown will go below the bottom of the stage
// and be clipped. Instead, have it grow up.
point.y -= (unscaledHeight + _dropdown.height);
initY = -_dropdown.height;
tweenUp = true;
}
else
{
initY = _dropdown.height;
tweenUp = false;
}
point = _dropdown.parent.globalToLocal(point);
// If the combobox's layout is mirrored then the the dropdown's
// will be too. That also means that (stage coordinate) point.x is
// currently the right edge of the dropdown. Fix that:
if (layoutDirection == LayoutDirection.RTL)
point.x -= _dropdown.width;
var sel:int = _dropdown.selectedIndex;
if (sel == -1)
sel = 0;
var pos:Number = _dropdown.verticalScrollPosition;
// try to set the verticalScrollPosition one above the selected index so
// it looks better when the dropdown is displayed
pos = sel - 1;
pos = Math.min(Math.max(pos, 0), _dropdown.maxVerticalScrollPosition);
_dropdown.verticalScrollPosition = pos;
if (_dropdown.x != point.x || _dropdown.y != point.y)
_dropdown.move(point.x, point.y);
_dropdown.scrollRect = new Rectangle(0, initY,
_dropdown.width, _dropdown.height);
if (!_dropdown.visible)
_dropdown.visible = true;
// Make sure we don't remove the dropdown at the end of the tween
bRemoveDropdown = false;
// Set up the tween and relevant variables.
_showingDropdown = show;
duration = getStyle(""openDuration"");
endY = 0;
easingFunction = getStyle(""openEasingFunction"") as Function;
}
// closing the dropdown
else if (_dropdown)
{
// Set up the tween and relevant variables.
endY = (point.y + _dropdown.height > screen.bottom || tweenUp
? -_dropdown.height
: _dropdown.height);
_showingDropdown = show;
initY = 0;
duration = getStyle(""closeDuration"");
easingFunction = getStyle(""closeEasingFunction"") as Function;
_dropdown.resetDragScrolling();
}
inTween = true;
// only force validation if we're about to show
// or closing with effect. Otherwise, if the iterator
// is out of sync in the dropdown, we'll get an RTE
// when closing
if (playEffect || show)
UIComponentGlobals.layoutManager.validateNow();
// Block all layout, responses from web service, and other background
// processing until the tween finishes executing.
UIComponent.suspendBackgroundProcessing();
// Disable the dropdown during the tween.
if (_dropdown)
_dropdown.enabled = false;
duration = Math.max(1, duration);
if (!playEffect)
duration = 1;
tween = new Tween(this, initY, endY, duration);
if (easingFunction != null && tween)
tween.easingFunction = easingFunction;
triggerEvent = trigger;
}
/**
* @private
*/
private function dispatchChangeEvent(oldEvent:Event, prevValue:int,
newValue:int):void
{
if (prevValue != newValue)
{
var newEvent:Event = oldEvent is ListEvent ?
oldEvent :
new ListEvent(""change"");
dispatchEvent(newEvent);
}
}
/**
* @private
*/
private function destroyDropdown():void
{
if (inTween && tween)
tween.endTween();
displayDropdown(false, null, false);
}
//--------------------------------------------------------------------------
//
// Overridden event handlers
//
//--------------------------------------------------------------------------
private var implicitSelectedIndex:Boolean = false;
/**
* @private
*/
override protected function collectionChangeHandler(event:Event):void
{
// Save a copy of the selectedIndex
var curSelectedIndex:int = selectedIndex;
super.collectionChangeHandler(event);
if (event is CollectionEvent)
{
// trace(""ListBase collectionEvent"");
var ce:CollectionEvent = CollectionEvent(event);
if (collection.length == 0)
{
// Special case: Empty dataProvider.
if (!selectedIndexChanged && !selectedItemChanged)
{
if (super.selectedIndex != -1)
super.selectedIndex = -1;
implicitSelectedIndex = true;
invalidateDisplayList();
}
// if the combobox is non-editable remove the text
// we don't want to remove the text if it is editable as user might
// have typed something.
if (textInput && !editable)
textInput.text = """";
}
else if (ce.kind == CollectionEventKind.ADD)
{
if (collection.length == ce.items.length)
{
// Special case: Adding the first item(s). Select item 0
// if there is no prompt
if (selectedIndex == -1 && _prompt == null)
selectedIndex = 0;
}
else
{
// we dont want to destroy the dropdown just
// because data got added. Especially true
// for paged data.
return;
}
}
else if (ce.kind == CollectionEventKind.UPDATE)
{
if (ce.location == selectedIndex ||
ce.items[0].source == selectedItem)
// unsorted lists don't have a valid location
// Force an update of the text input
selectionChanged = true;
}
else if (ce.kind == CollectionEventKind.REPLACE)
{
// bail on a replace, no need to change anything,
// especially for paged data
return;
}
else if (ce.kind == CollectionEventKind.RESET)
{
collectionChanged = true;
if (!selectedIndexChanged && !selectedItemChanged)
selectedIndex = prompt ? -1 : 0;
invalidateProperties();
}
invalidateDisplayList();
destroyDropdown();
}
}
/**
* @private
*/
override protected function textInput_changeHandler(event:Event):void
{
super.textInput_changeHandler(event);
// Force a change event to be dispatched
dispatchChangeEvent(event, -1, -2);
}
/**
* @private
*/
override protected function downArrowButton_buttonDownHandler(
event:FlexEvent):void
{
// The down arrow should always toggle the visibility of the dropdown.
if (_showingDropdown)
{
close(event);
}
else
{
displayDropdown(true, event);
}
}
//--------------------------------------------------------------------------
//
// Event handlers
//
//--------------------------------------------------------------------------
/**
* @private
*/
private function dropdown_mouseOutsideHandler(event:Event):void
{
// trace(""dropdown_mouseOutsideHandler: "" + event);
if (event is MouseEvent)
{
var mouseEvent:MouseEvent = MouseEvent(event);
if (mouseEvent.target != _dropdown)
// the dropdown's items can dispatch a mouseDownOutside
// event which then bubbles up to us
return;
if (!hitTestPoint(mouseEvent.stageX, mouseEvent.stageY, true))
{
close(event);
}
}
else if (event is SandboxMouseEvent)
{
close(event);
}
}
/**
* @private
*/
private function dropdown_itemClickHandler(event:ListEvent):void
{
if (_showingDropdown)
{
close();
}
}
/**
* @private
*/
override protected function focusOutHandler(event:FocusEvent):void
{
// Note: event.relatedObject is the object getting focus.
// It can be null in some cases, such as when you open
// the dropdown and then click outside the application.
// If the dropdown is open...
if (_showingDropdown && _dropdown &&
this.contains(DisplayObject(event.target)))
{
// If focus is moving outside the dropdown...
if (!event.relatedObject ||
!_dropdown.contains(event.relatedObject))
{
// Close the dropdown.
close();
}
}
super.focusOutHandler(event);
}
private function stage_resizeHandler(event:Event):void
{
destroyDropdown();
}
/**
* @private
*/
private function dropdown_scrollHandler(event:Event):void
{
// TextField.scroll bubbles so you might see it here
if (event is ScrollEvent)
{
var se:ScrollEvent = ScrollEvent(event);
if (se.detail == ScrollEventDetail.THUMB_TRACK ||
se.detail == ScrollEventDetail.THUMB_POSITION ||
se.detail == ScrollEventDetail.LINE_UP ||
se.detail == ScrollEventDetail.LINE_DOWN)
dispatchEvent(se);
}
}
/**
* @private
*/
private function dropdown_itemRollOverHandler(event:Event):void
{
dispatchEvent(event);
}
/**
* @private
*/
private function dropdown_itemRollOutHandler(event:Event):void
{
dispatchEvent(event);
}
/**
* @private
*/
private function dropdown_changeHandler(event:Event):void
{
var prevValue:int = selectedIndex;
// This assignment will also assign the label to the text field.
// See setSelectedIndex().
if (_dropdown)
selectedIndex = _dropdown.selectedIndex;
// If this was generated by the dropdown as a result of a keystroke, it is
// likely a Page-Up or Page-Down, or Arrow-Up or Arrow-Down.
// If the selection changes due to a keystroke,
// we leave the dropdown displayed.
// If it changes as a result of a mouse selection,
// we close the dropdown.
if (!_showingDropdown)
dispatchChangeEvent(event, prevValue, selectedIndex);
else if (!bInKeyDown)
{
// this will also send a change event if needed
close();
}
}
/**
* @private
*/
override protected function keyDownHandler(event:KeyboardEvent):void
{
// If the combo box is disabled, don't do anything
if (!enabled)
return;
// If a the editable field currently has focus, it is handling
// all arrow keys. We shouldn't also scroll this selection.
if (event.target == textInput)
return;
if (event.ctrlKey && event.keyCode == Keyboard.DOWN)
{
displayDropdown(true, event);
event.stopPropagation();
}
else if (event.ctrlKey && event.keyCode == Keyboard.UP)
{
close(event);
event.stopPropagation();
}
else if (event.keyCode == Keyboard.ESCAPE)
{
if (_showingDropdown)
{
if (_oldIndex != _dropdown.selectedIndex)
selectedIndex = _oldIndex;
displayDropdown(false);
event.stopPropagation();
}
}
else if (event.keyCode == Keyboard.ENTER)
{
if (_showingDropdown)
{
close();
event.stopPropagation();
}
}
else
{
if (!editable ||
event.keyCode == Keyboard.UP ||
event.keyCode == Keyboard.DOWN ||
event.keyCode == Keyboard.PAGE_UP ||
event.keyCode == Keyboard.PAGE_DOWN)
{
var oldIndex:int = selectedIndex;
// Make sure we know we are handling a keyDown,
// so if the dropdown sends out a ""change"" event
// (like when an up-arrow or down-arrow changes
// the selection) we know not to close the dropdown.
bInKeyDown = _showingDropdown;
// Redispatch the event to the dropdown
// and let its keyDownHandler() handle it.
dropdown.dispatchEvent(event.clone());
event.stopPropagation();
bInKeyDown = false;
}
}
}
/**
* @private
* This acts as the destructor.
*/
private function unloadHandler(event:Event):void
{
if (inTween)
{
UIComponent.resumeBackgroundProcessing();
inTween = false;
}
if (_dropdown)
_dropdown.parent.removeChild(_dropdown);
}
/**
* @private
*/
private function removedFromStageHandler(event:Event):void
{
// Ensure we've unregistered ourselves from PopupManager, else
// we'll be leaked.
destroyDropdown();
}
//--------------------------------------------------------------------------
//
// Tween handlers
//
//--------------------------------------------------------------------------
/**
* @private
*/
mx_internal function onTweenUpdate(value:Number):void
{
if (_dropdown)
{
_dropdown.scrollRect = new Rectangle(0, value,
_dropdown.width, _dropdown.height);
}
}
/**
* @private
*/
mx_internal function onTweenEnd(value:Number):void
{
if (_dropdown)
{
// Clear the scrollRect here. This way if drop shadows are
// assigned to the dropdown they show up correctly
_dropdown.scrollRect = null;
inTween = false;
_dropdown.enabled = true;
_dropdown.visible = _showingDropdown;
if (bRemoveDropdown)
{
_dropdown.removeEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE, dropdown_mouseOutsideHandler);
_dropdown.removeEventListener(FlexMouseEvent.MOUSE_WHEEL_OUTSIDE, dropdown_mouseOutsideHandler);
_dropdown.removeEventListener(SandboxMouseEvent.MOUSE_DOWN_SOMEWHERE, dropdown_mouseOutsideHandler);
_dropdown.removeEventListener(SandboxMouseEvent.MOUSE_WHEEL_SOMEWHERE, dropdown_mouseOutsideHandler);
PopUpManager.removePopUp(_dropdown);
_dropdown = null;
}
}
bRemoveDropdown = true;
UIComponent.resumeBackgroundProcessing();
var cbdEvent:DropdownEvent =
new DropdownEvent(_showingDropdown ? DropdownEvent.OPEN : DropdownEvent.CLOSE);
cbdEvent.triggerEvent = triggerEvent;
dispatchEvent(cbdEvent);
}
/**
* Determines default values of the height and width to use for each
* entry in the drop-down list, based on the maximum size of the label
* text in the first numItems items in the data provider.
*
* @param count The number of items to check to determine the value.
*
* @return An Object containing two properties: width and height.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
override protected function calculatePreferredSizeFromData(count:int):Object
{
var maxW:Number = 0;
var maxH:Number = 0;
var bookmark:CursorBookmark = iterator ? iterator.bookmark : null;
iterator.seek(CursorBookmark.FIRST, 0);
var more:Boolean = iterator != null;
var lineMetrics:TextLineMetrics;
for (var i:int = 0; i < count; i++)
{
var data:Object;
if (more)
data = iterator ? iterator.current : null;
else
data = null;
var txt:String = itemToLabel(data);
lineMetrics = measureText(txt);
maxW = Math.max(maxW, lineMetrics.width);
maxH = Math.max(maxH, lineMetrics.height);
if (iterator)
iterator.moveNext();
}
if (prompt)
{
lineMetrics = measureText(prompt);
maxW = Math.max(maxW, lineMetrics.width);
maxH = Math.max(maxH, lineMetrics.height);
}
maxW += getStyle(""paddingLeft"") + getStyle(""paddingRight"");
if (iterator)
iterator.seek(bookmark, 0);
return { width: maxW, height: maxH };
}
/**
* @private
*/
mx_internal function get isShowingDropdown():Boolean
{
return _showingDropdown;
}
}
}
",16284,True,2832.65001489805,median
"*&---------------------------------------------------------------------*
*& Report ZMMR0015
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zmmr0015.
*--------------------------------------------------------------------*
* Main Class
*--------------------------------------------------------------------*
CLASS lcl_zmmr0015 DEFINITION FINAL.
PUBLIC SECTION.
TYPE-POOLS: icon.
METHODS: constructor IMPORTING i_banfn TYPE ANY TABLE
i_bnfpo TYPE ANY TABLE
i_matnr TYPE ANY TABLE
i_werks TYPE ANY TABLE,
get_pr_data RETURNING VALUE(e_table_data) TYPE zmmc0012,
get_pr_log RETURNING VALUE(e_table_data) TYPE zmmc0013,
set_pr_conclusion CHANGING ch_pr_item TYPE zmmc0012,
set_pr_exclusion CHANGING ch_pr_item TYPE zmmc0012,
set_pr_log IMPORTING i_pr_item TYPE zmmc0012
RETURNING VALUE(not_found) TYPE flag.
PRIVATE SECTION.
CONSTANTS: BEGIN OF gc_action,
conclusion TYPE zmmt010-action VALUE 'CONCLUIR',
exclusion TYPE zmmt010-action VALUE 'EXCLUIR',
END OF gc_action.
DATA: gr_banfn TYPE RANGE OF eban-banfn,
gr_bnfpo TYPE RANGE OF eban-bnfpo,
gr_matnr TYPE RANGE OF eban-matnr,
gr_werks TYPE RANGE OF eban-werks.
DATA: gt_generated_log TYPE TABLE OF zmmt010.
ENDCLASS.
CLASS lcl_zmmr0015 IMPLEMENTATION.
METHOD constructor.
gr_banfn[] = i_banfn[].
gr_bnfpo[] = i_bnfpo[].
gr_matnr[] = i_matnr[].
gr_werks[] = i_werks[].
ENDMETHOD.
METHOD get_pr_data.
SELECT a~banfn a~bnfpo a~matnr b~maktx a~werks a~loekz a~ebakz
FROM eban AS a
INNER JOIN makt AS b
ON a~matnr = b~matnr
INTO TABLE e_table_data
WHERE a~banfn IN gr_banfn
AND a~bnfpo IN gr_bnfpo
AND a~matnr IN gr_matnr
AND a~werks IN gr_werks.
ENDMETHOD.
METHOD get_pr_log.
* Adjust icon
LOOP AT gt_generated_log ASSIGNING FIELD-SYMBOL().
APPEND INITIAL LINE TO e_table_data ASSIGNING FIELD-SYMBOL().
MOVE-CORRESPONDING TO .
IF -type = 'S'.
-icon = icon_led_green.
ELSE.
-icon = icon_led_red.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD set_pr_conclusion.
DATA: lt_pr_header TYPE zmmc0012,
lt_pritem TYPE TABLE OF bapimereqitemimp,
lt_pritemx TYPE TABLE OF bapimereqitemx,
lt_return TYPE TABLE OF bapiret2.
CLEAR gt_generated_log.
SORT ch_pr_item BY banfn.
* Get purchase requisition header
lt_pr_header[] = ch_pr_item[].
DELETE ADJACENT DUPLICATES FROM lt_pr_header COMPARING banfn.
* Call funtion for each purchase requisition
LOOP AT lt_pr_header ASSIGNING FIELD-SYMBOL().
CLEAR: lt_pritem, lt_return, lt_pritemx.
* Groups items by purchase requisition
LOOP AT ch_pr_item ASSIGNING FIELD-SYMBOL() WHERE banfn = -banfn.
APPEND INITIAL LINE TO lt_pritem ASSIGNING FIELD-SYMBOL().
-preq_item = -bnfpo.
-closed = abap_true.
APPEND INITIAL LINE TO lt_pritemx ASSIGNING FIELD-SYMBOL().
-preq_item = -bnfpo.
-preq_itemx = abap_true.
-closed = abap_true.
APPEND INITIAL LINE TO gt_generated_log ASSIGNING FIELD-SYMBOL().
-banfn = -banfn.
-bnfpo = -bnfpo.
-matnr = -matnr.
-action = gc_action-conclusion.
ENDLOOP.
* Set purchase requisition as completed
CALL FUNCTION 'BAPI_PR_CHANGE'
EXPORTING
number = -banfn
TABLES
return = lt_return
pritem = lt_pritem
pritemx = lt_pritemx.
* Save changes log
IF line_exists( lt_return[ type = 'E' ] ).
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
LOOP AT gt_generated_log ASSIGNING WHERE banfn = -banfn.
LOOP AT lt_return ASSIGNING FIELD-SYMBOL() WHERE type = 'E'.
MOVE-CORRESPONDING TO .
-msgno = -number.
ENDLOOP.
ENDLOOP.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
LOOP AT gt_generated_log ASSIGNING WHERE banfn = -banfn.
READ TABLE lt_return ASSIGNING WITH KEY type = 'S'
id = '06'
number = '403'.
IF sy-subrc = 0.
MOVE-CORRESPONDING TO .
-msgno = -number.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
IF lines( gt_generated_log ) > 0.
MODIFY zmmt010 FROM TABLE gt_generated_log.
ENDIF.
ENDMETHOD.
METHOD set_pr_exclusion.
DATA: lt_pr_header TYPE zmmc0012,
lt_pritem TYPE TABLE OF bapimereqitemimp,
lt_pritemx TYPE TABLE OF bapimereqitemx,
lt_return TYPE TABLE OF bapiret2.
CLEAR gt_generated_log.
SORT ch_pr_item BY banfn.
* Get purchase requisition header
lt_pr_header[] = ch_pr_item[].
DELETE ADJACENT DUPLICATES FROM lt_pr_header COMPARING banfn.
* Call funtion for each purchase requisition
LOOP AT lt_pr_header ASSIGNING FIELD-SYMBOL().
CLEAR: lt_pritem, lt_return, lt_pritemx.
* Groups items by purchase requisition
LOOP AT ch_pr_item ASSIGNING FIELD-SYMBOL() WHERE banfn = -banfn.
APPEND INITIAL LINE TO lt_pritem ASSIGNING FIELD-SYMBOL().
-preq_item = -bnfpo.
-delete_ind = abap_true.
APPEND INITIAL LINE TO lt_pritemx ASSIGNING FIELD-SYMBOL().
-preq_item = -bnfpo.
-preq_itemx = abap_true.
-delete_ind = abap_true.
APPEND INITIAL LINE TO gt_generated_log ASSIGNING FIELD-SYMBOL().
-banfn = -banfn.
-bnfpo = -bnfpo.
-matnr = -matnr.
-action = gc_action-exclusion.
ENDLOOP.
* Set purchase requisition as deleted
CALL FUNCTION 'BAPI_PR_CHANGE'
EXPORTING
number = -banfn
TABLES
return = lt_return
pritem = lt_pritem
pritemx = lt_pritemx.
* Save changes log
IF line_exists( lt_return[ type = 'E' ] ).
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
LOOP AT gt_generated_log ASSIGNING WHERE banfn = -banfn.
LOOP AT lt_return ASSIGNING FIELD-SYMBOL() WHERE type = 'E'.
MOVE-CORRESPONDING TO .
-msgno = -number.
ENDLOOP.
ENDLOOP.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
LOOP AT gt_generated_log ASSIGNING WHERE banfn = -banfn.
READ TABLE lt_return ASSIGNING WITH KEY type = 'S'
id = '06'
number = '403'.
IF sy-subrc = 0.
MOVE-CORRESPONDING TO .
-msgno = -number.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
IF lines( gt_generated_log ) > 0.
MODIFY zmmt010 FROM TABLE gt_generated_log.
ENDIF.
ENDMETHOD.
METHOD set_pr_log.
SELECT *
FROM zmmt010
INTO TABLE gt_generated_log
FOR ALL ENTRIES IN i_pr_item
WHERE banfn = i_pr_item-banfn
AND bnfpo = i_pr_item-bnfpo.
IF sy-subrc <> 0.
not_found = abap_true.
ENDIF.
ENDMETHOD.
ENDCLASS.
*--------------------------------------------------------------------*
* Global Objects
*--------------------------------------------------------------------*
TABLES: eban.
DATA: go_report TYPE REF TO lcl_zmmr0015,
gt_alv TYPE zmmc0012,
gt_log TYPE zmmc0013,
go_alv_9000 TYPE REF TO cl_gui_alv_grid,
go_alv_9001 TYPE REF TO cl_gui_alv_grid,
go_cont_9000 TYPE REF TO cl_gui_docking_container,
go_cont_9001 TYPE REF TO cl_gui_docking_container,
go_parent_9000 TYPE REF TO cl_gui_container,
go_parent_9001 TYPE REF TO cl_gui_container.
*--------------------------------------------------------------------*
* Selection Screen
*--------------------------------------------------------------------*
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: s_banfn FOR eban-banfn OBLIGATORY,
s_bnfpo FOR eban-bnfpo,"" OBLIGATORY,
s_matnr FOR eban-matnr,
s_werks FOR eban-werks.
SELECTION-SCREEN: END OF BLOCK b1.
*--------------------------------------------------------------------*
* Main event
*--------------------------------------------------------------------*
START-OF-SELECTION.
CREATE OBJECT go_report
EXPORTING
i_banfn = s_banfn[]
i_bnfpo = s_bnfpo[]
i_matnr = s_matnr[]
i_werks = s_werks[].
CALL SCREEN 9000.
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS 'STATUS_9000'.
SET TITLEBAR 'TITLE_9000'.
DATA: ls_layout TYPE lvc_s_layo,
ls_variant TYPE disvariant,
lt_sort TYPE lvc_t_sort.
* Edit layout
CLEAR ls_layout.
ls_layout-sel_mode = 'A'.
gt_alv = go_report->get_pr_data( ).
DATA: lt_fcat TYPE lvc_t_fcat.
CLEAR lt_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'ZMMS0009'
CHANGING
ct_fieldcat = lt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT lt_fcat ASSIGNING FIELD-SYMBOL().
IF -fieldname = 'LOEKZ' OR -fieldname = 'EBAKZ'.
-outputlen = 8.
-just = 'C'.
ELSE.
-col_opt = abap_true.
ENDIF.
IF -fieldname = 'BANFN' OR -fieldname = 'BNFPO'.
-key = abap_true.
ENDIF.
ENDLOOP.
IF go_cont_9000 IS BOUND.
go_alv_9000->set_frontend_fieldcatalog( it_fieldcatalog = lt_fcat ).
DATA: ls_stable TYPE lvc_s_stbl.
ls_stable-row = abap_true.
ls_stable-col = abap_true.
go_alv_9000->refresh_table_display(
EXPORTING
is_stable = ls_stable "" With Stable Rows/Columns
EXCEPTIONS
finished = 1 "" Display was Ended (by Export)
OTHERS = 2
).
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ELSE.
* Cria o Container para a tela do ALV
CREATE OBJECT go_cont_9000
EXPORTING
side = cl_gui_docking_container=>dock_at_top
repid = sy-repid
dynnr = '9000'
extension = 1000
EXCEPTIONS
OTHERS = 6.
* Casting para o tipo genério
go_parent_9000 = go_cont_9000.
* Criia Instância do ALV, referenciando o Container gerado acima
CREATE OBJECT go_alv_9000
EXPORTING
i_parent = go_parent_9000.
ls_variant-report = sy-repid.
ls_variant-username = sy-uname.
*APPEND INITIAL LINE TO lt_sort ASSIGNING FIELD-SYMBOL(<
CLEAR lt_sort.
APPEND VALUE #( fieldname = 'BANFN' up = 'X' ) TO lt_sort.
APPEND VALUE #( fieldname = 'BNFPO' up = 'X' ) TO lt_sort.
* Exibe o ALV
go_alv_9000->set_table_for_first_display(
EXPORTING
is_variant = ls_variant "" Layout
i_save = 'A' "" Save Layout
is_layout = ls_layout "" Layout
CHANGING
it_outtab = gt_alv "" Output Table
it_fieldcatalog = lt_fcat "" Field Catalog
it_sort = lt_sort "" Sort Criteria
EXCEPTIONS
invalid_parameter_combination = 1 "" Wrong Parameter
program_error = 2 "" Program Errors
too_many_lines = 3 "" Too many Rows in Ready for Input Grid
OTHERS = 4
).
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
DATA: lt_selected_data TYPE zmmc0012.
CASE sy-ucomm.
WHEN '&F03' OR '&F15' OR '&F12'.
go_alv_9000->free( ).
go_cont_9000->free( ).
CALL METHOD cl_gui_cfw=>flush.
CLEAR: go_alv_9000, go_cont_9000.
LEAVE TO SCREEN 0.
WHEN '&CONCL'.
* Get selected rows
CLEAR lt_selected_data.
go_alv_9000->check_changed_data( ).
go_alv_9000->get_selected_rows( IMPORTING et_index_rows = DATA(lt_index_rows) ).
IF lines( lt_index_rows ) = 0.
MESSAGE 'Favor selecionar uma linha para processamento'(002) TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
* Process rows
LOOP AT lt_index_rows ASSIGNING FIELD-SYMBOL().
READ TABLE gt_alv ASSIGNING FIELD-SYMBOL() INDEX .
IF sy-subrc = 0.
APPEND INITIAL LINE TO lt_selected_data ASSIGNING FIELD-SYMBOL().
= .
ENDIF.
ENDLOOP.
go_report->set_pr_conclusion( CHANGING ch_pr_item = lt_selected_data ).
* Display log screen
CALL SCREEN 9001.
WHEN '&DELET'.
* Get selected rows
CLEAR lt_selected_data.
go_alv_9000->check_changed_data( ).
go_alv_9000->get_selected_rows( IMPORTING et_index_rows = lt_index_rows ).
IF lines( lt_index_rows ) = 0.
MESSAGE 'Favor selecionar uma linha para processamento'(002) TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
* Process rows
LOOP AT lt_index_rows ASSIGNING .
READ TABLE gt_alv ASSIGNING INDEX .
IF sy-subrc = 0.
APPEND INITIAL LINE TO lt_selected_data ASSIGNING .
= .
ENDIF.
ENDLOOP.
go_report->set_pr_exclusion( CHANGING ch_pr_item = lt_selected_data ).
* Display log screen
CALL SCREEN 9001.
WHEN '&LOG'.
* Get selected rows
CLEAR lt_selected_data.
go_alv_9000->check_changed_data( ).
go_alv_9000->get_selected_rows( IMPORTING et_index_rows = lt_index_rows ).
IF lines( lt_index_rows ) = 0.
MESSAGE 'Favor selecionar uma linha para processamento'(002) TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
* Process rows
LOOP AT lt_index_rows ASSIGNING .
READ TABLE gt_alv ASSIGNING INDEX .
IF sy-subrc = 0.
APPEND INITIAL LINE TO lt_selected_data ASSIGNING .
= .
ENDIF.
ENDLOOP.
IF go_report->set_pr_log( EXPORTING i_pr_item = lt_selected_data ) = abap_true.
MESSAGE 'Não foram encontrados registros de log para a req.compra selecionada'(004) TYPE 'S' DISPLAY LIKE 'E'.
ELSE.
* Display log screen
CALL SCREEN 9001.
ENDIF.
ENDCASE.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module STATUS_9001 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_9001 OUTPUT.
SET PF-STATUS 'STATUS_9001'.
SET TITLEBAR 'TITLE_9001'.
gt_log = go_report->get_pr_log( ).
* Edit layout
CLEAR ls_layout.
ls_layout-cwidth_opt = abap_true.
IF go_cont_9001 IS BOUND.
go_alv_9001->set_frontend_layout( is_layout = ls_layout ).
ls_stable-row = abap_true.
ls_stable-col = abap_true.
go_alv_9001->refresh_table_display(
EXPORTING
is_stable = ls_stable "" With Stable Rows/Columns
EXCEPTIONS
finished = 1 "" Display was Ended (by Export)
OTHERS = 2
).
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ELSE.
* Cria o Container para a tela do ALV
CREATE OBJECT go_cont_9001
EXPORTING
side = cl_gui_docking_container=>dock_at_top
repid = sy-repid
dynnr = '9001'
extension = 1000
EXCEPTIONS
OTHERS = 6.
* Casting para o tipo genério
go_parent_9001 = go_cont_9001.
* Criia Instância do ALV, referenciando o Container gerado acima
CREATE OBJECT go_alv_9001
EXPORTING
i_parent = go_parent_9001.
CLEAR lt_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'ZMMS0010'
CHANGING
ct_fieldcat = lt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT lt_fcat ASSIGNING .
IF -fieldname CS 'MESSAGE_V'.
-no_out = abap_true.
ENDIF.
IF -fieldname = 'ICON'.
-icon = abap_true.
-coltext = 'Status'(003).
ENDIF.
ENDLOOP.
* Exibe o ALV
go_alv_9001->set_table_for_first_display(
EXPORTING
* i_buffer_active = "" Buffering Active
* i_bypassing_buffer = "" Switch Off Buffer
* i_consistency_check = "" Starting Consistency Check for Interface Error Recognition
i_structure_name = 'ZMMT010' "" Internal Output Table Structure Name
* is_variant = "" Layout
* i_save = "" Save Layout
* i_default = 'X' "" Default Display Variant
is_layout = ls_layout "" Layout
* is_print = "" Print Control
* it_special_groups = "" Field Groups
* it_toolbar_excluding = "" Excluded Toolbar Standard Functions
* it_hyperlink = "" Hyperlinks
* it_alv_graphics = "" Table of Structure DTC_S_TC
* it_except_qinfo = "" Table for Exception Quickinfo
* ir_salv_adapter = "" Interface ALV Adapter
CHANGING
it_outtab = gt_log "" Output Table
it_fieldcatalog = lt_fcat "" Field Catalog
* it_sort = "" Sort Criteria
* it_filter = "" Filter Criteria
EXCEPTIONS
invalid_parameter_combination = 1 "" Wrong Parameter
program_error = 2 "" Program Errors
too_many_lines = 3 "" Too many Rows in Ready for Input Grid
OTHERS = 4
).
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9001 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9001 INPUT.
CASE sy-ucomm.
WHEN '&F03' OR '&F15' OR '&F12'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.
",5473,False,1033.9443400110895,median
"CLASS ltcl_run_checks DEFINITION DEFERRED.
CLASS zcl_abapgit_file_status DEFINITION LOCAL FRIENDS ltcl_run_checks.
CLASS ltcl_run_checks DEFINITION FOR TESTING RISK LEVEL HARMLESS
DURATION SHORT FINAL.
PRIVATE SECTION.
DATA: mt_results TYPE zif_abapgit_definitions=>ty_results_tt,
mo_dot TYPE REF TO zcl_abapgit_dot_abapgit,
mi_log TYPE REF TO zif_abapgit_log.
METHODS:
append_result IMPORTING iv_obj_type TYPE trobjtype
iv_obj_name TYPE sobj_name
iv_match TYPE abap_bool
iv_lstate TYPE char1
iv_rstate TYPE char1
iv_package TYPE devclass
iv_path TYPE string
iv_filename TYPE string
iv_packmove TYPE abap_bool OPTIONAL,
setup,
positive FOR TESTING RAISING zcx_abapgit_exception,
neg_diff_path_for_same_obj FOR TESTING RAISING zcx_abapgit_exception,
neg_incorrect_path_vs_pack FOR TESTING RAISING zcx_abapgit_exception,
neg_similar_filenames FOR TESTING RAISING zcx_abapgit_exception,
neg_empty_filenames FOR TESTING RAISING zcx_abapgit_exception,
package_move FOR TESTING RAISING zcx_abapgit_exception.
ENDCLASS.
CLASS ltcl_run_checks IMPLEMENTATION.
METHOD append_result.
DATA ls_result LIKE LINE OF mt_results.
ls_result-inactive = abap_false.
ls_result-obj_type = iv_obj_type.
ls_result-obj_name = iv_obj_name.
ls_result-match = iv_match.
ls_result-lstate = iv_lstate.
ls_result-rstate = iv_rstate.
ls_result-package = iv_package.
ls_result-path = iv_path.
ls_result-filename = iv_filename.
ls_result-packmove = iv_packmove.
APPEND ls_result TO mt_results.
ENDMETHOD.
METHOD setup.
CREATE OBJECT mi_log TYPE zcl_abapgit_log.
mo_dot = zcl_abapgit_dot_abapgit=>build_default( ).
mo_dot->set_starting_folder( '/' ). "" assumed by unit tests
ENDMETHOD.
METHOD positive.
"" 0 Positive
append_result( iv_obj_type = 'CLAS'
iv_obj_name = 'ZCLASS1'
iv_match = ' '
iv_lstate = ' '
iv_rstate = 'A'
iv_package = '$Z$'
iv_path = '/'
iv_filename = 'zclass1.clas.abap' ).
append_result( iv_obj_type = 'CLAS'
iv_obj_name = 'ZCLASS1'
iv_match = 'X'
iv_lstate = ' '
iv_rstate = ' '
iv_package = '$Z$'
iv_path = '/'
iv_filename = 'zclass1.clas.xml' ).
append_result( iv_obj_type = 'DOMA'
iv_obj_name = 'ZDOMA1'
iv_match = 'X'
iv_lstate = ' '
iv_rstate = ' '
iv_package = '$Z$'
iv_path = '/'
iv_filename = 'zdoma1.doma.xml' ).
append_result( iv_obj_type = 'DOMA'
iv_obj_name = 'ZDOMA2'
iv_match = ' '
iv_lstate = 'M'
iv_rstate = ' '
iv_package = '$Z$'
iv_path = '/'
iv_filename = 'zdoma2.doma.xml' ).
zcl_abapgit_file_status=>run_checks(
ii_log = mi_log
it_results = mt_results
io_dot = mo_dot
iv_top = '$Z$' ).
cl_abap_unit_assert=>assert_equals(
act = mi_log->count( )
exp = 0 ).
ENDMETHOD.
METHOD neg_diff_path_for_same_obj.
"" 1 Negative, different path for same object
append_result( iv_obj_type = 'CLAS'
iv_obj_name = 'ZCLASS1'
iv_match = ' '
iv_lstate = ' '
iv_rstate = 'A'
iv_package = '$Z$'
iv_path = '/'
iv_filename = 'zclass1.clas.abap' ).
append_result( iv_obj_type = 'CLAS'
iv_obj_name = 'ZCLASS1'
iv_match = 'X'
iv_lstate = ' '
iv_rstate = ' '
iv_package = '$Z$'
iv_path = '/sub'
iv_filename = 'zclass1.clas.xml' ).
append_result( iv_obj_type = 'DOMA'
iv_obj_name = 'ZDOMA1'
iv_match = 'X'
iv_lstate = ' '
iv_rstate = ' '
iv_package = '$Z$'
iv_path = '/'
iv_filename = 'zdoma1.doma.xml' ).
append_result( iv_obj_type = 'DOMA'
iv_obj_name = 'ZDOMA2'
iv_match = ' '
iv_lstate = 'M'
iv_rstate = ' '
iv_package = '$Z$'
iv_path = '/'
iv_filename = 'zdoma2.doma.xml' ).
zcl_abapgit_file_status=>run_checks(
ii_log = mi_log
it_results = mt_results
io_dot = mo_dot
iv_top = '$Z$' ).
"" This one is not pure - incorrect path also triggers path vs package check
cl_abap_unit_assert=>assert_equals(
act = mi_log->count( )
exp = 2 ).
cl_abap_unit_assert=>assert_equals(
act = mi_log->has_rc( '1' )
exp = abap_true ).
ENDMETHOD.
METHOD neg_incorrect_path_vs_pack.
"" 2 Negative, incorrect path vs package
append_result( iv_obj_type = 'CLAS'
iv_obj_name = '$$ZCLASS1'
iv_match = ' '
iv_lstate = ' '
iv_rstate = 'A'
iv_package = '$Z$'
iv_path = '/'
iv_filename = '$$zclass1.clas.abap' ).
append_result( iv_obj_type = 'CLAS'
iv_obj_name = '$$ZCLASS1'
iv_match = 'X'
iv_lstate = ' '
iv_rstate = ' '
iv_package = '$Z$'
iv_path = '/'
iv_filename = '$$zclass1.clas.xml' ).
append_result( iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA1'
iv_match = 'X'
iv_lstate = ' '
iv_rstate = ' '
iv_package = '$Z$'
iv_path = '/sub'
iv_filename = '$$zdoma1.doma.xml' ).
append_result( iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA2'
iv_match = ' '
iv_lstate = 'M'
iv_rstate = ' '
iv_package = '$Z$'
iv_path = '/'
iv_filename = '$$zdoma2.doma.xml' ).
zcl_abapgit_file_status=>run_checks(
ii_log = mi_log
it_results = mt_results
io_dot = mo_dot
iv_top = '$Z$' ).
cl_abap_unit_assert=>assert_equals(
act = mi_log->count( )
exp = 1 ).
cl_abap_unit_assert=>assert_equals(
act = mi_log->has_rc( '2' )
exp = abap_true ).
ENDMETHOD.
METHOD neg_similar_filenames.
"" 3 Negative, similar filenames
append_result( iv_obj_type = 'CLAS'
iv_obj_name = '$$ZCLASS1'
iv_match = ' '
iv_lstate = ' '
iv_rstate = 'A'
iv_package = '$Z$'
iv_path = '/'
iv_filename = '$$zclass1.clas.abap' ).
append_result( iv_obj_type = 'CLAS'
iv_obj_name = '$$ZCLASS1'
iv_match = 'X'
iv_lstate = ' '
iv_rstate = ' '
iv_package = '$Z$'
iv_path = '/'
iv_filename = '$$zclass1.clas.xml' ).
append_result( iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA1'
iv_match = 'X'
iv_lstate = ' '
iv_rstate = ' '
iv_package = '$Z$'
iv_path = '/'
iv_filename = '$$zdoma1.doma.xml' ).
append_result( iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA2'
iv_match = ' '
iv_lstate = 'M'
iv_rstate = ' '
iv_package = '$Z$'
iv_path = '/'
iv_filename = '$$zdoma1.doma.xml' ).
zcl_abapgit_file_status=>run_checks(
ii_log = mi_log
it_results = mt_results
io_dot = mo_dot
iv_top = '$Z$' ).
cl_abap_unit_assert=>assert_equals(
act = mi_log->count( )
exp = 1 ).
cl_abap_unit_assert=>assert_equals(
act = mi_log->has_rc( '3' )
exp = abap_true ).
ENDMETHOD.
METHOD neg_empty_filenames.
"" 4 Negative, empty filenames
append_result( iv_obj_type = 'CLAS'
iv_obj_name = '$$ZCLASS1'
iv_match = ' '
iv_lstate = ' '
iv_rstate = 'A'
iv_package = '$Z$'
iv_path = '/'
iv_filename = '$$zclass1.clas.abap' ).
append_result( iv_obj_type = 'CLAS'
iv_obj_name = '$$ZCLASS1'
iv_match = 'X'
iv_lstate = ' '
iv_rstate = ' '
iv_package = '$Z$'
iv_path = '/'
iv_filename = '$$zclass1.clas.xml' ).
append_result( iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA1'
iv_match = 'X'
iv_lstate = ' '
iv_rstate = ' '
iv_package = '$Z$'
iv_path = '/'
iv_filename = '' ).
zcl_abapgit_file_status=>run_checks(
ii_log = mi_log
it_results = mt_results
io_dot = mo_dot
iv_top = '$Z$' ).
cl_abap_unit_assert=>assert_equals(
act = mi_log->count( )
exp = 1 ).
cl_abap_unit_assert=>assert_equals(
act = mi_log->has_rc( '4' )
exp = abap_true ).
ENDMETHOD.
METHOD package_move.
"" 5 Changed package assignment
append_result( iv_obj_type = 'CLAS'
iv_obj_name = 'ZCLASS1'
iv_match = ' '
iv_lstate = ' '
iv_rstate = 'A'
iv_package = '$Z$'
iv_path = '/'
iv_filename = 'zclass1.clas.abap'
iv_packmove = 'X' ).
append_result( iv_obj_type = 'CLAS'
iv_obj_name = 'ZCLASS1'
iv_match = ' '
iv_lstate = 'A'
iv_rstate = ' '
iv_package = '$Z$SUB'
iv_path = '/sub'
iv_filename = 'zclass1.clas.abap'
iv_packmove = 'X' ).
append_result( iv_obj_type = 'CLAS'
iv_obj_name = 'ZCLASS1'
iv_match = ' '
iv_lstate = ' '
iv_rstate = 'A'
iv_package = '$Z$'
iv_path = '/'
iv_filename = 'zclass1.clas.xml'
iv_packmove = 'X' ).
append_result( iv_obj_type = 'CLAS'
iv_obj_name = 'ZCLASS1'
iv_match = ' '
iv_lstate = 'A'
iv_rstate = ' '
iv_package = '$Z$SUB'
iv_path = '/sub'
iv_filename = 'zclass1.clas.xml'
iv_packmove = 'X' ).
append_result( iv_obj_type = 'DOMA'
iv_obj_name = 'ZDOMA1'
iv_match = ' '
iv_lstate = 'A'
iv_rstate = ' '
iv_package = '$Z$'
iv_path = '/'
iv_filename = 'zdoma1.doma.xml'
iv_packmove = 'X' ).
append_result( iv_obj_type = 'DOMA'
iv_obj_name = 'ZDOMA2'
iv_match = ' '
iv_lstate = ' '
iv_rstate = 'A'
iv_package = '$Z$SUB'
iv_path = '/sub'
iv_filename = 'zdoma1.doma.xml'
iv_packmove = 'X' ).
zcl_abapgit_file_status=>run_checks(
ii_log = mi_log
it_results = mt_results
io_dot = mo_dot
iv_top = '$Z$' ).
"" Three files, but only two msg (for two changed objects)
cl_abap_unit_assert=>assert_equals(
act = mi_log->count( )
exp = 2 ).
cl_abap_unit_assert=>assert_equals(
act = mi_log->has_rc( '5' )
exp = abap_true ).
ENDMETHOD.
ENDCLASS.
CLASS lcl_status_result DEFINITION.
PUBLIC SECTION.
METHODS:
constructor
IMPORTING
it_results TYPE zif_abapgit_definitions=>ty_results_tt,
get_line
IMPORTING
iv_line TYPE i
RETURNING
VALUE(rs_data) TYPE zif_abapgit_definitions=>ty_result,
assert_lines
IMPORTING
iv_lines TYPE i
iv_msg TYPE csequence OPTIONAL.
PRIVATE SECTION.
DATA: mt_results TYPE zif_abapgit_definitions=>ty_results_tt.
ENDCLASS.
CLASS lcl_status_result IMPLEMENTATION.
METHOD constructor.
mt_results = it_results.
SORT mt_results BY path filename.
ENDMETHOD.
METHOD get_line.
READ TABLE mt_results INDEX iv_line INTO rs_data.
cl_abap_unit_assert=>assert_subrc( ).
ENDMETHOD.
METHOD assert_lines.
cl_abap_unit_assert=>assert_equals(
act = lines( mt_results )
exp = iv_lines
msg = iv_msg ).
ENDMETHOD.
ENDCLASS.
CLASS ltcl_status_helper DEFINITION DEFERRED.
CLASS zcl_abapgit_file_status DEFINITION LOCAL FRIENDS ltcl_status_helper.
CLASS ltcl_status_helper DEFINITION FOR TESTING.
PUBLIC SECTION.
INTERFACES:
zif_abapgit_tadir.
METHODS:
constructor,
add_tadir
IMPORTING
iv_obj_type TYPE tadir-object
iv_obj_name TYPE tadir-obj_name
iv_devclass TYPE tadir-devclass,
add_remote
IMPORTING
iv_path TYPE string DEFAULT '/'
iv_filename TYPE string
iv_sha1 TYPE zif_abapgit_definitions=>ty_sha1,
add_local
IMPORTING
iv_path TYPE string DEFAULT '/'
iv_filename TYPE string
iv_sha1 TYPE zif_abapgit_definitions=>ty_sha1
iv_obj_type TYPE tadir-object OPTIONAL
iv_obj_name TYPE tadir-obj_name OPTIONAL
iv_devclass TYPE devclass DEFAULT '$Z$',
add_state
IMPORTING
iv_path TYPE string DEFAULT '/'
iv_filename TYPE string
iv_sha1 TYPE zif_abapgit_definitions=>ty_sha1,
run
IMPORTING
iv_devclass TYPE devclass DEFAULT '$Z$'
RETURNING
VALUE(ro_result) TYPE REF TO lcl_status_result
RAISING
zcx_abapgit_exception.
PRIVATE SECTION.
TYPES: BEGIN OF ty_tadir,
obj_type TYPE tadir-object,
obj_name TYPE tadir-obj_name,
devclass TYPE tadir-devclass,
END OF ty_tadir.
DATA:
mt_tadir TYPE STANDARD TABLE OF ty_tadir WITH DEFAULT KEY,
mt_local TYPE zif_abapgit_definitions=>ty_files_item_tt,
mt_remote TYPE zif_abapgit_definitions=>ty_files_tt,
mt_state TYPE zif_abapgit_definitions=>ty_file_signatures_tt.
ENDCLASS.
CLASS ltcl_status_helper IMPLEMENTATION.
METHOD constructor.
zcl_abapgit_injector=>set_tadir( me ).
ENDMETHOD.
METHOD add_tadir.
FIELD-SYMBOLS: LIKE LINE OF mt_tadir.
APPEND INITIAL LINE TO mt_tadir ASSIGNING .
-obj_type = iv_obj_type.
-obj_name = iv_obj_name.
-devclass = iv_devclass.
ENDMETHOD.
METHOD zif_abapgit_tadir~get_object_package.
DATA: ls_tadir LIKE LINE OF mt_tadir.
IF lines( mt_tadir ) > 0.
READ TABLE mt_tadir INTO ls_tadir WITH KEY
obj_type = iv_object
obj_name = iv_obj_name.
cl_abap_unit_assert=>assert_subrc( ).
rv_devclass = ls_tadir-devclass.
ENDIF.
ENDMETHOD.
METHOD zif_abapgit_tadir~read.
cl_abap_unit_assert=>fail( ).
ENDMETHOD.
METHOD zif_abapgit_tadir~read_single.
cl_abap_unit_assert=>fail( ).
ENDMETHOD.
METHOD add_remote.
FIELD-SYMBOLS: LIKE LINE OF mt_remote.
APPEND INITIAL LINE TO mt_remote ASSIGNING .
-path = iv_path.
-filename = iv_filename.
-sha1 = iv_sha1.
ENDMETHOD.
METHOD add_local.
FIELD-SYMBOLS: LIKE LINE OF mt_local.
APPEND INITIAL LINE TO mt_local ASSIGNING .
-item-obj_type = iv_obj_type.
-item-obj_name = iv_obj_name.
-item-devclass = iv_devclass.
-file-path = iv_path.
-file-filename = iv_filename.
-file-sha1 = iv_sha1.
ENDMETHOD.
METHOD add_state.
FIELD-SYMBOLS: LIKE LINE OF mt_state.
APPEND INITIAL LINE TO mt_state ASSIGNING .
-path = iv_path.
-filename = iv_filename.
-sha1 = iv_sha1.
ENDMETHOD.
METHOD run.
DATA: lt_results TYPE zif_abapgit_definitions=>ty_results_tt,
lo_dot TYPE REF TO zcl_abapgit_dot_abapgit.
lo_dot = zcl_abapgit_dot_abapgit=>build_default( ).
lo_dot->set_starting_folder( '/' ). "" assumed by unit tests
lt_results = zcl_abapgit_file_status=>calculate_status(
iv_devclass = iv_devclass
io_dot = lo_dot
it_local = mt_local
it_remote = mt_remote
it_cur_state = mt_state ).
CREATE OBJECT ro_result
EXPORTING
it_results = lt_results.
ENDMETHOD.
ENDCLASS.
CLASS ltcl_calculate_status DEFINITION DEFERRED.
CLASS zcl_abapgit_file_status DEFINITION LOCAL FRIENDS ltcl_calculate_status.
CLASS ltcl_calculate_status DEFINITION FOR TESTING RISK LEVEL HARMLESS
DURATION SHORT FINAL.
PRIVATE SECTION.
DATA:
mo_helper TYPE REF TO ltcl_status_helper,
mo_result TYPE REF TO lcl_status_result.
METHODS:
setup,
only_remote FOR TESTING RAISING zcx_abapgit_exception,
only_local FOR TESTING RAISING zcx_abapgit_exception,
match FOR TESTING RAISING zcx_abapgit_exception,
diff FOR TESTING RAISING zcx_abapgit_exception,
moved FOR TESTING RAISING zcx_abapgit_exception,
local_outside_main FOR TESTING RAISING zcx_abapgit_exception,
complete FOR TESTING RAISING zcx_abapgit_exception,
deleted_remotely FOR TESTING RAISING zcx_abapgit_exception.
ENDCLASS.
CLASS ltcl_calculate_status IMPLEMENTATION.
METHOD setup.
CREATE OBJECT mo_helper.
ENDMETHOD.
METHOD moved.
mo_helper->add_local(
iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA1'
iv_filename = '$$zdoma1.doma.xml'
iv_path = '/foo/'
iv_devclass = 'FOO'
iv_sha1 = 'D1' ).
mo_helper->add_remote(
iv_filename = '$$zdoma1.doma.xml'
iv_path = '/bar/'
iv_sha1 = 'D1' ).
mo_helper->add_tadir(
iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA1'
iv_devclass = 'FOO' ).
mo_result = mo_helper->run( iv_devclass = 'FOO' ).
mo_result->assert_lines(
iv_lines = 2
iv_msg = 'there must be a status calculated for both files, they are in different folders' ).
ENDMETHOD.
METHOD only_remote.
mo_helper->add_remote(
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = 'D1' ).
mo_result = mo_helper->run( ).
mo_result->assert_lines( 1 ).
cl_abap_unit_assert=>assert_equals(
act = mo_result->get_line( 1 )-rstate
exp = zif_abapgit_definitions=>c_state-added ).
ENDMETHOD.
METHOD only_local.
mo_helper->add_local(
iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA1'
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = 'D1' ).
mo_result = mo_helper->run( ).
mo_result->assert_lines( 1 ).
cl_abap_unit_assert=>assert_equals(
act = mo_result->get_line( 1 )-lstate
exp = zif_abapgit_definitions=>c_state-added ).
ENDMETHOD.
METHOD match.
mo_helper->add_local(
iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA1'
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = 'D1' ).
mo_helper->add_remote(
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = 'D1' ).
mo_result = mo_helper->run( ).
mo_result->assert_lines( 1 ).
cl_abap_unit_assert=>assert_equals(
act = mo_result->get_line( 1 )-match
exp = abap_true ).
ENDMETHOD.
METHOD diff.
mo_helper->add_local(
iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA1'
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '12345' ).
mo_helper->add_remote(
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '54321' ).
mo_result = mo_helper->run( ).
mo_result->assert_lines( 1 ).
cl_abap_unit_assert=>assert_equals(
act = mo_result->get_line( 1 )-lstate
exp = zif_abapgit_definitions=>c_state-modified ).
cl_abap_unit_assert=>assert_equals(
act = mo_result->get_line( 1 )-rstate
exp = zif_abapgit_definitions=>c_state-modified ).
ENDMETHOD.
METHOD local_outside_main.
mo_helper->add_tadir(
iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA1'
iv_devclass = '$OUTSIDE$' ).
mo_helper->add_remote(
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '54321' ).
mo_result = mo_helper->run( ).
mo_result->assert_lines( 1 ).
"" it should appear as not existing locally
cl_abap_unit_assert=>assert_equals(
act = mo_result->get_line( 1 )-rstate
exp = zif_abapgit_definitions=>c_state-added ).
ENDMETHOD.
METHOD complete.
DATA:
ls_line TYPE zif_abapgit_definitions=>ty_result,
lv_act TYPE c LENGTH 3,
lv_exp TYPE c LENGTH 3.
mo_helper->add_local(
iv_path = '/'
iv_filename = '.abapgit.xml'
iv_sha1 = '1017' ).
mo_helper->add_local(
iv_path = '/src/'
iv_filename = 'ztest_created_locally.prog.abap'
iv_sha1 = '1001' ).
mo_helper->add_local(
iv_path = '/src/'
iv_filename = 'ztest_created_locally.prog.xml'
iv_sha1 = '1022' ).
mo_helper->add_local(
iv_path = '/src/'
iv_filename = 'ztest_deleted_remotely.prog.abap'
iv_sha1 = '1016' ).
mo_helper->add_local(
iv_path = '/src/'
iv_filename = 'ztest_deleted_remotely.prog.xml'
iv_sha1 = '1003' ).
mo_helper->add_local(
iv_path = '/src/'
iv_filename = 'ztest_modified_both.prog.abap'
iv_sha1 = '1028' ).
mo_helper->add_local(
iv_path = '/src/'
iv_filename = 'ztest_modified_both.prog.xml'
iv_sha1 = '1032' ).
mo_helper->add_local(
iv_path = '/src/'
iv_filename = 'ztest_modified_locally.prog.abap'
iv_sha1 = '1023' ).
mo_helper->add_local(
iv_path = '/src/'
iv_filename = 'ztest_modified_locally.prog.xml'
iv_sha1 = '1033' ).
mo_helper->add_local(
iv_path = '/src/'
iv_filename = 'ztest_modified_remotely.prog.abap'
iv_sha1 = '1018' ).
mo_helper->add_local(
iv_path = '/src/'
iv_filename = 'ztest_modified_remotely.prog.xml'
iv_sha1 = '1011' ).
mo_helper->add_local(
iv_path = '/src/'
iv_filename = 'ztest_mod_del.prog.abap'
iv_sha1 = '1012' ).
mo_helper->add_local(
iv_path = '/src/'
iv_filename = 'ztest_mod_del.prog.xml'
iv_sha1 = '1006' ).
mo_helper->add_local(
iv_path = '/src/'
iv_filename = 'package.devc.xml'
iv_sha1 = '1027' ).
mo_helper->add_remote(
iv_path = '/'
iv_filename = '.abapgit.xml'
iv_sha1 = '1017' ).
mo_helper->add_remote(
iv_path = '/'
iv_filename = 'README.md'
iv_sha1 = '1007' ).
mo_helper->add_remote(
iv_path = '/src/'
iv_filename = 'package.devc.xml'
iv_sha1 = '1027' ).
mo_helper->add_remote(
iv_path = '/src/'
iv_filename = 'ztest_created_remotely.prog.abap'
iv_sha1 = '1025' ).
mo_helper->add_remote(
iv_path = '/src/'
iv_filename = 'ztest_created_remotely.prog.xml'
iv_sha1 = '1015' ).
mo_helper->add_remote(
iv_path = '/src/'
iv_filename = 'ztest_del_mod.prog.abap'
iv_sha1 = '1024' ).
mo_helper->add_remote(
iv_path = '/src/'
iv_filename = 'ztest_del_mod.prog.xml'
iv_sha1 = '1013' ).
mo_helper->add_remote(
iv_path = '/src/'
iv_filename = 'ztest_deleted_locally.prog.abap'
iv_sha1 = '1008' ).
mo_helper->add_remote(
iv_path = '/src/'
iv_filename = 'ztest_deleted_locally.prog.xml'
iv_sha1 = '1009' ).
mo_helper->add_remote(
iv_path = '/src/'
iv_filename = 'ztest_modified_both.prog.abap'
iv_sha1 = '1002' ).
mo_helper->add_remote(
iv_path = '/src/'
iv_filename = 'ztest_modified_both.prog.xml'
iv_sha1 = '1030' ).
mo_helper->add_remote(
iv_path = '/src/'
iv_filename = 'ztest_modified_locally.prog.abap'
iv_sha1 = '1026' ).
mo_helper->add_remote(
iv_path = '/src/'
iv_filename = 'ztest_modified_locally.prog.xml'
iv_sha1 = '1021' ).
mo_helper->add_remote(
iv_path = '/src/'
iv_filename = 'ztest_modified_remotely.prog.abap'
iv_sha1 = '1019' ).
mo_helper->add_remote(
iv_path = '/src/'
iv_filename = 'ztest_modified_remotely.prog.xml'
iv_sha1 = '1031' ).
mo_helper->add_state(
iv_path = '/'
iv_filename = '.abapgit.xml'
iv_sha1 = '1017' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'package.devc.xml'
iv_sha1 = '1027' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'ztest_deleted_locally.prog.abap'
iv_sha1 = '1008' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'ztest_deleted_locally.prog.xml'
iv_sha1 = '1009' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'ztest_deleted_remotely.prog.abap'
iv_sha1 = '1016' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'ztest_deleted_remotely.prog.xml'
iv_sha1 = '1003' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'ztest_del_mod.prog.abap'
iv_sha1 = '1020' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'ztest_del_mod.prog.xml'
iv_sha1 = '1029' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'ztest_modified_both.prog.abap'
iv_sha1 = '1010' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'ztest_modified_both.prog.xml'
iv_sha1 = '1004' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'ztest_modified_locally.prog.abap'
iv_sha1 = '1026' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'ztest_modified_locally.prog.xml'
iv_sha1 = '1021' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'ztest_modified_remotely.prog.abap'
iv_sha1 = '1018' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'ztest_modified_remotely.prog.xml'
iv_sha1 = '1011' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'ztest_mod_del.prog.abap'
iv_sha1 = '1014' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'ztest_mod_del.prog.xml'
iv_sha1 = '1005' ).
mo_result = mo_helper->run( ).
mo_result->assert_lines( 21 ).
DO 21 TIMES.
ls_line = mo_result->get_line( sy-index ).
lv_act+0(1) = ls_line-match.
lv_act+1(1) = ls_line-lstate.
lv_act+2(1) = ls_line-rstate.
CASE sy-index.
WHEN 1.
lv_exp = 'X '.
WHEN 2.
lv_exp = ' A'.
WHEN 3.
lv_exp = 'X '.
WHEN 4 OR 5.
lv_exp = ' A '.
WHEN 6 OR 7.
lv_exp = ' A'.
WHEN 8 OR 9.
lv_exp = ' DM'.
WHEN 10 OR 11.
lv_exp = ' D '.
WHEN 12 OR 13.
lv_exp = ' D'.
WHEN 14 OR 15.
lv_exp = ' MD'.
WHEN 16 OR 17.
lv_exp = ' MM'.
WHEN 18 OR 19.
lv_exp = ' M '.
WHEN 20 OR 21.
lv_exp = ' M'.
ENDCASE.
cl_abap_unit_assert=>assert_equals(
act = lv_act
exp = lv_exp
msg = |Line { sy-index }: { ls_line-filename }| ).
ENDDO.
ENDMETHOD.
METHOD deleted_remotely.
DATA:
ls_line TYPE zif_abapgit_definitions=>ty_result,
lv_act TYPE c LENGTH 3,
lv_exp TYPE c LENGTH 3.
mo_helper->add_local(
iv_path = '/src/'
iv_filename = 'ztest_deleted_remotely.prog.abap'
iv_sha1 = '1016' ).
mo_helper->add_state(
iv_path = '/src/'
iv_filename = 'ztest_deleted_remotely.prog.abap'
iv_sha1 = '2016' ). "" different checksum
mo_result = mo_helper->run( ).
mo_result->assert_lines( 1 ).
"" it should appear as deleted remotely
cl_abap_unit_assert=>assert_equals(
act = mo_result->get_line( 1 )-rstate
exp = zif_abapgit_definitions=>c_state-deleted ).
ENDMETHOD.
ENDCLASS.
",8114,False,1665.0214393326237,median
"CLASS zcl_abapgit_gui_page_diff DEFINITION
PUBLIC
INHERITING FROM zcl_abapgit_gui_page
CREATE PUBLIC.
PUBLIC SECTION.
TYPES:
BEGIN OF ty_file_diff,
path TYPE string,
filename TYPE string,
obj_type TYPE string,
obj_name TYPE string,
lstate TYPE char1,
rstate TYPE char1,
fstate TYPE char1, "" FILE state - Abstraction for shorter ifs
o_diff TYPE REF TO zcl_abapgit_diff,
changed_by TYPE xubname,
type TYPE string,
END OF ty_file_diff.
TYPES:
ty_file_diffs TYPE STANDARD TABLE OF ty_file_diff
WITH NON-UNIQUE DEFAULT KEY
WITH NON-UNIQUE SORTED KEY secondary
COMPONENTS path filename.
CONSTANTS:
BEGIN OF c_fstate,
local TYPE char1 VALUE 'L',
remote TYPE char1 VALUE 'R',
both TYPE char1 VALUE 'B',
END OF c_fstate.
METHODS constructor
IMPORTING
!iv_key TYPE zif_abapgit_persistence=>ty_repo-key
!is_file TYPE zif_abapgit_definitions=>ty_file OPTIONAL
!is_object TYPE zif_abapgit_definitions=>ty_item OPTIONAL
!it_files TYPE zif_abapgit_definitions=>ty_stage_tt OPTIONAL
RAISING
zcx_abapgit_exception.
METHODS zif_abapgit_gui_event_handler~on_event
REDEFINITION.
PROTECTED SECTION.
DATA mv_unified TYPE abap_bool VALUE abap_true ##NO_TEXT.
DATA mo_repo TYPE REF TO zcl_abapgit_repo .
DATA mt_diff_files TYPE ty_file_diffs .
METHODS get_normalized_fname_with_path
IMPORTING
!is_diff TYPE ty_file_diff
RETURNING
VALUE(rv_filename) TYPE string .
METHODS normalize_path
IMPORTING
!iv_path TYPE string
RETURNING
VALUE(rv_normalized) TYPE string .
METHODS normalize_filename
IMPORTING
!iv_filename TYPE string
RETURNING
VALUE(rv_normalized) TYPE string .
METHODS add_menu_end
IMPORTING
!io_menu TYPE REF TO zcl_abapgit_html_toolbar .
METHODS calculate_diff
IMPORTING
!is_file TYPE zif_abapgit_definitions=>ty_file OPTIONAL
!is_object TYPE zif_abapgit_definitions=>ty_item OPTIONAL
!it_files TYPE zif_abapgit_definitions=>ty_stage_tt OPTIONAL
RAISING
zcx_abapgit_exception .
METHODS add_menu_begin
IMPORTING
!io_menu TYPE REF TO zcl_abapgit_html_toolbar .
METHODS render_table_head_non_unified
IMPORTING
!ii_html TYPE REF TO zif_abapgit_html
!is_diff TYPE ty_file_diff .
METHODS render_beacon_begin_of_row
IMPORTING
!ii_html TYPE REF TO zif_abapgit_html
!is_diff TYPE ty_file_diff .
METHODS render_diff_head_after_state
IMPORTING
!ii_html TYPE REF TO zif_abapgit_html
!is_diff TYPE ty_file_diff .
METHODS insert_nav
RETURNING
VALUE(rv_insert_nav) TYPE abap_bool .
METHODS render_line_split_row
IMPORTING
!ii_html TYPE REF TO zif_abapgit_html
!iv_filename TYPE string
!is_diff_line TYPE zif_abapgit_definitions=>ty_diff
!iv_index TYPE sy-tabix
!iv_fstate TYPE char1
!iv_new TYPE string
!iv_old TYPE string
RAISING
zcx_abapgit_exception .
METHODS build_menu
RETURNING
VALUE(ro_menu) TYPE REF TO zcl_abapgit_html_toolbar .
METHODS render_content
REDEFINITION .
PRIVATE SECTION.
CONSTANTS:
BEGIN OF c_actions,
toggle_unified TYPE string VALUE 'toggle_unified',
END OF c_actions .
DATA mt_delayed_lines TYPE zif_abapgit_definitions=>ty_diffs_tt .
DATA mv_repo_key TYPE zif_abapgit_persistence=>ty_repo-key .
DATA mv_seed TYPE string . "" Unique page id to bind JS sessionStorage
METHODS render_diff
IMPORTING
!is_diff TYPE ty_file_diff
RETURNING
VALUE(ri_html) TYPE REF TO zif_abapgit_html
RAISING
zcx_abapgit_exception .
METHODS render_diff_head
IMPORTING
!is_diff TYPE ty_file_diff
RETURNING
VALUE(ri_html) TYPE REF TO zif_abapgit_html
RAISING
zcx_abapgit_exception .
METHODS render_table_head
IMPORTING
!is_diff TYPE ty_file_diff
RETURNING
VALUE(ri_html) TYPE REF TO zif_abapgit_html
RAISING
zcx_abapgit_exception .
METHODS render_beacon
IMPORTING
!is_diff_line TYPE zif_abapgit_definitions=>ty_diff
!is_diff TYPE ty_file_diff
RETURNING
VALUE(ri_html) TYPE REF TO zif_abapgit_html .
METHODS render_line_split
IMPORTING
!is_diff_line TYPE zif_abapgit_definitions=>ty_diff
!iv_filename TYPE string
!iv_fstate TYPE char1
!iv_index TYPE sy-tabix
RETURNING
VALUE(ri_html) TYPE REF TO zif_abapgit_html
RAISING
zcx_abapgit_exception .
METHODS render_line_unified
IMPORTING
!is_diff_line TYPE zif_abapgit_definitions=>ty_diff OPTIONAL
RETURNING
VALUE(ri_html) TYPE REF TO zif_abapgit_html .
METHODS append_diff
IMPORTING
!it_remote TYPE zif_abapgit_definitions=>ty_files_tt
!it_local TYPE zif_abapgit_definitions=>ty_files_item_tt
!is_status TYPE zif_abapgit_definitions=>ty_result
RAISING
zcx_abapgit_exception .
METHODS is_binary
IMPORTING
!iv_d1 TYPE xstring
!iv_d2 TYPE xstring
RETURNING
VALUE(rv_yes) TYPE abap_bool .
METHODS add_jump_sub_menu
IMPORTING
!io_menu TYPE REF TO zcl_abapgit_html_toolbar .
METHODS add_filter_sub_menu
IMPORTING
!io_menu TYPE REF TO zcl_abapgit_html_toolbar .
METHODS render_lines
IMPORTING
!is_diff TYPE ty_file_diff
RETURNING
VALUE(ri_html) TYPE REF TO zif_abapgit_html
RAISING
zcx_abapgit_exception .
METHODS render_table_head_unified
IMPORTING
!ii_html TYPE REF TO zif_abapgit_html .
METHODS render_scripts
RETURNING
VALUE(ri_html) TYPE REF TO zif_abapgit_html
RAISING
zcx_abapgit_exception .
METHODS filter_diff_by_files
IMPORTING
!it_files TYPE zif_abapgit_definitions=>ty_stage_tt
CHANGING
!ct_diff_files TYPE ty_file_diffs .
ENDCLASS.
CLASS zcl_abapgit_gui_page_diff IMPLEMENTATION.
METHOD add_filter_sub_menu.
DATA:
lo_sub_filter TYPE REF TO zcl_abapgit_html_toolbar,
lt_types TYPE string_table,
lt_users TYPE string_table.
FIELD-SYMBOLS: LIKE LINE OF mt_diff_files,
TYPE string.
"" Get unique
LOOP AT mt_diff_files ASSIGNING .
APPEND -type TO lt_types.
APPEND -changed_by TO lt_users.
ENDLOOP.
SORT lt_types.
DELETE ADJACENT DUPLICATES FROM lt_types.
SORT lt_users.
DELETE ADJACENT DUPLICATES FROM lt_users.
IF lines( lt_types ) > 1 OR lines( lt_users ) > 1.
CREATE OBJECT lo_sub_filter EXPORTING iv_id = 'diff-filter'.
"" File types
IF lines( lt_types ) > 1.
lo_sub_filter->add( iv_txt = 'TYPE'
iv_typ = zif_abapgit_html=>c_action_type-separator ).
LOOP AT lt_types ASSIGNING .
lo_sub_filter->add( iv_txt =
iv_typ = zif_abapgit_html=>c_action_type-onclick
iv_aux = 'type'
iv_chk = abap_true ).
ENDLOOP.
ENDIF.
"" Changed by
IF lines( lt_users ) > 1.
lo_sub_filter->add( iv_txt = 'CHANGED BY'
iv_typ = zif_abapgit_html=>c_action_type-separator ).
LOOP AT lt_users ASSIGNING .
lo_sub_filter->add( iv_txt =
iv_typ = zif_abapgit_html=>c_action_type-onclick
iv_aux = 'changed-by'
iv_chk = abap_true ).
ENDLOOP.
ENDIF.
io_menu->add( iv_txt = 'Filter'
io_sub = lo_sub_filter ).
ENDIF.
ENDMETHOD.
METHOD add_jump_sub_menu.
DATA: lo_sub_jump TYPE REF TO zcl_abapgit_html_toolbar,
lv_jump_target TYPE string.
FIELD-SYMBOLS: LIKE LINE OF mt_diff_files.
CREATE OBJECT lo_sub_jump EXPORTING iv_id = 'jump'.
LOOP AT mt_diff_files ASSIGNING .
lv_jump_target = -path && -filename.
lo_sub_jump->add(
iv_id = |li_jump_{ sy-tabix }|
iv_txt = lv_jump_target
iv_typ = zif_abapgit_html=>c_action_type-onclick ).
ENDLOOP.
io_menu->add( iv_txt = 'Jump'
io_sub = lo_sub_jump ).
ENDMETHOD.
METHOD add_menu_begin.
ENDMETHOD.
METHOD add_menu_end.
io_menu->add( iv_txt = 'Split/Unified view'
iv_act = c_actions-toggle_unified ).
ENDMETHOD.
METHOD append_diff.
DATA:
lv_offs TYPE i,
ls_r_dummy LIKE LINE OF it_remote ##NEEDED,
ls_l_dummy LIKE LINE OF it_local ##NEEDED.
FIELD-SYMBOLS: LIKE LINE OF it_remote,
LIKE LINE OF it_local,
LIKE LINE OF mt_diff_files.
READ TABLE it_remote ASSIGNING
WITH KEY filename = is_status-filename
path = is_status-path.
IF sy-subrc <> 0.
ASSIGN ls_r_dummy TO .
ENDIF.
READ TABLE it_local ASSIGNING
WITH KEY file-filename = is_status-filename
file-path = is_status-path.
IF sy-subrc <> 0.
ASSIGN ls_l_dummy TO .
ENDIF.
IF IS INITIAL AND IS INITIAL.
zcx_abapgit_exception=>raise( |DIFF: file not found { is_status-filename }| ).
ENDIF.
APPEND INITIAL LINE TO mt_diff_files ASSIGNING .
-path = is_status-path.
-filename = is_status-filename.
-obj_type = is_status-obj_type.
-obj_name = is_status-obj_name.
-lstate = is_status-lstate.
-rstate = is_status-rstate.
IF -lstate IS NOT INITIAL AND -rstate IS NOT INITIAL.
-fstate = c_fstate-both.
ELSEIF -lstate IS NOT INITIAL.
-fstate = c_fstate-local.
ELSE. ""rstate IS NOT INITIAL, lstate = empty.
-fstate = c_fstate-remote.
ENDIF.
"" Changed by
IF -item-obj_type IS NOT INITIAL.
-changed_by = zcl_abapgit_objects=>changed_by( -item ).
ENDIF.
IF -changed_by IS INITIAL.
-changed_by = zcl_abapgit_objects_super=>c_user_unknown.
ENDIF.
"" Extension
IF -file-filename IS NOT INITIAL.
-type = reverse( -file-filename ).
ELSE.
-type = reverse( -filename ).
ENDIF.
FIND FIRST OCCURRENCE OF '.' IN -type MATCH OFFSET lv_offs.
-type = reverse( substring( val = -type
len = lv_offs ) ).
IF -type <> 'xml' AND -type <> 'abap'.
-type = 'other'.
ENDIF.
IF -type = 'other'
AND is_binary( iv_d1 = -data
iv_d2 = -file-data ) = abap_true.
-type = 'binary'.
ENDIF.
"" Diff data
IF -type <> 'binary'.
IF -fstate = c_fstate-remote. "" Remote file leading changes
CREATE OBJECT -o_diff
EXPORTING
iv_new = -data
iv_old = -file-data.
ELSE. "" Local leading changes or both were modified
CREATE OBJECT -o_diff
EXPORTING
iv_new = -file-data
iv_old = -data.
ENDIF.
ENDIF.
ENDMETHOD.
METHOD build_menu.
CREATE OBJECT ro_menu.
add_menu_begin( ro_menu ).
add_jump_sub_menu( ro_menu ).
add_filter_sub_menu( ro_menu ).
add_menu_end( ro_menu ).
ENDMETHOD.
METHOD calculate_diff.
DATA: lt_remote TYPE zif_abapgit_definitions=>ty_files_tt,
lt_local TYPE zif_abapgit_definitions=>ty_files_item_tt,
lt_status TYPE zif_abapgit_definitions=>ty_results_tt.
FIELD-SYMBOLS: LIKE LINE OF lt_status.
CLEAR: mt_diff_files.
lt_remote = mo_repo->get_files_remote( ).
lt_local = mo_repo->get_files_local( ).
mo_repo->reset_status( ).
lt_status = mo_repo->status( ).
IF is_file IS NOT INITIAL. "" Diff for one file
READ TABLE lt_status ASSIGNING
WITH KEY path = is_file-path filename = is_file-filename.
append_diff( it_remote = lt_remote
it_local = lt_local
is_status = ).
ELSEIF is_object IS NOT INITIAL. "" Diff for whole object
LOOP AT lt_status ASSIGNING
WHERE obj_type = is_object-obj_type
AND obj_name = is_object-obj_name
AND match IS INITIAL.
append_diff( it_remote = lt_remote
it_local = lt_local
is_status = ).
ENDLOOP.
ELSE. "" Diff for the whole repo
SORT lt_status BY
path ASCENDING
filename ASCENDING.
LOOP AT lt_status ASSIGNING WHERE match IS INITIAL.
append_diff( it_remote = lt_remote
it_local = lt_local
is_status = ).
ENDLOOP.
ENDIF.
filter_diff_by_files(
EXPORTING
it_files = it_files
CHANGING
ct_diff_files = mt_diff_files ).
ENDMETHOD.
METHOD constructor.
DATA: lv_ts TYPE timestamp.
super->constructor( ).
ms_control-page_title = 'Diff'.
mv_unified = zcl_abapgit_persistence_user=>get_instance( )->get_diff_unified( ).
mv_repo_key = iv_key.
mo_repo ?= zcl_abapgit_repo_srv=>get_instance( )->get( iv_key ).
GET TIME STAMP FIELD lv_ts.
mv_seed = |diff{ lv_ts }|. "" Generate based on time
ASSERT is_file IS INITIAL OR is_object IS INITIAL. "" just one passed
calculate_diff(
is_file = is_file
is_object = is_object
it_files = it_files ).
IF lines( mt_diff_files ) = 0.
zcx_abapgit_exception=>raise( 'PAGE_DIFF ERROR: No diff files found' ).
ENDIF.
ms_control-page_menu = build_menu( ).
ENDMETHOD.
METHOD filter_diff_by_files.
FIELD-SYMBOLS: TYPE ty_file_diff.
IF lines( it_files ) = 0.
RETURN.
ENDIF.
"" Diff only for specified files
LOOP AT ct_diff_files ASSIGNING .
READ TABLE it_files TRANSPORTING NO FIELDS
WITH KEY file-filename = -filename.
IF sy-subrc <> 0.
DELETE TABLE ct_diff_files FROM .
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD get_normalized_fname_with_path.
rv_filename = normalize_path( is_diff-path )
&& `_`
&& normalize_filename( is_diff-filename ).
ENDMETHOD.
METHOD insert_nav.
ENDMETHOD.
METHOD is_binary.
FIELD-SYMBOLS LIKE iv_d1.
IF iv_d1 IS NOT INITIAL. "" One of them might be new and so empty
ASSIGN iv_d1 TO .
ELSE.
ASSIGN iv_d2 TO .
ENDIF.
rv_yes = zcl_abapgit_utils=>is_binary( ).
ENDMETHOD.
METHOD normalize_filename.
rv_normalized = replace( val = iv_filename
sub = '.'
occ = 0
with = '_' ).
ENDMETHOD.
METHOD normalize_path.
rv_normalized = replace( val = iv_path
sub = '/'
occ = 0
with = '_' ).
ENDMETHOD.
METHOD render_beacon.
DATA: lv_beacon TYPE string,
lt_beacons TYPE zif_abapgit_definitions=>ty_string_tt.
CREATE OBJECT ri_html TYPE zcl_abapgit_html.
IF is_diff_line-beacon > 0.
lt_beacons = is_diff-o_diff->get_beacons( ).
READ TABLE lt_beacons INTO lv_beacon INDEX is_diff_line-beacon.
ELSE.
lv_beacon = '---'.
ENDIF.
ri_html->add( '' ).
ri_html->add( '' ).
render_beacon_begin_of_row(
ii_html = ri_html
is_diff = is_diff ).
IF mv_unified = abap_true.
ri_html->add( ' | ' ).
ri_html->add( ' | ' ).
ri_html->add( |@@ { is_diff_line-new_num } @@ { lv_beacon } | | ).
ELSE.
ri_html->add( |@@ { is_diff_line-new_num } @@ { lv_beacon } | | ).
ENDIF.
ri_html->add( '
' ).
ri_html->add( '' ).
ENDMETHOD.
METHOD render_beacon_begin_of_row.
ii_html->add( ' | ' ).
ENDMETHOD.
METHOD render_content.
DATA: ls_diff_file LIKE LINE OF mt_diff_files,
li_progress TYPE REF TO zif_abapgit_progress.
CREATE OBJECT ri_html TYPE zcl_abapgit_html.
li_progress = zcl_abapgit_progress=>get_instance( lines( mt_diff_files ) ).
ri_html->add( `` ).
ri_html->add( zcl_abapgit_gui_chunk_lib=>render_repo_top( mo_repo ) ).
ri_html->add( `
` ).
ri_html->add( || ).
ri_html->add( zcl_abapgit_gui_chunk_lib=>render_js_error_banner( ) ).
LOOP AT mt_diff_files INTO ls_diff_file.
li_progress->show(
iv_current = sy-tabix
iv_text = |Render Diff - { ls_diff_file-filename }| ).
ri_html->add( render_diff( ls_diff_file ) ).
ENDLOOP.
IF sy-subrc <> 0.
ri_html->add( |No more diffs| ).
ENDIF.
ri_html->add( '
' ).
register_deferred_script( render_scripts( ) ).
ENDMETHOD.
METHOD render_diff.
CREATE OBJECT ri_html TYPE zcl_abapgit_html.
ri_html->add( || ).
ri_html->add( render_diff_head( is_diff ) ).
"" Content
IF is_diff-type <> 'binary'.
ri_html->add( '
' ).
ri_html->add( |
| ).
ri_html->add( render_table_head( is_diff ) ).
ri_html->add( render_lines( is_diff ) ).
ri_html->add( '
' ).
ELSE.
ri_html->add( '
' ).
ri_html->add( 'The content seems to be binary.' ).
ri_html->add( 'Cannot display as diff.' ).
ENDIF.
ri_html->add( '
' ).
ri_html->add( '
' ).
ENDMETHOD.
METHOD render_diff_head.
DATA: ls_stats TYPE zif_abapgit_definitions=>ty_count,
lv_adt_link TYPE string.
CREATE OBJECT ri_html TYPE zcl_abapgit_html.
ri_html->add( '
' ).
ri_html->add_icon(
iv_name = 'chevron-down'
iv_hint = 'Collapse/Expand'
iv_class = 'cursor-pointer'
iv_onclick = 'onDiffCollapse(event)' ).
IF is_diff-type <> 'binary'.
ls_stats = is_diff-o_diff->stats( ).
IF is_diff-fstate = c_fstate-both. "" Merge stats into 'update' if both were changed
ls_stats-update = ls_stats-update + ls_stats-insert + ls_stats-delete.
CLEAR: ls_stats-insert, ls_stats-delete.
ENDIF.
ri_html->add( |+ { ls_stats-insert }| ).
ri_html->add( |- { ls_stats-delete }| ).
ri_html->add( |~ { ls_stats-update }| ).
ENDIF.
"" no links for nonexistent or deleted objects
IF NOT ( is_diff-lstate = zif_abapgit_definitions=>c_state-unchanged AND
is_diff-rstate = zif_abapgit_definitions=>c_state-added ) AND
NOT is_diff-lstate = zif_abapgit_definitions=>c_state-deleted.
lv_adt_link = ri_html->a(
iv_txt = |{ is_diff-path }{ is_diff-filename }|
iv_typ = zif_abapgit_html=>c_action_type-sapevent
iv_act = |jump?TYPE={ is_diff-obj_type }&NAME={ is_diff-obj_name }| ).
ENDIF.
IF lv_adt_link IS NOT INITIAL.
ri_html->add( |{ lv_adt_link }| ).
ELSE.
ri_html->add( |{ is_diff-path }{ is_diff-filename }| ).
ENDIF.
ri_html->add( zcl_abapgit_gui_chunk_lib=>render_item_state(
iv_lstate = is_diff-lstate
iv_rstate = is_diff-rstate ) ).
render_diff_head_after_state(
ii_html = ri_html
is_diff = is_diff ).
ri_html->add( 'Last Changed by: ' ).
ri_html->add( zcl_abapgit_gui_chunk_lib=>render_user_name( is_diff-changed_by ) ).
ri_html->add( '' ).
ri_html->add( '
' ).
ENDMETHOD.
METHOD render_diff_head_after_state.
IF is_diff-fstate = c_fstate-both AND mv_unified = abap_true.
ii_html->add( '
Attention: Unified mode'
&& ' highlighting for MM assumes local file is newer ! ' ).
ENDIF.
ENDMETHOD.
METHOD render_lines.
DATA: lo_highlighter TYPE REF TO zcl_abapgit_syntax_highlighter,
lt_diffs TYPE zif_abapgit_definitions=>ty_diffs_tt,
lv_insert_nav TYPE abap_bool,
lv_tabix TYPE syst-tabix.
FIELD-SYMBOLS
LIKE LINE OF lt_diffs.
lo_highlighter = zcl_abapgit_syntax_highlighter=>create( is_diff-filename ).
CREATE OBJECT ri_html TYPE zcl_abapgit_html.
lt_diffs = is_diff-o_diff->get( ).
lv_insert_nav = insert_nav( ).
LOOP AT lt_diffs ASSIGNING .
lv_tabix = sy-tabix.
IF -short = abap_false.
lv_insert_nav = abap_true.
CONTINUE.
ENDIF.
IF lv_insert_nav = abap_true. "" Insert separator line with navigation
ri_html->add( render_beacon( is_diff_line =
is_diff = is_diff ) ).
lv_insert_nav = abap_false.
ENDIF.
IF lo_highlighter IS BOUND.
-new = lo_highlighter->process_line( -new ).
-old = lo_highlighter->process_line( -old ).
ELSE.
-new = escape( val = -new
format = cl_abap_format=>e_html_attr ).
-old = escape( val = -old
format = cl_abap_format=>e_html_attr ).
ENDIF.
CONDENSE -new_num. ""get rid of leading spaces
CONDENSE -old_num.
IF mv_unified = abap_true.
ri_html->add( render_line_unified( is_diff_line = ) ).
ELSE.
ri_html->add( render_line_split( is_diff_line =
iv_filename = get_normalized_fname_with_path( is_diff )
iv_fstate = is_diff-fstate
iv_index = lv_tabix ) ).
ENDIF.
ENDLOOP.
IF mv_unified = abap_true.
ri_html->add( render_line_unified( ) ). "" Release delayed lines
ENDIF.
ENDMETHOD.
METHOD render_line_split.
DATA: lv_new TYPE string,
lv_old TYPE string,
lv_mark TYPE string,
lv_bg TYPE string.
CREATE OBJECT ri_html TYPE zcl_abapgit_html.
"" New line
lv_mark = ` `.
IF is_diff_line-result IS NOT INITIAL.
IF iv_fstate = c_fstate-both OR is_diff_line-result = zif_abapgit_definitions=>c_diff-update.
lv_bg = ' diff_upd'.
lv_mark = `~`.
ELSEIF is_diff_line-result = zif_abapgit_definitions=>c_diff-insert.
lv_bg = ' diff_ins'.
lv_mark = `+`.
ENDIF.
ENDIF.
lv_new = | | |
&& |{ lv_mark } | |
&& |{ is_diff_line-new } | |.
"" Old line
CLEAR lv_bg.
lv_mark = ` `.
IF is_diff_line-result IS NOT INITIAL.
IF iv_fstate = c_fstate-both OR is_diff_line-result = zif_abapgit_definitions=>c_diff-update.
lv_bg = ' diff_upd'.
lv_mark = `~`.
ELSEIF is_diff_line-result = zif_abapgit_definitions=>c_diff-delete.
lv_bg = ' diff_del'.
lv_mark = `-`.
ENDIF.
ENDIF.
lv_old = | | |
&& |{ lv_mark } | |
&& |{ is_diff_line-old } | |.
"" render line, inverse sides if remote is newer
ri_html->add( '' ).
render_line_split_row(
ii_html = ri_html
iv_filename = iv_filename
is_diff_line = is_diff_line
iv_index = iv_index
iv_fstate = iv_fstate
iv_old = lv_old
iv_new = lv_new ).
ri_html->add( '
' ).
ENDMETHOD.
METHOD render_line_split_row.
IF iv_fstate = c_fstate-remote. "" Remote file leading changes
ii_html->add( iv_old ). "" local
ii_html->add( iv_new ). "" remote
ELSE. "" Local leading changes or both were modified
ii_html->add( iv_new ). "" local
ii_html->add( iv_old ). "" remote
ENDIF.
ENDMETHOD.
METHOD render_line_unified.
FIELD-SYMBOLS LIKE LINE OF mt_delayed_lines.
CREATE OBJECT ri_html TYPE zcl_abapgit_html.
"" Release delayed subsequent update lines
IF is_diff_line-result <> zif_abapgit_definitions=>c_diff-update.
LOOP AT mt_delayed_lines ASSIGNING .
ri_html->add( '' ).
ri_html->add( || -old_num }""> | |
&& | | |
&& |- | |
&& |{ -old } | | ).
ri_html->add( '
' ).
ENDLOOP.
LOOP AT mt_delayed_lines ASSIGNING .
ri_html->add( '' ).
ri_html->add( | | |
&& |-new_num }""> | |
&& |+ | |
&& |{ -new } | | ).
ri_html->add( '
' ).
ENDLOOP.
CLEAR mt_delayed_lines.
ENDIF.
ri_html->add( '' ).
CASE is_diff_line-result.
WHEN zif_abapgit_definitions=>c_diff-update.
APPEND is_diff_line TO mt_delayed_lines. "" Delay output of subsequent updates
WHEN zif_abapgit_definitions=>c_diff-insert.
ri_html->add( | | |
&& | | |
&& |+ | |
&& |{ is_diff_line-new } | | ).
WHEN zif_abapgit_definitions=>c_diff-delete.
ri_html->add( | | |
&& | | |
&& |- | |
&& |{ is_diff_line-old } | | ).
WHEN OTHERS. ""none
ri_html->add( | | |
&& | | |
&& | | |
&& |{ is_diff_line-old } | | ).
ENDCASE.
ri_html->add( '
' ).
ENDMETHOD.
METHOD render_scripts.
CREATE OBJECT ri_html TYPE zcl_abapgit_html.
ri_html->set_title( cl_abap_typedescr=>describe_by_object_ref( me )->get_relative_name( ) ).
ri_html->add( 'restoreScrollPosition();' ).
ri_html->add( 'var gHelper = new DiffHelper({' ).
ri_html->add( | seed: ""{ mv_seed }"",| ).
ri_html->add( ' ids: {' ).
ri_html->add( ' jump: ""jump"",' ).
ri_html->add( ' diffList: ""diff-list"",' ).
ri_html->add( ' filterMenu: ""diff-filter"",' ).
ri_html->add( ' }' ).
ri_html->add( '});' ).
ri_html->add( 'addMarginBottom();' ).
ri_html->add( 'var gGoJumpPalette = new CommandPalette(enumerateJumpAllFiles, {' ).
ri_html->add( ' toggleKey: ""F2"",' ).
ri_html->add( ' hotkeyDescription: ""Jump to file ...""' ).
ri_html->add( '});' ).
"" Feature for selecting ABAP code by column and copy to clipboard
ri_html->add( 'var columnSelection = new DiffColumnSelection();' ).
ENDMETHOD.
METHOD render_table_head.
CREATE OBJECT ri_html TYPE zcl_abapgit_html.
ri_html->add( '' ).
ri_html->add( '' ).
IF mv_unified = abap_true.
render_table_head_unified( ri_html ).
ELSE.
render_table_head_non_unified(
ii_html = ri_html
is_diff = is_diff ).
ENDIF.
ri_html->add( '
' ).
ri_html->add( '' ).
ENDMETHOD.
METHOD render_table_head_non_unified.
ii_html->add( ' | ' ).
ii_html->add( ' | ' ).
ii_html->add( 'LOCAL | ' ).
ii_html->add( ' | ' ).
ii_html->add( ' | ' ).
ii_html->add( 'REMOTE | ' ).
ENDMETHOD.
METHOD render_table_head_unified.
ii_html->add( 'old | ' ).
ii_html->add( 'new | ' ).
ii_html->add( ' | ' ).
ii_html->add( 'code | ' ).
ENDMETHOD.
METHOD zif_abapgit_gui_event_handler~on_event.
CASE ii_event->mv_action.
WHEN c_actions-toggle_unified. "" Toggle file diplay
mv_unified = zcl_abapgit_persistence_user=>get_instance( )->toggle_diff_unified( ).
rs_handled-state = zcl_abapgit_gui=>c_event_state-re_render.
WHEN OTHERS.
rs_handled = super->zif_abapgit_gui_event_handler~on_event( ii_event ).
ENDCASE.
ENDMETHOD.
ENDCLASS.
",8133,False,1520.3204499224819,median
"class ltcl_mockup_stub_factory_test definition final
for testing
duration short
risk level harmless.
private section.
methods main_test_stub for testing.
methods connect_deep_corresponding for testing raising zcx_mockup_loader_error.
methods connect_and_overrides for testing raising zcx_mockup_loader_error.
methods build_config for testing raising zcx_mockup_loader_error.
methods build_config_filter_type for testing raising zcx_mockup_loader_error.
methods build_config_multi_filter_neg for testing raising zcx_mockup_loader_error.
methods instantiation for testing.
methods forward_method for testing.
methods proxy_forwarding for testing raising zcx_mockup_loader_error.
methods filtering for testing raising zcx_mockup_loader_error.
methods filtering_w_const for testing raising zcx_mockup_loader_error.
methods filtering_w_struc_param for testing raising zcx_mockup_loader_error.
methods filtering_multi for testing raising zcx_mockup_loader_error.
methods filtering_multi_and_const for testing raising zcx_mockup_loader_error.
methods returning_value for testing raising zcx_mockup_loader_error.
methods corresponding for testing raising zcx_mockup_loader_error.
methods filter_by_range_param for testing raising zcx_mockup_loader_error.
methods controls for testing raising zcx_mockup_loader_error.
methods const_value for testing raising zcx_mockup_loader_error.
methods connect_string_positive for testing raising zcx_mockup_loader_error.
methods parse_string_negative for testing.
methods parse_string_positive for testing raising zcx_mockup_loader_error.
methods connect_string_multi for testing raising zcx_mockup_loader_error.
methods connect_string_multi_const for testing raising zcx_mockup_loader_error.
methods connect_string_multi_1value for testing raising zcx_mockup_loader_error.
"" HELPERS
methods get_ml
returning
value(ro_ml) type ref to zcl_mockup_loader
raising zcx_mockup_loader_error.
methods get_factory
importing
io_ml type ref to zcl_mockup_loader
io_proxy type ref to zif_mockup_loader_stub_dummy optional
returning
value(ro_factory) type ref to zcl_mockup_loader_stub_factory
raising zcx_mockup_loader_error.
methods get_sflights
importing
io_ml type ref to zcl_mockup_loader
returning
value(rt_tab) type flighttab
raising zcx_mockup_loader_error.
endclass.
class lcl_test_proxy_target definition.
public section.
interfaces zif_mockup_loader_stub_dummy.
class-methods create returning value(ro_instance) type ref to lcl_test_proxy_target.
endclass.
class lcl_test_proxy_target implementation.
method create.
create object ro_instance.
endmethod.
method zif_mockup_loader_stub_dummy~proxy_test.
r_val = |{ i_p1 } { i_p2 }|.
endmethod.
method zif_mockup_loader_stub_dummy~tab_return.
endmethod.
method zif_mockup_loader_stub_dummy~tab_return_w_date.
endmethod.
method zif_mockup_loader_stub_dummy~tab_return_by_range.
endmethod.
method zif_mockup_loader_stub_dummy~tab_return_extract_by_date.
endmethod.
method zif_mockup_loader_stub_dummy~tab_return_w_struc_param.
endmethod.
method zif_mockup_loader_stub_dummy~tab_export.
endmethod.
method zif_mockup_loader_stub_dummy~tab_change.
endmethod.
method zif_mockup_loader_stub_dummy~wrong_return.
endmethod.
method zif_mockup_loader_stub_dummy~wrong_sift.
endmethod.
method zif_mockup_loader_stub_dummy~gen_param_target.
endmethod.
method zif_mockup_loader_stub_dummy~return_value.
endmethod.
method zif_mockup_loader_stub_dummy~return_value_w_date.
endmethod.
method zif_mockup_loader_stub_dummy~return_deep.
endmethod.
endclass.
class lcl_test_base definition final.
public section.
class-methods main_test
importing iv_factory_classname type seoclsname.
endclass.
class lcl_test_base implementation.
method main_test.
data lo_dc type ref to zcl_mockup_loader_stub_factory.
data li_if type ref to zif_mockup_loader_stub_dummy.
data lo_ml type ref to zcl_mockup_loader.
data lt_exp type flighttab.
data lo_ex type ref to zcx_mockup_loader_error.
try.
lo_ml = zcl_mockup_loader=>create(
i_type = 'MIME'
i_path = 'ZMOCKUP_LOADER_EXAMPLE'
i_encoding = zif_mockup_loader_constants=>encoding_utf16 ).
create object lo_dc type (iv_factory_classname)
exporting
ii_ml_instance = lo_ml
i_interface_name = 'ZIF_MOCKUP_LOADER_STUB_DUMMY'.
lo_dc->connect_method(
i_sift_param = 'I_CONNID'
i_mock_tab_key = 'CONNID'
i_method_name = 'TAB_RETURN'
i_mock_name = 'EXAMPLE/sflight' ).
lo_dc->connect_method(
i_method_name = 'TAB_EXPORT'
i_mock_name = 'EXAMPLE/sflight'
i_output_param = 'E_TAB' ).
lo_dc->connect_method(
i_method_name = 'TAB_CHANGE'
i_mock_name = 'EXAMPLE/sflight'
i_output_param = 'C_TAB' ).
li_if ?= lo_dc->generate_stub( ).
lo_ml->load_data(
exporting
i_obj = 'EXAMPLE/sflight'
i_strict = abap_false
importing
e_container = lt_exp ).
delete lt_exp where connid <> '1000'.
data lt_res type flighttab.
lt_res = li_if->tab_return( i_connid = '1000' ).
cl_abap_unit_assert=>assert_equals( act = lt_res exp = lt_exp ).
lo_ml->load_data(
exporting
i_obj = 'EXAMPLE/sflight'
i_strict = abap_false
importing
e_container = lt_exp ).
clear lt_res.
li_if->tab_export( exporting i_connid = '1000' importing e_tab = lt_res ).
cl_abap_unit_assert=>assert_equals( act = lt_res exp = lt_exp ).
clear lt_res.
li_if->tab_change( exporting i_connid = '1000' changing c_tab = lt_res ).
cl_abap_unit_assert=>assert_equals( act = lt_res exp = lt_exp ).
catch zcx_mockup_loader_error into lo_ex.
cl_abap_unit_assert=>fail( ).
endtry.
endmethod.
endclass.
define assert_excode.
cl_abap_unit_assert=>assert_not_initial( act = lo_ex ).
cl_abap_unit_assert=>assert_equals( exp = &1 act = lo_ex->code ).
end-of-definition.
class zcl_mockup_loader_stub_factory definition local friends ltcl_mockup_stub_factory_test.
class ltcl_mockup_stub_factory_test implementation.
method main_test_stub.
lcl_test_base=>main_test( 'ZCL_MOCKUP_LOADER_STUB_FACTORY' ).
endmethod.
method connect_deep_corresponding.
data lo_ml type ref to zcl_mockup_loader.
data lo_dc type ref to zcl_mockup_loader_stub_factory.
data li_if type ref to zif_mockup_loader_stub_dummy.
data lt_exp type zif_mockup_loader_stub_dummy=>tt_deep.
lo_ml = zcl_mockup_loader=>create(
i_type = 'MIME'
i_path = 'ZMOCKUP_LOADER_EXAMPLE'
i_encoding = zif_mockup_loader_constants=>encoding_utf16 ).
create object lo_dc
exporting
ii_ml_instance = lo_ml
i_interface_name = 'ZIF_MOCKUP_LOADER_STUB_DUMMY'.
lo_dc->connect_method(
i_sift_param = 'I_CONNID'
i_mock_tab_key = 'CONNID'
i_method_name = 'RETURN_DEEP'
i_deep = abap_true
i_corresponding = abap_true
i_mock_name = 'EXAMPLE/sflight' ).
li_if ?= lo_dc->generate_stub( ).
lo_ml->load_data(
exporting
i_obj = 'EXAMPLE/sflight'
i_strict = abap_false
i_corresponding = abap_true
i_deep = abap_true
importing
e_container = lt_exp ).
delete lt_exp where connid <> '2000'.
data lt_res like lt_exp.
lt_res = li_if->return_deep( i_connid = '2000' ).
cl_abap_unit_assert=>assert_equals( act = lt_res exp = lt_exp ).
endmethod.
method connect_and_overrides.
data lo_dc type ref to zcl_mockup_loader_stub_factory.
data lo_ml type ref to zcl_mockup_loader.
data lo_ex type ref to zcx_mockup_loader_error.
data ls_config like line of lo_dc->mt_config.
lo_ml = zcl_mockup_loader=>create(
i_type = 'MIME'
i_path = 'ZMOCKUP_LOADER_EXAMPLE'
i_encoding = zif_mockup_loader_constants=>encoding_utf16 ).
create object lo_dc
exporting
io_proxy_target = lcl_test_proxy_target=>create( )
ii_ml_instance = lo_ml
i_interface_name = 'ZIF_MOCKUP_LOADER_STUB_DUMMY'.
lo_dc->connect_method(
i_method_name = 'TAB_RETURN'
i_mock_name = 'EXAMPLE/sflight' ).
"" Multiple connect
try.
lo_dc->connect_method(
i_method_name = 'TAB_RETURN'
i_mock_name = 'EXAMPLE/sflight' ).
cl_abap_unit_assert=>fail( ).
catch zcx_mockup_loader_error into lo_ex.
cl_abap_unit_assert=>assert_equals( exp = 'MC' act = lo_ex->code ).
endtry.
try. "" Multiple forward
lo_dc->forward_method( 'TAB_RETURN' ).
cl_abap_unit_assert=>fail( ).
catch zcx_mockup_loader_error into lo_ex.
cl_abap_unit_assert=>assert_equals( exp = 'MC' act = lo_ex->code ).
endtry.
"" Override
create object lo_dc
exporting
ii_ml_instance = lo_ml
io_proxy_target = lcl_test_proxy_target=>create( )
i_allow_overrides = abap_true
i_interface_name = 'ZIF_MOCKUP_LOADER_STUB_DUMMY'.
lo_dc->connect_method(
i_method_name = 'TAB_RETURN'
i_mock_name = 'EXAMPLE/sflight' ).
lo_dc->connect_method(
i_method_name = 'TAB_RETURN'
i_mock_name = 'EXAMPLE/override' ).
cl_abap_unit_assert=>assert_equals(
act = lines( lo_dc->mt_config )
exp = 1 ).
read table lo_dc->mt_config index 1 into ls_config.
cl_abap_unit_assert=>assert_equals(
act = ls_config-mock_name
exp = 'EXAMPLE/override' ).
lo_dc->forward_method( 'TAB_RETURN' ).
cl_abap_unit_assert=>assert_equals(
act = lines( lo_dc->mt_config )
exp = 1 ).
read table lo_dc->mt_config index 1 into ls_config.
cl_abap_unit_assert=>assert_equals(
act = ls_config-as_proxy
exp = abap_true ).
endmethod.
method build_config.
data ld_if type ref to cl_abap_objectdescr.
data ls_conf type zif_mockup_loader=>ty_mock_config.
data ls_conf_act type zif_mockup_loader=>ty_mock_config.
data lo_ex type ref to zcx_mockup_loader_error.
ld_if ?= cl_abap_typedescr=>describe_by_name( 'ZIF_MOCKUP_LOADER_STUB_DUMMY' ).
try.
clear: lo_ex, ls_conf.
ls_conf-method_name = 'TAB_RETURN'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
ls_conf_act = zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
catch zcx_mockup_loader_error into lo_ex.
cl_abap_unit_assert=>fail( ).
endtry.
cl_abap_unit_assert=>assert_equals( act = ls_conf_act-output_param exp = 'R_TAB' ).
cl_abap_unit_assert=>assert_equals( act = ls_conf_act-output_pkind exp = 'R' ).
cl_abap_unit_assert=>assert_bound( act = ls_conf_act-output_type ).
try. "" method missing
clear: lo_ex, ls_conf.
ls_conf-mock_name = 'EXAMPLE/sflight'.
zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'MM'.
try. "" mock missing
clear: lo_ex, ls_conf.
ls_conf-method_name = 'TAB_RETURN'.
zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'MK'.
try. "" sift incomplete
clear: lo_ex, ls_conf.
ls_conf-method_name = 'TAB_RETURN'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
ls_conf-sift_param = 'I_CONNID'.
zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'MS'.
try. "" sift incomplete
clear: lo_ex, ls_conf.
ls_conf-method_name = 'TAB_RETURN'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
ls_conf-mock_tab_key = 'CONNID'.
zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'MS'.
try. "" sift incomplete
clear: lo_ex, ls_conf.
ls_conf-method_name = '???'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'MF'.
try. "" sift not found
clear: lo_ex, ls_conf.
ls_conf-method_name = 'TAB_RETURN'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
ls_conf-sift_param = 'X_CONNID'.
ls_conf-mock_tab_key = 'CONNID'.
zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'PF'.
try. "" sift has wrong type
clear: lo_ex, ls_conf.
ls_conf-method_name = 'WRONG_SIFT'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
ls_conf-sift_param = 'I_CONNID'.
ls_conf-mock_tab_key = 'CONNID'.
zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'PE'.
try. "" no return
clear: lo_ex, ls_conf.
ls_conf-method_name = 'TAB_EXPORT'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'MR'.
try. "" no param
clear: lo_ex, ls_conf.
ls_conf-method_name = 'TAB_RETURN'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
ls_conf-output_param = '???'.
zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'PF'.
try. "" no param
clear: lo_ex, ls_conf.
ls_conf-method_name = 'TAB_RETURN'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
ls_conf-output_param = 'I_CONNID'.
zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'PI'.
try. "" no param
clear: lo_ex, ls_conf.
ls_conf-method_name = 'WRONG_RETURN'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'PT'.
try. "" field only elementary param
clear: lo_ex, ls_conf.
ls_conf-method_name = 'TAB_RETURN'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
ls_conf-field_only = 'PRICE'.
zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'PL'.
try. "" field only + corresponding
clear: lo_ex, ls_conf.
ls_conf-method_name = 'TAB_RETURN_EXTRACT_BY_DATE'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
ls_conf-corresponding = abap_true.
ls_conf-field_only = 'PRICE'.
zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'PC'.
endmethod.
method build_config_filter_type.
data ld_if type ref to cl_abap_objectdescr.
data ls_conf type zif_mockup_loader=>ty_mock_config.
data ls_conf_act type zif_mockup_loader=>ty_mock_config.
data lx type ref to zcx_mockup_loader_error.
data ld_otype type ref to cl_abap_structdescr.
ld_if ?= cl_abap_typedescr=>describe_by_name( 'ZIF_MOCKUP_LOADER_STUB_DUMMY' ).
"" Type from param
clear ls_conf.
ls_conf-method_name = 'RETURN_VALUE_W_DATE'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
ls_conf-mock_tab_key = 'CONNID'.
ls_conf-sift_param = 'I_CONNID'.
ls_conf-field_only = 'PRICE'.
ls_conf_act = zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
ld_otype ?= ls_conf_act-output_type.
cl_abap_unit_assert=>assert_equals(
exp = 'S_CONN_ID'
act = ld_otype->get_component_type( p_name = 'CONNID' )->get_relative_name( ) ).
"" Type from const
clear ls_conf.
ls_conf-method_name = 'RETURN_VALUE_W_DATE'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
ls_conf-mock_tab_key = 'CONNID'.
ls_conf-sift_const = '123'.
ls_conf-field_only = 'PRICE'.
ls_conf_act = zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
ld_otype ?= ls_conf_act-output_type.
cl_abap_unit_assert=>assert_equals(
exp = 'STRING'
act = ld_otype->get_component_type( p_name = 'CONNID' )->get_relative_name( ) ).
endmethod.
method build_config_multi_filter_neg.
data ld_if type ref to cl_abap_objectdescr.
data ls_conf type zif_mockup_loader=>ty_mock_config.
data lx type ref to zcx_mockup_loader_error.
field-symbols like line of ls_conf-filter.
ld_if ?= cl_abap_typedescr=>describe_by_name( 'ZIF_MOCKUP_LOADER_STUB_DUMMY' ).
try. "" both filters passed
clear ls_conf.
ls_conf-method_name = 'TAB_RETURN_W_DATE'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
ls_conf-mock_tab_key = 'CONNID'.
ls_conf-sift_param = 'I_CONNID'.
append initial line to ls_conf-filter assigning .
-mock_tab_key = 'CONNID'.
-sift_param = 'I_CONNID'.
zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
cl_abap_unit_assert=>fail( ).
catch zcx_mockup_loader_error into lx.
cl_abap_unit_assert=>assert_equals( exp = 'BF' act = lx->code ).
endtry.
try. "" duplication
clear ls_conf.
ls_conf-method_name = 'TAB_RETURN_W_DATE'.
ls_conf-mock_name = 'EXAMPLE/sflight'.
append initial line to ls_conf-filter assigning .
-mock_tab_key = 'CONNID'.
-sift_param = 'I_CONNID'.
append initial line to ls_conf-filter assigning .
-mock_tab_key = 'CONNID'.
-sift_param = 'I_CONNID'.
zcl_mockup_loader_stub_factory=>build_config(
id_if_desc = ld_if
i_config = ls_conf ).
cl_abap_unit_assert=>fail( ).
catch zcx_mockup_loader_error into lx.
cl_abap_unit_assert=>assert_equals( exp = 'DF' act = lx->code ).
endtry.
endmethod.
method instantiation.
data lo type ref to zcl_mockup_loader_stub_factory.
data lo_ex type ref to zcx_mockup_loader_error.
data lo_ml type ref to zcl_mockup_loader.
try. "" wrong interface
lo_ml = zcl_mockup_loader=>create(
i_type = 'MIME'
i_path = 'ZMOCKUP_LOADER_EXAMPLE'
i_encoding = zif_mockup_loader_constants=>encoding_utf16 ).
clear: lo_ex.
create object lo
exporting
ii_ml_instance = lo_ml
i_interface_name = 'CHAR1'.
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'IF'.
try. "" wrong proxy target
clear: lo_ex.
create object lo
exporting
ii_ml_instance = lo_ml
io_proxy_target = lo_ml
i_interface_name = 'ZIF_MOCKUP_LOADER_STUB_DUMMY'.
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'II'.
endmethod.
method forward_method.
data lo type ref to zcl_mockup_loader_stub_factory.
data lo_ex type ref to zcx_mockup_loader_error.
data lo_ml type ref to zcl_mockup_loader.
try. "" no proxy during creation
clear: lo_ex.
create object lo
exporting
ii_ml_instance = lo_ml
i_interface_name = 'ZIF_MOCKUP_LOADER_STUB_DUMMY'.
lo->forward_method( 'PROXY_TEST' ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'PA'.
try. "" missing method
clear: lo_ex.
create object lo
exporting
ii_ml_instance = lo_ml
io_proxy_target = lcl_test_proxy_target=>create( )
i_interface_name = 'ZIF_MOCKUP_LOADER_STUB_DUMMY'.
lo->forward_method( 'PROXY_TEST_XXX' ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'MF'.
try. "" missing method
clear: lo_ex.
lo->forward_method( 'PROXY_TEST' ).
lo->forward_method( 'PROXY_TEST' ).
catch zcx_mockup_loader_error into lo_ex.
endtry.
assert_excode 'MC'.
endmethod.
method proxy_forwarding.
data lo type ref to zcl_mockup_loader_stub_factory.
data lo_ml type ref to zcl_mockup_loader.
data li_if type ref to zif_mockup_loader_stub_dummy.
data l_act type string.
create object lo
exporting
ii_ml_instance = lo_ml
io_proxy_target = lcl_test_proxy_target=>create( )
i_interface_name = 'ZIF_MOCKUP_LOADER_STUB_DUMMY'.
lo->forward_method( 'PROXY_TEST' ).
li_if ?= lo->generate_stub( ).
l_act = li_if->proxy_test( i_p1 = 'Hello' i_p2 = 123 ).
cl_abap_unit_assert=>assert_equals( act = l_act exp = 'Hello 123' ).
endmethod.
**********************************************************************
method get_ml.
ro_ml = zcl_mockup_loader=>create(
i_type = 'MIME'
i_path = 'ZMOCKUP_LOADER_EXAMPLE'
i_encoding = zif_mockup_loader_constants=>encoding_utf16 ).
endmethod.
method get_factory.
create object ro_factory
exporting
ii_ml_instance = io_ml "" get_ml( )
i_interface_name = 'ZIF_MOCKUP_LOADER_STUB_DUMMY'
io_proxy_target = io_proxy.
endmethod.
method get_sflights.
io_ml->load_data(
exporting
i_obj = 'EXAMPLE/sflight'
i_strict = abap_false
importing
e_container = rt_tab ).
endmethod.
method filtering.
data factory type ref to zcl_mockup_loader_stub_factory.
data stub type ref to zif_mockup_loader_stub_dummy.
data ml type ref to zcl_mockup_loader.
data lt_exp type flighttab.
data lt_act type flighttab.
ml = get_ml( ).
factory = get_factory( ml ).
lt_exp = get_sflights( ml ).
delete lt_exp where connid <> '1000'.
factory->connect_method(
i_sift_param = 'I_CONNID'
i_mock_tab_key = 'CONNID'
i_method_name = 'TAB_RETURN'
i_mock_name = 'EXAMPLE/sflight' ).
stub ?= factory->generate_stub( ).
lt_act = stub->tab_return( i_connid = '1000' ).
cl_abap_unit_assert=>assert_equals( act = lt_act exp = lt_exp ).
endmethod.
method filtering_multi.
data factory type ref to zcl_mockup_loader_stub_factory.
data stub type ref to zif_mockup_loader_stub_dummy.
data ml type ref to zcl_mockup_loader.
data lt_exp type flighttab.
data lt_act type flighttab.
data lt_filter type zif_mockup_loader=>tty_stub_filter_params.
field-symbols like line of lt_filter.
ml = get_ml( ).
factory = get_factory( ml ).
lt_exp = get_sflights( ml ).
delete lt_exp where not ( connid = '2000' and fldate = '20150102' ).
append initial line to lt_filter assigning .
-mock_tab_key = 'CONNID'.
-sift_param = 'I_CONNID'.
append initial line to lt_filter assigning .
-mock_tab_key = 'FLDATE'.
-sift_param = 'I_FLDATE'.
factory->connect_method(
i_filter = lt_filter
i_method_name = 'TAB_RETURN_W_DATE'
i_mock_name = 'EXAMPLE/sflight' ).
stub ?= factory->generate_stub( ).
lt_act = stub->tab_return_w_date(
i_connid = '2000'
i_fldate = '20150102' ).
cl_abap_unit_assert=>assert_equals(
act = lt_act
exp = lt_exp ).
lt_act = stub->tab_return_w_date(
i_connid = '2000'
i_fldate = '20150130' ).
cl_abap_unit_assert=>assert_initial( lt_act ).
endmethod.
method filtering_multi_and_const.
data factory type ref to zcl_mockup_loader_stub_factory.
data stub type ref to zif_mockup_loader_stub_dummy.
data ml type ref to zcl_mockup_loader.
data lt_exp type flighttab.
data lt_act type flighttab.
data lt_filter type zif_mockup_loader=>tty_stub_filter_params.
field-symbols like line of lt_filter.
ml = get_ml( ).
factory = get_factory( ml ).
lt_exp = get_sflights( ml ).
delete lt_exp where not ( connid = '2000' and fldate = '20150102' ).
append initial line to lt_filter assigning .
-mock_tab_key = 'CONNID'.
-sift_param = 'I_CONNID'.
append initial line to lt_filter assigning .