Changes

Jump to: navigation, search

Teams Winter 2011/team2/lab3

1,963 bytes added, 12:40, 21 March 2011
no edit summary
==Creating and Using Commands==
*Commands are in the most lamen laymen terms, actions. What we mean by action is that we are insisting through some physical representation, whether it be a button or plain-typed text, we are calling an event. That event can be to exit the program or even perform a feature within the application.
*Let's create our first menu for the menu bar that will contain a command to exit the application.
*First open the file plugin.xml, click on the tab "Extensions", and then click on the "Add" button.
*This should pop up another window containing every package (including default and empty) available within the project. Double-click "ecl.team2.lab3.commands", this should enter automatically to the text box that dictates where you want the class to be stored.
[[File:Njwin2T2.png]]
*After completing the previous step, you will be back on the previous window (New Java Class). Since we require this java class to be used for a command, we must have this class inherit from the AbstractHandler class.We do this by clicking the "Browse..." button under the "Superclass" category.*A window to select your superclass appears. In the textbox, please enter "AbstractHandler". The textbox provides a means of searching for a particular class. From the search results, select the "AbstractHandler" that's located in "org.eclipse.core.commands". The reason for selecting this specific class is because it is the most up-to-date standard for creating handlers.[[File:ScT2.png]]*To ensure we include all methods necessary for our handler to function properly, we will now add an interface called "IHandler". Click the button "Add" near "Interfaces" category. The process of adding an interface is very similar to adding a superclass except we must highlight the interface we want, click add (clicking add allows you to create a list of interfaces to included in your application), and then click okay. After searching for "IHandler", ensure the interface is located in "org.eclipse.core.commands".*You are now back to your original window. As you may have noticed, you still cannot create the class. The reason is incredibly quite simple, you haven't named the class yet. Next to name, enter the following in the textbox "PrintWeather". You should have something that looks like the image below:[[File:Classl3-2T2.png]]*The java file is now in your editor and will contain something like this:<source lang=java>package ecl.team2.lab3.commands; import org.eclipse.core.commands.AbstractHandler;import org.eclipse.core.commands.ExecutionEvent;import org.eclipse.core.commands.ExecutionException;import org.eclipse.core.commands.IHandler; public class PrintWeather extends AbstractHandler implements IHandler {  @Override public Object execute(ExecutionEvent event) throws ExecutionException { // TODO Auto-generated method stub return null; } }</source>*We will now change this to the snippet code below.<source lang=java> </source>
1
edit

Navigation menu