This commit is contained in:
Alexander Lobas
2012-05-17 15:07:18 +04:00
parent 7a75131e25
commit 3bbe6867b5
9 changed files with 78 additions and 94 deletions
@@ -16,7 +16,6 @@
package com.intellij.android.designer.designSurface;
import com.android.ide.common.rendering.api.RenderSession;
import com.android.ide.common.rendering.api.Result;
import com.android.ide.common.resources.configuration.*;
import com.android.sdklib.IAndroidTarget;
import com.intellij.android.designer.actions.ProfileAction;
@@ -24,11 +23,13 @@ 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.RadViewComponent;
import com.intellij.android.designer.model.viewAnimator.RadViewAnimatorLayout;
import com.intellij.android.designer.profile.ProfileManager;
import com.intellij.designer.DesignerToolWindowManager;
import com.intellij.designer.componentTree.TreeComponentDecorator;
import com.intellij.designer.designSurface.*;
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.selection.NonResizeSelectionDecorator;
import com.intellij.designer.designSurface.tools.ComponentCreationFactory;
import com.intellij.designer.designSurface.tools.ComponentPasteFactory;
@@ -38,7 +39,6 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
@@ -57,7 +57,6 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.lang.reflect.Method;
import java.util.List;
/**
@@ -112,71 +111,6 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
});
}
@Override
public void updateTreeArea(EditableArea area) {
area.addSelectionListener(new ComponentSelectionListener() {
@Override
public void selectionChanged(EditableArea area) {
List<RadComponent> 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();
// XXX
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.revalidate();
DesignerToolWindowManager.getInstance(getProject()).refresh(true);
}
}
catch (Throwable e) {
showError("Render error", e);
}
}
}, new Condition() {
@Override
public boolean value(Object o) {
return mySession == null;
}
}
);
}
}
}
});
}
private void reparseFile() {
try {
storeState();
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

@@ -37,7 +37,7 @@ public class IdManager {
public void addComponent(RadViewComponent component) {
String id = component.getId();
if (id != null) {
if (id != null && !id.startsWith("@android:id/")) {
myIdList.add(id);
}
}
@@ -71,18 +71,18 @@ public class IdManager {
return newId;
}
public void ensurePasteIds(final RadViewComponent component) {
public void ensureIds(final RadViewComponent container) {
// TODO: rename all references
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
component.accept(new RadComponentVisitor() {
container.accept(new RadComponentVisitor() {
@Override
public void endVisit(RadComponent component) {
RadViewComponent viewComponent = (RadViewComponent)component;
String idValue = viewComponent.getId();
if (idValue != null && myIdList.contains(idValue)) {
if (component == container || (idValue != null && myIdList.contains(idValue))) {
createId(viewComponent);
}
}
@@ -179,21 +179,20 @@ public class ModelParser extends XmlRecursiveElementVisitor {
public String compute() {
return newComponent.getMetaModel().getCreation();
}
}, true);
});
PropertyParser propertyParser = container.getRoot().getClientProperty(PropertyParser.KEY);
propertyParser.load(newComponent);
if (!newComponent.getTag().isEmpty()) {
MetaManager metaManager = ViewsMetaManager.getInstance(newComponent.getTag().getProject());
IdManager idManager = container.getRoot().getClientProperty(IdManager.KEY);
addComponent(newComponent, metaManager, idManager, propertyParser);
addComponent(newComponent, ViewsMetaManager.getInstance(newComponent.getTag().getProject()), propertyParser);
}
IdManager.get(container).ensureIds(newComponent);
}
private static void addComponent(RadViewComponent parentComponent,
MetaManager metaManager,
IdManager idManager,
PropertyParser propertyParser) throws Exception {
for (XmlTag tag : parentComponent.getTag().getSubTags()) {
MetaModel metaModel = metaManager.getModelByTag(tag.getName());
@@ -203,11 +202,10 @@ public class ModelParser extends XmlRecursiveElementVisitor {
RadViewComponent component = createComponent(tag, metaModel);
idManager.addComponent(component);
parentComponent.add(component, null);
propertyParser.load(component);
addComponent(component, metaManager, idManager, propertyParser);
addComponent(component, metaManager, propertyParser);
}
}
@@ -218,7 +216,7 @@ public class ModelParser extends XmlRecursiveElementVisitor {
PropertyParser propertyParser = container.getRoot().getClientProperty(PropertyParser.KEY);
pasteComponent(newComponent, container.getTag(), insertBefore == null ? null : insertBefore.getTag(), propertyParser);
IdManager.get(container).ensurePasteIds(newComponent);
IdManager.get(container).ensureIds(newComponent);
}
private static void pasteComponent(final RadViewComponent component,
@@ -262,7 +260,7 @@ public class ModelParser extends XmlRecursiveElementVisitor {
return builder.append("/>").toString();
}
}, false);
});
XmlTag xmlTag = component.getTag();
List<RadComponent> children = component.getChildren();
@@ -284,8 +282,7 @@ public class ModelParser extends XmlRecursiveElementVisitor {
public static void addComponentTag(final XmlTag parentTag,
final RadViewComponent component,
final XmlTag nextTag,
final Computable<String> tagBuilder,
final boolean createId) {
final Computable<String> tagBuilder) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
@@ -323,10 +320,6 @@ public class ModelParser extends XmlRecursiveElementVisitor {
}
component.setTag(xmlTag);
if (createId) {
component.ensureId();
}
}
});
}
@@ -92,6 +92,9 @@ public class RadViewComponent extends RadVisualComponent {
if (StringUtil.isEmpty(idValue)) {
return null;
}
if (idValue.startsWith("@android:id/")) {
return idValue;
}
return "@id/" + idValue.substring(idValue.indexOf('/') + 1);
}
@@ -1230,6 +1230,64 @@
</creation>
</meta>
<meta model="com.intellij.android.designer.model.RadViewComponent"
layout="com.intellij.android.designer.model.RadViewLayout"
class="android.widget.TabHost"
tag="TabHost">
<palette title="TabHost" icon="/com/intellij/android/designer/icons/TabHost.png"
tooltip="Container for a tabbed window view. This object holds two children: a set of tab labels that the user clicks to select a specific tab, and a FrameLayout object that displays the contents of that page. The individual elements are typically controlled using this container object, rather than setting values on the child elements themselves."/>
<creation>
<![CDATA[
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
]]>
</creation>
</meta>
<meta model="com.intellij.android.designer.model.RadViewComponent"
class="android.widget.TabWidget"
tag="TabWidget">
<palette title="TabWidget" icon="/com/intellij/android/designer/icons/TabWidget.png"/>
<properties important="divider tabStripEnabled tabStripLeft tabStripRight tabLayout"/>
</meta>
<!-- ================= Palette ================= -->
<palette>
@@ -1283,6 +1341,7 @@
<item tag="RadioGroup"/>
<item tag="ListView"/>
<item tag="GridView"/>
<item tag="TabHost"/>
<item tag="Gallery"/>
<item tag="Spinner"/>
<item tag="ExpandableListView"/>
@@ -45,8 +45,6 @@ public final class ComponentTreeBuilder extends AbstractTreeBuilder implements C
new TreeDropListener(tree, myTreeArea, designer.getToolProvider());
designer.updateTreeArea(myTreeArea);
selectFromSurface();
expandFromState();
@@ -637,9 +637,6 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider
public abstract String getPlatformTarget();
public void updateTreeArea(EditableArea area) {
}
protected abstract ComponentDecorator getRootSelectionDecorator();
@Nullable