I am trying to write what I think is a very simple Eclipse plugin, but I am really struggling to find my way around as I have never worked with the PDE before.
Basically what I am trying to do is add a sub-menu to the Java Project context menu that will list a bunch of available files in the project's root directory. Then upon selecting one of these sub-menu items I want the handler to be called and passed the name of the file that was selected.
So far I have managed to get the menu to appear correctly by adding a dynamic menuContribution to the org.eclipse.ui.menus extension point. I have defined my own CompoundContributionItem which finds all of the files in the appropriate directory and populates the menu. Each of these menu items is hooked up to my handler (extends AbstractHandler) and the handler does get called each time a menu item is selected. What I don't know how to do is to get my handler to actually do something based on which of the menu items was selected. It would be enough if it was somehow passed the string of the menu item label, but I'm guessing there is probably a much better way of doing this.
I tried looking through the code of the org.eclipse.debug.ui to see how they do it with the run/debug configurations, because that is pretty much exactly what I want. They pick up the .launch files from the .launches directory of the project and display them in a list. The code for that is very complicated though and has a lot of other behaviour that is unassociated with it, so as a beginner I am struggling to get my head around it. Also, they seem to have done it a different way than I did, so it might be that I am totally wrong in my approach. Any help or pointers would be appreciated.
I finally found the answer to this myself. Within plugin.xml it is possible to specify parameters for each command, e.g.
<commandParameter
id="commandParameterID"
name="Name of the Parameter"
optional="false">
</commandParameter>
Now, when I am dynamically creating each menu item I can just add my parameter to the parameters Map of the CommandContributionItemParameter object.
CommandContributionItemParameter param = new CommandContributionItemParameter(PlatformUI.getWorkbench(), null, "CommandID", CommandContributionItem.STYLE_PUSH);
param.parameters = new HashMap<String, String>();
param.parameters.put("commandParameterID", "TheValue");
The parameters that are added this way are accessible in the handler class as follows:
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println(event.getParameter("commandParameterID"));
return null;
}
Possibly this simple menu creator helps you a step further (or the surrounding classes within the project underlying the link)
or maybe the plugin.xml of the popup menu within the same project
Related
So i am writing an eclipse plugin, which adds a custom-launch action to the toolbar. It extends AbstractLaunchToolbarAction , thus it also has that dropdown menu with launch history and so on. This menue is filled up with actions, containing the lauch-configurations.
At this point, when i open dropdown menu and select one launch configuration from the history, it works fine and runs the configuration.
However, my aim would be to alter this behaivor, to do something more.
My problem is that i cannot find the place where the launch configuration from the menu is processed, thus i cannot do anything with it...
So far i just create the menue by calling the fillMenu(Menu m)
So my question is, how (in code) does eclipse proccess the exceution of the history launch-configuration? Where does the actual launching take place.
Figured it out... The menu consists of Action elements, which have method 'run' ... This method gets called when the Action is clicked.
I am working on an eclipse Plugin, and I would like to use an Editor, set some listeners on the current page(good terminology?), and remove these listeners when the user switches on another page (basically, the user is editing several files, as you could do with the default JAVA editor).
For the moment I have written a class extending StructuredTextEditor. The behavior of the plugin was the one expected, but when I try to work on several files, many problems occur. The main problem, according to me, is that I am not able to get notified when the user opens another page.
I read (and tested) a few things about MultiPageEditor, but it seems like it doesn't integrate an XML editor as default editor. How should I proceed in order to get a MultiPageEditor, with XML syntax coloring, and get notified when the user changes the current page to adjust my listeners ?
Thanks for reading.
the code is not perfect but at least you will have an example of a MultiPageEditor integrating an XMLEditor: https://github.com/fusesource/fuseide/blob/8.0.0.Beta2/editor/plugins/org.fusesource.ide.camel.editor/src/org/fusesource/ide/camel/editor/CamelEditor.java
The idea is to call addPage(new StructuredTextEditor()) inside createPages() method.
regards,
In your editor you can listen to selection changes in the editor text using:
getSelectionProvider().addSelectionChangedListener(listener);
where listener implements ISelectionChangedListener.
This applies to any editor derived from AbstractTextEditor (which includes StructuredTextEditor.
You need to do this fairly late in the editor creation. In the createPartControl method works:
#Override
public void createPartControl(final Composite parent)
{
super.createPartControl(parent);
getSelectionProvider().addSelectionChangedListener(listener);
}
I need to provide a java widget that provides users with a subset of the controls that a JFilechooser provides. Specifically I need to provide the look and feel of a JFileChooser dialog for the following typical actions:
Save Action
Load Action
But I am allowing them to see and do only the following:
See a static list of names that has nothing to do with File objects (These are names pulled from a mysql table).
Change the name so it doesn't conflict with a name they can see from within the static list.
Select a name from the static list
Ok
Cancel
So really just a way to do the basic things you can do with a JFileChooser minus the directory navigation and creation. Does such a skeleton of the JFileChooser exist or do I need to create this from scratch?
Thanks.
-Dennis
I have an existing project for which i have decided to create a GUI for in Netbeans. The problem I am encountering is the fact that every component that i drag-and-drop is private in the source and is unmodifiable. Must i create getters for everything?
I mainly just need this problem resolved for appending to the TextArea.
Thank you in advance
If you want to change that globally, go to the options dialog, then select miscellaneous, and pick the gui builder tab. You can configure the default modifier there.
By right clicking on a component in the Inspector panel, you can influence the generated code, even though it is in an editor-fold and not directly editable. For example, right click on a JList and edit the Properties > model to add text entries; right click on Code > Post Creation Code to add a code snippet affecting the selection model:
itemList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
Examine the code in the editor-fold to see the generated changes.
See also Introduction to GUI Building.
You should see some tags in the code, something to do with begin and end of variable area. Usually there are 2 different sets of tags, any code between those tags will regenerate when you modify the gui with the form builder.
You can write your own code outside of those tags and it should remain even after you make changes. Getters and setters are a good idea if you need to update your object from another class. I've done that before with some text areas where I had a utility class update the text in it.
currently im building an application which is supposed for some sound processing. I'm doing this in java/eclipse with swt/jface.
The processing itself need some options/properties for the algorithem inside. At this time, i have a .properties file which holds all options like:
trimLeadingSilence=20
trimtrailingSilence=20
trimhold=5
fftFrameSize=512
...
I don't want the user to edit these options in a texteditor like notepad++, but within the gui of my app.
Now I think about how to do this. I have 2 "ideas":
Create a class for each option set, and manualy code all these boring gui code lines. Like here for just one option ;-)
Spinner spinnerSilenceBack = new Spinner(shell, SWT.BORDER);
spinnerSilenceBack.setMinimum(0);
spinnerSilenceBack.setMaximum(200);
selection = Integer.valueOf(PropertyManager.getPropertyValue("trimming", "trailingSilence"));
spinnerSilenceBack.setSelection(selection);
spinnerSilenceBack.setIncrement(5);
spinnerSilenceBack.setPageIncrement(20);
spinnerSilenceBack.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
int selection = ((Spinner) e.getSource()).getSelection();
int digits = ((Spinner) e.getSource()).getDigits();
int result = (int) (selection / Math.pow(10, digits));
PropertyManager.setPropertyValue("trimming", "trailingSilence", String
.valueOf(result));
}
});
This takes a lot of time due to the fact that there are a lot of different options. So I thought about how I can dynamicly create such gui code, or just dynamicly create these gui windows when starting up the application. At least I would need a config file for the "gui creator" but I don't want to reinvent such a thing-thats why i ask you guys :)
I couldn't get clearly what you are asking.
But, since your question was How to dynamicly build up a gui, i have a a suggestion:
You could use Java Template Engine
library like Freemarker. This
would help you create GUI's that can
be built to work on the fly. With
freemarker you can have one single
template file and then replace the
values accordingly.
I have used it to generate HTML files on the fly. You could evaluate if you can use it otherwise. The API Documentation is rich. So you could go through that once.
Do you mean, you want to make an UI which will have all options you specified? It doesn't matter its a form OR a menu, its up to you. But yeah you can surely configure the names and types in .properties file.
See, you build a Menu OR form in AWT/Swing OR Servlet, but you can read it from properties file right?
You can also configure the same using Spring bean XML definitions, which can provide more support like you can specify all details in some Map OR List etc...
thanks.
I didn't use Swing for a lot of time, so here is just a basic principle.
Config should be done in xml, .properties file is bad here, cuz it doesn't describe objects out-of-the-box.
Add button ("Apply config"), attach actionListener, which 1)parses xml config, 2)then creates form or change settings of existing form, textarea, colors etc.
example for xml config:
found - check it's x_coordinate, y_coord (or use layoutManager, depends on logic), action, than jframe.getLayout().add(new Button(x_coord, y_coord, action).
found - the same.
than jframe.setVisible(true);