How to display gef editor? - eclipse-rcp

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;
}
}

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.

HTML version of LibGDX game doesn't show any logging

I am having trouble getting a html version of my programme to appear.
I am using LibGDX 1.3.1 and running in Java it works fine.
I uploaded the game here:
http://www.darkflame.co.uk/MeshExplorer/index.html
The libgdx loading bar appears and finishes - and in Chromes network tag I can see assets loading.
However, nothing appears other then the rectangle of the expected game size.
Most confusingly for me though, I dont see any crashes or logs from my code.
That is, there is nothing after "SoundManager 2 loaded (OK) "
Given that the first lines of my main core class are:
game=this;
font = new BitmapFont();
batch = new SpriteBatch();
Gdx.app.log(logstag, "loading..");
I expected at least to see "loading.."
I even added some gwt logs to html launcher
public class HtmlLauncher extends GwtApplication {
static Logger Log = Logger.getLogger("HtmlLauncher");
#Override
public GwtApplicationConfiguration getConfig () {
Log.info("GwtApplicationConfiguration");
System.out.print("GwtApplicationConfiguration");
return new GwtApplicationConfiguration(640, 480);
}
#Override
public ApplicationListener getApplicationListener () {
Log.info("test, returning class ME() ");
System.out.print("test, returning class ME() ");
return new ME();
}
}
again, nothing.
I am at a lose how to disorganize this problem further.
It just seems like libgdx isn't even attempting to run my code.
The default logging level in the html target is LOG_ERROR. You would not see any Gdx.app.log messages unless you set the logging level to LOG_INFO.
Calling Gdx.app.setLogLevel(LOG_INFO) in your getConfig or getApplicationListener methods should do the trick.

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)

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.

How do I know when user minimizes / maximizes 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.