|
|
|
|
@ -12,9 +12,12 @@ import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Queue;
|
|
|
|
|
|
|
|
|
|
import javax.swing.DefaultListSelectionModel;
|
|
|
|
|
import javax.swing.JButton;
|
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
@ -56,7 +59,7 @@ public class SIPRPWindow extends JFrame implements TrackableWindow, ListSelectio
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
String onSelect();
|
|
|
|
|
String [] onSelect();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Array of actions to execute when a change is listened in this
|
|
|
|
|
@ -64,7 +67,7 @@ public class SIPRPWindow extends JFrame implements TrackableWindow, ListSelectio
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
String onChange();
|
|
|
|
|
String [] onChange();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -110,8 +113,8 @@ public class SIPRPWindow extends JFrame implements TrackableWindow, ListSelectio
|
|
|
|
|
/**
|
|
|
|
|
* Fields
|
|
|
|
|
*/
|
|
|
|
|
private Map<String, Object> mapWindowOnSelectFieldByActionName = new HashMap<String, Object>();
|
|
|
|
|
private Map<String, Object> mapWindowOnChangeFieldByActionName = new HashMap<String, Object>();
|
|
|
|
|
private Map<String, List<Object>> mapWindowOnSelectFieldByActionName = new HashMap<String, List<Object>>();
|
|
|
|
|
private Map<String, List<Object>> mapWindowOnChangeFieldByActionName = new HashMap<String, List<Object>>();
|
|
|
|
|
private Map<String, Field> mapLeafObjectByActionName = new HashMap<String, Field>();
|
|
|
|
|
private Map<Field, Object> mapInstanceByField = new HashMap<Field, Object>();
|
|
|
|
|
|
|
|
|
|
@ -126,6 +129,11 @@ public class SIPRPWindow extends JFrame implements TrackableWindow, ListSelectio
|
|
|
|
|
* Meta-info
|
|
|
|
|
*/
|
|
|
|
|
private Map<Object, Annotation> mapAnnotationByObject = new HashMap<Object, Annotation>();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Run later actions
|
|
|
|
|
*/
|
|
|
|
|
private Queue<String> listRunLater = new LinkedList<String>();
|
|
|
|
|
|
|
|
|
|
public SIPRPWindow(SIPRPLogic logicController) throws IllegalArgumentException, IllegalAccessException
|
|
|
|
|
{
|
|
|
|
|
@ -180,6 +188,8 @@ public class SIPRPWindow extends JFrame implements TrackableWindow, ListSelectio
|
|
|
|
|
{
|
|
|
|
|
mapActionByName.put( value, action );
|
|
|
|
|
mapWindowMethodsByActionName.put( value, new ArrayList<Method>() );
|
|
|
|
|
mapWindowOnSelectFieldByActionName.put( value, new ArrayList<Object>() );
|
|
|
|
|
mapWindowOnChangeFieldByActionName.put( value, new ArrayList<Object>() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -194,36 +204,43 @@ public class SIPRPWindow extends JFrame implements TrackableWindow, ListSelectio
|
|
|
|
|
ActionActivation componentBehaviour = field.getAnnotation( ActionActivation.class );
|
|
|
|
|
if( componentBehaviour != null )
|
|
|
|
|
{
|
|
|
|
|
String onChange = componentBehaviour.onChange();
|
|
|
|
|
// if( onChange != null )
|
|
|
|
|
// {
|
|
|
|
|
// for( String currentOnChange : onChange )
|
|
|
|
|
// {
|
|
|
|
|
if( mapActionByName.containsKey( onChange ) )
|
|
|
|
|
String[] allChanges = componentBehaviour.onChange();
|
|
|
|
|
if( allChanges != null )
|
|
|
|
|
{
|
|
|
|
|
// valid action
|
|
|
|
|
mapAnnotationByObject.put( field.get( instance ), componentBehaviour );
|
|
|
|
|
mapWindowOnChangeFieldByActionName.put( onChange, field.get( instance ) );
|
|
|
|
|
mapInstanceByField.put( field, instance );
|
|
|
|
|
addListenerForField( componentBehaviour, field, instance );
|
|
|
|
|
for( String onChange : allChanges )
|
|
|
|
|
{
|
|
|
|
|
if( mapActionByName.containsKey( onChange ) )
|
|
|
|
|
{
|
|
|
|
|
// valid action
|
|
|
|
|
mapAnnotationByObject.put( field.get( instance ), componentBehaviour );
|
|
|
|
|
mapWindowOnChangeFieldByActionName.get( onChange ).add( field.get( instance ) );
|
|
|
|
|
if(!mapInstanceByField.containsKey( field ))
|
|
|
|
|
{
|
|
|
|
|
addListenerForField( componentBehaviour, field, instance );
|
|
|
|
|
mapInstanceByField.put( field, instance );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
String onSelect = componentBehaviour.onSelect();
|
|
|
|
|
// if( onSelect != null )
|
|
|
|
|
// {
|
|
|
|
|
// for( String currentOnSelect : onSelect )
|
|
|
|
|
// {
|
|
|
|
|
if( mapActionByName.containsKey( onSelect ) )
|
|
|
|
|
|
|
|
|
|
String[] allSelect = componentBehaviour.onSelect();
|
|
|
|
|
if( allSelect != null )
|
|
|
|
|
{
|
|
|
|
|
// valid action
|
|
|
|
|
mapAnnotationByObject.put( field.get( instance ), componentBehaviour );
|
|
|
|
|
mapWindowOnSelectFieldByActionName.put( onSelect, field.get( instance ) );
|
|
|
|
|
mapInstanceByField.put( field, instance );
|
|
|
|
|
addListenerForField( componentBehaviour, field, instance );
|
|
|
|
|
for( String onSelect : allSelect )
|
|
|
|
|
{
|
|
|
|
|
if( mapActionByName.containsKey( onSelect ) )
|
|
|
|
|
{
|
|
|
|
|
// valid action
|
|
|
|
|
mapAnnotationByObject.put( field.get( instance ), componentBehaviour );
|
|
|
|
|
mapWindowOnSelectFieldByActionName.get( onSelect ).add( field.get( instance ) );
|
|
|
|
|
if(!mapInstanceByField.containsKey( field ))
|
|
|
|
|
{
|
|
|
|
|
addListenerForField( componentBehaviour, field, instance );
|
|
|
|
|
mapInstanceByField.put( field, instance );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LeafObject leafObject = field.getAnnotation( LeafObject.class );
|
|
|
|
|
@ -275,13 +292,17 @@ public class SIPRPWindow extends JFrame implements TrackableWindow, ListSelectio
|
|
|
|
|
LeafUIActionBinding actionBinding = method.getAnnotation( LeafUIActionBinding.class );
|
|
|
|
|
if( actionBinding != null )
|
|
|
|
|
{
|
|
|
|
|
String actionName = actionBinding.action();
|
|
|
|
|
if( mapActionByName.containsKey( actionName ) )
|
|
|
|
|
String [] actions = actionBinding.action();
|
|
|
|
|
for(String actionName : actions)
|
|
|
|
|
{
|
|
|
|
|
// valid action
|
|
|
|
|
mapAnnotationByObject.put( method, actionBinding );
|
|
|
|
|
mapWindowMethodsByActionName.get( actionName ).add( method );
|
|
|
|
|
mapInstanceByMethod.put( method, instance );
|
|
|
|
|
if( mapActionByName.containsKey( actionName ) )
|
|
|
|
|
{
|
|
|
|
|
// valid action
|
|
|
|
|
mapWindowMethodsByActionName.get( actionName ).add( method );
|
|
|
|
|
|
|
|
|
|
mapAnnotationByObject.put( method, actionBinding );
|
|
|
|
|
mapInstanceByMethod.put( method, instance );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -297,10 +318,10 @@ public class SIPRPWindow extends JFrame implements TrackableWindow, ListSelectio
|
|
|
|
|
LeafLogicActionBinding actionBinding = method.getAnnotation( LeafLogicActionBinding.class );
|
|
|
|
|
if( actionBinding != null )
|
|
|
|
|
{
|
|
|
|
|
String [] actions = actionBinding.actions();
|
|
|
|
|
if( actions != null)
|
|
|
|
|
String[] actions = actionBinding.actions();
|
|
|
|
|
if( actions != null )
|
|
|
|
|
{
|
|
|
|
|
for(String actionName : actions)
|
|
|
|
|
for( String actionName : actions )
|
|
|
|
|
{
|
|
|
|
|
if( mapActionByName.containsKey( actionName ) )
|
|
|
|
|
{
|
|
|
|
|
@ -336,8 +357,8 @@ public class SIPRPWindow extends JFrame implements TrackableWindow, ListSelectio
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Object getObjectForAction(String actionName)
|
|
|
|
|
|
|
|
|
|
private Object getObjectForAction( String actionName )
|
|
|
|
|
{
|
|
|
|
|
Object result = null;
|
|
|
|
|
Field field = mapLeafObjectByActionName.get( actionName );
|
|
|
|
|
@ -358,26 +379,49 @@ public class SIPRPWindow extends JFrame implements TrackableWindow, ListSelectio
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void runAction( String actionName )
|
|
|
|
|
{
|
|
|
|
|
runAction( actionName, null );
|
|
|
|
|
runGivenAction( actionName, null );
|
|
|
|
|
runPendingActions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void runAction( String actionName, Object argument)
|
|
|
|
|
{
|
|
|
|
|
runGivenAction( actionName, argument );
|
|
|
|
|
runPendingActions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void runActionLater(String action)
|
|
|
|
|
{
|
|
|
|
|
if( action != null && mapActionByName.containsKey( action ))
|
|
|
|
|
{
|
|
|
|
|
listRunLater.add( action );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void runPendingActions()
|
|
|
|
|
{
|
|
|
|
|
while( listRunLater.size() > 0)
|
|
|
|
|
{
|
|
|
|
|
runAction( listRunLater.poll() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Executes given action
|
|
|
|
|
*/
|
|
|
|
|
public void runAction( String actionName, Object argument )
|
|
|
|
|
private void runGivenAction( String actionName, Object argument )
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Running: "+actionName);
|
|
|
|
|
System.out.println( "Running: " + actionName );
|
|
|
|
|
if( actionName != null && mapActionByName.containsKey( actionName ) )
|
|
|
|
|
{
|
|
|
|
|
Action action = mapActionByName.get( actionName );
|
|
|
|
|
if( action.isSave() )
|
|
|
|
|
{
|
|
|
|
|
Object windowArgument = getObjectForAction(actionName);
|
|
|
|
|
Object windowArgument = getObjectForAction( actionName );
|
|
|
|
|
Object logicArgument = windowArgument;
|
|
|
|
|
for( Method currentWindowMethod : mapWindowMethodsByActionName.get( actionName ) )
|
|
|
|
|
{
|
|
|
|
|
@ -517,75 +561,106 @@ public class SIPRPWindow extends JFrame implements TrackableWindow, ListSelectio
|
|
|
|
|
private Object getArgumentListSelectionEvent( String actionName, ListSelectionEvent event )
|
|
|
|
|
{
|
|
|
|
|
Object source = event.getSource();
|
|
|
|
|
Object result = null;
|
|
|
|
|
Object component = mapWindowOnSelectFieldByActionName.get( actionName );
|
|
|
|
|
if( component instanceof BaseTable && ((BaseTable) component).getSelectionModel().equals( source ) )
|
|
|
|
|
List<Object> allComponents = mapWindowOnSelectFieldByActionName.get( actionName );
|
|
|
|
|
for( Object component : allComponents )
|
|
|
|
|
{
|
|
|
|
|
int index = ((BaseTable) component).getSelectedRow();
|
|
|
|
|
if( index > -1 )
|
|
|
|
|
if( component instanceof BaseTable && ((BaseTable) component).getSelectionModel().equals( source ) )
|
|
|
|
|
{
|
|
|
|
|
TableModel model = ((BaseTable) component).getModel();
|
|
|
|
|
if( model instanceof VectorTableModel )
|
|
|
|
|
int index = ((BaseTable) component).getSelectedRow();
|
|
|
|
|
if( index > -1 )
|
|
|
|
|
{
|
|
|
|
|
result = ((ColumnizedMappable) ((VectorTableModel) model).getRowAt( index )).getID();
|
|
|
|
|
TableModel model = ((BaseTable) component).getModel();
|
|
|
|
|
if( model instanceof VectorTableModel )
|
|
|
|
|
{
|
|
|
|
|
return ((ColumnizedMappable) ((VectorTableModel) model).getRowAt( index )).getID();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getActionListSelectionEvent( ListSelectionEvent event )
|
|
|
|
|
private List<String> getActionListSelectionEvent( ListSelectionEvent event )
|
|
|
|
|
{
|
|
|
|
|
for( String actionName : mapWindowOnSelectFieldByActionName.keySet() )
|
|
|
|
|
{
|
|
|
|
|
Object component = mapWindowOnSelectFieldByActionName.get( actionName );
|
|
|
|
|
if( component != null && component instanceof BaseTable && event.getSource().equals( ((BaseTable) component).getSelectionModel() ) )
|
|
|
|
|
List<String> result = new ArrayList<String>();
|
|
|
|
|
if( event.getSource() instanceof DefaultListSelectionModel)
|
|
|
|
|
{
|
|
|
|
|
DefaultListSelectionModel model = (DefaultListSelectionModel) event.getSource();
|
|
|
|
|
BaseTable table = null;
|
|
|
|
|
for(List<Object> allComponents : mapWindowOnSelectFieldByActionName.values()){
|
|
|
|
|
// for each registered table
|
|
|
|
|
for( Object component : allComponents )
|
|
|
|
|
{
|
|
|
|
|
if( component instanceof BaseTable && ((BaseTable) component).getSelectionModel().equals( model ) )
|
|
|
|
|
{
|
|
|
|
|
table = (BaseTable) component;
|
|
|
|
|
}
|
|
|
|
|
if( table != null)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if( table != null)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Annotation an = mapAnnotationByObject.get( table );
|
|
|
|
|
if(an != null && an instanceof ActionActivation)
|
|
|
|
|
{
|
|
|
|
|
return actionName;
|
|
|
|
|
String [] actions = ((ActionActivation) an).onSelect();
|
|
|
|
|
for( String actionName : actions )
|
|
|
|
|
{
|
|
|
|
|
result.add( actionName );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// returns selected node
|
|
|
|
|
private Object getArgumentTreeSelectionEvent( String actionName, TreeSelectionEvent event )
|
|
|
|
|
{
|
|
|
|
|
Object result = null;
|
|
|
|
|
Object component = mapWindowOnSelectFieldByActionName.get( actionName );
|
|
|
|
|
if( component instanceof JTree && event.getPath() != null )
|
|
|
|
|
List<Object> components = mapWindowOnSelectFieldByActionName.get( actionName );
|
|
|
|
|
for( Object component : components )
|
|
|
|
|
{
|
|
|
|
|
Object[] nodes = event.getPath().getPath();
|
|
|
|
|
if( nodes != null && nodes.length > 0 )
|
|
|
|
|
if( component instanceof JTree && event.getPath() != null )
|
|
|
|
|
{
|
|
|
|
|
result = nodes[nodes.length - 1];
|
|
|
|
|
Object[] nodes = event.getPath().getPath();
|
|
|
|
|
if( nodes != null && nodes.length > 0 )
|
|
|
|
|
{
|
|
|
|
|
return nodes[nodes.length - 1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getActionTreeSelectionEvent( TreeSelectionEvent event )
|
|
|
|
|
private List<String> getActionTreeSelectionEvent( TreeSelectionEvent event )
|
|
|
|
|
{
|
|
|
|
|
for( String actionName : mapWindowOnSelectFieldByActionName.keySet() )
|
|
|
|
|
List<String> result = new ArrayList<String>();
|
|
|
|
|
Annotation an = mapAnnotationByObject.get( event.getSource() );
|
|
|
|
|
if(an != null && an instanceof ActionActivation)
|
|
|
|
|
{
|
|
|
|
|
Object component = mapWindowOnSelectFieldByActionName.get( actionName );
|
|
|
|
|
if( component != null && component instanceof JTree && event.getSource().equals( component ) )
|
|
|
|
|
String [] actions = ((ActionActivation) an).onSelect();
|
|
|
|
|
for( String actionName : actions )
|
|
|
|
|
{
|
|
|
|
|
return actionName;
|
|
|
|
|
result.add( actionName );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getActionActionEvent( ActionEvent event )
|
|
|
|
|
private List<String> getActionActionEvent( ActionEvent event )
|
|
|
|
|
{
|
|
|
|
|
String result = null;
|
|
|
|
|
for( String actionName : mapWindowOnSelectFieldByActionName.keySet() )
|
|
|
|
|
List<String> result = new ArrayList<String>();
|
|
|
|
|
Annotation an = mapAnnotationByObject.get( event.getSource() );
|
|
|
|
|
if(an != null && an instanceof ActionActivation)
|
|
|
|
|
{
|
|
|
|
|
Object component = mapWindowOnSelectFieldByActionName.get( actionName );
|
|
|
|
|
if( event.getSource().equals( component ) )
|
|
|
|
|
String [] actions = ((ActionActivation) an).onSelect();
|
|
|
|
|
for( String actionName : actions )
|
|
|
|
|
{
|
|
|
|
|
result = actionName;
|
|
|
|
|
break;
|
|
|
|
|
result.add( actionName );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
@ -594,9 +669,12 @@ public class SIPRPWindow extends JFrame implements TrackableWindow, ListSelectio
|
|
|
|
|
@Override
|
|
|
|
|
public void valueChanged( TreeSelectionEvent event )
|
|
|
|
|
{
|
|
|
|
|
String actionName = getActionTreeSelectionEvent( event );
|
|
|
|
|
Object argument = getArgumentTreeSelectionEvent( actionName, event );
|
|
|
|
|
runAction( actionName, argument );
|
|
|
|
|
List<String> actions= getActionTreeSelectionEvent( event );
|
|
|
|
|
for( String action : actions )
|
|
|
|
|
{
|
|
|
|
|
Object argument = getArgumentTreeSelectionEvent( action, event );
|
|
|
|
|
runAction( action, argument );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -607,16 +685,22 @@ public class SIPRPWindow extends JFrame implements TrackableWindow, ListSelectio
|
|
|
|
|
{
|
|
|
|
|
if( !event.getValueIsAdjusting() )
|
|
|
|
|
{
|
|
|
|
|
String actionName = getActionListSelectionEvent( event );
|
|
|
|
|
Object argument = getArgumentListSelectionEvent( actionName, event );
|
|
|
|
|
runAction( actionName, argument );
|
|
|
|
|
List<String> actionNames = getActionListSelectionEvent( event );
|
|
|
|
|
for( String action : actionNames )
|
|
|
|
|
{
|
|
|
|
|
Object argument = getArgumentListSelectionEvent(action, event);
|
|
|
|
|
runAction( action, argument );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed( ActionEvent event )
|
|
|
|
|
{
|
|
|
|
|
String actionName = getActionActionEvent( event );
|
|
|
|
|
runAction( actionName, null );
|
|
|
|
|
List<String> actionName = getActionActionEvent( event );
|
|
|
|
|
for( String action : actionName )
|
|
|
|
|
{
|
|
|
|
|
runAction( action, null );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|