Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Schwarz2013-05-14 12:22:34 +0000
committerTobias Schwarz2013-05-14 12:23:13 +0000
commit7f8cebfdf922e75e88f5b254d4020e7822950afc (patch)
tree6dd36b3482b17ff99913b2f57b07c668464334eb /target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards
parentd3a39f85ad83f2a18ad33b47941f5c97405613ec (diff)
downloadorg.eclipse.tcf-7f8cebfdf922e75e88f5b254d4020e7822950afc.tar.gz
org.eclipse.tcf-7f8cebfdf922e75e88f5b254d4020e7822950afc.tar.xz
org.eclipse.tcf-7f8cebfdf922e75e88f5b254d4020e7822950afc.zip
Target Explorer: fix validation
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/pages/AbstractConfigWizardPage.java8
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/pages/NewTargetWizardPage.java68
2 files changed, 75 insertions, 1 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/pages/AbstractConfigWizardPage.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/pages/AbstractConfigWizardPage.java
index 679aaa7f4..31580cfbc 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/pages/AbstractConfigWizardPage.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/pages/AbstractConfigWizardPage.java
@@ -108,6 +108,14 @@ public abstract class AbstractConfigWizardPage extends AbstractFormsWizardPage i
}
}
+ if (!valid && getControlDecoration() != null) {
+ // Setup and show the control decoration if necessary
+ if (isEnabled()) {
+ // Update the control decorator
+ updateControlDecoration(getMessage(), getMessageType());
+ }
+ }
+
return valid ? super.isValid() : false;
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/pages/NewTargetWizardPage.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/pages/NewTargetWizardPage.java
index ee0fa4d35..ba5ad613b 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/pages/NewTargetWizardPage.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/wizards/pages/NewTargetWizardPage.java
@@ -9,6 +9,7 @@
*******************************************************************************/
package org.eclipse.tcf.te.tcf.ui.wizards.pages;
+import java.util.ArrayList;
import java.util.Map;
import java.util.UUID;
@@ -16,15 +17,19 @@ import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.tcf.protocol.IPeer;
+import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
import org.eclipse.tcf.te.tcf.core.interfaces.ITransportTypes;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tcf.te.tcf.locator.model.Model;
import org.eclipse.tcf.te.tcf.ui.controls.CustomTransportPanel;
import org.eclipse.tcf.te.tcf.ui.controls.PeerAttributesTablePart;
import org.eclipse.tcf.te.tcf.ui.controls.PeerNameControl;
@@ -59,6 +64,10 @@ public class NewTargetWizardPage extends AbstractValidatingWizardPage implements
// The UUID of the new peer to create
private final UUID uuid = UUID.randomUUID();
+ // The list of existing configuration names. Used to generate a unique name
+ // and validate the wizard
+ /* default */ final java.util.List<String> usedNames = new ArrayList<String>();
+
/**
* Local transport type control implementation.
*/
@@ -211,7 +220,33 @@ public class NewTargetWizardPage extends AbstractValidatingWizardPage implements
client.setBackground(parent.getBackground());
// Add the controls
- peerNameControl = new PeerNameControl(this);
+ peerNameControl = new PeerNameControl(this) {
+ @Override
+ public boolean isValid() {
+ boolean valid = true;
+
+ String name = getEditFieldControlTextForValidation();
+ if (!"".equals(name)) { //$NON-NLS-1$
+ // Name is not empty -> check against the list of used names
+ if (getParentPage() instanceof NewTargetWizardPage) {
+ valid = !((NewTargetWizardPage)getParentPage()).usedNames.contains(name.trim().toUpperCase());
+ if (!valid) {
+ setMessage(Messages.NewTargetWizardPage_error_nameInUse, IMessageProvider.ERROR);
+ }
+ }
+ }
+
+ if (!valid && getControlDecoration() != null) {
+ // Setup and show the control decoration if necessary
+ if (isEnabled()) {
+ // Update the control decorator
+ updateControlDecoration(getMessage(), getMessageType());
+ }
+ }
+
+ return valid ? super.isValid() : false;
+ }
+ };
peerNameControl.setFormToolkit(toolkit);
peerNameControl.setParentControlIsInnerPanel(true);
peerNameControl.setupPanel(client);
@@ -262,6 +297,9 @@ public class NewTargetWizardPage extends AbstractValidatingWizardPage implements
// restore the widget values from the history
restoreWidgetValues();
+
+ // Initialize the used configuration name list
+ initializeUsedNameList();
}
/**
@@ -405,4 +443,32 @@ public class NewTargetWizardPage extends AbstractValidatingWizardPage implements
if (transportTypePanelControl != null) transportTypePanelControl.restoreWidgetValues(settings, null);
}
}
+
+ /**
+ * Initialize the used name list.
+ */
+ protected void initializeUsedNameList() {
+ usedNames.clear();
+
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ // Get all peer model objects
+ IPeerModel[] peers = Model.getModel().getPeers();
+ // Loop them and find the ones which are of our handled types
+ for (IPeerModel peerModel : peers) {
+ if (peerModel.isStatic()) {
+ String name = peerModel.getPeer().getName();
+ Assert.isNotNull(name);
+ if (!"".equals(name) && !usedNames.contains(name)) { //$NON-NLS-1$
+ usedNames.add(name.trim().toUpperCase());
+ }
+ }
+ }
+ }
+ };
+
+ Assert.isTrue(!Protocol.isDispatchThread());
+ Protocol.invokeAndWait(runnable);
+ }
}

Back to the top