diff options
author | Tobias Schwarz | 2012-07-19 11:05:38 +0000 |
---|---|---|
committer | Uwe Stieber | 2012-07-19 11:12:05 +0000 |
commit | f32e7b0508a4b8dfaf11496957cfb8720a59a03e (patch) | |
tree | 71b6df8b6dff70dcfa30575bd903e0b15f1820b4 /target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core | |
parent | d5180015caac5bc65b5fa5948c3c5bd1508053e3 (diff) | |
download | org.eclipse.tcf-f32e7b0508a4b8dfaf11496957cfb8720a59a03e.tar.gz org.eclipse.tcf-f32e7b0508a4b8dfaf11496957cfb8720a59a03e.tar.xz org.eclipse.tcf-f32e7b0508a4b8dfaf11496957cfb8720a59a03e.zip |
Target Explorer: ADD change event listener to update attach launch configs when peer launch attributes are changing
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core')
3 files changed, 163 insertions, 74 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/activator/CoreBundleActivator.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/activator/CoreBundleActivator.java index 8b573bf8e..6cb026788 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/activator/CoreBundleActivator.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/activator/CoreBundleActivator.java @@ -1,72 +1,84 @@ -/*******************************************************************************
- * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. 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:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.tcf.launch.core.activator;
-
-import org.eclipse.tcf.te.runtime.tracing.TraceHandler;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class CoreBundleActivator implements BundleActivator {
- // The bundle context
- private static BundleContext context;
- // The trace handler instance
- private static volatile TraceHandler traceHandler;
-
- /**
- * Returns the bundle context
- *
- * @return the bundle context
- */
- public static BundleContext getContext() {
- return context;
- }
-
- /**
- * Convenience method which returns the unique identifier of this plugin.
- */
- public static String getUniqueIdentifier() {
- if (getContext() != null && getContext().getBundle() != null) {
- return getContext().getBundle().getSymbolicName();
- }
- return "org.eclipse.tcf.te.tcf.launch.core"; //$NON-NLS-1$
- }
-
- /**
- * Returns the bundles trace handler.
- *
- * @return The bundles trace handler.
- */
- public static TraceHandler getTraceHandler() {
- if (traceHandler == null) {
- traceHandler = new TraceHandler(getUniqueIdentifier());
- }
- return traceHandler;
- }
-
- /* (non-Javadoc)
- * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
- */
- @Override
- public void start(BundleContext bundleContext) throws Exception {
- CoreBundleActivator.context = bundleContext;
- }
-
- /* (non-Javadoc)
- * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- @Override
- public void stop(BundleContext bundleContext) throws Exception {
- CoreBundleActivator.context = null;
- traceHandler = null;
- }
-}
+/******************************************************************************* + * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.launch.core.activator; + +import org.eclipse.tcf.te.runtime.events.ChangeEvent; +import org.eclipse.tcf.te.runtime.events.EventManager; +import org.eclipse.tcf.te.runtime.interfaces.events.IEventListener; +import org.eclipse.tcf.te.runtime.tracing.TraceHandler; +import org.eclipse.tcf.te.tcf.launch.core.internal.EventListenerDelegate; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class CoreBundleActivator implements BundleActivator { + // The bundle context + private static BundleContext context; + // The trace handler instance + private static volatile TraceHandler traceHandler; + // The event listener to delegate peer attribute changes + private IEventListener eventListener; + + /** + * Returns the bundle context + * + * @return the bundle context + */ + public static BundleContext getContext() { + return context; + } + + /** + * Convenience method which returns the unique identifier of this plugin. + */ + public static String getUniqueIdentifier() { + if (getContext() != null && getContext().getBundle() != null) { + return getContext().getBundle().getSymbolicName(); + } + return "org.eclipse.tcf.te.tcf.launch.core"; //$NON-NLS-1$ + } + + /** + * Returns the bundles trace handler. + * + * @return The bundles trace handler. + */ + public static TraceHandler getTraceHandler() { + if (traceHandler == null) { + traceHandler = new TraceHandler(getUniqueIdentifier()); + } + return traceHandler; + } + + /* (non-Javadoc) + * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(BundleContext bundleContext) throws Exception { + CoreBundleActivator.context = bundleContext; + + eventListener = new EventListenerDelegate(); + EventManager.getInstance().addEventListener(eventListener, ChangeEvent.class); + } + + /* (non-Javadoc) + * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(BundleContext bundleContext) throws Exception { + CoreBundleActivator.context = null; + traceHandler = null; + + EventManager.getInstance().removeEventListener(eventListener); + eventListener = null; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/delegates/LaunchConfigurationDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/delegates/LaunchConfigurationDelegate.java index 75e96c7e6..082872250 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/delegates/LaunchConfigurationDelegate.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/delegates/LaunchConfigurationDelegate.java @@ -34,8 +34,7 @@ import org.eclipse.tcf.util.TCFTask; * <li>The launch configuration delegate creates launches of type {@link Launch}.</li> * </ul> */ -@SuppressWarnings("restriction") -public class LaunchConfigurationDelegate extends org.eclipse.tcf.te.launch.core.lm.internal.LaunchConfigurationDelegate { +public class LaunchConfigurationDelegate extends org.eclipse.tcf.te.launch.core.delegates.LaunchConfigurationDelegate { /* (non-Javadoc) * @see org.eclipse.tcf.te.launch.core.delegates.LaunchConfigurationDelegate#getLaunch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String) diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/EventListenerDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/EventListenerDelegate.java new file mode 100644 index 000000000..37fce2bc5 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/EventListenerDelegate.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2012 Wind River Systems, Inc. and others. 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ + +package org.eclipse.tcf.te.tcf.launch.core.internal; + +import java.util.EventObject; +import java.util.Map; + +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.te.launch.core.lm.LaunchConfigHelper; +import org.eclipse.tcf.te.launch.core.lm.interfaces.ICommonLaunchAttributes; +import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchContextLaunchAttributes; +import org.eclipse.tcf.te.launch.core.persistence.launchcontext.LaunchContextsPersistenceDelegate; +import org.eclipse.tcf.te.runtime.events.ChangeEvent; +import org.eclipse.tcf.te.runtime.interfaces.events.IEventListener; +import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode; +import org.eclipse.tcf.te.runtime.persistence.PersistenceManager; +import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate; +import org.eclipse.tcf.te.tcf.launch.core.interfaces.ILaunchTypes; +import org.eclipse.tcf.te.tcf.launch.core.interfaces.IPeerModelProperties; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; + +/** + * EventListenerDelegate + */ +public class EventListenerDelegate implements IEventListener { + + /** + * Constructor. + */ + public EventListenerDelegate() { + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.interfaces.events.IEventListener#eventFired(java.util.EventObject) + */ + @Override + public void eventFired(EventObject event) { + if (event instanceof ChangeEvent && event.getSource() instanceof IPeer) { + IPeer peer = (IPeer)event.getSource(); + String launchConfigAttributes = peer.getAttributes().get(IPeerModelProperties.PROP_LAUNCH_CONFIG_ATTRIBUTES); + try { + for (ILaunchConfiguration config : DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(ILaunchTypes.ATTACH))) { + IModelNode[] contexts = LaunchContextsPersistenceDelegate.getLaunchContexts(config); + if (contexts != null && contexts.length == 1 && contexts[0] instanceof IPeerModel && ((IPeerModel)contexts[0]).getPeerId().equalsIgnoreCase(peer.getID())) { + IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(Map.class, launchConfigAttributes, false); + try { + Map<String, String> attributes = (Map<String,String>)delegate.read(Map.class, launchConfigAttributes, null); + attributes.remove(ILaunchContextLaunchAttributes.ATTR_LAUNCH_CONTEXTS); + attributes.remove(ICommonLaunchAttributes.ATTR_UUID); + attributes.remove(ICommonLaunchAttributes.ATTR_LAST_LAUNCHED); + ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); + for (String key : attributes.keySet()) { + LaunchConfigHelper.addLaunchConfigAttribute(wc, key, attributes.get(key)); + } + wc.doSave(); + } + catch (Exception e) { + } + + } + } + } + catch (Exception e) { + } + } + } +} |