Search in sources :

Example 1 with Model2ObservableTreeItemConverter

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());
}
Also used : Binding(org.eclipse.core.databinding.Binding) ObservableTreeItemLabelProvider(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItemLabelProvider) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Label(org.eclipse.swt.widgets.Label) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) ProjectViewerComparator(org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator) IProject(com.openshift.restclient.model.IProject) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) IValidator(org.eclipse.core.databinding.validation.IValidator) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter) Button(org.eclipse.swt.widgets.Button) OpenShiftExplorerLabelProvider(org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue)

Example 2 with Model2ObservableTreeItemConverter

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;
}
Also used : IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) TabItem(org.eclipse.swt.widgets.TabItem) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) Composite(org.eclipse.swt.widgets.Composite) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) Text(org.eclipse.swt.widgets.Text) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue)

Example 3 with Model2ObservableTreeItemConverter

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;
}
Also used : SashForm(org.eclipse.swt.custom.SashForm) SelectProjectComponentBuilder(org.jboss.tools.openshift.internal.common.ui.SelectProjectComponentBuilder) CoreException(org.eclipse.core.runtime.CoreException) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) BooleanUtils(org.apache.commons.lang.BooleanUtils) ValidationStatus(org.eclipse.core.databinding.validation.ValidationStatus) OpenShiftIdentifierValidator(org.jboss.tools.openshift.internal.ui.validator.OpenShiftIdentifierValidator) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) DialogAdvancedPart(org.jboss.tools.openshift.internal.common.ui.utils.DialogAdvancedPart) BrowserUtility(org.jboss.tools.foundation.ui.util.BrowserUtility) Status(org.eclipse.core.runtime.Status) ValidationStatusProvider(org.eclipse.core.databinding.ValidationStatusProvider) ProjectViewerComparator(org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) ICompletable(org.jboss.ide.eclipse.as.ui.editor.DeploymentTypeUIUtil.ICompletable) OCBinary(org.jboss.tools.openshift.internal.core.preferences.OCBinary) Path(org.eclipse.core.runtime.Path) SWT(org.eclipse.swt.SWT) SelectExistingProjectDialog(org.jboss.tools.openshift.internal.common.ui.SelectExistingProjectDialog) SelectionListener(org.eclipse.swt.events.SelectionListener) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ImportApplicationWizard(org.jboss.tools.openshift.internal.ui.wizard.importapp.ImportApplicationWizard) IListProperty(org.eclipse.core.databinding.property.list.IListProperty) Converter(org.eclipse.core.databinding.conversion.Converter) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) NumericValidator(org.jboss.tools.openshift.internal.common.ui.databinding.NumericValidator) IBuildConfig(com.openshift.restclient.model.IBuildConfig) IWizard(org.eclipse.jface.wizard.IWizard) ProjectUtils(org.jboss.tools.openshift.common.core.utils.ProjectUtils) IValidator(org.eclipse.core.databinding.validation.IValidator) JFaceResources(org.eclipse.jface.resource.JFaceResources) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) IContainer(org.eclipse.core.resources.IContainer) WidgetProperties(org.eclipse.jface.databinding.swt.WidgetProperties) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) OpenShiftCommonUIMessages(org.jboss.tools.openshift.internal.common.ui.OpenShiftCommonUIMessages) IProject(org.eclipse.core.resources.IProject) VariablesHelper(org.jboss.tools.openshift.common.core.utils.VariablesHelper) Link(org.eclipse.swt.widgets.Link) RsyncStatus(org.jboss.tools.openshift.internal.core.util.RSyncValidator.RsyncStatus) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Shell(org.eclipse.swt.widgets.Shell) IResource(com.openshift.restclient.model.IResource) MultiListProperty(org.eclipse.core.databinding.property.list.MultiListProperty) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) IServer(org.eclipse.wst.server.core.IServer) OpenShiftServerUtils(org.jboss.tools.openshift.core.server.OpenShiftServerUtils) File(java.io.File) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) DOWNLOAD_INSTRUCTIONS_URL(org.jboss.tools.openshift.core.preferences.IOpenShiftCoreConstants.DOWNLOAD_INSTRUCTIONS_URL) Dialog(org.eclipse.jface.dialogs.Dialog) ModifyListener(org.eclipse.swt.events.ModifyListener) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) FormPresenterSupport(org.jboss.tools.openshift.internal.common.ui.databinding.FormPresenterSupport) StringUtils(org.jboss.tools.openshift.common.core.utils.StringUtils) RouteLabelProvider(org.jboss.tools.openshift.internal.ui.dialog.SelectRouteDialog.RouteLabelProvider) ControlDecorationSupport(org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) ValueBindingBuilder(org.jboss.tools.common.ui.databinding.ValueBindingBuilder) AbstractOpenShiftWizardPage(org.jboss.tools.openshift.internal.common.ui.wizard.AbstractOpenShiftWizardPage) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter) Button(org.eclipse.swt.widgets.Button) Collection(java.util.Collection) IViewerObservableValue(org.eclipse.jface.databinding.viewers.IViewerObservableValue) PreferencesUtil(org.eclipse.ui.dialogs.PreferencesUtil) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) Binding(org.eclipse.core.databinding.Binding) BeanProperties(org.eclipse.core.databinding.beans.BeanProperties) IRoute(com.openshift.restclient.model.route.IRoute) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) Label(org.eclipse.swt.widgets.Label) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) RSyncValidator(org.jboss.tools.openshift.internal.core.util.RSyncValidator) Image(org.eclipse.swt.graphics.Image) HashMap(java.util.HashMap) ISWTObservableValue(org.eclipse.jface.databinding.swt.ISWTObservableValue) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) ComboViewer(org.eclipse.jface.viewers.ComboViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) DataBindingUtils(org.jboss.tools.openshift.internal.common.ui.utils.DataBindingUtils) OPEN_SHIFT_PREFERENCE_PAGE_ID(org.jboss.tools.openshift.core.preferences.IOpenShiftCoreConstants.OPEN_SHIFT_PREFERENCE_PAGE_ID) UIUtils(org.jboss.tools.openshift.internal.common.ui.utils.UIUtils) ObservableListTreeContentProvider(org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider) InvertingBooleanConverter(org.jboss.tools.common.ui.databinding.InvertingBooleanConverter) FillLayout(org.eclipse.swt.layout.FillLayout) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Viewer(org.eclipse.jface.viewers.Viewer) Job(org.eclipse.core.runtime.jobs.Job) IFormPresenter(org.jboss.tools.openshift.internal.common.ui.databinding.FormPresenterSupport.IFormPresenter) ViewerProperties(org.eclipse.jface.databinding.viewers.ViewerProperties) Group(org.eclipse.swt.widgets.Group) Connection(org.jboss.tools.openshift.core.connection.Connection) WritableValue(org.eclipse.core.databinding.observable.value.WritableValue) WizardUtils(org.jboss.tools.common.ui.WizardUtils) DisableableMultiValitdator(org.jboss.tools.openshift.internal.common.ui.databinding.DisableableMultiValitdator) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OpenShiftCoreException(org.jboss.tools.openshift.common.core.OpenShiftCoreException) OpenShiftUIMessages(org.jboss.tools.openshift.internal.ui.OpenShiftUIMessages) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IListChangeListener(org.eclipse.core.databinding.observable.list.IListChangeListener) Collections(java.util.Collections) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) Text(org.eclipse.swt.widgets.Text) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) IViewerObservableValue(org.eclipse.jface.databinding.viewers.IViewerObservableValue) IResource(com.openshift.restclient.model.IResource)

Aggregations

IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)3 Model2ObservableTreeItemConverter (org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter)3 ObservableTreeItem2ModelConverter (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter)3 Binding (org.eclipse.core.databinding.Binding)2 IValidator (org.eclipse.core.databinding.validation.IValidator)2 Composite (org.eclipse.swt.widgets.Composite)2 Text (org.eclipse.swt.widgets.Text)2 IBuildConfig (com.openshift.restclient.model.IBuildConfig)1 IProject (com.openshift.restclient.model.IProject)1 IResource (com.openshift.restclient.model.IResource)1 IRoute (com.openshift.restclient.model.route.IRoute)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BooleanUtils (org.apache.commons.lang.BooleanUtils)1 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)1 ValidationStatusProvider (org.eclipse.core.databinding.ValidationStatusProvider)1