List of usage examples for com.vaadin.ui AbstractComponent equals
@Override public boolean equals(Object obj)
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);// w w w . jav a 2s. c om 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"); } } }