mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 01:36:01 +02:00
Bug 444781 - Fix error marker for invalid launch config name
fixed validation paths of the name/tabs markers Change-Id: I0e6f1dbcde00ea00c351fdf377429026b8a83bd3 Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com> Reviewed-on: https://git.eclipse.org/r/33923 Reviewed-by: Jonathan Williams <jonwilliams@qnx.com>
This commit is contained in:
parent
6be52837ae
commit
909315e0c7
1 changed files with 80 additions and 74 deletions
|
@ -40,7 +40,6 @@ import org.eclipse.swt.widgets.Label;
|
||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
public class NewLaunchConfigEditPage extends WizardPage {
|
public class NewLaunchConfigEditPage extends WizardPage {
|
||||||
|
|
||||||
ILaunchConfigurationWorkingCopy workingCopy;
|
ILaunchConfigurationWorkingCopy workingCopy;
|
||||||
ILaunchConfigurationTabGroup tabGroup;
|
ILaunchConfigurationTabGroup tabGroup;
|
||||||
private Text nameText;
|
private Text nameText;
|
||||||
|
@ -58,67 +57,66 @@ public class NewLaunchConfigEditPage extends WizardPage {
|
||||||
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(2, false));
|
||||||
|
|
||||||
Label label = new Label(comp, SWT.NONE);
|
Label label = new Label(comp, SWT.NONE);
|
||||||
label.setLayoutData(new GridData());
|
label.setLayoutData(new GridData());
|
||||||
label.setText("Name:");
|
label.setText("Name:");
|
||||||
|
|
||||||
nameText = new Text(comp, SWT.BORDER);
|
nameText = new Text(comp, SWT.BORDER);
|
||||||
nameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
nameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
||||||
nameText.addModifyListener(new ModifyListener() {
|
|
||||||
@Override
|
|
||||||
public void modifyText(ModifyEvent e) {
|
|
||||||
workingCopy.rename(nameText.getText());
|
|
||||||
checkName();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ColorRegistry reg = JFaceResources.getColorRegistry();
|
ColorRegistry reg = JFaceResources.getColorRegistry();
|
||||||
Color c1 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START"), //$NON-NLS-1$
|
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$
|
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);
|
tabFolder = new CTabFolder(comp, SWT.BORDER | SWT.NO_REDRAW_RESIZE | SWT.FLAT);
|
||||||
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
|
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
|
||||||
gridData.horizontalSpan = 2;
|
gridData.horizontalSpan = 2;
|
||||||
tabFolder.setLayoutData(gridData);
|
tabFolder.setLayoutData(gridData);
|
||||||
tabFolder.setSimple(false);
|
tabFolder.setSimple(false);
|
||||||
tabFolder.setSelectionBackground(new Color[] {c1, c2}, new int[] {100}, true);
|
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$
|
tabFolder.setSelectionForeground(reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")); //$NON-NLS-1$
|
||||||
|
|
||||||
checkName();
|
|
||||||
|
|
||||||
setControl(comp);
|
setControl(comp);
|
||||||
}
|
nameText.addModifyListener(new ModifyListener() {
|
||||||
|
@Override
|
||||||
private void checkName() {
|
public void modifyText(ModifyEvent e) {
|
||||||
if (workingCopy == null)
|
String name = nameText.getText();
|
||||||
return;
|
if (!name.equals(workingCopy.getName())) {
|
||||||
|
String errMessage = checkName(name);
|
||||||
try {
|
if (errMessage == null) {
|
||||||
if (workingCopy.getName().isEmpty()) {
|
workingCopy.rename(name);
|
||||||
setErrorMessage("Name can not be empty");
|
validateFields();
|
||||||
setPageComplete(false);
|
} else {
|
||||||
} else if (DebugPlugin.getDefault().getLaunchManager().isExistingLaunchConfigurationName(workingCopy.getName())) {
|
setErrorMessage(errMessage);
|
||||||
setErrorMessage("A configuration with this name already exists");
|
}
|
||||||
setPageComplete(false);
|
}
|
||||||
} else {
|
|
||||||
setErrorMessage(null);
|
|
||||||
setPageComplete(true);
|
|
||||||
}
|
}
|
||||||
} catch (CoreException exc) {
|
});
|
||||||
setErrorMessage(exc.getLocalizedMessage());
|
validateFields();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String checkName(String name) {
|
||||||
|
try {
|
||||||
|
if (name.isEmpty()) {
|
||||||
|
return "Name can not be empty";
|
||||||
|
} else if (DebugPlugin.getDefault().getLaunchManager().isExistingLaunchConfigurationName(name)) {
|
||||||
|
return ("A configuration with this name already exists");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Activator.log(e);
|
||||||
|
return (e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void changeLaunchConfigType(ILaunchConfigurationType type) {
|
void changeLaunchConfigType(ILaunchConfigurationType type) {
|
||||||
|
if (type == null)
|
||||||
|
return;
|
||||||
try {
|
try {
|
||||||
String initialMode = ((NewLaunchConfigWizard)getWizard()).modePage.selectedGroup.getMode();
|
String initialMode = ((NewLaunchConfigWizard) getWizard()).modePage.selectedGroup.getMode();
|
||||||
workingCopy = type.newInstance(null, "New Configuration");
|
workingCopy = type.newInstance(null, "New Configuration");
|
||||||
tabGroup = LaunchConfigurationPresentationManager.getDefault().getTabGroup(workingCopy, initialMode);
|
tabGroup = LaunchConfigurationPresentationManager.getDefault().getTabGroup(workingCopy, initialMode);
|
||||||
nameText.setText(workingCopy.getName());
|
nameText.setText(workingCopy.getName());
|
||||||
|
|
||||||
for (CTabItem item : tabFolder.getItems())
|
for (CTabItem item : tabFolder.getItems())
|
||||||
item.dispose();
|
item.dispose();
|
||||||
|
|
||||||
tabGroup.createTabs(launchConfigurationDialog, initialMode);
|
tabGroup.createTabs(launchConfigurationDialog, initialMode);
|
||||||
boolean firstTab = true;
|
boolean firstTab = true;
|
||||||
for (ILaunchConfigurationTab tab : tabGroup.getTabs()) {
|
for (ILaunchConfigurationTab tab : tabGroup.getTabs()) {
|
||||||
|
@ -153,15 +151,55 @@ public class NewLaunchConfigEditPage extends WizardPage {
|
||||||
boolean performFinish() {
|
boolean performFinish() {
|
||||||
if (workingCopy == null)
|
if (workingCopy == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (ILaunchConfigurationTab tab : tabGroup.getTabs())
|
for (ILaunchConfigurationTab tab : tabGroup.getTabs())
|
||||||
tab.performApply(workingCopy);
|
tab.performApply(workingCopy);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LaunchConfigurationDialog implements ILaunchConfigurationDialog {
|
public void validateFields() {
|
||||||
|
if (workingCopy == null)
|
||||||
|
return;
|
||||||
|
String message = null;
|
||||||
|
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);
|
||||||
|
if (getErrorMessage() != null) {
|
||||||
|
setPageComplete(false);
|
||||||
|
} else {
|
||||||
|
setPageComplete(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class LaunchConfigurationDialog implements ILaunchConfigurationDialog {
|
||||||
@Override
|
@Override
|
||||||
public void run(boolean fork, boolean cancelable,
|
public void run(boolean fork, boolean cancelable,
|
||||||
IRunnableWithProgress runnable)
|
IRunnableWithProgress runnable)
|
||||||
|
@ -175,44 +213,12 @@ public class NewLaunchConfigEditPage extends WizardPage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMessage() {
|
public void updateMessage() {
|
||||||
String message = null;
|
validateFields();
|
||||||
String old_msg = getErrorMessage();
|
|
||||||
ILaunchConfigurationTab[] tabs = tabGroup.getTabs();
|
|
||||||
ILaunchConfigurationTab tab;
|
|
||||||
CTabItem item;
|
|
||||||
int tLen = tabs.length;
|
|
||||||
int tfLen = tabFolder.getItems().length;
|
|
||||||
for (int i = 0; i < tLen; i++) {
|
|
||||||
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)) {
|
|
||||||
item = tabFolder.getItem(i);
|
|
||||||
if (item != null) {
|
|
||||||
item.setImage(message != null ? launchConfigurationMgr.getErrorTabImage(tab)
|
|
||||||
: tab.getImage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message != null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setErrorMessage(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -236,7 +242,7 @@ public class NewLaunchConfigEditPage extends WizardPage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMode() {
|
public String getMode() {
|
||||||
return ((NewLaunchConfigWizard)getWizard()).modePage.selectedGroup.getMode();
|
return ((NewLaunchConfigWizard) getWizard()).modePage.selectedGroup.getMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue