use of org.jboss.tools.openshift.internal.common.ui.databinding.FileExistsConverter in project jbosstools-openshift by jbosstools.
the class GitCloningWizardPage method createCloneGroup.
private Composite createCloneGroup(Composite parent, DataBindingContext dbc) {
Group cloneGroup = new Group(parent, SWT.NONE);
cloneGroup.setText("Clone destination");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(cloneGroup);
GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(cloneGroup);
Composite cloneGroupComposite = new Composite(cloneGroup, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(cloneGroupComposite);
GridLayoutFactory.fillDefaults().numColumns(3).applyTo(cloneGroupComposite);
// use default clone destination path
Button useDefaultCloneDestinationButton = new Button(cloneGroupComposite, SWT.CHECK);
useDefaultCloneDestinationButton.setText("Use default clone destination");
useDefaultCloneDestinationButton.setToolTipText("Uncheck if you want to use a custom location to clone to");
GridDataFactory.fillDefaults().span(3, 1).align(SWT.LEFT, SWT.CENTER).applyTo(useDefaultCloneDestinationButton);
final IObservableValue<Boolean> useDefaultCloneDestinationObservable = BeanProperties.value(IGitCloningPageModel.PROPERTY_USE_DEFAULT_CLONE_DESTINATION).observe(model);
ValueBindingBuilder.bind(WidgetProperties.selection().observe(useDefaultCloneDestinationButton)).to(useDefaultCloneDestinationObservable).in(dbc);
// clone destination
Label repoPathLabel = new Label(cloneGroupComposite, SWT.NONE);
repoPathLabel.setText("Git Clone Location:");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(repoPathLabel);
final Text cloneDestinationText = new Text(cloneGroupComposite, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(cloneDestinationText);
final IObservableValue<String> cloneDestinationObservable = WidgetProperties.text(SWT.Modify).observe(cloneDestinationText);
final IObservableValue<String> cloneDestinationModelObservable = BeanProperties.value(IGitCloningPageModel.PROPERTY_CLONE_DESTINATION).observe(model);
ValueBindingBuilder.bind(cloneDestinationObservable).to(cloneDestinationModelObservable).in(dbc);
Button browseCloneDestinationButton = new Button(cloneGroupComposite, SWT.PUSH);
browseCloneDestinationButton.setText("Browse...");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(100, SWT.DEFAULT).applyTo(browseCloneDestinationButton);
browseCloneDestinationButton.addSelectionListener(onCloneDestination());
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(cloneDestinationText)).notUpdating(useDefaultCloneDestinationObservable).converting(new InvertingBooleanConverter()).in(dbc);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(browseCloneDestinationButton)).notUpdating(useDefaultCloneDestinationObservable).converting(new InvertingBooleanConverter()).in(dbc);
// move focus to the project location text control when not choosing the
// 'Use default location' option.
UIUtils.focusOnSelection(useDefaultCloneDestinationButton, cloneDestinationText);
// Reuse git repository
Button reuseRepositoryButton = new Button(cloneGroupComposite, SWT.CHECK);
reuseRepositoryButton.setSelection(false);
reuseRepositoryButton.setText("Do not clone - use existing repository");
GridDataFactory.fillDefaults().span(3, 1).align(SWT.LEFT, SWT.CENTER).applyTo(reuseRepositoryButton);
final IObservableValue<Boolean> reuseGitReposityObservable = WidgetProperties.selection().observe(reuseRepositoryButton);
ValueBindingBuilder.bind(reuseGitReposityObservable).to(BeanProperties.value(IGitCloningPageModel.PROPERTY_REUSE_GIT_REPOSITORY).observe(model)).in(dbc);
IObservableValue<File> repoPathObservable = BeanProperties.value(IGitCloningPageModel.PROPERTY_REPO_PATH).observe(model);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(reuseRepositoryButton)).notUpdating(repoPathObservable).converting(new FileExistsConverter()).in(dbc);
ISWTObservableValue reuseRepoButtonEnabled = WidgetProperties.enabled().observe(reuseRepositoryButton);
ValueBindingBuilder.bind(reuseRepoButtonEnabled).notUpdating(repoPathObservable).converting(new Converter(File.class, Boolean.class) {
@Override
public Object convert(Object fromObject) {
return fromObject instanceof File && EGitUtils.isRepository((File) fromObject);
}
}).in(dbc);
this.cloneDestinationPathValidator = new CloneDestinationPathValidator(useDefaultCloneDestinationObservable, cloneDestinationObservable, reuseGitReposityObservable, repoPathObservable);
dbc.addValidationStatusProvider(cloneDestinationPathValidator);
ControlDecorationSupport.create(cloneDestinationPathValidator, SWT.LEFT | SWT.TOP);
// checkout reused repo button
Composite checkoutComposite = new Composite(cloneGroupComposite, SWT.NONE);
GridDataFactory.fillDefaults().span(3, 1).indent(20, SWT.DEFAULT).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(checkoutComposite);
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(checkoutComposite);
Button checkoutBranchCheckbox = new Button(checkoutComposite, SWT.CHECK);
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(checkoutBranchCheckbox);
ISWTObservableValue checkoutBranchCheckboxObservable = WidgetProperties.selection().observe(checkoutBranchCheckbox);
ValueBindingBuilder.bind(checkoutBranchCheckboxObservable).validatingAfterConvert(new CheckoutBranchValidator()).to(BeanProperties.value(IGitCloningPageModel.PROPERTY_CHECKOUT_BRANCH_REUSED_REPO).observe(model)).validatingAfterConvert(new CheckoutBranchValidator()).in(dbc);
IObservableValue<Boolean> isRepositoryBranchGitRefObservable = BeanProperties.value(IGitCloningPageModel.PROPERTY_IS_REPOSITORY_BRANCH_GIT_REF).observe(model);
ComputedValue<Boolean> checkoutBranchEnablement = new ComputedValue<Boolean>() {
@Override
protected Boolean calculate() {
// access all involved observables
Boolean isReuseRepoButtonEnabled = (Boolean) reuseRepoButtonEnabled.getValue();
Boolean isRepositoryBranchGitRef = isRepositoryBranchGitRefObservable.getValue();
Boolean isReuseGitRepository = reuseGitReposityObservable.getValue();
return isReuseRepoButtonEnabled && !isRepositoryBranchGitRef && isReuseGitRepository;
}
};
// checkout branch label
Label checkoutBranchLabel = new Label(checkoutComposite, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).grab(true, false).applyTo(checkoutBranchLabel);
checkoutBranchLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
checkoutBranchCheckboxObservable.setValue(!checkoutBranchCheckbox.getSelection());
}
});
ValueBindingBuilder.bind(WidgetProperties.text().observe(checkoutBranchLabel)).notUpdating(BeanProperties.value(IGitCloningPageModel.PROPERTY_GIT_REF).observe(model)).converting(new Converter(String.class, String.class) {
@Override
public Object convert(Object fromObject) {
return "Check out branch " + fromObject;
}
}).in(dbc);
ValueBindingBuilder.bind(new WritableValue<Boolean>() {
@Override
public void doSetValue(Boolean value) {
checkoutBranchCheckbox.setEnabled(value);
checkoutBranchLabel.setEnabled(value);
}
}).notUpdating(checkoutBranchEnablement).in(dbc);
return cloneGroup;
}
Aggregations