JMenuItem at pluginWorkspaceAccess.addMenuBarCustomizer

Post here questions and problems related to oXygen frameworks/document types.
vishwavaranasi
Posts: 144
Joined: Fri Feb 28, 2020 4:02 pm

JMenuItem at pluginWorkspaceAccess.addMenuBarCustomizer

Post by vishwavaranasi »

Hello Team ,

I have a menu item defined as

Code: Select all

JMenuItem Item1= new JMenuItem("Item1 Selection");

and  Action as

final Action selectionSourceAction = createShowSelectionAction(pluginWorkspaceAccess);

Item1 .setAction(createShowSelectionAction);
    
private AbstractAction createShowSelectionAction(
			final StandalonePluginWorkspace pluginWorkspaceAccess) {
return new AbstractAction("") {
}
}
since my menu item has already defined the label new JMenuItem("Item1 Selection");
I have not specified anything just empty string here
return new AbstractAction("")
but the menu is not showing label "Item1 Selection" when i run the plugin? it showing empty as below
image.png
image.png (4.01 KiB) Viewed 1596 times
Thanks,
vishwa
Radu
Posts: 9055
Joined: Fri Jul 09, 2004 5:18 pm

Re: JMenuItem at pluginWorkspaceAccess.addMenuBarCustomizer

Post by Radu »

Hi,
This is how the Java Swing libraries work, once you create an action and set it on a menu item, the action controls everything (menu text, code which gets performed when menu is clicked).
So this is not related with Oxygen's API, you can try to create a small java Swing application unrelated with Oxygen and see how it behaves.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
vishwavaranasi
Posts: 144
Joined: Fri Feb 28, 2020 4:02 pm

Re: JMenuItem at pluginWorkspaceAccess.addMenuBarCustomizer

Post by vishwavaranasi »

Thanks Radu , we have requirement as below
image.png
image.png (10.99 KiB) Viewed 1564 times
at the plugin start - > Menu Item 1 should be disabled.

and when i open a Menu Item 2 - this will open some JFRAME , once this JFRAME opened the Menu Item1 should be enabled.

and when I close the JFRAME , and go back to my custom Menu , then the Menu Item 1 should be disabled again.

How can we implement this?
I was having a instance variable inside my WorkspaceAccessPluginExtension java class ,and inside applicationStarted() method when i call the action for MenuItem2 to open Jframe am setting the value for the flag.

but next time when close that JFRAME and opening the menu , the Menu Item 1 still showing as enabled.

would you please give us some idea here?
Thanks,
vishwa
Radu
Posts: 9055
Joined: Fri Jul 09, 2004 5:18 pm

Re: JMenuItem at pluginWorkspaceAccess.addMenuBarCustomizer

Post by Radu »

Hi,
Once you create a menu item over an AbstractAction, you control the enabled state of the menu item by setting AbstractAction.setEnabled(...) directly on the action, the action controls the menu item's appearance.
I do not understand your entire setup, if you create a small Oxygen plugin exhibiting the problem without any of your custom code I could try to advice further.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
vishwavaranasi
Posts: 144
Joined: Fri Feb 28, 2020 4:02 pm

Re: JMenuItem at pluginWorkspaceAccess.addMenuBarCustomizer

Post by vishwavaranasi »

Hi Radu , here am attaching the sample plugin project with my requirements.
1 . First time MenuItem1Action is disabled.
2.  user click on MenuItem2Action - this will open a Jframe.
3.  Now users can access MenuItem1Action.
4. Now the user closes the Jframe opened at step 2.
5. Now the expected behavior is , the MenuItem1Action should be disabled.
Would you please help me here how to achieve the same here.
sample-plugin-workspace-access.zip
(136.52 KiB) Downloaded 168 times
Thanks,
vishwa
vishwavaranasi
Posts: 144
Joined: Fri Feb 28, 2020 4:02 pm

Re: JMenuItem at pluginWorkspaceAccess.addMenuBarCustomizer

Post by vishwavaranasi »

Hello Team , would you please help us when you get a chance.

Thanks,
vishwa
Thanks,
vishwa
Radu
Posts: 9055
Joined: Fri Jul 09, 2004 5:18 pm

Re: JMenuItem at pluginWorkspaceAccess.addMenuBarCustomizer

Post by Radu »

Hi,

How about if you do this in the createMenuItem2Action function?

Code: Select all

	private AbstractAction createMenuItem2Action(StandalonePluginWorkspace pluginWorkspaceAccess) {
		return new AbstractAction("MenuItem2Action") {
			@Override
			public void actionPerformed(ActionEvent e) {
			  JFrame toShow = new MenuItem2ActionManager();
			  toShow.addWindowListener(new WindowAdapter() {
			    @Override
			    public void windowClosed(WindowEvent e) {
			      MenuItem1Action.setEnabled(false);
			    }
			  });
			  toShow.setVisible(true);
			}
		};
	}
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
vishwavaranasi
Posts: 144
Joined: Fri Feb 28, 2020 4:02 pm

Re: JMenuItem at pluginWorkspaceAccess.addMenuBarCustomizer

Post by vishwavaranasi »

Thanks Radu , its worked for me.

we have another requirement where ,
We want MenuItem1Action.setEnabled(false); when the local file opened inside the oxygen main editor are read-only files
and MenuItem1Action.setEnabled(true); when the local file opened inside the oxygen main editor are writable.

This we are expecting as soon as oxygen loads the plugin and also as and when user closes and open files in the editor.

and also if i have 4 opened files ,
first file is read-only then MenuItem1Action.setEnabled(false);
if I TAB to second file - writable then MenuItem1Action.setEnabled(true);

and so on..

please help me here.
Thanks,
vishwa
Radu
Posts: 9055
Joined: Fri Jul 09, 2004 5:18 pm

Re: JMenuItem at pluginWorkspaceAccess.addMenuBarCustomizer

Post by Radu »

Hi,
Using our APis you can add a listener to notify you when a document is selected in the editor area:

Code: Select all

public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
      pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener() {
        /**
         * @see ro.sync.exml.workspace.api.listeners.WSEditorChangeListener#editorSelected(java.net.URL)
         */
        @Override
        public void editorSelected(URL editorLocation) {
          if(editorLocation != null && isReadonly(editorLocation)){
            MenuItem1Action.setEnabled(false);
          }
        }
      }, PluginWorkspace.MAIN_EDITING_AREA);
https://www.oxygenxml.com/InstData/Edit ... a.net.URL-
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply