use of org.eclipse.core.databinding.conversion.Converter in project jbosstools-openshift by jbosstools.
the class ApplicationSourceListPage method doCreateControls.
@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
super.doCreateControls(parent, dbc);
IObservableValue selectedEclipseProject = createEclipseProjectControls(parent, dbc);
SashForm listAndDetailsContainer = new SashForm(parent, SWT.VERTICAL);
GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(listAndDetailsContainer);
GridLayoutFactory.fillDefaults().applyTo(listAndDetailsContainer);
TabFolder tabContainer = new TabFolder(listAndDetailsContainer, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(tabContainer);
tabContainer.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
// JBIDE-21072: force re-layout of the parent upon tab switching
parent.layout(true, true);
}
});
IObservableValue useLocalTemplateObservable = BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_USE_LOCAL_APP_SOURCE).observe(model);
ValueBindingBuilder.bind(new TabFolderSelectionProperty().observe(tabContainer)).converting(new Converter(Integer.class, Boolean.class) {
@Override
public Object convert(Object fromObject) {
return Integer.valueOf(LOCAL_TEMPLATE_TAB_INDEX).equals(fromObject);
}
}).to(useLocalTemplateObservable).converting(new Converter(Boolean.class, Integer.class) {
@Override
public Object convert(Object fromObject) {
return (fromObject != null && (Boolean) fromObject) ? LOCAL_TEMPLATE_TAB_INDEX : 0;
}
}).in(dbc);
model.setUseLocalAppSource(false);
TabFolderTraverseListener tabFolderTraverseListener = new TabFolderTraverseListener(tabContainer);
IObservableValue serverTemplate = createServerTemplateControls(tabContainer, tabFolderTraverseListener, useLocalTemplateObservable, dbc);
IObservableValue localTemplateFilename = createLocalTemplateControls(tabContainer, tabFolderTraverseListener, useLocalTemplateObservable, dbc);
dbc.addValidationStatusProvider(new MultiValidator() {
@Override
protected IStatus validate() {
return (IStatus) BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_APP_SOURCE_STATUS, IStatus.class).observe(model).getValue();
}
});
createDetailsGroup(listAndDetailsContainer, dbc);
// template list initially takes twice the height of the details pane
listAndDetailsContainer.setWeights(new int[] { 2, 1 });
// validate required template
IObservableValue selectedTemplate = BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_SELECTED_APP_SOURCE).observe(model);
TemplateListPageValidator pageValidator = new TemplateListPageValidator(useLocalTemplateObservable, localTemplateFilename, serverTemplate, selectedTemplate, selectedEclipseProject, parent);
dbc.addValidationStatusProvider(pageValidator);
ControlDecorationSupport.create(pageValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
ProjectNameValidator projectNameValidator = new ProjectNameValidator(selectedEclipseProject, parent);
dbc.addValidationStatusProvider(projectNameValidator);
ControlDecorationSupport.create(projectNameValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
}
use of org.eclipse.core.databinding.conversion.Converter in project jbosstools-openshift by jbosstools.
the class ApplicationSourceListPage method createDetailsGroup.
private void createDetailsGroup(Composite parent, DataBindingContext dbc) {
// details
Group detailsGroup = new Group(parent, SWT.NONE);
detailsGroup.setText("Details");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(detailsGroup);
// TODO fix margins
GridLayoutFactory.fillDefaults().margins(10, 6).spacing(2, 2).applyTo(detailsGroup);
Composite detailsContainer = new Composite(detailsGroup, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(detailsContainer);
new ApplicationSourceDetailViews(BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_SELECTED_APP_SOURCE).observe(model), null, detailsContainer, dbc).createControls();
// detail resources button
Button btnDetails = new Button(detailsGroup, SWT.NONE);
btnDetails.setText("Defined Resources...");
GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(btnDetails);
IObservableValue selectedTemplate = BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_SELECTED_APP_SOURCE).observe(model);
ValueBindingBuilder.bind(WidgetProperties.visible().observe(btnDetails)).notUpdatingParticipant().to(selectedTemplate).converting(new Converter(Object.class, Boolean.class) {
@Override
public Object convert(Object fromObject) {
return fromObject != null && ResourceKind.TEMPLATE.equals(((IApplicationSource) fromObject).getSource().getKind());
}
}).in(dbc);
btnDetails.addSelectionListener(onDefinedResourcesClicked());
}
use of org.eclipse.core.databinding.conversion.Converter in project jbosstools-openshift by jbosstools.
the class SelectProjectComponentBuilder method build.
public void build(Composite container, DataBindingContext dbc) {
Label existingProjectLabel = new Label(container, SWT.NONE);
existingProjectLabel.setText("Eclipse Project: ");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(existingProjectLabel);
final Text existingProjectNameText = new Text(container, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(hSpan, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(existingProjectNameText);
projectNameTextObservable = WidgetProperties.text(SWT.Modify).observe(existingProjectNameText);
Binding eclipseProjectBinding = ValueBindingBuilder.bind(projectNameTextObservable).validatingAfterConvert(new IValidator() {
@Override
public IStatus validate(Object value) {
if (value instanceof String) {
return ValidationStatus.ok();
} else if (value == null) {
if (required) {
return ValidationStatus.error("Select an existing project");
} else if (!StringUtils.isEmpty(existingProjectNameText.getText())) {
return ValidationStatus.error(NLS.bind("Project {0} does not exist", existingProjectNameText.getText()));
}
}
return ValidationStatus.ok();
}
}).converting(new Converter(String.class, IProject.class) {
@Override
public Object convert(Object fromObject) {
String name = (String) fromObject;
return ProjectUtils.getProject(name);
}
}).to(eclipseProjectObservable).converting(new Converter(IProject.class, String.class) {
@Override
public Object convert(Object fromObject) {
return fromObject == null ? "" : ((IProject) fromObject).getName();
}
}).in(dbc);
ControlDecorationSupport.create(eclipseProjectBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
// project name content assist
ControlDecoration dec = new ControlDecoration(existingProjectNameText, SWT.TOP | SWT.RIGHT);
FieldDecoration contentProposalFieldIndicator = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
dec.setImage(contentProposalFieldIndicator.getImage());
dec.setDescriptionText("Auto-completion is enabled when you start typing a project name.");
dec.setShowOnlyOnFocus(true);
new AutoCompleteField(existingProjectNameText, new TextContentAdapter(), ProjectUtils.getAllAccessibleProjectNames());
// browse projects
Button browseProjectsButton = new Button(container, SWT.NONE);
browseProjectsButton.setText("Browse...");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).indent(buttonIndent, 0).applyTo(browseProjectsButton);
UIUtils.setDefaultButtonWidth(browseProjectsButton);
browseProjectsButton.addSelectionListener(selectionListener);
}
use of org.eclipse.core.databinding.conversion.Converter 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;
}
use of org.eclipse.core.databinding.conversion.Converter in project jbosstools-openshift by jbosstools.
the class ServerSettingsWizardPage method createOCWarningControls.
@SuppressWarnings("unchecked")
private void createOCWarningControls(Composite container, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
Composite composite = new Composite(container, SWT.NONE);
GridDataFactory.fillDefaults().applyTo(composite);
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);
ValueBindingBuilder.bind(WidgetProperties.visible().observe(composite)).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model)).converting(new Converter(IStatus.class, Boolean.class) {
@Override
public Object convert(Object fromObject) {
return !((IStatus) fromObject).isOK();
}
}).in(dbc);
Label label = new Label(composite, SWT.NONE);
ValueBindingBuilder.bind(WidgetProperties.image().observe(label)).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model)).converting(new Converter(IStatus.class, Image.class) {
@Override
public Object convert(Object fromObject) {
switch(((IStatus) fromObject).getSeverity()) {
case IStatus.WARNING:
return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
case IStatus.ERROR:
return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
default:
return null;
}
}
}).in(dbc);
Link link = new Link(composite, SWT.WRAP);
ValueBindingBuilder.bind(WidgetProperties.text().observe(link)).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model)).converting(new Converter(IStatus.class, String.class) {
@Override
public Object convert(Object fromObject) {
return ((IStatus) fromObject).getMessage();
}
}).in(dbc);
link.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (DOWNLOAD_LINK_TEXT.equals(e.text)) {
new BrowserUtility().checkedCreateExternalBrowser(DOWNLOAD_INSTRUCTIONS_URL, OpenShiftUIActivator.PLUGIN_ID, OpenShiftUIActivator.getDefault().getLog());
} else {
int rc = PreferencesUtil.createPreferenceDialogOn(getShell(), OPEN_SHIFT_PREFERENCE_PAGE_ID, new String[] { OPEN_SHIFT_PREFERENCE_PAGE_ID }, null).open();
if (rc == Dialog.OK) {
new Job("Checking oc binary") {
@Override
protected IStatus run(IProgressMonitor monitor) {
IStatus stat = OCBinary.getInstance().getStatus(model.getConnection(), monitor);
model.setOCBinaryStatus(stat);
return stat;
}
}.schedule();
}
}
}
});
GridDataFactory.fillDefaults().hint(LINK_DEFAULT_WIDTH, SWT.DEFAULT).applyTo(link);
MultiValidator validator = new MultiValidator() {
@Override
protected IStatus validate() {
IObservableValue<IStatus> observable = BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model);
Status status = (Status) observable.getValue();
switch(status.getSeverity()) {
case IStatus.ERROR:
return OpenShiftUIActivator.statusFactory().errorStatus(OpenShiftUIMessages.OCBinaryErrorMessage);
case IStatus.WARNING:
return OpenShiftUIActivator.statusFactory().warningStatus(OpenShiftUIMessages.OCBinaryWarningMessage);
}
return status;
}
};
dbc.addValidationStatusProvider(validator);
BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model).addValueChangeListener(event -> getShell().pack());
}
Aggregations