summaryrefslogtreecommitdiff
path: root/designer
diff options
context:
space:
mode:
authorJens Ole Lauridsen <jlauridsen@google.com>2015-06-30 15:50:07 -0700
committerDeepanshu Gupta <deepanshu@google.com>2015-07-13 17:39:16 -0700
commita63df1d142a63fe353ac1355a4af627ecc04639a (patch)
tree5e2ada049c9d98858e3f006b6e267c40d4cb15fc /designer
parent6bd74671be35d9950ddcba74f0a05adc517609a5 (diff)
downloadidea-a63df1d142a63fe353ac1355a4af627ecc04639a.tar.gz
Nele: Use a queue for displaying updates in the structure pane.
The user should not wait for the structure pane to update for every change made in the designer. Change-Id: I2360a0497d476b62787285481ac9d94d82ddb281 (cherry picked from commit b9fa097032d0baf9f7915220c6a490202700859c)
Diffstat (limited to 'designer')
-rw-r--r--designer/src/com/android/tools/idea/uibuilder/property/NlPropertiesPanel.java4
-rw-r--r--designer/src/com/android/tools/idea/uibuilder/structure/NlStructurePanel.java54
2 files changed, 39 insertions, 19 deletions
diff --git a/designer/src/com/android/tools/idea/uibuilder/property/NlPropertiesPanel.java b/designer/src/com/android/tools/idea/uibuilder/property/NlPropertiesPanel.java
index b634df4b9dc..55ebcc6aea1 100644
--- a/designer/src/com/android/tools/idea/uibuilder/property/NlPropertiesPanel.java
+++ b/designer/src/com/android/tools/idea/uibuilder/property/NlPropertiesPanel.java
@@ -41,6 +41,8 @@ import java.util.Collections;
import java.util.List;
public class NlPropertiesPanel extends JPanel implements DesignSurfaceListener {
+ public final static int UPDATE_DELAY_MSECS = 250;
+
private final PTable myTable;
private final NlPropertiesModel myModel;
private DesignSurface mySurface;
@@ -146,7 +148,7 @@ public class NlPropertiesPanel extends JPanel implements DesignSurfaceListener {
ApplicationManager.getApplication().assertIsDispatchThread();
if (myUpdateQueue == null) {
- myUpdateQueue = new MergingUpdateQueue("android.layout.propertysheet", 250, true, null, mySurface, null,
+ myUpdateQueue = new MergingUpdateQueue("android.layout.propertysheet", UPDATE_DELAY_MSECS, true, null, mySurface, null,
Alarm.ThreadToUse.SWING_THREAD);
}
return myUpdateQueue;
diff --git a/designer/src/com/android/tools/idea/uibuilder/structure/NlStructurePanel.java b/designer/src/com/android/tools/idea/uibuilder/structure/NlStructurePanel.java
index a5767820793..fc91009ec97 100644
--- a/designer/src/com/android/tools/idea/uibuilder/structure/NlStructurePanel.java
+++ b/designer/src/com/android/tools/idea/uibuilder/structure/NlStructurePanel.java
@@ -34,6 +34,8 @@ import com.intellij.ui.ScrollPaneFactory;
import com.intellij.util.IJSwingUtilities;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.tree.TreeUtil;
+import com.intellij.util.ui.update.MergingUpdateQueue;
+import com.intellij.util.ui.update.Update;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
@@ -52,6 +54,8 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.android.SdkConstants.*;
+import static com.android.tools.idea.uibuilder.property.NlPropertiesPanel.UPDATE_DELAY_MSECS;
+import static com.intellij.util.Alarm.ThreadToUse.SWING_THREAD;
import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
@@ -63,6 +67,7 @@ public class NlStructurePanel extends JPanel implements LightToolWindowContent,
private final Map<XmlTag, DefaultMutableTreeNode> myTag2Node;
private final AtomicBoolean mySelectionIsUpdating;
private final NlPropertiesPanel myPropertiesPanel;
+ private final MergingUpdateQueue myUpdateQueue;
private NlModel myModel;
private boolean myWasExpanded;
@@ -74,6 +79,8 @@ public class NlStructurePanel extends JPanel implements LightToolWindowContent,
mySelectionIsUpdating = new AtomicBoolean(false);
JScrollPane pane = ScrollPaneFactory.createScrollPane(myTree, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER);
myPropertiesPanel = new NlPropertiesPanel(designSurface);
+ myUpdateQueue = new MergingUpdateQueue(
+ "android.layout.structure-pane", UPDATE_DELAY_MSECS, true, null, designSurface, null, SWING_THREAD);
Splitter splitter = new Splitter(true, 0.4f);
splitter.setFirstComponent(pane);
splitter.setSecondComponent(myPropertiesPanel);
@@ -85,8 +92,7 @@ public class NlStructurePanel extends JPanel implements LightToolWindowContent,
public void setDesignSurface(@Nullable DesignSurface designSurface) {
myPropertiesPanel.setDesignSurface(designSurface);
- setModel(designSurface != null && designSurface.getCurrentScreenView() != null
- ? designSurface.getCurrentScreenView().getModel() : null);
+ setModel(designSurface != null && designSurface.getCurrentScreenView() != null ? designSurface.getCurrentScreenView().getModel() : null);
}
private void setModel(@Nullable NlModel model) {
@@ -157,27 +163,39 @@ public class NlStructurePanel extends JPanel implements LightToolWindowContent,
}
private void loadData() {
- try {
- mySelectionIsUpdating.set(true);
- myWasExpanded = false;
- myTag2Node.clear();
- updateHierarchy();
- } finally {
- mySelectionIsUpdating.set(false);
- }
- updateSelection();
+ updateHierarchy(true);
}
private void invalidateUI() {
IJSwingUtilities.updateComponentTreeUI(myTree);
}
- private void updateHierarchy() {
- DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode)myTree.getModel().getRoot();
- List<NlComponent> components = myModel != null ? myModel.getComponents() : null;
- replaceChildNodes(rootNode, components);
- expandOnce();
- invalidateUI();
+ private void updateHierarchy(final boolean firstLoad) {
+ ApplicationManager.getApplication().assertIsDispatchThread();
+ myTree.setPaintBusy(true);
+ myUpdateQueue.queue(new Update("updateComponentStructure") {
+ @Override
+ public void run() {
+ try {
+ mySelectionIsUpdating.set(true);
+ if (firstLoad) {
+ myWasExpanded = false;
+ myTag2Node.clear();
+ }
+ DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode)myTree.getModel().getRoot();
+ List<NlComponent> components = myModel != null ? myModel.getComponents() : null;
+ replaceChildNodes(rootNode, components);
+ expandOnce();
+ invalidateUI();
+ } finally {
+ myTree.setPaintBusy(false);
+ mySelectionIsUpdating.set(false);
+ }
+ if (firstLoad) {
+ updateSelection();
+ }
+ }
+ });
}
private void replaceChildNodes(@NonNull DefaultMutableTreeNode node, @Nullable List<NlComponent> subComponents) {
@@ -304,7 +322,7 @@ public class NlStructurePanel extends JPanel implements LightToolWindowContent,
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
- updateHierarchy();
+ updateHierarchy(false);
}
});
}