Show
Ignore:
Timestamp:
07/07/08 22:42:02 (4 years ago)
Author:
kohlhaas
Message:

* The new x (reservation, resource, person, user, period, ...) entries in the popup menu are now context sensitive. You can now only create new
objects that make sense in the selected tree node, that means you can only create a new user if you are in the user section of the tree.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Rapla/src/org/rapla/gui/internal/MenuFactoryImpl.java

    r1189 r1295  
    8484        Object focusedObject = context.getFocusedObject(); 
    8585        Point p = context.getPoint(); 
     86         
     87         
     88         
     89        boolean allocatableType = false; 
     90        boolean reservationType = false; 
     91        if ( focusedObject instanceof DynamicType) 
     92        { 
     93            DynamicType type = (DynamicType) focusedObject; 
     94            String classificationType = type.getAnnotation( DynamicTypeAnnotations.KEY_CLASSIFICATION_TYPE ); 
     95            allocatableType = classificationType.equals(  DynamicTypeAnnotations.VALUE_PERSON_CLASSIFICATION ) || classificationType.equals(  DynamicTypeAnnotations.VALUE_RESOURCE_CLASSIFICATION ); 
     96            reservationType = classificationType.equals(  DynamicTypeAnnotations.VALUE_RESERVATION_CLASSIFICATION ); 
     97        } 
     98        boolean allocatableNodeContext = allocatableType || focusedObject instanceof Allocatable  || focusedObject == CalendarSelectionModel.ALLOCATABLES_ROOT; 
    8699        if ( isRegisterer() || isAdmin()) { 
    87             menu.addSeparator(); 
    88             addAllocatableMenuNew( menu, parent,p, focusedObject); 
    89         } 
     100            if ( allocatableNodeContext) 
     101            { 
     102                menu.addSeparator(); 
     103                addAllocatableMenuNew( menu, parent,p, focusedObject);                 
     104            } 
     105        } 
     106        boolean reservationNodeContext =  reservationType || (focusedObject!= null && focusedObject.equals( getString("reservations" ))); 
    90107        if ( isAdmin() ) 
    91108        { 
    92             menu.addSeparator(); 
    93             addUserMenuNew( menu , parent, p, focusedObject); 
    94             addPeriodMenuNew(  menu , parent, p, focusedObject ); 
    95         } 
    96  
    97         addTypeMenuNew(menu, parent, p, focusedObject); 
     109            boolean userNodeContext = focusedObject instanceof User || (focusedObject  != null &&  focusedObject.equals( getString("users"))); 
     110            boolean periodNodeContext = focusedObject instanceof Period || (focusedObject  != null &&  focusedObject.equals( getString("periods"))); 
     111            if (userNodeContext || periodNodeContext || allocatableNodeContext || reservationNodeContext) 
     112            { 
     113                menu.addSeparator(); 
     114            } 
     115            if ( userNodeContext) 
     116            { 
     117                addUserMenuNew( menu , parent, p, focusedObject); 
     118            } 
     119            if ( periodNodeContext) 
     120            { 
     121                addPeriodMenuNew(  menu , parent, p, focusedObject ); 
     122            } 
     123            if (allocatableNodeContext) 
     124            { 
     125                addTypeMenuNew(menu, DynamicTypeAnnotations.VALUE_RESOURCE_CLASSIFICATION 
     126                        ,parent, p, focusedObject); 
     127                addTypeMenuNew(menu, DynamicTypeAnnotations.VALUE_PERSON_CLASSIFICATION 
     128                        ,parent, p, focusedObject); 
     129 
     130            } 
     131            if ( reservationNodeContext) 
     132            { 
     133                addTypeMenuNew(menu, DynamicTypeAnnotations.VALUE_RESERVATION_CLASSIFICATION 
     134                               ,parent, p, focusedObject); 
     135            } 
     136        } 
    98137 
    99138        return menu; 
     
    191230        RaplaObjectAction newResource = addAction(menu,parent,p).setNew( Allocatable.TYPE ); 
    192231        newResource.changeObject( obj ); 
    193         newResource.putValue(Action.NAME,getString("resource")); 
     232        DynamicType[] types = newResource.guessTypes(); 
     233        if (types.length == 1) 
     234        { 
     235            DynamicType type = types[0]; 
     236            newResource.putValue(Action.NAME,type.getName( getLocale() )); 
     237            return; 
     238        } 
     239        DynamicType[] resourceType= getQuery().getDynamicTypes(DynamicTypeAnnotations.VALUE_RESOURCE_CLASSIFICATION ); 
     240        if ( resourceType.length == 1) 
     241        { 
     242            newResource.putValue(Action.NAME,resourceType[0].getName( getLocale() ));             
     243        } 
     244        else 
     245        { 
     246            newResource.putValue(Action.NAME,getString("resource"));    
     247        } 
    194248 
    195249        RaplaObjectAction newPerson = addAction(menu,parent,p).setNew( Allocatable.TYPE ); 
    196250        newPerson.setPerson( true ); 
    197251        newPerson.changeObject( obj ); 
    198         newPerson.putValue(Action.NAME,getString("person")); 
     252        DynamicType[] personType= getQuery().getDynamicTypes(DynamicTypeAnnotations.VALUE_PERSON_CLASSIFICATION ); 
     253        if ( personType.length == 1) 
     254        { 
     255            newPerson.putValue(Action.NAME,personType[0].getName( getLocale())); 
     256        } 
     257        else 
     258        { 
     259            newPerson.putValue(Action.NAME,getString("person")); 
     260        } 
    199261 
    200262    } 
     
    209271 
    210272 
    211     private void addTypeMenuNew(MenuInterface menu,Component parent,Point p,Object obj) throws RaplaException { 
    212         if ( isAdmin() ) { 
    213             menu.addSeparator(); 
    214  
    215             DynamicTypeAction newResourceType = newDynamicTypeAction(parent,p); 
    216             menu.add(new JMenuItem(newResourceType)); 
    217             newResourceType.setNewClassificationType( DynamicTypeAnnotations.VALUE_RESOURCE_CLASSIFICATION); 
    218             newResourceType.putValue(Action.NAME,getString("resource_type")); 
    219  
    220             DynamicTypeAction newPersonType = newDynamicTypeAction(parent,p); 
    221             menu.add(new JMenuItem(newPersonType)); 
    222             newPersonType.setNewClassificationType(DynamicTypeAnnotations.VALUE_PERSON_CLASSIFICATION); 
    223             newPersonType.putValue(Action.NAME,getString("person_type")); 
    224  
     273    private void addTypeMenuNew(MenuInterface menu,String classificationType,Component parent,Point p,Object obj) throws RaplaException { 
    225274            DynamicTypeAction newReservationType = newDynamicTypeAction(parent,p); 
    226275            menu.add(new JMenuItem(newReservationType)); 
    227             newReservationType.setNewClassificationType(DynamicTypeAnnotations.VALUE_RESERVATION_CLASSIFICATION); 
    228             newReservationType.putValue(Action.NAME,getString("reservation_type")); 
    229         } 
     276            newReservationType.setNewClassificationType(classificationType); 
     277            newReservationType.putValue(Action.NAME,getString(classificationType + "_type")); 
    230278    } 
    231279