summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMax Weninger2013-03-26 02:36:39 (EDT)
committer Tobias Schwarz2013-03-26 02:37:21 (EDT)
commit69d3e7072524ebdd4814435c8f2ce30451b7f8c3 (patch)
tree192f780ace6dbca7603cb227bf0b13853dcd66d1
parentf3bb909192d5839b01d964b9fb4e730d8ef66714 (diff)
downloadorg.eclipse.tcf-69d3e7072524ebdd4814435c8f2ce30451b7f8c3.zip
org.eclipse.tcf-69d3e7072524ebdd4814435c8f2ce30451b7f8c3.tar.gz
org.eclipse.tcf-69d3e7072524ebdd4814435c8f2ce30451b7f8c3.tar.bz2
Target Explorer: fix assertion
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/internal/handler/LaunchTerminalCommandHandler.java29
1 files changed, 27 insertions, 2 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/internal/handler/LaunchTerminalCommandHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/internal/handler/LaunchTerminalCommandHandler.java
index 669b376..af30834 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/internal/handler/LaunchTerminalCommandHandler.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/internal/handler/LaunchTerminalCommandHandler.java
@@ -11,16 +11,21 @@ package org.eclipse.tcf.te.ui.terminals.internal.handler;
import java.text.DateFormat;
import java.util.Date;
+import java.util.Map;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
+import org.eclipse.tcf.te.runtime.services.ServiceManager;
+import org.eclipse.tcf.te.runtime.services.interfaces.IPropertiesAccessService;
+import org.eclipse.tcf.te.runtime.services.interfaces.constants.IPropertiesAccessServiceConstants;
import org.eclipse.tcf.te.runtime.services.interfaces.constants.ITerminalsConnectorConstants;
import org.eclipse.tcf.te.ui.terminals.activator.UIPlugin;
import org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate;
@@ -58,6 +63,7 @@ public class LaunchTerminalCommandHandler extends AbstractHandler {
Shell shell = HandlerUtil.getActiveShell(event);
// Get the current selection
ISelection selection = HandlerUtil.getCurrentSelection(event);
+
if (commandId.equals("org.eclipse.tcf.te.ui.terminals.command.launchToolbar")) { //$NON-NLS-1$
if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) {
UIPlugin.getTraceHandler().trace("(a) Attempt to open launch terminal settings dialog after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$
@@ -65,7 +71,10 @@ public class LaunchTerminalCommandHandler extends AbstractHandler {
}
LaunchTerminalSettingsDialog dialog = new LaunchTerminalSettingsDialog(shell, start);
- dialog.setSelection(selection);
+
+ if(isValidSelection(selection)){
+ dialog.setSelection(selection);
+ }
if (dialog.open() == Window.OK) {
// Get the terminal settings from the dialog
IPropertiesContainer properties = dialog.getSettings();
@@ -100,7 +109,9 @@ public class LaunchTerminalCommandHandler extends AbstractHandler {
// Create the launch terminal settings dialog
LaunchTerminalSettingsDialog dialog = new LaunchTerminalSettingsDialog(shell, start);
- dialog.setSelection(selection);
+ if(isValidSelection(selection)){
+ dialog.setSelection(selection);
+ }
if (dialog.open() == Window.OK) {
// Get the terminal settings from the dialog
IPropertiesContainer properties = dialog.getSettings();
@@ -130,4 +141,18 @@ public class LaunchTerminalCommandHandler extends AbstractHandler {
return null;
}
+ private boolean isValidSelection(ISelection selection) {
+ if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
+ Object element = ((IStructuredSelection) selection).getFirstElement();
+ IPropertiesAccessService service = ServiceManager.getInstance().getService(element, IPropertiesAccessService.class);
+ if (service != null) {
+ Map<String, String> props = service.getTargetAddress(element);
+ if (props != null && props.containsKey(IPropertiesAccessServiceConstants.PROP_ADDRESS)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
}