Method: getSelectionEmptyMessage()

1: /*
2: * #%~
3: * org.overture.ide.vdmpp.debug
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.vdmpp.debug.ui.launchconfigurations;
23:
24: import org.eclipse.core.runtime.CoreException;
25: import org.eclipse.debug.core.ILaunchConfiguration;
26: import org.eclipse.debug.core.ILaunchConfigurationType;
27: import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
28: import org.eclipse.jface.dialogs.MessageDialog;
29: import org.eclipse.jface.operation.IRunnableContext;
30: import org.overture.ast.node.INode;
31: import org.overture.ide.debug.core.VdmDebugPlugin;
32: import org.overture.ide.debug.core.IDebugConstants;
33: import org.overture.ide.debug.ui.launchconfigurations.LauncherMessages;
34: import org.overture.ide.debug.ui.launchconfigurations.MethodSearchEngine;
35: import org.overture.ide.debug.ui.launchconfigurations.VdmLaunchShortcut;
36: import org.overture.ide.ui.utility.ast.AstNameUtil;
37: import org.overture.ide.vdmpp.debug.IVdmPpDebugConstants;
38:
39: public class VdmPpApplicationLaunchShortcut extends VdmLaunchShortcut
40: {
41:
42:         /**
43:          * Returns a title for a type selection dialog used to prompt the user when there is more than one type that can be
44:          * launched.
45:          *
46:          * @return type selection dialog title
47:          */
48:         @Override
49:         protected String getTypeSelectionTitle()
50:         {
51:                 return "Select VDM-PP Application";
52:         }
53:
54:         /**
55:          * Returns an error message to use when the editor does not contain a type that can be launched.
56:          *
57:          * @return error message when editor cannot be launched
58:          */
59:         @Override
60:         protected String getEditorEmptyMessage()
61:         {
62:                 return "Editor does not contain a main type";
63:         }
64:
65:         /**
66:          * Returns an error message to use when the selection does not contain a type that can be launched.
67:          *
68:          * @return error message when selection cannot be launched
69:          */
70:         @Override
71:         protected String getSelectionEmptyMessage()
72:         {
73:                 return "Selection does not contain a launchable operation or function type";
74:         }
75:
76:         /*
77:          * (non-Javadoc)
78:          * @see org.eclipse.jdt.debug.ui.launchConfigurations.JavaLaunchShortcut#createConfiguration(org.eclipse.jdt
79:          * .core.IType)
80:          */
81:         protected ILaunchConfiguration createConfiguration(INode type,
82:                         String projectName)
83:         {
84:                 ILaunchConfiguration config = null;
85:                 ILaunchConfigurationWorkingCopy wc = null;
86:                 try
87:                 {
88:                         
89:                         ILaunchConfigurationType configType = getConfigurationType();
90:                         wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(projectName+" "+AstNameUtil.getName(type)));
91:                         wc.setAttribute(IDebugConstants.VDM_LAUNCH_CONFIG_PROJECT, projectName);
92:                         wc.setAttribute(IDebugConstants.VDM_LAUNCH_CONFIG_CREATE_COVERAGE, true);
93:
94:                         wc.setAttribute(IDebugConstants.VDM_LAUNCH_CONFIG_DEFAULT, getModuleName( type));
95:                         wc.setAttribute(IDebugConstants.VDM_LAUNCH_CONFIG_OPERATION, getOperationName( type)
96:                                         + "()");
97:                         if (isStaticAccessRequired(type))
98:                         {
99:                                 wc.setAttribute(IDebugConstants.VDM_LAUNCH_CONFIG_MODULE, getModuleName(type));
100:                                 wc.setAttribute(IDebugConstants.VDM_LAUNCH_CONFIG_EXPRESSION, getModuleName(type)
101:                                                 + "`" + getOperationName(type) + "()");
102:                         } else
103:                         {
104:                                 wc.setAttribute(IDebugConstants.VDM_LAUNCH_CONFIG_MODULE, getModuleNameLaunch(type));
105:                                 wc.setAttribute(IDebugConstants.VDM_LAUNCH_CONFIG_EXPRESSION, "new "
106:                                                 + getModuleNameLaunch(type)
107:                                                 + "."
108:                                                 + getOperationName(type) + "()");
109:                         }
110:                         wc.setAttribute(IDebugConstants.VDM_LAUNCH_CONFIG_STATIC_OPERATION, isStaticAccessRequired(type));
111:
112:                         wc.setAttribute(IDebugConstants.VDM_LAUNCH_CONFIG_ENABLE_LOGGING, false);
113:
114:                         config = wc.doSave();
115:                 } catch (CoreException exception)
116:                 {
117:
118:                         MessageDialog.openError(VdmDebugPlugin.getActiveWorkbenchShell(), LauncherMessages.VdmLaunchShortcut_3, exception.getStatus().getMessage());
119:                 }
120:                 return config;
121:         }
122:
123:         @Override
124:         protected INode[] filterTypes(Object[] elements, IRunnableContext context)
125:         {
126:                 return new MethodSearchEngine().searchMainMethods(context, elements, MethodSearchEngine.EXPLICIT_FUNCTION
127:                                 | MethodSearchEngine.EXPLICIT_OPERATION
128:                                 | MethodSearchEngine.PUBLIC);
129:
130:         }
131:
132:         @Override
133:         protected ILaunchConfigurationType getConfigurationType()
134:         {
135:                 return getLaunchManager().getLaunchConfigurationType(IVdmPpDebugConstants.ATTR_VDM_PROGRAM);
136:         }
137:
138: }