use of org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter in project jbosstools-openshift by jbosstools.
the class AbstractProjectPage method createProjectControls.
private void createProjectControls(Composite parent, DataBindingContext dbc) {
Label projectLabel = new Label(parent, SWT.NONE);
projectLabel.setText("OpenShift project: ");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(projectLabel);
StructuredViewer projectsViewer = new ComboViewer(parent);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(projectsViewer.getControl());
final OpenShiftExplorerLabelProvider labelProvider = new OpenShiftExplorerLabelProvider();
projectsViewer.setContentProvider(new ObservableListContentProvider());
projectsViewer.setLabelProvider(new ObservableTreeItemLabelProvider());
projectsViewer.setInput(BeanProperties.list(IProjectPageModel.PROPERTY_PROJECT_ITEMS).observe(model));
projectsViewer.setComparator(ProjectViewerComparator.createProjectTreeSorter(labelProvider));
model.setProjectsComparator(new ProjectViewerComparator(labelProvider).asItemComparator());
IObservableValue selectedProjectObservable = ViewerProperties.singleSelection().observe(projectsViewer);
Binding selectedProjectBinding = ValueBindingBuilder.bind(selectedProjectObservable).converting(new ObservableTreeItem2ModelConverter(IProject.class)).validatingAfterConvert(new IValidator() {
@Override
public IStatus validate(Object value) {
if (value instanceof IProject) {
return ValidationStatus.ok();
}
return ValidationStatus.cancel("Please choose an OpenShift project.");
}
}).to(BeanProperties.value(IProjectPageModel.PROPERTY_PROJECT).observe(model)).converting(new Model2ObservableTreeItemConverter(null)).in(dbc);
ControlDecorationSupport.create(selectedProjectBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
IObservableValue connectionObservable = BeanProperties.value(IProjectPageModel.PROPERTY_CONNECTION).observe(model);
DataBindingUtils.addDisposableValueChangeListener(onConnectionChanged(), connectionObservable, projectsViewer.getControl());
Button newProjectButton = new Button(parent, SWT.PUSH);
newProjectButton.setText("New...");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.FILL).applyTo(newProjectButton);
UIUtils.setDefaultButtonWidth(newProjectButton);
newProjectButton.addSelectionListener(onNewProjectClicked());
}
use of org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter in project jbosstools-openshift by jbosstools.
the class ApplicationSourceListPage method createServerTemplateControls.
private IObservableValue createServerTemplateControls(TabFolder tabFolder, TabFolderTraverseListener tabFolderTraverseListener, IObservableValue uploadTemplate, DataBindingContext dbc) {
TabItem serverTemplatesTab = new TabItem(tabFolder, SWT.NONE);
serverTemplatesTab.setText("Server application source");
Composite parent = new Composite(tabFolder, SWT.NONE);
GridLayoutFactory.fillDefaults().margins(10, 6).spacing(2, 2).applyTo(parent);
serverTemplatesTab.setControl(parent);
// filter text
final Text txtTemplateFilter = UIUtils.createSearchText(parent);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(txtTemplateFilter);
IObservableValue eclipseProjectObservable = BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_ECLIPSE_PROJECT).observe(model);
DataBindingUtils.addDisposableValueChangeListener(new IValueChangeListener() {
@Override
public void handleValueChange(ValueChangeEvent event) {
filterTemplates(txtTemplateFilter, (org.eclipse.core.resources.IProject) event.getObservableValue().getValue());
}
}, eclipseProjectObservable, txtTemplateFilter);
filterTemplates(txtTemplateFilter, model.getEclipseProject());
// the list of templates
this.templatesViewer = createServerTemplatesViewer(parent, txtTemplateFilter);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(400, 180).applyTo(templatesViewer.getControl());
IObservableValue selectedViewerServerTemplate = ViewerProperties.singleSelection().observe(templatesViewer);
ValueBindingBuilder.bind(selectedViewerServerTemplate).converting(new ObservableTreeItem2ModelConverter(IApplicationSource.class)).to(BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_SERVER_APP_SOURCE).observe(model)).converting(new Model2ObservableTreeItemConverter(ApplicationSourceTreeItems.INSTANCE)).in(dbc);
templatesViewer.addDoubleClickListener(onServerTemplateDoubleClicked());
txtTemplateFilter.addModifyListener(onFilterTextTyped(templatesViewer));
tabFolderTraverseListener.bindTabControls(tabFolder.getItemCount() - 1, txtTemplateFilter, templatesViewer.getTree());
return selectedViewerServerTemplate;
}
use of org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter in project jbosstools-openshift by jbosstools.
the class ServerSettingsWizardPage method createResourceTree.
@SuppressWarnings("unchecked")
private IViewerObservableValue createResourceTree(ServerSettingsWizardPageModel model, SashForm resourceControlsContainer, DataBindingContext dbc) {
Composite resourceTreeContainer = new Composite(resourceControlsContainer, SWT.None);
GridLayoutFactory.fillDefaults().applyTo(resourceTreeContainer);
// filter
Text selectorText = UIUtils.createSearchText(resourceTreeContainer);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(selectorText);
// resource tree
final TreeViewer resourcesViewer = createResourcesTreeViewer(resourceTreeContainer, model, selectorText);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(RESOURCE_TREE_WIDTH, RESOURCE_TREE_HEIGHT).applyTo(resourcesViewer.getControl());
resourcesViewer.addDoubleClickListener(onDoubleClickService());
IObservableList<ObservableTreeItem> resourceItemsObservable = BeanProperties.list(ServerSettingsWizardPageModel.PROPERTY_RESOURCE_ITEMS).observe(model);
DataBindingUtils.addDisposableListChangeListener(onResourceItemsChanged(resourcesViewer), resourceItemsObservable, resourcesViewer.getTree());
selectorText.addModifyListener(onFilterTextModified(resourcesViewer));
IViewerObservableValue selectedResourceTreeItem = ViewerProperties.singleSelection().observe(resourcesViewer);
ValueBindingBuilder.bind(selectedResourceTreeItem).converting(new ObservableTreeItem2ModelConverter(IResource.class)).validatingAfterConvert(value -> {
if ((value instanceof IResource) && OpenShiftServerUtils.isAllowedForServerAdapter((IResource) value)) {
return ValidationStatus.ok();
}
return ValidationStatus.cancel("Please select a resource that this adapter will be bound to.");
}).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_RESOURCE).observe(model)).converting(new Model2ObservableTreeItemConverter(new ServerSettingsWizardPageModel.ResourceTreeItemsFactory())).in(dbc);
return selectedResourceTreeItem;
}
Aggregations