mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Bug 441445 - Implement 'Add Target' functionality for target type
contributions to LaunchBar Change-Id: I577c0e1438090aaaf27bba34660169cde82a8e8c Signed-off-by: Jonathan Williams <jonwilliams@qnx.com> Reviewed-on: https://git.eclipse.org/r/31319 Tested-by: Hudson CI Reviewed-by: Elena Laskavaia <elaskavaia.cdt@gmail.com>
This commit is contained in:
parent
bc0a8fb72f
commit
c1ca67ed34
5 changed files with 169 additions and 54 deletions
|
@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.ui,
|
|||
org.eclipse.cdt.launchbar.core,
|
||||
org.eclipse.debug.ui,
|
||||
org.eclipse.ui.workbench,
|
||||
org.eclipse.ui.ide
|
||||
org.eclipse.ui.ide,
|
||||
org.eclipse.swt
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-Localization: plugin
|
||||
|
|
|
@ -67,7 +67,8 @@
|
|||
</descriptorUI>
|
||||
<targetUI
|
||||
labelProvider="org.eclipse.cdt.launchbar.ui.internal.LocalTargetLabelProvider"
|
||||
targetTypeId="org.eclipse.cdt.launchbar.core.target.local">
|
||||
targetTypeId="org.eclipse.cdt.launchbar.core.target.local"
|
||||
name="Local Target">
|
||||
</targetUI>
|
||||
</extension>
|
||||
|
||||
|
|
|
@ -85,6 +85,26 @@
|
|||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="name" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Used for identifying this launch target type in various UI elements.
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute translatable="true"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="icon" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Used for identifying this launch target type in various UI elements.
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute kind="resource"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="labelProvider" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
|
|
@ -10,29 +10,32 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.launchbar.ui.internal;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
|
||||
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
|
||||
import org.eclipse.cdt.launchbar.core.ILaunchTargetType;
|
||||
import org.eclipse.cdt.launchbar.ui.IHoverProvider;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExtension;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.ILabelProvider;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
public class LaunchBarUIManager {
|
||||
|
||||
ILaunchBarManager manager;
|
||||
Map<String, ILabelProvider> descriptorLabelProviders = new HashMap<>();
|
||||
Map<String, ILabelProvider> targetLabelProviders = new HashMap<>();
|
||||
Map<String, IHoverProvider> targetHoverProviders = new HashMap<>();
|
||||
Map<String, String> targetEditCommandIds = new HashMap<>();
|
||||
Map<String, String> targetAddNewCommandIds = new HashMap<>();
|
||||
Map<String, LaunchBarTargetContribution> targetContributions = new HashMap<>();
|
||||
|
||||
private final LaunchBarTargetContribution DEFAULT_CONTRIBUTION = new LaunchBarTargetContribution(null, null, null, null, null,
|
||||
null, null);
|
||||
|
||||
public LaunchBarUIManager(ILaunchBarManager manager) {
|
||||
this.manager = manager;
|
||||
|
@ -54,23 +57,21 @@ public class LaunchBarUIManager {
|
|||
} else if (elementName.equals("targetUI")) {
|
||||
try {
|
||||
String targetTypeId = element.getAttribute("targetTypeId");
|
||||
String targetName = element.getAttribute("name");
|
||||
|
||||
String iconStr = element.getAttribute("icon");
|
||||
|
||||
ILabelProvider labelProvider = (ILabelProvider) element.createExecutableExtension("labelProvider");
|
||||
targetLabelProviders.put(targetTypeId, labelProvider);
|
||||
|
||||
IHoverProvider hoverProvider = null;
|
||||
if (element.getAttribute("hoverProvider") != null) {
|
||||
IHoverProvider hoverProvider = (IHoverProvider) element.createExecutableExtension("hoverProvider");
|
||||
if (hoverProvider != null)
|
||||
targetHoverProviders.put(targetTypeId, hoverProvider);
|
||||
hoverProvider = (IHoverProvider) element.createExecutableExtension("hoverProvider");
|
||||
}
|
||||
|
||||
String editCommandId = element.getAttribute("editCommandId");
|
||||
if (editCommandId != null && editCommandId.length() > 0)
|
||||
targetEditCommandIds.put(targetTypeId, editCommandId);
|
||||
|
||||
String addNewCommandId = element.getAttribute("addNewTargetCommandId");
|
||||
if (addNewCommandId != null && addNewCommandId.length() > 0)
|
||||
targetAddNewCommandIds.put(targetTypeId, addNewCommandId);
|
||||
|
||||
targetContributions.put(targetTypeId, new LaunchBarTargetContribution(targetTypeId, targetName, iconStr,
|
||||
labelProvider, hoverProvider, editCommandId, addNewCommandId));
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
}
|
||||
|
@ -87,19 +88,89 @@ public class LaunchBarUIManager {
|
|||
return descriptorLabelProviders.get(descriptor.getType().getId());
|
||||
}
|
||||
|
||||
public String getTargetTypeName(ILaunchTarget target) {
|
||||
return getContribution(target).name;
|
||||
}
|
||||
|
||||
public ILabelProvider getLabelProvider(ILaunchTarget target) {
|
||||
return targetLabelProviders.get(target.getType().getId());
|
||||
return getContribution(target).labelProvider;
|
||||
}
|
||||
|
||||
public IHoverProvider getHoverProvider(ILaunchTarget target) {
|
||||
return targetHoverProviders.get(target.getType().getId());
|
||||
return getContribution(target).hoverProvider;
|
||||
}
|
||||
|
||||
public String getEditCommand(ILaunchTarget target) {
|
||||
return targetEditCommandIds.get(target.getType().getId());
|
||||
return getContribution(target).editCommandId;
|
||||
}
|
||||
|
||||
public String getAddTargetCommand(ILaunchTargetType targetType) {
|
||||
return targetAddNewCommandIds.get(targetType.getId());
|
||||
public String getAddTargetCommand(ILaunchTarget target) {
|
||||
return getContribution(target).addNewCommandId;
|
||||
}
|
||||
|
||||
public Map<String, String> getAddTargetCommands() {
|
||||
Map<String, String> commands = new HashMap<>();
|
||||
for (LaunchBarTargetContribution contribution : targetContributions.values()) {
|
||||
if (contribution.addNewCommandId != null)
|
||||
commands.put(contribution.name, contribution.addNewCommandId);
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
public Map<String, Image> getTargetIcons() {
|
||||
Map<String, Image> icons = new HashMap<>();
|
||||
for (LaunchBarTargetContribution contribution : targetContributions.values()) {
|
||||
Image icon = contribution.getIcon();
|
||||
if (icon != null) {
|
||||
icons.put(contribution.name, icon);
|
||||
}
|
||||
}
|
||||
return icons;
|
||||
}
|
||||
|
||||
private LaunchBarTargetContribution getContribution(ILaunchTarget target) {
|
||||
LaunchBarTargetContribution c = targetContributions.get(target.getType().getId());
|
||||
if (c == null) {
|
||||
return DEFAULT_CONTRIBUTION;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private class LaunchBarTargetContribution {
|
||||
|
||||
String id;
|
||||
String name;
|
||||
String iconStr;
|
||||
Image icon;
|
||||
ILabelProvider labelProvider;
|
||||
IHoverProvider hoverProvider;
|
||||
String editCommandId;
|
||||
String addNewCommandId;
|
||||
|
||||
LaunchBarTargetContribution(String id, String name, String iconStr, ILabelProvider labelProvider,
|
||||
IHoverProvider hoverProvider, String editCommand, String addNewCommand) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.iconStr = iconStr;
|
||||
this.icon = null;
|
||||
this.labelProvider = labelProvider;
|
||||
this.hoverProvider = hoverProvider;
|
||||
this.editCommandId = editCommand;
|
||||
this.addNewCommandId = addNewCommand;
|
||||
}
|
||||
|
||||
Image getIcon() {
|
||||
if (icon == null) {
|
||||
if (iconStr != null && !iconStr.isEmpty()) {
|
||||
try {
|
||||
icon = ImageDescriptor.createFromURL(new URL(iconStr)).createImage();
|
||||
} catch (MalformedURLException e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.launchbar.ui.internal.controls;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
|
||||
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
|
||||
|
@ -19,12 +20,16 @@ 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.core.runtime.CoreException;
|
||||
import org.eclipse.jface.viewers.ArrayContentProvider;
|
||||
import org.eclipse.jface.viewers.ILabelProvider;
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.window.Window;
|
||||
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;
|
||||
|
@ -36,6 +41,7 @@ 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.ui.dialogs.ListDialog;
|
||||
|
||||
public class TargetSelector extends CSelector {
|
||||
|
||||
|
@ -43,7 +49,6 @@ public class TargetSelector extends CSelector {
|
|||
|
||||
private static final String[] noTargets = new String[] { "---" };
|
||||
|
||||
|
||||
public TargetSelector(Composite parent, int style) {
|
||||
super(parent, style);
|
||||
|
||||
|
@ -52,8 +57,7 @@ public class TargetSelector extends CSelector {
|
|||
|
||||
setContentProvider(new IStructuredContentProvider() {
|
||||
@Override
|
||||
public void inputChanged(Viewer viewer, Object oldInput,
|
||||
Object newInput) {
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -154,14 +158,11 @@ public class TargetSelector extends CSelector {
|
|||
|
||||
@Override
|
||||
public boolean hasActionArea() {
|
||||
// TODO need an add target command similar to the add configuration that allows the user
|
||||
// to select the target type.
|
||||
// return uiManager.getAddTargetCommand(getManager().getActiveLaunchDescriptor()) != null;
|
||||
return false;
|
||||
return !uiManager.getAddTargetCommands().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createActionArea(Composite parent) {
|
||||
public void createActionArea(final Composite parent) {
|
||||
Composite actionArea = new Composite(parent, SWT.NONE);
|
||||
GridLayout actionLayout = new GridLayout();
|
||||
actionLayout.marginWidth = actionLayout.marginHeight = 0;
|
||||
|
@ -169,8 +170,7 @@ public class TargetSelector extends CSelector {
|
|||
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));
|
||||
createButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
||||
GridLayout buttonLayout = new GridLayout();
|
||||
buttonLayout.marginWidth = buttonLayout.marginHeight = 7;
|
||||
createButton.setLayout(buttonLayout);
|
||||
|
@ -190,19 +190,14 @@ public class TargetSelector extends CSelector {
|
|||
createLabel.setText("Add New Target...");
|
||||
createLabel.setBackground(white);
|
||||
|
||||
// try {
|
||||
// final String command = uiManager.getAddTargetCommand(getManager().getActiveLaunchDescriptor());
|
||||
// MouseListener mouseListener = new MouseAdapter() {
|
||||
// public void mouseUp(org.eclipse.swt.events.MouseEvent e) {
|
||||
// Activator.runCommand(command);
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// createButton.addMouseListener(mouseListener);
|
||||
// createLabel.addMouseListener(mouseListener);
|
||||
// } catch (CoreException e) {
|
||||
// Activator.log(e.getStatus());
|
||||
// }
|
||||
MouseListener mouseListener = new MouseAdapter() {
|
||||
public void mouseUp(org.eclipse.swt.events.MouseEvent e) {
|
||||
handleCreateTarget();
|
||||
}
|
||||
};
|
||||
|
||||
createButton.addMouseListener(mouseListener);
|
||||
createLabel.addMouseListener(mouseListener);
|
||||
|
||||
MouseTrackListener mouseTrackListener = new MouseTrackAdapter() {
|
||||
@Override
|
||||
|
@ -221,6 +216,33 @@ public class TargetSelector extends CSelector {
|
|||
createLabel.addMouseTrackListener(mouseTrackListener);
|
||||
}
|
||||
|
||||
protected void handleCreateTarget() {
|
||||
final Map<String, String> commands = uiManager.getAddTargetCommands();
|
||||
final Map<String, Image> images = uiManager.getTargetIcons();
|
||||
if (!commands.isEmpty()) {
|
||||
ListDialog ld = new ListDialog(getShell());
|
||||
ld.setTitle("New Launch Target");
|
||||
ld.setMessage("Select target type to create");
|
||||
ld.setContentProvider(new ArrayContentProvider());
|
||||
ld.setLabelProvider(new LabelProvider() {
|
||||
@Override
|
||||
public String getText(Object element) {
|
||||
return (String)element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getImage(Object element) {
|
||||
return images.get(element);
|
||||
}
|
||||
});
|
||||
ld.setInput(commands.keySet().toArray());
|
||||
if (ld.open() == Window.OK) {
|
||||
String command = commands.get((String) (ld.getResult()[0]));
|
||||
Activator.runCommand(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fireSelectionChanged() {
|
||||
Object selection = getSelection();
|
||||
|
|
Loading…
Add table
Reference in a new issue