Search in sources :

Example 1 with TabFolderSelectionProperty

use of org.jboss.tools.openshift.internal.common.ui.databinding.TabFolderSelectionProperty 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));
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) SelectionListener(org.eclipse.swt.events.SelectionListener) IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) KeyListener(org.eclipse.swt.events.KeyListener) TabFolder(org.eclipse.swt.widgets.TabFolder) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) SashForm(org.eclipse.swt.custom.SashForm) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) KeyEvent(org.eclipse.swt.events.KeyEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) PageChangingEvent(org.eclipse.jface.dialogs.PageChangingEvent) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Converter(org.eclipse.core.databinding.conversion.Converter) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) TabFolderSelectionProperty(org.jboss.tools.openshift.internal.common.ui.databinding.TabFolderSelectionProperty)

Aggregations

Converter (org.eclipse.core.databinding.conversion.Converter)1 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)1 IValueChangeListener (org.eclipse.core.databinding.observable.value.IValueChangeListener)1 ValueChangeEvent (org.eclipse.core.databinding.observable.value.ValueChangeEvent)1 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)1 IStatus (org.eclipse.core.runtime.IStatus)1 PageChangingEvent (org.eclipse.jface.dialogs.PageChangingEvent)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 SashForm (org.eclipse.swt.custom.SashForm)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 KeyListener (org.eclipse.swt.events.KeyListener)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 Event (org.eclipse.swt.widgets.Event)1 Listener (org.eclipse.swt.widgets.Listener)1 TabFolder (org.eclipse.swt.widgets.TabFolder)1 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)1