All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.gluebooster.java.booster.basic.mvc.AppDefinition Maven / Gradle / Ivy

package net.sf.gluebooster.java.booster.basic.mvc;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;

import javax.swing.tree.DefaultMutableTreeNode;

import net.sf.gluebooster.java.booster.basic.gui.UserInteraction;
import net.sf.gluebooster.java.booster.essentials.eventsCommands.Callable;
import net.sf.gluebooster.java.booster.essentials.meta.objects.ObjectDescription;

/**
 * Basic definition of an application. Defines general commands, fields, commandHandler, etc. of an application.
 * 
 * TODO: Refactor this class into the corresponding models.
 * 
 * @author cbauer
 *
 */
public class AppDefinition {

	/**
	 * The command to set the controller (of a view).
	 */
	public static final String COMMAND_SET_CONTROLLER = "set controller";

	/**
	 * The command to return the model (without doing something)
	 */
	// public static final String COMMAND_GET_MODEL = "get model";

	/**
	 * The command to load the configuration of the app.
	 */
	public static final String COMMAND_LOAD_CONFIGURATION = "load configuration";

	/**
	 * The command to save the configuration of the app.
	 */
	public static final String COMMAND_SAVE_CONFIGURATION = "save configuration";

	/**
	 * The command to edit the configuration of the app.
	 */
	public static final String COMMAND_EDIT_CONFIGURATION = "edit configuration";

	/**
	 * The command that the configuration of the app has been edited.
	 */
	public static final String COMMAND_EDITED_CONFIGURATION = "edited configuration";

	/**
	 * The name of the field that contains the title of the application
	 */
	public static final String FIELD_TITLE = "title";

	/**
	 * The key to get the user interaction handler.
	 */
	public static final Class USER_INTERACTION = UserInteraction.class;

	/**
	 * The key to get the command handler. The command handler may differ depending on the layer of the application.
	 */
	public static final Class COMMAND_HANDLER = Callable.class;

	/**
	 * The key to the configuration (editable, loadable, saveable) of the application
	 */
	// public static final Class CONFIGURATION = Configuration.class;

	/**
	 * The name of the flag in the display model that display the configuration dialog.
	 */
	public static final String DIALOG_DISPLAY_CONFIGURATION = "Display configuration dialog";

	/**
	 * The title of the application.
	 */
	private String title;

	/**
	 * Fields used for configuration of the app. The fields are ordered, so that a layout can be created automatically. The fields are ordered into a tree. This
	 * method returns the root of the tree. The userObjects are ObjectDescription. If the root node has no user object, it probably will not be displayed.
	 * 
	 */
	private DefaultMutableTreeNode configuration;

	public DefaultMutableTreeNode getConfiguration() {
		return configuration;
	}

	public void setConfiguration(DefaultMutableTreeNode configurationFields) {
		this.configuration = configurationFields;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * Gets the fields used for configuration.
	 * 
	 * @return the user objects of the object descriptions of the fields
	 */
	public Collection getConfigurationFields() {
		ArrayList result = new ArrayList<>();
		Enumeration enumeration = configuration.breadthFirstEnumeration();
		while (enumeration.hasMoreElements()) {
			DefaultMutableTreeNode node = enumeration.nextElement();
			ObjectDescription field = (ObjectDescription) node.getUserObject();
			// field may be null at the root, then it is ignored
			if (field != null) {
				result.add(field);
			}
		}
		return result;
	}

}