How to make GraphicalEditorWithFlyoutPalette's PaletteView visible on first start - eclipse-rcp

My GEF editor (extending GraphicalEditorWithFlyoutPalette) always opens the editor with the palette hidden on first start of the application / first opening of the editor (after a build for example).
As this will potentially bewilder users who'll need to go in search of the flyout icon first, I'd like to have the palette view shown whenever the editor is opened. The user can then choose to close it on his/her preferences.
How can I achieve this? The API doesn't seem to give any clues, or I'm unable to find them...

The state of the palette defines if it is open or closed. This state is accessible using the getPalettePreferences().setPaletteState() method that is accessible in the GraphicalEditorWithFlyoutPalette. To open the palette, you must set it to the FlyoutPaletteComposite.STATE_PINNED_OPEN, like this:
getPalettePreferences().setPaletteState(FlyoutPaletteComposite.STATE_PINNED_OPEN);
If you want to ALWAYS override the state so that the palette is always opened with the editor, you have to add the line to the constructor of your editor. If you only want to do this once, and then leave the state as it was last selected by the user... No idea how to do this :-(

Related

How to customize the "Save Resource" dialog of an ISaveablePart in Eclipse?

I have an Eclipse application that uses a ViewPart as a floating window with buttons/options for what is happening in the editor.
It looks similar to the floating tool windows in GIMP.
Implementing ISaveablePart in the ViewPart provides a default dialog upon closing the ViewPart with everything I want: a Yes button for saving, a No button and a Cancel button.
However, I would like to customize that default dialog.
Is that possible? If so how?
I looked into ISaveablePart2, but I just end up with my own custom dialog PLUS the default. Is there a way to suppress the default dialog in ISaveablePart2? If so, that would also be a solution.
For clarity: I'm not married to either of these ideas. What I ultimately want is a custom dialog box to come up when someone closes the ViewPart to ask the user if they want to save the contents of the editor ---> with an option to cancel the closing of the ViewPart.
If you use ISaveablePart2 you should only get your own dialog as long as your promptToSaveOnClose method does not return ISaveablePart2.DEFAULT. So there should be no other dialog if you return ISaveablePart2.YES, ISaveablePart2.NO or ISaveablePart2.CANCEL.
The standard Save Prompt dialog is not customizable.
The code for this is org.eclipse.ui.internal.SaveableHelper.

Adding New Components in WindowBuilder Design View

At risk of this being a trivial question, I need to know how to add more components (in the components explorer) in WindowBuilder for Eclipse Juno. I'm taking a dive and trying learn how to add a GUI to one of my personal projects. Right now all I have mustered up is just a JFrame that has a button that launches my program in the console with a little notification saying so. But what I am thinking about having is a "Start up Window" with just some stuff and button or something that says Enter application or something. So then I want a new window to pop up as a "Run Window". I have created a new JFrame as a "run window" and hide/set visibility of "startWindow" to false and get the result I want. But I want to be able to edit this new JFrame in the design window along with the default JFrame I started with.
Is there a way to do this? I tried right-clicking in the components window in the design view and it doesn't do anything. I also tried right-click the object from the project explorer and couldn't find anything. Am I missing something? Is this even possible?
The question seems to have 2 parts, so I will try to answer both of them.
1) Adding components directly in the components explorer
The only thing you could do, to get new components into there via right-click is "Surround with". For example you have a JPanel, right-click on it and click "Surround with...". You could try and put a JScrollPanel in there, so you can scroll your JPanel.
But the usual way to add components is by the "Palette", it contains a lot of components, that you can drag&drop into either the components-explorer or directly into your app Window -> Show View -> Palette.
2) Showing a certain window
If I understand this correctly, you want to show one window, click on a button and then show another window which has the same size etc. like the one before.
Setting the visibility for the first window to false and the second does work.
But under certain circumstances it's easier to use CardLayout.
Imagine a stack of cards, you can see only the first card. Then you click a button and now see the second card and so on.
See this: https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html
for information and examples.

Adding menu listener for Paste option in SWT Browser

I have a org.eclipse.swt.browser.Browser instance created in a composite. I would like to know when some content is pasted in the browser using the (platform specific) right click context menu and selecting the paste option.
In the menuDetected() of MenuDetectListener, I get a notification when the context menu is detected in the browser.
How can I know if the Paste option is selected from the context menu?
Regards,
Noopur
No you can't access the selected context menu item. There is no direct provision for that. At least not in eclipse 3.7. Although, you could try different combinations of events for determining the menu item. For example, in windows the internet explorer populates the status bar with 'inserts the clipboard...' when your mouse pointer hovers over the Paste menu item, you can capture this using StatusTextListener event.
Note: The hack is not an elegant solution, even if you get it working, there is still some possibility that it may break with new or older releases of SWT or in fact its behavior may vary with operating systems !!

Eclipse code template to insert a bookmark?

Eclipse has a nifty feature which allows you to define "templates" for code. I have created one to automatically put in a println and add a "TODO" comment. I'd like for this to also add a bookmark so I can easily find it again.
(The codebase I am working with makes it unfeasible to use just the Task List to find what I need to do since there are a lot of TODOs laying around.)
My current template is simply System.out.println("don't commit me!"); //TODO: fix this ${cursor}.
A bookmark is part of the editor.
You can find all of your TODO comments in the Eclipse Tasks view. If the Tasks view isn't open, just left click on Window -> Show View -> Tasks (not Task List).
If you left click on the Tasks description to make sure the Tasks view has focus, then double click on the Tasks description, Eclipse will open the editor and take you to the TODO line.
If you have the code already open in the Eclipse editor, Eclipse draws blue rectangles on the right side of the editor to mark all of the TODO comments. Left clicking on the blue rectangles will take you to the TODO comment line.
Edited to add: You can sort the Tasks view by clicking on any of the titles, like Resource.
I don't think it's possible via a code template.
It's certainly possible with the a key shortcut that can be assigned to add bookmark in:
Window->Preferences->Keys
but you still have the prompt to enter the name of the bookmark (rather than use a default set of text).
If you really want to get close to the functionality you want you could take a look at the Eclipse Bookmarks plugin:
http://www.etc.to/eclipse_bookmarks_plugin
and maybe hack it to do what you want... (if it doesn't already)...

How to Display Current Function in Eclipse

I miss a certain functionality in Eclipse. I would like to know the name of the current function the cursor is currently inside. This is useful when browsing unknown code using the search function, for example.
Any idea how to show it? Maybe a plugin?
I'm using the "Toggle Breadcrumb" option from toolbar:
It shows a nice breadcrumb, ending with current function name.
It's quite handy for me, as Outline becomes cumbersome to use if you have zilions of functions.
It produces the following structure above your Java Editor (truncated at the picture below):
The "Outline" view shows the current function.
It may be necessary to enable the 'Link to Editor' option in the Outline View dropdown menu. This might be off by default for CDT.
I was looking for something similar (Xcode-like bar at the top showing the current function, where you can also go to another function by clicking on it to open a popup list of functions). Here is what I settled on with Eclipse 3.5.1 CDT:
I moved the Outline view to the top, resized it to make it a 1-line horizontal strip (don't make it too narrow), and selected "Link With Editor" in its menu, so that it always shows the current function. However, this doesn't open a popup list like Xcode. For that functionality, I assigned a shortcut to the "Show Outline" command which does open a popup list of all functions.
The Eclipse function 'show outline' will pop up a list of outline objects, and it will highlight the object your cursor is inside in grey. It's typically bound to 'ctrl-o' (the letter 'o', not zero), but you can re-bind it as you see fit. I'm running Eclipse with the CDT plugin and it works pretty well for me.
To enable the breadcrumb invoke Toggle Java Editor Breadcrumb in the toolbar or press Alt+Shift+B in the Java editor.
You can also display the Quick Outline (ctrl+o). This way you see the context quickly without having to have a permanent Outline Window linked to the Editor.
Use the "Link With Editor" option on the outline menu
Press Ctrl+o (cursor is currently inside a function at a particular line).
It highlights the current method, or name of the class if the cursor is outside the method body.
You can click on highlighted method.
It has got inline search feature ...start typing name of the method to navigate to the specified method or method with matching search pattern.
If you press again Ctrl+o to shows the inherited members/methods.
Using outline with "link with editor" option worked also for me, thanks!
Just an addition, you can move outline pane in to the same window group as search, progress etc. saves the space in your perspective instead of keeping it at another group.