Search in sources :

Example 6 with Pair

use of eu.esdihumboldt.util.Pair in project hale by halestudio.

the class InstanceValueLabelProvider method update.

/**
 * @see CellLabelProvider#update(ViewerCell)
 */
@Override
public void update(ViewerCell cell) {
    TreePath treePath = cell.getViewerRow().getTreePath();
    Object element = treePath.getLastSegment();
    Definition<?> definition = null;
    Object value = ((Pair<?, ?>) element).getSecond();
    if (((Pair<?, ?>) element).getFirst() instanceof Definition)
        definition = (Definition<?>) ((Pair<?, ?>) element).getFirst();
    InstanceValidationReport report = null;
    if (definition instanceof ChildDefinition<?>) {
        report = validator.validate(value, (ChildDefinition<?>) ((Pair<?, ?>) element).getFirst());
    } else if (definition instanceof TypeDefinition) {
        report = validator.validate((Instance) value);
    }
    boolean hasValue = false;
    if (value instanceof Instance) {
        hasValue = ((Instance) value).getValue() != null;
    }
    StyledString styledString;
    if (value == null) {
        styledString = new StyledString("no value", StyledString.DECORATIONS_STYLER);
    } else if (value instanceof Group && !hasValue) {
        styledString = new StyledString("+", StyledString.QUALIFIER_STYLER);
    } else {
        if (value instanceof Instance) {
            value = ((Instance) value).getValue();
        }
        // TODO some kind of conversion?
        String stringValue = value.toString();
        /*
			 * Values that are very large, e.g. string representations of very
			 * complex geometries lead to
			 * StyledCellLabelProvider.updateTextLayout taking a very long time,
			 * rendering the application unresponsive when the data views are
			 * displayed. As such, we reduce the string to a maximum size.
			 */
        if (stringValue.length() > MAX_STRING_LENGTH) {
            stringValue = stringValue.substring(0, MAX_STRING_LENGTH) + "...";
        }
        styledString = new StyledString(stringValue, null);
    }
    cell.setText(styledString.toString());
    cell.setStyleRanges(styledString.getStyleRanges());
    if (report != null && !report.getWarnings().isEmpty()) {
        cell.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
    }
    super.update(cell);
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) InstanceValidationReport(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport) TreePath(org.eclipse.jface.viewers.TreePath) Pair(eu.esdihumboldt.util.Pair)

Example 7 with Pair

use of eu.esdihumboldt.util.Pair in project hale by halestudio.

the class InstanceValueLabelProvider method getToolTipText.

/**
 * @see org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object)
 */
@Override
public String getToolTipText(Object element) {
    InstanceValidationReport report;
    Object value = ((Pair<?, ?>) element).getSecond();
    Definition<?> definition = null;
    if (((Pair<?, ?>) element).getFirst() instanceof Definition)
        definition = (Definition<?>) ((Pair<?, ?>) element).getFirst();
    if (definition instanceof ChildDefinition<?>) {
        report = validator.validate(value, (ChildDefinition<?>) ((Pair<?, ?>) element).getFirst());
    } else if (definition instanceof TypeDefinition) {
        report = validator.validate((Instance) value);
    } else {
        return null;
    }
    Collection<InstanceValidationMessage> warnings = report.getWarnings();
    if (warnings.isEmpty())
        return null;
    StringBuilder toolTip = new StringBuilder();
    for (Message m : warnings) {
        toolTip.append(m.getFormattedMessage()).append('\n');
    }
    return toolTip.substring(0, toolTip.length() - 1);
}
Also used : InstanceValidationReport(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport) Message(eu.esdihumboldt.hale.common.core.report.Message) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) InstanceValidationMessage(eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage) Pair(eu.esdihumboldt.util.Pair) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 8 with Pair

use of eu.esdihumboldt.util.Pair in project hale by halestudio.

the class GenericParameterPage method createAddButton.

/**
 * Create add and remove buttons for the given function parameter in the
 * given composite with the given initial visibility.
 *
 * @param parent the composite
 * @param fp the function parameter
 * @param addEnabled whether the add button is enabled in the beginning
 */
private void createAddButton(final Composite parent, final FunctionParameterDefinition fp, boolean addEnabled) {
    // create add button -> left
    final Button addButton = new Button(parent, SWT.PUSH);
    addButtons.put(fp, addButton);
    addButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false, 2, 1));
    addButton.setText("Add parameter value");
    addButton.setEnabled(addEnabled);
    // create selection listeners
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // add text field
            List<Pair<AttributeEditor<?>, Button>> texts = inputFields.get(fp);
            boolean removeButtonsDisabled = texts.size() == fp.getMinOccurrence();
            Pair<AttributeEditor<?>, Button> added = createField(addButton.getParent(), fp, null, false);
            added.getFirst().getControl().moveAbove(addButton);
            added.getSecond().moveAbove(addButton);
            // update add button
            if (texts.size() == fp.getMaxOccurrence())
                addButton.setEnabled(false);
            // need to enable all remove buttons or only the new one?
            if (removeButtonsDisabled)
                for (Pair<AttributeEditor<?>, Button> pair : texts) pair.getSecond().setEnabled(true);
            else
                added.getSecond().setEnabled(true);
            // update state, could change to invalid because of new field
            updateState();
            // relayout
            layoutAndPack();
        }
    });
}
Also used : Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AttributeEditor(eu.esdihumboldt.hale.ui.common.AttributeEditor) List(java.util.List) Pair(eu.esdihumboldt.util.Pair)

Example 9 with Pair

use of eu.esdihumboldt.util.Pair in project hale by halestudio.

the class GenericParameterPage method createContent.

/**
 * @see HaleWizardPage#createContent(Composite)
 */
@Override
protected void createContent(Composite page) {
    page.setLayout(GridLayoutFactory.swtDefaults().create());
    // create section for each function parameter
    for (final FunctionParameterDefinition fp : params) {
        boolean fixed = fp.getMinOccurrence() == fp.getMaxOccurrence();
        boolean unbounded = fp.getMaxOccurrence() == AbstractParameter.UNBOUNDED;
        Group group = new Group(page, SWT.NONE);
        group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
        group.setText(fp.getDisplayName());
        // only one column if the amount is fixed (-> no remove buttons)
        group.setLayout(GridLayoutFactory.swtDefaults().numColumns(fixed ? 1 : 2).create());
        if (fp.getDescription() != null) {
            Label description = new Label(group, SWT.WRAP);
            description.setText(fp.getDescription());
            description.setLayoutData(GridDataFactory.swtDefaults().span(fixed ? 1 : 2, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).hint(250, SWT.DEFAULT).create());
        }
        // walk over data of initial cell while creating input fields
        List<ParameterValue> initialData = initialValues.get(fp.getName());
        Iterator<ParameterValue> initialDataIter = initialData.iterator();
        // create a minimum number of input fields
        int i;
        for (i = 0; i < fp.getMinOccurrence(); i++) if (initialDataIter.hasNext())
            createField(group, fp, initialDataIter.next(), fixed);
        else
            createField(group, fp, null, fixed);
        // create further fields if initial cell has more
        for (; initialDataIter.hasNext() && (unbounded || i < fp.getMaxOccurrence()); i++) createField(group, fp, initialDataIter.next(), false);
        // create control buttons if max occurrence != min occurrence
        if (!fixed)
            createAddButton(group, fp, unbounded || i < fp.getMaxOccurrence());
        // required
        if (i > fp.getMinOccurrence())
            for (Pair<AttributeEditor<?>, Button> pair : inputFields.get(fp)) pair.getSecond().setEnabled(true);
    }
    // update state now that all texts (with validators) are generated
    updateState();
}
Also used : Group(org.eclipse.swt.widgets.Group) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Point(org.eclipse.swt.graphics.Point) Pair(eu.esdihumboldt.util.Pair)

Example 10 with Pair

use of eu.esdihumboldt.util.Pair in project hale by halestudio.

the class NewRelationPage method createViewer.

/**
 * @see ViewerWizardSelectionPage#createViewer(Composite)
 */
@Override
protected Pair<StructuredViewer, Control> createViewer(Composite parent) {
    PatternFilter filter = new PatternFilter();
    filter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new FilteredTree(parent, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
    viewer = tree.getViewer();
    viewer.setContentProvider(new FunctionWizardNodeContentProvider(getContainer(), initialSelection, selectionMatcher));
    viewer.setLabelProvider(new FunctionWizardNodeLabelProvider());
    // no input needed, but we have to set something
    viewer.setInput(Boolean.TRUE);
    // set focus on viewer control to prevent odd behavior
    viewer.getControl().setFocus();
    // expand selection
    viewer.expandAll();
    // selection context
    contextProvider = new HALEContextProvider(viewer, null);
    // help update on page shown
    if (getContainer() instanceof IPageChangeProvider) {
        ((IPageChangeProvider) getContainer()).addPageChangedListener(changeListener = new IPageChangedListener() {

            @Override
            public void pageChanged(PageChangedEvent event) {
                if (event.getSelectedPage() == NewRelationPage.this) {
                    // update the help button
                    if (getContainer() instanceof HaleWizardDialog) {
                        ((HaleWizardDialog) getContainer()).setHelpButtonEnabled(getHelpContext() != null);
                    }
                }
            }
        });
    }
    // help update on selection change
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IContext context = getHelpContext();
            // update the help button
            if (getContainer() instanceof HaleWizardDialog) {
                ((HaleWizardDialog) getContainer()).setHelpButtonEnabled(context != null);
            }
            // update the help
            if (context != null) {
                TrayDialog trayDialog = (TrayDialog) getContainer();
                if (trayDialog.getTray() != null) {
                    // if the tray is already open, update the help
                    performHelp();
                }
            }
        }
    });
    // load page configuration
    // XXX would be better if called from outside
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    restore(ps.getConfigurationService());
    return new Pair<StructuredViewer, Control>(viewer, tree);
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) IContext(org.eclipse.help.IContext) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IPageChangeProvider(org.eclipse.jface.dialogs.IPageChangeProvider) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) PageChangedEvent(org.eclipse.jface.dialogs.PageChangedEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TrayDialog(org.eclipse.jface.dialogs.TrayDialog) HALEContextProvider(eu.esdihumboldt.hale.ui.HALEContextProvider) IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog) Pair(eu.esdihumboldt.util.Pair)

Aggregations

Pair (eu.esdihumboldt.util.Pair)33 ArrayList (java.util.ArrayList)11 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)8 List (java.util.List)7 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)6 Cell (eu.esdihumboldt.hale.common.align.model.Cell)4 Entity (eu.esdihumboldt.hale.common.align.model.Entity)4 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)4 Group (eu.esdihumboldt.hale.common.instance.model.Group)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 Point (org.eclipse.swt.graphics.Point)4 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)3 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)3 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)3 GroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition)3 IOException (java.io.IOException)3 URI (java.net.URI)3 Collection (java.util.Collection)3 QName (javax.xml.namespace.QName)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3