Show editor area in E4 - eclipse-plugin

I have a simple perspective without the editor area:
public class MainPerspective implements IPerspectiveFactory {
#Override
public void createInitialLayout(IPageLayout layout) {
layout.setEditorAreaVisible(false);
}
}
Now I open an editor:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, "org.acme.project");
In E3, this made the application show the editor area (because how else would I see the newly opened editor part). In E4 (or E3 compatibility) nothing of the sort happens.
The API to open the editor area manually is IWorkbenchPage#setEditorAreaVisible(true), but it does not work for me. Maybe because the intro screen is still open when I want to open the editor? It should not matter either way.
There is a bug report for someting like this, but it was allegedly fixed 4 years ago, in Eclipse 4.2.
So how do I show the editor area in E4?

Related

Intellij new Java Class opening a different dialog than usual

When creating a new java class via new -> Java Class while using IntelliJ IDE, a random Dialog started appearing, and I can't find how to disable it.
This is the strange dialog that started showing, a sort of a wizard. Clicking the help button get's me There is no help for this dialog message.
How can I disable this window in the Intellij IDEA?
I too had the same problem, the exact same dialog. In my case, it actually ended up not being a bug, but IJ acting properly (kinda).
TL;DR: The template code for creating a "Class" object got automagically changed after an IJ update so that it would prompt for answers from the coder when creating a new class file. Changing it back in "Settings/File and Code Templates" to the default template code removes the problem, as the default template code does not use any variables that are prompted for upon class object creation (ex.: ${IMPORT_BLOCK}).
Long version ...
Bring up the Settings dialog for IJ, and in the search field type "template", and then select the "File and Code Templates" option. You'll see on the right side of the dialog the "Editor > File and Code Templates" area. If you select "Class" from the list of template types, to the right of that list of template types you'll see the template used when you create a class ...
Now I don't know why, but after a particular IJ update some months back, via their Toolbox app, the default template text/code was different, so that it looked like this ...
... and that latter template code/text caused the second dialog to appear that you see.
To fix the problem, highlight the "Class" template from the list, then click on the "Reset to Default" button that appears below the Files/Includes/Code/Other tabs (looks like a piece of paper with a 180 degree curving arrow on top of it), so that the template text goes back to what I have showing in the first screenshot, and then select the OK button.
Assuming your "default" template for the Class template is not corrupted/bad, you should no longer see the dialog that you asked about.
Go to Settings/File and Code Templates -> class and change it to:
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
public class ${NAME} {
}
You can also try hitting the reset to default button, as Adrian Romanelli suggested.

Allman-Style in Intelliji

I was wondering how I might configure Intelliji IDEA to automatically make my code look like:
public void Something()
{
// something
}
rather than:
public void Something() {
// something
}
I believe it is called the "Allman" style. Intelliji comes out of box using the "K&R" (I think?) style, however.
go to project settings. configure code style formatting.
To do Allman for Java (newbie-ish version) go to File/Settings/Editor/Code Style/Java. Next select the Wrapping and Braces tab and expand Braces placement. Now you must click 'End of line' for all three choices and select 'Next line' for each in the box that appears. Then click apply and OK.
I know this question is already answered, but to save people from actually modifying the settings.
Here is the AllmanIndent.xml download the .zip file.
After you download and extract the zip do the following steps:
From IntelliJ go to File->Settings->Editor->Code-Style and click the gear icon by the "Scheme" and then click on "Import Scheme -> IntelliJ code style XML" and then choose the extracted .xml file.
After this import, you can press Ctrl+Alt+L to auto-indent code.

Eclispe RCP: Is there an extension point that notifies me that an editor is opened?

When opening an editor in my Eclipse RCP I may want to close it again based on the content of the editor.
Where is the best spot for closing an editor that has just been opened? Is there some kind of extension point available for this or is there a way to avoid opening the editor at all?
The editor itself is added via the extension point org.eclipse.ui.editors.
I tried to hook myself in the connect method of the editor but I didn't manage to avoid the opening of the editor.
Solution: Thanks greg for pointing me into the right direction!
My Editor implements IPartListener now and the implementation works like that:
#Override
public void partOpened(IWorkbenchPart part) {
if (part instanceof MyEditor) {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(this, false);
}
}
This will close the editor after opening it.
You can use IPartListener to listen for all parts opening, closing and being activated.
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
window.getPartService().addPartListener(partListener);

IntelliJ IDEA: Auto detect run configuration like Eclipse

If you open up a class with a publis static void main(String[] args) {} method in Eclipse and hit run, then that class will run. If you move to another class with its own main() method and hit run, then that class will run. Is this possible in IntelliJ IDEA? Or will I have to manually change Run configuration every time I want to run something other than the current run configuration?
You can right click on the class in the Project view and select 'Run YourMainClass.main()'
Alternatively in the text editor with that class open you can right click anywhere in the window and select 'Run YourMainClass.main()'.
Or if you don't want to right click there's a shortcut too (should be displayed in the right click menu - differs by OS)
Doing this will save a configuration in the dropdown as well, so if you go in the edit configurations dialog there you can add vm parameters or any options that need to differ from the default. Configurations created like this have a semi-transparent icon to differentiate them.

eclipse workbench selections

I have written one code for getting the source and selected of the part of the eclipse. If we click on the view or editor it will display the object and if we select something it will displayed the selected item.The same way is it possible to get for dialogues and others actions. For example if I click on one dialog it should the dialog name or object. The same way for whate ever object i clicked on the wokbench its hould whats the object.including actions. Following is my code.
private ISelectionListener listener = new ISelectionListener() {
public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection) {
System.out.println(sourcepart, selection);
}
};
I got the for the commands. we can use IExecutionListener for the what ever the command they have attached to the workbench. Now I want for actions,dialogues,etc..
The short answer: it's a lot of work.
Have a look at Plug-in Spy code (ALT+SHIFT+F1). It looks at SWT events and uses the widget in the event as a starting point. It then has to use its knowledge of how various structures are constructed (views, wizards dialogs, preference dialogs, property dialogs, editors, menus, toolbars) to figure out if there is any useful information.
To do something similar, you would have to look at what builds a specific dialog, or action, and try and figure out how to extract that information. Repeat for each dialog that you care about.
See org.eclipse.pde.internal.runtime.spy.SpyFormToolkit and surrounding classes in org.eclipse.pde.runtime.