1
0
Fork 0
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:
Jonathan Williams 2014-07-29 14:25:49 -04:00 committed by Elena Laskavaia
parent bc0a8fb72f
commit c1ca67ed34
5 changed files with 169 additions and 54 deletions

View file

@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.cdt.launchbar.core, org.eclipse.cdt.launchbar.core,
org.eclipse.debug.ui, org.eclipse.debug.ui,
org.eclipse.ui.workbench, org.eclipse.ui.workbench,
org.eclipse.ui.ide org.eclipse.ui.ide,
org.eclipse.swt
Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin Bundle-Localization: plugin

View file

@ -67,7 +67,8 @@
</descriptorUI> </descriptorUI>
<targetUI <targetUI
labelProvider="org.eclipse.cdt.launchbar.ui.internal.LocalTargetLabelProvider" 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> </targetUI>
</extension> </extension>

View file

@ -85,6 +85,26 @@
</appinfo> </appinfo>
</annotation> </annotation>
</attribute> </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"> <attribute name="labelProvider" type="string" use="required">
<annotation> <annotation>
<documentation> <documentation>

View file

@ -10,30 +10,33 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal; package org.eclipse.cdt.launchbar.ui.internal;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.ILaunchTargetType;
import org.eclipse.cdt.launchbar.ui.IHoverProvider; import org.eclipse.cdt.launchbar.ui.IHoverProvider;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.graphics.Image;
public class LaunchBarUIManager { public class LaunchBarUIManager {
ILaunchBarManager manager; ILaunchBarManager manager;
Map<String, ILabelProvider> descriptorLabelProviders = new HashMap<>(); Map<String, ILabelProvider> descriptorLabelProviders = new HashMap<>();
Map<String, ILabelProvider> targetLabelProviders = new HashMap<>(); Map<String, LaunchBarTargetContribution> targetContributions = new HashMap<>();
Map<String, IHoverProvider> targetHoverProviders = new HashMap<>();
Map<String, String> targetEditCommandIds = new HashMap<>(); private final LaunchBarTargetContribution DEFAULT_CONTRIBUTION = new LaunchBarTargetContribution(null, null, null, null, null,
Map<String, String> targetAddNewCommandIds = new HashMap<>(); null, null);
public LaunchBarUIManager(ILaunchBarManager manager) { public LaunchBarUIManager(ILaunchBarManager manager) {
this.manager = manager; this.manager = manager;
@ -54,23 +57,21 @@ public class LaunchBarUIManager {
} else if (elementName.equals("targetUI")) { } else if (elementName.equals("targetUI")) {
try { try {
String targetTypeId = element.getAttribute("targetTypeId"); String targetTypeId = element.getAttribute("targetTypeId");
String targetName = element.getAttribute("name");
String iconStr = element.getAttribute("icon");
ILabelProvider labelProvider = (ILabelProvider) element.createExecutableExtension("labelProvider"); ILabelProvider labelProvider = (ILabelProvider) element.createExecutableExtension("labelProvider");
targetLabelProviders.put(targetTypeId, labelProvider);
if (element.getAttribute("hoverProvider") != null) {
IHoverProvider hoverProvider = (IHoverProvider) element.createExecutableExtension("hoverProvider");
if (hoverProvider != null)
targetHoverProviders.put(targetTypeId, hoverProvider);
}
String editCommandId = element.getAttribute("editCommandId");
if (editCommandId != null && editCommandId.length() > 0)
targetEditCommandIds.put(targetTypeId, editCommandId);
IHoverProvider hoverProvider = null;
if (element.getAttribute("hoverProvider") != null) {
hoverProvider = (IHoverProvider) element.createExecutableExtension("hoverProvider");
}
String editCommandId = element.getAttribute("editCommandId");
String addNewCommandId = element.getAttribute("addNewTargetCommandId"); 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) { } catch (CoreException e) {
Activator.log(e.getStatus()); Activator.log(e.getStatus());
} }
@ -82,24 +83,94 @@ public class LaunchBarUIManager {
public ILaunchBarManager getManager() { public ILaunchBarManager getManager() {
return manager; return manager;
} }
public ILabelProvider getLabelProvider(ILaunchDescriptor descriptor) { public ILabelProvider getLabelProvider(ILaunchDescriptor descriptor) {
return descriptorLabelProviders.get(descriptor.getType().getId()); return descriptorLabelProviders.get(descriptor.getType().getId());
} }
public String getTargetTypeName(ILaunchTarget target) {
return getContribution(target).name;
}
public ILabelProvider getLabelProvider(ILaunchTarget target) { public ILabelProvider getLabelProvider(ILaunchTarget target) {
return targetLabelProviders.get(target.getType().getId()); return getContribution(target).labelProvider;
} }
public IHoverProvider getHoverProvider(ILaunchTarget target) { public IHoverProvider getHoverProvider(ILaunchTarget target) {
return targetHoverProviders.get(target.getType().getId()); return getContribution(target).hoverProvider;
} }
public String getEditCommand(ILaunchTarget target) { public String getEditCommand(ILaunchTarget target) {
return targetEditCommandIds.get(target.getType().getId()); return getContribution(target).editCommandId;
} }
public String getAddTargetCommand(ILaunchTargetType targetType) { public String getAddTargetCommand(ILaunchTarget target) {
return targetAddNewCommandIds.get(targetType.getId()); 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;
}
} }
} }

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.launchbar.ui.internal.controls; package org.eclipse.cdt.launchbar.ui.internal.controls;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchTarget; 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.Activator;
import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager; import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseTrackAdapter; import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.MouseTrackListener; import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintEvent;
@ -36,13 +41,13 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.dialogs.ListDialog;
public class TargetSelector extends CSelector { public class TargetSelector extends CSelector {
private final LaunchBarUIManager uiManager; private final LaunchBarUIManager uiManager;
private static final String[] noTargets = new String[] { "---" }; private static final String[] noTargets = new String[] { "---" };
public TargetSelector(Composite parent, int style) { public TargetSelector(Composite parent, int style) {
super(parent, style); super(parent, style);
@ -52,8 +57,7 @@ public class TargetSelector extends CSelector {
setContentProvider(new IStructuredContentProvider() { setContentProvider(new IStructuredContentProvider() {
@Override @Override
public void inputChanged(Viewer viewer, Object oldInput, public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
Object newInput) {
} }
@Override @Override
@ -120,7 +124,7 @@ public class TargetSelector extends CSelector {
} }
return false; return false;
} }
@Override @Override
public void dismissHover(Object element, boolean immediate) { public void dismissHover(Object element, boolean immediate) {
if (element instanceof ILaunchTarget) { if (element instanceof ILaunchTarget) {
@ -154,14 +158,11 @@ public class TargetSelector extends CSelector {
@Override @Override
public boolean hasActionArea() { public boolean hasActionArea() {
// TODO need an add target command similar to the add configuration that allows the user return !uiManager.getAddTargetCommands().isEmpty();
// to select the target type.
// return uiManager.getAddTargetCommand(getManager().getActiveLaunchDescriptor()) != null;
return false;
} }
@Override @Override
public void createActionArea(Composite parent) { public void createActionArea(final Composite parent) {
Composite actionArea = new Composite(parent, SWT.NONE); Composite actionArea = new Composite(parent, SWT.NONE);
GridLayout actionLayout = new GridLayout(); GridLayout actionLayout = new GridLayout();
actionLayout.marginWidth = actionLayout.marginHeight = 0; actionLayout.marginWidth = actionLayout.marginHeight = 0;
@ -169,8 +170,7 @@ public class TargetSelector extends CSelector {
actionArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); actionArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
final Composite createButton = new Composite(actionArea, SWT.NONE); final Composite createButton = new Composite(actionArea, SWT.NONE);
createButton createButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
GridLayout buttonLayout = new GridLayout(); GridLayout buttonLayout = new GridLayout();
buttonLayout.marginWidth = buttonLayout.marginHeight = 7; buttonLayout.marginWidth = buttonLayout.marginHeight = 7;
createButton.setLayout(buttonLayout); createButton.setLayout(buttonLayout);
@ -190,19 +190,14 @@ public class TargetSelector extends CSelector {
createLabel.setText("Add New Target..."); createLabel.setText("Add New Target...");
createLabel.setBackground(white); createLabel.setBackground(white);
// try { MouseListener mouseListener = new MouseAdapter() {
// final String command = uiManager.getAddTargetCommand(getManager().getActiveLaunchDescriptor()); public void mouseUp(org.eclipse.swt.events.MouseEvent e) {
// MouseListener mouseListener = new MouseAdapter() { handleCreateTarget();
// public void mouseUp(org.eclipse.swt.events.MouseEvent e) { }
// Activator.runCommand(command); };
// }
// }; createButton.addMouseListener(mouseListener);
// createLabel.addMouseListener(mouseListener);
// createButton.addMouseListener(mouseListener);
// createLabel.addMouseListener(mouseListener);
// } catch (CoreException e) {
// Activator.log(e.getStatus());
// }
MouseTrackListener mouseTrackListener = new MouseTrackAdapter() { MouseTrackListener mouseTrackListener = new MouseTrackAdapter() {
@Override @Override
@ -221,6 +216,33 @@ public class TargetSelector extends CSelector {
createLabel.addMouseTrackListener(mouseTrackListener); 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 @Override
protected void fireSelectionChanged() { protected void fireSelectionChanged() {
Object selection = getSelection(); Object selection = getSelection();
@ -233,7 +255,7 @@ public class TargetSelector extends CSelector {
} }
} }
} }
@Override @Override
public Point computeSize(int wHint, int hHint, boolean changed) { public Point computeSize(int wHint, int hHint, boolean changed) {
return super.computeSize(200, hHint, changed); return super.computeSize(200, hHint, changed);
@ -249,5 +271,5 @@ public class TargetSelector extends CSelector {
element = noTargets[0]; element = noTargets[0];
super.setSelection(element); super.setSelection(element);
} }
} }