List of usage examples for org.eclipse.jface.databinding.swt SWTObservables observeSelection
@Deprecated public static ISWTObservableValue observeSelection(Control control)
control
. From source file:com.amazonaws.eclipse.explorer.cloudformation.wizard.CreateStackWizardFirstPage.java
License:Apache License
private void createTemplateUrlControl(Group stackTemplateSourceGroup, int fieldDecorationWidth) { final Button templateUrlOption = new Button(stackTemplateSourceGroup, SWT.RADIO); templateUrlOption.setText("Template URL: "); templateURLText = new Text(stackTemplateSourceGroup, SWT.BORDER); templateURLText.setEnabled(false);//from w ww . j av a2s . c o m GridDataFactory.fillDefaults().grab(true, false).indent(fieldDecorationWidth, 0).applyTo(templateURLText); Link link = new Link(stackTemplateSourceGroup, SWT.None); String sampleUrl = "http://docs.aws.amazon.com/cloudformation/aws-cloudformation-templates/"; // TODO: this should really live in the regions file, not hardcoded here Region currentRegion = RegionUtils.getCurrentRegion(); if (currentRegion.getId().equals("us-east-1")) { sampleUrl = "http://docs.aws.amazon.com/cloudformation/aws-cloudformation-templates/"; } else { sampleUrl = "http://docs.aws.amazon.com/cloudformation/aws-cloudformation-templates/aws-cloudformation-templates-" + currentRegion.getId() + "/"; } link.setText("<a href=\"" + sampleUrl + "\">Browse for samples</a>"); link.addListener(SWT.Selection, new WebLinkListener()); bindingContext.bindValue(SWTObservables.observeText(templateURLText, SWT.Modify), templateUrl) .updateTargetToModel(); bindingContext.bindValue(SWTObservables.observeSelection(templateUrlOption), useTemplateUrl) .updateTargetToModel(); ChainValidator<String> templateUrlValidationStatusProvider = new ChainValidator<String>(templateUrl, useTemplateUrl, new NotEmptyValidator("Please provide a valid URL for your template")); bindingContext.addValidationStatusProvider(templateUrlValidationStatusProvider); addStatusDecorator(templateURLText, templateUrlValidationStatusProvider); templateUrlOption.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean selected = templateUrlOption.getSelection(); templateURLText.setEnabled(selected); } }); }
From source file:com.amazonaws.eclipse.explorer.cloudformation.wizard.CreateStackWizardFirstPage.java
License:Apache License
private void createTemplateFileControl(Group stackTemplateSourceGroup, int fieldDecorationWidth) { Button fileTemplateOption = new Button(stackTemplateSourceGroup, SWT.RADIO); fileTemplateOption.setText("Template File: "); fileTemplateOption.setSelection(true); fileTemplateText = new Text(stackTemplateSourceGroup, SWT.BORDER | SWT.READ_ONLY); GridDataFactory.fillDefaults().grab(true, false).indent(fieldDecorationWidth, 0).applyTo(fileTemplateText); Button browseButton = new Button(stackTemplateSourceGroup, SWT.PUSH); browseButton.setText("Browse..."); Listener fileTemplateSelectionListener = new Listener() { public void handleEvent(Event event) { if ((Boolean) useTemplateFile.getValue()) { FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); String result = dialog.open(); if (result != null) { fileTemplateText.setText(result); }/*from w w w . ja va 2s. c om*/ } } }; browseButton.addListener(SWT.Selection, fileTemplateSelectionListener); fileTemplateText.addListener(SWT.MouseUp, fileTemplateSelectionListener); bindingContext.bindValue(SWTObservables.observeSelection(fileTemplateOption), useTemplateFile) .updateTargetToModel(); bindingContext.bindValue(SWTObservables.observeText(fileTemplateText, SWT.Modify), templateFile) .updateTargetToModel(); ChainValidator<String> templateFileValidationStatusProvider = new ChainValidator<String>(templateFile, useTemplateFile, new NotEmptyValidator("Please provide a valid file for your template")); bindingContext.addValidationStatusProvider(templateFileValidationStatusProvider); addStatusDecorator(fileTemplateText, templateFileValidationStatusProvider); }
From source file:com.amazonaws.eclipse.explorer.cloudformation.wizard.CreateStackWizardFirstPage.java
License:Apache License
private void createSNSTopicControl(final Composite comp, int fieldDecorationWidth) { final Button notifyWithSNSButton = new Button(comp, SWT.CHECK); notifyWithSNSButton.setText("SNS Topic (Optional):"); final Combo snsTopicCombo = new Combo(comp, SWT.DROP_DOWN | SWT.READ_ONLY); GridDataFactory.fillDefaults().grab(true, false).indent(fieldDecorationWidth, 0).applyTo(snsTopicCombo); loadTopics(snsTopicCombo);//from w w w . j a v a 2 s . co m bindingContext.bindValue(SWTObservables.observeSelection(notifyWithSNSButton), notifyWithSNS) .updateTargetToModel(); bindingContext.bindValue(SWTObservables.observeSelection(snsTopicCombo), snsTopicArn).updateTargetToModel(); ChainValidator<String> snsTopicValidationStatusProvider = new ChainValidator<String>(snsTopicArn, notifyWithSNS, new NotEmptyValidator("Please select an SNS notification topic")); bindingContext.addValidationStatusProvider(snsTopicValidationStatusProvider); addStatusDecorator(snsTopicCombo, snsTopicValidationStatusProvider); final Button newTopicButton = new Button(comp, SWT.PUSH); newTopicButton.setText("Create New Topic"); newTopicButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { CreateTopicDialog dialog = new CreateTopicDialog(); if (dialog.open() == 0) { try { AwsToolkitCore.getClientFactory().getSNSClient() .createTopic(new CreateTopicRequest().withName(dialog.getTopicName())); } catch (Exception ex) { AwsToolkitCore.getDefault().logException("Failed to create new topic", ex); } loadTopics(snsTopicCombo); } } }); snsTopicCombo.setEnabled(false); newTopicButton.setEnabled(false); notifyWithSNSButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean selection = notifyWithSNSButton.getSelection(); snsTopicCombo.setEnabled(selection); newTopicButton.setEnabled(selection); } }); }
From source file:com.amazonaws.eclipse.explorer.cloudformation.wizard.CreateStackWizardFirstPage.java
License:Apache License
private void createTimeoutControl(final Composite comp) { new Label(comp, SWT.None).setText("Creation Timeout:"); Combo timeoutCombo = new Combo(comp, SWT.DROP_DOWN | SWT.READ_ONLY); GridDataFactory.fillDefaults().grab(false, false).span(2, 1).applyTo(timeoutCombo); timeoutCombo.setItems(new String[] { "None", "5 minutes", "10 minutes", "15 minutes", "20 minutes", "30 minutes", "60 minutes", "90 minutes", }); timeoutCombo.select(0);/* ww w . j ava 2s . c o m*/ UpdateValueStrategy timeoutUpdateStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE); timeoutUpdateStrategy.setConverter(new IConverter() { public Object getToType() { return Integer.class; } public Object getFromType() { return String.class; } public Object convert(Object fromObject) { String value = (String) fromObject; if ("None".equals(value)) { return 0; } else { String minutes = value.substring(0, value.indexOf(' ')); return Integer.parseInt(minutes); } } }); bindingContext.bindValue(SWTObservables.observeSelection(timeoutCombo), timeoutMinutes, timeoutUpdateStrategy, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)) .updateTargetToModel(); }
From source file:com.amazonaws.eclipse.explorer.cloudformation.wizard.CreateStackWizardFirstPage.java
License:Apache License
private void createRollbackControl(final Composite comp) { Button rollbackButton = new Button(comp, SWT.CHECK); rollbackButton.setText("Rollback on Failure"); GridDataFactory.fillDefaults().grab(false, false).span(3, 1).applyTo(rollbackButton); rollbackButton.setSelection(true);//from w w w. j a v a 2 s. c o m bindingContext.bindValue(SWTObservables.observeSelection(rollbackButton), rollbackOnFailure) .updateTargetToModel(); }
From source file:com.amazonaws.eclipse.explorer.cloudformation.wizard.CreateStackWizardSecondPage.java
License:Apache License
@SuppressWarnings({ "rawtypes", "unchecked" }) private void createParameterSection(Composite comp, TemplateParameter param) { Map parameterMap = (Map) wizard.getDataModel().getTemplate().get("Parameters"); // Unfortunately, we have to manually adjust for field decorations FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault() .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR); int fieldDecorationWidth = fieldDecoration.getImage().getBounds().width; Control paramControl = null;//from www .j ava 2 s . c om ISWTObservableValue observeParameter = null; ChainValidator<String> validationStatusProvider = null; if (parameterMap.containsKey(param.getParameterKey())) { Label label = new Label(comp, SWT.None); label.setText(param.getParameterKey()); Map paramMap = (Map) parameterMap.get(param.getParameterKey()); // Update the default value in the model. if (wizard.getDataModel().getParameterValues().get(param.getParameterKey()) == null) { wizard.getDataModel().getParameterValues().put(param.getParameterKey(), param.getDefaultValue()); } // If the template enumerates allowed values, present them as a // combo drop down if (paramMap.containsKey(ALLOWED_VALUES)) { Combo combo = new Combo(comp, SWT.DROP_DOWN | SWT.READ_ONLY); Collection<String> allowedValues = (Collection<String>) paramMap.get(ALLOWED_VALUES); GridDataFactory.fillDefaults().grab(true, false).indent(fieldDecorationWidth, 0).applyTo(combo); combo.setItems(allowedValues.toArray(new String[allowedValues.size()])); observeParameter = SWTObservables.observeSelection(combo); paramControl = combo; } else { // Otherwise, just use a text field with validation constraints Text text = new Text(comp, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).indent(fieldDecorationWidth, 0).applyTo(text); observeParameter = SWTObservables.observeText(text, SWT.Modify); paramControl = text; // Add validators for the constraints listed in the template List<IValidator> validators = new ArrayList<IValidator>(); validators.add(new NotEmptyValidator("Please enter a value for " + param.getParameterKey())); if (paramMap.containsKey(ALLOWED_PATTERN)) { String pattern = (String) paramMap.get(ALLOWED_PATTERN); Pattern p = Pattern.compile(pattern); validators.add(new PatternValidator(p, param.getParameterKey() + ": " + (String) paramMap.get(CONSTRAINT_DESCRIPTION))); } if (paramMap.containsKey(MIN_LENGTH)) { validators.add(new MinLengthValidator(Integer.parseInt((String) paramMap.get(MIN_LENGTH)), param.getParameterKey())); } if (paramMap.containsKey(MAX_LENGTH)) { validators.add(new MaxLengthValidator(Integer.parseInt((String) paramMap.get(MAX_LENGTH)), param.getParameterKey())); } if (paramMap.containsKey(MIN_VALUE)) { validators.add(new MinValueValidator(Integer.parseInt((String) paramMap.get(MIN_VALUE)), param.getParameterKey())); } if (paramMap.containsKey(MAX_VALUE)) { validators.add(new MaxValueValidator(Integer.parseInt((String) paramMap.get(MAX_VALUE)), param.getParameterKey())); } if (!validators.isEmpty()) { validationStatusProvider = new ChainValidator<String>(observeParameter, validators.toArray(new IValidator[validators.size()])); } } } else { AwsToolkitCore.getDefault().logException("No parameter map object found for " + param.getParameterKey(), null); return; } if (param.getDescription() != null) { Label description = new Label(comp, SWT.WRAP); GridDataFactory.fillDefaults().grab(true, false).span(2, 1).indent(0, -8).applyTo(description); description.setText(param.getDescription()); description.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY)); } bindingContext.bindValue(observeParameter, Observables.observeMapEntry( wizard.getDataModel().getParameterValues(), param.getParameterKey(), String.class)); if (validationStatusProvider != null) { bindingContext.addValidationStatusProvider(validationStatusProvider); ControlDecoration decoration = new ControlDecoration(paramControl, SWT.TOP | SWT.LEFT); decoration.setDescriptionText("Invalid value"); decoration.setImage(fieldDecoration.getImage()); new DecorationChangeListener(decoration, validationStatusProvider.getValidationStatus()); } }
From source file:com.amazonaws.eclipse.explorer.dynamodb.AddGSIDialog.java
License:Apache License
@Override protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); composite.setLayout(new GridLayout()); composite = new Composite(composite, SWT.NULL); GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); composite.setLayout(new GridLayout(2, false)); // Index hash key attribute name Group indexHashKeyGroup = CreateTablePageUtil.newGroup(composite, "Index Hash Key", 2); new Label(indexHashKeyGroup, SWT.NONE | SWT.READ_ONLY).setText("Index Hash Key Name:"); indexHashKeyNameText = new Text(indexHashKeyGroup, SWT.BORDER); bindingContext.bindValue(SWTObservables.observeText(indexHashKeyNameText, SWT.Modify), indexHashKeyNameInKeySchemaDefinitionModel); ChainValidator<String> indexHashKeyNameValidationStatusProvider = new ChainValidator<String>( indexHashKeyNameInKeySchemaDefinitionModel, new NotEmptyValidator("Please provide the index hash key name")); bindingContext.addValidationStatusProvider(indexHashKeyNameValidationStatusProvider); bindingContext.bindValue(SWTObservables.observeText(indexHashKeyNameText, SWT.Modify), indexHashKeyNameInAttributeDefinitionsModel); indexHashKeyNameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (primaryKeyTypes.containsKey(indexHashKeyNameText.getText()) && indexHashKeyAttributeTypeCombo != null && primaryKeyTypes.get(indexHashKeyNameText.getText()) > -1) { indexHashKeyAttributeTypeCombo.select(primaryKeyTypes.get(indexHashKeyNameText.getText())); indexHashKeyAttributeTypeCombo.setEnabled(false); } else if (indexHashKeyAttributeTypeCombo != null) { indexHashKeyAttributeTypeCombo.setEnabled(true); }//from www .j av a 2 s . c om } }); GridDataFactory.fillDefaults().grab(true, false).applyTo(indexHashKeyNameText); // Index hash key attribute type new Label(indexHashKeyGroup, SWT.NONE | SWT.READ_ONLY).setText("Index Hash Key Type:"); indexHashKeyAttributeTypeCombo = new Combo(indexHashKeyGroup, SWT.DROP_DOWN | SWT.READ_ONLY); indexHashKeyAttributeTypeCombo.setItems(DATA_TYPE_STRINGS); indexHashKeyAttributeTypeCombo.select(0); bindingContext.bindValue(SWTObservables.observeSelection(indexHashKeyAttributeTypeCombo), indexHashKeyAttributeTypeModel); Group indexRangeKeyGroup = CreateTablePageUtil.newGroup(composite, "Index Range Key", 2); // Enable index range key button enableIndexRangeKeyButton = new Button(indexRangeKeyGroup, SWT.CHECK); enableIndexRangeKeyButton.setText("Enable Index Range Key"); GridDataFactory.fillDefaults().span(2, 1).applyTo(enableIndexRangeKeyButton); bindingContext.bindValue(SWTObservables.observeSelection(enableIndexRangeKeyButton), enableIndexRangeKeyModel); // Index range key attribute name final Label indexRangeKeyAttributeLabel = new Label(indexRangeKeyGroup, SWT.NONE | SWT.READ_ONLY); indexRangeKeyAttributeLabel.setText("Index Range Key Name:"); indexRangeKeyNameText = new Text(indexRangeKeyGroup, SWT.BORDER); bindingContext.bindValue(SWTObservables.observeText(indexRangeKeyNameText, SWT.Modify), indexRangeKeyNameInKeySchemaDefinitionModel); ChainValidator<String> indexRangeKeyNameValidationStatusProvider = new ChainValidator<String>( indexRangeKeyNameInKeySchemaDefinitionModel, enableIndexRangeKeyModel, new NotEmptyValidator("Please provide the index range key name")); bindingContext.addValidationStatusProvider(indexRangeKeyNameValidationStatusProvider); bindingContext.bindValue(SWTObservables.observeText(indexRangeKeyNameText, SWT.Modify), indexRangeKeyNameInAttributeDefinitionsModel); indexRangeKeyNameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (primaryKeyTypes.containsKey(indexRangeKeyNameText.getText()) && indexRangeKeyAttributeTypeCombo != null && primaryKeyTypes.get(indexRangeKeyNameText.getText()) > -1) { indexRangeKeyAttributeTypeCombo.select(primaryKeyTypes.get(indexRangeKeyNameText.getText())); indexRangeKeyAttributeTypeCombo.setEnabled(false); } else if (indexRangeKeyAttributeTypeCombo != null) { indexRangeKeyAttributeTypeCombo.setEnabled(true); } } }); GridDataFactory.fillDefaults().grab(true, false).applyTo(indexRangeKeyNameText); // Index range key attribute type final Label indexRangeKeyTypeLabel = new Label(indexRangeKeyGroup, SWT.NONE | SWT.READ_ONLY); indexRangeKeyTypeLabel.setText("Index Range Key Type:"); indexRangeKeyAttributeTypeCombo = new Combo(indexRangeKeyGroup, SWT.DROP_DOWN | SWT.READ_ONLY); indexRangeKeyAttributeTypeCombo.setItems(DATA_TYPE_STRINGS); indexRangeKeyAttributeTypeCombo.select(0); bindingContext.bindValue(SWTObservables.observeSelection(indexRangeKeyAttributeTypeCombo), indexRangeKeyAttributeTypeModel); enableIndexRangeKeyButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { enableIndexRangeKey = enableIndexRangeKeyButton.getSelection(); indexRangeKeyAttributeLabel.setEnabled(enableIndexRangeKey); indexRangeKeyNameText.setEnabled(enableIndexRangeKey); indexRangeKeyTypeLabel.setEnabled(enableIndexRangeKey); indexRangeKeyAttributeTypeCombo.setEnabled(enableIndexRangeKey); } }); enableIndexRangeKeyButton.setSelection(false); indexRangeKeyAttributeLabel.setEnabled(false); indexRangeKeyNameText.setEnabled(false); indexRangeKeyTypeLabel.setEnabled(false); indexRangeKeyAttributeTypeCombo.setEnabled(false); // Index name Label indexNameLabel = new Label(composite, SWT.NONE | SWT.READ_ONLY); indexNameLabel.setText("Index Name:"); indexNameText = new Text(composite, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(indexNameText); bindingContext.bindValue(SWTObservables.observeText(indexNameText, SWT.Modify), indexNameModel); ChainValidator<String> indexNameValidationStatusProvider = new ChainValidator<String>(indexNameModel, new NotEmptyValidator("Please provide an index name")); bindingContext.addValidationStatusProvider(indexNameValidationStatusProvider); // Projection type new Label(composite, SWT.NONE | SWT.READ_ONLY).setText("Projected Attributes:"); projectionTypeCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); projectionTypeCombo.setItems(PROJECTED_ATTRIBUTES); projectionTypeCombo.select(0); bindingContext.bindValue(SWTObservables.observeSelection(projectionTypeCombo), projectionTypeModel); projectionTypeCombo.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { if (projectionTypeCombo.getSelectionIndex() == 2) { // Enable the list for adding non-key attributes to the projection addAttributeButton.setEnabled(true); } else { addAttributeButton.setEnabled(false); } } public void widgetDefaultSelected(SelectionEvent e) { } }); // Non-key attributes in the projection final AttributeList attributeList = new AttributeList(composite); GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, SWT.DEFAULT).applyTo(attributeList); addAttributeButton = new Button(composite, SWT.PUSH); addAttributeButton.setText("Add Attribute"); addAttributeButton.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); addAttributeButton.setImage(AwsToolkitCore.getDefault().getImageRegistry().get(AwsToolkitCore.IMAGE_ADD)); addAttributeButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { AddNewAttributeDialog newAttributeTable = new AddNewAttributeDialog(); if (newAttributeTable.open() == 0) { // lazy-initialize the list if (null == globalSecondaryIndex.getProjection().getNonKeyAttributes()) { globalSecondaryIndex.getProjection().setNonKeyAttributes(new LinkedList<String>()); } globalSecondaryIndex.getProjection().getNonKeyAttributes() .add(newAttributeTable.getNewAttributeName()); attributeList.refresh(); } } public void widgetDefaultSelected(SelectionEvent e) { } }); addAttributeButton.setEnabled(false); // GSI throughput FontData[] fontData = indexNameLabel.getFont().getFontData(); for (FontData fd : fontData) { fd.setStyle(SWT.ITALIC); } italicFont = new Font(Display.getDefault(), fontData); Group throughputGroup = CreateTablePageUtil.newGroup(composite, "Global Secondary Index Throughput", 3); new Label(throughputGroup, SWT.READ_ONLY).setText("Read Capacity Units:"); final Text readCapacityText = CreateTablePageUtil.newTextField(throughputGroup); readCapacityText.setText("" + CAPACITY_UNIT_MINIMUM); bindingContext.bindValue(SWTObservables.observeText(readCapacityText, SWT.Modify), readCapacityModel); ChainValidator<Long> readCapacityValidationStatusProvider = new ChainValidator<Long>(readCapacityModel, new RangeValidator("Please enter a read capacity of " + CAPACITY_UNIT_MINIMUM + " or more.", CAPACITY_UNIT_MINIMUM, Long.MAX_VALUE)); bindingContext.addValidationStatusProvider(readCapacityValidationStatusProvider); Label minimumReadCapacityLabel = new Label(throughputGroup, SWT.READ_ONLY); minimumReadCapacityLabel.setText("(Minimum capacity " + CAPACITY_UNIT_MINIMUM + ")"); minimumReadCapacityLabel.setFont(italicFont); new Label(throughputGroup, SWT.READ_ONLY).setText("Write Capacity Units:"); final Text writeCapacityText = CreateTablePageUtil.newTextField(throughputGroup); writeCapacityText.setText("" + CAPACITY_UNIT_MINIMUM); Label minimumWriteCapacityLabel = new Label(throughputGroup, SWT.READ_ONLY); minimumWriteCapacityLabel.setText("(Minimum capacity " + CAPACITY_UNIT_MINIMUM + ")"); minimumWriteCapacityLabel.setFont(italicFont); bindingContext.bindValue(SWTObservables.observeText(writeCapacityText, SWT.Modify), writeCapacityModel); ChainValidator<Long> writeCapacityValidationStatusProvider = new ChainValidator<Long>(writeCapacityModel, new RangeValidator("Please enter a write capacity of " + CAPACITY_UNIT_MINIMUM + " or more.", CAPACITY_UNIT_MINIMUM, Long.MAX_VALUE)); bindingContext.addValidationStatusProvider(writeCapacityValidationStatusProvider); final Label throughputCapacityLabel = new Label(throughputGroup, SWT.WRAP); throughputCapacityLabel .setText("This throughput is separate from and in addition to the primary table's throughput."); GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false); gridData.horizontalSpan = 3; gridData.widthHint = 200; throughputCapacityLabel.setLayoutData(gridData); throughputCapacityLabel.setFont(italicFont); // Finally provide aggregate status reporting for the entire wizard page final AggregateValidationStatus aggregateValidationStatus = new AggregateValidationStatus(bindingContext, AggregateValidationStatus.MAX_SEVERITY); aggregateValidationStatus.addChangeListener(new IChangeListener() { public void handleChange(ChangeEvent event) { Object value = aggregateValidationStatus.getValue(); if (value instanceof IStatus == false) return; IStatus status = (IStatus) value; if (status.getSeverity() == Status.ERROR) { setErrorMessage(status.getMessage()); if (okButton != null) { okButton.setEnabled(false); } } else { setErrorMessage(null); if (okButton != null) { okButton.setEnabled(true); } } } }); bindingContext.updateModels(); return composite; }
From source file:com.amazonaws.eclipse.explorer.dynamodb.AddLSIDialog.java
License:Apache License
@Override protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); composite.setLayout(new GridLayout()); composite = new Composite(composite, SWT.NULL); GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); composite.setLayout(new GridLayout(2, false)); // Index range key attribute name new Label(composite, SWT.NONE | SWT.READ_ONLY).setText("Attribute to Index:"); attributeNameText = new Text(composite, SWT.BORDER); bindingContext.bindValue(SWTObservables.observeText(attributeNameText, SWT.Modify), indexRangeKeyNameInKeySchemaDefinitionModel); ChainValidator<String> attributeNameValidationStatusProvider = new ChainValidator<String>( indexRangeKeyNameInKeySchemaDefinitionModel, new NotEmptyValidator("Please provide an attribute name")); bindingContext.addValidationStatusProvider(attributeNameValidationStatusProvider); bindingContext.bindValue(SWTObservables.observeText(attributeNameText, SWT.Modify), indexRangeKeyNameInAttributeDefinitionsModel); attributeNameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (attributeNameText.getText().equals(primaryRangeKeyName) && attributeTypeCombo != null && primaryRangeKeyTypeComboIndex > -1) { attributeTypeCombo.select(primaryRangeKeyTypeComboIndex); attributeTypeCombo.setEnabled(false); } else if (attributeTypeCombo != null) { attributeTypeCombo.setEnabled(true); }// w w w.jav a 2 s .c o m } }); GridDataFactory.fillDefaults().grab(true, false).applyTo(attributeNameText); // Index range key attribute type new Label(composite, SWT.NONE | SWT.READ_ONLY).setText("Attribute Type:"); attributeTypeCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); attributeTypeCombo.setItems(DATA_TYPE_STRINGS); attributeTypeCombo.select(0); bindingContext.bindValue(SWTObservables.observeSelection(attributeTypeCombo), indexRangeKeyAttributeTypeModel); // Index name new Label(composite, SWT.NONE | SWT.READ_ONLY).setText("Index Name:"); indexNameText = new Text(composite, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(indexNameText); bindingContext.bindValue(SWTObservables.observeText(indexNameText, SWT.Modify), indexNameModel); ChainValidator<String> indexNameValidationStatusProvider = new ChainValidator<String>(indexNameModel, new NotEmptyValidator("Please provide an index name")); bindingContext.addValidationStatusProvider(indexNameValidationStatusProvider); // Projection type new Label(composite, SWT.NONE | SWT.READ_ONLY).setText("Projected Attributes:"); projectionTypeCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); projectionTypeCombo.setItems(PROJECTED_ATTRIBUTES); projectionTypeCombo.select(0); bindingContext.bindValue(SWTObservables.observeSelection(projectionTypeCombo), projectionTypeModel); projectionTypeCombo.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { if (projectionTypeCombo.getSelectionIndex() == 2) { // Enable the list for adding non-key attributes to the projection addAttributeButton.setEnabled(true); } else { addAttributeButton.setEnabled(false); } } public void widgetDefaultSelected(SelectionEvent e) { } }); // Non-key attributes in the projection final AttributeList attributeList = new AttributeList(composite); GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, SWT.DEFAULT).applyTo(attributeList); addAttributeButton = new Button(composite, SWT.PUSH); addAttributeButton.setText("Add Attribute"); addAttributeButton.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); addAttributeButton.setImage(AwsToolkitCore.getDefault().getImageRegistry().get(AwsToolkitCore.IMAGE_ADD)); addAttributeButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { AddNewAttributeDialog newAttributeTable = new AddNewAttributeDialog(); if (newAttributeTable.open() == 0) { // lazy-initialize the list if (null == localSecondaryIndex.getProjection().getNonKeyAttributes()) { localSecondaryIndex.getProjection().setNonKeyAttributes(new LinkedList<String>()); } localSecondaryIndex.getProjection().getNonKeyAttributes() .add(newAttributeTable.getNewAttributeName()); attributeList.refresh(); } } public void widgetDefaultSelected(SelectionEvent e) { } }); addAttributeButton.setEnabled(false); // Finally provide aggregate status reporting for the entire wizard page final AggregateValidationStatus aggregateValidationStatus = new AggregateValidationStatus(bindingContext, AggregateValidationStatus.MAX_SEVERITY); aggregateValidationStatus.addChangeListener(new IChangeListener() { public void handleChange(ChangeEvent event) { Object value = aggregateValidationStatus.getValue(); if (value instanceof IStatus == false) return; IStatus status = (IStatus) value; if (status.getSeverity() == Status.ERROR) { setErrorMessage(status.getMessage()); if (okButton != null) { okButton.setEnabled(false); } } else { setErrorMessage(null); if (okButton != null) { okButton.setEnabled(true); } } } }); bindingContext.updateModels(); return composite; }
From source file:com.amazonaws.eclipse.explorer.dynamodb.CreateTableFirstPage.java
License:Apache License
public void createControl(Composite parent) { Composite comp = new Composite(parent, SWT.NONE); GridDataFactory.fillDefaults().grab(true, true).applyTo(comp); GridLayoutFactory.fillDefaults().numColumns(2).applyTo(comp); // Table name Label tableNameLabel = new Label(comp, SWT.READ_ONLY); tableNameLabel.setText("Table Name:"); final Text tableNameText = CreateTablePageUtil.newTextField(comp); bindingContext.bindValue(SWTObservables.observeText(tableNameText, SWT.Modify), tableName); ChainValidator<String> tableNameValidationStatusProvider = new ChainValidator<String>(tableName, new NotEmptyValidator("Please provide a table name")); bindingContext.addValidationStatusProvider(tableNameValidationStatusProvider); // Hash key//from ww w .j a va 2 s. co m Group hashKeyGroup = CreateTablePageUtil.newGroup(comp, "Hash Key", 2); new Label(hashKeyGroup, SWT.READ_ONLY).setText("Hash Key Name:"); final Text hashKeyText = CreateTablePageUtil.newTextField(hashKeyGroup); bindingContext.bindValue(SWTObservables.observeText(hashKeyText, SWT.Modify), hashKeyName); ChainValidator<String> hashKeyNameValidationStatusProvider = new ChainValidator<String>(hashKeyName, new NotEmptyValidator("Please provide an attribute name for the hash key")); bindingContext.addValidationStatusProvider(hashKeyNameValidationStatusProvider); new Label(hashKeyGroup, SWT.READ_ONLY).setText("Hash Key Type:"); final Combo hashKeyTypeCombo = new Combo(hashKeyGroup, SWT.DROP_DOWN | SWT.READ_ONLY); hashKeyTypeCombo.setItems(DATA_TYPE_STRINGS); bindingContext.bindValue(SWTObservables.observeSelection(hashKeyTypeCombo), hashKeyType); hashKeyTypeCombo.select(0); // Range key Group rangeKeyGroup = CreateTablePageUtil.newGroup(comp, "Range Key", 2); final Button enableRangeKeyButton = new Button(rangeKeyGroup, SWT.CHECK); enableRangeKeyButton.setText("Enable Range Key"); GridDataFactory.fillDefaults().span(2, 1).applyTo(enableRangeKeyButton); bindingContext.bindValue(SWTObservables.observeSelection(enableRangeKeyButton), enableRangeKey); final Label rangeKeyAttributeLabel = new Label(rangeKeyGroup, SWT.READ_ONLY); rangeKeyAttributeLabel.setText("Range Key Name:"); final Text rangeKeyText = CreateTablePageUtil.newTextField(rangeKeyGroup); bindingContext.bindValue(SWTObservables.observeText(rangeKeyText, SWT.Modify), rangeKeyName); ChainValidator<String> rangeKeyNameValidationStatusProvider = new ChainValidator<String>(rangeKeyName, enableRangeKey, new NotEmptyValidator("Please provide an attribute name for the range key")); bindingContext.addValidationStatusProvider(rangeKeyNameValidationStatusProvider); final Label rangeKeyTypeLabel = new Label(rangeKeyGroup, SWT.READ_ONLY); rangeKeyTypeLabel.setText("Range Key Type:"); final Combo rangeKeyTypeCombo = new Combo(rangeKeyGroup, SWT.DROP_DOWN | SWT.READ_ONLY); rangeKeyTypeCombo.setItems(DATA_TYPE_STRINGS); bindingContext.bindValue(SWTObservables.observeSelection(rangeKeyTypeCombo), rangeKeyType); rangeKeyTypeCombo.select(0); enableRangeKeyButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { usesRangeKey = enableRangeKeyButton.getSelection(); rangeKeyAttributeLabel.setEnabled(usesRangeKey); rangeKeyText.setEnabled(usesRangeKey); rangeKeyTypeLabel.setEnabled(usesRangeKey); rangeKeyTypeCombo.setEnabled(usesRangeKey); } }); enableRangeKeyButton.setSelection(false); rangeKeyAttributeLabel.setEnabled(usesRangeKey); rangeKeyText.setEnabled(usesRangeKey); rangeKeyTypeLabel.setEnabled(usesRangeKey); rangeKeyTypeCombo.setEnabled(usesRangeKey); FontData[] fontData = tableNameLabel.getFont().getFontData(); for (FontData fd : fontData) { fd.setStyle(SWT.ITALIC); } italicFont = new Font(Display.getDefault(), fontData); // Table throughput Group throughputGroup = CreateTablePageUtil.newGroup(comp, "Table Throughput", 3); new Label(throughputGroup, SWT.READ_ONLY).setText("Read Capacity Units:"); final Text readCapacityText = CreateTablePageUtil.newTextField(throughputGroup); readCapacityText.setText("" + CAPACITY_UNIT_MINIMUM); bindingContext.bindValue(SWTObservables.observeText(readCapacityText, SWT.Modify), readCapacity); ChainValidator<Long> readCapacityValidationStatusProvider = new ChainValidator<Long>(readCapacity, new RangeValidator("Please enter a read capacity of " + CAPACITY_UNIT_MINIMUM + " or more.", CAPACITY_UNIT_MINIMUM, Long.MAX_VALUE)); bindingContext.addValidationStatusProvider(readCapacityValidationStatusProvider); Label minimumReadCapacityLabel = new Label(throughputGroup, SWT.READ_ONLY); minimumReadCapacityLabel.setText("(Minimum capacity " + CAPACITY_UNIT_MINIMUM + ")"); minimumReadCapacityLabel.setFont(italicFont); new Label(throughputGroup, SWT.READ_ONLY).setText("Write Capacity Units:"); final Text writeCapacityText = CreateTablePageUtil.newTextField(throughputGroup); writeCapacityText.setText("" + CAPACITY_UNIT_MINIMUM); Label minimumWriteCapacityLabel = new Label(throughputGroup, SWT.READ_ONLY); minimumWriteCapacityLabel.setText("(Minimum capacity " + CAPACITY_UNIT_MINIMUM + ")"); minimumWriteCapacityLabel.setFont(italicFont); bindingContext.bindValue(SWTObservables.observeText(writeCapacityText, SWT.Modify), writeCapacity); ChainValidator<Long> writeCapacityValidationStatusProvider = new ChainValidator<Long>(writeCapacity, new RangeValidator("Please enter a write capacity of " + CAPACITY_UNIT_MINIMUM + " or more.", CAPACITY_UNIT_MINIMUM, Long.MAX_VALUE)); bindingContext.addValidationStatusProvider(writeCapacityValidationStatusProvider); final Label throughputCapacityLabel = new Label(throughputGroup, SWT.WRAP); throughputCapacityLabel.setText( "Amazon DynamoDB will reserve the necessary machine resources to meet your throughput needs based on the read and write capacity specified with consistent, low-latency performance. You pay a flat, hourly rate based on the capacity you reserve."); GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false); gridData.horizontalSpan = 3; gridData.widthHint = 200; throughputCapacityLabel.setLayoutData(gridData); throughputCapacityLabel.setFont(italicFont); // Help info String pricingLinkText = "<a href=\"" + "http://aws.amazon.com/dynamodb/#pricing" + "\">" + "More information on Amazon DynamoDB pricing</a>. "; CreateTablePageUtil.newLink(new WebLinkListener(), pricingLinkText, throughputGroup); // Finally provide aggregate status reporting for the entire wizard page final AggregateValidationStatus aggregateValidationStatus = new AggregateValidationStatus(bindingContext, AggregateValidationStatus.MAX_SEVERITY); aggregateValidationStatus.addChangeListener(new IChangeListener() { public void handleChange(ChangeEvent event) { Object value = aggregateValidationStatus.getValue(); if (value instanceof IStatus == false) return; IStatus status = (IStatus) value; if (status.isOK()) { setErrorMessage(null); setMessage(OK_MESSAGE, Status.OK); } else if (status.getSeverity() == Status.WARNING) { setErrorMessage(null); setMessage(status.getMessage(), Status.WARNING); } else if (status.getSeverity() == Status.ERROR) { setErrorMessage(status.getMessage()); } setPageComplete(status.isOK()); } }); setPageComplete(false); setControl(comp); }
From source file:com.amazonaws.eclipse.identitymanagement.group.CreateGroupSecondPage.java
License:Apache License
public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(1, false); layout.marginLeft = 5;/*from ww w.j a v a 2 s. c o m*/ composite.setLayout(layout); GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); grantPermissionButton = new Button(composite, SWT.CHECK); grantPermissionButton.setText("Grant permissions"); grantPermissionButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { if (grantPermissionButton.getSelection()) { policyNameText.setEnabled(true); policyDocText.setEnabled(true); } else { policyNameText.setEnabled(false); policyDocText.setEnabled(false); } } public void widgetDefaultSelected(SelectionEvent e) { } }); bindingContext.bindValue(SWTObservables.observeSelection(grantPermissionButton), grantPermission); new Label(composite, SWT.NONE).setText("Policy Name:"); policyNameText = new Text(composite, SWT.BORDER); policyNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); bindingContext.bindValue(SWTObservables.observeText(policyNameText, SWT.Modify), policyName); ChainValidator<String> policyNameValidationStatusProvider = new ChainValidator<String>(policyName, grantPermission, new NotEmptyValidator("Please enter policy name")); bindingContext.addValidationStatusProvider(policyNameValidationStatusProvider); DataBindingUtils.addStatusDecorator(policyNameText, policyNameValidationStatusProvider); new Label(composite, SWT.NONE).setText("Policy Documentation:"); policyDocText = new Text(composite, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER | SWT.H_SCROLL); GridData gridData = new GridData(GridData.FILL_BOTH); gridData.minimumHeight = 250; policyDocText.setLayoutData(gridData); bindingContext.bindValue(SWTObservables.observeText(policyDocText, SWT.Modify), policyDoc); ChainValidator<String> policyDocValidationStatusProvider = new ChainValidator<String>(policyDoc, grantPermission, new NotEmptyValidator("Please enter valid policy doc")); bindingContext.addValidationStatusProvider(policyDocValidationStatusProvider); DataBindingUtils.addStatusDecorator(policyDocText, policyDocValidationStatusProvider); Link link = new Link(composite, SWT.NONE | SWT.WRAP); link.setText("For more information about the access policy language, " + "see <a href=\"" + ConceptUrl + "\">Key Concepts</a> in Using AWS Identity and Access Management."); link.addListener(SWT.Selection, new WebLinkListener()); gridData = new GridData(SWT.FILL, SWT.TOP, true, false); gridData.widthHint = 200; link.setLayoutData(gridData); setControl(composite); setPageComplete(false); // Finally provide aggregate status reporting for the entire wizard page final AggregateValidationStatus aggregateValidationStatus = new AggregateValidationStatus(bindingContext, AggregateValidationStatus.MAX_SEVERITY); aggregateValidationStatus.addChangeListener(new IChangeListener() { public void handleChange(ChangeEvent event) { Object value = aggregateValidationStatus.getValue(); if (value instanceof IStatus == false) return; IStatus status = (IStatus) value; if (status.isOK()) { setErrorMessage(null); setMessage(OK_MESSAGE, Status.OK); } else if (status.getSeverity() == Status.WARNING) { setErrorMessage(null); setMessage(status.getMessage(), Status.WARNING); } else if (status.getSeverity() == Status.ERROR) { setErrorMessage(status.getMessage()); } setPageComplete(status.isOK()); } }); policyNameText.setEnabled(false); policyDocText.setEnabled(false); setPageComplete(true); }