From bc661996aa1be1bfd9c52c613f0abdb28e782140 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Fri, 13 Oct 2017 12:07:33 -0400 Subject: [PATCH] Combine Mode and Type into a single page for new configs. Change-Id: Ic8c6a4580ecd7dcb4435b204c10f37703ad1443a --- .../launchbar/ui/NewLaunchConfigWizard.java | 61 +----- .../launchbar/ui/internal/Messages.java | 4 + .../dialogs/NewLaunchConfigTypePage2.java | 200 ++++++++++++++++++ .../launchbar/ui/internal/messages.properties | 4 +- 4 files changed, 216 insertions(+), 53 deletions(-) create mode 100644 bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/dialogs/NewLaunchConfigTypePage2.java diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/NewLaunchConfigWizard.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/NewLaunchConfigWizard.java index b6adf46ac13..66cac5a4b21 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/NewLaunchConfigWizard.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/NewLaunchConfigWizard.java @@ -19,28 +19,25 @@ 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.debug.ui.ILaunchGroup; import org.eclipse.jface.wizard.IWizardContainer; import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.launchbar.ui.internal.Activator; import org.eclipse.launchbar.ui.internal.Messages; import org.eclipse.launchbar.ui.internal.dialogs.NewLaunchConfigEditPage; -import org.eclipse.launchbar.ui.internal.dialogs.NewLaunchConfigModePage; -import org.eclipse.launchbar.ui.internal.dialogs.NewLaunchConfigTypePage; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Composite; +import org.eclipse.launchbar.ui.internal.dialogs.NewLaunchConfigTypePage2; public class NewLaunchConfigWizard extends Wizard implements ILaunchConfigurationListener { - private NewLaunchConfigModePage modePage = new NewLaunchConfigModePage(); - private NewLaunchConfigTypePage typePage = new NewLaunchConfigTypePage(); - private NewLaunchConfigEditPage editPage = new NewLaunchConfigEditPage(); + private NewLaunchConfigTypePage2 typePage; + private NewLaunchConfigEditPage editPage; private List configsToDelete = new ArrayList<>(); public NewLaunchConfigWizard() { + editPage = new NewLaunchConfigEditPage(); + typePage = new NewLaunchConfigTypePage2(editPage); + setWindowTitle(Messages.NewLaunchConfigWizard_0); // while the wizard is open, some ill behaved launch config tabs save the working copy. @@ -50,46 +47,6 @@ public class NewLaunchConfigWizard extends Wizard implements ILaunchConfiguratio DebugPlugin.getDefault().getLaunchManager().addLaunchConfigurationListener(this); } - @Override - public void createPageControls(Composite pageContainer) { - super.createPageControls(pageContainer); - - // Link the pages - SelectionListener modePageListener = new SelectionListener() { - @Override - public void widgetSelected(SelectionEvent e) { - ILaunchGroup selectedGroup = modePage.getSelectedGroup(); - typePage.setLaunchGroup(selectedGroup); - editPage.setLaunchGroup(selectedGroup); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); - getContainer().showPage(modePage.getNextPage()); - } - }; - modePage.addGroupSelectionListener(modePageListener); - modePageListener.widgetSelected(null); - - SelectionListener typePageListener = new SelectionListener() { - @Override - public void widgetSelected(SelectionEvent e) { - editPage.setLaunchConfigType(typePage.getSelectedType()); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); - getContainer().showPage(typePage.getNextPage()); - } - }; - typePage.addTypeSelectionListener(typePageListener); - typePageListener.widgetSelected(null); - - editPage.setLaunchConfigType(typePage.getSelectedType()); - } - @Override public void setContainer(IWizardContainer wizardContainer) { super.setContainer(wizardContainer); @@ -102,7 +59,6 @@ public class NewLaunchConfigWizard extends Wizard implements ILaunchConfiguratio @Override public void addPages() { - addPage(modePage); addPage(typePage); addPage(editPage); } @@ -120,8 +76,9 @@ public class NewLaunchConfigWizard extends Wizard implements ILaunchConfiguratio } public ILaunchMode getLaunchMode() { - String initMode = modePage.getSelectedGroup().getMode(); - return DebugPlugin.getDefault().getLaunchManager().getLaunchMode(initMode); + // TODO we want to make sure the newly created config has the right mode + // selected in the launch bar + return null; } @Override diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java index e220d9b1e10..105892d1fff 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java @@ -31,6 +31,10 @@ public class Messages extends NLS { public static String NewLaunchConfigTypePage_0; public static String NewLaunchConfigTypePage_1; public static String NewLaunchConfigTypePage_2; + + public static String NewLaunchConfigTypePage2_Mode; + + public static String NewLaunchConfigTypePage2_Type; public static String NewLaunchConfigWizard_0; public static String NewLaunchTargetWizard_Title; diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/dialogs/NewLaunchConfigTypePage2.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/dialogs/NewLaunchConfigTypePage2.java new file mode 100644 index 00000000000..b33a13278df --- /dev/null +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/dialogs/NewLaunchConfigTypePage2.java @@ -0,0 +1,200 @@ +/******************************************************************************* + * Copyright (c) 2017 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 + *******************************************************************************/ +package org.eclipse.launchbar.ui.internal.dialogs; + +import java.util.Arrays; +import java.util.Comparator; + +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.launchbar.ui.internal.Messages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; + +public class NewLaunchConfigTypePage2 extends WizardPage { + + private final NewLaunchConfigEditPage editPage; + + private Table modeTable; + private Table typeTable; + + public NewLaunchConfigTypePage2(NewLaunchConfigEditPage editPage) { + super(NewLaunchConfigTypePage2.class.getName()); + this.editPage = editPage; + setTitle(Messages.NewLaunchConfigTypePage_1); + setDescription(Messages.NewLaunchConfigTypePage_2); + } + + @Override + public void createControl(Composite parent) { + Composite comp = new Composite(parent, SWT.NONE); + comp.setLayout(new GridLayout()); + + Group modeGroup = new Group(comp, SWT.NONE); + modeGroup.setText(Messages.NewLaunchConfigTypePage2_Mode); + modeGroup.setLayout(new GridLayout()); + modeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + modeTable = new Table(modeGroup, SWT.SINGLE | SWT.BORDER); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); + data.heightHint = 100; + modeTable.setLayoutData(data); + modeTable.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + modeChanged(); + } + }); + + Group typeGroup = new Group(comp, SWT.NONE); + typeGroup.setText(Messages.NewLaunchConfigTypePage2_Type); + typeGroup.setLayout(new GridLayout()); + typeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + typeTable = new Table(typeGroup, SWT.SINGLE | SWT.BORDER); + typeTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + typeTable.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + typeChanged(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + getContainer().showPage(getNextPage()); + } + }); + + populateMode(); + + setControl(comp); + } + + private void populateMode() { + int select = -1; + + for (ILaunchGroup group : DebugUITools.getLaunchGroups()) { + if (group.getMode().equals("run")) { //$NON-NLS-1$ + if (createModeItem(modeTable, group)) { + select++; + } + } + } + + for (ILaunchGroup group : DebugUITools.getLaunchGroups()) { + if (group.getMode().equals("debug")) { //$NON-NLS-1$ + if (createModeItem(modeTable, group)) { + select++; + } + } + } + + for (ILaunchGroup group : DebugUITools.getLaunchGroups()) { + if (!group.getMode().equals("run") && !group.getMode().equals("debug")) { //$NON-NLS-1$ //$NON-NLS-2$ + createModeItem(modeTable, group); + } + } + + if (select >= 0) { + modeTable.select(select); + modeChanged(); + } else if (modeTable.getItemCount() > 0) { + modeTable.select(0); + modeChanged(); + } else { + setPageComplete(false); + } + } + + private boolean createModeItem(Table table, ILaunchGroup group) { + if (group.getCategory() != null || !group.isPublic()) + return false; + + TableItem item = new TableItem(table, SWT.NONE); + item.setText(group.getLabel().replace("&", "")); //$NON-NLS-1$ //$NON-NLS-2$ + ImageDescriptor imageDesc = group.getImageDescriptor(); + if (imageDesc != null) { + item.setImage(imageDesc.createImage()); + } + item.setData(group); + + return true; + } + + private void modeChanged() { + TableItem[] selection = modeTable.getSelection(); + if (selection.length == 0) { + editPage.setLaunchGroup(null); + setPageComplete(false); + return; + } + + ILaunchGroup group = (ILaunchGroup) selection[0].getData(); + editPage.setLaunchGroup(group); + + ILaunchConfigurationType[] types = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationTypes(); + Arrays.sort(types, new Comparator() { + @Override + public int compare(ILaunchConfigurationType type0, ILaunchConfigurationType type1) { + int comp = type0.getPluginIdentifier().compareTo(type1.getPluginIdentifier()); + if (comp != 0) { + return comp; + } else { + return type0.getName().compareTo(type1.getName()); + } + } + }); + + typeTable.removeAll(); + for (ILaunchConfigurationType type : types) { + if (!type.isPublic() || type.getCategory() != null || !type.supportsMode(group.getMode())) + continue; + + TableItem item = new TableItem(typeTable, SWT.NONE); + item.setText(type.getName()); + ImageDescriptor imageDesc = DebugUITools.getDefaultImageDescriptor(type); + if (imageDesc != null) + item.setImage(imageDesc.createImage()); + item.setData(type); + } + + if (typeTable.getItemCount() > 0) { + typeTable.select(0); + typeChanged(); + } else { + setPageComplete(false); + } + } + + private void typeChanged() { + TableItem[] selection = typeTable.getSelection(); + if (selection.length == 0) { + editPage.setLaunchConfigType(null); + setPageComplete(false); + return; + } + + ILaunchConfigurationType type = (ILaunchConfigurationType) selection[0].getData(); + editPage.setLaunchConfigType(type); + setPageComplete(true); + } + +} diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties index 8f0cabb106c..4e66d904734 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties @@ -23,7 +23,9 @@ NewLaunchConfigModePage_1=Initial Launch Mode NewLaunchConfigModePage_2=Select initial launch mode. NewLaunchConfigTypePage_0=Select Launch Configuration Type NewLaunchConfigTypePage_1=Launch Configuration Type -NewLaunchConfigTypePage_2=Select the type of launch configuration to create. +NewLaunchConfigTypePage_2=Select the mode and type of the launch configuration to create. +NewLaunchConfigTypePage2_Mode=Launch Mode +NewLaunchConfigTypePage2_Type=Launch Configuration Type NewLaunchConfigWizard_0=Create Launch Configuration NewLaunchTargetWizard_Title=New Launch Target