mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Launch Bar - New Target Wizard somewhat like the new resource wizards.
Has a page to select the target type. The INewWizard for the target type is registered in the launchBarUIContributions extension point. When selected and nextPage is hit, the wizard starts up. Also some minor cleanup to the new config wizard. Change-Id: Ic2bb5164d531a21b7a2a9dd7ecd109e18f2411cd Reviewed-on: https://git.eclipse.org/r/34017 Reviewed-by: Doug Schaefer <dschaefer@qnx.com> Tested-by: Doug Schaefer <dschaefer@qnx.com>
This commit is contained in:
parent
ce15475828
commit
c84b8cc5d6
8 changed files with 202 additions and 75 deletions
|
@ -50,4 +50,16 @@ public class ExecutableExtension<T> {
|
|||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new object. Can't be done if you've done a get already.
|
||||
* @return a new object from the extension or null if get was called earlier
|
||||
* @throws CoreException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public T create() throws CoreException {
|
||||
if (element != null) {
|
||||
return (T) element.createExecutableExtension(propertyName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,13 +135,13 @@
|
|||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="addNewTargetCommandId" type="string">
|
||||
<attribute name="newWizard" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
An INewWizard that creates a target of this type.
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute kind="identifier" basedOn="org.eclipse.ui.commands/command/@id"/>
|
||||
<meta.attribute kind="java" basedOn=":org.eclipse.ui.INewWizard"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
|
|
|
@ -14,9 +14,11 @@ import java.net.MalformedURLException;
|
|||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
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.core.internal.ExecutableExtension;
|
||||
import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager;
|
||||
import org.eclipse.cdt.launchbar.ui.IHoverProvider;
|
||||
|
@ -28,6 +30,7 @@ import org.eclipse.core.runtime.Platform;
|
|||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.ILabelProvider;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.ui.INewWizard;
|
||||
|
||||
public class LaunchBarUIManager {
|
||||
|
||||
|
@ -62,10 +65,14 @@ public class LaunchBarUIManager {
|
|||
}
|
||||
|
||||
String editCommandId = element.getAttribute("editCommandId");
|
||||
String addNewCommandId = element.getAttribute("addNewTargetCommandId");
|
||||
|
||||
ExecutableExtension<INewWizard> newWizard = null;
|
||||
if (element.getAttribute("newWizard") != null) {
|
||||
newWizard = new ExecutableExtension<INewWizard>(element, "newWizard");
|
||||
}
|
||||
|
||||
targetContributions.put(targetTypeId, new LaunchBarTargetContribution(targetName, iconStr,
|
||||
labelProvider, hoverProvider, editCommandId, addNewCommandId));
|
||||
labelProvider, hoverProvider, editCommandId, newWizard));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +88,18 @@ public class LaunchBarUIManager {
|
|||
}
|
||||
|
||||
public String getTargetTypeName(ILaunchTarget target) {
|
||||
return getContribution(target).name;
|
||||
return getTargetTypeName(target.getType());
|
||||
}
|
||||
|
||||
public String getTargetTypeName(ILaunchTargetType targetType) {
|
||||
String typeId = manager.getTargetTypeId(targetType);
|
||||
String name = targetContributions.get(typeId).name;
|
||||
return name != null ? name : typeId;
|
||||
}
|
||||
|
||||
public Image getTargetTypeIcon(ILaunchTargetType targetType) {
|
||||
String typeId = manager.getTargetTypeId(targetType);
|
||||
return targetContributions.get(typeId).getIcon();
|
||||
}
|
||||
|
||||
public ILabelProvider getLabelProvider(ILaunchTarget target) throws CoreException {
|
||||
|
@ -98,17 +116,17 @@ public class LaunchBarUIManager {
|
|||
return getContribution(target).editCommandId;
|
||||
}
|
||||
|
||||
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);
|
||||
public Map<ILaunchTargetType, ExecutableExtension<INewWizard>> getNewTargetWizards() {
|
||||
Map<ILaunchTargetType, ExecutableExtension<INewWizard>> wizards = new HashMap<>();
|
||||
for (Entry<String, LaunchBarTargetContribution> contrib : targetContributions.entrySet()) {
|
||||
if (contrib.getValue().newWizard != null) {
|
||||
ILaunchTargetType type = manager.getLaunchTargetType(contrib.getKey());
|
||||
if (type != null) {
|
||||
wizards.put(type, contrib.getValue().newWizard);
|
||||
}
|
||||
}
|
||||
}
|
||||
return commands;
|
||||
return wizards;
|
||||
}
|
||||
|
||||
public Map<String, Image> getTargetIcons() {
|
||||
|
@ -137,19 +155,20 @@ public class LaunchBarUIManager {
|
|||
ExecutableExtension<ILabelProvider> labelProvider;
|
||||
ExecutableExtension<IHoverProvider> hoverProvider;
|
||||
String editCommandId;
|
||||
String addNewCommandId;
|
||||
ExecutableExtension<INewWizard> newWizard;
|
||||
|
||||
LaunchBarTargetContribution(String name, String iconStr,
|
||||
ExecutableExtension<ILabelProvider> labelProvider,
|
||||
ExecutableExtension<IHoverProvider> hoverProvider,
|
||||
String editCommand, String addNewCommand) {
|
||||
String editCommand,
|
||||
ExecutableExtension<INewWizard> newWizard) {
|
||||
this.name = name;
|
||||
this.iconStr = iconStr;
|
||||
this.icon = null;
|
||||
this.labelProvider = labelProvider;
|
||||
this.hoverProvider = hoverProvider;
|
||||
this.editCommandId = editCommand;
|
||||
this.addNewCommandId = addNewCommand;
|
||||
this.newWizard = newWizard;
|
||||
}
|
||||
|
||||
Image getIcon() {
|
||||
|
|
|
@ -11,20 +11,19 @@
|
|||
package org.eclipse.cdt.launchbar.ui.internal.controls;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
|
||||
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.cdt.launchbar.ui.internal.dialogs.NewLaunchTargetWizard;
|
||||
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.jface.wizard.WizardDialog;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.MouseAdapter;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
|
@ -40,7 +39,6 @@ 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 {
|
||||
|
||||
|
@ -93,16 +91,16 @@ public class TargetSelector extends CSelector {
|
|||
@Override
|
||||
public String getText(Object element) {
|
||||
if (element instanceof ILaunchTarget) {
|
||||
ILaunchTarget target = (ILaunchTarget) element;
|
||||
try {
|
||||
ILabelProvider labelProvider = uiManager.getLabelProvider(target);
|
||||
if (labelProvider != null) {
|
||||
return labelProvider.getText(element);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
ILaunchTarget target = (ILaunchTarget) element;
|
||||
try {
|
||||
ILabelProvider labelProvider = uiManager.getLabelProvider(target);
|
||||
if (labelProvider != null) {
|
||||
return labelProvider.getText(element);
|
||||
}
|
||||
return target.getName();
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
}
|
||||
return target.getName();
|
||||
}
|
||||
return super.getText(element);
|
||||
}
|
||||
|
@ -170,7 +168,7 @@ public class TargetSelector extends CSelector {
|
|||
|
||||
@Override
|
||||
public boolean hasActionArea() {
|
||||
return !uiManager.getAddTargetCommands().isEmpty();
|
||||
return !uiManager.getNewTargetWizards().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -199,12 +197,14 @@ public class TargetSelector extends CSelector {
|
|||
|
||||
final Label createLabel = new Label(createButton, SWT.None);
|
||||
createLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
||||
createLabel.setText("Add New Target...");
|
||||
createLabel.setText("Create New Target...");
|
||||
createLabel.setBackground(white);
|
||||
|
||||
MouseListener mouseListener = new MouseAdapter() {
|
||||
public void mouseUp(org.eclipse.swt.events.MouseEvent e) {
|
||||
handleCreateTarget();
|
||||
NewLaunchTargetWizard wizard = new NewLaunchTargetWizard(uiManager);
|
||||
WizardDialog dialog = new WizardDialog(getShell(), wizard);
|
||||
dialog.open();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -217,7 +217,6 @@ public class TargetSelector extends CSelector {
|
|||
createButton.setBackground(highlightColor);
|
||||
createLabel.setBackground(highlightColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExit(MouseEvent e) {
|
||||
createButton.setBackground(white);
|
||||
|
@ -228,33 +227,6 @@ 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();
|
||||
|
|
|
@ -85,7 +85,6 @@ public class NewLaunchConfigEditPage extends WizardPage {
|
|||
tabFolder.setSelectionForeground(reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")); //$NON-NLS-1$
|
||||
|
||||
checkName();
|
||||
changeLaunchConfigType();
|
||||
|
||||
setControl(comp);
|
||||
}
|
||||
|
@ -110,11 +109,7 @@ public class NewLaunchConfigEditPage extends WizardPage {
|
|||
}
|
||||
}
|
||||
|
||||
void changeLaunchConfigType() {
|
||||
ILaunchConfigurationType type = ((NewLaunchConfigWizard)getWizard()).typePage.type;
|
||||
if (type == null)
|
||||
return;
|
||||
|
||||
void changeLaunchConfigType(ILaunchConfigurationType type) {
|
||||
try {
|
||||
String initialMode = ((NewLaunchConfigWizard)getWizard()).modePage.selectedGroup.getMode();
|
||||
workingCopy = type.newInstance(null, "New Configuration");
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.eclipse.swt.widgets.TableItem;
|
|||
public class NewLaunchConfigTypePage extends WizardPage {
|
||||
|
||||
private Table table;
|
||||
ILaunchConfigurationType type;
|
||||
|
||||
public NewLaunchConfigTypePage() {
|
||||
super("Select Launch Configuration Type");
|
||||
|
@ -75,8 +74,6 @@ public class NewLaunchConfigTypePage extends WizardPage {
|
|||
table.select(0);
|
||||
}
|
||||
setPageComplete(haveItems);
|
||||
|
||||
type = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -86,10 +83,9 @@ public class NewLaunchConfigTypePage extends WizardPage {
|
|||
|
||||
@Override
|
||||
public IWizardPage getNextPage() {
|
||||
setMessage("Initializing. Please wait...", INFORMATION);
|
||||
type = (ILaunchConfigurationType)table.getSelection()[0].getData();
|
||||
ILaunchConfigurationType type = (ILaunchConfigurationType)table.getSelection()[0].getData();
|
||||
NewLaunchConfigEditPage editPage = ((NewLaunchConfigWizard)getWizard()).editPage;
|
||||
editPage.changeLaunchConfigType();
|
||||
editPage.changeLaunchConfigType(type);
|
||||
return editPage;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
package org.eclipse.cdt.launchbar.ui.internal.dialogs;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.cdt.launchbar.core.ILaunchTargetType;
|
||||
import org.eclipse.cdt.launchbar.core.internal.Activator;
|
||||
import org.eclipse.cdt.launchbar.core.internal.ExecutableExtension;
|
||||
import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.wizard.IWizardPage;
|
||||
import org.eclipse.jface.wizard.WizardPage;
|
||||
import org.eclipse.swt.SWT;
|
||||
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.Table;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
import org.eclipse.ui.INewWizard;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
public class NewLaunchTargetTypePage extends WizardPage {
|
||||
|
||||
private final LaunchBarUIManager uiManager;
|
||||
private Table table;
|
||||
private ExecutableExtension<INewWizard> currentExtension;
|
||||
private INewWizard nextWizard;
|
||||
|
||||
public NewLaunchTargetTypePage(LaunchBarUIManager uiManager) {
|
||||
super("NewLaunchTargetTypePage");
|
||||
setTitle("Launch Target Type");
|
||||
setDescription("Select type of launch target to create.");
|
||||
this.uiManager = uiManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createControl(Composite parent) {
|
||||
Composite comp = new Composite(parent, SWT.NONE);
|
||||
comp.setLayout(new GridLayout());
|
||||
|
||||
table = new Table(comp, SWT.SINGLE | SWT.BORDER);
|
||||
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
|
||||
table.setLayoutData(data);
|
||||
|
||||
setPageComplete(false);
|
||||
for (Entry<ILaunchTargetType, ExecutableExtension<INewWizard>> entry : uiManager.getNewTargetWizards().entrySet()) {
|
||||
TableItem item = new TableItem(table, SWT.NONE);
|
||||
ILaunchTargetType targetType = entry.getKey();
|
||||
item.setText(uiManager.getTargetTypeName(targetType));
|
||||
Image icon = uiManager.getTargetTypeIcon(targetType);
|
||||
if (icon != null) {
|
||||
item.setImage(icon);
|
||||
}
|
||||
item.setData(entry.getValue());
|
||||
table.select(0);
|
||||
setPageComplete(true);
|
||||
}
|
||||
|
||||
setControl(comp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFlipToNextPage() {
|
||||
return isPageComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWizardPage getNextPage() {
|
||||
@SuppressWarnings("unchecked")
|
||||
ExecutableExtension<INewWizard> extension = (ExecutableExtension<INewWizard>) table.getSelection()[0].getData();
|
||||
if (extension != currentExtension) {
|
||||
try {
|
||||
nextWizard = extension.create();
|
||||
nextWizard.init(PlatformUI.getWorkbench(), null);
|
||||
nextWizard.addPages();
|
||||
currentExtension = extension;
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
if (nextWizard != null) {
|
||||
IWizardPage [] pages = nextWizard.getPages();
|
||||
if (pages.length > 0) {
|
||||
return pages[0];
|
||||
}
|
||||
}
|
||||
|
||||
return super.getNextPage();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*******************************************************************************
|
||||
* 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.cdt.launchbar.ui.internal.LaunchBarUIManager;
|
||||
import org.eclipse.jface.wizard.Wizard;
|
||||
|
||||
public class NewLaunchTargetWizard extends Wizard {
|
||||
|
||||
private final NewLaunchTargetTypePage typePage;
|
||||
|
||||
public NewLaunchTargetWizard(LaunchBarUIManager uiManager) {
|
||||
typePage = new NewLaunchTargetTypePage(uiManager);
|
||||
setForcePreviousAndNextButtons(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPages() {
|
||||
addPage(typePage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performFinish() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFinish() {
|
||||
// Need to move onto the new target wizard
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue