Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Schwarz2015-03-11 12:23:47 +0000
committerTobias Schwarz2015-03-11 12:23:47 +0000
commit51f1be2dc75d2b887e182c089f6b5d1c65b96678 (patch)
tree76ba9296a74c3b13576b8d1548eb080a07736c56
parent09d7b0b7c4ba6ae8a83e173f4b13d9af85d1cf34 (diff)
downloadorg.eclipse.tcf-51f1be2dc75d2b887e182c089f6b5d1c65b96678.tar.gz
org.eclipse.tcf-51f1be2dc75d2b887e182c089f6b5d1c65b96678.tar.xz
org.eclipse.tcf-51f1be2dc75d2b887e182c089f6b5d1c65b96678.zip
SM: fix possible ClassCastException
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/LaunchLaunchConfigurationContributionItem.java34
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/NewLaunchConfigurationContributionItem.java139
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/OpenLaunchConfigurationContributionItem.java99
3 files changed, 156 insertions, 116 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/LaunchLaunchConfigurationContributionItem.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/LaunchLaunchConfigurationContributionItem.java
index 0a9766bdc..23b489df1 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/LaunchLaunchConfigurationContributionItem.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/LaunchLaunchConfigurationContributionItem.java
@@ -82,24 +82,26 @@ public class LaunchLaunchConfigurationContributionItem extends CompoundContribut
IHandlerService service = (IHandlerService)serviceLocator.getService(IHandlerService.class);
IEvaluationContext state = service.getCurrentState();
ISelection selection = (ISelection)state.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
- IStructuredSelection iss = (IStructuredSelection)selection;
- Object obj = iss.getFirstElement();
List<IContributionItem> items = new ArrayList<IContributionItem>();
- if (obj instanceof LaunchNode) {
- LaunchNode node = (LaunchNode) obj;
- if (node.getLaunchConfiguration() != null) {
- try {
- for (String mode : LaunchConfigHelper.getLaunchConfigTypeModes(node.getLaunchConfigurationType(), false)) {
- ILaunchMode launchMode = DebugPlugin.getDefault().getLaunchManager().getLaunchMode(mode);
- IAction action = new LaunchAction(node.getLaunchConfiguration(), mode);
- action.setText(launchMode.getLabel());
- action.setImageDescriptor(DebugUITools.getLaunchGroup(node.getLaunchConfiguration(), mode).getImageDescriptor());
- action.setEnabled(node.isValidFor(mode));
- items.add(new ActionContributionItem(action));
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection iss = (IStructuredSelection)selection;
+ Object obj = iss.getFirstElement();
+ if (obj instanceof LaunchNode) {
+ LaunchNode node = (LaunchNode) obj;
+ if (node.getLaunchConfiguration() != null) {
+ try {
+ for (String mode : LaunchConfigHelper.getLaunchConfigTypeModes(node.getLaunchConfigurationType(), false)) {
+ ILaunchMode launchMode = DebugPlugin.getDefault().getLaunchManager().getLaunchMode(mode);
+ IAction action = new LaunchAction(node.getLaunchConfiguration(), mode);
+ action.setText(launchMode.getLabel());
+ action.setImageDescriptor(DebugUITools.getLaunchGroup(node.getLaunchConfiguration(), mode).getImageDescriptor());
+ action.setEnabled(node.isValidFor(mode));
+ items.add(new ActionContributionItem(action));
+ }
+ }
+ catch (Exception e) {
+ if (Platform.inDebugMode()) e.printStackTrace();
}
- }
- catch (Exception e) {
- if (Platform.inDebugMode()) e.printStackTrace();
}
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/NewLaunchConfigurationContributionItem.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/NewLaunchConfigurationContributionItem.java
index 6b31d852d..8851aa5c9 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/NewLaunchConfigurationContributionItem.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/NewLaunchConfigurationContributionItem.java
@@ -67,21 +67,26 @@ public class NewLaunchConfigurationContributionItem extends CompoundContribution
/**
* Constructor.
+ *
* @param id
*/
public NewLaunchConfigurationContributionItem(String id) {
super(id);
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.menus.IWorkbenchContribution#initialize(org.eclipse.ui.services.IServiceLocator)
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.ui.menus.IWorkbenchContribution#initialize(org.eclipse.ui.services.IServiceLocator
+ * )
*/
@Override
public void initialize(IServiceLocator serviceLocator) {
this.serviceLocator = serviceLocator;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.eclipse.jface.action.ContributionItem#isEnabled()
*/
@Override
@@ -89,72 +94,94 @@ public class NewLaunchConfigurationContributionItem extends CompoundContribution
return enabled;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
*/
@Override
protected IContributionItem[] getContributionItems() {
// Get the selected node.
- IHandlerService service = (IHandlerService)serviceLocator.getService(IHandlerService.class);
+ IHandlerService service = (IHandlerService) serviceLocator
+ .getService(IHandlerService.class);
IEvaluationContext state = service.getCurrentState();
- ISelection selection = (ISelection)state.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
- IStructuredSelection iss = (IStructuredSelection)selection;
- Object obj = iss.getFirstElement();
+ ISelection selection = (ISelection) state
+ .getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
List<IContributionItem> items = new ArrayList<IContributionItem>();
- if (obj instanceof LaunchNode) {
- final LaunchNode node = (LaunchNode) obj;
- final ILaunchConfigurationType type = node.getLaunchConfigurationType();
- if (type != null) {
- try {
- for (String mode : LaunchConfigHelper.getLaunchConfigTypeModes(type, false)) {
- ILaunchManagerDelegate delegate = LaunchManager.getInstance().getLaunchManagerDelegate(type, mode);
- ILaunchSelection launchSelection = null;
- if (node.getModel().getModelRoot() instanceof ICategory) {
- launchSelection = LaunchSelectionManager.getInstance().getLaunchSelection(type, mode, LaunchSelectionManager.PART_ID_TE_VIEW);
- }
- else if (node.getModel().getModelRoot() instanceof IModelNode) {
- List<ISelectionContext> selectionContexts = new ArrayList<ISelectionContext>();
- selectionContexts.add(new RemoteSelectionContext((IModelNode)node.getModel().getModelRoot(), true));
- selectionContexts.addAll(LaunchSelectionManager.getInstance().getSelectionContextsFor(LaunchSelectionManager.PART_ID_PROJECT_VIEW, type, mode, false));
- launchSelection = new LaunchSelection(mode, selectionContexts.toArray(new ISelectionContext[selectionContexts.size()]));
- }
- else if (node.getModel().getModelRoot() instanceof IProject) {
- List<ISelectionContext> selectionContexts = new ArrayList<ISelectionContext>();
- selectionContexts.add(new ProjectSelectionContext((IProject)node.getModel().getModelRoot(), true));
- selectionContexts.addAll(LaunchSelectionManager.getInstance().getSelectionContextsFor(LaunchSelectionManager.PART_ID_TE_VIEW, type, mode, false));
- launchSelection = new LaunchSelection(mode, selectionContexts.toArray(new ISelectionContext[selectionContexts.size()]));
- }
- if (launchSelection != null) {
- final ILaunchSpecification launchSpec = delegate.getLaunchSpecification(type.getIdentifier(), launchSelection);
- final ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(type.newInstance(null, "temp"), mode); //$NON-NLS-1$
- ILaunchMode launchMode = DebugPlugin.getDefault().getLaunchManager().getLaunchMode(mode);
- IAction action = new Action() {
- @Override
- public void run() {
- try {
- ILaunchConfiguration config = LaunchManager.getInstance().createOrUpdateLaunchConfiguration(null, launchSpec);
- DebugUITools.openLaunchConfigurationDialogOnGroup(
- UIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),
- new StructuredSelection(config),
- launchGroup.getIdentifier());
- }
- catch (Exception e) {
- e.printStackTrace();
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection iss = (IStructuredSelection) selection;
+ Object obj = iss.getFirstElement();
+ if (obj instanceof LaunchNode) {
+ final LaunchNode node = (LaunchNode) obj;
+ final ILaunchConfigurationType type = node.getLaunchConfigurationType();
+ if (type != null) {
+ try {
+ for (String mode : LaunchConfigHelper.getLaunchConfigTypeModes(type, false)) {
+ ILaunchManagerDelegate delegate = LaunchManager.getInstance()
+ .getLaunchManagerDelegate(type, mode);
+ ILaunchSelection launchSelection = null;
+ if (node.getModel().getModelRoot() instanceof ICategory) {
+ launchSelection = LaunchSelectionManager
+ .getInstance()
+ .getLaunchSelection(type, mode, LaunchSelectionManager.PART_ID_TE_VIEW);
+ }
+ else if (node.getModel().getModelRoot() instanceof IModelNode) {
+ List<ISelectionContext> selectionContexts = new ArrayList<ISelectionContext>();
+ selectionContexts.add(new RemoteSelectionContext((IModelNode) node
+ .getModel().getModelRoot(), true));
+ selectionContexts
+ .addAll(LaunchSelectionManager
+ .getInstance()
+ .getSelectionContextsFor(LaunchSelectionManager.PART_ID_PROJECT_VIEW, type, mode, false));
+ launchSelection = new LaunchSelection(mode, selectionContexts.toArray(new ISelectionContext[selectionContexts
+ .size()]));
+ }
+ else if (node.getModel().getModelRoot() instanceof IProject) {
+ List<ISelectionContext> selectionContexts = new ArrayList<ISelectionContext>();
+ selectionContexts.add(new ProjectSelectionContext((IProject) node
+ .getModel().getModelRoot(), true));
+ selectionContexts
+ .addAll(LaunchSelectionManager
+ .getInstance()
+ .getSelectionContextsFor(LaunchSelectionManager.PART_ID_TE_VIEW, type, mode, false));
+ launchSelection = new LaunchSelection(mode, selectionContexts.toArray(new ISelectionContext[selectionContexts
+ .size()]));
+ }
+ if (launchSelection != null) {
+ final ILaunchSpecification launchSpec = delegate
+ .getLaunchSpecification(type.getIdentifier(), launchSelection);
+ final ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(type
+ .newInstance(null, "temp"), mode); //$NON-NLS-1$
+ ILaunchMode launchMode = DebugPlugin.getDefault()
+ .getLaunchManager().getLaunchMode(mode);
+ IAction action = new Action() {
+ @Override
+ public void run() {
+ try {
+ ILaunchConfiguration config = LaunchManager
+ .getInstance()
+ .createOrUpdateLaunchConfiguration(null, launchSpec);
+ DebugUITools.openLaunchConfigurationDialogOnGroup(UIPlugin
+ .getDefault().getWorkbench()
+ .getActiveWorkbenchWindow().getShell(), new StructuredSelection(config), launchGroup
+ .getIdentifier());
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
}
- }
- };
- action.setText(launchMode.getLabel() + " Configuration"); //$NON-NLS-1$
- action.setImageDescriptor(launchGroup.getImageDescriptor());
- items.add(new ActionContributionItem(action));
+ };
+ action.setText(launchMode.getLabel() + " Configuration"); //$NON-NLS-1$
+ action.setImageDescriptor(launchGroup.getImageDescriptor());
+ items.add(new ActionContributionItem(action));
+ }
}
}
- }
- catch (Exception e) {
- e.printStackTrace();
+ catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
}
-
enabled = !items.isEmpty();
return items.toArray(new IContributionItem[items.size()]);
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/OpenLaunchConfigurationContributionItem.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/OpenLaunchConfigurationContributionItem.java
index ab92a5b09..dd7365ceb 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/OpenLaunchConfigurationContributionItem.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/handler/OpenLaunchConfigurationContributionItem.java
@@ -56,21 +56,26 @@ public class OpenLaunchConfigurationContributionItem extends CompoundContributio
/**
* Constructor.
+ *
* @param id
*/
public OpenLaunchConfigurationContributionItem(String id) {
super(id);
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.menus.IWorkbenchContribution#initialize(org.eclipse.ui.services.IServiceLocator)
+ /*
+ * (non-Javadoc)
+ * @see
+ * org.eclipse.ui.menus.IWorkbenchContribution#initialize(org.eclipse.ui.services.IServiceLocator
+ * )
*/
@Override
public void initialize(IServiceLocator serviceLocator) {
this.serviceLocator = serviceLocator;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.eclipse.jface.action.ContributionItem#isEnabled()
*/
@Override
@@ -78,57 +83,63 @@ public class OpenLaunchConfigurationContributionItem extends CompoundContributio
return enabled;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
*/
@Override
protected IContributionItem[] getContributionItems() {
// Get the selected node.
- IHandlerService service = (IHandlerService)serviceLocator.getService(IHandlerService.class);
+ IHandlerService service = (IHandlerService) serviceLocator
+ .getService(IHandlerService.class);
IEvaluationContext state = service.getCurrentState();
- ISelection selection = (ISelection)state.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
- IStructuredSelection iss = (IStructuredSelection)selection;
- Object obj = iss.getFirstElement();
- Assert.isTrue(obj instanceof LaunchNode);
- final LaunchNode node = (LaunchNode) obj;
+ ISelection selection = (ISelection) state
+ .getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
List<IContributionItem> items = new ArrayList<IContributionItem>();
- final ILaunchConfigurationType type = node.getLaunchConfigurationType();
- final ILaunchConfiguration config;
- final boolean openConfig;
- if (node.getLaunchConfiguration() != null) {
- openConfig = true;
- config = node.getLaunchConfiguration();
- }
- else {
- openConfig = false;
- ILaunchConfiguration newConfig = null;
- try {
- newConfig = type.newInstance(null, "temp"); //$NON-NLS-1$
- }
- catch (Exception e) {
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection iss = (IStructuredSelection) selection;
+ Object obj = iss.getFirstElement();
+ Assert.isTrue(obj instanceof LaunchNode);
+ final LaunchNode node = (LaunchNode) obj;
+ final ILaunchConfigurationType type = node.getLaunchConfigurationType();
+ final ILaunchConfiguration config;
+ final boolean openConfig;
+ if (node.getLaunchConfiguration() != null) {
+ openConfig = true;
+ config = node.getLaunchConfiguration();
}
- config = newConfig;
- }
- if (type != null && config != null) {
- try {
- for (String mode : LaunchConfigHelper.getLaunchConfigTypeModes(type, false)) {
- final ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(config, mode);
- ILaunchMode launchMode = DebugPlugin.getDefault().getLaunchManager().getLaunchMode(mode);
- IAction action = new Action() {
- @Override
- public void run() {
- DebugUITools.openLaunchConfigurationDialogOnGroup(
- UIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),
- new StructuredSelection(openConfig ? config : type),
- launchGroup.getIdentifier());
- }
- };
- action.setText(launchMode.getLabel() + " Configuration" + (openConfig ? "" : "s") + "..."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- action.setImageDescriptor(launchGroup.getImageDescriptor());
- items.add(new ActionContributionItem(action));
+ else {
+ openConfig = false;
+ ILaunchConfiguration newConfig = null;
+ try {
+ newConfig = type.newInstance(null, "temp"); //$NON-NLS-1$
}
+ catch (Exception e) {
+ }
+ config = newConfig;
}
- catch (Exception e) {
+ if (type != null && config != null) {
+ try {
+ for (String mode : LaunchConfigHelper.getLaunchConfigTypeModes(type, false)) {
+ final ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(config, mode);
+ ILaunchMode launchMode = DebugPlugin.getDefault().getLaunchManager()
+ .getLaunchMode(mode);
+ IAction action = new Action() {
+ @Override
+ public void run() {
+ DebugUITools.openLaunchConfigurationDialogOnGroup(UIPlugin
+ .getDefault().getWorkbench()
+ .getActiveWorkbenchWindow().getShell(), new StructuredSelection(openConfig ? config : type), launchGroup
+ .getIdentifier());
+ }
+ };
+ action.setText(launchMode.getLabel() + " Configuration" + (openConfig ? "" : "s") + "..."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ action.setImageDescriptor(launchGroup.getImageDescriptor());
+ items.add(new ActionContributionItem(action));
+ }
+ }
+ catch (Exception e) {
+ }
}
}

Back to the top