ComponentDropLocation (final GuiEditor editor, final List<? extends RadComponent> selection) { ComponentDropLocation dropLocation = null; if (selection.size() > 0) { RadComponent component = selection.get(0); final RadContainer container = component.getParent(); if (container.getLayoutManager().isGrid()) { GridConstraints c = component.getConstraints(); // try to insert in empty cell to the right or below the component; if not found - // insert row below selected component int nextCol = FormEditingUtil.adjustForGap(component.getParent(), c.getColumn() + c.getColSpan(), false, 1); int nextRow = FormEditingUtil.adjustForGap(component.getParent(), c.getRow() + c.getRowSpan(), true, 1); if (nextCol < container.getGridColumnCount() && container.getComponentAtGrid(c.getRow(), nextCol) == null) { dropLocation = new GridDropLocation(container, c.getRow(), nextCol); } else if (nextRow < container.getGridRowCount() && container.getComponentAtGrid(nextRow, c.getColumn()) == null) { dropLocation = new GridDropLocation(container, nextRow, c.getColumn()); } else { dropLocation = new GridInsertLocation(container, c.getRow() + c.getRowSpan() - 1, c.getColumn(), GridInsertMode.RowAfter); } } } if (dropLocation == null) { final Point mousePosition = editor.getMainProcessor().getLastMousePosition(); if (mousePosition != null) { RadContainer container = GridInsertProcessor.getDropTargetContainer(editor.getRootContainer(), mousePosition); if (container == null) { container = editor.getRootContainer(); } if (container instanceof RadRootContainer && container.getComponentCount() == 1 && container.getComponent(0) instanceof RadContainer childContainer) { dropLocation = childContainer.getDropLocation(null); } else { dropLocation = GridInsertProcessor.getDropLocation(editor.getRootContainer(), mousePosition); } } else { final RadRootContainer container = editor.getRootContainer(); if (container.getComponentCount() == 1 && container.getComponent(0) instanceof RadContainer childContainer) { dropLocation = childContainer.getDropLocation(null); } else { dropLocation = container.getDropLocation(null); } } } return dropLocation; }