diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/GridLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/GridLayout.java index 2d106bad3b54..c21b4664ffcb 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/GridLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/GridLayout.java @@ -16,6 +16,7 @@ package com.intellij.android.designer.model.morphing; import com.intellij.android.designer.model.*; +import com.intellij.android.designer.model.grid.GridInfo; import com.intellij.android.designer.model.layout.grid.RadGridLayoutComponent; import com.intellij.android.designer.model.layout.table.RadTableLayout; import com.intellij.android.designer.model.layout.table.RadTableLayoutComponent; @@ -24,24 +25,30 @@ import com.intellij.designer.model.RadComponent; import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlTag; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + /** * @author Alexander Lobas */ public class GridLayout { public static RadViewComponent TableLayout(RadViewComponent component, MetaModel target) throws Exception { - final RadComponent[][] components = ((RadGridLayoutComponent)component).getGridComponents(false); + final List[][] components = getGridComponents((RadGridLayoutComponent)component); final MetaModel tableRowModel = ViewsMetaManager.getInstance(component.getTag().getProject()).getModelByTag("TableRow"); return new ComponentMorphingTool(component, new RadTableLayoutComponent(), target, new RadTableLayout()) { @Override protected void convertChildren() throws Exception { - for (RadComponent[] rowComponents : components) { + for (List[] rowComponents : components) { RadViewComponent newRowComponent = ModelParser.createComponent(null, tableRowModel); ModelParser.addComponent(myNewComponent, newRowComponent, null); - for (RadComponent cellComponent : rowComponents) { - if (cellComponent != null) { - ModelParser.moveComponent(newRowComponent, (RadViewComponent)cellComponent, null); + for (List cellComponents : rowComponents) { + if (cellComponents != null) { + for (RadComponent cellComponent : cellComponents) { + ModelParser.moveComponent(newRowComponent, (RadViewComponent)cellComponent, null); + } } } } @@ -72,4 +79,21 @@ public class GridLayout { } }.result(); } + + private static List[][] getGridComponents(RadGridLayoutComponent parent) { + GridInfo gridInfo = parent.getGridInfo(); + List[][] components = new List[gridInfo.rowCount][gridInfo.columnCount]; + + for (RadComponent child : parent.getChildren()) { + Rectangle cellInfo = RadGridLayoutComponent.getCellInfo(child); + List cellComponents = components[cellInfo.y][cellInfo.x]; + if (cellComponents == null) { + cellComponents = new ArrayList(); + components[cellInfo.y][cellInfo.x] = cellComponents; + } + cellComponents.add(child); + } + + return components; + } } \ No newline at end of file