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 149f5ec81f3b..a01afc543447 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 @@ -31,6 +31,7 @@ import com.intellij.designer.designSurface.selection.NonResizeSelectionDecorator import com.intellij.designer.designSurface.tools.ComponentCreationFactory; import com.intellij.designer.designSurface.tools.ComponentPasteFactory; import com.intellij.designer.model.RadComponent; +import com.intellij.designer.model.WrapInProvider; import com.intellij.designer.palette.DefaultPaletteItem; import com.intellij.designer.palette.PaletteGroup; import com.intellij.designer.palette.PaletteItem; @@ -77,6 +78,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { private volatile RenderSession mySession; private boolean myParseTime; private int myProfileLastVersion; + private WrapInProvider myWrapInProvider; public AndroidDesignerEditorPanel(@NotNull DesignerEditor editor, @NotNull Project project, @@ -464,6 +466,14 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { return myTreeDecorator; } + @Override + public WrapInProvider getWrapInProvider() { + if (myWrapInProvider == null) { + myWrapInProvider = new AndroidWrapInProvider(getProject()); + } + return myWrapInProvider; + } + private static final ComponentDecorator NON_RESIZE_DECORATOR = new NonResizeSelectionDecorator(Color.RED, 2); @Override diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/AndroidWrapInProvider.java b/plugins/android-designer/src/com/intellij/android/designer/model/AndroidWrapInProvider.java new file mode 100644 index 000000000000..46e20f726d8c --- /dev/null +++ b/plugins/android-designer/src/com/intellij/android/designer/model/AndroidWrapInProvider.java @@ -0,0 +1,48 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.android.designer.model; + +import com.intellij.designer.model.MetaModel; +import com.intellij.designer.model.RadComponent; +import com.intellij.designer.model.WrapInProvider; +import com.intellij.openapi.project.Project; + +import java.util.List; + +/** + * @author Alexander Lobas + */ +public final class AndroidWrapInProvider extends WrapInProvider { + public AndroidWrapInProvider(Project project) { + super(ViewsMetaManager.getInstance(project)); + } + + @Override + public RadComponent wrapIn(RadViewComponent parent, List components, MetaModel target) throws Exception { + RadViewComponent newParent = ModelParser.createComponent(null, target); + + ModelParser.addComponent(parent, newParent, components.get(0)); + + for (RadViewComponent component : components) { + ModelParser.moveComponent(newParent, component, null); + } + + RadViewLayout layout = (RadViewLayout)parent.getLayout(); + layout.wrapIn(newParent, components); + + return newParent; + } +} \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java index 20a36399f595..08165feb0f80 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java @@ -43,4 +43,7 @@ public class RadViewLayout extends RadLayout { JComponent shortcuts, List selection) { } + + public void wrapIn(RadViewComponent newParent, List components) throws Exception { + } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml b/plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml index eb369e8a4e9d..0311d7976093 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml +++ b/plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml @@ -1447,6 +1447,15 @@ + + + + + + + + + diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/DesignerActionPanel.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/DesignerActionPanel.java index 86c813b7cadc..24a15a36953b 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/DesignerActionPanel.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/DesignerActionPanel.java @@ -177,6 +177,7 @@ public class DesignerActionPanel implements DataProvider { myDynamicPopupGroup.removeAll(); } + WrapInAction.fill(myDesigner, myDynamicPopupGroup, area); MorphingAction.fill(myDesigner, myDynamicPopupGroup, area); return myPopupGroup; diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/WrapInAction.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/WrapInAction.java new file mode 100644 index 000000000000..92e5e6d26e5a --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/WrapInAction.java @@ -0,0 +1,102 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.designer.actions; + +import com.intellij.designer.designSurface.DesignerEditorPanel; +import com.intellij.designer.designSurface.EditableArea; +import com.intellij.designer.model.MetaModel; +import com.intellij.designer.model.RadComponent; +import com.intellij.designer.model.RadLayout; +import com.intellij.designer.model.WrapInProvider; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.DefaultActionGroup; +import com.intellij.util.ThrowableRunnable; + +import java.util.List; +import java.util.Set; + +/** + * @author Alexander Lobas + */ +public class WrapInAction extends AnAction { + private final DesignerEditorPanel myDesigner; + private final EditableArea myArea; + private final WrapInProvider myProvider; + private final RadComponent myParent; + private final List myComponents; + private final MetaModel myTarget; + + public WrapInAction(DesignerEditorPanel designer, + EditableArea area, + WrapInProvider provider, + RadComponent parent, + List components, + MetaModel target) { + super(target.getTag(), null, target.getIcon()); + myDesigner = designer; + myArea = area; + myProvider = provider; + myParent = parent; + myComponents = components; + myTarget = target; + } + + @Override + public void actionPerformed(AnActionEvent e) { + myDesigner.getToolProvider().execute(new ThrowableRunnable() { + @Override + public void run() throws Exception { + myArea.select(myProvider.wrapIn(myParent, myComponents, myTarget)); + } + }, "Run Wrap In action", true); + } + + public static void fill(DesignerEditorPanel designer, DefaultActionGroup group, EditableArea area) { + List selection = area.getSelection(); + if (selection.isEmpty()) { + return; + } + + Set parents = RadComponent.getParents(selection); + if (parents.size() != 1) { + return; + } + + RadComponent parent = parents.iterator().next(); + RadLayout layout = parent.getLayout(); + if (layout != null && !layout.isWrapIn(selection)) { + return; + } + + WrapInProvider provider = designer.getWrapInProvider(); + if (provider == null) { + return; + } + + List models = provider.getModels(); + if (models.isEmpty()) { + return; + } + + DefaultActionGroup wrapGroup = new DefaultActionGroup("Wrap In", true); + for (MetaModel wrapModel : models) { + wrapGroup.add(new WrapInAction(designer, area, provider, parent, selection, wrapModel)); + } + + group.add(wrapGroup); + } +} \ No newline at end of file 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 b6dd0ebf50a4..3ec787cd1d48 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 @@ -24,6 +24,7 @@ import com.intellij.designer.componentTree.TreeComponentDecorator; import com.intellij.designer.designSurface.tools.*; import com.intellij.designer.model.FindComponentVisitor; import com.intellij.designer.model.RadComponent; +import com.intellij.designer.model.WrapInProvider; import com.intellij.designer.palette.PaletteGroup; import com.intellij.designer.palette.PaletteItem; import com.intellij.designer.palette.PaletteToolWindowManager; @@ -729,6 +730,11 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider Disposer.dispose(myProgressIcon); } + @Nullable + public WrapInProvider getWrapInProvider() { + return null; + } + public RadComponent getRootComponent() { return myRootComponent; } diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaManager.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaManager.java index a66a1c751b8b..08b69a16d928 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaManager.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaManager.java @@ -43,12 +43,14 @@ public abstract class MetaManager { private static final String NAME = "name"; private static final String ITEM = "item"; private static final String TAG = "tag"; + private static final String WRAP_IN = "wrap-in"; private static final Logger LOG = Logger.getInstance("#com.intellij.designer.model.MetaManager"); private final Map myTag2Model = new HashMap(); private final Map myTarget2Model = new HashMap(); private final List myPaletteGroups = new ArrayList(); + private final List myWrapModels = new ArrayList(); private PropertyChangeSupport myPaletteChangeSupport; @@ -73,6 +75,14 @@ public abstract class MetaManager { loadGroup((Element)element); } + Element wrapInElement = rootElement.getChild(WRAP_IN); + if (wrapInElement != null) { + for (Object element : wrapInElement.getChildren(ITEM)) { + Element item = (Element)element; + myWrapModels.add(myTag2Model.get(item.getAttributeValue("tag"))); + } + } + for (Map.Entry> entry : modelToMorphing.entrySet()) { MetaModel meta = entry.getKey(); List morphingModels = new ArrayList(); @@ -209,6 +219,10 @@ public abstract class MetaManager { return myTarget2Model.get(target); } + public List getWrapInModels() { + return myWrapModels; + } + public List getPaletteGroups() { return myPaletteGroups; } diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java index c5ceb44c64ab..72ae7bd8ad26 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java @@ -265,6 +265,11 @@ public abstract class RadComponent { return null; } + @Nullable + public RadComponent wrapIn(MetaModel target) throws Exception { + return null; + } + ////////////////////////////////////////////////////////////////////////////////////////// // // Utils diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadLayout.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadLayout.java index d0c8f518da47..46feaa509946 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadLayout.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadLayout.java @@ -62,4 +62,8 @@ public abstract class RadLayout { public ICaption getCaption(RadComponent component) { return null; } + + public boolean isWrapIn(List components) { + return true; + } } \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/WrapInProvider.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/WrapInProvider.java new file mode 100644 index 000000000000..7ff3aa8a06fd --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/WrapInProvider.java @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.designer.model; + +import java.util.List; + +/** + * @author Alexander Lobas + */ +public abstract class WrapInProvider { + private final List myModels; + + public WrapInProvider(MetaManager metaManager) { + myModels = metaManager.getWrapInModels(); + } + + public List getModels() { + return myModels; + } + + public abstract RadComponent wrapIn(T parent, List components, MetaModel target) throws Exception; +} \ No newline at end of file