Search in sources :

Example 1 with RouteLabelProvider

use of org.jboss.tools.openshift.internal.ui.dialog.SelectRouteDialog.RouteLabelProvider in project jbosstools-openshift by jbosstools.

the class ServerSettingsWizardPage method createRouteControls.

@SuppressWarnings("unchecked")
private void createRouteControls(Composite container, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
    Group routeGroup = new Group(container, SWT.NONE);
    routeGroup.setText("Route");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(routeGroup);
    GridLayoutFactory.fillDefaults().applyTo(routeGroup);
    // additional nesting required because of
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=478618
    Composite routeContainer = new Composite(routeGroup, SWT.None);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(routeContainer);
    GridLayoutFactory.fillDefaults().margins(10, 10).numColumns(2).applyTo(routeContainer);
    Button promptRouteButton = new Button(routeContainer, SWT.CHECK);
    promptRouteButton.setSelection(true);
    promptRouteButton.setText("Prompt for route when multiple routes available to show in browser");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(2, 1).applyTo(promptRouteButton);
    Label routeLabel = new Label(routeContainer, SWT.NONE);
    routeLabel.setText("Use Route: ");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(routeLabel);
    StructuredViewer routesViewer = new ComboViewer(routeContainer);
    GridDataFactory.fillDefaults().span(1, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(routesViewer.getControl());
    routesViewer.setContentProvider(new ObservableListContentProvider());
    routesViewer.setLabelProvider(new RouteLabelProvider());
    routesViewer.setInput(BeanProperties.list(ServerSettingsWizardPageModel.PROPERTY_ROUTES).observe(model));
    // routesViewer.setComparer(new IElementComparer() {
    // 
    // @Override
    // public boolean equals(Object object1, Object object2) {
    // if (object1 instanceof IRoute) {
    // if (!(object2 instanceof IRoute)) {
    // return false;
    // }
    // 
    // IRoute route1 = (IRoute) object1;
    // IRoute route2 = (IRoute) object2;
    // 
    // return Objects.equals(route1.getServiceName(), route2.getServiceName())
    // && Objects.equals(route1.getURL(), route2.getURL());
    // } else if (object2 instanceof IRoute) {
    // return false;
    // } else {
    // return Objects.equals(object1, object2);
    // }
    // }
    // 
    // @Override
    // public int hashCode(Object element) {
    // if (element instanceof IRoute) {
    // IRoute route = (IRoute) element;
    // return new HashCodeBuilder()
    // .append(route.getServiceName())
    // .append(route.getURL())
    // .toHashCode();
    // }
    // return element.hashCode();
    // }
    // });
    IObservableValue<IResource> selectedRouteObservable = ViewerProperties.singleSelection().observe(routesViewer);
    ValueBindingBuilder.bind(selectedRouteObservable).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_ROUTE).observe(model)).in(dbc);
    final IObservableValue<Boolean> isSelectDefaultRouteObservable = WidgetProperties.selection().observe(promptRouteButton);
    final IObservableValue<Boolean> selectDefaultRouteModelObservable = BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_SELECT_DEFAULT_ROUTE).observe(model);
    ValueBindingBuilder.bind(isSelectDefaultRouteObservable).converting(new InvertingBooleanConverter()).to(selectDefaultRouteModelObservable).converting(new InvertingBooleanConverter()).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(routesViewer.getControl())).notUpdating(selectDefaultRouteModelObservable).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(routeLabel)).notUpdating(selectDefaultRouteModelObservable).in(dbc);
    RouteValidator routeValidator = new RouteValidator(isSelectDefaultRouteObservable, selectedRouteObservable);
    dbc.addValidationStatusProvider(routeValidator);
    ControlDecorationSupport.create(routeValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
}
Also used : Group(org.eclipse.swt.widgets.Group) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) InvertingBooleanConverter(org.jboss.tools.common.ui.databinding.InvertingBooleanConverter) Label(org.eclipse.swt.widgets.Label) RouteLabelProvider(org.jboss.tools.openshift.internal.ui.dialog.SelectRouteDialog.RouteLabelProvider) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) Button(org.eclipse.swt.widgets.Button) ComboViewer(org.eclipse.jface.viewers.ComboViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) IResource(com.openshift.restclient.model.IResource)

Aggregations

IResource (com.openshift.restclient.model.IResource)1 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)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 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)1 InvertingBooleanConverter (org.jboss.tools.common.ui.databinding.InvertingBooleanConverter)1 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)1 RouteLabelProvider (org.jboss.tools.openshift.internal.ui.dialog.SelectRouteDialog.RouteLabelProvider)1