Changeset 1994

Show
Ignore:
Timestamp:
03/11/08 15:52:15 (9 months ago)
Author:
apatel
Message:

put all the editor actions in its own package. Changed AddCustomAction? from selection action to just an action. Improves the performance as its state is calculated only when it is dipslayed.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/compiler/translator/SELinuxPolicy.java

    r1989 r1994  
    125125        } 
    126126         
     127        public SELinuxPolicy (Linkage i_linkage, boolean i_bCustomizationTemplates) 
     128        { 
     129                m_linkage = i_linkage; 
     130                m_moduleName = "customization"; 
     131        } 
     132         
    127133        protected void finalize () 
    128134                throws Throwable 
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/editor/action/AddCustomPolicy.java

    r1992 r1994  
    88 */ 
    99 
    10 package com.tresys.framework.plugin.editor.custom
     10package com.tresys.framework.plugin.editor.action
    1111 
    1212import java.io.ByteArrayInputStream; 
     
    1616import org.eclipse.core.resources.IResource; 
    1717import org.eclipse.core.runtime.CoreException; 
    18 import org.eclipse.gef.ui.actions.SelectionAction; 
     18import org.eclipse.jface.action.Action; 
    1919import org.eclipse.jface.dialogs.ErrorDialog; 
    2020import org.eclipse.jface.dialogs.MessageDialog; 
     
    3636import com.tresys.framework.plugin.editor.policy.graphic.model.Shape; 
    3737import com.tresys.framework.plugin.editor.policy.graphic.parts.AbstractConnectionEditPart; 
    38 import com.tresys.framework.plugin.editor.policy.graphic.parts.AccessEditPart; 
    39 import com.tresys.framework.plugin.editor.policy.graphic.parts.DomainEditPart; 
    4038import com.tresys.framework.plugin.editor.policy.graphic.parts.PolicyEditPart; 
    41 import com.tresys.framework.plugin.editor.policy.graphic.parts.ShapeEditPart; 
    4239import com.tresys.slide.plugin.editors.module.ModuleEditor; 
    4340 
    4441public class AddCustomPolicy 
    45         extends SelectionAction 
     42        extends Action 
    4643{ 
    4744         
     
    5148        public AddCustomPolicy (GraphicPolicyEditor part) 
    5249        { 
    53                 super (part); 
     50                super ("Add Custom Policy..."); 
    5451                mEditor = part; 
     52                setEnabled (false); 
     53                setToolTipText ("Creates a new module that contains custom policy"); 
    5554        } 
    5655 
     
    5958                return ID; 
    6059        } 
    61          
    62         protected boolean calculateEnabled () 
    63         { 
    64                  
    65                 if( !(getSelection () instanceof StructuredSelection) ) 
    66                         return false; 
    67                 IStructuredSelection selection = (StructuredSelection)getSelection (); 
    68                  
    69                 if( selection.size () != 1 ) 
    70                         return false; 
    71                  
    72                 Object selected_item = selection.getFirstElement (); 
    73                 if ( !(selected_item instanceof ShapeEditPart || selected_item instanceof AccessEditPart 
    74                         || selected_item instanceof DomainEditPart) ) 
    75                         return false; 
    76                 return customizationAllowed (selected_item); 
    77         } 
    78  
    79         /** 
    80          * @see org.eclipse.gef.ui.actions.EditorPartAction#init() 
    81          */ 
    82         protected void init () 
    83         { 
    84                 setId (getId ()); 
    85                 setText ("Add custom Policy..."); 
    86         } 
    8760 
    8861        public void run () 
    8962        { 
    90                  
     63                Object unknown_selection = mEditor.getViewer ().getSelection (); 
     64                if(!( unknown_selection instanceof StructuredSelection)) 
     65                        return; 
     66                IStructuredSelection selection = (StructuredSelection)unknown_selection; 
     67                Object selected_item = selection.getFirstElement (); 
     68 
    9169                /** 
    9270                 * Warn user ...! 
     
    11593                                 * and get the file system resource for editor input. 
    11694                                 */ 
    117                                 OutputStream stream = getPolicy (); 
     95                                OutputStream stream = getPolicy (selected_item); 
    11896                                if( stream == null ) 
    11997                                { 
     
    140118        } 
    141119         
    142         private final boolean customizationAllowed(Object selected_item) 
     120        private OutputStream getPolicy(Object selected_item) 
    143121        { 
    144                 boolean supports_customization = false; 
    145                  
    146                 if( selected_item instanceof PolicyEditPart) 
    147                 { 
    148                         PolicyEditPart policy_part = (PolicyEditPart)selected_item; 
    149                         Object model = policy_part.getModel (); 
    150                         if( model instanceof Shape ) 
    151                         { 
    152                                 Shape shape = (Shape)model; 
    153                                 Component comp = shape.getComponent ();  
    154                                 if( comp instanceof ICustomPolicy ) 
    155                                 { 
    156                                         ICustomPolicy customization = (ICustomPolicy)comp; 
    157                                         boolean can_be_customized = customization.supportsCustomPolicy (); 
    158                                         boolean modified = !customization.hasCustomization (); 
    159                                         supports_customization = (can_be_customized & modified); 
    160                                 } 
    161                         } 
    162                 } 
    163                 else if( selected_item instanceof AbstractConnectionEditPart ) 
    164                 { 
    165                         AbstractConnectionEditPart part = (AbstractConnectionEditPart)selected_item; 
    166                         Object model = part.getModel (); 
    167                         if( model instanceof Connection) 
    168                         { 
    169                                 Connection con = (Connection)model; 
    170                                 if( con instanceof ICustomPolicy ) 
    171                                 { 
    172                                         ICustomPolicy customization = (ICustomPolicy)con; 
    173                                         boolean can_be_customized = customization.supportsCustomPolicy (); 
    174                                         boolean modified = !customization.hasCustomization (); 
    175                                         supports_customization = (can_be_customized & modified); 
    176                                 } 
    177                         } 
    178                 } 
    179                 return supports_customization; 
    180         } 
    181          
    182         private OutputStream getPolicy() 
    183         { 
    184                 IStructuredSelection selection = (StructuredSelection)getSelection (); 
    185                 Object selected_item = selection.getFirstElement (); 
    186                  
    187122                Linkage linkage = mEditor.getSystem ().getLinkage (); 
    188123                SELinuxPolicy policy = new SELinuxPolicy(linkage, null, null); 
     
    229164        } 
    230165         
    231          
    232166        void print_debug(Object o) 
    233167        { 
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/GraphicPolicyEditor.java

    r1991 r1994  
    9191import com.tresys.framework.plugin.builder.GUIErrorHandler; 
    9292import com.tresys.framework.plugin.builder.SELinuxSystem; 
    93 import com.tresys.framework.plugin.editor.custom.AddCustomPolicy; 
     93import com.tresys.framework.plugin.editor.action.AddCustomPolicy; 
     94import com.tresys.framework.plugin.editor.action.RemoveCustomPolicy; 
    9495import com.tresys.framework.plugin.editor.policy.IPolicyEditor; 
    9596import com.tresys.framework.plugin.editor.policy.graphic.model.ModelElement; 
     
    857858                getSelectionActions().add(action.getId()); 
    858859                 
     860                action = new RemoveCustomPolicy(this); 
     861                registry.registerAction(action); 
     862                getSelectionActions().add(action.getId()); 
    859863} 
    860864         
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/GraphicPolicyEditorContextMenuProvider.java

    r1987 r1994  
    1515import org.eclipse.jface.dialogs.Dialog; 
    1616import org.eclipse.jface.dialogs.ErrorDialog; 
     17import org.eclipse.jface.viewers.IStructuredSelection; 
     18import org.eclipse.jface.viewers.StructuredSelection; 
    1719import org.eclipse.ui.actions.ActionFactory; 
    1820 
     
    2224import org.eclipse.gef.ui.actions.GEFActionConstants; 
    2325 
     26import com.tresys.framework.compiler.custom.ICustomPolicy; 
    2427import com.tresys.framework.compiler.linkage.refpolicy.InfoDirection; 
    25 import com.tresys.framework.plugin.editor.custom.AddCustomPolicy; 
     28import com.tresys.framework.compiler.policy.Component; 
     29import com.tresys.framework.plugin.editor.action.AddCustomPolicy; 
     30import com.tresys.framework.plugin.editor.action.RemoveCustomPolicy; 
     31import com.tresys.framework.plugin.editor.policy.graphic.model.Connection; 
     32import com.tresys.framework.plugin.editor.policy.graphic.model.Shape; 
     33import com.tresys.framework.plugin.editor.policy.graphic.parts.AbstractConnectionEditPart; 
     34import com.tresys.framework.plugin.editor.policy.graphic.parts.AccessEditPart; 
     35import com.tresys.framework.plugin.editor.policy.graphic.parts.DomainEditPart; 
     36import com.tresys.framework.plugin.editor.policy.graphic.parts.PolicyEditPart; 
     37import com.tresys.framework.plugin.editor.policy.graphic.parts.ShapeEditPart; 
    2638 
    2739 
     
    7486                                getAction(ActionFactory.DELETE.getId())); 
    7587                 
    76                 menu.appendToGroup( 
    77                         GEFActionConstants.GROUP_EDIT, 
    78                         getAction(AddCustomPolicy.ID)); 
     88                 
     89                IAction action = getAction (AddCustomPolicy.ID); 
     90                if( action != null ) 
     91                { 
     92                        action.setEnabled (customizationAllowed ()); 
     93                        menu.appendToGroup(GEFActionConstants.GROUP_EDIT, action); 
     94                } 
     95                action = getAction (RemoveCustomPolicy.ID); 
     96                if( action != null ) 
     97                { 
     98                        action.setEnabled (true); 
     99                        menu.appendToGroup(GEFActionConstants.GROUP_EDIT,action); 
     100                } 
    79101        } 
    80102         
     
    88110                super.add (action); 
    89111        } 
     112         
     113        private boolean customizationAllowed() 
     114        { 
     115                Object sele = getViewer ().getSelection (); 
     116                if( !(sele instanceof StructuredSelection) ) 
     117                        return false; 
     118                IStructuredSelection selection = (StructuredSelection)sele; 
     119                 
     120                if( selection.size () != 1 ) 
     121                        return false; 
     122                 
     123                Object selected_item = selection.getFirstElement (); 
     124                if ( !(selected_item instanceof ShapeEditPart || selected_item instanceof AccessEditPart 
     125                        || selected_item instanceof DomainEditPart) ) 
     126                        return false; 
     127                 
     128                boolean supports_customization = false; 
     129                 
     130                if( selected_item instanceof PolicyEditPart) 
     131                { 
     132                        PolicyEditPart policy_part = (PolicyEditPart)selected_item; 
     133                        Object model = policy_part.getModel (); 
     134                        if( model instanceof Shape ) 
     135                        { 
     136                                Shape shape = (Shape)model; 
     137                                Component comp = shape.getComponent ();  
     138                                if( comp instanceof ICustomPolicy ) 
     139                                { 
     140                                        ICustomPolicy customization = (ICustomPolicy)comp; 
     141                                        boolean can_be_customized = customization.supportsCustomPolicy (); 
     142                                        boolean modified = !customization.hasCustomization (); 
     143                                        supports_customization = (can_be_customized & modified); 
     144                                } 
     145                        } 
     146                } 
     147                else if( selected_item instanceof AbstractConnectionEditPart ) 
     148                { 
     149                        AbstractConnectionEditPart part = (AbstractConnectionEditPart)selected_item; 
     150                        Object model = part.getModel (); 
     151                        if( model instanceof Connection) 
     152                        { 
     153                                Connection con = (Connection)model; 
     154                                if( con instanceof ICustomPolicy ) 
     155                                { 
     156                                        ICustomPolicy customization = (ICustomPolicy)con; 
     157                                        boolean can_be_customized = customization.supportsCustomPolicy (); 
     158                                        boolean modified = !customization.hasCustomization (); 
     159                                        supports_customization = (can_be_customized & modified); 
     160                                } 
     161                        } 
     162                } 
     163                return supports_customization; 
     164        } 
     165 
    90166}