diff options
Diffstat (limited to 'org.eclipse.debug.ui/ui/org/eclipse/debug/ui/launchVariables/expanders/ContainerNameExpander.java')
-rw-r--r-- | org.eclipse.debug.ui/ui/org/eclipse/debug/ui/launchVariables/expanders/ContainerNameExpander.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/launchVariables/expanders/ContainerNameExpander.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/launchVariables/expanders/ContainerNameExpander.java new file mode 100644 index 000000000..496bbb6bf --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/launchVariables/expanders/ContainerNameExpander.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.ui.launchVariables.expanders; + + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.variables.*; +import org.eclipse.debug.core.variables.ExpandVariableContext; +import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsMessages; + +/** + * Extracts the container name from a variable context. + * @since 3.0 + */ +public class ContainerNameExpander extends DefaultVariableExpander { + + /** + * @see IVariableTextExpander#getText(String, String, ExpandVariableContext) + */ + public String getText(String varTag, String varValue, ExpandVariableContext context) throws CoreException { + IResource resource= context.getSelectedResource(); + if (resource != null) { + IContainer parent= resource.getParent(); + if (parent != null) { + return parent.getName(); + } + throwExpansionException(varTag, LaunchConfigurationsMessages.getString("ContainerNameExpander.No_container_could_be_determined_for_the_selected_resource._1")); //$NON-NLS-1$ + } + throwExpansionException(varTag, LaunchConfigurationsMessages.getString("ContainerNameExpander.No_resource_selected._2")); //$NON-NLS-1$ + return null; + } + +} |