1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 437392 Initial commit of LaunchBar.

The LaunchBar is a Tool Control that allows the user to select an
active launch configuration, launch mode, and a new concept, a launch
target, and the build for that combination and launch that combination.
It also provides shortcuts to create launch configurations, and edit
their properties using the existing launch config edit dialog.

Change-Id: I8c6c9b72fed9052c03d2028c4611c78872d971c4
Reviewed-on: https://git.eclipse.org/r/28727
Tested-by: Hudson CI
Reviewed-by: Doug Schaefer <dschaefer@qnx.com>
This commit is contained in:
Doug Schaefer 2014-06-18 22:44:08 -04:00
parent 397b269e26
commit c2da55547c
55 changed files with 4312 additions and 0 deletions

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.launchbar.core</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7

View file

@ -0,0 +1,12 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: LaunchBar Core
Bundle-SymbolicName: org.eclipse.cdt.launchbar.core
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.eclipse.cdt.launchbar.core.internal.Activator
Bundle-Vendor: Eclipse CDT
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.debug.core;bundle-version="3.9.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.cdt.launchbar.core

View file

@ -0,0 +1,24 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head>
<body lang="EN-US">
<h2>About This Content</h2>
<p>June 22, 2007</p>
<h3>License</h3>
<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
indicated below, the Content is provided to you under the terms and conditions of the
Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
For purposes of the EPL, "Program" will mean the Content.</p>
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
being redistributed by another party ("Redistributor") and different terms and conditions may
apply to your use of any object code in the Content. Check the Redistributor's license that was
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
</body></html>

View file

@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.cdt</groupId>
<artifactId>cdt-parent</artifactId>
<version>8.4.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<version>1.0.0-SNAPSHOT</version>
<artifactId>org.eclipse.cdt.launchbar.core</artifactId>
<packaging>eclipse-plugin</packaging>
</project>

View file

@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.ILaunchMode;
public interface ILaunchBarManager extends IAdaptable {
ILaunchConfigurationDescriptor[] getLaunchConfigurationDescriptors();
ILaunchConfigurationDescriptor getActiveLaunchConfigurationDescriptor();
void setActiveLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc) throws CoreException;
void addLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc) throws CoreException;
void removeLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc);
ILaunchMode[] getLaunchModes() throws CoreException;
ILaunchMode getActiveLaunchMode();
void setActiveLaunchMode(ILaunchMode mode);
ILaunchTarget[] getLaunchTargets();
ILaunchTarget getActiveLaunchTarget();
void setActiveLaunchTarget(ILaunchTarget target);
void addLaunchTarget(ILaunchTarget target);
void removeLaunchTarget(ILaunchTarget target);
interface Listener {
void activeConfigurationDescriptorChanged();
void activeLaunchModeChanged();
void activeLaunchTargetChanged();
}
void addListener(Listener listener);
void removeListener(Listener listener);
}

View file

@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
public interface ILaunchConfigurationDescriptor {
/**
* Name to show in the launch configuration selector.
*
* @return name of the launch configuration
*/
String getName();
/**
* The type of launch configuration supported by this descriptor.
*
* @return
*/
ILaunchConfigurationType getLaunchConfigurationType() throws CoreException;
/**
* The corresponding launch configuration.
* If this launch config hasn't been created yet, it will be
*
* @return the corresponding launch configuration
* @throws CoreException
*/
ILaunchConfiguration getLaunchConfiguration() throws CoreException;
/**
* Is this launch configuration managed by this descriptor.
*
* @param launchConfiguration
* @return
*/
boolean matches(ILaunchConfiguration launchConfiguration);
}

View file

@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
/**
* Provides the list of launch configurations
*
*/
public interface ILaunchConfigurationsProvider {
/**
* Called after existing launch configs have been added. The provider
* can now add any more that they'd like to have.
*/
void init(ILaunchBarManager manager);
/**
* If the provider has a better descriptor than the suggested one, return a better one.
* Otherwise, return the one that was passed in.
*
* @param descriptor candidate descriptor
* @return the best descriptor
*/
ILaunchConfigurationDescriptor filterDescriptor(ILaunchConfigurationDescriptor descriptor);
}

View file

@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
public interface ILaunchTarget {
String getName();
ILaunchTargetType getType();
}

View file

@ -0,0 +1,17 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
public interface ILaunchTargetType {
String getId();
}

View file

@ -0,0 +1,75 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
public class Activator implements BundleActivator {
public static final String PLUGIN_ID = "org.eclipse.cdt.launchbar.core";
private static BundleContext context;
private LaunchBarManager launchBarManager;
static BundleContext getContext() {
return context;
}
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
bundleContext.registerService(ILaunchBarManager.class, new ServiceFactory<ILaunchBarManager>() {
@Override
public synchronized ILaunchBarManager getService(Bundle bundle, ServiceRegistration<ILaunchBarManager> registration) {
if (launchBarManager == null) {
launchBarManager = new LaunchBarManager();
new Job("Init LaunchBar Manager") {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
launchBarManager.init();
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();
}
}
}.schedule();;
}
return launchBarManager;
}
@Override
public synchronized void ungetService(Bundle bundle,
ServiceRegistration<ILaunchBarManager> registration,
ILaunchBarManager service) {
}
}, null);
}
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
launchBarManager = null;
}
public static void throwCoreException(Exception e) throws CoreException {
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e));
}
}

View file

@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
public class DefaultLaunchConfigurationDescriptor implements ILaunchConfigurationDescriptor {
final ILaunchConfiguration config;
public DefaultLaunchConfigurationDescriptor(ILaunchConfiguration config) {
this.config = config;
}
@Override
public String getName() {
return config.getName();
}
@Override
public ILaunchConfiguration getLaunchConfiguration() throws CoreException {
return config;
}
@Override
public ILaunchConfigurationType getLaunchConfigurationType() throws CoreException{
return config.getType();
}
@Override
public boolean matches(ILaunchConfiguration launchConfiguration) {
return config.equals(launchConfiguration);
}
}

View file

@ -0,0 +1,309 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core.internal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationsProvider;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationListener;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.ILaunchMode;
public class LaunchBarManager extends PlatformObject implements ILaunchBarManager, ILaunchConfigurationListener {
private List<Listener> listeners = new LinkedList<>();
private List<ProviderExtensionDescriptor> providers = new ArrayList<>();
private Map<String, ILaunchConfigurationDescriptor> configDescs = new HashMap<>();
private ILaunchConfigurationDescriptor activeConfigDesc;
private ILaunchMode[] launchModes;
private ILaunchMode activeLaunchMode;
private final LocalTargetType localTargetType = new LocalTargetType();
private static final String PREF_ACTIVE_CONFIG_DESC = "activeConfigDesc";
private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode";
private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget";
private class ProviderExtensionDescriptor {
private ILaunchConfigurationsProvider provider;
private int priority;
public ProviderExtensionDescriptor(ILaunchConfigurationsProvider provider, int priority) {
super();
this.provider = provider;
this.priority = priority;
}
public ILaunchConfigurationsProvider getProvider() {
return provider;
}
public int getPriority() {
return priority;
}
}
void init() throws CoreException {
IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(
Activator.PLUGIN_ID,
"launchConfigProvider");
for (IConfigurationElement element : elements) {
ILaunchConfigurationsProvider provider = (ILaunchConfigurationsProvider) element.createExecutableExtension("class");
String priorityString = element.getAttribute("priority");
int priority = 1; // Default is 1
if (priorityString != null) {
try {
priority = Integer.parseInt(priorityString);
} catch (NumberFormatException e) {
Activator.throwCoreException(e);
}
}
providers.add(new ProviderExtensionDescriptor(provider, priority));
}
Collections.sort(providers, new Comparator<ProviderExtensionDescriptor>() {
@Override
public int compare(ProviderExtensionDescriptor o1, ProviderExtensionDescriptor o2) {
int p1 = o1.getPriority();
int p2 = o2.getPriority();
if (p1 > p2)
return 1;
else if (p1 < p2)
return -1;
else
return 0;
}
});
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) {
launchConfigurationAdded(configuration);
}
for (ProviderExtensionDescriptor providerDesc : providers) {
providerDesc.getProvider().init(this);
}
launchManager.addLaunchConfigurationListener(this);
// Load up the active from the preferences or pick reasonable defaults
IEclipsePreferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
String activeConfigDescName = store.get(PREF_ACTIVE_CONFIG_DESC, null);
if (activeConfigDescName == null && !configDescs.isEmpty()) {
activeConfigDescName = configDescs.values().iterator().next().getName();
}
if (activeConfigDescName != null) {
ILaunchConfigurationDescriptor configDesc = configDescs.get(activeConfigDescName);
if (configDesc != null) {
setActiveLaunchConfigurationDescriptor(configDesc);
}
}
}
@Override
public void launchConfigurationAdded(ILaunchConfiguration configuration) {
ILaunchConfigurationDescriptor configDesc = new DefaultLaunchConfigurationDescriptor(configuration);
for (ProviderExtensionDescriptor provider : providers) {
configDesc = provider.getProvider().filterDescriptor(configDesc);
}
try {
addLaunchConfigurationDescriptor(configDesc);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void launchConfigurationChanged(ILaunchConfiguration configuration) {
// TODO Auto-generated method stub
}
@Override
public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
// TODO Auto-generated method stub
}
@Override
public ILaunchConfigurationDescriptor[] getLaunchConfigurationDescriptors() {
ILaunchConfigurationDescriptor[] descs = configDescs.values().toArray(new ILaunchConfigurationDescriptor[configDescs.size()]);
Arrays.sort(descs, new Comparator<ILaunchConfigurationDescriptor>() {
@Override
public int compare(ILaunchConfigurationDescriptor o1, ILaunchConfigurationDescriptor o2) {
return o1.getName().compareTo(o2.getName());
}
});
return descs;
}
@Override
public ILaunchConfigurationDescriptor getActiveLaunchConfigurationDescriptor() {
return activeConfigDesc;
}
@Override
public void setActiveLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc) throws CoreException {
if (activeConfigDesc == configDesc)
return;
activeConfigDesc = configDesc;
// Get the launch modes
List<ILaunchMode> mymodes = new ArrayList<>();
ILaunchConfigurationType type = activeConfigDesc.getLaunchConfigurationType();
ILaunchMode[] modes = DebugPlugin.getDefault().getLaunchManager().getLaunchModes();
for (ILaunchMode mode : modes) {
if (type.supportsMode(mode.getIdentifier())) {
mymodes.add(mode);
}
}
launchModes = mymodes.toArray(new ILaunchMode[mymodes.size()]);
// Get the launch targets
// TODO
// Send notifications
for (Listener listener : listeners) {
listener.activeConfigurationDescriptorChanged();
}
// Set active mode
IEclipsePreferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
String activeModeName = store.get(PREF_ACTIVE_LAUNCH_MODE, null);
boolean foundMode = false;
if (activeModeName != null) {
for (ILaunchMode mode : launchModes) {
if (activeModeName.equals(mode.getIdentifier())) {
setActiveLaunchMode(mode);
foundMode = true;
break;
}
}
}
if (!foundMode) {
if (launchModes.length > 0) {
ILaunchMode mode = getLaunchMode("debug");
if (mode == null) {
mode = getLaunchMode("run");
}
if (mode == null) {
mode = launchModes[0];
}
setActiveLaunchMode(mode);
} else {
setActiveLaunchMode(null);
}
}
}
@Override
public void addLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc) throws CoreException {
configDescs.put(configDesc.getName(), configDesc);
setActiveLaunchConfigurationDescriptor(configDesc);
}
@Override
public void removeLaunchConfigurationDescriptor(
ILaunchConfigurationDescriptor configDesc) {
// TODO Auto-generated method stub
}
@Override
public ILaunchMode[] getLaunchModes() throws CoreException {
return launchModes;
}
public ILaunchMode getLaunchMode(String id) {
for (ILaunchMode mode : launchModes)
if (id.equals(mode.getIdentifier()))
return mode;
return null;
}
@Override
public ILaunchMode getActiveLaunchMode() {
return activeLaunchMode;
}
@Override
public void setActiveLaunchMode(ILaunchMode mode) {
if (activeLaunchMode == mode)
return;
activeLaunchMode = mode;
for (Listener listener : listeners)
listener.activeLaunchModeChanged();
}
@Override
public ILaunchTarget[] getLaunchTargets() {
// TODO for reals
return new ILaunchTarget[] { localTargetType.getTarget() };
}
@Override
public ILaunchTarget getActiveLaunchTarget() {
// TODO for reals
return localTargetType.getTarget();
}
@Override
public void setActiveLaunchTarget(ILaunchTarget target) {
// TODO Auto-generated method stub
}
@Override
public void addLaunchTarget(ILaunchTarget target) {
// TODO Auto-generated method stub
}
@Override
public void removeLaunchTarget(ILaunchTarget target) {
// TODO Auto-generated method stub
}
@Override
public void addListener(Listener listener) {
listeners.add(listener);
}
@Override
public void removeListener(Listener listener) {
listeners.remove(listener);
}
}

View file

@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.ILaunchTargetType;
public class LocalTarget implements ILaunchTarget {
private final LocalTargetType type;
public LocalTarget(LocalTargetType type) {
this.type = type;
}
@Override
public String getName() {
return "Local Machine";
}
@Override
public ILaunchTargetType getType() {
return type;
}
}

View file

@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.ILaunchTargetType;
public class LocalTargetType implements ILaunchTargetType {
private final LocalTarget target;
public LocalTargetType() {
target = new LocalTarget(this);
}
@Override
public String getId() {
return "org.eclipse.cdt.launchbar.target.local";
}
public LocalTarget getTarget() {
return target;
}
}

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.launchbar.ui</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7

View file

@ -0,0 +1,21 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: LaunchBar UI
Bundle-SymbolicName: org.eclipse.cdt.launchbar.ui;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.eclipse.cdt.launchbar.ui.internal.Activator
Bundle-Vendor: Eclipse CDT
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.e4.ui.workbench,
org.eclipse.e4.ui.model.workbench,
org.eclipse.e4.core.di,
org.eclipse.e4.core.services,
org.eclipse.osgi.services,
org.eclipse.cdt.launchbar.core,
org.eclipse.debug.ui,
org.eclipse.ui.workbench,
org.eclipse.ui.ide
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin

View file

@ -0,0 +1,24 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head>
<body lang="EN-US">
<h2>About This Content</h2>
<p>June 22, 2007</p>
<h3>License</h3>
<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
indicated below, the Content is provided to you under the terms and conditions of the
Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
For purposes of the EPL, "Program" will mean the Content.</p>
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
being redistributed by another party ("Redistributor") and different terms and conditions may
apply to your use of any object code in the Content. Check the Redistributor's license that was
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
</body></html>

View file

@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 358 B

View file

@ -0,0 +1 @@
launchToolBar.label = LaunchBar

View file

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
id="launchBarInjector"
point="org.eclipse.e4.workbench.model">
<processor
apply="always"
beforefragment="false"
class="org.eclipse.cdt.launchbar.ui.internal.LaunchBarInjector">
</processor>
</extension>
<extension
point="org.eclipse.core.runtime.adapters">
<factory
adaptableType="org.eclipse.cdt.launchbar.core.ILaunchBarManager"
class="org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManagerAdapterFactory">
<adapter
type="org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager">
</adapter>
</factory>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="org.eclipse.cdt.launchbar.ui.internal.commands.BuildActiveCommandHandler"
id="org.eclipse.cdt.launchbar.ui.command.buildActive"
name="Build Active Configuration">
</command>
<command
defaultHandler="org.eclipse.cdt.launchbar.ui.internal.commands.LaunchActiveCommandHandler"
id="org.eclipse.cdt.launchbar.ui.command.launchActive"
name="Launch Active Configuration">
</command>
<command
defaultHandler="org.eclipse.cdt.launchbar.ui.internal.commands.StopActiveCommandHandler"
id="org.eclipse.cdt.launchbar.ui.command.stop"
name="Stop">
</command>
<command
defaultHandler="org.eclipse.cdt.launchbar.ui.internal.commands.ConfigureActiveLaunchHandler"
id="org.eclipse.cdt.launchbar.ui.command.configureActiveLaunch"
name="Configure Active Launch Configuration">
</command>
</extension>
</plugin>

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.cdt</groupId>
<artifactId>cdt-parent</artifactId>
<version>8.4.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<version>1.0.0-SNAPSHOT</version>
<artifactId>org.eclipse.cdt.launchbar.ui</artifactId>
<packaging>eclipse-plugin</packaging>
</project>

View file

@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui;
public interface IHoverProvider {
/**
* Display the hover item.
*
* @return true if hover item was displayed, otherwise false
*/
public abstract boolean displayHover(Object element);
/**
* Dismiss the hover item.
*
* @param immediate
* if true, the hover item will be immediately dismissed, otherwise it may be be dismissed at a later time.
*/
public abstract void dismissHover(Object element, boolean immediate);
}

View file

@ -0,0 +1,17 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui;
public interface ILaunchBarUIConstants {
public static final String TARGET_NAME = "targetName";
}

View file

@ -0,0 +1,138 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.IParameter;
import org.eclipse.core.commands.Parameterization;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.cdt.launchbar.ui"; //$NON-NLS-1$
// Images
public static final String IMG_BUTTON_BUILD = "build";
public static final String IMG_BUTTON_LAUNCH = "launch";
public static final String IMG_BUTTON_STOP = "stop";
// Command ids
public static final String CMD_BUILD = "org.eclipse.cdt.launchbar.ui.command.buildActive";
public static final String CMD_LAUNCH = "org.eclipse.cdt.launchbar.ui.command.launchActive";
public static final String CMD_STOP = "org.eclipse.cdt.launchbar.ui.command.stop";
public static final String CMD_CONFIG = "org.eclipse.cdt.launchbar.ui.command.configureActiveLaunch";
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
ImageRegistry imageRegistry = getImageRegistry();
imageRegistry.put(IMG_BUTTON_BUILD, imageDescriptorFromPlugin(PLUGIN_ID, "icons/build.png"));
imageRegistry.put(IMG_BUTTON_LAUNCH, imageDescriptorFromPlugin(PLUGIN_ID, "icons/launch.png"));
imageRegistry.put(IMG_BUTTON_STOP, imageDescriptorFromPlugin(PLUGIN_ID, "icons/stop.png"));
}
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
public Image getImage(String id) {
return getImageRegistry().get(id);
}
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
public static void runCommand(String commandId, String... params) {
final ICommandService commandService = (ICommandService) PlatformUI.getWorkbench()
.getService(ICommandService.class);
Command command = commandService.getCommand(commandId);
final Event trigger = new Event();
final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench()
.getService(IHandlerService.class);
ExecutionEvent executionEvent = handlerService.createExecutionEvent(command, trigger);
if (params.length == 0) {
try {
command.executeWithChecks(executionEvent);
} catch (OperationCanceledException e) {
// abort
} catch (Exception e) {
log(e);
}
} else {
try {
final Parameterization[] parameterizations = new Parameterization[params.length / 2];
for (int i = 0; i < params.length; i += 2) {
IParameter param = command.getParameter(params[i]);
Parameterization parm = new Parameterization(param, params[i + 1]);
parameterizations[i / 2] = parm;
}
ParameterizedCommand parmCommand = new ParameterizedCommand(command, parameterizations);
handlerService.executeCommand(parmCommand, null);
} catch (Exception e) {
log(e);
}
}
}
public static void log(CoreException e) {
plugin.getLog().log(e.getStatus());
}
public static void log(Exception e) {
plugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e));
}
public static <T> T getService(Class<T> cls) {
BundleContext context = getDefault().getBundle().getBundleContext();
ServiceReference<T> ref = context.getServiceReference(cls);
return ref != null ? context.getService(ref) : null;
}
}

View file

@ -0,0 +1,79 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal;
import javax.inject.Inject;
import org.eclipse.cdt.launchbar.ui.internal.controls.LaunchBarControl;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.SideValue;
import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar;
import org.eclipse.e4.ui.model.application.ui.basic.MTrimElement;
import org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
import org.eclipse.e4.ui.model.application.ui.menu.MToolControl;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
public class LaunchBarInjector {
@Inject
MApplication application;
@Inject
IEventBroker eventBroker;
@Execute
void execute() {
// Inject the toolbar into all top trims
for (MWindow window : application.getChildren()) {
if (window instanceof MTrimmedWindow) {
for (MTrimBar trimBar : ((MTrimmedWindow) window).getTrimBars()) {
if (trimBar.getSide() == SideValue.TOP) {
injectLaunchBar(trimBar);
}
}
}
}
// Watch for new trimmed windows and inject there too.
eventBroker.subscribe(UIEvents.TrimmedWindow.TOPIC_TRIMBARS, new EventHandler() {
@Override
public void handleEvent(Event event) {
if (!UIEvents.isADD(event))
return;
Object newValue = event.getProperty(UIEvents.EventTags.NEW_VALUE);
if (newValue instanceof MTrimBar) {
MTrimBar trimBar = (MTrimBar) newValue;
if (trimBar.getSide() == SideValue.TOP)
injectLaunchBar(trimBar);
}
}
});
}
void injectLaunchBar(MTrimBar trimBar) {
// Skip if we're already there
for (MTrimElement trimElement : trimBar.getChildren())
if (LaunchBarControl.ID.equals(trimElement.getElementId()))
return;
MToolControl launchBar = MMenuFactory.INSTANCE.createToolControl();
launchBar.setElementId(LaunchBarControl.ID);
launchBar.setContributionURI(LaunchBarControl.CLASS_URI);
trimBar.getChildren().add(0, launchBar);
}
}

View file

@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.ui.IHoverProvider;
import org.eclipse.jface.viewers.ILabelProvider;
public class LaunchBarUIManager {
ILaunchBarManager manager;
public LaunchBarUIManager(ILaunchBarManager manager) {
this.manager = manager;
}
public ILaunchBarManager getManager() {
return manager;
}
public ILabelProvider getLabelProvider(ILaunchConfigurationDescriptor configDesc) {
// TODO
return null;
}
public ILabelProvider getLabelProvider(ILaunchTarget target) {
// TODO
return null;
}
public String getEditCommand(ILaunchTarget target) {
// TODO
return null;
}
public IHoverProvider getHoverProvider(ILaunchTarget target) {
// TODO
return null;
}
public String getAddTargetCommand(ILaunchConfigurationDescriptor configDesc) {
// TODO
return null;
}
}

View file

@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.core.runtime.IAdapterFactory;
public class LaunchBarUIManagerAdapterFactory implements IAdapterFactory {
private static Map<ILaunchBarManager, LaunchBarUIManager> uiProvider = new HashMap<>();
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adaptableObject instanceof ILaunchBarManager && adapterType.equals(LaunchBarUIManager.class)) {
ILaunchBarManager manager = (ILaunchBarManager) adaptableObject;
LaunchBarUIManager uiManager = uiProvider.get(manager);
if (uiManager == null) {
uiManager = new LaunchBarUIManager(manager);
uiProvider.put(manager, uiManager);
}
return uiManager;
}
return null;
}
@Override
public Class[] getAdapterList() {
return new Class[] { LaunchBarUIManager.class };
}
}

View file

@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal;
import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.launchbar.ui.internal.messages"; //$NON-NLS-1$
public static String LaunchBarControl_Build;
public static String LaunchBarControl_Launch;
public static String LaunchBarControl_Stop;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}
private Messages() {
}
}

View file

@ -0,0 +1,201 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.commands;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchDelegate;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate2;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.BuildAction;
import org.eclipse.ui.ide.ResourceUtil;
import org.eclipse.ui.progress.UIJob;
/**
* Build active project
*/
public class BuildActiveCommandHandler extends AbstractHandler {
private final ILaunchBarManager launchBarManager;
public BuildActiveCommandHandler() {
launchBarManager = Activator.getService(ILaunchBarManager.class);
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
new UIJob(Display.getDefault(), "Building Active Configuration") {
public IStatus runInUIThread(IProgressMonitor monitor) {
final ILaunchConfigurationDescriptor desc = launchBarManager.getActiveLaunchConfigurationDescriptor();
if (desc == null) {
// popout - No launch configuration
// showConfigurationErrorCallOut(NLS.bind("{0}\n{1}", Messages.RunActiveCommandHandler_No_Launch_Configuration_Selected,
// Messages.RunActiveCommandHanlder_Create_Launch_Configuration));
}
new Job("Building Active Configuration") {
@Override
public boolean belongsTo(Object family) {
return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family);
}
protected IStatus run(IProgressMonitor monitor) {
try {
if (desc == null) {
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
return Status.OK_STATUS;
}
ILaunchMode launchMode = launchBarManager.getActiveLaunchMode();
ILaunchConfiguration config = desc.getLaunchConfiguration();
Collection<IProject> projects = getProjects(config);
if (BuildAction.isSaveAllSet()) {
saveEditors(projects);
}
String mode = launchMode.getIdentifier();
Set<String> modes = new HashSet<>();
modes.add(mode);
ILaunchDelegate delegate = config.getType().getPreferredDelegate(modes);
if (delegate == null)
delegate = config.getType().getDelegates(modes)[0];
ILaunchConfigurationDelegate configDel = delegate.getDelegate();
if (configDel instanceof ILaunchConfigurationDelegate2) {
ILaunchConfigurationDelegate2 configDel2 = (ILaunchConfigurationDelegate2)configDel;
boolean ret;
ret = configDel2.preLaunchCheck(config, mode, monitor);
if (!ret)
return Status.CANCEL_STATUS;
if (!configDel2.buildForLaunch(config, mode, monitor))
return Status.OK_STATUS;
}
// Fall through, do a normal build
if (projects.isEmpty()) {
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
} else {
Collection<IBuildConfiguration> buildConfigs = getBuildConfigs(projects);
ResourcesPlugin.getWorkspace().build(buildConfigs.toArray(new IBuildConfiguration[buildConfigs.size()]),
IncrementalProjectBuilder.INCREMENTAL_BUILD, true, monitor);
// TODO, may need to get the buildReferences argument from the descriptor
}
} catch (CoreException e) {
return e.getStatus();
}
return Status.OK_STATUS;
}
}.schedule();
return Status.OK_STATUS;
};
}.schedule();
return Status.OK_STATUS;
}
protected Collection<IProject> getProjects(ILaunchConfiguration config) {
Set<IProject> projects = new HashSet<>();
IResource[] mappedResources;
try {
mappedResources = config.getMappedResources();
} catch (CoreException e) {
return projects;
}
if (mappedResources != null) {
for (IResource resource : mappedResources) {
IProject project = resource.getProject();
if (projects.contains(project))
continue;
projects.add(project);
try {
projects.addAll(Arrays.asList(project.getReferencedProjects()));
} catch (CoreException e) {
// skip
}
}
}
return projects;
}
protected Collection<IBuildConfiguration> getBuildConfigs(Collection<IProject> projects) {
Set<IBuildConfiguration> configs = new HashSet<>();
for (IProject project : projects) {
try {
configs.add(project.getActiveBuildConfig());
} catch (CoreException e) {
// skip
}
}
return configs;
}
protected void saveEditors(final Collection<IProject> projects) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
for (IWorkbenchWindow window : windows) {
IWorkbenchPage[] pages = window.getPages();
for (IWorkbenchPage page : pages) {
if (projects.isEmpty()) {
page.saveAllEditors(false);
} else {
IEditorPart[] editors = page.getDirtyEditors();
for (IEditorPart editor : editors) {
IFile inputFile = ResourceUtil.getFile(editor.getEditorInput());
if (inputFile != null) {
if (projects.contains(inputFile.getProject())) {
page.saveEditor(editor, false);
}
}
}
}
}
}
}
});
}
}

View file

@ -0,0 +1,70 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.commands;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.ILaunchGroup;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.handlers.HandlerUtil;
public class ConfigureActiveLaunchHandler extends AbstractHandler {
private final ILaunchBarManager launchBarManager;
public ConfigureActiveLaunchHandler() {
launchBarManager = Activator.getService(ILaunchBarManager.class);
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ILaunchConfigurationDescriptor activeLaunchConfiguration = launchBarManager.getActiveLaunchConfigurationDescriptor();
ILaunchMode activeLaunchMode = launchBarManager.getActiveLaunchMode();
if (activeLaunchConfiguration == null)
return Status.OK_STATUS;
ILaunchConfiguration launchConfiguration;
try {
launchConfiguration = activeLaunchConfiguration.getLaunchConfiguration();
} catch (CoreException e1) {
return e1.getStatus();
}
try {
ILaunchConfigurationWorkingCopy wc = launchConfiguration.getWorkingCopy();
// TODO, gah, this is internal. Get it added to DebugUIUtil
ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(launchConfiguration.getType(), activeLaunchMode.getIdentifier());
if (DebugUITools.openLaunchConfigurationPropertiesDialog(HandlerUtil.getActiveShell(event), wc, group.getIdentifier()) == Window.OK)
wc.doSave();
} catch (CoreException e) {
return e.getStatus();
}
return Status.OK_STATUS;
}
protected String getMode() {
return "config"; //$NON-NLS-1$
}
}

View file

@ -0,0 +1,100 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.commands;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.progress.UIJob;
public class LaunchActiveCommandHandler extends AbstractHandler {
private final ILaunchBarManager launchBarManager;
public LaunchActiveCommandHandler() {
launchBarManager = Activator.getService(ILaunchBarManager.class);
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
new UIJob(Display.getDefault(), "Launching Active Configuration") {
public IStatus runInUIThread(IProgressMonitor monitor) {
try {
ILaunchConfigurationDescriptor desc = launchBarManager.getActiveLaunchConfigurationDescriptor();
if (desc == null) {
// popout - No launch configuration
// showConfigurationErrorCallOut(NLS.bind("{0}\n{1}", Messages.RunActiveCommandHandler_No_Launch_Configuration_Selected,
// Messages.RunActiveCommandHanlder_Create_Launch_Configuration));
return Status.OK_STATUS;
}
ILaunchMode launchMode = launchBarManager.getActiveLaunchMode();
ILaunchTarget target = launchBarManager.getActiveLaunchTarget();
if (target == null) {
// popout - No target
// if (TargetCorePlugin.getDefault().getTargetRegistry().getTargets().length == 1) {
// showTargetErrorCallOut(NLS.bind("{0}{1}", Messages.RunActiveCommandHandler_Cannot, getMode(launchMode)),
// DeviceErrors.Error.NO_DEVICES, Messages.RunActiveCommandHandler_Select_Manage_Devices);
// } else { // Don't think this can occur. Leaving just in case.
// showTargetErrorCallOut(NLS.bind("{0}{1}", Messages.RunActiveCommandHandler_Cannot, getMode(launchMode)),
// DeviceErrors.Error.NO_ACTIVE, Messages.RunActiveCommandHandler_Select_Device_Or_Simulator);
// }
return Status.OK_STATUS;
}
DebugUITools.launch(desc.getLaunchConfiguration(), launchMode.getIdentifier());
} catch (CoreException e) {
return e.getStatus();
}
return Status.OK_STATUS;
};
}.schedule();
return Status.OK_STATUS;
}
protected void showConfigurationErrorCallOut(final String error) {
// Control activeProjectControl = LaunchToolBar.getInstance().getActiveConfigurationControl();
// showErrorToolTipOnControl(error, activeProjectControl);
}
// protected void showTargetErrorCallOut(final String title, DeviceErrors.Error e, String action) {
// Control activeTargetControl = LaunchToolBar.getInstance().getActiveTargetControl();
// DeviceErrors.showCallOutErrorOnControl(activeTargetControl, title, e, action);
// }
public static void showErrorToolTipOnControl(final String error, Control activeProjectControl) {
// CalloutError tip = new CalloutError();
// tip.setTarget(activeProjectControl);
// tip.setHook(Position.BOTTOM_CENTER, Position.TOP_CENTER, new Point(0, 0));
// tip.setData(error);
// tip.show();
}
protected String getMode(ILaunchMode launchMode) {
return launchMode.getIdentifier(); //$NON-NLS-1$
}
}

View file

@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.commands;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
public class StopActiveCommandHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// TODO
return null;
}
}

View file

@ -0,0 +1,103 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.controls;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
public class CButton extends Canvas {
private boolean inButton;
private Image hotImage;
private Image coldImage;
public CButton(Composite parent, int style) {
super(parent, style);
addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
if (inButton) {
if (hotImage != null) {
e.gc.drawImage(hotImage, 0, 0);
} else if (coldImage != null) {
e.gc.drawImage(coldImage, 0, 0);
}
} else {
if (coldImage != null) {
e.gc.drawImage(coldImage, 0, 0);
} else if (hotImage != null) {
e.gc.drawImage(hotImage, 0, 0);
}
}
}
});
addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseEnter(MouseEvent e) {
inButton = true;
redraw();
}
@Override
public void mouseExit(MouseEvent e) {
inButton = false;
redraw();
}
});
}
@Override
public void dispose() {
super.dispose();
if (hotImage != null)
hotImage.dispose();
if (coldImage != null)
coldImage.dispose();
}
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
int width = 0;
int height = 0;
if (hotImage != null) {
Rectangle bounds = hotImage.getBounds();
width = bounds.width;
height = bounds.height;
}
if (coldImage != null) {
Rectangle bounds = coldImage.getBounds();
if (bounds.width > width)
width = bounds.width;
if (bounds.height > height)
height = bounds.height;
}
return new Point(width, height);
}
public void setHotImage(Image image) {
this.hotImage = image;
}
public void setColdImage(Image image) {
this.coldImage = image;
}
}

View file

@ -0,0 +1,854 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.controls;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.launchbar.ui.IHoverProvider;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.LineAttributes;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
public class CSelector extends Composite implements ISelectionProvider {
private IStructuredContentProvider contentProvider;
private ILabelProvider labelProvider;
private IHoverProvider hoverProvider;
private Comparator<Object> sorter;
private Object input;
private Composite buttonComposite;
private String toolTipText;
private boolean toolTipWasModified; // Used for the hover provider
private static final int arrowMax = 2;
private Transition arrowTransition;
private IStructuredSelection selection;
private List<ISelectionChangedListener> selectionChangedListeners = new LinkedList<>();
protected final Color backgroundColor;
protected final Color outlineColor;
protected final Color highlightColor;
protected final Color white;
private boolean mouseOver;
private Image editImage;
private boolean inEditButton;
private Image buttonImage;
private Label currentIcon;
private Label currentLabel;
private Shell popup;
private ListItem listItems[];
private int selIndex;
private ScrolledComposite listScrolled;
private final int itemH = 30;
private int scrollBucket;
private final int maxScrollBucket = 7;
private MouseTrackListener mouseTrackListener = new MouseTrackListener() {
@Override
public void mouseEnter(MouseEvent e) {
if (!mouseOver) {
mouseOver = true;
redraw();
if (toolTipWasModified) {
buttonComposite.setToolTipText(toolTipText);
if (currentLabel != null) {
currentLabel.setToolTipText(toolTipText);
}
if (currentIcon != null) {
currentIcon.setToolTipText(toolTipText);
}
}
}
}
@Override
public void mouseHover(MouseEvent e) {
if (hoverProvider != null && (popup == null || popup.isDisposed())) {
final Object eventSource = e.getSource();
if ((eventSource == currentLabel || eventSource == buttonComposite || eventSource == currentIcon)) {
if (hoverProvider.displayHover(CSelector.this.selection.getFirstElement())) {
buttonComposite.setToolTipText("");
if (currentLabel != null) {
currentLabel.setToolTipText("");
}
if (currentIcon != null) {
currentIcon.setToolTipText("");
}
toolTipWasModified = true;
}
}
}
}
@Override
public void mouseExit(MouseEvent e) {
if (mouseOver) {
mouseOver = false;
redraw();
}
}
};
private MouseListener mouseListener = new MouseAdapter() {
@Override
public void mouseUp(MouseEvent event) {
if (popup == null || popup.isDisposed()) {
openPopup();
} else {
closePopup();
}
}
};
private Listener focusOutListener = new Listener() {
@Override
public void handleEvent(Event event) {
switch (event.type) {
case SWT.FocusOut:
Control focusControl = getDisplay().getFocusControl();
if (focusControl != null && focusControl.getShell() == popup) {
Point loc = getDisplay().getCursorLocation();
if (!getBounds().contains(toControl(loc))) {
// Don't do it if we're in the selector, we'll deal with that later
closePopup();
}
}
break;
case SWT.MouseUp:
if (popup != null && !popup.isDisposed()) {
Point loc = getDisplay().getCursorLocation();
if (!popup.getBounds().contains(loc) && !getBounds().contains(toControl(loc))) {
closePopup();
}
}
break;
}
}
};
public CSelector(Composite parent, int style) {
super(parent, style);
backgroundColor = new Color(getDisplay(), new RGB(249, 249, 249));
outlineColor = new Color(getDisplay(), new RGB(189, 195, 200));
highlightColor = new Color(getDisplay(), new RGB(223, 239, 241));
white = getDisplay().getSystemColor(SWT.COLOR_WHITE);
GridLayout mainButtonLayout = new GridLayout();
setLayout(mainButtonLayout);
addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
GC gc = e.gc;
gc.setBackground(backgroundColor);
gc.setForeground(outlineColor);
Point size = getSize();
final int arc = 3;
gc.fillRoundRectangle(0, 0, size.x - 1, size.y - 1, arc, arc);
gc.drawRoundRectangle(0, 0, size.x - 1, size.y - 1, arc, arc);
}
});
addMouseListener(mouseListener);
addMouseTrackListener(mouseTrackListener);
}
@Override
public void dispose() {
super.dispose();
backgroundColor.dispose();
outlineColor.dispose();
highlightColor.dispose();
if (editImage != null)
editImage.dispose();
if (buttonImage != null)
buttonImage.dispose();
if (popup != null)
popup.dispose();
}
@Override
public void addSelectionChangedListener(ISelectionChangedListener listener) {
selectionChangedListeners.add(listener);
}
@Override
public void removeSelectionChangedListener(
ISelectionChangedListener listener) {
selectionChangedListeners.remove(listener);
}
@Override
public void setSelection(ISelection selection) {
if (!(selection instanceof IStructuredSelection))
return;
IStructuredSelection newSelection = (IStructuredSelection) selection;
if (this.selection != null && newSelection.getFirstElement() == this.selection.getFirstElement())
// Already selected
return;
this.selection = newSelection;
if (buttonComposite != null)
buttonComposite.dispose();
toolTipText = getToolTipText();
boolean editable = false;
int columns = 2;
Object element = null;
element = this.selection.getFirstElement();
Image image = labelProvider.getImage(element);
if (image != null)
columns++;
editable = isEditable(element);
if (editable)
columns++;
buttonComposite = new Composite(this, SWT.NONE);
GridLayout buttonLayout = new GridLayout(columns, false);
buttonLayout.marginHeight = buttonLayout.marginWidth = 0;
buttonComposite.setLayout(buttonLayout);
buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
buttonComposite.setBackground(backgroundColor);
buttonComposite.addMouseListener(mouseListener);
buttonComposite.addMouseTrackListener(mouseTrackListener);
buttonComposite.setToolTipText(toolTipText);
if (element != null) {
if (image != null) {
Label icon = createImage(buttonComposite, image);
icon.addMouseListener(mouseListener);
icon.addMouseTrackListener(mouseTrackListener);
currentIcon = icon;
currentIcon.setToolTipText(toolTipText);
}
Label label = createLabel(buttonComposite, element);
label.addMouseListener(mouseListener);
label.addMouseTrackListener(mouseTrackListener);
currentLabel = label;
currentLabel.setToolTipText(toolTipText);
} else {
Composite blank = new Composite(buttonComposite, SWT.NONE);
blank.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
currentIcon = null;
currentLabel = null;
}
final Canvas arrow = new Canvas(buttonComposite, SWT.NONE) {
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
return new Point(12, 16);
}
};
arrow.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
arrow.setBackground(backgroundColor);
arrowTransition = new Transition(arrow, arrowMax, 80);
arrow.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
final int hPadding = 2;
GC gc = e.gc;
LineAttributes attributes = new LineAttributes(2);
attributes.cap = SWT.CAP_ROUND;
gc.setLineAttributes(attributes);
gc.setAlpha(mouseOver ? 255 : 100);
Rectangle bounds = arrow.getBounds();
int arrowWidth = bounds.width - hPadding * 2;
int current = arrowTransition.getCurrent();
gc.drawPolyline(new int[] { hPadding,
bounds.height / 2 - current,
hPadding + (arrowWidth / 2),
bounds.height / 2 + current, hPadding + arrowWidth,
bounds.height / 2 - current });
}
});
arrow.addMouseListener(mouseListener);
arrow.addMouseTrackListener(mouseTrackListener);
if (editable) {
Control editButton = createEditButton(buttonComposite, element);
editButton.setBackground(backgroundColor);
editButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
// Need to run this after the current event storm
// Or we get a disposed error.
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (CSelector.this.selection != null)
handleEdit(CSelector.this.selection.getFirstElement());
}
});
}
});
}
layout();
fireSelectionChanged();
}
private void fireSelectionChanged() {
SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
for (ISelectionChangedListener listener : selectionChangedListeners) {
listener.selectionChanged(event);
}
}
@Override
public IStructuredSelection getSelection() {
return selection;
}
public MouseListener getMouseListener() {
return mouseListener;
}
public MouseTrackListener getMouseTrackListener() {
return mouseTrackListener;
}
protected void openPopup() {
Object[] elements = contentProvider.getElements(input);
if (elements.length == 0 && !hasActionArea())
return;
arrowTransition.to(-arrowMax);
if (popup != null && !popup.isDisposed()) {
popup.dispose();
}
popup = new Shell(getShell(), SWT.TOOL | SWT.ON_TOP);
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = 0;
layout.verticalSpacing = 0;
popup.setLayout(layout);
listScrolled = new ScrolledComposite(popup, SWT.V_SCROLL | SWT.NO_BACKGROUND);
listScrolled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
listScrolled.setExpandHorizontal(true);
Composite listComp = new Composite(listScrolled, SWT.NONE);
listScrolled.setContent(listComp);
layout = new GridLayout();
layout.marginHeight = layout.marginWidth = 0;
layout.verticalSpacing = 0;
listComp.setLayout(layout);
for (Control child : listComp.getChildren())
child.dispose();
Arrays.sort(elements, sorter);
listItems = new ListItem[elements.length];
int heightHint = 0;
for (int i = 0; i < elements.length; ++i) {
listItems[i] = new ListItem(listComp, SWT.NONE, elements[i], i);
if (i < maxScrollBucket) { // this is how many visible by default
listItems[i].lazyInit();
if (i == 0) {
heightHint = listItems[0].computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
}
} else {
GridData gd = (GridData) listItems[i].getLayoutData();
gd.heightHint = heightHint;
}
}
Point listCompSize = listComp.computeSize(SWT.DEFAULT, SWT.DEFAULT);
listComp.setSize(listCompSize);
if (hasActionArea())
createActionArea(popup);
Rectangle buttonBounds = getBounds();
Point popupLocation = popup.getDisplay().map(this, null, 0,
buttonBounds.height);
popup.setLocation(popupLocation.x, popupLocation.y + 5);
Point size = popup.computeSize(SWT.DEFAULT, SWT.DEFAULT);
Point buttonSize = getSize();
size.x = Math.min(size.x + 16, buttonSize.x * 4 / 3);
size.y = Math.min(size.y, 250);
popup.setSize(size);
popup.setVisible(true);
popup.setFocus();
getDisplay().addFilter(SWT.FocusOut, focusOutListener);
getDisplay().addFilter(SWT.MouseUp, focusOutListener);
popup.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
getDisplay().removeFilter(SWT.FocusOut, focusOutListener);
getDisplay().removeFilter(SWT.MouseUp, focusOutListener);
}
});
selIndex = -1;
scrollBucket = 0;
if (hoverProvider != null) {
hoverProvider.dismissHover(selection != null ? selection.getFirstElement() : null, true);
}
}
private void closePopup() {
arrowTransition.to(arrowMax);
popup.setVisible(false);
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
popup.dispose();
}
});
}
TraverseListener listItemTraverseListener = new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e) {
final ListItem currItem = selIndex >=0 ? listItems[selIndex] : null;
if (currItem == null && e.keyCode != SWT.ARROW_DOWN) {
return;
}
if (e.detail == SWT.TRAVERSE_ARROW_NEXT || e.detail == SWT.TRAVERSE_TAB_NEXT) {
if (inEditButton || e.keyCode == SWT.ARROW_DOWN) {
int maxIdx = listItems.length -1;
if (selIndex < maxIdx) {
inEditButton = false;
if (currItem != null)
currItem.setBackground(white);
// move to next item
selIndex++;
if (scrollBucket < maxScrollBucket) {
scrollBucket++;
} else {
// need to scroll the list up 1 item
int sY = listScrolled.getOrigin().y;
listScrolled.setOrigin(0, sY + itemH);
}
listItems[selIndex].setBackground(highlightColor);
} else if (selIndex == maxIdx && maxIdx > maxScrollBucket) {
// level the scroll for any offset at the bottom of the list
listScrolled.setOrigin(0, itemH * (maxIdx - maxScrollBucket +1));
}
} else if (currItem.editButton != null) {
// move focus on edit button
inEditButton = true;
currItem.editButton.redraw();
}
} else if (e.detail == SWT.TRAVERSE_ARROW_PREVIOUS || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
if (!inEditButton || e.keyCode == SWT.ARROW_UP) {
if (selIndex > 0) {
inEditButton = false;
currItem.setBackground(white);
// move to previous item
selIndex--;
if (scrollBucket > 0) {
scrollBucket--;
} else {
// need to scroll the list down 1 item
int sY = listScrolled.getOrigin().y;
listScrolled.setOrigin(0, sY - itemH);
}
listItems[selIndex].setBackground(highlightColor);
} else if (selIndex == 0) {
// level any offset @ beginning
listScrolled.setOrigin(0, 0);
}
} else if (currItem.editButton != null) {
// remove focus from edit button
inEditButton = false;
currItem.editButton.redraw();
}
} else if (e.detail == SWT.TRAVERSE_RETURN) {
if (inEditButton) {
inEditButton = false;
// edit button in list item was pressed
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (CSelector.this.selection != null)
handleEdit(currItem.element);
}
});
} else {
// list item was pressed
popup.dispose();
setSelection(new StructuredSelection(currItem.element));
}
} else if (e.detail == SWT.TRAVERSE_ESCAPE) {
popup.dispose();
}
}
};
private class ListItem extends Composite {
protected final Object element;
private Label icon;
private Label label;
protected Control editButton;
private int index;
public ListItem(Composite parent, int style, Object _element, int index) {
super(parent, style);
this.element = _element;
this.index = index;
setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
Point size = getSize();
GC gc = e.gc;
gc.setForeground(outlineColor);
gc.drawLine(0, size.y - 1, size.x, size.y - 1);
if (label == null)
lazyInit();
}
});
// lazyInit();
} // end ListItem(..)
protected void lazyInit() {
Image image = labelProvider.getImage(element);
boolean editable = isEditable(element);
int columns = 1;
if (image != null)
columns++;
if (editable)
columns++;
GridLayout layout = new GridLayout(columns, false);
layout.marginWidth = layout.marginHeight = 7;
setLayout(layout);
MouseListener listItemMouseListener = new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
popup.dispose();
setSelection(new StructuredSelection(element));
}
};
MouseTrackListener listItemMouseTrackListener = new MouseTrackAdapter() {
@Override
public void mouseEnter(MouseEvent e) {
setBackground(highlightColor);
int idx = getIndex();
if (idx != selIndex) {
if (selIndex >= 0) {
listItems[selIndex].setBackground(white);
scrollBucket = Math.max(Math.min(scrollBucket + idx - selIndex, maxScrollBucket), 0);
} else { // initially
scrollBucket = Math.min(idx, maxScrollBucket);
}
}
selIndex = idx;
}
@Override
public void mouseExit(MouseEvent e) {
setBackground(white);
}
};
addMouseListener(listItemMouseListener);
addMouseTrackListener(listItemMouseTrackListener);
if (image != null) {
icon = createImage(this, image);
icon.addMouseListener(listItemMouseListener);
icon.addMouseTrackListener(listItemMouseTrackListener);
}
label = createLabel(this, element);
label.addMouseListener(listItemMouseListener);
label.addMouseTrackListener(listItemMouseTrackListener);
if (editable) {
editButton = createEditButton(this, element);
editButton.setBackground(white);
editButton.addMouseTrackListener(listItemMouseTrackListener);
editButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
// Need to run this after the current event storm
// Or we get a disposed error.
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (CSelector.this.selection != null)
handleEdit(element);
}
});
}
});
editButton.addTraverseListener(listItemTraverseListener);
} else {
addTraverseListener(listItemTraverseListener);
}
setBackground(white);
layout(true);
}
@Override
public void setBackground(Color color) {
super.setBackground(color);
if (icon != null && !icon.isDisposed())
icon.setBackground(color);
if (!label.isDisposed())
label.setBackground(color);
if (editButton != null && !editButton.isDisposed())
editButton.setBackground(color);
}
public void setImage(Image image) {
if (icon != null && !icon.isDisposed())
icon.setImage(image);
}
public void setText(String text) {
if (!label.isDisposed())
label.setText(text);
}
protected int getIndex() {
return index;
}
} // end ListItem class
private Label createImage(Composite parent, Image image) {
Rectangle bounds = image.getBounds();
boolean disposeImage = false;
if (bounds.height > 16 || bounds.width > 16) {
buttonImage = new Image(getDisplay(), 16, 16);
GC gc = new GC(buttonImage);
gc.setAntialias(SWT.ON);
gc.setInterpolation(SWT.HIGH);
gc.drawImage(image, 0, 0, image.getBounds().width,
image.getBounds().height, 0, 0, 16, 16);
gc.dispose();
image = buttonImage;
}
Label icon = new Label(parent, SWT.NONE);
icon.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
icon.setImage(image);
if (disposeImage) {
final Image disposableImage = image;
icon.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
disposableImage.dispose();
}
});
}
return icon;
}
private Label createLabel(Composite parent, Object element) {
Label label = new Label(parent, SWT.NONE);
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
label.setText(labelProvider.getText(element));
label.setFont(getDisplay().getSystemFont());
return label;
}
private Control createEditButton(Composite parent, Object element) {
if (editImage == null) {
editImage = Activator.getImageDescriptor("icons/config_config.png").createImage();
}
final Canvas editButton = new Canvas(parent, SWT.NONE) {
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
Rectangle bounds = editImage.getBounds();
return new Point(bounds.width, bounds.height);
};
};
editButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
editButton.setToolTipText("Edit");
editButton.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
GC gc = e.gc;
gc.setAlpha(inEditButton ? 255 : 64);
gc.drawImage(editImage, 0, 0);
}
});
editButton.addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseEnter(MouseEvent e) {
inEditButton = true;
editButton.redraw();
}
@Override
public void mouseExit(MouseEvent e) {
inEditButton = false;
editButton.redraw();
}
});
return editButton;
}
public void setContentProvider(IStructuredContentProvider contentProvider) {
this.contentProvider = contentProvider;
}
public IStructuredContentProvider getContentProvider() {
return contentProvider;
}
public void setLabelProvider(ILabelProvider labelProvider) {
this.labelProvider = labelProvider;
}
public ILabelProvider getLabelProvider() {
return labelProvider;
}
public void setHoverProvider(IHoverProvider hoverProvider) {
this.hoverProvider = hoverProvider;
}
public IHoverProvider getHoverProvider() {
return hoverProvider;
}
public void setSorter(Comparator<Object> sorter) {
this.sorter = sorter;
}
public void setInput(Object input) {
this.input = input;
}
public Object getInput() {
return input;
}
public void refresh() {
// TODO add any new ones to the popup if it's open
}
public void update(Object element) {
if (selection.getFirstElement() == element) {
if (currentIcon != null && !currentIcon.isDisposed()) {
currentIcon.setImage(labelProvider.getImage(element));
}
if (currentLabel != null && !currentLabel.isDisposed()) {
currentLabel.setText(labelProvider.getText(element));
}
}
if (popup != null && !popup.isDisposed()) {
Object[] elements = contentProvider.getElements(input);
int i;
for (i = 0; i < elements.length; ++i)
if (element == elements[i])
break;
if (i != elements.length) {
listItems[i].setImage(labelProvider.getImage(element));
listItems[i].setText(labelProvider.getText(element));
}
}
}
protected boolean hasActionArea() {
return false;
}
protected void createActionArea(Composite parent) {
// empty
}
protected boolean isEditable(Object element) {
return false;
}
protected void handleEdit(Object element) {
// nothing to do here
}
}

View file

@ -0,0 +1,294 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.controls;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager;
import org.eclipse.cdt.launchbar.ui.internal.dialogs.LaunchConfigurationEditDialog;
import org.eclipse.cdt.launchbar.ui.internal.dialogs.NewLaunchConfigWizard;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.ILaunchGroup;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
@SuppressWarnings("restriction")
public class ConfigSelector extends CSelector {
private LaunchBarUIManager uiManager;
private static final ISelection nullSelection = new StructuredSelection("No Launch Configurations");
public ConfigSelector(Composite parent, int style) {
super(parent, style);
setToolTipText("Launch configuration");
setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
ILaunchConfigurationDescriptor[] descs = getManager().getLaunchConfigurationDescriptors();
if (descs.length == 0) {
return new String[] { "No Launch Configurations" };
} else {
return descs;
}
}
});
setLabelProvider(new LabelProvider() {
private Map<ImageDescriptor, Image> images = new HashMap<>();
@Override
public void dispose() {
super.dispose();
for (Image image : images.values()) {
image.dispose();
}
}
@Override
public Image getImage(Object element) {
if (element instanceof ILaunchConfigurationDescriptor) {
ILaunchConfigurationDescriptor configDesc = (ILaunchConfigurationDescriptor)element;
ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc);
if (labelProvider != null) {
return labelProvider.getImage(element);
}
// Default
try {
ILaunchConfigurationType type = configDesc.getLaunchConfigurationType();
ImageDescriptor imageDescriptor = DebugUITools.getDefaultImageDescriptor(type);
if (imageDescriptor != null) {
Image image = images.get(imageDescriptor);
if (image == null) {
image = imageDescriptor.createImage();
images.put(imageDescriptor, image);
}
return image;
}
} catch (CoreException e) {
Activator.log(e);
}
}
// Default
return null;
}
@Override
public String getText(Object element) {
if (element instanceof String) {
return (String)element;
} else if (element instanceof ILaunchConfigurationDescriptor) {
ILaunchConfigurationDescriptor configDesc = (ILaunchConfigurationDescriptor)element;
ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc);
if (labelProvider != null) {
return labelProvider.getText(element);
}
// Default
return configDesc.getName();
}
return null;
}
});
setSorter(new Comparator<Object>() {
@Override
public int compare(Object o1, Object o2) {
String text1 = getLabelProvider().getText(o1);
String text2 = getLabelProvider().getText(o2);
return text1.compareTo(text2);
}
});
addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
Object selected = getSelection().getFirstElement();
if (selected instanceof ILaunchConfigurationDescriptor) {
ILaunchConfigurationDescriptor configDesc = (ILaunchConfigurationDescriptor) selected;
try {
getManager().setActiveLaunchConfigurationDescriptor(configDesc);
} catch (CoreException e) {
Activator.log(e);
}
}
}
});
}
@Override
public boolean isEditable(Object element) {
return element instanceof ILaunchConfigurationDescriptor;
}
@Override
public void handleEdit(Object element) {
try {
ILaunchConfigurationDescriptor config = (ILaunchConfigurationDescriptor) element;
ILaunchMode mode = getManager().getActiveLaunchMode();
ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager()
.getLaunchGroup(config.getLaunchConfiguration().getType(), mode.getIdentifier());
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
LaunchGroupExtension groupExt = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(group.getIdentifier());
if (groupExt != null) {
final LaunchConfigurationEditDialog dialog = new LaunchConfigurationEditDialog(shell, config.getLaunchConfiguration(), groupExt);
dialog.setInitialStatus(Status.OK_STATUS);
dialog.open();
}
} catch (CoreException e2) {
Activator.log(e2);
}
}
@Override
public boolean hasActionArea() {
return true;
}
@Override
public void createActionArea(Composite parent) {
Composite actionArea = new Composite(parent, SWT.NONE);
GridLayout actionLayout = new GridLayout();
actionLayout.marginWidth = actionLayout.marginHeight = 0;
actionArea.setLayout(actionLayout);
actionArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
final Composite createButton = new Composite(actionArea, SWT.NONE);
createButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
GridLayout buttonLayout = new GridLayout();
buttonLayout.marginWidth = buttonLayout.marginHeight = 7;
createButton.setLayout(buttonLayout);
createButton.setBackground(white);
createButton.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
Point size = createButton.getSize();
GC gc = e.gc;
gc.setForeground(outlineColor);
gc.drawLine(0, 0, size.x, 0);
}
});
final Label createLabel = new Label(createButton, SWT.None);
createLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
createLabel.setText("Create New Configuration...");
createLabel.setBackground(white);
MouseListener mouseListener = new MouseAdapter() {
public void mouseUp(org.eclipse.swt.events.MouseEvent e) {
final NewLaunchConfigWizard wizard = new NewLaunchConfigWizard();
WizardDialog dialog = new WizardDialog(getShell(), wizard);
if (dialog.open() == Window.OK) {
new Job("Create Launch Configuration") {
protected IStatus run(IProgressMonitor monitor) {
try {
wizard.getWorkingCopy().doSave();
ILaunchMode lm = wizard.getLaunchMode();
getManager().setActiveLaunchMode(lm);
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();
}
};
}.schedule();
}
}
};
createButton.addMouseListener(mouseListener);
createLabel.addMouseListener(mouseListener);
MouseTrackListener mouseTrackListener = new MouseTrackAdapter() {
@Override
public void mouseEnter(MouseEvent e) {
createButton.setBackground(highlightColor);
createLabel.setBackground(highlightColor);
}
@Override
public void mouseExit(MouseEvent e) {
createButton.setBackground(white);
createLabel.setBackground(white);
}
};
createButton.addMouseTrackListener(mouseTrackListener);
createLabel.addMouseTrackListener(mouseTrackListener);
}
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
return super.computeSize(250, hHint, changed);
}
private ILaunchBarManager getManager() {
return (ILaunchBarManager) getInput();
}
@Override
public void setInput(Object input) {
super.setInput(input);
uiManager = (LaunchBarUIManager) ((ILaunchBarManager) input).getAdapter(LaunchBarUIManager.class);
}
@Override
public void setSelection(ISelection selection) {
if (selection == null)
super.setSelection(nullSelection);
else
super.setSelection(selection);
}
}

View file

@ -0,0 +1,148 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.controls;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.cdt.launchbar.ui.internal.Messages;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
public class LaunchBarControl implements ILaunchBarManager.Listener {
public static final String ID = "org.eclipse.cdt.launchbar"; //$NON-NLS-1$
public static final String CLASS_URI = "bundleclass://" + Activator.PLUGIN_ID + "/" + LaunchBarControl.class.getName(); //$NON-NLS-1$ //$NON-NLS-2$
@Inject
private ILaunchBarManager manager;
private ConfigSelector configSelector;
private ModeSelector modeSelector;
private TargetSelector targetSelector;
@PostConstruct
public void createControl(Composite parent) {
manager.addListener(this);
Composite container = new Composite(parent, SWT.NONE);
container.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
GridLayout layout = new GridLayout(7, false);
container.setLayout(layout);
createButton(container, Activator.IMG_BUTTON_BUILD, Messages.LaunchBarControl_Build, Activator.CMD_BUILD);
createButton(container, Activator.IMG_BUTTON_LAUNCH, Messages.LaunchBarControl_Launch, Activator.CMD_LAUNCH);
createButton(container, Activator.IMG_BUTTON_STOP, Messages.LaunchBarControl_Stop, Activator.CMD_STOP);
modeSelector = new ModeSelector(container, SWT.NONE);
modeSelector.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
modeSelector.setInput(manager);
configSelector = new ConfigSelector(container, SWT.NONE);
configSelector.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
configSelector.setInput(manager);
Label label = new Label(container, SWT.NONE);
label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
label.setText("on" + ":");
targetSelector = new TargetSelector(container, SWT.NONE);
targetSelector.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
targetSelector.setInput(manager);
ILaunchConfigurationDescriptor configDesc = manager.getActiveLaunchConfigurationDescriptor();
configSelector.setSelection(configDesc == null ? null : new StructuredSelection(configDesc));
ILaunchMode mode = manager.getActiveLaunchMode();
modeSelector.setSelection(mode == null ? null : new StructuredSelection(mode));
ILaunchTarget target = manager.getActiveLaunchTarget();
targetSelector.setSelection(target == null ? null : new StructuredSelection(target));
}
@PreDestroy
public void shutdown() {
manager.removeListener(this);
}
private void createButton(Composite parent, String imageName, String toolTipText, final String command) {
CButton button = new CButton(parent, SWT.NONE);
button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
Image srcImage = Activator.getDefault().getImage(imageName);
Image image = new Image(parent.getDisplay(), srcImage, SWT.IMAGE_COPY);
button.setHotImage(image);
button.setToolTipText(toolTipText);
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
Activator.runCommand(command);
}
});
}
@Override
public void activeConfigurationDescriptorChanged() {
if (configSelector != null && !configSelector.isDisposed()) {
final ILaunchConfigurationDescriptor configDesc = manager.getActiveLaunchConfigurationDescriptor();
configSelector.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (!configSelector.isDisposed())
configSelector.setSelection(configDesc == null ? null : new StructuredSelection(configDesc));
}
});
}
}
@Override
public void activeLaunchModeChanged() {
if (modeSelector != null && !modeSelector.isDisposed()) {
final ILaunchMode mode = manager.getActiveLaunchMode();
modeSelector.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (!modeSelector.isDisposed())
modeSelector.setSelection(mode == null ? null : new StructuredSelection(mode));
}
});
}
}
@Override
public void activeLaunchTargetChanged() {
if (targetSelector != null && !targetSelector.isDisposed()) {
final ILaunchTarget target = manager.getActiveLaunchTarget();
targetSelector.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (!targetSelector.isDisposed())
targetSelector.setSelection(target == null ? null : new StructuredSelection(target));
}
});
}
}
}

View file

@ -0,0 +1,172 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.controls;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.ui.ILaunchGroup;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
@SuppressWarnings("restriction")
public class ModeSelector extends CSelector {
private static final ISelection nullSelection = new StructuredSelection("---");
public ModeSelector(Composite parent, int style) {
super(parent, style);
setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
try {
return getManager().getLaunchModes();
} catch (CoreException e) {
Activator.log(e);
return new Object[0];
}
}
});
setLabelProvider(new LabelProvider() {
private Map<ImageDescriptor, Image> images = new HashMap<>();
@Override
public void dispose() {
super.dispose();
for (Image image : images.values()) {
image.dispose();
}
}
@Override
public Image getImage(Object element) {
ILaunchConfigurationDescriptor config = getManager().getActiveLaunchConfigurationDescriptor();
if (config != null && element instanceof ILaunchMode) {
ILaunchMode mode = (ILaunchMode) element;
try {
ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager()
.getLaunchGroup(config.getLaunchConfigurationType(), mode.getIdentifier());
if (group != null) {
ImageDescriptor imageDesc = group.getImageDescriptor();
Image image = images.get(imageDesc);
if (image == null) {
image = imageDesc.createImage();
images.put(imageDesc, image);
}
return image;
}
} catch (CoreException e) {
Activator.log(e);
}
}
return super.getImage(element);
}
@Override
public String getText(Object element) {
ILaunchConfigurationDescriptor config = getManager().getActiveLaunchConfigurationDescriptor();
if (config != null && element instanceof ILaunchMode) {
ILaunchMode mode = (ILaunchMode) element;
try {
ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager()
.getLaunchGroup(config.getLaunchConfigurationType(), mode.getIdentifier());
if (group != null) {
return group.getLabel().replace("&", "");
}
} catch (CoreException e) {
Activator.log(e);
}
}
return super.getText(element);
}
});
setSorter(new Comparator<Object>() {
@Override
public int compare(Object o1, Object o2) {
if (o1 instanceof ILaunchMode && o2 instanceof ILaunchMode) {
String mode1 = ((ILaunchMode)o1).getIdentifier();
String mode2 = ((ILaunchMode)o2).getIdentifier();
// run comes first, then debug, then the rest
if (mode1.equals("run")) {
if (mode2.equals("run"))
return 0;
else
return -1;
}
if (mode2.equals("run"))
return 1;
if (mode1.equals("debug")) {
if (mode2.equals("debug"))
return 0;
else
return -1;
}
if (mode2.equals("debug"))
return 1;
}
return 0;
}
});
setToolTipText("Launch configuration");
addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
Object selected = getSelection().getFirstElement();
if (selected instanceof ILaunchMode) {
ILaunchMode mode = (ILaunchMode) selected;
getManager().setActiveLaunchMode(mode);
}
}
});
}
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
return super.computeSize(150, hHint, changed);
}
private ILaunchBarManager getManager() {
return (ILaunchBarManager) getInput();
}
@Override
public void setSelection(ISelection selection) {
if (selection == null)
super.setSelection(nullSelection);
else
super.setSelection(selection);
}
}

View file

@ -0,0 +1,229 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.controls;
import java.util.Comparator;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.ui.IHoverProvider;
import org.eclipse.cdt.launchbar.ui.ILaunchBarUIConstants;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
public class TargetSelector extends CSelector {
private final LaunchBarUIManager uiManager;
private static final ISelection nullSelection = new StructuredSelection("---");
public TargetSelector(Composite parent, int style) {
super(parent, style);
ILaunchBarManager manager = Activator.getService(ILaunchBarManager.class);
uiManager = (LaunchBarUIManager) manager.getAdapter(LaunchBarUIManager.class);
setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput,
Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
return getManager().getLaunchTargets();
}
});
setLabelProvider(new LabelProvider() {
@Override
public Image getImage(Object element) {
if (element instanceof ILaunchTarget) {
ILaunchTarget target = (ILaunchTarget) element;
ILabelProvider labelProvider = uiManager.getLabelProvider(target);
if (labelProvider != null) {
return labelProvider.getImage(element);
}
}
return super.getImage(element);
}
@Override
public String getText(Object element) {
if (element instanceof ILaunchTarget) {
ILaunchTarget target = (ILaunchTarget) element;
ILabelProvider labelProvider = uiManager.getLabelProvider(target);
if (labelProvider != null) {
return labelProvider.getText(element);
}
return target.getName();
}
return super.getText(element);
}
});
setSorter(new Comparator<Object>() {
@Override
public int compare(Object o1, Object o2) {
// Sort by name
return 0;
}
});
setHoverProvider(new IHoverProvider() {
@Override
public boolean displayHover(Object element) {
if (element instanceof ILaunchTarget) {
ILaunchTarget target = (ILaunchTarget) element;
IHoverProvider hoverProvider = uiManager.getHoverProvider(target);
if (hoverProvider != null) {
return hoverProvider.displayHover(element);
}
}
return false;
}
@Override
public void dismissHover(Object element, boolean immediate) {
if (element instanceof ILaunchTarget) {
ILaunchTarget target = (ILaunchTarget) element;
IHoverProvider hoverProvider = uiManager.getHoverProvider(target);
if (hoverProvider != null) {
hoverProvider.dismissHover(element, immediate);
}
}
}
});
}
@Override
public boolean isEditable(Object element) {
if (element instanceof ILaunchTarget) {
ILaunchTarget target = (ILaunchTarget) element;
return uiManager.getEditCommand(target) != null;
}
return false;
}
@Override
public void handleEdit(Object element) {
if (element instanceof ILaunchTarget) {
ILaunchTarget target = (ILaunchTarget) element;
String commandId = uiManager.getEditCommand(target);
Activator.runCommand(commandId, ILaunchBarUIConstants.TARGET_NAME, target.getName());
}
}
@Override
public boolean hasActionArea() {
return uiManager.getAddTargetCommand(getManager().getActiveLaunchConfigurationDescriptor()) != null;
}
@Override
public void createActionArea(Composite parent) {
Composite actionArea = new Composite(parent, SWT.NONE);
GridLayout actionLayout = new GridLayout();
actionLayout.marginWidth = actionLayout.marginHeight = 0;
actionArea.setLayout(actionLayout);
actionArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
final Composite createButton = new Composite(actionArea, SWT.NONE);
createButton
.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
GridLayout buttonLayout = new GridLayout();
buttonLayout.marginWidth = buttonLayout.marginHeight = 7;
createButton.setLayout(buttonLayout);
createButton.setBackground(white);
createButton.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
Point size = createButton.getSize();
GC gc = e.gc;
gc.setForeground(outlineColor);
gc.drawLine(0, 0, size.x, 0);
}
});
final Label createLabel = new Label(createButton, SWT.None);
createLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
createLabel.setText("Add New Target...");
createLabel.setBackground(white);
final String command = uiManager.getAddTargetCommand(getManager().getActiveLaunchConfigurationDescriptor());
MouseListener mouseListener = new MouseAdapter() {
public void mouseUp(org.eclipse.swt.events.MouseEvent e) {
Activator.runCommand(command);
}
};
createButton.addMouseListener(mouseListener);
createLabel.addMouseListener(mouseListener);
MouseTrackListener mouseTrackListener = new MouseTrackAdapter() {
@Override
public void mouseEnter(MouseEvent e) {
createButton.setBackground(highlightColor);
createLabel.setBackground(highlightColor);
}
@Override
public void mouseExit(MouseEvent e) {
createButton.setBackground(white);
createLabel.setBackground(white);
}
};
createButton.addMouseTrackListener(mouseTrackListener);
createLabel.addMouseTrackListener(mouseTrackListener);
}
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
return super.computeSize(200, hHint, changed);
}
private ILaunchBarManager getManager() {
return (ILaunchBarManager) getInput();
}
@Override
public void setSelection(ISelection selection) {
if (selection == null)
super.setSelection(nullSelection);
else
super.setSelection(selection);
}
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.controls;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
public class Transition implements Runnable {
private final Control control;
private final int tick;
private int current;
private int to;
private int incr;
public Transition(Control control, int current, int tick) {
this.control = control;
this.current = current;
this.tick = tick;
}
@Override
public void run() {
current += incr;
if (!control.isDisposed())
control.redraw();
if (!done())
Display.getCurrent().timerExec(tick, this);
}
public void to(int to) {
if (current == to)
return;
this.to = to;
this.incr = current > to ? -1 : 1;
Display.getCurrent().timerExec(tick, this);
}
public int getCurrent() {
return current;
}
public boolean done() {
return current == to;
}
}

View file

@ -0,0 +1,162 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.dialogs;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationPropertiesDialog;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
@SuppressWarnings("restriction")
public class LaunchConfigurationEditDialog extends LaunchConfigurationPropertiesDialog {
private static final int DELETE_ID = 64;
private static final int DUPLICATE_ID = 65;
private static final int LAUNCH_ID = 66;
public LaunchConfigurationEditDialog(Shell shell, ILaunchConfiguration launchConfiguration, LaunchGroupExtension group) {
super(shell, launchConfiguration, group);
}
@Override
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
PlatformUI.getWorkbench().getProgressService().run(fork, cancelable, runnable);
}
@Override
protected Control createButtonBar(Composite parent) {
// Clone super's implementation, removes the monitor since we don't run from here
// And adds in the left button bar.
Font font = parent.getFont();
Composite composite = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
composite.setFont(font);
// create help control if needed
if (isHelpAvailable()) {
createHelpControl(composite);
}
Composite leftButtonComp = new Composite(composite, SWT.NULL);
layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.numColumns = 0;
leftButtonComp.setLayout(layout);
leftButtonComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
leftButtonComp.setFont(parent.getFont());
createButton(leftButtonComp, DELETE_ID, "Delete", false);
createButton(leftButtonComp, DUPLICATE_ID, "Duplicate", false);
createButton(leftButtonComp, LAUNCH_ID, "Launch", false);
Composite mainButtonComp = new Composite(composite, SWT.NONE);
layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.numColumns = 0;
mainButtonComp.setLayout(layout);
mainButtonComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
mainButtonComp.setFont(parent.getFont());
createButton(mainButtonComp, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
createButton(mainButtonComp, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
return composite;
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
// Do nothing since we now have the buttons created above.
}
@Override
public void launchConfigurationAdded(ILaunchConfiguration configuration) {
// update the dialog with the new config
getTabViewer().setInput(configuration);
}
@Override
protected void buttonPressed(int buttonId) {
switch (buttonId) {
case DELETE_ID:
ILaunchConfiguration c = getLaunchConfiguration();
if (c.isWorkingCopy())
c = ((ILaunchConfigurationWorkingCopy)c).getOriginal();
final ILaunchConfiguration config = c;
if (MessageDialog.openConfirm(getShell(), "Confirm Delete",
"Are you sure you want to delete " + config.getName())) {
new Job("Deleting launch configuration") {
protected IStatus run(IProgressMonitor monitor) {
try {
config.delete();
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();
}
};
}.schedule();
cancelPressed();
}
break;
case DUPLICATE_ID:
final ILaunchConfiguration original = getLaunchConfiguration();
final String newName = DebugPlugin.getDefault().getLaunchManager().generateLaunchConfigurationName(original.getName());
new Job("Duplicating launch configuration") {
protected IStatus run(IProgressMonitor monitor) {
try {
ILaunchConfigurationWorkingCopy newWorkingCopy = original.copy(newName);
newWorkingCopy.doSave();
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();
}
};
}.schedule();
break;
case LAUNCH_ID:
okPressed();
Activator.runCommand(Activator.CMD_LAUNCH);
break;
default:
super.buttonPressed(buttonId);
}
}
}

View file

@ -0,0 +1,253 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.dialogs;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationPresentationManager;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.debug.ui.ILaunchConfigurationTabGroup;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
public class NewLaunchConfigEditPage extends WizardPage {
ILaunchConfigurationWorkingCopy workingCopy;
ILaunchConfigurationTabGroup tabGroup;
private Text nameText;
private CTabFolder tabFolder;
private LaunchConfigurationDialog launchConfigurationDialog = new LaunchConfigurationDialog();
private LaunchConfigurationManager launchConfigurationMgr = DebugUIPlugin.getDefault().getLaunchConfigurationManager();
public NewLaunchConfigEditPage() {
super("NewLaunchConfigEditPage");
setTitle("Launch Configuration Properties");
setDescription("Edit the new launch configuration properties");
}
@Override
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new GridLayout(2, false));
Label label = new Label(comp, SWT.NONE);
label.setLayoutData(new GridData());
label.setText("Name:");
nameText = new Text(comp, SWT.BORDER);
nameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
nameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
workingCopy.rename(nameText.getText());
checkName();
}
});
ColorRegistry reg = JFaceResources.getColorRegistry();
Color c1 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START"), //$NON-NLS-1$
c2 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END"); //$NON-NLS-1$
tabFolder = new CTabFolder(comp, SWT.BORDER | SWT.NO_REDRAW_RESIZE | SWT.FLAT);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.horizontalSpan = 2;
tabFolder.setLayoutData(gridData);
tabFolder.setSimple(false);
tabFolder.setSelectionBackground(new Color[] {c1, c2}, new int[] {100}, true);
tabFolder.setSelectionForeground(reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")); //$NON-NLS-1$
checkName();
changeLaunchConfigType();
setControl(comp);
}
private void checkName() {
if (workingCopy == null)
return;
try {
if (workingCopy.getName().isEmpty()) {
setErrorMessage("Name can not be empty");
setPageComplete(false);
} else if (DebugPlugin.getDefault().getLaunchManager().isExistingLaunchConfigurationName(workingCopy.getName())) {
setErrorMessage("A configuration with this name already exists");
setPageComplete(false);
} else {
setErrorMessage(null);
setPageComplete(true);
}
} catch (CoreException exc) {
setErrorMessage(exc.getLocalizedMessage());
}
}
void changeLaunchConfigType() {
ILaunchConfigurationType type = ((NewLaunchConfigWizard)getWizard()).typePage.type;
if (type == null)
return;
try {
String initialMode = ((NewLaunchConfigWizard)getWizard()).modePage.selectedGroup.getMode();
workingCopy = type.newInstance(null, "New Configuration");
tabGroup = LaunchConfigurationPresentationManager.getDefault().getTabGroup(workingCopy, initialMode);
nameText.setText(workingCopy.getName());
for (CTabItem item : tabFolder.getItems())
item.dispose();
tabGroup.createTabs(launchConfigurationDialog, initialMode);
boolean firstTab = true;
for (ILaunchConfigurationTab tab : tabGroup.getTabs()) {
tab.setLaunchConfigurationDialog(launchConfigurationDialog);
tab.createControl(tabFolder);
tab.setDefaults(workingCopy);
if (firstTab) {
firstTab = false;
// tab.setDefaults likely renames it
nameText.setText(workingCopy.getName());
}
tab.initializeFrom(workingCopy);
CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE);
tabItem.setText(tab.getName());
tabItem.setImage(!tab.isValid(workingCopy) && tab.getErrorMessage() != null ?
launchConfigurationMgr.getErrorTabImage(tab) : tab.getImage());
tabItem.setControl(tab.getControl());
}
tabFolder.setSelection(0);
} catch (CoreException e) {
Activator.log(e);
return;
}
}
boolean performFinish() {
if (workingCopy == null)
return false;
for (ILaunchConfigurationTab tab : tabGroup.getTabs())
tab.performApply(workingCopy);
return true;
}
private class LaunchConfigurationDialog implements ILaunchConfigurationDialog {
@Override
public void run(boolean fork, boolean cancelable,
IRunnableWithProgress runnable)
throws InvocationTargetException, InterruptedException {
// TODO Auto-generated method stub
}
@Override
public void updateButtons() {
}
@Override
public void updateMessage() {
String message = null;
String old_msg = getErrorMessage();
ILaunchConfigurationTab[] tabs = tabGroup.getTabs();
ILaunchConfigurationTab tab;
CTabItem item;
int tLen = tabs.length;
int tfLen = tabFolder.getItems().length;
for (int i = 0; i < tLen; i++) {
tab = tabs[i];
try {
tab.isValid(workingCopy);
message = tab.getErrorMessage();
} catch(Exception e) {
// if createControl hasn't been called yet can throw exception..
// like the NPE issue in CTestingTab
message = e.getMessage();
}
// this is similar to what LaunchConfigurationTabGroupViewer.refresh() does, which is not available in this case
if (tLen == tfLen &&
(old_msg == null && message != null || old_msg != null && message == null)) {
item = tabFolder.getItem(i);
if (item != null) {
item.setImage(message != null ? launchConfigurationMgr.getErrorTabImage(tab)
: tab.getImage());
}
}
if (message != null) {
break;
}
}
setErrorMessage(message);
}
@Override
public void setName(String name) {
// TODO Auto-generated method stub
}
@Override
public String generateName(String name) {
if (name == null)
return "";
return DebugPlugin.getDefault().getLaunchManager().generateLaunchConfigurationName(name);
}
@Override
public ILaunchConfigurationTab[] getTabs() {
// TODO Auto-generated method stub
return null;
}
@Override
public ILaunchConfigurationTab getActiveTab() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getMode() {
return ((NewLaunchConfigWizard)getWizard()).modePage.selectedGroup.getMode();
}
@Override
public void setActiveTab(ILaunchConfigurationTab tab) {
// TODO Auto-generated method stub
}
@Override
public void setActiveTab(int index) {
// TODO Auto-generated method stub
}
}
}

View file

@ -0,0 +1,114 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.dialogs;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.ILaunchGroup;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
public class NewLaunchConfigModePage extends WizardPage {
private Table table;
ILaunchGroup selectedGroup;
public NewLaunchConfigModePage() {
super("Select Initial Launch Mode");
setTitle("Initial Launch Mode");
setDescription("Select initial launch mode.");
}
@Override
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new GridLayout(1, false));
table = new Table(comp, SWT.SINGLE | SWT.BORDER);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
table.setLayoutData(data);
Set<ILaunchGroup> done = new HashSet<>();
for (ILaunchGroup group : DebugUITools.getLaunchGroups()) {
if (group.getMode().equals("run")) {
createModeItem(group);
done.add(group);
}
}
for (ILaunchGroup group : DebugUITools.getLaunchGroups()) {
if (group.getMode().equals("debug")) {
createModeItem(group);
done.add(group);
}
}
for (ILaunchGroup group : DebugUITools.getLaunchGroups()) {
if (!done.contains(group)) {
createModeItem(group);
}
}
if (table.getItemCount() > 0) {
// Select debug as default
int i = 0;
boolean hasDebug = false;
for (TableItem item : table.getItems()) {
if ("debug".equals(((ILaunchGroup) item.getData()).getMode())) {
hasDebug = true;
table.select(i);
break;
}
i++;
}
if (!hasDebug) {
table.select(0);
}
selectedGroup = (ILaunchGroup) table.getSelection()[0].getData();
}
table.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
selectedGroup = (ILaunchGroup)table.getSelection()[0].getData();
((NewLaunchConfigWizard)getWizard()).typePage.populateItems();
}
});
setControl(comp);
}
private void createModeItem(ILaunchGroup group) {
if (group.getCategory() != null || !group.isPublic())
return;
TableItem item = new TableItem(table, SWT.NONE);
item.setText(group.getLabel().replace("&", ""));
ImageDescriptor imageDesc = group.getImageDescriptor();
if (imageDesc != null) {
item.setImage(imageDesc.createImage());
}
item.setData(group);
}
}

View file

@ -0,0 +1,101 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.dialogs;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.ILaunchGroup;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.progress.UIJob;
public class NewLaunchConfigTypePage extends WizardPage {
private Table table;
ILaunchConfigurationType type;
public NewLaunchConfigTypePage() {
super("Select Launch Configuration Type");
setTitle("Launch Configuration Type");
setDescription("Select the type of launch configuration to create.");
}
@Override
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new GridLayout(1, false));
table = new Table(comp, SWT.SINGLE | SWT.BORDER);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
data.heightHint = 500;
table.setLayoutData(data);
populateItems();
table.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e);
type = (ILaunchConfigurationType)table.getSelection()[0].getData();
setMessage("Initializing. Please wait...", INFORMATION);
UIJob job = new UIJob("Updating Page") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
((NewLaunchConfigWizard)getWizard()).editPage.changeLaunchConfigType();
setPageComplete(true);
setMessage(null);
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
});
setControl(comp);
}
void populateItems() {
ILaunchGroup group = ((NewLaunchConfigWizard)getWizard()).modePage.selectedGroup;
if (group == null)
return;
table.removeAll();
for (ILaunchConfigurationType type : DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationTypes()) {
if (!type.isPublic() || type.getCategory() != null || !type.supportsMode(group.getMode()))
continue;
TableItem item = new TableItem(table, SWT.NONE);
item.setText(type.getName());
ImageDescriptor imageDesc = DebugUITools.getDefaultImageDescriptor(type);
if (imageDesc != null)
item.setImage(imageDesc.createImage());
item.setData(type);
}
type = null;
setPageComplete(false);
}
}

View file

@ -0,0 +1,105 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems 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:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.dialogs;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationListener;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.jface.wizard.Wizard;
public class NewLaunchConfigWizard extends Wizard implements ILaunchConfigurationListener {
NewLaunchConfigModePage modePage = new NewLaunchConfigModePage();
NewLaunchConfigTypePage typePage = new NewLaunchConfigTypePage();
NewLaunchConfigEditPage editPage = new NewLaunchConfigEditPage();
private List<ILaunchConfiguration> configsToDelete = new ArrayList<>();
public NewLaunchConfigWizard() {
setWindowTitle("Create Launch Configuration");
initListeners();
}
@Override
public void addPages() {
addPage(modePage);
addPage(typePage);
addPage(editPage);
}
public ILaunchConfigurationWorkingCopy getWorkingCopy() {
return editPage.workingCopy;
}
public ILaunchMode getLaunchMode() {
String initMode = modePage.selectedGroup.getMode();
return DebugPlugin.getDefault().getLaunchManager().getLaunchMode(initMode);
}
@Override
public boolean performFinish() {
cleanUpListeners();
return editPage.performFinish();
}
@Override
public boolean performCancel() {
cleanUpListeners();
return super.performCancel();
}
private void initListeners() {
// while the wizard is open, some ill behaved launch config tabs save the working copy.
// We need to make sure those saves are deleted when the dialog is finished.
// We also need to turn off listening in the tool bar manager so that we don't treat these
// as real launch configs.
// LaunchToolBarManager.getInstance().setIgnoreLaunchConfigEvents(true);
DebugPlugin.getDefault().getLaunchManager().addLaunchConfigurationListener(this);
}
private void cleanUpListeners() {
DebugPlugin.getDefault().getLaunchManager().removeLaunchConfigurationListener(this);
for (ILaunchConfiguration config : configsToDelete) {
try {
config.delete();
} catch (CoreException e) {
Activator.log(e);
}
}
// LaunchToolBarManager.getInstance().setIgnoreLaunchConfigEvents(false);
}
@Override
public void launchConfigurationAdded(ILaunchConfiguration configuration) {
if (!configuration.isWorkingCopy())
configsToDelete.add(configuration);
}
@Override
public void launchConfigurationChanged(ILaunchConfiguration configuration) {
// Nothing to do
}
@Override
public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
if (!configuration.isWorkingCopy())
configsToDelete.remove(configuration);
}
}

View file

@ -0,0 +1,3 @@
LaunchBarControl_Build=Build
LaunchBarControl_Launch=Launch
LaunchBarControl_Stop=Stop

View file

@ -204,6 +204,9 @@
<module>remote/org.eclipse.cdt.remote.core</module>
<module>remote/org.eclipse.cdt.remote-feature</module>
<module>launch/org.eclipse.cdt.launchbar.core</module>
<module>launch/org.eclipse.cdt.launchbar.ui</module>
<!--
<module>lrparser/org.eclipse.cdt.core.lrparser.tests</module>
<module>upc/org.eclipse.cdt.core.parser.upc.tests</module>