Permalink
Browse files

Added an new icon.

  • Loading branch information...
1 parent 1ee60e7 commit d1d0fc7150ed178a723430062186258d67d4c6e0 @KlasJoensson committed Feb 9, 2012
@@ -20,6 +20,10 @@
import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -30,7 +34,7 @@
/**
*
* @author Klas Jšnsson (aka "konditorn")
- * TODO Make sure the created SWT-components are removed
+ *
*/
public class AccountPropertiesPage {
@@ -42,50 +46,93 @@
private Image reqImage = FieldDecorationRegistry.getDefault()
.getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED)
.getImage();
+ private Image errImage = FieldDecorationRegistry.getDefault()
+ .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR)
+ .getImage();
private AccountType accountType;
+ private Boolean errorFlag = false;
public AccountPropertiesPage(Composite parent,
AccountType accountType) {
- int noOfFields = 0, noOfSecretFields = 0, i = 0;
+ int noOfFields = 0, noOfSecretFields = 0, i = 0, contentMinHight;
+ int rowSpace = 25;
Iterator<Property> propertyIter;
Property temp;
- this.accountType = accountType;
+ GridData txtData= new GridData(GridData.FILL_HORIZONTAL);
- accountComposite = new Composite(parent, SWT.NONE);
- GridData gd_ac = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
- gd_ac.widthHint = 430;
- gd_ac.heightHint = 160;
- accountComposite.setLayoutData(gd_ac);
- accountComposite.setLayout(new GridLayout(2, false));
- // TODO Add a icon for the account using an icon provided by it self.
+ this.accountType = accountType;
properties = accountType.getProperties();
for (propertyIter = properties.iterator(); propertyIter.hasNext(); ) {
if (propertyIter.next().isSecret())
noOfSecretFields++;
}
-
noOfFields = properties.size() + noOfSecretFields;
+ contentMinHight = noOfFields * rowSpace;
+
+ accountComposite = new Composite(parent, SWT.NONE);
+ GridData gd_ac = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+ gd_ac.widthHint = 430;
+ gd_ac.heightHint = contentMinHight;
+ accountComposite.setLayoutData(gd_ac);
+ accountComposite.setLayout(new GridLayout(2, false));
+ // TODO Add a icon for the account using an icon provided by it self.
+
accountLabels = new Label[noOfFields];
accountTxt = new Text[noOfFields];
propertyIter = properties.iterator();
while (propertyIter.hasNext()) {
- temp = propertyIter.next();
+ temp = propertyIter.next();
if (temp.isSecret()) {
accountLabels[i] = new Label(accountComposite, SWT.NONE);
- accountLabels[i].setText(temp.getName()+":");
+ accountLabels[i].setText(temp.getName() + ":");
accountTxt[i] = new Text(accountComposite,
SWT.BORDER | SWT.PASSWORD);
accountTxt[i].setToolTipText(accountLabels[i].getText());
+ accountTxt[i].setLayoutData(txtData);
if (temp.isRequired()) {
setReqDeco(accountLabels[i]);
requiredFields.add(accountTxt[i]);
}
- accountLabels[i++] = new Label(accountComposite, SWT.NONE);
- accountLabels[i].setText("Repeat "+temp.getName()+":");
+ i++;
+ accountLabels[i] = new Label(accountComposite, SWT.NONE);
+ accountLabels[i].setText("Repeat " + temp.getName() + ":");
accountTxt[i] = new Text(accountComposite,
SWT.BORDER | SWT.PASSWORD);
+ accountTxt[i].setLayoutData(txtData);
accountTxt[i].setToolTipText(accountLabels[i].getText());
+ final int my_i = i;
+ final ControlDecoration deco = new ControlDecoration(
+ accountTxt[my_i], SWT.TOP | SWT.RIGHT);
+ deco.setDescriptionText("The value has to be the same as " +
+ "the value above");
+ deco.setImage(errImage);
+ deco.setShowOnlyOnFocus(false);
+ deco.hide();
+ accountTxt[i].addKeyListener(new KeyListener() {
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ if (!(accountTxt[my_i-1].getText().equals(
+ accountTxt[my_i].getText()))) {
+ deco.show();
+ errorFlag = true;
+ } else {
+ deco.hide();
+ errorFlag = false;
+ }
+// accountTxt[my_i].getParent().getAccessible().sendEvent(SWT.Selection, null);
+// accountComposite.getParent().getAccessible()
+// .sendEvent(SWT.Activate, null);
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+// accountComposite.getParent().getAccessible()
+// .sendEvent(SWT.Activate, null);
+ }
+ });
+
if (temp.isRequired()) {
setReqDeco(accountLabels[i]);
requiredFields.add(accountTxt[i]);
@@ -95,6 +142,7 @@ public AccountPropertiesPage(Composite parent,
accountLabels[i].setText(temp.getName());
accountTxt[i] = new Text(accountComposite, SWT.BORDER);
accountTxt[i].setToolTipText(accountLabels[i].getText());
+ accountTxt[i].setLayoutData(txtData);
if (temp.isRequired()) {
setReqDeco(accountLabels[i]);
requiredFields.add(accountTxt[i]);
@@ -171,7 +219,7 @@ public void createAccount() {
*/
public Boolean isAllRequierdPropertiesFilledIn() {
Iterator<Text> itr = requiredFields.iterator();
- while (itr.hasNext()){
+ while (itr.hasNext()) {
if (itr.next().getText().isEmpty())
return false;
}
@@ -187,13 +235,25 @@ public Boolean isAllRequierdPropertiesFilledIn() {
public ArrayList<String> getRequiredPropertiesLeft() {
Iterator<Text> itr = requiredFields.iterator();
ArrayList<String> requiredPropertiesLeft = new ArrayList<String>();
- while (itr.hasNext()){
+ while (itr.hasNext()) {
Text temp = itr.next();
if (temp.getText().isEmpty())
requiredPropertiesLeft.add(temp.getToolTipText());
}
return requiredPropertiesLeft;
}
+
+ /**
+ * A method to check that all the fields are valid.
+ *
+ * @return True if everything is ok
+ */
+ public Boolean isFieldsProperlyFilled() {
+ return !errorFlag;
+ }
+ public void dispose() {
+ dispose();
+ }
}
@@ -152,7 +152,7 @@ public Property(String name, boolean required) {
super();
this.name = name;
this.required = required;
- this.secret = false;
+ this.secret = true;
}
public Property(String name, boolean required, boolean secret) {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -11,10 +11,14 @@
package net.bioclipse.usermanager;
import java.util.ArrayList;
+import java.util.Iterator;
+
import net.bioclipse.usermanager.business.IUserManager;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
+import org.eclipse.swt.events.GestureEvent;
+import org.eclipse.swt.events.GestureListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
@@ -27,7 +31,7 @@
* The wizard page that handles the different parts accounts.
*
* @author Klas Jšnsson
- * TODO Make sure the created SWT-components are removed
+ *
*/
public class NewAccountWizardPage extends WizardPage implements Listener {
@@ -72,7 +76,6 @@ public void createControl(Composite parent) {
accountType.setLayoutData(gd_accountSettings);
accountStack = new StackLayout();
accountSettings.setLayout(accountStack);
-
// Adding the availably account-types to the combobox and a composite
// with the account specific fields to the array list of account
// composites.
@@ -81,8 +84,19 @@ public void createControl(Composite parent) {
accountTypeCombo.add(accountTypes[i].getName());
addedAccounts.add(new AccountPropertiesPage(accountSettings,
accountTypes[i]));
+
accountComposites.add(addedAccounts.get(i)
.getAccountPropertiesPage());
+// accountComposites.get(i).addListener(SWT.Selection, this);
+
+// .addGestureListener(new GestureListener() {
+//
+// @Override
+// public void gesture(GestureEvent e) {
+// // TODO Auto-generated method stub
+// System.out.println("Something happend! =)");
+// }
+// });
}
if (accountComposites.size() > 0) {
@@ -100,6 +114,8 @@ public void createControl(Composite parent) {
*/
@Override
public void handleEvent(Event event) {
+ isPageComplete();
+// System.out.println("Something happend:\n" + event.toString());
if (event.widget == accountTypeCombo) {
if (accountTypeCombo.getSelectionIndex() == -1){
System.out.println("Please select an account-type");
@@ -110,7 +126,7 @@ public void handleEvent(Event event) {
accountSettings.layout();
giveFocus();
}
- }
+ }
}
/**
@@ -149,27 +165,46 @@ private Composite empty(Composite parent) {
protected Boolean createAccount(){
AccountPropertiesPage account =
addedAccounts.get(accountTypeCombo.getSelectionIndex());
- if (account.isAllRequierdPropertiesFilledIn()) {
+ if (account.isAllRequierdPropertiesFilledIn() &&
+ account.isFieldsProperlyFilled()) {
+ setErrorMessage(null);
account.createAccount();
+ // TODO Do I need this for-loop or is the dispose below enough to
+ // remove the subpages SWT-components?
+// for (Iterator<AccountPropertiesPage> itr = addedAccounts.iterator();
+// itr.hasNext();) {
+// itr.next().dispose();
+// }
+ dispose();
return true;
} else {
- // TODO If the error-messages gets to large it is cut of.
- String errorMessage = "Please fill in the following field";
- ArrayList<String> unfilledFields = account
- .getRequiredPropertiesLeft();
- if (unfilledFields.size()==1)
- errorMessage += ": " + unfilledFields.get(0);
- else if(unfilledFields.size() > 1) {
- errorMessage += "s:\n" + createErrorMessage(unfilledFields);
- } else
- errorMessage = "WTF? All requierd fileds aren't filled in...";
-
- setErrorMessage(errorMessage);
+ createErrorMessage(account);
return false;
}
}
/**
+ * If there's some error this method shows an error message in the header.
+ *
+ * @param account The active subpage
+ */
+ private void createErrorMessage(AccountPropertiesPage account) {
+ // TODO If the error-messages gets to large it's cut of.
+ String errorMessage = "Please fill in the following field";
+ ArrayList<String> unfilledFields = account
+ .getRequiredPropertiesLeft();
+ if (unfilledFields.size()==1)
+ errorMessage += ": " + unfilledFields.get(0);
+ else if(unfilledFields.size() > 1) {
+ errorMessage += "s:\n" + createErrorMessage(unfilledFields);
+ } else if (!account.isFieldsProperlyFilled())
+ errorMessage = "Gšr om, gšr rŠtt";
+ else
+ errorMessage = "WTF?";
+ setErrorMessage(errorMessage);
+ }
+
+ /**
* An recursive method that to get the names of the required fields that
* aren't filled in yet.
*
@@ -186,4 +221,18 @@ private String createErrorMessage(ArrayList<String> unfilledFields) {
return field + ", " + createErrorMessage(unfilledFields);
}
}
+
+// @Override
+// public boolean isPageComplete() {
+// AccountPropertiesPage account =
+// addedAccounts.get(accountTypeCombo.getSelectionIndex());
+// if (account.isAllRequierdPropertiesFilledIn() &&
+// account.isFieldsProperlyFilled()){
+// setErrorMessage(null);
+// return true;
+// } else {
+// createErrorMessage(account);
+// return false;
+// }
+// }
}

0 comments on commit d1d0fc7

Please sign in to comment.