mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Morphing
This commit is contained in:
+16
@@ -16,6 +16,7 @@
|
||||
package com.intellij.android.designer.model;
|
||||
|
||||
import com.android.ide.common.rendering.api.ViewInfo;
|
||||
import com.intellij.designer.model.MetaModel;
|
||||
import com.intellij.designer.model.RadComponent;
|
||||
import com.intellij.designer.model.RadVisualComponent;
|
||||
import com.intellij.designer.propertyTable.Property;
|
||||
@@ -250,4 +251,19 @@ public class RadViewComponent extends RadVisualComponent {
|
||||
child.copyTo(parent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void morphingTo(final MetaModel target) throws Exception {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myTag.setName(target.getTag());
|
||||
}
|
||||
});
|
||||
|
||||
setMetaModel(target);
|
||||
|
||||
PropertyParser propertyParser = getRoot().getClientProperty(PropertyParser.KEY);
|
||||
propertyParser.load(this);
|
||||
}
|
||||
}
|
||||
@@ -108,6 +108,8 @@
|
||||
<palette title="Button" icon="/com/intellij/android/designer/icons/Button.png"
|
||||
tooltip="Represents a push-button widget."/>
|
||||
|
||||
<morphing to="RadioButton CheckBox ToggleButton"/>
|
||||
|
||||
<properties
|
||||
inplace="text"
|
||||
important="onClick"
|
||||
|
||||
+13
-4
@@ -38,6 +38,7 @@ public class DesignerActionPanel implements DataProvider {
|
||||
private final DefaultActionGroup myStaticGroup = new DefaultActionGroup();
|
||||
private final DefaultActionGroup myDynamicGroup = new DefaultActionGroup();
|
||||
private final DefaultActionGroup myPopupGroup = new DefaultActionGroup();
|
||||
private final DefaultActionGroup myDynamicPopupGroup = new DefaultActionGroup();
|
||||
private JComponent myToolbar;
|
||||
private final DesignerEditorPanel myDesigner;
|
||||
private final CommonEditActionsProvider myCommonEditActionsProvider;
|
||||
@@ -84,6 +85,8 @@ public class DesignerActionPanel implements DataProvider {
|
||||
myPopupGroup.addSeparator();
|
||||
myPopupGroup.add(selectParent);
|
||||
myPopupGroup.add(selectAllAction);
|
||||
myPopupGroup.addSeparator();
|
||||
myPopupGroup.add(myDynamicPopupGroup);
|
||||
|
||||
designer.getSurfaceArea().addSelectionListener(new ComponentSelectionListener() {
|
||||
@Override
|
||||
@@ -144,10 +147,12 @@ public class DesignerActionPanel implements DataProvider {
|
||||
private void updateSelectionActions(List<RadComponent> selection) {
|
||||
boolean update = isVisible(myDynamicGroup);
|
||||
|
||||
for (AnAction action : myDynamicGroup.getChildActionsOrStubs()) {
|
||||
action.unregisterCustomShortcutSet(myShortcuts);
|
||||
if (myDynamicGroup.getChildrenCount() > 0) {
|
||||
for (AnAction action : myDynamicGroup.getChildActionsOrStubs()) {
|
||||
action.unregisterCustomShortcutSet(myShortcuts);
|
||||
}
|
||||
myDynamicGroup.removeAll();
|
||||
}
|
||||
myDynamicGroup.removeAll();
|
||||
|
||||
for (RadComponent parent : RadComponent.getParents(selection)) {
|
||||
parent.getLayout().addSelectionActions(myDesigner, myDynamicGroup, myShortcuts, selection);
|
||||
@@ -162,7 +167,11 @@ public class DesignerActionPanel implements DataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public ActionGroup getPopupActions() {
|
||||
public ActionGroup getPopupActions(EditableArea area) {
|
||||
if (myDynamicPopupGroup.getChildrenCount() > 0) {
|
||||
myDynamicPopupGroup.removeAll();
|
||||
}
|
||||
MorphingAction.fill(myDesigner, myDynamicPopupGroup, area);
|
||||
return myPopupGroup;
|
||||
}
|
||||
|
||||
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Alexander Lobas
|
||||
*/
|
||||
public class MorphingAction extends AnAction {
|
||||
private final DesignerEditorPanel myDesigner;
|
||||
private final List<RadComponent> myComponents;
|
||||
private final MetaModel myTarget;
|
||||
|
||||
public MorphingAction(DesignerEditorPanel designer, List<RadComponent> components, MetaModel target) {
|
||||
super(target.getTag(), null, target.getIcon());
|
||||
myDesigner = designer;
|
||||
myComponents = components;
|
||||
myTarget = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
myDesigner.getToolProvider().execute(new ThrowableRunnable<Exception>() {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
for (RadComponent component : myComponents) {
|
||||
component.morphingTo(myTarget);
|
||||
}
|
||||
}
|
||||
}, "Run Morphing action", true);
|
||||
}
|
||||
|
||||
public static void fill(DesignerEditorPanel designer, DefaultActionGroup group, EditableArea area) {
|
||||
List<RadComponent> selection = area.getSelection();
|
||||
if (selection.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
MetaModel model = null;
|
||||
for (RadComponent component : selection) {
|
||||
if (model == null) {
|
||||
model = component.getMetaModel();
|
||||
}
|
||||
else if (model != component.getMetaModel()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (model == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<MetaModel> models = model.getMorphingModels();
|
||||
if (models.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DefaultActionGroup morphingGroup = new DefaultActionGroup("Morphing", true);
|
||||
for (MetaModel morphingModel : models) {
|
||||
morphingGroup.add(new MorphingAction(designer, selection, morphingModel));
|
||||
}
|
||||
|
||||
group.add(morphingGroup);
|
||||
}
|
||||
}
|
||||
+1
-7
@@ -19,7 +19,6 @@ import com.intellij.designer.designSurface.ComponentSelectionListener;
|
||||
import com.intellij.designer.designSurface.DesignerEditorPanel;
|
||||
import com.intellij.designer.designSurface.EditableArea;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeBuilder;
|
||||
import com.intellij.openapi.actionSystem.ActionGroup;
|
||||
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
|
||||
@@ -41,12 +40,7 @@ public final class ComponentTreeBuilder extends AbstractTreeBuilder implements C
|
||||
initRootNode();
|
||||
|
||||
mySurfaceArea = designer.getSurfaceArea();
|
||||
myTreeArea = new TreeEditableArea(tree, this) {
|
||||
@Override
|
||||
public ActionGroup getPopupActions() {
|
||||
return mySurfaceArea.getPopupActions();
|
||||
}
|
||||
};
|
||||
myTreeArea = new TreeEditableArea(tree, this, designer.getActionPanel());
|
||||
myGlassLayer = new TreeGlassLayer(tree, designer.getToolProvider(), myTreeArea);
|
||||
myExpandStateHandler = new ExpandStateHandler(tree, designer, this);
|
||||
|
||||
|
||||
+11
-2
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
package com.intellij.designer.componentTree;
|
||||
|
||||
import com.intellij.designer.actions.DesignerActionPanel;
|
||||
import com.intellij.designer.designSurface.*;
|
||||
import com.intellij.designer.designSurface.tools.InputTool;
|
||||
import com.intellij.designer.model.RadComponent;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeBuilder;
|
||||
import com.intellij.openapi.actionSystem.ActionGroup;
|
||||
import com.intellij.openapi.actionSystem.ActionPlaces;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -37,14 +39,16 @@ import java.util.List;
|
||||
/**
|
||||
* @author Alexander Lobas
|
||||
*/
|
||||
public abstract class TreeEditableArea implements EditableArea, FeedbackTreeLayer, TreeSelectionListener {
|
||||
public final class TreeEditableArea implements EditableArea, FeedbackTreeLayer, TreeSelectionListener {
|
||||
private final EventListenerList myListenerList = new EventListenerList();
|
||||
private final ComponentTree myTree;
|
||||
private final AbstractTreeBuilder myTreeBuilder;
|
||||
private final DesignerActionPanel myActionPanel;
|
||||
|
||||
public TreeEditableArea(ComponentTree tree, AbstractTreeBuilder treeBuilder) {
|
||||
public TreeEditableArea(ComponentTree tree, AbstractTreeBuilder treeBuilder, DesignerActionPanel actionPanel) {
|
||||
myTree = tree;
|
||||
myTreeBuilder = treeBuilder;
|
||||
myActionPanel = actionPanel;
|
||||
hookSelection();
|
||||
}
|
||||
|
||||
@@ -225,6 +229,11 @@ public abstract class TreeEditableArea implements EditableArea, FeedbackTreeLaye
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionGroup getPopupActions() {
|
||||
return myActionPanel.getPopupActions(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPopupPlace() {
|
||||
return ActionPlaces.GUI_DESIGNER_COMPONENT_TREE_POPUP;
|
||||
|
||||
+1
-1
@@ -192,7 +192,7 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider
|
||||
|
||||
@Override
|
||||
public ActionGroup getPopupActions() {
|
||||
return myActionPanel.getPopupActions();
|
||||
return myActionPanel.getPopupActions(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+25
-2
@@ -64,13 +64,31 @@ public abstract class MetaManager {
|
||||
Element rootElement = document.getRootElement();
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
|
||||
Map<MetaModel, List<String>> modelToMorphing = new HashMap<MetaModel, List<String>>();
|
||||
|
||||
for (Object element : rootElement.getChildren(META)) {
|
||||
loadModel(classLoader, (Element)element);
|
||||
loadModel(classLoader, (Element)element, modelToMorphing);
|
||||
}
|
||||
|
||||
for (Object element : rootElement.getChild(PALETTE).getChildren(GROUP)) {
|
||||
loadGroup(name, (Element)element);
|
||||
}
|
||||
|
||||
for (Map.Entry<MetaModel, List<String>> entry : modelToMorphing.entrySet()) {
|
||||
MetaModel meta = entry.getKey();
|
||||
List<MetaModel> morphingModels = new ArrayList<MetaModel>();
|
||||
|
||||
for (String tag : entry.getValue()) {
|
||||
MetaModel morphingModel = myTag2Model.get(tag);
|
||||
if (morphingModel != null) {
|
||||
morphingModels.add(morphingModel);
|
||||
}
|
||||
}
|
||||
|
||||
if (!morphingModels.isEmpty()) {
|
||||
meta.setMorphingModels(morphingModels);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
LOG.error(e);
|
||||
@@ -78,7 +96,7 @@ public abstract class MetaManager {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void loadModel(ClassLoader classLoader, Element element) throws Exception {
|
||||
private void loadModel(ClassLoader classLoader, Element element, Map<MetaModel, List<String>> modelToMorphing) throws Exception {
|
||||
String modelValue = element.getAttributeValue("model");
|
||||
Class<RadComponent> model = modelValue == null ? null : (Class<RadComponent>)classLoader.loadClass(modelValue);
|
||||
String target = element.getAttributeValue("class");
|
||||
@@ -145,6 +163,11 @@ public abstract class MetaManager {
|
||||
}
|
||||
}
|
||||
|
||||
Element morphing = element.getChild("morphing");
|
||||
if (morphing != null) {
|
||||
modelToMorphing.put(meta, StringUtil.split(morphing.getAttribute("to").getValue(), " "));
|
||||
}
|
||||
|
||||
if (tag != null) {
|
||||
myTag2Model.put(tag, meta);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ public class MetaModel {
|
||||
private List<String> myImportantProperties = Collections.emptyList();
|
||||
private List<String> myExpertProperties = Collections.emptyList();
|
||||
private List<String> myDeprecatedProperties = Collections.emptyList();
|
||||
private List<MetaModel> myMorphingModels = Collections.emptyList();
|
||||
|
||||
public MetaModel(Class<RadComponent> model, String target, String tag) {
|
||||
myModel = model;
|
||||
@@ -117,6 +118,14 @@ public class MetaModel {
|
||||
myPaletteItem.setMetaModel(this);
|
||||
}
|
||||
|
||||
public List<MetaModel> getMorphingModels() {
|
||||
return myMorphingModels;
|
||||
}
|
||||
|
||||
public void setMorphingModels(List<MetaModel> morphingModels) {
|
||||
myMorphingModels = morphingModels;
|
||||
}
|
||||
|
||||
public List<String> getInplaceProperties() {
|
||||
return myInplaceProperties;
|
||||
}
|
||||
|
||||
@@ -260,6 +260,9 @@ public abstract class RadComponent {
|
||||
public void copyTo(Element parentElement) throws Exception {
|
||||
}
|
||||
|
||||
public void morphingTo(MetaModel target) throws Exception {
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Utils
|
||||
|
||||
Reference in New Issue
Block a user