I have an Eclipse Editor plugin associated with .xxx filetype, how can I detect when the user switches from a document to another?
I mean when a user switches from a tab with graph1.xxx to another opened tab with graph2.xxx
I would add an IPartListener (or IPartListener2) event listener to the PartService of the Active Workbench Window, and listen for the various changes. Something similar to the following code could be used (if you register the listener inside your editor code, you should get the workbench window through the inherited methods):
Workbench.getInstance().getActiveWorkbenchWindow()
.getPartService().addPartListener(new IPartListener2() { ... }
Be careful, that both Editors and Views are parts, so some notification will be unnecessary for your job.
Related
I´m writing an Eclipse plugin to show the contents of an own file type in an own custom editor.
This file basically consists of 1..n IFile´s from the Project Explorer which are shown in a SWT TreeView.
The entries in this TreeView are some Beans organized in a flat List, but i provide an adapter to convert them to IFile´s.
<extension
point="org.eclipse.core.runtime.adapters">
<factory
adaptableType="de.dstg.delta.collections.model.Collection$Member"
class="de.dstg.delta.collections.CollectionMemberAdapterFactory">
<adapter
type="org.eclipse.ui.views.properties.IPropertySource2">
</adapter>
<adapter
type="org.eclipse.core.resources.IFile">
</adapter>
</factory>
</extension>
Eclipse Screenshot
It´s no problem to show a custom SWT menu but i think the right way is using the Eclipse menu structure, especially by providing default behaviour for Resources.
How can i show the default context popup menu, which is used by right-clicking resources in the Project Explorer, in my SWT TableView?
EDIT second question removed
EDIT2
According to the answer from greg-449, the problem remains that the context menu shows no entries i would like to have for this type of selection.
f.e. i need delete or open with or something like that 'file basics' without implementing it on my own.
We have also some other menus from additional plugins that should be visible here when the appropriate file type is selected. This works in Project Explorer but not in my table view.
I think the problem is the type of the selected element.
Plugin spy shows the following in my table view:
type of the selected element: Collection$Member,
interfaces valid for the selected element: IAdaptable
whereas the Project Explorer shows File and IFile, respectively.
My adapter works generally and delivers the related IFile while being triggered from an unknown Eclipse source.
I think i have to explicitely say, that the context menu should use the IFile type to get the correct menu entries but i dont´t know how.
Or did i miss something?
There isn't really a 'default' menu. Some menu items are defined to be added to all popup menus that define a specific place holder.
To use the place holder you must register your context menu with Eclipse, something like:
private void createContextMenu(Viewer viewer) {
Control menuControl = viewer.getControl();
MenuManager menuMgr = new MenuManager("#PopUp");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
#Override
public void menuAboutToShow(IMenuManager mgr) {
fillContextMenu(mgr);
}
});
Menu menu = menuMgr.createContextMenu(menuControl);
menuControl.setMenu(menu);
// register the context menu such that other plugins may contribute to it
getSite().registerContextMenu(menuMgr, viewer);
}
private void fillContextMenu(IMenuManager menu) {
// TODO add your actions
// Standard additions
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
You will probably also need to set your viewer as the 'selection provider':
getSite().setSelectionProvider(viewer);
Many menu items will check this to see what the type of the current selection is.
There is nothing that will automatically give you things like Open With or Delete, you have to add these yourself in the 'fillContextMenu' section.
You can use org.eclipse.ui.actions.OpenWithMenu for Open With.
IFile file = ... currently selected file
IMenuManager submenu = new MenuManager("Open With...");
submenu.add(new OpenWithMenu(getSite().getPage(), file);
menu.append(submenu);
What object type (eg. JFace, Shell, ApplicationWindow) should I use to create my own window?
In my plugin, this window will have three 'panels', lots of components and what' s most important I want it to be on top, till it's closed - like any other window in Eclipse, so that user can' t do anything else in IDE till he close the window.
The window will be launched after clicking the icon in Eclipse's menu.
If you mean something like the Eclipse 'Find/Replace' dialog which does not block the main window use a JFace Dialog (org.eclipse.jface.dialogs.Dialog).
Set the dialog to be modeless and turn off 'block on open'.
This is what the Find/Replace dialog uses:
public FindReplaceDialog(Shell parentShell) {
super(parentShell);
// .... other code ...
setShellStyle(getShellStyle() ^ SWT.APPLICATION_MODAL | SWT.MODELESS);
setBlockOnOpen(false);
}
Add a command following tutorial at : http://www.vogella.com/tutorials/EclipseCommands/article.html
Create a handler for the command that opens a swt widget Dialog that is modal. ( use SWT.APPLICATION_MODAL ) populate the dialog with composites that you need.
I have a button in a SapToolbarControl which is of type ToolBarButtonType.ButtonAndMenu. I found out how to get the ID of the button and I have tried the three methods selectContextButton(), selectButton() and pressContextButton():
selectContextButton() always throws a UnsupportedMethodException with the message
The method SapToolbarControl::SelectContextButton is not supported for SAP.
The other two methods do not throw an exception but do nothing.
How can I make use of toolbar control buttons of type Menu and ButtonAndMenu?
I'm using Silk4J 16.0 Hotfix 2 in Eclipse Luna 4.4.2 with SAPGui 7.30.
Clicking the button programmatically does not create the visual effect of opening a context menu, but after clicking the button, the context menu exists from which an item can be selected, e.g. with the method selectContextMenuItemByText().
selectContextMenuItemByText() takes the translated human readable text as a parameter which you can see when pressing the button manually (which creates the visual effect of opening a context menu).
I have a RCP applicaton from which I need to show a GEF Editor in a modal "dialog". But since the editor framework seems to be tightly coupled to the use of a workbench window etc I need to find a why to open a new workbench window (with its own WorkbenchWindowAdvisor etc) so that I can open my GEF editor within this workbench window. Once I get this workbenchWindow opened I will set the style of the WorkbenchWindow's shell to be application modal.
I have done this in a customer project using the following components:
A static class with a method openNewWindow(String type, ...). This is the method you call to open a new window. The type argument specifies the wanted type of window.
The class looks up the specified type via a new extension point to get an ILocalWorkbenchWindowAdvisor and the initial perspective ID.
It then saves the information in global variables and calls IWorkbench.openWorkbenchWindow(perspectiveID, ...)
In ApplicationWorkbenchAdvisor.createWorkbenchWindowAdvisor(...) a new advisor is create based on the saved ILocalWorkbenchWindowAdvisor - the returned advisor basically delegates all the postWindowCreate(...), etc to the same methods in ILocalWorkbenchWindowAdvisor...
If no ILocalWorkbenchWindowAdvisor is saved - which is the case for the very first window to be opened - the type "mainWindow" is looked up and used...
It works pretty well and let all parts of the project add new windows as needed.
Use the command "org.eclipse.ui.window.newWindow" to open a new window. In your WorkbenchWindowAdvisor.preWindowOpen(), set the shell style on the IWorkbenchWindowConfigurer to be application modal. You can also hide the coolbar, menu and status bars, so it looks more like a dialog than a window.
So I made a standard swing application in Netbeans 6.8 but I can't find where the resource file that defines the localized string for the Exit menu item under File.
It doesn't seem to be defined among the resource files in <project>/resources. Is this a standard string somewhere or am I missing something?
The "Exit" string doesn't get defined as a localized string like the File menu item -- it gets generated into code through the Netbeans GUI builder. That is why you don't see it in the properties file.
If you open the file {ProjectName}View.java you can see that it gets defined through the netbeans GUI builder. Click on the file menu and then the exit menu item in the GUI builder and you can look at the properties of the swing item. One of the properties is the text of the JMenuItem.
Then these properties get generated into code.
Are you just trying to shut down your application in such a way that you are able to do clean-up tasks before the system shuts down? If so then on the Java Sun site they say that you need to override the shutdown method; specifically :
#Override
protected void shutdown() {
// The default shutdown saves session window state.
super.shutdown();
// Now perform any other shutdown tasks you need.
}
This is located at this location