[yocto] [RFC 10/17] plugins/sdk.ide: Add UI method to create a new profile

Timo Mueller mail at timomueller.eu
Thu Jan 24 07:12:34 PST 2013


From: Timo Mueller <timo.mueller at bmw-carit.de>

When the new button is clicked a dialog shows up and the user has to
provide the name of the new profile. The validity of the name is
checked during input. If the name is valid and the users confirms the
new profile is created.

Signed-off-by: Timo Mueller <timo.mueller at bmw-carit.de>
---
 .../src/org/yocto/sdk/ide/YoctoProfileSetting.java | 31 +++++++++
 .../org/yocto/sdk/ide/YoctoSDKMessages.properties  |  7 +++
 .../ide/preferences/ProfileNameInputValidator.java | 73 ++++++++++++++++++++++
 3 files changed, 111 insertions(+)
 create mode 100644 plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java

diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProfileSetting.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProfileSetting.java
index 7c2b8d4..6a38fb1 100644
--- a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProfileSetting.java
+++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoProfileSetting.java
@@ -10,8 +10,12 @@
  *******************************************************************************/
 package org.yocto.sdk.ide;
 
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.InputDialog;
 import org.eclipse.jface.preference.PreferencePage;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
@@ -20,10 +24,13 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Listener;
+import org.yocto.sdk.ide.preferences.ProfileNameInputValidator;
 
 public class YoctoProfileSetting {
 	private static final String PROFILES_TITLE = "Preferences.Profiles.Title";
 	private static final String NEW_PROFILE_TITLE = "Preferences.Profile.New.Title";
+	private static final String NEW_DIALOG_TITLE = "Preferences.Profile.New.Dialog.Title";
+	private static final String NEW_DIALOG_MESSAGE = "Preferences.Profile.New.Dialog.Message";
 	private static final String RENAME_PROFILE_TITLE = "Preferences.Profile.Rename.Title";
 	private static final String REMOVE_PROFILE_TITLE = "Preferences.Profile.Remove.Title";
 
@@ -89,6 +96,30 @@ public class YoctoProfileSetting {
 	{
 		btnConfigNew = new Button(storeYoctoConfigurationsGroup, SWT.PUSH | SWT.LEAD);
 		btnConfigNew.setText(YoctoSDKMessages.getString(NEW_PROFILE_TITLE));
+		btnConfigNew.addMouseListener(new MouseAdapter()
+		{
+			@Override
+			public void mouseDown(MouseEvent e)
+			{
+				saveChangesOnCurrentProfile();
+				InputDialog profileNameDialog =
+									new InputDialog(null,
+													YoctoSDKMessages.getString(NEW_DIALOG_TITLE),
+													YoctoSDKMessages.getString(NEW_DIALOG_MESSAGE),
+													null,
+													new ProfileNameInputValidator(profileElement));
+
+				int returnCode = profileNameDialog.open();
+				if (returnCode == IDialogConstants.CANCEL_ID) {
+					return;
+				}
+
+				profileElement.addProfile(profileNameDialog.getValue());
+				int index = sdkConfigsCombo.getItemCount();
+				sdkConfigsCombo.add(profileNameDialog.getValue(), index);
+				sdkConfigsCombo.select(index);
+			}
+		});
 	}
 
 	private void createRemoveButton(Group storeYoctoConfigurationsGroup)
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.properties b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.properties
index f8c2e4b..6876663 100644
--- a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.properties
+++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.properties
@@ -46,8 +46,15 @@ Preferences.SDK.Target.name = Target Preferences:
 Preferences.SDK.Informing.Title   = Yocto Project ADT has been successfully set up. 
 Preferences.SDK.Informing.Message = You might need to reconfigure your existing Yocto Project Autotools Projects to use the Yocto Project ADT. Do this from Project > Reconfigure Project!
 
+Preferences.Profile.Validator.InvalidName.Comma = Warning: The profile name cannot contain a comma (,).
+Preferences.Profile.Validator.InvalidName.Quote = Warning: The profile name cannot contain a double quote (\").
+Preferences.Profile.Validator.InvalidName.Empty = Please provide a new profile name.
+Preferences.Profile.Validator.InvalidName.Exists = Warning: The profile already exists.
+
 Preferences.Profiles.Title = Target profiles:
 Preferences.Profile.New.Title = New ...
+Preferences.Profile.New.Dialog.Title = Create a new target profile
+Preferences.Profile.New.Dialog.Message = Please input a profile name.
 Preferences.Profile.Rename.Title = Rename
 Preferences.Profile.Remove.Title = Remove
 
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java
new file mode 100644
index 0000000..17f21db
--- /dev/null
+++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2012 BMW Car IT GmbH.
+ * 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
+ *
+ * Contributors:
+ * BMW Car IT - initial API and implementation
+ *******************************************************************************/
+package org.yocto.sdk.ide.preferences;
+
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.yocto.sdk.ide.YoctoProfileElement;
+import org.yocto.sdk.ide.YoctoSDKMessages;
+
+public class ProfileNameInputValidator implements IInputValidator
+{
+	private static final String WARNING_CONTAINS_COMMA = "Preferences.Profile.Validator.InvalidName.Comma";
+	private static final String WARNING_CONTAINS_DOUBLEQUOTE = "Preferences.Profile.Validator.InvalidName.Quote";
+	private static final String PROFILE_NAME_IS_EMPTY = "Preferences.Profile.Validator.InvalidName.Empty";
+	private static final String WARNING_ALREADY_EXISTS = "Preferences.Profile.Validator.InvalidName.Exists";
+
+	private final String selectedItem;
+	private final YoctoProfileElement profileSetting;
+
+	public ProfileNameInputValidator(YoctoProfileElement profileSetting)
+	{
+		this(profileSetting, "");
+	}
+
+	public ProfileNameInputValidator(YoctoProfileElement profileSetting, String selectedItem)
+	{
+		this.selectedItem = selectedItem;
+		this.profileSetting = profileSetting;
+	}
+
+	@Override
+	public String isValid(String newText)
+	{
+		if (newText.contains(","))
+		{
+			return YoctoSDKMessages.getString(WARNING_CONTAINS_COMMA);
+		}
+
+		if (newText.contains("\""))
+		{
+			return YoctoSDKMessages.getString(WARNING_CONTAINS_DOUBLEQUOTE);
+		}
+
+		if (newText.isEmpty())
+		{
+			return YoctoSDKMessages.getString(PROFILE_NAME_IS_EMPTY);
+		}
+
+		if (selectedItemEquals(newText))
+		{
+			return null;
+		}
+
+		if (profileSetting.contains(newText))
+		{
+			return YoctoSDKMessages.getString(WARNING_ALREADY_EXISTS);
+		}
+
+		return null;
+	}
+
+	private boolean selectedItemEquals(String newText)
+	{
+		return !selectedItem.isEmpty() && newText.equals(selectedItem);
+	}
+}
-- 
1.7.11.7




More information about the yocto mailing list