List of usage examples for org.eclipse.jface.databinding.swt SWTObservables observeEnabled
@Deprecated public static ISWTObservableValue observeEnabled(Control control)
From source file:org.kalypso.ui.addlayer.internal.wms.CapabilitiesComposite.java
License:Open Source License
private void createOpenCapabilitiesControls() { /* placeholder */ new Label(this, SWT.NONE); /* Open capabilities in external browser */ final Action openCapabilitiesAction = new OpenCapabilitiesAction(m_data); final ImageHyperlink link = ActionHyperlink.createHyperlink(null, this, getStyle(), openCapabilitiesAction); link.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); /* Binding */ final ISWTObservableValue targetEnablement = SWTObservables.observeEnabled(link); final IObservableValue modelEnablement = BeansObservables.observeValue(m_data, ICapabilitiesData.PROPERTY_VALID_ADDRESS); m_binding.bindValue(targetEnablement, modelEnablement); }
From source file:org.kalypso.ui.addlayer.internal.wms.ImportWmsWizardPage.java
License:Open Source License
private void createMultiLayerControl(final Composite parent) { final Button checkbox = new Button(parent, SWT.CHECK); checkbox.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1)); checkbox.setText(Messages.getString("org.kalypso.ui.wizard.wms.pages.ImportWmsWizardPage.10")); //$NON-NLS-1$ checkbox.setToolTipText(Messages.getString("org.kalypso.ui.wizard.wms.pages.ImportWmsWizardPage.11")); //$NON-NLS-1$ /**//from w w w . j av a 2s. c o m * BIDING */ final ISWTObservableValue targetEnablement = SWTObservables.observeEnabled(checkbox); final IObservableValue modelEnablement = BeansObservables.observeValue(m_data, ImportWmsData.PROPERTY_MULTI_LAYER_ENABLEMENT); m_binding.bindValue(targetEnablement, modelEnablement); final ISWTObservableValue targetValue = SWTObservables.observeSelection(checkbox); final IObservableValue modelValue = BeansObservables.observeValue(m_data, ImportWmsData.PROPERTY_MULTI_LAYER); m_binding.bindValue(targetValue, modelValue); }
From source file:org.kalypso.ui.wizard.shape.ImportShapeFileImportPage.java
License:Open Source License
private WorkspaceFileBinding createStyleFileControls(final Composite parent) { final Label styleLabel = new Label(parent, SWT.NONE); styleLabel.setText(Messages.getString("org.kalypso.ui.wizard.shape.ImportShapeFileImportPage.6")); //$NON-NLS-1$ final IObservableValue modelFile = BeansObservables.observeValue(m_data.getStyleFile(), FileAndHistoryData.PROPERTY_PATH); final IObservableValue modelHistory = BeansObservables.observeValue(m_data.getStyleFile(), FileAndHistoryData.PROPERTY_HISTORY); final String dialogMessage = Messages.getString("org.kalypso.ui.wizard.shape.ImportShapeFileImportPage.14"); //$NON-NLS-1$ final String[] extensions = new String[] { "sld" }; //$NON-NLS-1$ final WorkspaceFileBinding fileBinding = new WorkspaceFileBinding(m_binding, modelFile, dialogMessage, extensions);/*from w ww .j a v a 2s.c om*/ fileBinding.setInputContainer(m_project); final Control fileField = fileBinding.createFileFieldWithHistory(parent, modelHistory); fileField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); final Button searchButton = fileBinding.createFileSearchButton(parent); /* file is optional iff import type is 'existing' */ fileBinding.setIsOptional(m_data.getStyleImportType() != StyleImport.selectExisting); // final DataBindingContext bindingContext = m_binding.getBindingContext(); m_data.addPropertyChangeListener(ImportShapeFileData.PROPERTY_STYLE_IMPORT_TYPE, new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent evt) { final IObservableValue validationStatus = fileBinding.getFileBinding() .getValidationStatus(); fileBinding.setIsOptional(evt.getNewValue() != StyleImport.selectExisting); // If style file is currently bad, clear it now, else the error message remains final IStatus value = (IStatus) validationStatus.getValue(); if (value != null && !value.isOK() && evt.getNewValue() != StyleImport.selectExisting) modelFile.setValue(null); // we need to force revalidation here, but how...?! fileBinding.getFileBinding().validateTargetToModel(); } }); /* Enablement */ final IObservableValue modelEnablement = BeansObservables.observeValue(m_data, ImportShapeFileData.PROPERTY_STYLE_CONTROLS_ENABLED); final IObservableValue targetLabelEnablement = SWTObservables.observeEnabled(styleLabel); m_binding.bindValue(targetLabelEnablement, modelEnablement); final IObservableValue targetFieldEnablement = SWTObservables.observeEnabled(fileField); m_binding.bindValue(targetFieldEnablement, modelEnablement); final IObservableValue targetButtonEnablement = SWTObservables.observeEnabled(searchButton); m_binding.bindValue(targetButtonEnablement, modelEnablement); return fileBinding; }
From source file:org.kalypso.ui.wizard.shape.ImportShapeFileImportPage.java
License:Open Source License
private void createStyleNameControls(final Composite parent) { final Label styleNameLabel = new Label(parent, SWT.NONE); styleNameLabel.setText(Messages.getString("org.kalypso.ui.wizard.shape.ImportShapeFileImportPage.8")); //$NON-NLS-1$ final ComboViewer styleNameChooser = new ComboViewer(parent, SWT.DROP_DOWN | SWT.READ_ONLY); styleNameChooser.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); styleNameChooser.setContentProvider(new ArrayContentProvider()); styleNameChooser.setLabelProvider(new LabelProvider() { @Override//from w w w.java 2s . c o m public String getText(final Object element) { if (element instanceof UserStyle) { final UserStyle userStyle = (UserStyle) element; final String title = userStyle.getTitle(); if (StringUtils.isBlank(title)) return userStyle.getName(); return title; } return ObjectUtils.toString(element); } }); /* bind input */ final IObservableValue targetInput = ViewersObservables.observeInput(styleNameChooser); final IObservableValue modelInput = BeansObservables.observeValue(m_data, ImportShapeFileData.PROPERTY_STYLES); m_binding.bindValue(targetInput, modelInput); /* bind selection */ final IObservableValue targetSelection = ViewersObservables.observeSinglePostSelection(styleNameChooser); final IObservableValue modelSelection = BeansObservables.observeValue(m_data, ImportShapeFileData.PROPERTY_STYLE); m_binding.bindValue(targetSelection, modelSelection); /* Enablement */ final IObservableValue modelEnablement = BeansObservables.observeValue(m_data, ImportShapeFileData.PROPERTY_STYLE_NAME_CONTROL_ENABLED); final IObservableValue targetLabelEnablement = SWTObservables.observeEnabled(styleNameLabel); m_binding.bindValue(targetLabelEnablement, modelEnablement); final IObservableValue targetComboEnablement = SWTObservables.observeEnabled(styleNameChooser.getControl()); m_binding.bindValue(targetComboEnablement, modelEnablement); }
From source file:org.marketcetera.photon.internal.strategy.engine.ui.workbench.NewPropertyInputDialog.java
@Override protected void createButtonsForButtonBar(Composite parent) { super.createButtonsForButtonBar(parent); final AggregateValidationStatus agg = new AggregateValidationStatus(mDataBindingContext, AggregateValidationStatus.MAX_SEVERITY); mObservablesManager.addObservable(agg); mDataBindingContext.bindValue(SWTObservables.observeEnabled(getButton(IDialogConstants.OK_ID)), new ComputedValue() { @Override/*from w w w . j a v a 2 s . c o m*/ protected Object calculate() { return ((IStatus) agg.getValue()).isOK(); } }); }
From source file:org.marketcetera.photon.views.OrderTicketView.java
/** * Binds the UI to the model.//from w w w. j a v a 2 s .c o m */ protected void bindMessage() { final DataBindingContext dbc = getDataBindingContext(); final OrderTicketModel model = getModel(); final IOrderTicket ticket = getXSWTView(); /* * Side */ bindRequiredCombo(mSideComboViewer, model.getSide(), Messages.ORDER_TICKET_VIEW_SIDE__LABEL.getText()); enableForNewOrderOnly(mSideComboViewer.getControl()); /* * Quantity */ bindRequiredDecimal(ticket.getQuantityText(), model.getQuantity(), Messages.ORDER_TICKET_VIEW_QUANTITY__LABEL.getText()); /* * Symbol */ bindRequiredText(ticket.getSymbolText(), getModel().getSymbol(), Messages.ORDER_TICKET_VIEW_SYMBOL__LABEL.getText()); enableForNewOrderOnly(ticket.getSymbolText()); /* * Order Type */ bindRequiredCombo(mOrderTypeComboViewer, model.getOrderType(), Messages.ORDER_TICKET_VIEW_ORDER_TYPE__LABEL.getText()); /* * Price * * Need custom required field logic since price is only required for * limit orders. */ { Binding binding = bindDecimal(ticket.getPriceText(), model.getPrice(), Messages.ORDER_TICKET_VIEW_PRICE__LABEL.getText()); /* * RequiredFieldSupport reports an error if the value is null or * empty string. We want this behavior when the order is a limit * order, but not when it is a market order (since empty string is * correct as the price is uneditable. So we decorate the observable * and pass the decorated one to RequiredFieldsupport. */ IObservableValue priceDecorator = new DecoratingObservableValue((IObservableValue) binding.getTarget(), false) { @Override public Object getValue() { Object actualValue = super.getValue(); if ("".equals(actualValue) //$NON-NLS-1$ && !model.isLimitOrder().getTypedValue()) { /* * Return an object to "trick" RequiredFieldSupport to * not error. */ return new Object(); } return actualValue; } }; RequiredFieldSupport.initFor(dbc, priceDecorator, Messages.ORDER_TICKET_VIEW_PRICE__LABEL.getText(), false, SWT.BOTTOM | SWT.LEFT, binding); dbc.bindValue(SWTObservables.observeEnabled(ticket.getPriceText()), model.isLimitOrder()); } /* * Broker * * Custom binding logic required since the viewer list can dynamically * change. */ { IObservableValue target = ViewersObservables.observeSingleSelection(mAvailableBrokersViewer); /* * Bind the target (combo) to the model, but use POLICY_ON_REQUEST * for target-to-model binding since we don't want the model to * change simply because a broker went down. The target-to-model * updates are handled manually below. */ final Binding binding = dbc.bindValue(target, model.getBrokerId(), new UpdateValueStrategy(UpdateValueStrategy.POLICY_ON_REQUEST) .setConverter(new TypedConverter<Broker, BrokerID>(Broker.class, BrokerID.class) { @Override public BrokerID doConvert(Broker fromObject) { return fromObject.getId(); } }), new UpdateValueStrategy() .setConverter(new TypedConverter<BrokerID, Broker>(BrokerID.class, Broker.class) { @Override public Broker doConvert(BrokerID fromObject) { return BrokerManager.getCurrent().getBroker(fromObject); } })); /* * If the target changes and the new value is not null, then this * was a user selection and the model should be updated. */ target.addValueChangeListener(new IValueChangeListener() { @Override public void handleValueChange(ValueChangeEvent event) { if (event.diff.getNewValue() != null) { binding.updateTargetToModel(); } } }); /* * When the broker list changes, we force a model-to-target update * to ensure the two are in sync if possible. */ final IListChangeListener listener = new IListChangeListener() { @Override public void handleListChange(ListChangeEvent event) { binding.updateModelToTarget(); } }; BrokerManager.getCurrent().getAvailableBrokers().addListChangeListener(listener); /* * Need to remove the listener when the widget is disposed. */ mAvailableBrokersViewer.getControl().addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { BrokerManager.getCurrent().getAvailableBrokers().removeListChangeListener(listener); } }); /* * If the model has a broker id, but the target doesn't have a * corresponding entry, the target will be null which needs to * generate an error. */ setRequired(binding, Messages.ORDER_TICKET_VIEW_BROKER__LABEL.getText()); } enableForNewOrderOnly(mAvailableBrokersViewer.getControl()); /* * Time in Force */ bindCombo(mTimeInForceComboViewer, model.getTimeInForce()); /* * Account */ bindText(getXSWTView().getAccountText(), model.getAccount()); }
From source file:org.marketcetera.photon.views.OrderTicketView.java
/** * Initialization the validation (error message area) of the view. *//* ww w . j av a 2 s . c o m*/ protected void initValidation() { DataBindingContext dbc = getDataBindingContext(); AggregateValidationStatus aggregateValidationStatus = new AggregateValidationStatus(dbc, AggregateValidationStatus.MAX_SEVERITY); dbc.bindValue(SWTObservables.observeText(getXSWTView().getErrorMessageLabel()), aggregateValidationStatus); dbc.bindValue(SWTObservables.observeImage(getXSWTView().getErrorIconLabel()), aggregateValidationStatus, null, new UpdateValueStrategy().setConverter(new StatusToImageConverter())); dbc.bindValue(SWTObservables.observeEnabled(getXSWTView().getSendButton()), aggregateValidationStatus, null, new UpdateValueStrategy() .setConverter(new TypedConverter<IStatus, Boolean>(IStatus.class, Boolean.class) { @Override public Boolean doConvert(IStatus fromObject) { return fromObject.getSeverity() < IStatus.ERROR; } })); }
From source file:org.marketcetera.photon.views.OrderTicketView.java
/** * Configures a control to be enabled only when model contains a new order * (as opposed to a replace order).//from w w w . java 2 s . c o m * * @param control * the control */ protected void enableForNewOrderOnly(Control control) { getDataBindingContext().bindValue(SWTObservables.observeEnabled(control), getModel().getOrderObservable(), null, new UpdateValueStrategy().setConverter(new Converter(NewOrReplaceOrder.class, Boolean.class) { @Override public Object convert(Object fromObject) { return fromObject instanceof OrderSingle; } })); }
From source file:org.nabucco.framework.exporting.ui.rcp.wizard.ExportWizardPage.java
License:Open Source License
/** * Add the selection and deselection buttons to the composite. * //from w w w .j a v a2 s.c o m * @param parent * the parent composite * @param viewer * the checkbox tree viewer */ private Composite layoutSelectionButtons(Composite parent, CheckboxTreeViewer viewer) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(2, false)); GridData data = new GridData(GridData.GRAB_HORIZONTAL); data.grabExcessHorizontalSpace = true; composite.setLayoutData(data); Font parentFont = parent.getFont(); composite.setFont(parentFont); IObservableValue uiElement; IObservableValue modelElement; DataBindingContext bindingContext = new DataBindingContext(); Button selectAllButton = this.createButton(composite, IDialogConstants.SELECT_ALL_ID, I18N.i18n(BUTTON_SELECT)); uiElement = SWTObservables.observeEnabled(selectAllButton); modelElement = BeansObservables.observeValue(this.model, ExportWizardModel.PROPERTY_EXPORTSEPERATE); bindingContext.bindValue(uiElement, modelElement); selectAllButton.addSelectionListener(new ExportSelectionListener(viewer, true)); selectAllButton.setFont(parentFont); Button deselectAllButton = createButton(composite, IDialogConstants.DESELECT_ALL_ID, I18N.i18n(BUTTON_DESELECT)); uiElement = SWTObservables.observeEnabled(deselectAllButton); modelElement = BeansObservables.observeValue(this.model, ExportWizardModel.PROPERTY_EXPORTSEPERATE); bindingContext.bindValue(uiElement, modelElement); deselectAllButton.addSelectionListener(new ExportSelectionListener(viewer, false)); deselectAllButton.setFont(parentFont); return composite; }
From source file:org.nabucco.framework.importing.ui.rcp.wizard.ImportWizardPage.java
License:Open Source License
/** * Add the selection and deselection buttons to the composite. * //from w w w .ja va2 s . c om * @param parent * the parent composite * @param viewer * the checkbox tree viewer */ private Composite layoutSelectionButtons(Composite parent, CheckboxTreeViewer viewer) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(2, false)); GridData data = new GridData(GridData.GRAB_HORIZONTAL); data.grabExcessHorizontalSpace = true; composite.setLayoutData(data); Font parentFont = parent.getFont(); composite.setFont(parentFont); IObservableValue uiElement; IObservableValue modelElement; DataBindingContext bindingContext = new DataBindingContext(); Button selectAllButton = this.createButton(composite, IDialogConstants.SELECT_ALL_ID, I18N.i18n(BUTTON_SELECT)); uiElement = SWTObservables.observeEnabled(selectAllButton); modelElement = BeansObservables.observeValue(this.model, ImportWizardModel.PROPERTY_EXPORTSEPERATE); bindingContext.bindValue(uiElement, modelElement); selectAllButton.addSelectionListener(new ImportSelectionListener(viewer, true)); selectAllButton.setFont(parentFont); Button deselectAllButton = createButton(composite, IDialogConstants.DESELECT_ALL_ID, I18N.i18n(BUTTON_DESELECT)); uiElement = SWTObservables.observeEnabled(deselectAllButton); modelElement = BeansObservables.observeValue(this.model, ImportWizardModel.PROPERTY_EXPORTSEPERATE); bindingContext.bindValue(uiElement, modelElement); deselectAllButton.addSelectionListener(new ImportSelectionListener(viewer, false)); deselectAllButton.setFont(parentFont); return composite; }