diff options
author | Alena Laskavaia | 2014-09-25 20:32:15 +0000 |
---|---|---|
committer | Elena Laskavaia | 2014-10-01 19:08:28 +0000 |
commit | 909315e0c79102a25aa65b87fb457624133dc106 (patch) | |
tree | 8c158a7bde1f43f5fea83a928b606c3a2d36965d /launch | |
parent | 6be52837ae6861f2b2306e9f774dec7a420dff8f (diff) | |
download | org.eclipse.cdt-909315e0c79102a25aa65b87fb457624133dc106.tar.gz org.eclipse.cdt-909315e0c79102a25aa65b87fb457624133dc106.tar.xz org.eclipse.cdt-909315e0c79102a25aa65b87fb457624133dc106.zip |
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>
Diffstat (limited to 'launch')
-rw-r--r-- | launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/dialogs/NewLaunchConfigEditPage.java | 128 |
1 files changed, 67 insertions, 61 deletions
diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/dialogs/NewLaunchConfigEditPage.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/dialogs/NewLaunchConfigEditPage.java index 751d979c281..ca2fc6622f8 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/dialogs/NewLaunchConfigEditPage.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/dialogs/NewLaunchConfigEditPage.java @@ -40,7 +40,6 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; public class NewLaunchConfigEditPage extends WizardPage { - ILaunchConfigurationWorkingCopy workingCopy; ILaunchConfigurationTabGroup tabGroup; private Text nameText; @@ -58,67 +57,66 @@ public class NewLaunchConfigEditPage extends WizardPage { public void createControl(Composite parent) { Composite comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); - Label label = new Label(comp, SWT.NONE); label.setLayoutData(new GridData()); label.setText("Name:"); - nameText = new Text(comp, SWT.BORDER); 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(); 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); 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.setSelectionBackground(new Color[] { c1, c2 }, new int[] { 100 }, true); tabFolder.setSelectionForeground(reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")); //$NON-NLS-1$ - checkName(); - setControl(comp); + nameText.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + String name = nameText.getText(); + if (!name.equals(workingCopy.getName())) { + String errMessage = checkName(name); + if (errMessage == null) { + workingCopy.rename(name); + validateFields(); + } else { + setErrorMessage(errMessage); + } + } + } + }); + validateFields(); } - private void checkName() { - if (workingCopy == null) - return; - + private String checkName(String name) { try { - if (workingCopy.getName().isEmpty()) { - setErrorMessage("Name can not be empty"); - setPageComplete(false); - } else if (DebugPlugin.getDefault().getLaunchManager().isExistingLaunchConfigurationName(workingCopy.getName())) { - setErrorMessage("A configuration with this name already exists"); - setPageComplete(false); - } else { - setErrorMessage(null); - setPageComplete(true); + 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 (CoreException exc) { - setErrorMessage(exc.getLocalizedMessage()); + } catch (Exception e) { + Activator.log(e); + return (e.getLocalizedMessage()); } + return null; } + void changeLaunchConfigType(ILaunchConfigurationType type) { + if (type == null) + return; try { - String initialMode = ((NewLaunchConfigWizard)getWizard()).modePage.selectedGroup.getMode(); + String initialMode = ((NewLaunchConfigWizard) getWizard()).modePage.selectedGroup.getMode(); workingCopy = type.newInstance(null, "New Configuration"); tabGroup = LaunchConfigurationPresentationManager.getDefault().getTabGroup(workingCopy, initialMode); nameText.setText(workingCopy.getName()); - for (CTabItem item : tabFolder.getItems()) item.dispose(); - tabGroup.createTabs(launchConfigurationDialog, initialMode); boolean firstTab = true; for (ILaunchConfigurationTab tab : tabGroup.getTabs()) { @@ -153,41 +151,28 @@ public class NewLaunchConfigEditPage extends WizardPage { boolean performFinish() { if (workingCopy == null) return false; - for (ILaunchConfigurationTab tab : tabGroup.getTabs()) tab.performApply(workingCopy); - return true; } - private class LaunchConfigurationDialog implements ILaunchConfigurationDialog { - - @Override - public void run(boolean fork, boolean cancelable, - IRunnableWithProgress runnable) - throws InvocationTargetException, InterruptedException { - // TODO Auto-generated method stub - } - - @Override - public void updateButtons() { - } - - @Override - public void updateMessage() { - String message = null; - String old_msg = getErrorMessage(); + 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(); - ILaunchConfigurationTab tab; - CTabItem item; int tLen = tabs.length; int tfLen = tabFolder.getItems().length; for (int i = 0; i < tLen; i++) { - tab = tabs[i]; + ILaunchConfigurationTab tab = tabs[i]; try { tab.isValid(workingCopy); message = tab.getErrorMessage(); - } catch(Exception e) { + } catch (Exception e) { // if createControl hasn't been called yet can throw exception.. // like the NPE issue in CTestingTab message = e.getMessage(); @@ -195,24 +180,45 @@ public class NewLaunchConfigEditPage extends WizardPage { // 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); + 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) { + setPageComplete(false); + } else { + setPageComplete(true); + } + } + + private class LaunchConfigurationDialog implements ILaunchConfigurationDialog { + @Override + public void run(boolean fork, boolean cancelable, + IRunnableWithProgress runnable) + throws InvocationTargetException, InterruptedException { + // TODO Auto-generated method stub + } + + @Override + public void updateButtons() { + } + + @Override + public void updateMessage() { + validateFields(); } @Override public void setName(String name) { // TODO Auto-generated method stub - } @Override @@ -236,7 +242,7 @@ public class NewLaunchConfigEditPage extends WizardPage { @Override public String getMode() { - return ((NewLaunchConfigWizard)getWizard()).modePage.selectedGroup.getMode(); + return ((NewLaunchConfigWizard) getWizard()).modePage.selectedGroup.getMode(); } @Override |