mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Wrap In
This commit is contained in:
+10
@@ -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
|
||||
|
||||
+48
@@ -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<RadViewComponent> {
|
||||
public AndroidWrapInProvider(Project project) {
|
||||
super(ViewsMetaManager.getInstance(project));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RadComponent wrapIn(RadViewComponent parent, List<RadViewComponent> 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;
|
||||
}
|
||||
}
|
||||
@@ -43,4 +43,7 @@ public class RadViewLayout extends RadLayout {
|
||||
JComponent shortcuts,
|
||||
List<RadComponent> selection) {
|
||||
}
|
||||
|
||||
public void wrapIn(RadViewComponent newParent, List<RadViewComponent> components) throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -1447,6 +1447,15 @@
|
||||
</creation>
|
||||
</meta>
|
||||
|
||||
<wrap-in>
|
||||
<item tag="FrameLayout"/>
|
||||
<item tag="LinearLayout"/>
|
||||
<item tag="TableLayout"/>
|
||||
<item tag="TableRow"/>
|
||||
<item tag="GridLayout"/>
|
||||
<item tag="RelativeLayout"/>
|
||||
</wrap-in>
|
||||
|
||||
<!-- ================= Palette ================= -->
|
||||
|
||||
<palette>
|
||||
|
||||
+1
@@ -177,6 +177,7 @@ public class DesignerActionPanel implements DataProvider {
|
||||
myDynamicPopupGroup.removeAll();
|
||||
}
|
||||
|
||||
WrapInAction.fill(myDesigner, myDynamicPopupGroup, area);
|
||||
MorphingAction.fill(myDesigner, myDynamicPopupGroup, area);
|
||||
|
||||
return myPopupGroup;
|
||||
|
||||
+102
@@ -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<RadComponent> myComponents;
|
||||
private final MetaModel myTarget;
|
||||
|
||||
public WrapInAction(DesignerEditorPanel designer,
|
||||
EditableArea area,
|
||||
WrapInProvider provider,
|
||||
RadComponent parent,
|
||||
List<RadComponent> 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<Exception>() {
|
||||
@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<RadComponent> selection = area.getSelection();
|
||||
if (selection.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<RadComponent> 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<MetaModel> 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);
|
||||
}
|
||||
}
|
||||
+6
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<String, MetaModel> myTag2Model = new HashMap<String, MetaModel>();
|
||||
private final Map<String, MetaModel> myTarget2Model = new HashMap<String, MetaModel>();
|
||||
private final List<PaletteGroup> myPaletteGroups = new ArrayList<PaletteGroup>();
|
||||
private final List<MetaModel> myWrapModels = new ArrayList<MetaModel>();
|
||||
|
||||
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<MetaModel, List<String>> entry : modelToMorphing.entrySet()) {
|
||||
MetaModel meta = entry.getKey();
|
||||
List<MetaModel> morphingModels = new ArrayList<MetaModel>();
|
||||
@@ -209,6 +219,10 @@ public abstract class MetaManager {
|
||||
return myTarget2Model.get(target);
|
||||
}
|
||||
|
||||
public List<MetaModel> getWrapInModels() {
|
||||
return myWrapModels;
|
||||
}
|
||||
|
||||
public List<PaletteGroup> getPaletteGroups() {
|
||||
return myPaletteGroups;
|
||||
}
|
||||
|
||||
@@ -265,6 +265,11 @@ public abstract class RadComponent {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public RadComponent wrapIn(MetaModel target) throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Utils
|
||||
|
||||
@@ -62,4 +62,8 @@ public abstract class RadLayout {
|
||||
public ICaption getCaption(RadComponent component) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isWrapIn(List<RadComponent> components) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+35
@@ -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<T extends RadComponent> {
|
||||
private final List<MetaModel> myModels;
|
||||
|
||||
public WrapInProvider(MetaManager metaManager) {
|
||||
myModels = metaManager.getWrapInModels();
|
||||
}
|
||||
|
||||
public List<MetaModel> getModels() {
|
||||
return myModels;
|
||||
}
|
||||
|
||||
public abstract RadComponent wrapIn(T parent, List<T> components, MetaModel target) throws Exception;
|
||||
}
|
||||
Reference in New Issue
Block a user