Search in sources :

Example 1 with FileExistsConverter

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;
}
Also used : Group(org.eclipse.swt.widgets.Group) ComputedValue(org.eclipse.core.databinding.observable.value.ComputedValue) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) InvertingBooleanConverter(org.jboss.tools.common.ui.databinding.InvertingBooleanConverter) Label(org.eclipse.swt.widgets.Label) FileExistsConverter(org.jboss.tools.openshift.internal.common.ui.databinding.FileExistsConverter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Text(org.eclipse.swt.widgets.Text) Button(org.eclipse.swt.widgets.Button) ISWTObservableValue(org.eclipse.jface.databinding.swt.ISWTObservableValue) Converter(org.eclipse.core.databinding.conversion.Converter) FileExistsConverter(org.jboss.tools.openshift.internal.common.ui.databinding.FileExistsConverter) InvertingBooleanConverter(org.jboss.tools.common.ui.databinding.InvertingBooleanConverter) File(java.io.File)

Aggregations

File (java.io.File)1 Converter (org.eclipse.core.databinding.conversion.Converter)1 ComputedValue (org.eclipse.core.databinding.observable.value.ComputedValue)1 ISWTObservableValue (org.eclipse.jface.databinding.swt.ISWTObservableValue)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 InvertingBooleanConverter (org.jboss.tools.common.ui.databinding.InvertingBooleanConverter)1 FileExistsConverter (org.jboss.tools.openshift.internal.common.ui.databinding.FileExistsConverter)1