1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-11 11:05:24 +02:00

LaunchBar: use o.e.debug control to manage lc tabs

- current wizard page tries to replicate functionality
of lc editor in regards to tabs but it does not work
the same which creates issues for contributed tabs
- for example it never calls "activate" on the tab
- we also have rendering problem - pages are not resized correctly and
show up empty until resized
- I switched to use standard control called
LaunchConfigurationTabGroupViewer to show tabs. Hack with fake
LaunchConfigurationDialog has to remain to interact with this control.
- If we move it to o.e.debug we have to fix these classes to remove some
of the hacks and expose proper APIs to re-use this control

Change-Id: Ia39706fb5972883167f5f39751985d97e1815c86
This commit is contained in:
Alena Laskavaia 2015-10-06 11:44:32 -04:00
parent 117074d323
commit 50e08bc7d5
4 changed files with 92 additions and 199 deletions

View file

@ -17,43 +17,28 @@ import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.internal.core.LaunchManager;
import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationDialog; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationDialog;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationPresentationManager;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension;
import org.eclipse.debug.ui.ILaunchConfigurationTab; import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTabGroup;
import org.eclipse.debug.ui.ILaunchGroup; import org.eclipse.debug.ui.ILaunchGroup;
import org.eclipse.jface.operation.IRunnableWithProgress; 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.jface.wizard.WizardPage;
import org.eclipse.launchbar.ui.internal.Activator; import org.eclipse.launchbar.ui.internal.Activator;
import org.eclipse.launchbar.ui.internal.Messages; import org.eclipse.launchbar.ui.internal.Messages;
import org.eclipse.swt.SWT; 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.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.Text;
@SuppressWarnings("restriction") @SuppressWarnings("restriction")
public class NewLaunchConfigEditPage extends WizardPage { public class NewLaunchConfigEditPage extends WizardPage {
ILaunchConfigurationWorkingCopy workingCopy; private ILaunchConfigurationWorkingCopy workingCopy;
ILaunchConfigurationTabGroup tabGroup; private LaunchConfigurationDialogExt launchConfigurationDialog = new LaunchConfigurationDialogExt();
private Text nameText; private LaunchConfigurationTabGroupViewerExt tabViewer;
private CTabFolder tabFolder; private ILaunchConfigurationType type;
private LaunchConfigurationDialog launchConfigurationDialog = new LaunchConfigurationDialogFake();
private LaunchConfigurationManager launchConfigurationMgr = DebugUIPlugin.getDefault().getLaunchConfigurationManager();
public NewLaunchConfigEditPage() { public NewLaunchConfigEditPage() {
super(Messages.NewLaunchConfigEditPage_0); super(Messages.NewLaunchConfigEditPage_0);
@ -64,111 +49,50 @@ public class NewLaunchConfigEditPage extends WizardPage {
@Override @Override
public void createControl(Composite parent) { public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE); Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new GridLayout(2, false)); comp.setLayout(new GridLayout(1, false));
Label label = new Label(comp, SWT.NONE);
label.setLayoutData(new GridData());
label.setText(Messages.NewLaunchConfigEditPage_3 + ":"); //$NON-NLS-1$
nameText = new Text(comp, SWT.BORDER);
nameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
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$
setControl(comp); setControl(comp);
nameText.addModifyListener(new ModifyListener() { // create tab viewer
@Override LaunchConfigurationsDialog.setCurrentlyVisibleLaunchConfigurationDialog(launchConfigurationDialog);
public void modifyText(ModifyEvent e) { tabViewer = new LaunchConfigurationTabGroupViewerExt(comp, launchConfigurationDialog);
String name = nameText.getText().trim(); launchConfigurationDialog.setTabViewer(tabViewer);
workingCopy.rename(name); changeLaunchConfigType(type);
GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
String errMessage = checkName(name); data.heightHint = 500;
if (errMessage == null) { tabViewer.getControl().setLayoutData(data);
validateFields(); parent.layout(true, true);
} else {
setErrorMessage(errMessage);
}
}
});
validateFields(); validateFields();
} }
private String checkName(String name) { /**
try { * @return the workingCopy
if (name.isEmpty()) { */
return Messages.NewLaunchConfigEditPage_4; public ILaunchConfigurationWorkingCopy getWorkingCopy() {
} return workingCopy;
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
if (manager.isExistingLaunchConfigurationName(name)) {
ILaunchConfiguration config = ((LaunchManager) manager).findLaunchConfiguration(name);
if (config != workingCopy.getOriginal()) {
return (Messages.NewLaunchConfigEditPage_5);
}
}
} catch (Exception e) {
Activator.log(e);
return (e.getLocalizedMessage());
}
return null;
} }
void changeLaunchConfigType(ILaunchConfigurationType type) { void changeLaunchConfigType(ILaunchConfigurationType type) {
if (type == null) if (type == null)
return; return;
try { try {
String initialMode = ((NewLaunchConfigWizard) getWizard()).modePage.selectedGroup.getMode(); this.type = type;
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
String name = manager.generateLaunchConfigurationName("launchConfiguration"); //$NON-NLS-1$
workingCopy = type.newInstance(null, name);
tabGroup = LaunchConfigurationPresentationManager.getDefault().getTabGroup(workingCopy, initialMode);
for (CTabItem item : tabFolder.getItems())
item.dispose();
LaunchConfigurationsDialog.setCurrentlyVisibleLaunchConfigurationDialog(launchConfigurationDialog); LaunchConfigurationsDialog.setCurrentlyVisibleLaunchConfigurationDialog(launchConfigurationDialog);
tabGroup.createTabs(launchConfigurationDialog, initialMode); if (tabViewer != null) {
String name = launchConfigurationDialog.generateName("launchConfiguration"); //$NON-NLS-1$
for (ILaunchConfigurationTab tab : tabGroup.getTabs()) { workingCopy = type.newInstance(null, name);
tab.setLaunchConfigurationDialog(launchConfigurationDialog); launchConfigurationDialog.doSetDefaults(workingCopy);
tab.createControl(tabFolder); tabViewer.setInput(workingCopy);
tab.setDefaults(workingCopy);
} }
// Do this after all the tabs have their controls created
for (ILaunchConfigurationTab tab : tabGroup.getTabs()) {
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());
}
// Clean up any created configs before we set the name and trigger
// any validation
((NewLaunchConfigWizard) getWizard()).cleanUpConfigs();
tabFolder.setSelection(0);
nameText.setText(workingCopy.getName());
} catch (CoreException e) { } catch (CoreException e) {
Activator.log(e); Activator.log(e);
return; return;
} }
} }
boolean performFinish() { boolean performFinish() {
if (workingCopy == null) if (workingCopy == null)
return false; return false;
for (ILaunchConfigurationTab tab : tabGroup.getTabs()) workingCopy.rename(tabViewer.getWorkingCopy().getName());
tab.performApply(workingCopy); tabViewer.getTabGroup().performApply(workingCopy);
LaunchConfigurationsDialog.setCurrentlyVisibleLaunchConfigurationDialog(null); LaunchConfigurationsDialog.setCurrentlyVisibleLaunchConfigurationDialog(null);
return true; return true;
} }
@ -183,38 +107,7 @@ public class NewLaunchConfigEditPage extends WizardPage {
setPageComplete(false); setPageComplete(false);
if (workingCopy == null) if (workingCopy == null)
return; return;
String message = null; String message = tabViewer.getErrorMesssage();
String old_msg = getErrorMessage();
setErrorMessage(null);
message = checkName(workingCopy.getName());
if (message == null) {
ILaunchConfigurationTab[] tabs = tabGroup.getTabs();
int tLen = tabs.length;
int tfLen = tabFolder.getItems().length;
for (int i = 0; i < tLen; i++) {
ILaunchConfigurationTab 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)) {
CTabItem item = tabFolder.getItem(i);
if (item != null) {
item.setImage(message != null ? launchConfigurationMgr.getErrorTabImage(tab)
: tab.getImage());
}
}
if (message != null) {
break;
}
}
}
setErrorMessage(message); setErrorMessage(message);
if (getErrorMessage() != null) { if (getErrorMessage() != null) {
setPageComplete(false); setPageComplete(false);
@ -223,8 +116,8 @@ public class NewLaunchConfigEditPage extends WizardPage {
} }
} }
private class LaunchConfigurationDialogFake extends LaunchConfigurationDialog { private class LaunchConfigurationDialogExt extends LaunchConfigurationDialog {
public LaunchConfigurationDialogFake() { public LaunchConfigurationDialogExt() {
super(NewLaunchConfigEditPage.this.getShell(), null, null); super(NewLaunchConfigEditPage.this.getShell(), null, null);
} }
@ -250,24 +143,22 @@ public class NewLaunchConfigEditPage extends WizardPage {
return NewLaunchConfigEditPage.this.getMode(); return NewLaunchConfigEditPage.this.getMode();
} }
@Override
public void run(boolean fork, boolean cancelable,
IRunnableWithProgress runnable)
throws InvocationTargetException, InterruptedException {
// ignore
}
@Override
public void updateButtons() {
}
@Override @Override
public void updateMessage() { public void updateMessage() {
validateFields(); validateFields();
} }
@Override @Override
public void setName(String name) { public void updateButtons() {
// Launch button
getTabViewer().refresh();
// getButton(ID_LAUNCH_BUTTON).setEnabled(getTabViewer().canLaunch() & getTabViewer().canLaunchWithModes() & !getTabViewer().hasDuplicateDelegates());
}
@Override
public void run(boolean fork, boolean cancelable,
IRunnableWithProgress runnable)
throws InvocationTargetException, InterruptedException {
// ignore // ignore
} }
@ -279,36 +170,27 @@ public class NewLaunchConfigEditPage extends WizardPage {
} }
@Override @Override
public ILaunchConfigurationTab[] getTabs() { public void doSetDefaults(ILaunchConfigurationWorkingCopy wc) {
return tabGroup.getTabs(); super.doSetDefaults(wc);
} }
@Override @Override
public ILaunchConfigurationTab getActiveTab() { public void setTabViewer(LaunchConfigurationTabGroupViewer viewer) {
int i = tabFolder.getSelectionIndex(); super.setTabViewer(viewer);
return tabGroup.getTabs()[i];
}
@Override
public void setActiveTab(ILaunchConfigurationTab tab) {
ILaunchConfigurationTab[] tabs = tabGroup.getTabs();
int tLen = tabs.length;
for (int i = 0; i < tLen; i++) {
ILaunchConfigurationTab tabi = tabs[i];
if (tabi.equals(tab)) {
setActiveTab(i);
break;
}
}
}
@Override
public void setActiveTab(int index) {
tabFolder.setSelection(index);
} }
} }
private class LaunchConfigurationTabGroupViewerExt extends LaunchConfigurationTabGroupViewer {
public LaunchConfigurationTabGroupViewerExt(Composite parent, ILaunchConfigurationDialog dialog) {
super(parent, dialog);
}
@Override
public ILaunchConfigurationWorkingCopy getWorkingCopy() {
return super.getWorkingCopy();
}
};
public String getMode() { public String getMode() {
return ((NewLaunchConfigWizard) getWizard()).modePage.selectedGroup.getMode(); return ((NewLaunchConfigWizard) getWizard()).modePage.selectedGroup.getMode();
} }

View file

@ -31,38 +31,38 @@ public class NewLaunchConfigModePage extends WizardPage {
private Table table; private Table table;
ILaunchGroup selectedGroup; ILaunchGroup selectedGroup;
public NewLaunchConfigModePage() { public NewLaunchConfigModePage() {
super(Messages.NewLaunchConfigModePage_0); super(Messages.NewLaunchConfigModePage_0);
setTitle(Messages.NewLaunchConfigModePage_1); setTitle(Messages.NewLaunchConfigModePage_1);
setDescription(Messages.NewLaunchConfigModePage_2); setDescription(Messages.NewLaunchConfigModePage_2);
} }
@Override @Override
public void createControl(Composite parent) { public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE); Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new GridLayout(1, false)); comp.setLayout(new GridLayout(1, false));
table = new Table(comp, SWT.SINGLE | SWT.BORDER); table = new Table(comp, SWT.SINGLE | SWT.BORDER);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
table.setLayoutData(data); table.setLayoutData(data);
Set<ILaunchGroup> done = new HashSet<>(); Set<ILaunchGroup> done = new HashSet<>();
for (ILaunchGroup group : DebugUITools.getLaunchGroups()) { for (ILaunchGroup group : DebugUITools.getLaunchGroups()) {
if (group.getMode().equals("run")) { //$NON-NLS-1$ if (group.getMode().equals("run")) { //$NON-NLS-1$
createModeItem(group); createModeItem(group);
done.add(group); done.add(group);
} }
} }
for (ILaunchGroup group : DebugUITools.getLaunchGroups()) { for (ILaunchGroup group : DebugUITools.getLaunchGroups()) {
if (group.getMode().equals("debug")) { //$NON-NLS-1$ if (group.getMode().equals("debug")) { //$NON-NLS-1$
createModeItem(group); createModeItem(group);
done.add(group); done.add(group);
} }
} }
for (ILaunchGroup group : DebugUITools.getLaunchGroups()) { for (ILaunchGroup group : DebugUITools.getLaunchGroups()) {
if (!done.contains(group)) { if (!done.contains(group)) {
createModeItem(group); createModeItem(group);
@ -87,7 +87,7 @@ public class NewLaunchConfigModePage extends WizardPage {
} }
selectedGroup = (ILaunchGroup) table.getSelection()[0].getData(); selectedGroup = (ILaunchGroup) table.getSelection()[0].getData();
} }
table.addSelectionListener(new SelectionAdapter() { table.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
@ -102,7 +102,7 @@ public class NewLaunchConfigModePage extends WizardPage {
private void createModeItem(ILaunchGroup group) { private void createModeItem(ILaunchGroup group) {
if (group.getCategory() != null || !group.isPublic()) if (group.getCategory() != null || !group.isPublic())
return; return;
TableItem item = new TableItem(table, SWT.NONE); TableItem item = new TableItem(table, SWT.NONE);
item.setText(group.getLabel().replace("&", "")); //$NON-NLS-1$ //$NON-NLS-2$ item.setText(group.getLabel().replace("&", "")); //$NON-NLS-1$ //$NON-NLS-2$
ImageDescriptor imageDesc = group.getImageDescriptor(); ImageDescriptor imageDesc = group.getImageDescriptor();

View file

@ -26,27 +26,26 @@ import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.TableItem;
public class NewLaunchConfigTypePage extends WizardPage { public class NewLaunchConfigTypePage extends WizardPage {
private Table table; private Table table;
public NewLaunchConfigTypePage() { public NewLaunchConfigTypePage() {
super(Messages.NewLaunchConfigTypePage_0); super(Messages.NewLaunchConfigTypePage_0);
setTitle(Messages.NewLaunchConfigTypePage_1); setTitle(Messages.NewLaunchConfigTypePage_1);
setDescription(Messages.NewLaunchConfigTypePage_2); setDescription(Messages.NewLaunchConfigTypePage_2);
} }
@Override @Override
public void createControl(Composite parent) { public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE); Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new GridLayout(1, false)); comp.setLayout(new GridLayout(1, false));
table = new Table(comp, SWT.SINGLE | SWT.BORDER); table = new Table(comp, SWT.SINGLE | SWT.BORDER);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
data.heightHint = 500; data.heightHint = 500;
table.setLayoutData(data); table.setLayoutData(data);
populateItems(); populateItems();
setControl(comp); setControl(comp);
} }
@ -70,7 +69,7 @@ public class NewLaunchConfigTypePage extends WizardPage {
item.setImage(imageDesc.createImage()); item.setImage(imageDesc.createImage());
item.setData(type); item.setData(type);
} }
if (haveItems) { if (haveItems) {
table.select(0); table.select(0);
} }
@ -84,10 +83,14 @@ public class NewLaunchConfigTypePage extends WizardPage {
@Override @Override
public IWizardPage getNextPage() { public IWizardPage getNextPage() {
ILaunchConfigurationType type = (ILaunchConfigurationType)table.getSelection()[0].getData(); ILaunchConfigurationType type = (ILaunchConfigurationType) table.getSelection()[0].getData();
NewLaunchConfigEditPage editPage = ((NewLaunchConfigWizard)getWizard()).editPage; NewLaunchConfigWizard wiz = (NewLaunchConfigWizard) getWizard();
NewLaunchConfigEditPage editPage = wiz.editPage;
// lazy page creation
if (wiz.getPage(editPage.getName()) == null) {
wiz.addPage(editPage);
}
editPage.changeLaunchConfigType(type); editPage.changeLaunchConfigType(type);
return editPage; return editPage;
} }
} }

View file

@ -28,28 +28,36 @@ public class NewLaunchConfigWizard extends Wizard implements ILaunchConfiguratio
NewLaunchConfigModePage modePage = new NewLaunchConfigModePage(); NewLaunchConfigModePage modePage = new NewLaunchConfigModePage();
NewLaunchConfigTypePage typePage = new NewLaunchConfigTypePage(); NewLaunchConfigTypePage typePage = new NewLaunchConfigTypePage();
NewLaunchConfigEditPage editPage = new NewLaunchConfigEditPage(); NewLaunchConfigEditPage editPage = new NewLaunchConfigEditPage();
private List<ILaunchConfiguration> configsToDelete = new ArrayList<>(); private List<ILaunchConfiguration> configsToDelete = new ArrayList<>();
public NewLaunchConfigWizard() { public NewLaunchConfigWizard() {
setWindowTitle(Messages.NewLaunchConfigWizard_0); setWindowTitle(Messages.NewLaunchConfigWizard_0);
initListeners(); initListeners();
} }
@Override @Override
public void addPages() { public void addPages() {
addPage(modePage); addPage(modePage);
addPage(typePage); addPage(typePage);
addPage(editPage); //addPage(editPage); // add dynamically on the types page
} }
@Override
public boolean canFinish() {
if (getPage(editPage.getName()) == null) {
return false;
}
return super.canFinish();
}
public ILaunchConfigurationWorkingCopy getWorkingCopy() { public ILaunchConfigurationWorkingCopy getWorkingCopy() {
return editPage.workingCopy; return editPage.getWorkingCopy();
} }
public ILaunchMode getLaunchMode() { public ILaunchMode getLaunchMode() {
String initMode = modePage.selectedGroup.getMode(); String initMode = modePage.selectedGroup.getMode();
return DebugPlugin.getDefault().getLaunchManager().getLaunchMode(initMode); return DebugPlugin.getDefault().getLaunchManager().getLaunchMode(initMode);
} }
@Override @Override