Eclipse RCP EditorReference / IEditorPart - eclipse

Eclipse RCP components
I have small experience with Eclipse RCP and I'm wondering if some thinks are possible from the framework, or I should implement them.
Regarding to the attached image from the upper link I have some questions:
1. Is it possible to detect what EditorReference is Focused, Visible or Not Visible(I'm speaking for the Editors that are on >>4, opened but not visible)?
For me FormData.java EditorReference is Visible but not Focused, FormLayout.java is Visible and Focused, the other EditorReference behind >>4 are Not Visible.
PS: I want to do this for an Eclipse RCP application that I write it now.

Check out this link : https://wiki.eclipse.org/FAQ_How_do_I_find_out_what_view_or_editor_is_selected%3F
IWorkbenchPage page = ...;
//the active part
IWorkbenchPart active = page.getActivePart();
//adding a listener
IPartListener2 pl = new IPartListener2() {
public void partActivated(IWorkbenchPartReference ref)
System.out.println("Active: "+ref.getTitle());
}
... other listener methods ...
};
page.addPartListener(pl);

Related

Custom button for toolbar Eclipse RCP Application

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
}

How to add Perspective Bar Switcher to pure eclipse 4 rcp application

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:

Eclipse RCP 4.x show view

I'm working for a short time on the libraries of eclipse 4.x someone could tell me how can I open a view through from the context menu? Thank you in advance.
To show a part anywhere you should define a command in the application model and a handler for the command. To show a part in the handler use:
#Execute
public void execute(EPartService partService)
{
MPart mpart = partService.showPart(part id, PartState.ACTIVATE);
}
In the application Part definition for your part add a Popup Menu to the Menus section. In the popup menu define a HandledMenuItem for your command.
To register the popup menu as the context menu for a control (tree, table etc) use:
#Inject
private EMenuService;
...
menuService.registerContextMenu(control, menu id);

what is method to call the eclipse Save/SaveAs option programatically in plugin [duplicate]

I am developing a plug-in.
On clicking a button, I'd like to call the save method of Eclipse or call the save button on Eclipse toolbar.
What is the way to do it?
org.eclipse.ui.PlatformUI.getWorkbench().saveAll(..)
should do the trick.
If you want to save the active editor, please try
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = page.getActiveEditor();
page.saveEditor(editor, true /* confirm */);
Note that the elements in the navigation path may be null.
I use this to save dirty editors for one or more projects:
//Save all changes
Display.getDefault().syncExec(new Runnable() { // save all editors needs to be called by the ui thread!
#Override
public void run() {
IDE.saveAllEditors(new IResource[]{prj}, true);
}
});
where prj is an IProject object.
hope this helps
bye
I used -
IDEWorkbenchPlugin.getDefault().getWorkbench().saveAllEditors(true);

Refreshing the workbench

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