Eclipse: ctrl+space completion for main no longer works - java

I use Eclipse (3.7.1) and I like ctrl+space autocompletion. It used to work for generating a static public void main(String[] args) method but no longer does; instead if I type mai or main and hit Ctrl-space, I get a bunch of Main classes.
What's going on, and how can I fix this?
for what it's worth, I have Lombok 0.9.3 installed, so I wonder if that's messing things up.

Had you been playing around with content assist settings?
One quick try would be going to Window->Preferences and then choosing Java->Editor->Content Assist.
On Content assist property pane press 'Restore Defaults'
or
set "Sort proposals" to "alphabetically" - this should restore default content assist behavior.

In your eclipse
Go to Windows-->Preferences --> Java --> Editor --> Content Assist --> Advanced. Here you have to make sure “Java Proposals” is ticked.
I am sure it will work,it worked for me.

You could select checkbox public static void main(String[] args) in New Java Class menu.

Related

Using Jdf and Intellij: Specifically running a Jfd form in intellij

I don't really understand how to integrate jfd and intellij.
So far I have played around with it a little bit and developed a program that looks .
I then generated an actionEventHandler to handle when the add package button is pressed. For now I just kept it simple and had it output "THIS IS A TEST" into the outputField which is the textField in the picture above.
the actionEventHandler looks like this:
private void addPackageButtonActionPerformed(ActionEvent e) {
outputArea.setText("THIS IS A TEST");
}
I would then expect when I did "Test Form" on the jfd tab I would click the addPackageButton and it would put "THIS IS A TEST" into the outputField.
However, nothing happens. Is this what "Test Form" is for? Or is there another way that I can run my form and test it that I am not seeing? Or is this functionality only available in netbeans?
I figured out how to do this so I will post this for posterity.
Jfd doesn't add a main to your project by default so adding this:
public static void main(String[] args){
GUIClassName window = new GUIClassName();
window.setVisible(true);
}
will allow you to run the module and see the window.

Eclipse Java Error: Cannot find or load main class

I am using Eclipse Luna and i am trying to run a simple text program but Eclipse gives the error:
Error: Could not find or load main class Main
I have no idea what's going on. I haven't found anything useful on Stack Overflow or Google. Here is my code:
public class Main {
public static void main(String[] args) {
System.out.println("This is a String");
}
}
Thank you.
Your code looking fine !
Do following steps to run your class
Select your project, go to Project section in menu bar then click clean.
In tool section click on enter code here Build Automatically.
Select your class right click on it and then select run.
In the menu Run, select Run Configurations....
In the dialog box that opens, on the left side, you are supposed to have an entry Java Application, and under it, there should be your class (and maybe other classes you worked on before). It may be named Main or Main__ here.
Select it. If it was erroneously named Main__, change that to Main in the Name: field.
Now look at the entry for Main Class. In the text field, it should say Main. If it says Main__ or anything else, change that to Main.
Apply and Run.

Custom message when closing a part in Eclipse RCP 4

we have the following problem:
In our Eclipse RCP 4 application there are multiple parts and the parts are closable. When the user is closing a part there should be a custom pop-up (depending on some internal part state) which is asking the user if he really wants to close the part or not.
It seems to be not that easy to implement in Eclipse RCP 4 or we have just totally overseen something.
I'll just give you a short brieifing about the things we tried:
Use dirtable with a #persist method in the part. Though the problem is, we don't want this standard eclipse save dialog. So is there a way to override this?
public int promptToSaveOnClose(): This seemed to be promising but not for Eclipse 4 or is there a way to integrate it that way? Compare: http://e-rcp.blogspot.de/2007/09/prevent-that-rcp-editor-is-closed.html
Our last try was to integrate a custom part listener, simple example shown in the following:
partService.addPartListener(new IPartListener() {
public void partVisible(MPart part) {
}
public void partHidden(MPart part) {
partService.showPart(part, PartState.ACTIVATE);
}
public void partDeactivated(MPart part) {
}
public void partBroughtToTop(MPart part) {
}
public void partActivated(MPart part) {
}
});
The problem with this was we are running into a continuous loop. Something similar is posted over here in the last comment: Detect tab close in Eclipse editor
So I could write some more about this problem, but I think that's enough for the moment. If you need some more input just give me a hint.
Thanks for helping.
The save prompt is generated by the ISaveHandler registered in the context of the MWindow containing the MPart. You can write your own ISaveHandler and set it in the window context to replace the default.
You might also want to look at the IWindowCloseHandler also in the window context.
Thanks greg, this has helped and I was able to achieve changing the pop-up when the user closes a part. Here's a short description of what I've done:
Use the MDirtyable for marking the part as dirty whenever it's needed.
Create a custom save handler which implements ISaveHandler (when a part got closed the save method is called). Add the additional logic to this handler (e.g. a custom message dialog)
Register this handler at application start-up (I just chose a method which is called at the start-up):
#Inject
private MWindow window;
...
ISaveHandler saveHandler = new CustomSaveHandler(shell);
window.getContext().set(ISaveHandler.class, saveHandler);
Note that the registration via a model processor was sadly not that easy because the model processor is called too early. (Take a look at: http://www.eclipse.org/forums/index.php/t/369989/)
The IWindowCloseHandler is just needed when the complete window is closed, though this was not an requirement for us :).

How to insert main method in Netbeans (shortcut)

Sometimes you would like to run a single file to test some code quickly. Typing in public static void main(String[] args) { each time is tedious. How to do it quicker?
Thanks to predefined code templates in Netbeans it's simple:
just type psvm and press Tab.
psvm is an acronym for: public static void main
"psvm" is not the most intuitive abbreviation I can think of when I want to quickly insert a main method, so I created a new one more to my liking in the Code Templates library.
"main" seemed to be more natural for me, and since there's nothing else like it in the list of templates, I used it as an abbreviation and copied the same code from "psvm" in.
Now when I type "main" + TAB (without the quotes of course) I get my main method.
It is redundant, but more intuitive for me.
To create "main" go to Tools->Options, click the "Editor" Icon, then the "Code Templates" tab.
Make sure that the "Language" combo is set to "Java"
Click the "New" button that's to the right of the "Templates" window
Enter "main" (without quotes) in the "Abbreviation" textbox that pops up
Enter the template code in the "Expanded Text" window below
my entry looks like this:
Abbreviation
main
Expanded Text
public static void main(String[] args) {$cursor}
Expanded Text (Code Window)
public static void main(String[] args) {
${cursor}
}
Of course, you can always have Netbeans create your application's main class with the main method inserted by default.
You do that by Choosing "Java Main Class" from the "New File" dialog instead of "Java Class". That will do it.
Cheers!
If you want to just run some test why not use your testing framework?
like JUnit:
#Test
public void test() {
// do something
}
This way you can even store the test for later usage.
It is properbly in most cases not a good idear to think of tests as something to execute once and then throw away.

Open and maximise a browser window in OATS Java (not javascript)

I am a tester and just installed oracle application test suite to use testing eBus apps
Anyway the only language it supports for coding test scripts (I don't want to use the recorder for a number of reasons). The problem I am having is that everything I search or google is javascript not java (even googling with -script I still ended up looking at javascript. This just gets rejected by the oats editor
The only other examples I have seen, appear to be defining a variable then setting the value of that variable as the window they want to maximize. Aside from the fact that my java skills are not up to doing that - I do not need to do this for a newly opened browser window do I? (The assumption is that this will be the only browser window open (ie test is executed with browser closed)
Is there any easy way to do this?
Below is the very simple initiate of the browser which is generated from a recording plus part of the first step which loads the url the test starts at: (I realize the first step is not complete below -I didn't paste it all, just enough to hopefully allow someone to show me what I need to edit to force the browser to load maximized, or maximize it immediately after loading?
public void initialize() throws Exception {
browser.launch();
}
/**
* Add code to be executed each iteration for this virtual user.
*/
public void run() throws Exception {
beginStep("[1] Login (/RF.jsp)", 0);
{
web
.window(2,
"/web:window[#index='0' or #title='about:blank']")
.navigate(
"http://somepageiwantolaunch");
web.window(4, "/web:window[#index='0' or #title='Login']")
.waitForPage(null);
I am not sure whether you already got the answer for this.. if not this code should help you
browser.launch();
DOMBrowser currentExecutionBrowser = web.window("/web:window[#index='0' or #index='1']");
currentExecutionBrowser.maximize();
Let me know if this helps!
There is a function in the Oracle Functional Tester API Reference which has a build in function called object.WindowState It says you can get or set using this function and it has values
0 - Normal, 1- minimized and 2-maximised.
Only issue is that these examples look more like VB than Javascript but presumably there is a similar function built into to the Oracle libraries for Java.
I did a quick search for Oracle Openscript API and came up with this link which asks for the same thing. They suggest using Help->Search from within the openscript application and then searching for "openscript API" which should provide a list of the functions available.
Hope that helps.
To Maximize browser in OATS, follow the below code
Open script ha in built methods which helps coding easy
browser.launch();
web.window(12, "/web:window[#index='0' or #title='about:blank']").navigate("http://www.google.com/");
web.window(12, "/web:window[#index='0' or #title='about:blank']").maximize();
for more OATS Tips/Tricks follow here
http://www.testinghive.com/category/oracle-application-testing-suite-tips
If it is the only browser window open, you can use the below code. It must be used with caution since the code maximizes any window that is open above the browser window.
try {
Robot a = new Robot();
a.keyPress(KeyEvent.VK_ALT);
a.keyPress(KeyEvent.VK_SPACE);
a.keyRelease(KeyEvent.VK_SPACE);
a.keyRelease(KeyEvent.VK_ALT);
a.keyPress(KeyEvent.VK_X);
a.keyRelease(KeyEvent.VK_X);
} catch (AWTException e) {
}

Categories