Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: editor/tools/plugins/com.google.dart.tools.debug.ui/src/com/google/dart/tools/debug/ui/internal/dialogs/ManageLaunchesDialog.java

Issue 9695004: validate name of launch configurations (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | editor/tools/plugins/com.google.dart.tools.debug.ui/src/com/google/dart/tools/debug/ui/internal/dialogs/Messages.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: editor/tools/plugins/com.google.dart.tools.debug.ui/src/com/google/dart/tools/debug/ui/internal/dialogs/ManageLaunchesDialog.java
===================================================================
--- editor/tools/plugins/com.google.dart.tools.debug.ui/src/com/google/dart/tools/debug/ui/internal/dialogs/ManageLaunchesDialog.java (revision 5323)
+++ editor/tools/plugins/com.google.dart.tools.debug.ui/src/com/google/dart/tools/debug/ui/internal/dialogs/ManageLaunchesDialog.java (working copy)
@@ -23,6 +23,8 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationListener;
@@ -90,6 +92,8 @@
private IAction createAction;
private IAction deleteAction;
+ private ILaunchConfiguration launchConfig;
+
public ManageLaunchesDialog(IWorkbenchWindow window) {
super(window.getShell());
@@ -98,6 +102,29 @@
setShellStyle(getShellStyle() | SWT.RESIZE);
}
+ public boolean canLaunch() {
+
+ if (workingCopy == null) {
+ return false;
+ }
+ try {
+ verifyName();
+ } catch (CoreException e) {
+ return false;
+ }
+
+ ILaunchConfigurationTab[] tabs = getTabs();
+ if (tabs == null) {
+ return false;
+ }
+ for (int i = 0; i < tabs.length; i++) {
+ if (!tabs[i].isValid(workingCopy)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
@Override
public String generateName(String name) {
if (name == null) {
@@ -220,7 +247,7 @@
if (getButton(IDialogConstants.OK_ID) != null) {
// Run button
getButton(IDialogConstants.OK_ID).setEnabled(
- activeTab != null && activeTab.getErrorMessage() == null);
+ activeTab != null && activeTab.getErrorMessage() == null && canLaunch());
// Delete action
getDeleteAction().setEnabled(selectedConfig != null);
@@ -229,6 +256,14 @@
@Override
public void updateMessage() {
+
+ try {
+ verifyName();
+ } catch (CoreException ce) {
+ setErrorMessage(ce.getStatus().getMessage());
+ return;
+ }
+
if (activeTab != null) {
String errorMessage = activeTab.getErrorMessage();
@@ -475,6 +510,10 @@
launchesViewer.refresh();
}
+// private boolean isDirty() {
+// return workingCopy == null ? false : workingCopy.isDirty();
+// }
+
private void saveConfig() {
if (currentTabGroup != null) {
currentTabGroup.performApply(workingCopy);
@@ -491,10 +530,6 @@
updateMessage();
}
-// private boolean isDirty() {
-// return workingCopy == null ? false : workingCopy.isDirty();
-// }
-
private void selectFirstLaunchConfig() {
final ILaunchConfiguration launchConfig = (ILaunchConfiguration) launchesViewer.getElementAt(0);
@@ -524,7 +559,8 @@
private void show(ILaunchConfiguration config) {
try {
- workingCopy = config.getWorkingCopy();
+ launchConfig = config;
+ workingCopy = launchConfig.getWorkingCopy();
configNameText.setText(workingCopy.getName());
currentTabGroup = LaunchConfigurationPresentationManager.getDefault().getTabGroup(
@@ -544,4 +580,34 @@
}
}
+ /**
+ * Verify that the launch configuration name is valid.
+ */
+ private void verifyName() throws CoreException {
+ if (configNameText.isVisible()) {
+ ILaunchManager mgr = getLaunchManager();
+ String currentName = configNameText.getText().trim();
+
+ // If there is no name, complain
+ if (currentName.length() < 1) {
+ throw new CoreException(new Status(IStatus.ERROR, DartDebugUIPlugin.PLUGIN_ID, 0,
+ Messages.ManageLaunchesDialog_Name_required_for_launch_configuration, null));
+ }
+ try {
+ mgr.isValidLaunchConfigurationName(currentName);
+ } catch (IllegalArgumentException iae) {
+ throw new CoreException(new Status(IStatus.ERROR, DartDebugUIPlugin.PLUGIN_ID, 0,
+ iae.getMessage(), null));
+ }
+ // Otherwise, if there's already a config with the same name, complain
+ if (!launchConfig.getName().equals(currentName)) {
+ if (mgr.isExistingLaunchConfigurationName(currentName)) {
+ throw new CoreException(new Status(IStatus.ERROR, DartDebugUIPlugin.PLUGIN_ID, 0,
+ Messages.ManageLaunchesDialog_Launch_configuration_already_exists_with_this_name,
+ null));
+ }
+ }
+ }
+ }
+
}
« no previous file with comments | « no previous file | editor/tools/plugins/com.google.dart.tools.debug.ui/src/com/google/dart/tools/debug/ui/internal/dialogs/Messages.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698