Howto enable disable menubar items in actionscript

Hello,
My problem is that i want to enable/disable buttons in a
menubar according to the loaded page.
So what i did was when the user clicks on the menubar, it
triggers a function. Inside that function there will become a check
on which page is at front. According to that page i am gonna set
menuitems on and off.
Thats the idea i had, so now my problem.
I first try to create a simple solution like my code beneath.

I'd suggest changing things around a bit. See if the
following works for you. The clickHandler() method has the syntax
you're looking for.
TS

Similar Messages

  • Enable/disable an item in a multirecord block

    hello to all
    How is possible Enable/disable an item in a multirecord block?
    set_item_property change all instances of an item in a multi-record block
    SET_ITEM_INSTANCE_PROPERTY only affects the display
    thanks

    Hi,
    You cannot set the Enabled property in a multi-record block, instead you can change the INSERT_ALLOWED, UPDATE_ALLOWED properties. So that the user can't change the value in the item.
    Regards,
    Manu.
    If my response or the response of another was helpful, please mark it accordingly

  • Using XMLLIST - Enable/Disable Menu Items

    I am using XMLList for creating menu items.
    I want to enable / disable menu items based on the permissions to the user.
    Below is the code snippet:
    <fx:XMLList  id="newData">
                                  <menuitem id="item1" label="{resourceManager.getString('taskmgmt', 'taskmgmt.label.newProject')}" />
                                  <menuitem id="item2" label="{resourceManager.getString('taskmgmt', 'taskmgmt.label.projectFromTemplate')}" enabled="false"/>
                        </fx:XMLList>
    private function ItemClickHandler(event:MenuEvent):void
         if(PermissionManager.isAddPermitted("WTM_PROJECT_PLANNING")){
                                                           ProjectAssignmentModel.projectAssignmentFlag=false;
                                                           if(event.item.@label == resourceManager.getString('taskmgmt', 'taskmgmt.label.newProject')){
                                                                     clearModel();
                                                                     dispatchEvent(new SwitchViewEvent(SwitchViewEvent.SWITCH_VIEW_EVENT,false));
    protected function newMenuButton_clickHandler(event:MouseEvent):void
                                            if(! PermissionManager.isAddPermitted("WTM_PROJECT_PLANNING")){
                                                      newData.item1.enabled = false;
                                            else
                                                      menuList.dataProvider = newData;
                                                      menuList.show(event.stageX + 5 , event.stageY + 5);
                                                      mode = CREATE;
    Based on the permission, I want to dynamically enable / disable the "New Project" button.
    Can someone provide information how to achieve this ?
    Further update on this, it is giving the following error while running of the application:
    "TypeError: Error #1089: assignment to list with more than one item is not supported"

    Resolved by using the correct Data Provider and iterating through the list

  • Enable disable toolbar items on click on any checkbox,radio button,text box.

    Hi Friends,
    I am create application in eclipse RCP E4 and now i am trying to Enable disable toolbar items on click on any checkbox, radio button, text box .
    Please Help me friends....

    Hello friend my proble is solve and now i am sharing my solution ....
    I am create RCP application and view side any listener click event fire time apply this code
    IEvaluationService evaludationService = (IEvaluationService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(IEvaluationService.class);
    evaludationService.getCurrentState().addVariable("noOfRowsChecked", noOfRowsChecked);
    evaludationService.requestEvaluation("com.jobsleaf.propertytester.canDeleteItem");
    and add plug in extension and create property tester class means listener property tester class side apply this code
    IEvaluationService ws = (IEvaluationService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(IEvaluationService.class);
    Integer integer = (Integer) ws.getCurrentState().getVariable("noOfRowsChecked");
    if (integer != null)
    if (integer.intValue() > 0)
    return true;
    I hope useful above code when use property tester in eclipse RCP

  • Enable/disable textbox depending on list option, list is dependent on Radio

    Hi,
    I'm trying to enable/disable text_box which is dependent on select_list option, select_list is dependent on radio_button.
    I'm able to enable/disable select_list using radio_button options, but I'm unable to handle text box which is again dependent on this SELECT_LIST item.
    under html header page:-
    <script type="text/javascript">
    function disableOnValue(o)
    if (o.value == 'Y')
    document.getElementById('P86_Select_list_item').disabled = false;
    else
    document.getElementById('P86_Select_list_item').disabled = true;
    document.getElementById('P86_text_box_item').disabled = true;
    </script>
    <script type="text/javascript">
    $(document).ready(function()
    $('#P86_Select_list_item').change(function()
    if($(this).val() == 'Other')
    $('#P86_text_box_item').attr("disabled", false);
    else
    $('#P86_text_box_item').attr("disabled", true);
    </script>
    under Region_Source of the region, whose Display point :- <b>Before Footer</b>
    <script type="text/javascript">
    if(document.getElementById('P86_radio_button_0').checked == true)
    {disableOnValue(document.getElementById('P86_radio_button_0'));}
    else
    {disableOnValue(document.getElementById('P86_radio_button_1'));}
    </script>
    and under Radio_button item, HTML Form Element Attributes :- <b>onchange="javascript:disableOnValue(this);"</b>
    also same way under text_box item , HTML Form Element Attributes :- <b>disabled</b>
    any help
    Deep

    Thanks for replying Ben,
    I have kept an example into apex workspace
    workspace:- DEEPAPEX
    username:- [email protected]
    password:- walubu
    application "Javascript" page 1
    I'm able to enable/disable Select_list item & Text_box item with the help of Radio_button item(depending on user select yes or no option of the radio button)
    But after selecting Yes option of the radio_button, only when user select "Other" option of the Select_List item the Text_box should be enabled otherwise it should be disabled for any of the options of the Select_list item.
    I hope you understand my point.
    Deep

  • Is there a way to enable/disable a tabular form item based on the value of a second item?

    Hi Everyone,
    I have a tabular form based on a collection.   The column c050(maps to f30) will be either Y/N.  If it is Y, then I would like to enable column c024( maps to f24) (which happens to be a radio button based on lov).  If the value of c050 = N, then disable c024.   There are potentially many rows, and the item c024 would only be enable/disabled for the specific row.   So if row 1 has c050=Y and row 2 has C050=N then row 1 c024 is enabled, and row 2 c024 is disabled.  Hope that makes sense.
    I have created a dynamic action called enable/disable HMS fields.
    event=CHANGE
    selection type = jquery selector
    jquery selector = input[name='f30']
    condition EQUAL TO
    value Y
    true action1 - enable, jquery selector, input[name='f24']
    true action 2 - alert, You have added an HMS Species.   There may be additional data to enter.  thanks
    false action1 - disable jquery selector, input[name='f24']
    false action2 - alert, no hms worries.
    The alerts in both cases show properly...but nothing seems to happen to f24.....what am I doing wrong?
    thanks

    Agh! This is the first time you mention this is a radio button!  That changes things a lot! As you can see, the format is different (f24_0001_0001) than what we have discussed (f24_0001).
    Radio buttons have their own quirks.  My bad, I should have asked what you had.  But since you said your original selectors on input were working I just thought these were text fields or something like that.
    How about you change it to a drop down list just so that you can see all work?  And fully understand it.
    Then you can work out the radio button option.
    If that doesn't get you there... I'm going to ask you setup an example in apex.oracle.com and give me credentials to log in and take a look.
    I could re-try the js on my side with a radio but it will take some time.
    So just to be clear... f30 is a drop down and f24 is a radio?
    See, this line:
    $x_disableItem("f24_" + row, true);
    Is NEVER going to find the radio buttons because it's missing the 3rd 0001 and 0002 (how many options do you have?)
    So perhaps you try it like this:
    $x_disableItem("f24_" + row + '_0001', true);
    $x_disableItem("f24_" + row + '_0002', true);
    ... keep going for the options...
    Do the same for the false of course.
    But I think this needs a better approach if you'll have radio buttons.  I just need to work it out.
    Ok, go try things...
    Thanks
    -Jorge

  • Cannot enable the text item after disable it in Forms 6i

    Hi All,
    I want to enable/disable the text items depending on the value of the radio group. Since the text items and the radio group are on different tab page, so I place the following code on the WHEN-TAB-PAGE-CHANGED trigger, to do this:
    if :recordgroup ='P' then
    set_item_property(item1, ENABLED,PROPERTY_TRUE);
    set_item_property(item1, NAVIGABLE,PROPERTY_TRUE);
    elsif :recordgroup ='K' then
    set_item_property(item1, ENABLED,PROPERTY_FALSE);
    set_item_property(item1, NAVIGABLE,PROPERTY_FALSE);
    end if;
    When recordgroup is 'K', item1 is disabled, then when recordgroup has changed to 'P', item1 is still disabled.
    Both recordgroup and items are database items.
    How come like this?
    Thanks is advance,
    Vanessa

    Hi Vanessa, you must use a "when-radio-changed" trigger, and you need to know what properties of a item are afected when you change any one of this, for your problem ...
    if :recordgroup ='P' then
    set_item_property(item1, ENABLED,PROPERTY_TRUE);
    set_item_property(item1, NAVIGABLE,PROPERTY_TRUE);
    -- Add this line:
    Set_Item_property(item1, Update_Allowed, Property_True);
    elsif :recordgroup ='K' then
    set_item_property(item1, ENABLED,PROPERTY_FALSE);
    -- If you want, you can delete this line:
    set_item_property(item1, NAVIGABLE,PROPERTY_FALSE);
    end if;
    try it!
    Ruben.

  • Enable/Disable Column in a Advanced Bean Table

    Hi,
    I have 2 columns that needs to be enabled/disabled on a standard oa page PO Lines summary page.
    I went through couple of blogs/forums and found 2 approaches :-
    Approach 1
    1) Extended the standard VO POLinesMerge.
    2) Added a attribute column DeriveDisplayFlag of type VARCHAR2 . This call a database function and will return Y or N
    3) Added a attribute of type ShowAdditionalColumn boolean. the get method of this attribute returns TRUE if DeriveDisplayFlag is 'Y' otherwise returns FALSE.
    4) created a substitution for the custom VO
    5) uploaded the substitution to mds.
    6) copied the xml/class files to $JAVA_TOP/..
    7) Bounced entire middle tier
    8) using personalization, entered a SPEL command on the rendered property. I know rendered will hide/show the column but for time being I just want this to work.
    But this fails :-
    oracle.apps.fnd.framework.OAException: Message not found. Application: FND, Message Name: FND_VIEWOBJECT_NOT_FOUND. Tokens: VONAME = XXPBPoLinesMergeVO; APPLICATION_MODULE = oracle.apps.po.document.server.DocumentAM;
    I am not aware how to get around this. Can someone help please?
    Approach 2
    1) steps 1 to 6 from Approach 1.
    2) trying to extend controller class OrderLinesTableRNCO. But have couple of questions. This iis a advanced bean table so how should i reference individual record and the column that i need to disable/enable ?
    Conceptual questions
    Also, when i am entering a new record at what point in time the 2 new attribute will derive its value? the 2 attributes are dependent on the Item number column but i have not created a dependency between the attributes and Item# column.
    Will the controller logic fire for every column while i am entering a new record?
    Thanks.

    Hi Anil,
    Thanks for the response. I have given up that i will get reply on this post.
    I have done the substitution and upload the jpx to umsing importer.
    But you are correct may be i might have done something wrong. Can you please help me. I can send you the files if you can review and let me know it will be great.
    Also, will this approach work since PO Lines is a advanced bean table ?
    One of the experts suggested to use Bound values. I am not sure how to implement it though?
    I have went and told back to my business team that I am not able to do this so now they have asked me to enable/disable columns based on a dff value on po header. I thought this will be easier by extending the controller class on PO Lines table but that too is not working.
    Can you help me please ?
    Here is my code to extend the controller class :-
    package xxpb.oracle.apps.po.webui;
    import oracle.apps.fnd.common.VersionInfo;
    import oracle.apps.fnd.framework.webui.OAControllerImpl;
    import oracle.apps.fnd.framework.webui.OAPageContext;
    import oracle.apps.fnd.framework.webui.beans.OAWebBean;
    import oracle.apps.fnd.framework.webui.beans.message.OAMessageLovInputBean;
    import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;
    import oracle.apps.fnd.framework.webui.beans.table.OAAdvancedTableBean;
    import oracle.apps.fnd.framework.webui.beans.table.OAColumnBean;
    import oracle.apps.fnd.framework.webui.beans.table.OASortableHeaderBean;
    import oracle.apps.fnd.framework.webui.beans.table.OATableBean;
    import oracle.apps.po.document.order.webui.OrderLinesTableRNCO;
    public class XXPBOrderLinesTableRNCO extends OrderLinesTableRNCO
    public void processRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processRequest(pageContext, webBean);
    OAAdvancedTableBean tableBean =
    (OAAdvancedTableBean)webBean.findIndexedChildRecursive("LinesTableRN");
    OAMessageLovInputBean poLineLov =
    (OAMessageLovInputBean)tableBean.findIndexedChildRecursive("XXPBSecondaryUOMLOV");
    poLineLov.setDisabled(false);
    }

  • Need help with OA Framework. Enable/Disable LOV dynamically

    Hello,
    I am new to OA Framework. My requirement is as follows;
    The page should have a field with parameter org code (LOV). When the user selects an org and click GO button, the page should display all the inactive items (which have no Sales order or work order for last 2 years). In the table region, user selects single record or multiple records by a check box. The selected records should be processed after clicking a submit button in the table region. The process is, calling an API to change the status of the item to Inactive or some other status. The status should be determined by the user by selecting a LOV within the table region. I could create LOV based field for org code and could display the data on the page. I have been trying to display the LOV for item status , I have created a LOV under table region under table components > table actions. I could open the LOV and select a value, but the value is not defaulting to the field on the page. Somebody please help me with a suggestion or if you have the code for a similar kind of requirement please share with me.
    Also, need some suggestion on how to enable and disable LOV dynamically. I want to display the 2 LOV's in different regions. I want to enable the LOV for Item Status only after the org code is selected and the page populated after the user clicks GO button.
    Thanks in Advance…..

    Hi,
    I could open the LOV and select a value, but the value is not defaulting to the field on the page.pls check the LOV mapping ,this might be wrong.
    to enable/Disable LOV dynamically ,u need to use PPR,please check the lab solution exercise create employee chapter to learn to implement PPR functionality.
    Thanks
    Pratap

  • Does anyone know how to enable/disable a dropdown menu in Forms at runtime?

    Is there a way how to disable/enable dropdown menu for menus that have multiple sub levels in Oracle Forms? I am trying to use the set_menu_item_property function but this takes 'menu.item' format for the first argument. I am trying to enable/disable a menu item in the form of 'menu.item.subitem' and was not able to do it using this function. If anyone knows a different function or method, please reply. I have shown an example below.
    Setup -> Software -> Front Page
    From the above example, I can enable/disable Software using set_menu_item_property function. But, how do I enable/disable the Front Page menu in Oracle forms at runtime?
    Thanks
    Edited by: user480347 on Aug 24, 2010 3:37 PM

    Yes you are on the right track. You need to pass then complete menu name to set_menu_item_property
    Immediate_parent menu.item_name e.g
    For example you have menu like this
    Id like
    A1    A10 > A1010
    Home > Input > Form 1
    A1    A10 > A1020
    Home > Input > Form 2 To disable Form 2 you must pass menu name as
    A10.A1020Hope it helps

  • Enable/disable lov button in a multi-row bloc

    Hi all,
    I have a form in which there is a multi-row block with some lov buttons related to some items,
    in query mode, user should not be able to modify item, item property update_allowed is set to false, that worked, but user is able to modify item when he clicks on the lov button...so i want to disable the button for query records and for record in (insert or new), button should be enable,
    i tried some tips but don't work, do you have any idea
    Thanks for your help.

    Hi,
    Can you suggest some methods to enable/disable LOVs in my search query? I have a customized VC which performs search and I need to enable/disable the LOVs depending on requirement.
    Abhishek

  • Enable disable linkbar links in datagrid itemrenderer.

    Hi All,
    I have to show the linkbar in datagrid column as a renderer and enable and disable the links according to attached documents codes.
    here are my sample code
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            [Bindable]
              public var arrColl:ArrayCollection = new ArrayCollection();
              public function init():void{
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
        ]]>
    </mx:Script>
        <mx:DataGrid id="dg" dataProvider="{arrColl}" width="200" height="500" x="510" y="168" >
            <mx:columns>
                <mx:DataGridColumn  itemRenderer="assets.components.linkbarItemRenderer"  />   
            </mx:columns>
        </mx:DataGrid>
    </mx:Application>
    My item renderer linkbarItemRenderer.mxml as
    <?xml version="1.0" encoding="utf-8"?>
    <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" creationComplete="init();" >
    <mx:Script>
        <![CDATA[
            import mx.controls.LinkButton;
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            [Bindable] public var arrColl : ArrayCollection = new ArrayCollection();
            public var arrDocType : ArrayCollection = new ArrayCollection([{data:"1" , label:"AP"},{data:"2" , label:"AR"},{data:"3" , label:"BOL"}]);
            public var attDoccodes : Array;
            public function init():void
                try
                    var requiredDoc :String = data[0];
                    var attachDoc : String = data[1];
                    var reqDocCodes :Array =  requiredDoc.split(",");
                    attDoccodes = attachDoc.split(",");
                    if(reqDocCodes != null)
                        //add the links of required documents.
                        for(var i:int = 0 ; i<reqDocCodes.length; i++ )
                            var obj:Object = new Object();
                            for(var j : int = 0; j < arrDocType.length; j++)
                                if(arrDocType.getItemAt(j).data == reqDocCodes[i])
                                    obj.label = arrDocType.getItemAt(j).label;
                                    obj.data  = reqDocCodes[i];
                            arrColl.addItem(obj);
                    callLater(enableDisalbeLinks);
                catch(error:Error)
                    Alert.show("error ::"+error.getStackTrace());
            public function enableDisalbeLinks():void
                try
                    //disable all links first
                    for(var q:int=0; q< arrColl.length; q++)
                        LinkButton(linkBarId.getChildAt(q)).enabled = false;   
                    if(attDoccodes != null)
                        for(var k:int = 0; k<attDoccodes.length; k++)
                            for(var l:int = 0 ; l<arrColl.length; l++)
                                if(arrColl.getItemAt(l).data == attDoccodes[k])
                                    LinkButton(linkBarId.getChildAt(l)).enabled = true;   
                catch(error:Error)
                    Alert.show("error ::"+error.getStackTrace());
        ]]>
    </mx:Script>
            <mx:LinkBar id="linkBarId" dataProvider="{arrColl}" />   
    </mx:HBox>
    It renderes the link in correct form in datagrid first time.when i scroll the datagrid the rows are miss up with each other and links are not shown propers in enable/disable format.
    Thanks,
    Amol.

    Hi All,
    It was my fault. Got it work now.
    When I redirect to PR, it also calls my page initialization method and clear all data. I added a parameter and issue resolved.
    Thanks & Regards,
    KJ

  • Disableing an item in enter query mode

    Hello experts,
    i want that a perticular item will be disabled after you press enter button of query menu.(or query->enter).Can any body please tell me what is the actual trigger in which i write the disable statement.
    set_item_property('itemname', enabled, property_false);
    Regards
    Anutosh

    You can't set the enabled property if the cursor is in the item and I expect it's the same for the query_allowed property. if the cursor is in the item which you set to Query_Allowed=false and then you go to enter-query mode, perhaps forms doesn't know what item to move the cursor to, so just leaves it where it is.
    You can solve the problem by moving to a different item (with go_item) before setting the property.
    When do you need to set the item back to enabled? If you want it enabled at all times other than when a query is being entered then use the Property Pallet to set the Query Allowed property. If you want to disable the field under certain conditions then the when-new-record-instance trigger might be better for you. Eg
    if :system.mode = 'ENTER-QUERY' and <condition> then
      go_item(<another item>);
      set_item_property(<item>, enabled, property_false);
    else
      set_item_property(<item>, enabled, property_true);
      set_item_property(<item>, update_allowed, property_true);
      set_item_property(<item>, navigable, property_true);
      set_item_property(<item>, update_null, property_true);
    end if;It might be better to set the query_allowed property instead of the enabled property, but I can't check right now whether that's possible after the enter-query mode has begun.
    The update_allowed, update_null and navigable properties are all set to false as a consequence of the enabled property being set to false. If they should be true then you need to reset them after reenabling the item.

  • Adobe interactive form : Disabled menu item

    Hi experts,
    we recenlty satred working in Adobe iteractive form in SAP. and we are facing folllowing issues
    1)submenu item is disable (submenu item from "Layout" and "Table" is not enable)
    any solution?

    Hi Sandy,
    Thanks for Replying
    yes i am in display mode but same thing happens when i am in edit mode..
    sorry i can not go in edit mode right now as another developer is working on it.
    SAP Net weaver version - 7.31 with EHP 6.0
    ALD version :  ES2 9.0
    See below Screenshot from other adobe form
    Message was edited by: Zubin ..

  • Enabling/Disabling menuitems in a JMenu

    Hi,
    The application I'm developing has a JMenu, like any other Swing app
    out there. The menuitems in that JMenu are enabled/disabled according
    to the state of the app. I'd like to know which is the best way to
    enable or disable the individual JMenuItems from any point in the
    app, do I have to hold a global pointer to every JMenuItem in the
    app and call setEnable() ? Or can I send a change event which
    is captured by a hypothetical enablelistener registered in
    every menu item ?
    thanks in advance

    Okay, here's a skeleton of working with actions and a Document/Listener pattern.
    Here are the core classes:
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    public interface DocModel {
        public class Event extends EventObject {
            public enum Type {DOC_OPENED, DOC_CLOSED};
            public Event(DocModel model, Type type) {
                super(model);
                this.type = type;
            public final Type getType() {
                return type;
            private final Type type;
        public interface Listener extends EventListener {
            public void docOpened(Event event);
            public void docClosed(Event event);
        public void addDocListener(Listener l);
        public void removeDocListener(Listener l);
        public void open(File file) throws IOException;
        public void play();
        public void close();
        public JComponent createView();
    }You don't have to nest types, but I like to.
    Here is an abstract class the lets EventListenerList do all the work (I copyied and pasted the code from the API.)
    import java.io.*;
    import javax.swing.event.*;
    public abstract class AbstractDocModel implements DocModel {
        private EventListenerList listenerList = new EventListenerList();
        protected void fireDocOpened() {
            Object[] listeners = listenerList.getListenerList();
            Event evt = new Event(this, Event.Type.DOC_OPENED);
            for (int i = listeners.length-2; i>=0; i-=2) {
                if (listeners==Listener.class)
    ((Listener)listeners[i+1]).docOpened(evt);
    protected void fireDocClosed() {
    Object[] listeners = listenerList.getListenerList();
    Event evt = new Event(this, Event.Type.DOC_CLOSED);
    for (int i = listeners.length-2; i>=0; i-=2) {
    if (listeners[i]==Listener.class)
    ((Listener)listeners[i+1]).docClosed(evt);
    public void addDocListener(Listener l) {
    listenerList.add(Listener.class, l);
    public void removeDocListener(Listener l) {
    listenerList.remove(Listener.class, l);
    public void open(File file) throws IOException {
    fireDocOpened();
    public void close() {
    fireDocClosed();
    Here is a simple implementation with Actions. I didn't have to make the actions DocListeners as well --
    that's overkill, I could have adjusted their enabled state in open/play/close, but I wanted to demonstrate
    letting listeners keep themselves in synch.
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class SimpleDocModel extends AbstractDocModel {
        private Document document = new PlainDocument();
        private class OpenAction extends AbstractAction implements DocModel.Listener {
            public OpenAction() {
                super("open");
            public void actionPerformed(ActionEvent evt) {
                try {//find file
                    File file = new File("bogus");
                    open(file);
                } catch (IOException e) {
                    //report it...
            public void docOpened(Event event) {
                setEnabled(false);
            public void docClosed(Event event) {
                setEnabled(true);
        private OpenAction openAction = new OpenAction();
        private class PlayAction extends AbstractAction implements DocModel.Listener {
            public PlayAction()
            {   super("play");
                setEnabled(false);
            public void actionPerformed(ActionEvent evt) {
                play();
            public void docOpened(Event event) {
                setEnabled(true);
            public void docClosed(Event event) {
                setEnabled(false);
        private PlayAction playAction = new PlayAction();
        private class CloseAction extends AbstractAction implements DocModel.Listener {
            public CloseAction()
            {   super("close");
                setEnabled(false);
            public void actionPerformed(ActionEvent evt) {
                close();
            public void docOpened(Event event) {
                setEnabled(true);
            public void docClosed(Event event) {
                setEnabled(false);
        private CloseAction closeAction = new CloseAction();
        public SimpleDocModel() {
            setMessage("empty doc");
            addDocListener(openAction);
            addDocListener(playAction);
            addDocListener(closeAction);
        public void addToToolBar(JToolBar tb) {
            tb.add(openAction);
            tb.add(closeAction);
            tb.add(playAction);
        public void open(File file) throws IOException {
            setMessage("file opened");
            super.open(file);
        public void close() {
            setMessage("closed");
            super.close();
        public void play() {
            setMessage("playing continuously");
        public JComponent createView() {
            JTextField view = new JTextField();
            view.setDocument(document);
            view.setEditable(false);
            return view;
        private void setMessage(String message) {
            try {
                document.remove(0, document.getLength());
                document.insertString(0, message, null);
            } catch (BadLocationException e) {
                e.printStackTrace();
    }Are you still with me? Run this code:
    import java.awt.*;
    import javax.swing.*;
    public class SampleApp {
        JFrame frame = new JFrame("Sample App");
        SimpleDocModel model = new SimpleDocModel();
        public SampleApp () {
            JToolBar tb = new JToolBar();
            model.addToToolBar(tb);
            Container cp = frame.getContentPane();
            cp.add(tb, BorderLayout.NORTH);
            cp.add(model.createView(), BorderLayout.SOUTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args) {
            new SampleApp();

Maybe you are looking for

  • PO Line Item Change

    Hi, I have a question regarding the sequence in the PO, when adding a new item from a Purchase requisition. we have in an existing PO, added a new item from a requisition (created from a BOM), but we want to change the item-sequence in the PO from th

  • How to use error table in mapping level?

    Hi all Any one please tell me how to use error table in mapping level or how to handle the errors in mapping. I am creating one error table in oracle but i dont know how to use it in mapping. Thanks in advance. Kumar

  • Toshiba 39L4333DG CloudTV: I don't understand! Guide needed

    Hello, I just set up my new TV, I think it's great (apart from being too slow), but I don't understand how to use the CloudTV. My TV came with NO manuals: it only included a quick setup guide and a brief Cloud TV description. I've been able to downlo

  • Height parameter is 'grayed out' in interface builder?

    hello, i would like to alter the height of my newly created view in my .xib file, and although the view is selected the height parameter is 'grayed out' in interface builder?, any one know why ?

  • Error 1009 code cant see my buttons

    TypeError: Error #1009: Cannot access a property or method of a null object reference.           at ife3m_fla::MainTimeline/frame41()[ife3m_fla.MainTimeline::frame41:9] Code of frame 41 line 9 boton2_btn.addEventListener(MouseEvent.MOUSE_DOWN, playSp