diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java index 3f9b7711f8a3..c22c7b18bf16 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java @@ -22,14 +22,12 @@ import com.intellij.android.designer.actions.ProfileAction; import com.intellij.android.designer.componentTree.AndroidTreeDecorator; import com.intellij.android.designer.model.ModelParser; import com.intellij.android.designer.model.PropertyParser; +import com.intellij.android.designer.model.RadViewAnimatorLayout; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.profile.ProfileManager; import com.intellij.designer.DesignerToolWindowManager; import com.intellij.designer.componentTree.TreeComponentDecorator; -import com.intellij.designer.designSurface.ComponentDecorator; -import com.intellij.designer.designSurface.DesignerEditorPanel; -import com.intellij.designer.designSurface.EditOperation; -import com.intellij.designer.designSurface.OperationContext; +import com.intellij.designer.designSurface.*; import com.intellij.designer.designSurface.selection.NonResizeSelectionDecorator; import com.intellij.designer.designSurface.tools.ComponentCreationFactory; import com.intellij.designer.designSurface.tools.ComponentPasteFactory; @@ -57,6 +55,7 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; +import java.lang.reflect.Method; import java.util.List; /** @@ -106,6 +105,69 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { }); } + @Override + public void updateTreeArea(EditableArea area) { + area.addSelectionListener(new ComponentSelectionListener() { + @Override + public void selectionChanged(EditableArea area) { + List selection = area.getSelection(); + if (selection.size() == 1) { + final RadComponent component = selection.get(0); + final RadComponent parent = component.getParent(); + if (parent instanceof RadViewComponent && parent.getLayout() instanceof RadViewAnimatorLayout) { + ApplicationManager.getApplication().invokeLater( + new Runnable() { + @Override + public void run() { + try { + int index = parent.getChildren().indexOf(component); + Object parentView = + ((RadViewComponent)parent).getViewInfo().getViewObject(); + Method method = + parentView.getClass().getMethod("setDisplayedChild", int.class); + method.invoke(parentView, index); + + Result result = mySession.render(); + + if (!result.isSuccess()) { + System.out.println( + "No re render session: " + + result.getErrorMessage() + + " : " + + result.getStatus() + + " : " + + result.getData() + + " : " + + result.getException()); + } + else { + RadViewComponent rootComponent = (RadViewComponent)myRootComponent; + RootView rootView = (RootView)rootComponent.getNativeComponent(); + rootView.setImage(mySession.getImage()); + ModelParser.updateRootComponent(rootComponent, mySession, rootView); + + myLayeredPane.repaint(); + + DesignerToolWindowManager.getInstance(getProject()).refresh(); + } + } + catch (Throwable e) { + showError("reRender error: ", e); + } + } + }, new Condition() { + @Override + public boolean value(Object o) { + return mySession == null; + } + } + ); + } + } + } + }); + } + private void reparseFile() { try { myToolProvider.loadDefaultTool(); diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/DropToOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/DropToOperation.java index 8ac4aaf9f624..c38f0369428b 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/DropToOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/DropToOperation.java @@ -81,7 +81,7 @@ public class DropToOperation implements EditOperation { @Override public void execute() throws Exception { - if (myContext.isAdd()) { + if (myContext.isAdd() || myContext.isMove()) { for (RadComponent component : myComponents) { ModelParser.moveComponent(myContainer, (RadViewComponent)component, null); } diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/TreeDropToOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/TreeDropToOperation.java index 9c1b22416373..c9dc4f1f5158 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/TreeDropToOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/TreeDropToOperation.java @@ -34,7 +34,7 @@ public class TreeDropToOperation extends TreeEditOperation { RadViewComponent host = (RadViewComponent)myHost; RadViewComponent before = (RadViewComponent)insertBefore; - if (myContext.isAdd()) { + if (myContext.isAdd() || myContext.isMove()) { for (RadComponent component : myComponents) { ModelParser.moveComponent(host, (RadViewComponent)component, before); } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewAnimatorLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewAnimatorLayout.java index 45185f5c29db..7e16b93f0d47 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewAnimatorLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewAnimatorLayout.java @@ -25,7 +25,7 @@ import com.intellij.designer.designSurface.OperationContext; */ public class RadViewAnimatorLayout extends RadViewLayout { public EditOperation processChildOperation(OperationContext context) { - if ((context.isCreate() || context.isPaste() || context.isAdd()) && checkChildOperation(context)) { + if ((context.isCreate() || context.isPaste() || context.isAdd() || context.isMove()) && checkChildOperation(context)) { if (context.isTree()) { return new TreeDropToOperation(myContainer, context); } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewSwitcherLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewSwitcherLayout.java index 7f99403f539d..c2db529a195d 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewSwitcherLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewSwitcherLayout.java @@ -23,6 +23,6 @@ import com.intellij.designer.designSurface.OperationContext; public class RadViewSwitcherLayout extends RadViewAnimatorLayout { @Override protected boolean checkChildOperation(OperationContext context) { - return myContainer.getChildren().size() < 2; + return context.isMove() || myContainer.getChildren().size() < 2; } } \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java index d5b3d0f04b6d..9d626ba5c93a 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java @@ -39,6 +39,8 @@ public final class ComponentTreeBuilder extends AbstractTreeBuilder implements C myTreeArea = new TreeEditableArea(tree, this); myGlassLayer = new TreeGlassLayer(tree, designer.getToolProvider(), myTreeArea); + designer.updateTreeArea(myTreeArea); + // TODO: restore expanded state select(mySurfaceArea.getSelection().toArray(), null); diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DesignerEditorPanel.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DesignerEditorPanel.java index 3dda7b490b9f..c3ffd4db2ad0 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DesignerEditorPanel.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DesignerEditorPanel.java @@ -315,6 +315,9 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider return treeArea == null ? mySurfaceArea : treeArea; } + public void updateTreeArea(EditableArea area) { + } + public ToolProvider getToolProvider() { return myToolProvider; }