Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 16a4a842dd25aaf5308c1da4f0d0242797eb7fab (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*******************************************************************************
 * Copyright (c) 2009 R.Dvorak and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v20.html
 *
 * Contributors:
 *     Radek Dvorak - initial API and implementation
 *******************************************************************************/
package org.eclipse.m2m.internal.qvt.oml.debug.ui;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IStatusHandler;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IThread;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.m2m.internal.qvt.oml.debug.ui.actions.QVTOBreakpointPropertiesAction;
import org.eclipse.m2m.qvt.oml.debug.core.BreakpointError;
import org.eclipse.m2m.qvt.oml.debug.core.QVTOBreakpoint;
import org.eclipse.m2m.qvt.oml.debug.core.QVTODebugCore;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;


public class BreakpointCondErrorHandler implements IStatusHandler {
	
	private static class CondErrorDialog extends ErrorDialog {
	    
	    CondErrorDialog(Shell parentShell, String message, IStatus status) {
	        super(parentShell, DebugUIMessages.BreakpointCondErrorHandler_DialogTitle, message, status, IStatus.ERROR); 
	    }

	    @Override
	    protected void createButtonsForButtonBar(Composite parent) {
	        // create buttons to cancel the handler or edit the condition settings
			createButton(parent, IDialogConstants.CANCEL_ID,
					IDialogConstants.CANCEL_LABEL, false);
			createButton(
					parent,
					IDialogConstants.OK_ID,
					DebugUIMessages.BreakpointCondErrorHandler_EditConditionButtonLabel,
					true);
	    }
	}	
	
	public BreakpointCondErrorHandler() {
		super();
	}
	
	public Object handleStatus(IStatus status, Object source) throws CoreException {
		if(source instanceof IDebugTarget == false) {
			throw new CoreException(QVTODebugCore.createStatus(IStatus.ERROR,
					"Unable to resolve status for:" + source)); //$NON-NLS-1$
		}
		
		BreakpointError breakpointError = (BreakpointError) status;
		final IDebugTarget target = (IDebugTarget) source;
		
		suspendDebugUI(target);

		showErrorDialog(
				breakpointError.getfBreakpointID(), 
				breakpointError.getMessage(), 
				breakpointError.getDetail());
		
		return Boolean.TRUE;
	}

    public void showErrorDialog(final long breakPointID, final String errorMessage, final String detail) {    	
        final Display display = QVTODebugUIPlugin.getStandardDisplay();

        display.asyncExec(new Runnable() {
            public void run() {               
            	QVTOBreakpoint breakpoint = QVTOBreakpoint.getBreakpointByID(breakPointID);
            	if(breakpoint == null) {
    				QVTODebugCore.log(QVTODebugCore.createStatus(IStatus.ERROR,"Breakpoint not found")); //$NON-NLS-1$
         			return;
            	}

                if (display.isDisposed()) {
                    return;
                }
                
                Shell shell = QVTODebugUIPlugin.getActiveWorkbenchShell();
                IStatus errorStatus = QVTODebugUIPlugin.createErrorStatus(detail);
                
                CondErrorDialog dialog = new CondErrorDialog(shell, errorMessage, errorStatus);
                int result = dialog.open();
                if (result == Window.OK) {
                	// jump to breakpoint properties
                    QVTOBreakpointPropertiesAction action = new QVTOBreakpointPropertiesAction();
                    action.selectionChanged(null, new StructuredSelection(breakpoint));
                    action.run(null);
                }
            }
        });
    }	
    
	private void suspendDebugUI(final IDebugTarget target) {
		QVTODebugUIPlugin.getStandardDisplay().asyncExec(new Runnable() {
			public void run() {
				try {
					IThread[] threads = target.getThreads();
					IThread mainThread = (threads.length > 0) ? threads[0] : null;
					// check if we still execute
					if(mainThread != null) {
						// Note: broadcast the suspend even to update the debug framework UI
						DebugEvent debugEvent = new DebugEvent(mainThread, DebugEvent.SUSPEND, DebugEvent.BREAKPOINT);
						DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { debugEvent });
					}
					
				} catch (DebugException e) {
					QVTODebugUIPlugin.log(e.getStatus());
				}
			}
		});
	}	    
}

Back to the top