Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 731672c0ed8de18515bb7acad70646aafcf3db38 (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2008 ARM Limited and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * ARM Limited - Initial API and implementation
 *******************************************************************************/

package org.eclipse.cdt.debug.internal.ui.disassembly.commands;

import java.util.Map;

import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.ICDebugConstants;
import org.eclipse.cdt.debug.core.model.ISteppingModeTarget;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.menus.UIElement;

/**
 * org.eclipse.cdt.debug.internal.ui.disassembly.commands.SetSteppingModeHandler: 
 * //TODO Add description.
 */
public class SetSteppingModeHandler extends AbstractHandler implements IElementUpdater {

    private static final String ID_PARAMETER_MODE = "com.arm.eclipse.rvd.ui.command.steppingMode.parameterMode"; //$NON-NLS-1$

    private String fCurrentValue = null;

    public SetSteppingModeHandler() {
        super();
        fCurrentValue = CDebugCorePlugin.getDefault().getPluginPreferences().getString( ICDebugConstants.PREF_STEP_MODE );
    }

    /* (non-Javadoc)
     * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
     */
    @Override
	public Object execute( ExecutionEvent event ) throws ExecutionException {
        String param = event.getParameter( ID_PARAMETER_MODE );
        if ( param == null || param.equals( fCurrentValue ) )
            return null;
        
        fCurrentValue = param;
        CDebugCorePlugin.getDefault().getPluginPreferences().setValue( ICDebugConstants.PREF_STEP_MODE, fCurrentValue );

        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked( event );
        ICommandService service = (ICommandService)window.getService( ICommandService.class );
        service.refreshElements( event.getCommand().getId(), null );

        return null;
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.commands.IElementUpdater#updateElement(org.eclipse.ui.menus.UIElement, java.util.Map)
     */
    @Override
	@SuppressWarnings("unchecked")
    public void updateElement( UIElement element, Map parameters ) {
        String param = (String)parameters.get( ID_PARAMETER_MODE );
        if ( param != null ) {
            element.setChecked( ( fCurrentValue != null && fCurrentValue.equals( param ) ) );
        }
    }

    /* (non-Javadoc)
     * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
     */
    @Override
    public boolean isEnabled() {
        IWorkbenchWindow window = CDebugUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
        return ( window != null && getSteppingModeTarget( window ) != null );
    }

    /* (non-Javadoc)
     * @see org.eclipse.core.commands.AbstractHandler#isHandled()
     */
    @Override
    public boolean isHandled() {
        IWorkbenchWindow window = CDebugUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
        return ( window != null && getSteppingModeTarget( window ) != null );
    }

    private ISteppingModeTarget getSteppingModeTarget( IWorkbenchWindow window ) {
        ISelection selection = DebugUITools.getDebugContextManager().getContextService( window ).getActiveContext();
        if ( selection instanceof IStructuredSelection ) {
            Object element = ((IStructuredSelection)selection).getFirstElement();
            if ( element instanceof IAdaptable )
                return (ISteppingModeTarget)((IAdaptable)element).getAdapter( ISteppingModeTarget.class );
        }
        return null;
    }
}

Back to the top