Application Development in WebOS

4812 단어 UImvcOSgwtwebos
Develop applications in WebOS

Recognize the abstract class Application
The operating system accepts classes that implement Application,
Install the application by calling the install() method
Call the uninstall() method to uninstall the application

package com.single.os.core.client;


public abstract class Application {
	
	protected boolean installed=false;
	protected String prefix;
	
	public String getPrefix() {
		return prefix;
	}


	public Application(String prefix){
		this.prefix=prefix;
	}
	
	
	public boolean isInstalled() {
		return installed;
	}
	/**
	 *  
	 * @return
	 */
	abstract boolean install();
	/**
	 *  
	 * @return
	 */
	abstract boolean uninstall();
}

For simple applications we provide the SimpleApplication class
It includes several main properties,
Includes controller, program menu items, command set
You just need to create a class extending SimpleApplication
Override the initial() method, assign controller, appMenuItem and add commands using the addCommand method.
The controller is the controller. To use this object, you need to understand the MVC architecture of GXT first.
appMenuItem is your program menu, which will be added to: Start -> Programs.
The addCommand method is to register your command in the system. For details, please refer to the related articles introduced by Command.

package com.single.os.core.client;

import java.util.HashMap;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.widget.menu.MenuItem;
import com.single.os.core.client.ui.desktop.Desktop;

public class SimpleApplication extends Application{

	public SimpleApplication(String prefix) {
		super(prefix);
	}
	private static int increase=1;
	protected String baseStyle="module"+increase++;
	/**
	 *  
	 */
	protected Controller controller;
	/**
	 *  -> -> 
	 */
	protected MenuItem appMenuItem;
	/**
	 *  
	 */
	private HashMap<String, CommandExecute> commands=new HashMap<String, CommandExecute>();

	public void addCommand(String command,CommandExecute execute){
		commands.put(command, execute);
	}
	// , 
	protected void initial(){
		
	}
	@Override
	boolean install() {
		
		if(installed){
			return false;
		}
		
		initial();
		
		// 
		if(controller!=null){
			Dispatcher.get().addController(controller);
		}
		// 
		if(appMenuItem!=null){
			Desktop desktop=Registry.get(OS.DESKTOP);
			desktop.getStartMenu().addApplicationMenuItem(appMenuItem);
		}
		// 
		if(commands.size()>0){
			for(String command:commands.keySet()){
				CommandCollection.add(command, commands.get(command));
			}
		}
		
		installed=true;
		
		return true;
	}
	@Override
	boolean uninstall() {
		if(!installed){
			return false;
		}
		// 
		if(controller!=null){
			Dispatcher.get().removeController(controller);
		}
		// 
		if(commands.size()>0){
			for(String command:commands.keySet()){
				CommandCollection.remove(command);
			}
		}
		
		installed=false;
		
		return true;
	}
	
}

You can build a class YourApplication that extends SimpleApplication
Then after setting the relevant content in the initial() method,
Add the application to the OS system

OS.addApplication(new YourApplication());


How to create a well-formed application
A well-formed application means that the program is independent, has a good degree of modularity, and has simple and clear dependencies.
That is, as long as someone inherits your module in gwt.xml, your system can automatically install and take effect.

Generally, one application corresponds to one module.
Create a new module, and then create an entry EntryPoint for the module
The method onMouldeLoad is the method that will be called when the program enters your module.
You can initialize your module or application here.
For example, create your own Application,
Then call OS.addApplication(new YourApplication());
Add your application to the system.

좋은 웹페이지 즐겨찾기