How do I know when user minimizes / maximizes Eclipse? - eclipse

I need to respond to the events of minimizing / maximizing Eclipse window. How do I do that?

I can suggest a way: you can write a plugin for it.
For example see this improvized "tutorial", I made it, tried it works on Ganymede. A bit ugly at the final Shell variable, but working. If you know nicer solution just shoot :)
((actually there is a way: to extend your own ControlListener class, but that needs more coding :))
Create a new Plug-in Project, name it as you want, create it from a template named: Hello World Command
Open the SampleHandler class, and then replace the execute() function with this code.
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil
.getActiveWorkbenchWindowChecked(event);
final Shell s = window.getShell();
window.getShell().addControlListener(new ControlListener() {
#Override
public void controlMoved(ControlEvent e) {
// TODO Auto-generated method stub
}
#Override
public void controlResized(ControlEvent e) {
MessageDialog.openInformation(s,
"WindowEventHandler Plug-in", "RESIZED: "
+ e.toString() + "\nHello, Eclipse world");
}
});
MessageDialog.openInformation(window.getShell(),
"WindowEventHandler Plug-in",
"Hello, Eclipse world, resize will be taken care of.");
return null;
}
now. Start the project (Run As-> Eclipse application), and you'll se an Eclipse button on the toolbar. Click on it! It triggers the running of the above code where the essence is that the window.getShell() returns with the main window component so you can add listeners to it.
If you want it to run automatically, not just for a button, you have to find out a plugin where the entry point is connected to the starting of the application.
Hope this helps.
b

Found a way to do it easily: you have to create a ShellListener or ShellAdapter, which have methods that are called when the shell is iconified, deiconified, activated, deactivated and closed.
After creating it, add it as a listener with the following line:
int i;
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().addShellListener( yourListenerHere);
If you ever remove it from the shell's listeners list, be sure that Workbench, ActiveWorkbnchWindow and Shell are not null.

Related

breakpoints location change by modifying code

in eclipse and Visual studio, I find that placing a break point in certain line
1- public class HelloWorld {
* 2- public static void main(String[] args) {
3- System.out.println("Hello, World");
4- }
5- }
if i placed breakpoint in line 3 and edited the code in notepad editor to add anything before that line then open back eclipse it'll point automatically to line 4 with the breakpoint as it adapted the line I chose before.
1- public class HelloWorld {
2- public static void main(String[] args) {
3- int i=0;
* 4- System.out.println("Hello, World");
5- }
6- }
I need to know the location of the code in eclipse source code that handle this case? or is there any known algorithm that is used to adapt the breakpoint location after modifying the code ?
I don't think it searches for the line by text as when I change the content of the line it does go to it w'ever the change
To control syntax, types etc., modern IDE creates tree-model of your source code (similar what compiler does before compiling).
The changes in code - inside or outside IDE - does not require rebuilding the entire tree, therefore it is able to remember at which node of "source tree" the breakpoint is, rather than remembering only line.
It is quite handy, if you are actively debugging and changing the code, you do not have to move all your breakpoint up or down, if the code few lines up or down.
It looks like this , the breakpoint is (probably) attached not to line, but to one of those nodes.

How to display gef editor?

I am trying to use GEF for displaying and editing a flow diagram in an RCP. I have used GraphicalEditorWithFlyoutPalette as my editor looking at various examples on the internet. I n all those examples I dont find tips on how to show this editor when my RCP application starts first. previously I used a ViewPart to display the flow diagram and it worked fine. Now I am struck without knowing how to open the same on the editor which I designed.
The IDE class has several methods for opening an editor, for example:
IFile file = ... file you want to open
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorInput input = new FileEditorInput(file);
IDE.openEditor(page, input, "editor id");
You can use the org.eclipse.ui.startup extension point to run code early in the Eclipse start up but the code above will not run so early in the start up. But you can schedule a UIJob to run the code:
#Override
public void earlyStartup()
{
new StartJob().schedule();
}
class StartJob extends UIJob
{
public StartJob()
{
super("Start Job");
}
#Override
public IStatus runInUIThread(final IProgressMonitor monitor)
{
.. open editor code
return Status.OK_STATUS;
}
}

How do I access active IWorkbenchWindow in BundleActivator's start method?

In my BundleActivator's start method, I need to access the active IWorkbenchWindow to add an IPartListener to it. However, when the start() method is called,
Workbench.getInstance().getActiveWorkbenchWindow()
returns null.
I tried adding a IWindowListener to Workbench.getInstance(), but a window open event is never fired. Only a window activated event is fired when I switch to another program and back to eclipse.
How do I add the IPartListener properly?
Workbench is an internal class and you should not be using it (Eclipse API Rules of Engagement). Internal classes may be changed without notice (Workbench in fact was completely rewritten between Eclipse 3 or 4).
The official way to get the IWorkbench interface is:
IWorkbench workbench = PlatformUI.getWorkbench();
However this may also return null if it is called too early in the Eclipse startup.
It is not usual to add a part listener in an activator, usually this is done in a view or editor part initialization or in a command handler or action.
I found a way to do it:
final IWorkbench workbench = PlatformUI.getWorkbench();
workbench.getDisplay().asyncExec(new Runnable() {
public void run() {
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window != null) {
// do something
}
}
});
(from Eclipse documentation)

GWT input event on TextBox

Given the following code:
TextBox tb = new TextBox();
tb.addValueChangeHandler(new ValueChangeHandler<String>() {
#Override
public void onValueChange(ValueChangeEvent<String> event) {
Window.alert(event.getValue());
}
});
onValueChange will be called if the TextBox loses focus. I am trying to have it called whenever the input value changes. The solutions I have read all involve handling the keyup and paste events such as in this answer. How to build a Facebook-style input box in GWT Hasn't this been addresses in GWT 2.5.1? Is there a way to bind to the native input change method? Another widget or using the UI framework would be acceptable if they have this functionality
The only way in GWT is to bind to the key down/key up and paste events.
Please send a patch to add support for the input event (using addBitlessDomHandler): http://www.gwtproject.org/makinggwtbetter.html, it should be rather easy (add a acase in DOMImpl) and has good chances to make it in (and if sent early enough, would have good chances to ship in GWT 2.6)
The solution is use the right event and that is the input event, so look how to hook on it, there are many ways to do it. Because I work with elements and not with Widgets this the code that I use it:
Element input = Document.get().getElementById("my-input");
DOM.sinkBitlessEvent(input, "input");
DOM.setEventListener(input, event -> GWT.log("Event!"));
You can just use addChangeHandler() and onChange, tb.getValue().
I used the following to detect when the value of a textbox changes. Just bare in mind this only detects if the text box goes from empty to full or full to empty. This was done to try reduce async calls to the server to validate the input
#UiHandler("notes")
#SuppressWarnings("unused")
public void notes(KeyUpEvent event) {
if (!areNotesCaptured && !notes.getText().isEmpty()){
fireLeaveSelectionUpdatedEvent();
areNotesCaptured = true;
} else if (areNotesCaptured && notes.getText().isEmpty()){
fireLeaveSelectionUpdatedEvent();
areNotesCaptured = false;
}
}

Inconsistent output to Eclipse Console View

I am invoking a compiler command but the compiler messages are not getting displayed in the Eclipse Console View consistently.
I have my launch() method implemented the same way as first code block of
this question; I have the command-line string setup which I use to call DebugPlugin.exec() method. However, unlike the the author of the question above, my output Eclipse console is very inconsistent. T
There is no activity in the console when I invoke the command and the console continues to display the "No console to display at this time." But after invoking the command numerous time and activating different consoles from the drop-down menu, the console occasionally does become active and message is displayed.
I am confused with how the eclipse is behaving and not sure how to resolve this issue. Any comment and/or recommendation would be appreciated.
Thanks!!
--
EDIT
To add some more info, running the external process using External Tools works fine. I add the compiler process c:\path\myprocess.exe in Locations field and the file to compile in the Arguments field within the External Tools Configuration window. When I run it, all the output is displayed fine. It just won't display when I run it programmatically through LaunchConfigurationDelegate class.
Maybe try bringing the console to front programmatically see if it helps:
* Bring the console to front.
*/
public static void showConsole() {
Display.getDefault().asyncExec(new Runnable() {
#Override
public void run() {
IWorkbenchWindow window = CUIPlugin.getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IViewPart consoleView =
page.findView(IConsoleConstants.ID_CONSOLE_VIEW);
if (consoleView == null) {
IWorkbenchPart activePart = page.getActivePart();
try {
consoleView =
page.showView(IConsoleConstants.ID_CONSOLE_VIEW);
} catch (PartInitException pie) {
CUIPlugin.log(pie);
}
// restore focus stolen by the creation of the
// console
page.activate(activePart);
} else {
boolean bringToTop = true;
if (bringToTop) {
page.bringToTop(consoleView);
}
}
}
}
}
});
}
Finally got it to work. The main change I've made is having my MyLaunchConfigurationDelegate extend LaunchConfigurationDelegate instead of just implementing ILaunchConfigurationDelegate. When observed through the debugger, the launch() method went through similar code path as external process that was launched via External Tools when MyLaunchConfigurationDelegate extended LaunchConfigurationDelegate.
I guess it was lack of information on my part but I wasn't sure which part of the code was more important to share.
Another piece of code that was removed was:
IProcess dbgProcess = DebugPlugin.newProcess(launch, compilerProcess, "XVR Compiler", processAttributes);
...
launch.removeProcess(dbgProcess);
I've added it while attempting different approach in debugging this issue and it actually caused more issues by removing the debugProcess before it has chance to display output to the console.