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));
}
Aggregations