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
|
/*******************************************************************************
* Copyright (c) 2010 Intel Corporation.
* 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:
* Intel - initial API and implementation
*******************************************************************************/
package org.yocto.sdk.ide.actions;
import java.lang.reflect.Method;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.cdt.internal.autotools.ui.actions.AbstractAutotoolsHandler;
import org.eclipse.cdt.internal.autotools.ui.actions.InvokeAction;
import org.eclipse.swt.widgets.Display;
import org.yocto.sdk.ide.YoctoSDKPlugin;
@SuppressWarnings("restriction")
public class ReconfigYoctoHandler extends AbstractAutotoolsHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
ReconfigYoctoAction action = new ReconfigYoctoAction();
Method method = null;
try {
/*
* This is hack to workaround upstream eclipse bug #370288
*/
Class [] params = {ExecutionEvent.class, InvokeAction.class};
method = AbstractAutotoolsHandler.class.getDeclaredMethod("execute",params );
} catch (NoSuchMethodException e) {
//no such method, old version of plugin org.eclipse.linuxtools.autotools.ui
method = null;
} catch (Exception e) {
throw new ExecutionException(e.getMessage(), e);
}
if (method != null) {
//new version
Object [] params = {event, action};
try {
return method.invoke(this, params);
}catch (Exception e) {
throw new ExecutionException(e.getMessage(), e);
}
} else {
//old version
//display a dialog to warn the user
Display.getDefault().syncExec(new Runnable() {
public void run() {
ErrorDialog.openError(null, "Change Yocto Project Settings", "Please update the plugin of \"Autotools support for CDT\"!",
new Status(IStatus.WARNING,YoctoSDKPlugin.PLUGIN_ID,"old version of plugin \"Autotools support for CDT\" detected."));
}
});
//try to display the dialog in the old way
Object o = event.getApplicationContext();
if (o instanceof IEvaluationContext) {
IContainer container = getContainer((IEvaluationContext)o);
if (container != null) {
action.setSelectedContainer(container);
action.run(null);
}
}
}
return null;
}
}
|