IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Eclipse Platform Discussion :

grisé un bouton et un menu


Sujet :

Eclipse Platform

  1. #1
    Membre régulier
    Inscrit en
    Mars 2005
    Messages
    226
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 226
    Points : 78
    Points
    78
    Par défaut grisé un bouton et un menu
    Bonjour,

    je realise une application RCP. Le but de cette application de capturer des packets dans le réseau. dans ma barre de bouton, j'ai un bouton Start et un bouton Stop. De plus il est possible de lancer/arreter la capture a partir du menu capture. Je voudrai savoir coment je peux grise un bouton et une action dans un menu

    je voudrais que quand la capture est lancée : le bouton "Start" et l'action "Start" dans le menu capture soit grisée
    et je voudrais qund la capture est arretée: le bouton "Stop" et l action "Stop" du menu Capture soit grisée

    classe ApplicationActionBar.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
     
    package icmp.agent;
     
    import interfaces.ICommandConstant;
     
    import org.eclipse.jface.action.Action;
    import org.eclipse.jface.action.GroupMarker;
    import org.eclipse.jface.action.ICoolBarManager;
    import org.eclipse.jface.action.IMenuManager;
    import org.eclipse.jface.action.IToolBarManager;
    import org.eclipse.jface.action.MenuManager;
    import org.eclipse.jface.action.Separator;
    import org.eclipse.jface.action.ToolBarContributionItem;
    import org.eclipse.jface.action.ToolBarManager;
    import org.eclipse.jface.resource.ImageDescriptor;
    import org.eclipse.swt.SWT;
    import org.eclipse.ui.IWorkbenchActionConstants;
    import org.eclipse.ui.IWorkbenchWindow;
    import org.eclipse.ui.actions.ActionFactory;
    import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
    import org.eclipse.ui.application.ActionBarAdvisor;
    import org.eclipse.ui.application.IActionBarConfigurer;
     
    import actions.ConfigurationAction;
    import actions.StartAction;
    import actions.StopAction;
     
    import views.AboutJNetmon;
    import views.QuitJNetmon;
     
    public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
     
    	private static final String IMG_START = "/icons/start.gif";
    	private static final String IMG_STOP = "/icons/stop.gif";
    	private static final String IMG_CONFIG = "/icons/config.gif";
     
     
    	private IWorkbenchAction exitAction;
    	private IWorkbenchAction aboutAction;
    	private Action startAction;
    	private Action stopAction;
    	private Action configurationAction;
     
     
     
        public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
            super(configurer);
        }
     
        protected void makeActions(IWorkbenchWindow window) {
        	// Exit
    		ActionFactory quit = new ActionFactory("quite") {//$NON-NLS-1$
    			public IWorkbenchAction create(IWorkbenchWindow window) {
    				if (window == null) {
    					throw new IllegalArgumentException();
    				}
    				IWorkbenchAction action = new QuitJNetmon(window);
    				action.setId(getId());
    				return action;
    			}
    		};
    		exitAction = quit.create(window);
    		exitAction.setText("Exit");
    		register(exitAction);
     
    		// start
    		startAction = new StartAction(ICommandConstant.CMD_START);
    		startAction.setDescription("Start");
    		startAction.setImageDescriptor(Activator
    				.getImageDescriptor(IMG_START));
    		register(startAction);
     
    		// configuration
    		stopAction = new StopAction(ICommandConstant.CMD_STOP);
    		stopAction.setDescription("Stop");
    		stopAction.setImageDescriptor(Activator
    				.getImageDescriptor(IMG_STOP));
    		register(stopAction);
     
    		// configuration
    		configurationAction = new ConfigurationAction(window);
    		configurationAction.setDescription("Configuration");
    		configurationAction.setImageDescriptor(Activator
    				.getImageDescriptor(IMG_CONFIG));
    		register(configurationAction);
     
     
     
    		// about
    		ActionFactory about = new ActionFactory("about") {//$NON-NLS-1$
    			public IWorkbenchAction create(IWorkbenchWindow window) {
    				if (window == null) {
    					throw new IllegalArgumentException();
    				}
    				IWorkbenchAction action = new AboutJNetmon(window);
    				action.setId(getId());
    				return action;
    			}
    		};
    		aboutAction = about.create(window);
    		aboutAction.setText("About");
    		aboutAction.setImageDescriptor(Activator
    				.getImageDescriptor("/icons/about.ico"));
    		register(aboutAction);
        }
     
     
     
     
     
        protected void fillMenuBar(IMenuManager menuBar) {
        	MenuManager fileMenu = new MenuManager("&File",
    				IWorkbenchActionConstants.M_FILE);
    		menuBar.add(fileMenu);
    		fileMenu.add(configurationAction);
    		fileMenu.add(new Separator());
    		fileMenu.add(exitAction);
     
    		menuBar.add(new GroupMarker("additions"));
     
    		MenuManager helpMenu = new MenuManager("&Help",
    				IWorkbenchActionConstants.M_HELP);
    		menuBar.add(helpMenu);
    		helpMenu.add(aboutAction);
        }
     
     
     
     
     
        protected void fillCoolBar(ICoolBarManager coolBar) {
    		IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.BOTTOM);
    		coolBar.add(new ToolBarContributionItem(toolbar, "main"));
    		toolbar.add(startAction);
    		toolbar.add(stopAction);
    		toolbar.add(configurationAction);
    	}
     
    }
    plugin.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     
    <extension
    		point="org.eclipse.ui.actionSets">
          <actionSet
          		id="icmp.agent.captureActionSet"
                label="Capture actionSet"
                visible="false">
            <menu
            	id="captureMenu"
                label="Capture">
                	<groupMarker
                    	name="captureGroup">
                    </groupMarker>
             </menu>   
             <action
                class="actions.CaptureMenu"
                id="Stop"
                label="Stop"
                menubarPath="captureMenu/captureGroup">
            </action> 
             <action
    			class="actions.CaptureMenu"
                id="Start"
                label="Start"
                menubarPath="captureMenu/captureGroup">
             </action>
         </actionSet>
    </extension>
    classe CaptureMenu
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
     
    package actions;
     
    import interfaces.ICommandConstant;
     
    import org.eclipse.jface.action.IAction;
    import org.eclipse.jface.viewers.ISelection;
    import org.eclipse.ui.IWorkbenchWindow;
    import org.eclipse.ui.IWorkbenchWindowActionDelegate;
     
    public class CaptureMenu implements IWorkbenchWindowActionDelegate{
     
    	public void run(IAction action) {
    		if(action.getId().equals(ICommandConstant.CMD_START)){
    			StartAction startAction = new StartAction(ICommandConstant.CMD_START);
    			startAction.run();
    		}
    		else if(action.getId().equals(ICommandConstant.CMD_STOP)){
    			StopAction stopAction = new StopAction(ICommandConstant.CMD_STOP);
    			stopAction.run();
    		}
    		else{
    			System.out.println("Unknown action: " + action.getId());
    		}
    	}
     
    	@Override
    	public void dispose() {
    		// TODO Auto-generated method stub
     
    	}
     
    	@Override
    	public void init(IWorkbenchWindow window) {
    		// TODO Auto-generated method stub
     
    	}
     
    	@Override
    	public void selectionChanged(IAction action, ISelection selection) {
    		// TODO Auto-generated method stub
     
    	}
    }
    Merci de votre aide

  2. #2
    Membre confirmé

    Homme Profil pro
    Consultant en technologies
    Inscrit en
    Juin 2004
    Messages
    332
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultant en technologies

    Informations forums :
    Inscription : Juin 2004
    Messages : 332
    Points : 556
    Points
    556
    Par défaut
    A priori , il suffit de désactiver les actions.

    Les boutons (ActionBarContributionItems) de ta barre de menu sont en fait listeners de la propriété "enabled" (entre autres, ... de même que "visible", le "text", ou l'"image" de ton action...) et sont donc rafraichis tout seuls !


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    package actions;
     
    import interfaces.ICommandConstant;
     
    import org.eclipse.jface.action.IAction;
    import org.eclipse.jface.viewers.ISelection;
    import org.eclipse.ui.IWorkbenchWindow;
    import org.eclipse.ui.IWorkbenchWindowActionDelegate;
     
    public class CaptureMenu implements IWorkbenchWindowActionDelegate{
     
        public void run(IAction action) {
            if(action.getId().equals(ICommandConstant.CMD_START)){
                StartAction startAction = new StartAction(ICommandConstant.CMD_START);
                startAction.run();
    ======>                startAction.setEnabled(false);
    ======>                stopAction.setEnabled(true);
            }
            else if(action.getId().equals(ICommandConstant.CMD_STOP)){
                StopAction stopAction = new StopAction(ICommandConstant.CMD_STOP);
                stopAction.run();
    ======>                startAction.setEnabled(true);
    ======>                stopAction.setEnabled(false);
            }
            else{
                System.out.println("Unknown action: " + action.getId());
            }
        }
     
        @Override
        public void dispose() {
            // TODO Auto-generated method stub
            
        }
     
        @Override
        public void init(IWorkbenchWindow window) {
            // TODO Auto-generated method stub
            
        }
     
        @Override
        public void selectionChanged(IAction action, ISelection selection) {
            // TODO Auto-generated method stub
            
        }
    }

  3. #3
    Membre régulier
    Inscrit en
    Mars 2005
    Messages
    226
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 226
    Points : 78
    Points
    78
    Par défaut
    C'est une partie de la solution.
    Voila j'ai du mettre dans la classe ApplicationActionBarAdvisor mes action StopAction et StartAction en public static.

    quand j'appuie sur les boutons de ma barre de boutons, la modification se fait bien pour la barre des boutons seulement, pour le menu les deux choix restent accessibles.

    Comment appeler le menu dans mes deux classes?

    ma deuxieme question est que quand je choisis de passer par le menu, suivant le choix selectioné, je suis obligée de créer une action (classe StartAction ou StopAction) et d'appeler à la main la méthode run. est ce que c'est normal ou il y a une autre possibilté plus jolie d'appeler la fonction run automatiquement?
    J'ai essayer de forcer le typage du parametre action mais je n'ai pas reussit a lancer la methode run a partir de la (j'ai pas trouvé de méthode start ou autre chose qui y ressemblait).

    classe CaptureMenu:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
    public class CaptureMenu implements IWorkbenchWindowActionDelegate{
     
    	public void run(IAction action) {	
    		if(action.getId().equals(ICommandConstant.CMD_START)){		
    			StartAction startAction = new StartAction(ICommandConstant.CMD_START);
    			startAction.run();
    		}
    		else if(action.getId().equals(ICommandConstant.CMD_STOP)){
    			StopAction stopAction = new StopAction(ICommandConstant.CMD_STOP);
    			stopAction.run();
    		}
    		else{
    			System.out.println("Unknown action: " + action.getId());
    		}
    	}
    }
    classe StartAction:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
     
    package actions;
     
    import icmp.agent.ApplicationActionBarAdvisor;
     
    import org.eclipse.jface.action.Action;
     
    public class StartAction extends Action{
     
    	/**
             * Default constructor
             * @param window
             */
    	public StartAction(String id){
    		super(id);
    		setId(id);
    	}
     
    	/**
             * Open he dialog window
             */
    	public void run() {
    		//manage the button in the tool bar
    		ApplicationActionBarAdvisor.startAction.setEnabled(false);
    		ApplicationActionBarAdvisor.stopAction.setEnabled(true);
     
                    // manage menu Capture
                    //?????????????????????
     
    		System.out.println("start run");
    	}
    }
    clase StopAction est similaire a StartAction.

Discussions similaires

  1. [ADO][DBgrid]grisé un bouton
    Par napz dans le forum Bases de données
    Réponses: 3
    Dernier message: 17/04/2007, 13h03
  2. [VBA-E] Création d'un bouton dans "Worksheet Menu Bar"
    Par damsmut dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 14/03/2007, 08h25
  3. [VBA-E] Bouton perso dans menu standard
    Par electrosat03 dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 24/01/2007, 17h09
  4. Bouton flash et menu
    Par sebouuu dans le forum ActionScript 1 & ActionScript 2
    Réponses: 4
    Dernier message: 15/01/2007, 18h34
  5. [FLASH MX] Action des boutons dans un menu déroulant
    Par zab_paris dans le forum Flash
    Réponses: 1
    Dernier message: 05/07/2005, 18h14

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo