I have created a pure Eclipse e4 rich client platform application application model. I created multiple perspectives using perspective stack, but I am unable to switch other perspective because there is no default perspective bar or switcher icon present in Eclipse e4. How to implement a perspective switcher in pure Eclipse e4?
EPartService.switchPerspective will do the actual switch, but you will have to design and implement the UI.
You could use a ToolBar in the window Trim Bar with buttons for each perspective. Alternatively a Combo as a Tool Control with a list of the perspectives, it is up to you.
To put a control at the right of a Trim Bar you need to add two Tool Control objects to the trim. Something like:
The first Tool Control is just a spacer to fill the center of the bar.
On the tags tab for the control add the word stretch to tell e4 to stretch this control over as much space as possible:
You will also have to specify a class for the control. This just needs to create an empty Composite to occupy the space. For example:
public class SpacerControl
{
#PostConstruct
public void postConstruct(final Composite parent)
{
Composite body = new Composite(parent, SWT.NONE);
body.setLayout(new FillLayout());
}
}
The second Tool Control will contain your Combo control for the perspective switch. Something like:
public class ComboControl
{
#PostConstruct
public void createGui(final Composite parent)
{
Combo combo = new Combo(parent, SWT.READ_ONLY);
... initialize Combo, add listeners, ....
}
}
This should end up looking something like this:
Related
What is the canonical way of creating a menu item that implements a toggle or radio state in an eclipse e4 rcp application?
It seems such a basic thing, but all the documentation I found relies on e3 API and creates dependencies to org.eclipse.ui, which is not allowed in e4.
One possible way that I use for a radio button menu which saves the radio button state in the part class.
I use multiple Direct Menu Item entries with the type set to Radio.
I set a Tag value (on the supplementary page of the menu item) to the value I want to associate with the menu item.
I use the same handler for all of the menu items.
In the handler I inject the MPart and the MItem:
#Execute
public void execute(final MPart part, final MItem mitem)
{
// Only take action on the selected radio item
if (!mitem.isSelected())
return;
// The tag value specifying the radio state
String tag = mitem.getTags().get(0);
// Get the part class
MyPart myPart = (MyPart)part.getObject();
// tell the part about the state change
myPart.setState(tag);
}
Instead of the MPart you could also use any class that is in the Eclipse Context - such as one declared as #Creatable and #Singleton.
I am currently working on a web browser application using Eclipse e4.
I want to put on the toolbar a toggle button for saving my favorites url's.
I want it to be like in Google Chrome , a star which gets the yellow color when it's pressed(the link was added to favorites).
How can I do this?
Should I use for this the Application.e4xmi ?
You can use the Application.e4xmi if this is a tool bar for a Window or a Part. You would use a 'Handled Tool Item' in the tool bar.
The Application.e4xmi does not provide a way to set separate icons for the selected and normal states of a tool item so you will have to do this in the handler class. Something like:
#Execute
public void execute(MToolItem mitem)
{
if (mitem.isSelected())
mitem.setIconURI("platform:/plugin/your.plugin.id/icons/selectedimage.png");
else
mitem.setIconURI("platform:/plugin/your.plugin.id/icons/unselectedimage.png");
// TODO other code
}
I am trying to provide some default behavior to a standard Pane in Java FX. I would like to use this Pane in SceneBuilder. For some reason the layout isn't working as I would expect.
I created the following component:
public class GroupBox extends Pane {
public void configureGroupBox(String title) {
//Perform needed set up here.....
}
}
I have exported this control into a JAR file and imported that control into SceneBuilder. I am able to select this control in SceneBuilder and add it to my FXML.
However, the problem starts when I attempt to add controls within it. Even though this extends a javafx.scene.layout.Pane the layout engine of SceneBuilder is pushing all controls to the top left and overlapping them, rather than having no layout instructions.
Is what I am trying to do possible? If so, is there something else I need to do? At this point, my control is just an empty extension of the Pane class.
Thanks.
That is a Scene Builder limitation.
SB provides full operation for builtin containers only (i.e. the ones that are part of JavaFX). For custom containers, it provides limited operations: typically SB allows to drop a component inside but not to move it (because it considers that extending Pane does not imply free positioning of children).
I have created a simple view, but it would be nice to add buttons to it. For example, I drew two blue buttons into the view below. Is there a way to add similar buttons to my Eclipse view? I know that I can add a pulldown menu, from this question, but buttons are preferable.
My example below is just a demonstration - the location/size/color of the buttons does not matter as long as the buttons are inside the view.
In case you are using SWT:
For a start you could install WindowBuilder. It lets you work on the UI level without caring to much about implementation. The generated code however is not layed out in the way that you can work with, when you are creating views with more than a few buttons.
The implementation depends on your Eclipse version.
In the old Eclipse 3.x, a Button could be set up by Overriding the method createPartControl:
#Override
public void createPartControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new GridLayout(1, false));
Button btnMybutton = new Button(container, SWT.NONE);
btnMybutton.setBounds(0, 10, 75, 25);
btnMybutton.setText("MyButton");
//do anything else here
}
If you are familiar with other UI Frameworks and don't like SWT, you might as well switch to e.g. Vaadin or JavaFX. There's a blog articleabout changing the renderer of your application.
HI,
I am facing some problem.. I want to hide the menu when eclipse workbench starts.
But the problem is menu is not hiding when the eclipse workbench starts. It is hiding only
when some refresh is happened. for example: when I change the default perspective to some other perspective, I am getting the desired out put. That means menu is hiding.
But when the eclipse workbench is loaded it is not hiding the menu. Below is my code.
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
try {
IWorkbenchWindow window = Workbench.getInstance().getActiveWorkbenchWindow()
if(window instanceof WorkbenchWindow) {
MenuManager menuManager = ((WorkbenchWindow)window).getMenuManager();
IContributionItem[] items = menuManager.getItems();
for(IContributionItem item:items){
System.out.println("item.getId()::: "+item.getId());
menuManager.remove("org.eclipse.ui.run");
menuManager.remove("help");
menuManager.remove("project");
}
}
}`
}
};
Given that you are looking to hide some features, I don't think that this is the best approach. (Not I am using the term feature here in the colloquial way, not as an Eclipse feature.
I would recommend one of two avenues:
Perspectives: See the extension point org.eclipse.ui.perspectives. This allows you to create a new perspective like the debug perspective or the Java perspective. Using a perspective, you can select exactly what menu items and views are shown and which ones are hidden.
Capabilities (aka activites): See the extension point org.eclipse.ui.activities. This allows you to have some fairly fine-grained control over what features are available in the workspace. See more info here: http://wiki.eclipse.org/Galileo_Capabilities
Put Your code in org.eclipse.ui.startup extention point. Make a Startup class after implementing the interface IStartup. For Details follow this link:-
Eclipse plugin : disable/enable dynamically an action from main menubar