Search in sources :

Example 1 with ClassificationLink

use of name.abuchen.portfolio.ui.wizards.security.EditSecurityModel.ClassificationLink in project portfolio by buchen.

the class SecurityTaxonomyPage method createTaxonomySection.

private void createTaxonomySection(final Composite taxonomyPicker, final TaxonomyDesignation designation) {
    // label
    Label label = new Label(taxonomyPicker, SWT.NONE);
    label.setFont(boldFont);
    label.setText(designation.getTaxonomy().getName());
    boolean isFirst = designation.equals(model.getDesignations().get(0));
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).align(SWT.BEGINNING, SWT.CENTER).indent(0, isFirst ? 0 : 20).applyTo(label);
    // drop-down selection block
    addBlock(taxonomyPicker, designation);
    // add button
    Link link = new Link(taxonomyPicker, SWT.UNDERLINE_LINK);
    link.setText(Messages.EditWizardMasterDataLinkNewCategory);
    GridDataFactory.fillDefaults().span(2, 1).indent(0, 5).align(SWT.BEGINNING, SWT.CENTER).applyTo(link);
    link.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ClassificationLink link = new ClassificationLink();
            link.setWeight(designation.getLinks().isEmpty() ? Classification.ONE_HUNDRED_PERCENT : 0);
            designation.getLinks().add(link);
            recreateTaxonomyPicker(taxonomyPicker);
        }
    });
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ClassificationLink(name.abuchen.portfolio.ui.wizards.security.EditSecurityModel.ClassificationLink) Link(org.eclipse.swt.widgets.Link) ClassificationLink(name.abuchen.portfolio.ui.wizards.security.EditSecurityModel.ClassificationLink)

Example 2 with ClassificationLink

use of name.abuchen.portfolio.ui.wizards.security.EditSecurityModel.ClassificationLink in project portfolio by buchen.

the class SecurityTaxonomyPage method addBlock.

private void addBlock(final Composite taxonomyPicker, final TaxonomyDesignation designation) {
    Label sumOfWeights = null;
    final List<IObservableValue> weightObservables = new ArrayList<IObservableValue>();
    final List<IObservableValue> classificationObservables = new ArrayList<IObservableValue>();
    if (designation.getLinks().size() == 1 && designation.getLinks().get(0).getWeight() == Classification.ONE_HUNDRED_PERCENT) {
        addSimpleBlock(taxonomyPicker, designation, designation.getLinks().get(0), classificationObservables);
    } else if (!designation.getLinks().isEmpty()) {
        for (ClassificationLink link : designation.getLinks()) addFullBlock(taxonomyPicker, designation, link, weightObservables, classificationObservables);
        // add summary
        sumOfWeights = new Label(taxonomyPicker, SWT.NONE);
        // $NON-NLS-1$
        sumOfWeights.setText("");
        GridDataFactory.fillDefaults().span(2, 1).indent(0, 5).align(SWT.BEGINNING, SWT.CENTER).applyTo(sumOfWeights);
    }
    setupWeightMultiValidator(sumOfWeights, designation, weightObservables);
    setupClassificationMultiValidator(designation, classificationObservables);
}
Also used : Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) ClassificationLink(name.abuchen.portfolio.ui.wizards.security.EditSecurityModel.ClassificationLink) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue)

Example 3 with ClassificationLink

use of name.abuchen.portfolio.ui.wizards.security.EditSecurityModel.ClassificationLink in project portfolio by buchen.

the class SecurityTaxonomyPage method setupWeightMultiValidator.

private void setupWeightMultiValidator(Label sumOfWeights, TaxonomyDesignation designation, final List<IObservableValue> weightObservables) {
    MultiValidator multiValidator = new WeightsAreGreaterThan100Validator(sumOfWeights, designation.getTaxonomy(), weightObservables);
    bindings.getBindingContext().addValidationStatusProvider(multiValidator);
    validators.add(multiValidator);
    for (int ii = 0; ii < weightObservables.size(); ii++) {
        IObservableValue observable = weightObservables.get(ii);
        ClassificationLink link = designation.getLinks().get(ii);
        UpdateValueStrategy strategy = new UpdateValueStrategy();
        strategy.setAfterConvertValidator(new GreaterThanZeroValidator());
        validators.add(bindings.getBindingContext().bindValue(multiValidator.observeValidatedValue(observable), BeanProperties.value("weight").observe(link), strategy, // $NON-NLS-1$
        null));
    }
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) ClassificationLink(name.abuchen.portfolio.ui.wizards.security.EditSecurityModel.ClassificationLink) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator)

Example 4 with ClassificationLink

use of name.abuchen.portfolio.ui.wizards.security.EditSecurityModel.ClassificationLink in project portfolio by buchen.

the class SecurityTaxonomyPage method setupClassificationMultiValidator.

private void setupClassificationMultiValidator(TaxonomyDesignation designation, final List<IObservableValue> classificationObservables) {
    MultiValidator multiValidator = new ClassificationNotTwiceValidator(classificationObservables);
    bindings.getBindingContext().addValidationStatusProvider(multiValidator);
    validators.add(multiValidator);
    for (int ii = 0; ii < classificationObservables.size(); ii++) {
        IObservableValue observable = classificationObservables.get(ii);
        ClassificationLink link = designation.getLinks().get(ii);
        UpdateValueStrategy strategy = new UpdateValueStrategy();
        strategy.setAfterConvertValidator(new NotNullValidator());
        validators.add(bindings.getBindingContext().bindValue(multiValidator.observeValidatedValue(observable), BeanProperties.value("classification").observe(link), strategy, // $NON-NLS-1$
        null));
    }
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) ClassificationLink(name.abuchen.portfolio.ui.wizards.security.EditSecurityModel.ClassificationLink) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator)

Aggregations

ClassificationLink (name.abuchen.portfolio.ui.wizards.security.EditSecurityModel.ClassificationLink)4 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)3 UpdateValueStrategy (org.eclipse.core.databinding.UpdateValueStrategy)2 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)2 Label (org.eclipse.swt.widgets.Label)2 ArrayList (java.util.ArrayList)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Link (org.eclipse.swt.widgets.Link)1