Example usage for com.vaadin.ui AbstractSplitPanel getFirstComponent

List of usage examples for com.vaadin.ui AbstractSplitPanel getFirstComponent

Introduction

In this page you can find the example usage for com.vaadin.ui AbstractSplitPanel getFirstComponent.

Prototype

public Component getFirstComponent() 

Source Link

Document

Gets the first component of this split panel.

Usage

From source file:org.semanticsoft.vaaclipse.presentation.renderers.SashRenderer.java

License:Open Source License

public void generateSplitPanelStructure(MPartSashContainer sash) {
    VerticalLayout layout = (VerticalLayout) sash.getWidget();
    layout.removeAllComponents();//from   w  w w  .  j a  v a  2s.  com

    ComponentContainer sashWidget = null;

    @SuppressWarnings("unchecked")
    List<MPartSashContainerElement> renderableAndVisible = (List<MPartSashContainerElement>) filterRenderableAndVisibleElements(
            sash);

    if (renderableAndVisible.isEmpty()) {
        sashWidget = new VerticalLayout();
    } else if (renderableAndVisible.size() == 1) {
        sashWidget = new VerticalLayout();
        MPartSashContainerElement child = renderableAndVisible.get(0);
        sashWidget.addComponent((Component) child.getWidget());
    } else {
        sashWidget = sash.isHorizontal() ? new SashWidgetHorizontal() : new SashWidgetVertical();
        AbstractSplitPanel currentSashWidget = (AbstractSplitPanel) sashWidget;
        currentSashWidget.setLocked(sash.getTags().contains(Tags.NO_RESIZE));
        for (int i = 0; i < renderableAndVisible.size(); i++) {
            MPartSashContainerElement child = renderableAndVisible.get(i);

            if (currentSashWidget.getFirstComponent() == null) {
                currentSashWidget.setFirstComponent((Component) child.getWidget());
            } else {
                if (i == renderableAndVisible.size() - 1) {
                    currentSashWidget.setSecondComponent((Component) child.getWidget());
                } else {
                    AbstractSplitPanel newSashWidget = sash.isHorizontal() ? new SashWidgetHorizontal()
                            : new SashWidgetVertical();
                    newSashWidget.setLocked(sash.getTags().contains(Tags.NO_RESIZE));
                    newSashWidget.setFirstComponent((Component) child.getWidget());
                    currentSashWidget.setSecondComponent(newSashWidget);
                    currentSashWidget = newSashWidget;
                }
            }
        }
    }

    sashWidget.setSizeFull();
    layout.addComponent(sashWidget);

    setWeights(sash);
}

From source file:org.semanticsoft.vaaclipse.presentation.renderers.SashRenderer.java

License:Open Source License

void setWeights(MPartSashContainer sash) {
    @SuppressWarnings("unchecked")
    List<MPartSashContainerElement> renderableAndVisible = (List<MPartSashContainerElement>) filterRenderableAndVisibleElements(
            sash);//from w  ww . j av  a2s  .co m
    if (renderableAndVisible.size() < 2)
        return;

    Map<MPartSashContainerElement, Double> weights = new HashMap<MPartSashContainerElement, Double>();
    Map<Component, MPartSashContainerElement> map = new HashMap<Component, MPartSashContainerElement>();
    double total_weight = 0;
    for (MPartSashContainerElement children : renderableAndVisible) {
        String data = children.getContainerData();
        double weight = parseContainerData(data);

        map.put((Component) children.getWidget(), children);
        weights.put(children, weight);
        total_weight += weight;
    }

    if (total_weight == 0.0) //all child elements has zero weight
        total_weight = 1.0;

    AbstractSplitPanel topSashWidget = (AbstractSplitPanel) ((VerticalLayout) sash.getWidget()).getComponent(0);
    AbstractSplitPanel currentSashWidget = topSashWidget;
    while (true) {
        MPartSashContainerElement e1 = map.get(currentSashWidget.getFirstComponent());
        //the first - is always element
        double w = weights.get(e1);
        double pos = (w / total_weight) * 100;
        currentSashWidget.setSplitPosition((float) pos);

        if (map.containsKey(currentSashWidget.getSecondComponent()))
            break;

        currentSashWidget = (AbstractSplitPanel) currentSashWidget.getSecondComponent();
        total_weight = total_weight - w;
    }
}

From source file:org.semanticsoft.vaaclipse.presentation.renderers.SashRenderer.java

License:Open Source License

public void addSplitPaneListener(MUIElement element) {
    final MPartSashContainer sash = (MPartSashContainer) element;

    List<MPartSashContainerElement> renderableAndVisible = (List<MPartSashContainerElement>) filterRenderableAndVisibleElements(
            sash);/*from   w  w  w.j  ava 2  s .  co m*/

    if (renderableAndVisible.size() > 1) {
        for (MPartSashContainerElement child : renderableAndVisible) {
            Component childComponent = (Component) child.getWidget();
            if (childComponent.getParent() instanceof SashWidget) {
                SashWidget sashWidget = (SashWidget) childComponent.getParent();
                sashWidget.addListener(new SplitPositionChangedListener() {

                    @Override
                    public void processEvent(AbstractSplitPanel splitPanel, float newSplitPos) {
                        AbstractComponent firstWidget = (AbstractComponent) splitPanel.getFirstComponent();

                        //filter renderable and visible again (list can be changed)
                        List<MPartSashContainerElement> renderableAndVisible = (List<MPartSashContainerElement>) filterRenderableAndVisibleElements(
                                sash);
                        MPartSashContainerElement firstChild = null;
                        double rest_weight = 0;
                        List<MPartSashContainerElement> restChilds = new LinkedList<MPartSashContainerElement>();
                        for (int i = 0; i < renderableAndVisible.size(); i++) {
                            MPartSashContainerElement child = renderableAndVisible.get(i);
                            if (firstWidget.equals(child.getWidget())) {
                                firstChild = child;
                            }

                            if (firstChild != null) {
                                try {
                                    double w = parseContainerData(child.getContainerData());
                                    rest_weight += w;
                                } catch (NumberFormatException e) {
                                    logger.error(
                                            "Changing weights of SashContainer's childs is failed. Can not parse children container data");
                                    return;
                                }

                                restChilds.add(child);
                            }
                        }

                        if (restChilds.size() > 1) {
                            //String debugstr = "weights: ";
                            ignoreSashWeights = true;

                            double rest_weight_except_first = rest_weight
                                    - parseContainerData(firstChild.getContainerData());
                            double newW1 = (newSplitPos / 100) * rest_weight;
                            double new_rest_weight_except_first = rest_weight - newW1;
                            long longVal1 = Math.round(newW1);
                            firstChild.setContainerData(Long.toString(longVal1));
                            //debugstr += longVal1;

                            //if the weight of remainder (except first) is not zero, then we distribute the new space appropriate weights
                            if (rest_weight_except_first > 0.0) {
                                for (int i = 1; i < restChilds.size(); i++) {
                                    MPartSashContainerElement child = restChilds.get(i);
                                    double w = parseContainerData(child.getContainerData());
                                    double newW = (w / rest_weight_except_first) * new_rest_weight_except_first;
                                    long longVal = Math.round(newW);

                                    child.setContainerData(Long.toString(longVal));
                                    //debugstr += ", " + longVal;
                                }
                            } else //otherwise we assign all new space to the last component
                            {
                                MPartSashContainerElement rest1 = restChilds.get(restChilds.size() - 1);
                                rest1.setContainerData(Long.toString(Math.round(new_rest_weight_except_first)));
                            }

                            ignoreSashWeights = false;

                            //System.out.println(debugstr);

                            //ATTENTION! Really line below is not required if code above works correctly.
                            //But if there are any wrong behaviour appear then we have wrong synchronized state
                            //that may caused side effects, so we do back syncronization (and bug if it occur become obvious).
                            //This is also zeroed weight mismatch occuring when double rounded (and possible when vaadin process changes),
                            //so we avoid mismatch accumulating. 
                            //Most likely in the future this will be deleted (when this code will be proved that all ok).
                            setWeights(sash);
                        } else
                            logger.error(
                                    "Changing SashContainer child weights is failed. User changes is not processed correctly");

                        //and last thing what we must do - tell the WorkbenchWindow to recalculate bounds of it content
                        //(because bounds of some content of workbench window changed after sash widget split position changed)
                        MWindow window = modelService.getTopLevelWindowFor(sash);
                        TrimmedWindowContent windowContent = (TrimmedWindowContent) ((Panel) window.getWidget())
                                .getContent();
                        windowContent.invalidateBounds();
                    }
                });
            } else
                logger.error(
                        "Error in  widget hierarchy detected - if sash container has more than one element its child widget must has SashWidget as a parent");
        }
    }
}

From source file:org.semanticsoft.vaaclipse.widgets.WorkbenchWindow.java

License:Open Source License

private void updateBounds(ComponentContainer container, Bounds currentBounds) {
    if (container instanceof BoundsinfoVerticalLayout) {
        BoundsinfoVerticalLayout bvl = (BoundsinfoVerticalLayout) container;
        bvl.setBounds(currentBounds);/*from  ww  w .java 2s  .c om*/
    } else if (container instanceof StackWidget) {
        StackWidget bvl = (StackWidget) container;
        bvl.setBounds(currentBounds);
    }

    if (container instanceof SashWidget) {
        AbstractSplitPanel splitPanel = (AbstractSplitPanel) container;
        float splitPos = splitPanel.getSplitPosition() / 100;
        if (splitPanel instanceof HorizontalSplitPanel) {
            int firstBoundsWidth = (int) (splitPos * currentBounds.w);
            if (splitPanel.getFirstComponent() instanceof ComponentContainer) {
                Bounds leftBounds = new Bounds(currentBounds.x, currentBounds.y, firstBoundsWidth,
                        currentBounds.h);
                updateBounds((ComponentContainer) splitPanel.getFirstComponent(), leftBounds);
            }

            if (splitPanel.getSecondComponent() instanceof ComponentContainer) {
                Bounds rightBounds = new Bounds(currentBounds.x + firstBoundsWidth, currentBounds.y,
                        (int) (currentBounds.w - firstBoundsWidth), currentBounds.h);
                updateBounds((ComponentContainer) splitPanel.getSecondComponent(), rightBounds);
            }
        } else if (splitPanel instanceof VerticalSplitPanel) {
            int firstBoundsHeight = (int) (splitPos * currentBounds.h);
            if (splitPanel.getFirstComponent() instanceof ComponentContainer) {
                Bounds leftBounds = new Bounds(currentBounds.x, currentBounds.y, currentBounds.w,
                        firstBoundsHeight);
                updateBounds((ComponentContainer) splitPanel.getFirstComponent(), leftBounds);
            }

            if (splitPanel.getSecondComponent() instanceof ComponentContainer) {
                Bounds rightBounds = new Bounds(currentBounds.x, currentBounds.y + firstBoundsHeight,
                        (int) (currentBounds.w), currentBounds.h - firstBoundsHeight);
                updateBounds((ComponentContainer) splitPanel.getSecondComponent(), rightBounds);
            }
        }
    } else if (container instanceof ComponentContainer) {
        Iterator<Component> it = container.getComponentIterator();
        while (it.hasNext()) {
            Component c = it.next();
            if (c instanceof ComponentContainer) {
                updateBounds((ComponentContainer) c, currentBounds);
            }
        }
    }
}