org.japura.controller
Class Controller<V extends java.awt.Component>

java.lang.Object
  extended by org.japura.controller.AbstractController
      extended by org.japura.controller.Controller<V>
All Implemented Interfaces:
ControllerModel

public abstract class Controller<V extends java.awt.Component>
extends AbstractController

The Controller isolates business logic from presentation.

Must implement the following methods:

Every instantiated controller is added to a pool of controllers. Through the pool, its possible reach any controller.

The state of permanent indicates that the controller can't be removed from the pool unless the parent has been removed.

Annotations:

Copyright (C) 2009-2012 Carlos Eduardo Leite de Andrade

This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see www.gnu.org/licenses/

For more information, contact: www.japura.org

E

Author:
Carlos Eduardo Leite de Andrade

Nested Class Summary
 
Nested classes/interfaces inherited from class org.japura.controller.AbstractController
AbstractController.TokenKey
 
Constructor Summary
Controller()
           
 
Method Summary
 void addModal(java.awt.Component component)
          Shows a modal
 void addModal(java.awt.Component component, ModalListener listener)
           
 void addModal(java.awt.Component component, ModalListener listener, java.lang.Integer modalDepth)
           
protected  void afterFreeController()
           
protected  void beforeFreeController()
           
protected  void cancelExecutions()
          Cancels all task executions from the controllers of the group
 void closeAllModals()
          Close all modals.
 void closeCurrentModal()
          Close the current modal.
 void closeModal(java.awt.Component component)
          Close a modal
static boolean contains(ControllerModel controller)
           
static int count(java.lang.Class<?> clss)
          Get the total of controllers of a specific class.
static DebugComponent createDebugPanel()
           
protected  void execute(Task<?> task)
           
protected  void execute(Task<?> task, boolean isAsynchronous)
           
protected  void execute(Task<?> task, boolean isAsynchronous, java.lang.String message)
           
protected  void execute(Task<?> task, java.lang.String message)
          Executes a task
protected  void execute(TaskSequence taskSequence)
           
protected  void executeAndFree(Task<?> task)
           
protected  void executeAndFree(Task<?> task, java.lang.String message)
           
static boolean existsLink(ControllerModel controller, java.lang.Class<?> clss)
           
static boolean existsLink(ControllerModel controller1, ControllerModel controller2)
           
static void free(int id)
          Remove a controller from the memory.
static void free(int id, boolean cancelTaskExecution)
          Remove a controller from the memory.
 void freeAfterExecutions()
          Removes the controller from the memory after the all task executions.
static void freeAll()
          Remove from the memory all controllers.
static void freeAll(java.lang.Class<?> clss)
          Remove from the memory all controllers of a specific class.
static void freeAllFromGroup(int groupId, java.lang.Class<?> clss)
          Remove from the memory all controllers of a specific class and group.
static void freeGroup(int groupdId)
          Remove from the memory all controllers of a specific group.
static
<E> E
get(java.lang.Class<E> clss)
          Get the first controller of a specific class.
static
<E> E
get(java.lang.Class<E> clss, java.awt.Component comp)
          Get the first controller of a specific class and controlled component.
static ControllerModel get(java.awt.Component comp)
          Get the first controller of a specific controlled component.
static ControllerModel get(int id)
          Get the controller with a specific identifier.
static
<E> E
get(int id, java.lang.Class<E> clss)
          Get the controller of a specific class and identifier.
static java.util.List<ControllerModel> getAll()
          Get all controllers
static
<E> java.util.List<E>
getAll(java.lang.Class<E> clss)
          Get all controllers of a specific class.
static java.util.List<ControllerModel> getAllFromGroup(int groupId)
          Get the all controllers of a specific group.
static
<E> java.util.List<E>
getAllFromGroup(int groupId, java.lang.Class<E> clss)
          Get the all controllers of a specific group and class.
protected abstract  V getComponent()
          Get the controlled component.
 java.awt.Component getCurrentModal()
          Get the current modal component
static
<E> E
getFromGroup(int groupId, java.lang.Class<E> clss)
          Get the controller of a specific group and class.
static ControllerModel getFromGroup(int groupId, int id)
          Get the controller of a specific group and identifier.
static
<E> E
getFromGroup(int groupId, int id, java.lang.Class<E> clss)
          Get the controller of a specific group, class and identifier.
static
<E> E
getFromLink(ControllerModel controllerInLink, java.lang.Class<E> clss)
           
static MockPool getMockPool()
           
static ModalPanelFactory getModalPanelFactory()
           
static ControllerModel getRoot(int groupId)
           
 java.awt.Window getWindowAncestor()
           
static boolean hasMockPool()
           
 boolean hasModal()
          Indicates whether exists a modal.
 boolean isFocused()
           
static boolean isInstancied(java.lang.Class<?> clss)
          Indicates whether the controller is instantiated.
static boolean isInstanciedInGroup(int groupId, java.lang.Class<?> clss)
          Indicates whether the controller is instantiated in a group.
 boolean isWindowFocused()
           
static void link(ControllerModel controller1, ControllerModel controller2)
          Link two controllers each other.
static MockPool newMockPool()
           
static void printAllControllers()
          Show all the instantiated controllers in the pool.
static void publishToAll(Message message)
           
static void removeMockPool()
           
 void requestFocus()
           
 void requestWindowFocus()
           
static void setModalPanelFactory(ModalPanelFactory modalPanelFactory)
           
 void showConfirmationModal(java.lang.String title, java.lang.String question, ModalAction confirmAction)
          Shows a confirmation message modal.
 void showConfirmationModal(java.lang.String title, java.lang.String question, ModalAction confirmAction, ModalAction cancelAction)
          Shows a confirmation message modal.
static void showDebugWindow()
           
 void showErrorModal(java.lang.String title, java.lang.String error)
          Shows a error message modal.
 void showInformationModal(java.lang.String title, java.lang.String info)
          Shows a information message modal.
 void showQuestionModal(java.lang.String title, java.lang.String question, ModalAction yesAction)
          Shows a question message modal.
 void showQuestionModal(java.lang.String title, java.lang.String question, ModalAction yesAction, ModalAction noAction)
          Shows a question message modal.
 void showWarningModal(java.lang.String title, java.lang.String warning)
          Shows a warning message modal.
static void unlink(ControllerModel controller)
           
static void unlink(ControllerModel controller1, ControllerModel controller2)
           
static void updateDebugComponents()
           
 
Methods inherited from class org.japura.controller.AbstractController
addMessageFilter, canExecute, containsMessageFilter, createChild, equals, free, free, freeGroup, getChild, getChild, getChildren, getChildren, getControllerName, getFromLink, getGroup, getGroupId, getId, getMessageFilters, getModalGroupName, getParent, getParentId, getRoot, hashCode, hasLinkTo, hasLinkTo, isChildInstancied, isPermanent, isRemoved, isRoot, linkTo, publish, removeMessageFilter, removeMessageFilters, setControllerName, setModalGroupName, setPermanent, stringToDebugComponent, subscribe, testControllerModel, unlink
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.japura.controller.ControllerModel
isComponentInstancied
 

Constructor Detail

Controller

public Controller()
Method Detail

hasMockPool

public static boolean hasMockPool()

newMockPool

public static MockPool newMockPool()

removeMockPool

public static void removeMockPool()

getMockPool

public static MockPool getMockPool()

existsLink

public static boolean existsLink(ControllerModel controller1,
                                 ControllerModel controller2)

existsLink

public static boolean existsLink(ControllerModel controller,
                                 java.lang.Class<?> clss)

link

public static void link(ControllerModel controller1,
                        ControllerModel controller2)
Link two controllers each other.

The link is undone when one of the controllers is disposed.

Parameters:
controller1 - first controller
controller2 - second controller

unlink

public static void unlink(ControllerModel controller1,
                          ControllerModel controller2)

createDebugPanel

public static DebugComponent createDebugPanel()

showDebugWindow

public static void showDebugWindow()

free

public static void free(int id)
Remove a controller from the memory.

Controllers defined as permanent, can not be removed unless the parent has been removed.

All executions of the tasks will be canceled.

Parameters:
id - the controller's identifier
See Also:
AbstractController.setPermanent(boolean), AbstractController.isPermanent(), freeAll(), freeAll(Class)

free

public static void free(int id,
                        boolean cancelTaskExecution)
Remove a controller from the memory.

Controllers defined as permanent, can not be removed unless the parent has been removed.

Parameters:
id - the controller's identifier
cancelTaskExecution -
See Also:
AbstractController.setPermanent(boolean), AbstractController.isPermanent(), freeAll(), freeAll(Class)

freeGroup

public static void freeGroup(int groupdId)
Remove from the memory all controllers of a specific group.

Controllers defined as permanent, can not be removed unless the parent has been removed.

All executions of the tasks will be canceled.

Parameters:
groupdId -
See Also:
AbstractController.setPermanent(boolean), AbstractController.isPermanent(), free(int)

freeAll

public static void freeAll(java.lang.Class<?> clss)
Remove from the memory all controllers of a specific class.

Controllers defined as permanent, can not be removed unless the parent has been removed.

All executions of the tasks will be canceled.

Parameters:
clss - controller's class
See Also:
AbstractController.setPermanent(boolean), AbstractController.isPermanent(), free(int)

freeAllFromGroup

public static void freeAllFromGroup(int groupId,
                                    java.lang.Class<?> clss)
Remove from the memory all controllers of a specific class and group.

Controllers defined as permanent, can not be removed unless the parent has been removed.

All executions of the tasks will be canceled.

Parameters:
groupId -
clss - controller's class
See Also:
AbstractController.setPermanent(boolean), AbstractController.isPermanent(), free(int)

isInstancied

public static boolean isInstancied(java.lang.Class<?> clss)
Indicates whether the controller is instantiated.

Parameters:
clss - controller's class
Returns:
boolean

isInstanciedInGroup

public static boolean isInstanciedInGroup(int groupId,
                                          java.lang.Class<?> clss)
Indicates whether the controller is instantiated in a group.

Parameters:
groupId -
clss - controller's class
Returns:
boolean

freeAll

public static void freeAll()
Remove from the memory all controllers.

Controllers defined as permanent, can not be removed unless the parent has been removed.

All executions of the tasks will be canceled.

See Also:
AbstractController.setPermanent(boolean), AbstractController.isPermanent(), free(int), freeAll(Class)

count

public static int count(java.lang.Class<?> clss)
Get the total of controllers of a specific class.

Parameters:
clss - the controller's class
Returns:
the total of controllers

get

public static <E> E get(java.lang.Class<E> clss)
Get the first controller of a specific class.

If not exists, a controller will be instantiated.

Type Parameters:
E - .
Parameters:
clss - the controller's class
Returns:
the controller
See Also:
get(int, Class)

get

public static <E> E get(int id,
                        java.lang.Class<E> clss)
Get the controller of a specific class and identifier.

Parameters:
id - the controller's identifier
clss - the controller's class
Returns:
the controller or NULL if its not exist.
See Also:
get(Class)

getFromGroup

public static <E> E getFromGroup(int groupId,
                                 java.lang.Class<E> clss)
Get the controller of a specific group and class.

Parameters:
groupId - the controller's group identifier
clss - the controller's class
Returns:
the controller or NULL if its not exist.

getFromGroup

public static <E> E getFromGroup(int groupId,
                                 int id,
                                 java.lang.Class<E> clss)
Get the controller of a specific group, class and identifier.

Parameters:
groupId - the controller's group identifier
id - the controller's identifier
clss - the controller's class
Returns:
the controller or NULL if its not exist.

getFromGroup

public static ControllerModel getFromGroup(int groupId,
                                           int id)
Get the controller of a specific group and identifier.

Parameters:
groupId - the controller's group identifier
id - the controller's identifier
Returns:
the controller or NULL if its not exist.

getAllFromGroup

public static <E> java.util.List<E> getAllFromGroup(int groupId,
                                                    java.lang.Class<E> clss)
Get the all controllers of a specific group and class.

Parameters:
groupId - the controller's group identifier
clss - the controller's class
Returns:
List with the controllers.
See Also:
get(Class)

getAllFromGroup

public static java.util.List<ControllerModel> getAllFromGroup(int groupId)
Get the all controllers of a specific group.

Parameters:
groupId - the controller's group identifier
Returns:
List with the controllers.
See Also:
get(Class)

get

public static ControllerModel get(int id)
Get the controller with a specific identifier.

Parameters:
id - the controller's identifier
Returns:
the controller or NULL if its not exist.

getAll

public static <E> java.util.List<E> getAll(java.lang.Class<E> clss)
Get all controllers of a specific class.

Parameters:
clss - the controller's class
Returns:
List with the controllers

getAll

public static java.util.List<ControllerModel> getAll()
Get all controllers

Returns:
List with all controllers

get

public static <E> E get(java.lang.Class<E> clss,
                        java.awt.Component comp)
Get the first controller of a specific class and controlled component.

Type Parameters:
E - .
Parameters:
clss - the controller's class
comp - the controlled component
Returns:
the controller or NULL if its not exist.
See Also:
get(Class), get(int)

get

public static ControllerModel get(java.awt.Component comp)
Get the first controller of a specific controlled component.

Parameters:
comp - the controlled component
Returns:
the controller or NULL if its not exist.
See Also:
get(Class), get(int)

setModalPanelFactory

public static void setModalPanelFactory(ModalPanelFactory modalPanelFactory)

getModalPanelFactory

public static ModalPanelFactory getModalPanelFactory()

contains

public static boolean contains(ControllerModel controller)

printAllControllers

public static void printAllControllers()
Show all the instantiated controllers in the pool.


getRoot

public static ControllerModel getRoot(int groupId)

updateDebugComponents

public static void updateDebugComponents()

unlink

public static void unlink(ControllerModel controller)

getFromLink

public static <E> E getFromLink(ControllerModel controllerInLink,
                                java.lang.Class<E> clss)

publishToAll

public static void publishToAll(Message message)

beforeFreeController

protected void beforeFreeController()
Overrides:
beforeFreeController in class AbstractController

afterFreeController

protected void afterFreeController()
Overrides:
afterFreeController in class AbstractController

getWindowAncestor

public java.awt.Window getWindowAncestor()

requestWindowFocus

public void requestWindowFocus()

isWindowFocused

public boolean isWindowFocused()

requestFocus

public void requestFocus()

isFocused

public boolean isFocused()

getComponent

protected abstract V getComponent()
Get the controlled component.

Returns:
V the component

freeAfterExecutions

public final void freeAfterExecutions()
Removes the controller from the memory after the all task executions.

See Also:
free(int), freeAll(), freeAll(Class), beforeFreeController(), afterFreeController()

showQuestionModal

public void showQuestionModal(java.lang.String title,
                              java.lang.String question,
                              ModalAction yesAction,
                              ModalAction noAction)
Shows a question message modal.

Parameters:
title - title for the modal
question - the question
yesAction - action for the confirmation button
noAction - action for the cancel button
See Also:
setModalPanelFactory(ModalPanelFactory)

showQuestionModal

public void showQuestionModal(java.lang.String title,
                              java.lang.String question,
                              ModalAction yesAction)
Shows a question message modal.

The cancel button just close the modal.

Parameters:
title - title for the modal
question - the question
yesAction - action for the confirmation button
See Also:
setModalPanelFactory(ModalPanelFactory)

showConfirmationModal

public void showConfirmationModal(java.lang.String title,
                                  java.lang.String question,
                                  ModalAction confirmAction,
                                  ModalAction cancelAction)
Shows a confirmation message modal.

Parameters:
title - title for the modal
question - the question
confirmAction - action for the confirmation button
cancelAction - action for the cancel button
See Also:
setModalPanelFactory(ModalPanelFactory)

showConfirmationModal

public void showConfirmationModal(java.lang.String title,
                                  java.lang.String question,
                                  ModalAction confirmAction)
Shows a confirmation message modal.

The cancel button just close the modal.

Parameters:
title - title for the modal
question - the question
confirmAction - action for the confirmation button
See Also:
setModalPanelFactory(ModalPanelFactory)

showInformationModal

public void showInformationModal(java.lang.String title,
                                 java.lang.String info)
Shows a information message modal.

Parameters:
title - title for the modal
info - the information
See Also:
setModalPanelFactory(ModalPanelFactory)

showWarningModal

public void showWarningModal(java.lang.String title,
                             java.lang.String warning)
Shows a warning message modal.

Parameters:
title - title for the modal
warning - the warning
See Also:
setModalPanelFactory(ModalPanelFactory)

showErrorModal

public void showErrorModal(java.lang.String title,
                           java.lang.String error)
Shows a error message modal.

Parameters:
title - title for the modal
error - the error
See Also:
setModalPanelFactory(ModalPanelFactory)

addModal

public void addModal(java.awt.Component component)
Description copied from interface: ControllerModel
Shows a modal

Parameters:
component - Component

addModal

public void addModal(java.awt.Component component,
                     ModalListener listener)

addModal

public void addModal(java.awt.Component component,
                     ModalListener listener,
                     java.lang.Integer modalDepth)

getCurrentModal

public java.awt.Component getCurrentModal()
Get the current modal component

Returns:
Component

closeCurrentModal

public void closeCurrentModal()
Close the current modal.


closeModal

public void closeModal(java.awt.Component component)
Description copied from interface: ControllerModel
Close a modal

Parameters:
component - the component's modal

closeAllModals

public void closeAllModals()
Description copied from interface: ControllerModel
Close all modals.


hasModal

public boolean hasModal()
Description copied from interface: ControllerModel
Indicates whether exists a modal.

Returns:
boolean

execute

protected void execute(Task<?> task,
                       java.lang.String message)
Executes a task

Parameters:
task - the task
message - message for the task
See Also:
TaskManagerListener

execute

protected void execute(Task<?> task)

execute

protected void execute(Task<?> task,
                       boolean isAsynchronous,
                       java.lang.String message)

execute

protected void execute(Task<?> task,
                       boolean isAsynchronous)

execute

protected void execute(TaskSequence taskSequence)

executeAndFree

protected void executeAndFree(Task<?> task,
                              java.lang.String message)

executeAndFree

protected void executeAndFree(Task<?> task)

cancelExecutions

protected void cancelExecutions()
Cancels all task executions from the controllers of the group

See Also:
execute(Task), execute(Task, String), executeAndFree(Task), executeAndFree(Task, String)