private LayoutConstraints<?>[] removeLayoutDelegate(boolean extractConstraints) { int componentCount = layoutDelegate.getComponentCount(); LayoutConstraints<?>[] constraints = null; if (componentCount > 0) { RADVisualComponent<?>[] radComps = radContainer.getSubComponents(); if (radComps.length == componentCount) { // robustness: might be called after failed layout initialization if (extractConstraints) { constraints = new LayoutConstraints<?>[componentCount]; } for (int i = 0; i < componentCount; i++) { LayoutConstraints<?> constr = layoutDelegate.getConstraints(i); if (extractConstraints) { constraints[i] = constr; } if (constr != null) { radComps[i].setLayoutConstraints(layoutDelegate.getClass(), constr); } } } } layoutDelegate.removeAll(); layoutDelegate.clearContainer(getPrimaryContainer(), getPrimaryContainerDelegate()); layoutDelegate = null; return constraints; }
// components adding/removing public void injectComponents( RADVisualComponent<?>[] components, LayoutConstraints<?>[] aConstraints, int index) { if (index <= -1) { index = layoutDelegate.getComponentCount(); } layoutDelegate.addComponents(components, aConstraints, index); for (RADVisualComponent<?> component : components) { component.resetConstraintsProperties(); } }
public LayoutConstraints<?> getConstraints(RADVisualComponent<?> radComp) { if (layoutDelegate != null) { int index = radComp.getComponentIndex(); // radContainer.getIndexOf(radComp); return index >= 0 && index < layoutDelegate.getComponentCount() ? layoutDelegate.getConstraints(index) : null; } else { return null; } }
public void addComponents( RADVisualComponent<?>[] components, LayoutConstraints<?>[] aConstraints, int index) { if (index <= -1) { index = layoutDelegate.getComponentCount(); } injectComponents(components, aConstraints, index); Component[] comps = new Component[components.length]; for (int i = 0; i < components.length; i++) { comps[i] = components[i].getBeanInstance(); } layoutDelegate.addComponentsToContainer( getPrimaryContainer(), getPrimaryContainerDelegate(), comps, index); }
public void removeAll() { // first store constraints in meta components RADVisualComponent<?>[] components = radContainer.getSubComponents(); for (int i = 0; i < components.length; i++) { LayoutConstraints<?> constr = layoutDelegate.getConstraints(i); if (constr != null) { components[i].setLayoutConstraints(layoutDelegate.getClass(), constr); } } // remove components from layout layoutDelegate.removeAll(); // clear the primary container instance layoutDelegate.clearContainer(getPrimaryContainer(), getPrimaryContainerDelegate()); }
public boolean isLayoutChanged() { Container defaultContainer = (Container) BeanSupport.getDefaultInstance(radContainer.getBeanClass()); Container defaultContDelegate = radContainer.getContainerDelegate(defaultContainer); return layoutDelegate.isLayoutChanged(defaultContainer, defaultContDelegate); }
public void setLayoutDelegate(LayoutSupportDelegate newDelegate /*, boolean fromCode*/) throws Exception { LayoutConstraints<?>[] oldConstraints; LayoutSupportDelegate oldDelegate = layoutDelegate; if (layoutDelegate != null && (layoutDelegate != newDelegate /* || !fromCode*/)) { oldConstraints = removeLayoutDelegate(true); } else { oldConstraints = null; } layoutDelegate = newDelegate; propertySets = null; needInit = false; if (layoutDelegate != null) { try { layoutDelegate.initialize(this, null); fillLayout(oldConstraints); getPropertySets(); // force properties and listeners creation } catch (Exception ex) { removeLayoutDelegate(false); layoutDelegate = oldDelegate; if (layoutDelegate != null) { fillLayout(null); } throw ex; } } }
@Override public void componentLayoutChanged(int index, PropertyChangeEvent ev) throws PropertyVetoException { RADVisualComponent<?> radComp = radContainer.getSubComponent(index); if (ev != null && ev.getPropertyName() != null) { layoutDelegate.acceptComponentLayoutChange(index, ev); FormModel formModel = radContainer.getFormModel(); formModel.fireComponentLayoutChanged( radComp, ev.getPropertyName(), ev.getOldValue(), ev.getNewValue()); if (radComp.getNodeReference() != null) // propagate the change to node { radComp .getNodeReference() .firePropertyChangeHelper(ev.getPropertyName(), ev.getOldValue(), ev.getNewValue()); } } else { if (radComp.getNodeReference() != null) // propagate the change to node { radComp.getNodeReference().fireComponentPropertySetsChange(); } radComp.resetConstraintsProperties(); } }
@Override public void updatePrimaryContainer() { Container cont = getPrimaryContainer(); Container contDel = getPrimaryContainerDelegate(); layoutDelegate.clearContainer(cont, contDel); layoutDelegate.setLayoutToContainer(cont, contDel); RADVisualComponent<?>[] components = radContainer.getSubComponents(); if (components.length > 0) { Component[] comps = new Component[components.length]; for (int i = 0; i < components.length; i++) { comps[i] = (Component) components[i].getBeanInstance(); } layoutDelegate.addComponentsToContainer(cont, contDel, comps, 0); } }
// copy layout delegate from another container public void copyLayoutDelegateFrom( LayoutSupportManager sourceLayoutSupport, RADVisualComponent<?>[] newRadComps) { LayoutSupportDelegate sourceDelegate = sourceLayoutSupport.getLayoutDelegate(); int componentCount = sourceDelegate.getComponentCount(); Container cont = getPrimaryContainer(); Container contDel = getPrimaryContainerDelegate(); if (layoutDelegate != null) { removeLayoutDelegate(false); } Component[] primaryComps = new Component[componentCount]; for (int i = 0; i < componentCount; i++) { RADVisualComponent<?> radComp = newRadComps[i]; primaryComps[i] = (Component) radComp.getBeanInstance(); } LayoutSupportDelegate newDelegate = sourceDelegate.cloneLayoutSupport(this, newRadComps); newDelegate.setLayoutToContainer(cont, contDel); newDelegate.addComponentsToContainer(cont, contDel, primaryComps, 0); layoutDelegate = newDelegate; // Ensure correct propagation of copied properties (issue 50011, 72351) try { layoutDelegate.acceptContainerLayoutChange(null); } catch (PropertyVetoException pvex) { // should not happen } }
public void initializeLayoutDelegate() throws Exception { if (layoutDelegate != null && needInit) { LayoutManager lmInstance = initializeFromInstance ? getPrimaryContainerDelegate().getLayout() : null; layoutDelegate.initialize(this, lmInstance); // , initializeFromCode); fillLayout(null); getPropertySets(); // force properties and listeners creation needInit = false; } }
public boolean paintDragFeedback( Container container, Container containerDelegate, Component component, LayoutConstraints<?> newConstraints, int newIndex, Graphics g) { return layoutDelegate.paintDragFeedback( container, containerDelegate, component, newConstraints, newIndex, g); }
public int getNewIndex( Container container, Container containerDelegate, Component component, int index, Point posInCont, Point posInComp) { return layoutDelegate.getNewIndex( container, containerDelegate, component, index, posInCont, posInComp); }
public LayoutConstraints<?> getResizedConstraints( Container container, Container containerDelegate, Component component, int index, Rectangle originalBounds, Insets sizeChanges, Point posInCont) { return layoutDelegate.getResizedConstraints( container, containerDelegate, component, index, originalBounds, sizeChanges, posInCont); }
public void removeComponent(RADVisualComponent<?> radComp, int index) { // first store constraints in the meta component LayoutConstraints<?> constr = layoutDelegate.getConstraints(index); if (constr != null) { radComp.setLayoutConstraints(layoutDelegate.getClass(), constr); } // remove the component from layout layoutDelegate.removeComponent(index); // remove the component instance from the primary container instance if (!layoutDelegate.removeComponentFromContainer( getPrimaryContainer(), getPrimaryContainerDelegate(), (Component) radComp .getBeanInstance())) { // layout delegate does not support removing individual // components, // so we clear the container and add the remaining components again layoutDelegate.clearContainer(getPrimaryContainer(), getPrimaryContainerDelegate()); RADVisualComponent<?>[] radComps = radContainer.getSubComponents(); if (radComps.length > 1) { // we rely on that radcomp was not removed from the model yet Component[] comps = new Component[radComps.length - 1]; for (int i = 0; i < radComps.length; i++) { if (i != index) { Component comp = (Component) radComps[i].getBeanInstance(); comps[i < index ? i : i - 1] = comp; } } layoutDelegate.addComponentsToContainer( getPrimaryContainer(), getPrimaryContainerDelegate(), comps, 0); } } }
private void fillLayout(LayoutConstraints<?>[] oldConstraints) { RADVisualComponent<?>[] radComps = radContainer.getSubComponents(); int componentCount = radComps.length; Component[] primaryComps = new Component[componentCount]; LayoutConstraints<?>[] newConstraints = new LayoutConstraints<?>[componentCount]; for (int i = 0; i < componentCount; i++) { primaryComps[i] = radComps[i].getBeanInstance(); newConstraints[i] = radComps[i].getLayoutConstraints(layoutDelegate.getClass()); } layoutDelegate.convertConstraints(oldConstraints, newConstraints, primaryComps); if (componentCount > 0) { layoutDelegate.acceptNewComponents(radComps, newConstraints, 0); layoutDelegate.addComponents(radComps, newConstraints, 0); for (int i = 0; i < componentCount; i++) { radComps[i].resetConstraintsProperties(); } } // setup primary container Container cont = getPrimaryContainer(); Container contDel = getPrimaryContainerDelegate(); layoutDelegate.setLayoutToContainer(cont, contDel); if (componentCount > 0) { layoutDelegate.addComponentsToContainer(cont, contDel, primaryComps, 0); } }
// properties and customizer public Node.PropertySet[] getPropertySets() { if (propertySets == null) { if (layoutDelegate == null) { return new Node.PropertySet[0]; // Issue 63916 } propertySets = layoutDelegate.getPropertySets(); for (Node.PropertySet propertySet : propertySets) { FormProperty<?>[] props = (FormProperty<?>[]) propertySet.getProperties(); for (FormProperty<?> prop : props) { prop.addVetoableChangeListener(getLayoutListener()); prop.addPropertyChangeListener(getLayoutListener()); } } } return propertySets; }
@Override public void containerLayoutChanged(PropertyChangeEvent ev) throws PropertyVetoException { if (ev != null && ev.getPropertyName() != null) { layoutDelegate.acceptContainerLayoutChange(ev); FormModel formModel = radContainer.getFormModel(); formModel.fireContainerLayoutChanged( radContainer, ev.getPropertyName(), ev.getOldValue(), ev.getNewValue()); } else { propertySets = null; } LayoutNode node = radContainer.getLayoutNodeReference(); if (node != null) { // propagate the change to node if (ev != null && ev.getPropertyName() != null) { node.fireLayoutPropertiesChange(); } else { node.fireLayoutPropertySetsChange(); } } }
// drag and drop support public LayoutConstraints<?> getNewConstraints( Container container, Container containerDelegate, Component component, int index, Point posInCont, Point posInComp) { LayoutConstraints<?> constraints = layoutDelegate.getNewConstraints( container, containerDelegate, component, index, posInCont, posInComp); String context = null; Object[] params = null; if (layoutDelegate instanceof AbstractLayoutSupport) { AbstractLayoutSupport support = (AbstractLayoutSupport) layoutDelegate; context = support.getAssistantContext(); params = support.getAssistantParams(); } context = (context == null) ? "generalPosition" : context; // NOI18N radContainer.getFormModel().getAssistantModel().setContext(context, params); return constraints; }
// managing live components public void setLayoutToContainer(Container container, Container containerDelegate) { layoutDelegate.setLayoutToContainer(container, containerDelegate); }
// arranging support public void arrangeContainer(Container container, Container containerDelegate) { layoutDelegate.arrangeContainer(container, containerDelegate); }
// arranging support public void selectComponent(int index) { layoutDelegate.selectComponent(index); }
// arranging support public void processMouseClick(Point p, Container cont, Container contDelegate) { layoutDelegate.processMouseClick(p, cont, contDelegate); }
// data validation public void acceptNewComponents( RADVisualComponent<?>[] components, LayoutConstraints<?>[] constraints, int index) { layoutDelegate.acceptNewComponents(components, constraints, index); }
// resizing support public int getResizableDirections( Container container, Container containerDelegate, Component component, int index) { return layoutDelegate.getResizableDirections(container, containerDelegate, component, index); }
public LayoutConstraints<?> getStoredConstraints(RADVisualComponent<?> radComp) { return radComp.getLayoutConstraints(layoutDelegate.getClass()); }
// managing constraints public LayoutConstraints<?> getConstraints(int index) { return layoutDelegate.getConstraints(index); }
public boolean clearContainer(Container container, Container containerDelegate) { return layoutDelegate.clearContainer(container, containerDelegate); }
public boolean removeComponentFromContainer( Container container, Container containerDelegate, Component component) { return layoutDelegate.removeComponentFromContainer(container, containerDelegate, component); }
public void addComponentsToContainer( Container container, Container containerDelegate, Component[] components, int index) { layoutDelegate.addComponentsToContainer(container, containerDelegate, components, index); }