Dependent JMenuItem at addMenuBarCustomizer

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

Dependent JMenuItem at addMenuBarCustomizer

Post by vishwavaranasi »

Hello Team , here am attaching the sample plugin project with my requirements.
1 . First time MenuItem1Action enabled and MenuItem2Action is disabled.
2. user click on MenuItem1Action - This will open a Jframe with a Jtable and Menu2tem1Action enabled.
3. Now users can access Menu2tem1Action - this will open a jframe with 2 text fields.
4. here the requirement is , in the step3 of Jframe I want to access if any table row selected from the Jframe opened in step 2.

Would you please help me here how to achieve the same here.
sample-plugin-workspace-access.zip
(154.49 KiB) Downloaded 36 times
Thanks,
vishwa
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Dependent JMenuItem at addMenuBarCustomizer

Post by Radu »

Hi,

You do not seem to have much experience writing Java code, unfortunately I do not have time to review your entire Java code, my purpose here is just to help you with advice using our Oxygen specific APIs, not to help you with building custom Swing components.
Just a couple of observations, code like this:

Code: Select all

			                JFrame f = new JFrame("Test123");
			                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

			                TableExample tableData = new TableExample();
			                f.setContentPane(tableData.getGUI());
The TableExample is also a JFrame, you could just configure and show it directly. Because right now the method "com.oxygenxml.sdksamples.workspace.TableExample.getGUI()" returns the JFrame and then you place the JFrame in another JFrame.
This code:

Code: Select all

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
instructs the operating system to force close the entire Java application when the end user closes the frame. So once the end user closes this custom frame of yours the entire Oxygen application will be force closed.
Are you sure you want to use JFrame and not some modal dialogs (JDialog) which block the application until the end user chooses content in them?

I would suggest also removing this code:

Code: Select all

try {
			                    // Significantly improves the look of the output in
			                    // terms of the file names returned by FileSystemView!
			                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			                } catch(Exception weTried) {
			                }
Your code runs in Oxygen, it is not a standalone Swing application. Oxygen sets up its own color theme, look and feel.

Coming back to your original request:
here the requirement is , in the step3 of Jframe I want to access if any table row selected from the Jframe opened in step 2.
A way to do this would be to keep the "tableData" as a field, once it's a field you can access it also from the other "MenuItem2Action".

Code: Select all

  private TableExample tableData;

	@SuppressWarnings("serial")
	private AbstractAction createMenuItem1Action(StandalonePluginWorkspace pluginWorkspaceAccess) {
		
		return new AbstractAction("MenuItem1Action") {
			@Override
			public void actionPerformed(ActionEvent e) {
				
				 SwingUtilities.invokeLater(new Runnable() {
			            public void run() {
			                try {
			                    // Significantly improves the look of the output in
			                    // terms of the file names returned by FileSystemView!
			                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			                } catch(Exception weTried) {
			                }
			                JFrame f = new JFrame("Test123");
			                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

			                tableData = new TableExample();
			                f.setContentPane(tableData.getGUI());
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply