From d44ec23a574e9bd740196eafcbf03bd068661aa7 Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Thu, 5 Apr 2012 15:49:09 +0400 Subject: [PATCH 01/10] Properties --- .../designer/model/PropertyParser.java | 114 +++++++++--------- .../designer/model/views-meta-model.xml | 4 +- .../propertyTable/AttributeProperty.java | 10 +- .../AttributePropertyWithDefault.java | 16 ++- .../CompoundDimensionProperty.java | 70 +++++++++++ .../propertyTable/CompoundProperty.java | 89 +++++++++++--- .../designer/propertyTable/FlagProperty.java | 39 +++--- .../renderers/ResourceRenderer.java | 10 +- .../intellij/designer/model/MetaModel.java | 29 ++++- .../propertyTable/IPropertyDecorator.java | 26 ++++ .../designer/propertyTable/Property.java | 8 +- 11 files changed, 312 insertions(+), 103 deletions(-) create mode 100644 plugins/android-designer/src/com/intellij/android/designer/propertyTable/CompoundDimensionProperty.java create mode 100644 plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/IPropertyDecorator.java diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/PropertyParser.java b/plugins/android-designer/src/com/intellij/android/designer/model/PropertyParser.java index a0a4c86c87ae..ba0b682c85c5 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/PropertyParser.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/PropertyParser.java @@ -18,10 +18,7 @@ package com.intellij.android.designer.model; import com.android.ide.common.rendering.api.ViewInfo; import com.android.resources.ResourceType; import com.android.sdklib.IAndroidTarget; -import com.intellij.android.designer.propertyTable.AttributeProperty; -import com.intellij.android.designer.propertyTable.AttributePropertyWithDefault; -import com.intellij.android.designer.propertyTable.CompoundProperty; -import com.intellij.android.designer.propertyTable.FlagProperty; +import com.intellij.android.designer.propertyTable.*; import com.intellij.android.designer.propertyTable.editors.ResourceDialog; import com.intellij.designer.model.MetaManager; import com.intellij.designer.model.MetaModel; @@ -138,7 +135,7 @@ public class PropertyParser { StyleableDefinition definitions = myDefinitions.getStyleableByName(component); if (definitions != null) { - Property padding = null; + boolean padding = false; for (AttributeDefinition definition : definitions.getAttributes()) { String name = definition.getName(); @@ -146,10 +143,10 @@ public class PropertyParser { Property property; if ("padding".equals(name) && "View".equals(component)) { - property = padding = new CompoundProperty(name, definition); + padding = true; } - else if (formats.contains(AttributeFormat.Flag)) { - property = new FlagProperty(name, definition, model); + if (formats.contains(AttributeFormat.Flag)) { + property = new FlagProperty(name, definition); } else { property = new AttributeProperty(name, definition); @@ -158,19 +155,21 @@ public class PropertyParser { if (model != null) { model.decorate(property, name); } - properties.add(property); } - if (padding != null) { - List children = padding.getChildren(null); - - children.add(PropertyTable.extractProperty(properties, "paddingLeft")); - children.add(PropertyTable.extractProperty(properties, "paddingTop")); - children.add(PropertyTable.extractProperty(properties, "paddingRight")); - children.add(PropertyTable.extractProperty(properties, "paddingBottom")); - children.add(PropertyTable.extractProperty(properties, "paddingStart")); - children.add(PropertyTable.extractProperty(properties, "paddingEnd")); + if (padding) { + CompoundDimensionProperty paddingProperty = new CompoundDimensionProperty("padding"); + moveProperties(properties, paddingProperty, + "padding", "all", + "paddingLeft", "left", + "paddingTop", "top", + "paddingRight", "right", + "paddingBottom", "bottom", + "paddingStart", "start", + "paddingEnd", "end"); + paddingProperty.decorate(model); + properties.add(paddingProperty); } } @@ -188,25 +187,7 @@ public class PropertyParser { properties.add(superProperty); } else { - String name = superProperty.getName(); - boolean normal = model.isNormalProperty(name); - boolean important = model.isImportantProperty(name); - boolean expert = model.isExpertProperty(name); - boolean deprecated = model.isDeprecatedProperty(name); - - if ((normal && (superProperty.isImportant() || superProperty.isExpert())) || - (important && !superProperty.isImportant()) || - (expert && !superProperty.isExpert()) || - (deprecated && !superProperty.isDeprecated())) { - Property property = superProperty.createForNewPresentation(); - property.setImportant(important); - property.setExpert(expert); - property.setDeprecated(deprecated); - properties.add(property); - } - else { - properties.add(superProperty); - } + properties.add(model.decorateWithOverride(superProperty)); } } } @@ -236,7 +217,7 @@ public class PropertyParser { StyleableDefinition definitions = myDefinitions.getStyleableByName(component); if (definitions != null) { - Property margin = null; + boolean margin = false; for (AttributeDefinition definition : definitions.getAttributes()) { String name = definition.getName(); @@ -244,7 +225,7 @@ public class PropertyParser { Set formats = definition.getFormats(); Property property; - if (name.startsWith(LAYOUT_MARGIN_PREFIX) && name.length() > LAYOUT_MARGIN_PREFIX.length()) { + if (name.startsWith(LAYOUT_MARGIN_PREFIX)) { name = name.substring(LAYOUT_PREFIX.length()); important = false; } @@ -252,45 +233,54 @@ public class PropertyParser { name = "layout:" + name.substring(LAYOUT_PREFIX.length()); } - if ("layout:margin".equals(name) && "ViewGroup_MarginLayout".equals(component)) { - property = margin = new CompoundProperty(name, definition); + if ("margin".equals(name) && "ViewGroup_MarginLayout".equals(component)) { + margin = true; } - else if ("layout:width".equals(name) || "layout:height".equals(name)) { + if ("layout:width".equals(name) || "layout:height".equals(name)) { property = new AttributePropertyWithDefault(name, definition, "wrap_content"); } else if (formats.contains(AttributeFormat.Flag)) { - property = new FlagProperty(name, definition, model); + property = new FlagProperty(name, definition); } else { property = new AttributeProperty(name, definition); } + if (model != null) { + model.decorate(property, name); + } property.setImportant(important); properties.add(property); } - if (margin != null) { - List children = margin.getChildren(null); - - PropertyTable.moveProperty(properties, "marginLeft", children, -1); - PropertyTable.moveProperty(properties, "marginTop", children, -1); - PropertyTable.moveProperty(properties, "marginRight", children, -1); - PropertyTable.moveProperty(properties, "marginBottom", children, -1); - PropertyTable.moveProperty(properties, "marginStart", children, -1); - PropertyTable.moveProperty(properties, "marginEnd", children, -1); - + if (margin) { + CompoundDimensionProperty marginProperty = new CompoundDimensionProperty("layout:margin"); + moveProperties(properties, marginProperty, + "margin", "all", + "marginLeft", "left", + "marginTop", "top", + "marginRight", "right", + "marginBottom", "bottom", + "marginStart", "start", + "marginEnd", "end"); if (model != null) { - for (Property child : children) { - model.decorate(child, "layout:margin." + child.getName()); - } + marginProperty.decorate(model); } + marginProperty.setImportant(true); + properties.add(marginProperty); } } if (++index < components.length) { for (Property property : loadLayoutProperties(components, index, model)) { if (PropertyTable.findProperty(properties, property) == -1) { - properties.add(property); + if (model == null) { + properties.add(property); + } + else { + property = model.decorateWithOverride(property); + properties.add(property); + } } } } @@ -313,6 +303,16 @@ public class PropertyParser { return properties; } + private static void moveProperties(List source, Property destination, String... names) { + List children = destination.getChildren(null); + for (int i = 0; i < names.length; i += 2) { + Property property = PropertyTable.extractProperty(source, names[i]); + if (property != null) { + children.add(property.createForNewPresentation(destination, names[i + 1])); + } + } + } + public boolean isAssignableFrom(MetaModel base, MetaModel test) { try { Class baseClass = myClassLoader.loadClass(base.getTarget()); 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 0be0e93bf296..2fd7fd6d54c7 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 @@ -1012,8 +1012,8 @@ - diff --git a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/AttributeProperty.java b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/AttributeProperty.java index 9ebc9d7c3f28..739bd12025c9 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/AttributeProperty.java +++ b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/AttributeProperty.java @@ -45,7 +45,11 @@ public class AttributeProperty extends Property { private final PropertyEditor myEditor; public AttributeProperty(@NotNull String name, @NotNull AttributeDefinition definition) { - super(null, name); + this(null, name, definition); + } + + public AttributeProperty(@Nullable Property parent, @NotNull String name, @NotNull AttributeDefinition definition) { + super(parent, name); myDefinition = definition; Set formats = definition.getFormats(); @@ -76,8 +80,8 @@ public class AttributeProperty extends Property { } @Override - public Property createForNewPresentation() { - return new AttributeProperty(getName(), myDefinition); + public Property createForNewPresentation(@Nullable Property parent, @NotNull String name) { + return new AttributeProperty(parent, name, myDefinition); } @Override diff --git a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/AttributePropertyWithDefault.java b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/AttributePropertyWithDefault.java index 2a8d41fe0818..7d42fb382bb8 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/AttributePropertyWithDefault.java +++ b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/AttributePropertyWithDefault.java @@ -16,9 +16,11 @@ package com.intellij.android.designer.propertyTable; import com.intellij.android.designer.model.RadViewComponent; +import com.intellij.designer.propertyTable.Property; import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.android.dom.attrs.AttributeDefinition; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author Alexander Lobas @@ -27,10 +29,22 @@ public class AttributePropertyWithDefault extends AttributeProperty { private final String myDefaultValue; public AttributePropertyWithDefault(@NotNull String name, @NotNull AttributeDefinition definition, @NotNull String defaultValue) { - super(name, definition); + this(null, name, definition, defaultValue); + } + + public AttributePropertyWithDefault(@Nullable Property parent, + @NotNull String name, + @NotNull AttributeDefinition definition, + @NotNull String defaultValue) { + super(parent, name, definition); myDefaultValue = defaultValue; } + @Override + public Property createForNewPresentation(@Nullable Property parent, @NotNull String name) { + return new AttributePropertyWithDefault(parent, name, myDefinition, myDefaultValue); + } + @Override public boolean isDefaultValue(RadViewComponent component) throws Exception { return myDefaultValue.equals(getValue(component)); diff --git a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/CompoundDimensionProperty.java b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/CompoundDimensionProperty.java new file mode 100644 index 000000000000..bca550170e15 --- /dev/null +++ b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/CompoundDimensionProperty.java @@ -0,0 +1,70 @@ +/* + * 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.propertyTable; + +import com.intellij.android.designer.propertyTable.renderers.ResourceRenderer; +import com.intellij.designer.propertyTable.PropertyRenderer; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.ui.SimpleTextAttributes; +import org.jetbrains.android.dom.attrs.AttributeFormat; +import org.jetbrains.annotations.NotNull; + +import java.util.EnumSet; + +/** + * @author Alexander Lobas + */ +public class CompoundDimensionProperty extends CompoundProperty { + private ResourceRenderer myRenderer = new ResourceRenderer(EnumSet.of(AttributeFormat.Dimension)) { + @Override + protected void formatValue(String value) { + myColoredComponent.append("["); + if (!StringUtil.isEmpty(value)) { + int index = 0; + for (String childValue : StringUtil.split(value, ",")) { + if (index++ > 0) { + myColoredComponent.append(", "); + } + childValue = childValue.trim(); + if (childValue.length() > 0) { + if (childValue.equals("?")) { + myColoredComponent.append("?", SimpleTextAttributes.EXCLUDED_ATTRIBUTES); + } + else { + super.formatValue(childValue); + } + } + } + } + myColoredComponent.append("]"); + } + }; + + public CompoundDimensionProperty(@NotNull String name) { + super(name); + } + + @Override + protected CompoundProperty createForNewPresentation(@NotNull String name) { + return new CompoundDimensionProperty(name); + } + + @NotNull + @Override + public PropertyRenderer getRenderer() { + return myRenderer; + } +} \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/CompoundProperty.java b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/CompoundProperty.java index 5a0b3f4936e0..4f18cb19d424 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/CompoundProperty.java +++ b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/CompoundProperty.java @@ -16,8 +16,11 @@ package com.intellij.android.designer.propertyTable; import com.intellij.android.designer.model.RadViewComponent; +import com.intellij.designer.model.MetaModel; +import com.intellij.designer.propertyTable.IPropertyDecorator; import com.intellij.designer.propertyTable.Property; -import org.jetbrains.android.dom.attrs.AttributeDefinition; +import com.intellij.designer.propertyTable.PropertyEditor; +import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,25 +30,81 @@ import java.util.List; /** * @author Alexander Lobas */ -public class CompoundProperty extends AttributeProperty { - private List myChildren = new ArrayList(); +public abstract class CompoundProperty extends Property implements IPropertyDecorator { + private List> myChildren = new ArrayList>(); - public CompoundProperty(@NotNull String name, @NotNull AttributeDefinition definition) { - super(name, definition); + public CompoundProperty(@NotNull String name) { + super(null, name); } @Override - public List getChildren(@Nullable RadViewComponent component) { - return myChildren; - } - - @Override - public Property createForNewPresentation() { - CompoundProperty property = new CompoundProperty(getName(), myDefinition); - List children = property.getChildren(null); - for (Property childProperty : myChildren) { - children.add(childProperty.createForNewPresentation()); + public Property createForNewPresentation(@Nullable Property parent, @NotNull String name) { + CompoundProperty property = createForNewPresentation(name); + List> children = property.getChildren(null); + for (Property childProperty : myChildren) { + children.add(childProperty.createForNewPresentation(property, childProperty.getName())); } return property; } + + public void decorate(@NotNull MetaModel model) { + String name = getName(); + model.decorate0(this, name); + for (Property childProperty : myChildren) { + model.decorate(childProperty, name + "." + childProperty.getName()); + } + } + + @Override + public List> getChildren(@Nullable RadViewComponent component) { + return myChildren; + } + + protected abstract CompoundProperty createForNewPresentation(@NotNull String name); + + @Override + public Object getValue(RadViewComponent component) throws Exception { + StringBuilder value = new StringBuilder(); + int index = 0; + int empty = 0; + for (Property childProperty : myChildren) { + if (index++ > 0) { + value.append(", "); + } + String childValue = (String)childProperty.getValue(component); + if (StringUtil.isEmpty(childValue)) { + empty++; + value.append("?"); + } + else { + value.append(childValue); + } + } + if (empty == myChildren.size()) { + return ""; + } + return value.toString(); + } + + @Override + public boolean isDefaultValue(RadViewComponent component) throws Exception { + for (Property childProperty : myChildren) { + if (!childProperty.isDefaultValue(component)) { + return false; + } + } + return true; + } + + @Override + public void setDefaultValue(RadViewComponent component) throws Exception { + for (Property childProperty : myChildren) { + childProperty.setDefaultValue(component); + } + } + + @Override + public PropertyEditor getEditor() { + return null; + } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FlagProperty.java b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FlagProperty.java index 6be484046935..449d3c2c6c1f 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FlagProperty.java +++ b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FlagProperty.java @@ -17,6 +17,7 @@ package com.intellij.android.designer.propertyTable; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.model.MetaModel; +import com.intellij.designer.propertyTable.IPropertyDecorator; import com.intellij.designer.propertyTable.Property; import com.intellij.designer.propertyTable.PropertyEditor; import com.intellij.designer.propertyTable.PropertyRenderer; @@ -35,39 +36,41 @@ import java.util.*; /** * @author Alexander Lobas */ -public class FlagProperty extends Property { +public class FlagProperty extends Property implements IPropertyDecorator { private final PropertyRenderer myRenderer = new LabelPropertyRenderer(null); private final AttributeDefinition myDefinition; - private final List myOptions = new ArrayList(); + private final List> myOptions = new ArrayList>(); - public FlagProperty(@NotNull String name, @NotNull AttributeDefinition definition, @Nullable MetaModel model) { + public FlagProperty(@NotNull String name, @NotNull AttributeDefinition definition) { super(null, name); myDefinition = definition; for (String option : definition.getValues()) { myOptions.add(new OptionProperty(this, option, option)); } + } - if (model != null) { - for (Property option : myOptions) { - model.decorate(option, name + "." + option.getName()); - } + @Override + public Property createForNewPresentation(@Nullable Property parent, @NotNull String name) { + return new FlagProperty(name, myDefinition); + } + + @Override + public void decorate(@NotNull MetaModel model) { + String name = getName(); + for (Property option : myOptions) { + model.decorate(option, name + "." + option.getName()); } } @Override - public Property createForNewPresentation() { - return new FlagProperty(getName(), myDefinition, null); - } - - @Override - public List getChildren(@Nullable RadViewComponent component) { + public List> getChildren(@Nullable RadViewComponent component) { return myOptions; } @Override public Object getValue(RadViewComponent component) throws Exception { - StringBuffer value = new StringBuffer("["); + StringBuilder value = new StringBuilder("["); Set options = getOptions(component); int index = 0; for (Property option : myOptions) { @@ -158,6 +161,12 @@ public class FlagProperty extends Property { }); } + ////////////////////////////////////////////////////////////////////////////////////////// + // + // Option + // + ////////////////////////////////////////////////////////////////////////////////////////// + private class OptionProperty extends Property { private PropertyRenderer myRenderer = new BooleanRenderer(); private PropertyEditor myEditor = new BooleanEditor(); @@ -173,7 +182,7 @@ public class FlagProperty extends Property { } @Override - public Property createForNewPresentation() { + public Property createForNewPresentation(@Nullable Property parent, @NotNull String name) { return null; } diff --git a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/renderers/ResourceRenderer.java b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/renderers/ResourceRenderer.java index e679288ffd3f..4288b7a7da4b 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/renderers/ResourceRenderer.java +++ b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/renderers/ResourceRenderer.java @@ -41,7 +41,7 @@ public class ResourceRenderer implements PropertyRenderer { private final ColorIcon myColorIcon = new ColorIcon(10, 9); private BooleanRenderer myBooleanRenderer; - private final SimpleColoredComponent myColoredComponent; + protected final SimpleColoredComponent myColoredComponent; private final Set myFormats; public ResourceRenderer(Set formats) { @@ -75,6 +75,12 @@ public class ResourceRenderer implements PropertyRenderer { myColoredComponent.setBackground(UIUtil.getTableBackground()); } + formatValue(value); + + return myColoredComponent; + } + + protected void formatValue(String value) { if (!StringUtil.isEmpty(value)) { int prefix = -1; if (value.startsWith("#")) { @@ -113,8 +119,6 @@ public class ResourceRenderer implements PropertyRenderer { } } } - - return myColoredComponent; } @Override diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaModel.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaModel.java index 4bb2fd945785..5b37f41b759a 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaModel.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaModel.java @@ -16,6 +16,7 @@ package com.intellij.designer.model; import com.intellij.designer.palette.Item; +import com.intellij.designer.propertyTable.IPropertyDecorator; import com.intellij.designer.propertyTable.Property; import com.intellij.openapi.util.IconLoader; import org.jetbrains.annotations.NotNull; @@ -114,10 +115,6 @@ public class MetaModel { myPaletteItem.setMetaModel(this); } - public boolean isNormalProperty(String name) { - return myNormalProperties.contains(name); - } - public void setNormalProperties(List normalProperties) { myNormalProperties = normalProperties; } @@ -146,9 +143,31 @@ public class MetaModel { myDeprecatedProperties = deprecatedProperties; } - public void decorate(Property property, String name) { + public void decorate0(Property property, String name) { property.setImportant(isImportantProperty(name)); property.setExpert(isExpertProperty(name)); property.setDeprecated(isDeprecatedProperty(name)); } + + public void decorate(Property property, String name) { + decorate0(property, name); + + if (property instanceof IPropertyDecorator) { + ((IPropertyDecorator)property).decorate(this); + } + } + + public Property decorateWithOverride(Property property) { + String name = property.getName(); + + if (myNormalProperties.contains(name) || + myImportantProperties.contains(name) || + myExpertProperties.contains(name) || + myDeprecatedProperties.contains(name)) { + property = property.createForNewPresentation(); + decorate(property, name); + } + + return property; + } } \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/IPropertyDecorator.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/IPropertyDecorator.java new file mode 100644 index 000000000000..ab422d745634 --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/IPropertyDecorator.java @@ -0,0 +1,26 @@ +/* + * 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.propertyTable; + +import com.intellij.designer.model.MetaModel; +import org.jetbrains.annotations.NotNull; + +/** + * @author Alexander Lobas + */ +public interface IPropertyDecorator { + void decorate(@NotNull MetaModel model); +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/Property.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/Property.java index eda3c2457be5..326058e67bad 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/Property.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/Property.java @@ -37,7 +37,11 @@ public abstract class Property { myName = name; } - public abstract Property createForNewPresentation(); + public Property createForNewPresentation() { + return createForNewPresentation(myParent, myName); + } + + public abstract Property createForNewPresentation(@Nullable Property parent, @NotNull String name); ////////////////////////////////////////////////////////////////////////////////////////// // // Hierarchy @@ -48,7 +52,7 @@ public abstract class Property { return myParent; } - public List getChildren(@Nullable T component) { + public List> getChildren(@Nullable T component) { return Collections.emptyList(); } From a4306589f886f6f5ce6ecf3d7f87b65986b0a839 Mon Sep 17 00:00:00 2001 From: Dmitry Boulytchev Date: Thu, 5 Apr 2012 16:44:49 +0400 Subject: [PATCH 02/10] Better storage clean-up on class removal (compile-server). --- .../ether/dependencyView/Mappings.java | 109 +++++++++++------- 1 file changed, 70 insertions(+), 39 deletions(-) diff --git a/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java b/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java index 427496953f08..f79b0a38d312 100644 --- a/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java +++ b/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java @@ -46,7 +46,7 @@ public class Mappings { private final TIntHashSet myDeletedClasses; private final Object myLock; - private void addDeletedClass (final int it) { + private void addDeletedClass(final int it) { assert (myDeletedClasses != null); myDeletedClasses.add(it); @@ -68,7 +68,7 @@ public class Mappings { } private TIntHashSet getDeletedClasses() { - return myDeletedClasses; + return myDeletedClasses; } private TIntHashSet getChangedClasses() { @@ -180,16 +180,21 @@ public class Mappings { myClassToSourceFile = new IntIntTransientMaplet(); } else { - myClassToSubclasses = new IntIntPersistentMultiMaplet(DependencyContext.getTableFile(myRootDir, CLASS_TO_SUBCLASSES), INT_KEY_DESCRIPTOR); - myClassToClassDependency = new IntIntPersistentMultiMaplet(DependencyContext.getTableFile(myRootDir, CLASS_TO_CLASS), INT_KEY_DESCRIPTOR); + myClassToSubclasses = + new IntIntPersistentMultiMaplet(DependencyContext.getTableFile(myRootDir, CLASS_TO_SUBCLASSES), INT_KEY_DESCRIPTOR); + myClassToClassDependency = + new IntIntPersistentMultiMaplet(DependencyContext.getTableFile(myRootDir, CLASS_TO_CLASS), INT_KEY_DESCRIPTOR); mySourceFileToClasses = new IntObjectPersistentMultiMaplet( - DependencyContext.getTableFile(myRootDir, SOURCE_TO_CLASS), INT_KEY_DESCRIPTOR, ClassRepr.externalizer(myContext), ourClassSetConstructor + DependencyContext.getTableFile(myRootDir, SOURCE_TO_CLASS), INT_KEY_DESCRIPTOR, ClassRepr.externalizer(myContext), + ourClassSetConstructor ); mySourceFileToAnnotationUsages = new IntObjectPersistentMultiMaplet( - DependencyContext.getTableFile(myRootDir, SOURCE_TO_ANNOTATIONS), INT_KEY_DESCRIPTOR, UsageRepr.externalizer(myContext), ourUsageSetConstructor + DependencyContext.getTableFile(myRootDir, SOURCE_TO_ANNOTATIONS), INT_KEY_DESCRIPTOR, UsageRepr.externalizer(myContext), + ourUsageSetConstructor ); mySourceFileToUsages = new IntObjectPersistentMultiMaplet( - DependencyContext.getTableFile(myRootDir, SOURCE_TO_USAGES), INT_KEY_DESCRIPTOR, UsageRepr.Cluster.clusterExternalizer(myContext), ourUsageClusterSetConstructor + DependencyContext.getTableFile(myRootDir, SOURCE_TO_USAGES), INT_KEY_DESCRIPTOR, UsageRepr.Cluster.clusterExternalizer(myContext), + ourUsageClusterSetConstructor ); myClassToSourceFile = new IntIntPersistentMaplet(DependencyContext.getTableFile(myRootDir, CLASS_TO_SOURCE), INT_KEY_DESCRIPTOR); } @@ -289,6 +294,8 @@ public class Mappings { } private void runPostPasses() { + myChangedClasses.removeAll(myDeletedClasses.toArray()); + for (final PostPass p : myPostPasses) { p.run(); } @@ -689,7 +696,8 @@ public class Mappings { debug("Affect method usage referenced of class ", p); - final UsageRepr.Usage usage = rootUsage instanceof UsageRepr.MetaMethodUsage ? method.createMetaUsage(myContext, p) : method.createUsage(myContext, p); + final UsageRepr.Usage usage = + rootUsage instanceof UsageRepr.MetaMethodUsage ? method.createMetaUsage(myContext, p) : method.createUsage(myContext, p); affectedUsages.add(usage); return true; } @@ -891,7 +899,12 @@ public class Mappings { boolean accept(File file); } - public boolean differentiate(final Mappings delta, final Collection removed, final Collection filesToCompile, final Collection compiledFiles, final Collection affectedFiles, DependentFilesFilter filter) { + public boolean differentiate(final Mappings delta, + final Collection removed, + final Collection filesToCompile, + final Collection compiledFiles, + final Collection affectedFiles, + DependentFilesFilter filter) { synchronized (myLock) { debug("Begin of Differentiate:"); @@ -1259,7 +1272,9 @@ public class Mappings { if (source > 0) { final String f = myContext.getValue(source); - debug( "Removed method is not abstract & overrides some abstract method which is not then over-overriden in subclass ", p); + debug( + "Removed method is not abstract & overrides some abstract method which is not then over-overriden in subclass ", + p); debug("Affecting subclass source file ", f); affectedFiles.add(new File(f)); } @@ -1286,7 +1301,8 @@ public class Mappings { debug("Class is annotation, default value is removed => adding annotation query"); final TIntHashSet l = new TIntHashSet(DEFAULT_SET_CAPACITY, DEFAULT_SET_LOAD_FACTOR); l.add(m.name); - annotationQuery.add((UsageRepr.AnnotationUsage)UsageRepr.createAnnotationUsage(myContext, TypeRepr.createClassType( myContext, it.name), l, null)); + annotationQuery.add((UsageRepr.AnnotationUsage)UsageRepr + .createAnnotationUsage(myContext, TypeRepr.createClassType(myContext, it.name), l, null)); } } else if (d.base() != Difference.NONE || throwsChanged) { @@ -1389,7 +1405,8 @@ public class Mappings { final int outerClass = r.outerClassName; if (!empty(outerClass) && u.fieldVisible(outerClass, f)) { - debug("Affecting inner subclass (introduced field can potentially hide surrounding class fields): ", sourceFileName); + debug("Affecting inner subclass (introduced field can potentially hide surrounding class fields): ", + sourceFileName); affectedFiles.add(new File(myContext.getValue(sourceFileName))); } } @@ -1658,6 +1675,45 @@ public class Mappings { } } + private void cleanupRemovedClass(final int className, ClassRepr cr) { + if (cr == null) { + cr = new Util().reprByName(className); + } + + if (cr != null) { + for (final int superSomething : cr.getSupers()) { + myClassToSubclasses.removeFrom(superSomething, cr.name); + } + + final int sourceFile = myClassToSourceFile.get(className); + + if (sourceFile > 0) { + final Collection clusters = mySourceFileToUsages.get(sourceFile); + + if (clusters != null) { + for (final UsageRepr.Cluster cluster : clusters) { + final Set usages = cluster.getUsages(); + if (usages != null) { + for (final UsageRepr.Usage u : usages) { + if (u instanceof UsageRepr.ClassUsage) { + final TIntHashSet residents = cluster.getResidence(u); + + if (residents != null && residents.contains(cr.name)) { + myClassToClassDependency.removeFrom(((UsageRepr.ClassUsage)u).className, cr.name); + } + } + } + } + } + } + } + } + + myClassToClassDependency.remove(className); + myClassToSubclasses.remove(className); + myClassToSourceFile.remove(className); + } + public void integrate(final Mappings delta, final Collection compiled, final Collection removed) { synchronized (myLock) { try { @@ -1671,30 +1727,7 @@ public class Mappings { if (classes != null) { for (final ClassRepr cr : classes) { - myClassToSubclasses.remove(cr.name); - myClassToSourceFile.remove(cr.name); - myClassToClassDependency.remove(cr.name); - - for (final int superSomething : cr.getSupers()) { - myClassToSubclasses.removeFrom(superSomething, cr.name); - } - - if (clusters != null) { - for (final UsageRepr.Cluster cluster : clusters) { - final Set usages = cluster.getUsages(); - if (usages != null) { - for (final UsageRepr.Usage u : usages) { - if (u instanceof UsageRepr.ClassUsage) { - final TIntHashSet residents = cluster.getResidence(u); - - if (residents != null && residents.contains(cr.name)) { - myClassToClassDependency.removeFrom(((UsageRepr.ClassUsage)u).className, cr.name); - } - } - } - } - } - } + cleanupRemovedClass(cr.name, cr); } } @@ -1708,9 +1741,7 @@ public class Mappings { delta.getDeletedClasses().forEach(new TIntProcedure() { @Override public boolean execute(int value) { - myClassToClassDependency.remove(value); - myClassToSubclasses.remove(value); - myClassToSourceFile.remove(value); + cleanupRemovedClass(value, null); return true; } }); From 46c96ffe82864b281a00f95188849035ddce9d31 Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Thu, 5 Apr 2012 16:50:38 +0400 Subject: [PATCH 03/10] Refactoring --- .../designSurface/DesignerEditorPanel.java | 110 +++++++++++------- 1 file changed, 67 insertions(+), 43 deletions(-) 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 db4db0918eb9..658d12998c2f 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 @@ -297,38 +297,6 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider add(myErrorPanel, ERROR_CARD); } - private void createProgressPanel() { - myProgressIcon = new AsyncProcessIcon("Designer progress"); - myProgressMessage = new JLabel(); - - JPanel progressBlock = new JPanel(); - progressBlock.add(myProgressIcon); - progressBlock.add(myProgressMessage); - progressBlock.setBorder(IdeBorderFactory.createRoundedBorder()); - - myProgressPanel = new JPanel(new GridBagLayout()); - myProgressPanel.add(progressBlock, - new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), - 0, 0)); - myProgressPanel.setOpaque(false); - } - - protected final void showProgress(String message) { - myProgressMessage.setText(message); - if (myProgressPanel.getParent() == null) { - myGlassLayer.setEnabled(false); - myProgressIcon.resume(); - myLayeredPane.add(myProgressPanel, LAYER_PROGRESS); - myLayeredPane.repaint(); - } - } - - protected final void hideProgress() { - myGlassLayer.setEnabled(true); - myProgressIcon.suspend(); - myLayeredPane.remove(myProgressPanel); - } - public final void showError(@NonNls String message, Throwable e) { while (e instanceof InvocationTargetException) { e = e.getCause(); @@ -375,7 +343,43 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider repaint(); } - public abstract String getPlatformTarget(); + private void createProgressPanel() { + myProgressIcon = new AsyncProcessIcon("Designer progress"); + myProgressMessage = new JLabel(); + + JPanel progressBlock = new JPanel(); + progressBlock.add(myProgressIcon); + progressBlock.add(myProgressMessage); + progressBlock.setBorder(IdeBorderFactory.createRoundedBorder()); + + myProgressPanel = new JPanel(new GridBagLayout()); + myProgressPanel.add(progressBlock, + new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), + 0, 0)); + myProgressPanel.setOpaque(false); + } + + protected final void showProgress(String message) { + myProgressMessage.setText(message); + if (myProgressPanel.getParent() == null) { + myGlassLayer.setEnabled(false); + myProgressIcon.resume(); + myLayeredPane.add(myProgressPanel, LAYER_PROGRESS); + myLayeredPane.repaint(); + } + } + + protected final void hideProgress() { + myGlassLayer.setEnabled(true); + myProgressIcon.suspend(); + myLayeredPane.remove(myProgressPanel); + } + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // + // + ////////////////////////////////////////////////////////////////////////////////////////// @NotNull public Module getModule() { @@ -395,9 +399,24 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider return treeArea == null ? mySurfaceArea : treeArea; } - public void updateTreeArea(EditableArea area) { + public ToolProvider getToolProvider() { + return myToolProvider; } + public DesignerActionPanel getActionPanel() { + return myActionPanel; + } + + public JComponent getPreferredFocusedComponent() { + return myDesignerCard.isVisible() ? myGlassLayer : myErrorPanel; + } + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // State + // + ////////////////////////////////////////////////////////////////////////////////////////// + @Nullable public List getExpandedComponents() { return myExpandedComponents; @@ -485,12 +504,15 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider } } - public ToolProvider getToolProvider() { - return myToolProvider; - } + ////////////////////////////////////////////////////////////////////////////////////////// + // + // + // + ////////////////////////////////////////////////////////////////////////////////////////// - public DesignerActionPanel getActionPanel() { - return myActionPanel; + public abstract String getPlatformTarget(); + + public void updateTreeArea(EditableArea area) { } protected abstract ComponentDecorator getRootSelectionDecorator(); @@ -534,10 +556,6 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider Disposer.dispose(myProgressIcon); } - public JComponent getPreferredFocusedComponent() { - return myDesignerCard.isVisible() ? myGlassLayer : myErrorPanel; - } - public RadComponent getRootComponent() { return myRootComponent; } @@ -548,6 +566,12 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider public abstract TreeComponentDecorator getTreeDecorator(); + ////////////////////////////////////////////////////////////////////////////////////////// + // + // + // + ////////////////////////////////////////////////////////////////////////////////////////// + private static final class FillLayout implements LayoutManager2 { @Override public void addLayoutComponent(Component comp, Object constraints) { From 4a10bc4d52ef9b97c55fb93acbc34f12248d7bb0 Mon Sep 17 00:00:00 2001 From: Anna Bulenkova Date: Thu, 5 Apr 2012 09:42:14 +0200 Subject: [PATCH 04/10] RubyRegExpRangeProvider --- .../intention/CheckRegExpIntentionAction.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/RegExpSupport/src/org/intellij/lang/regexp/intention/CheckRegExpIntentionAction.java b/RegExpSupport/src/org/intellij/lang/regexp/intention/CheckRegExpIntentionAction.java index ba340f3b1c4b..da762fd5a68d 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/intention/CheckRegExpIntentionAction.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/intention/CheckRegExpIntentionAction.java @@ -16,6 +16,7 @@ package org.intellij.lang.regexp.intention; import com.intellij.codeInsight.intention.impl.QuickEditAction; +import com.intellij.lang.Language; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; @@ -43,23 +44,28 @@ public class CheckRegExpIntentionAction extends QuickEditAction implements Icona @Override protected Pair getRangePair(PsiFile file, Editor editor) { Pair pair = super.getRangePair(file, editor); - if (pair != null) return pair; - RegExpRangeProvider[] rangeProviders = RegExpRangeProvider.EP_NAME.getExtensions(); - PsiElement element = PsiUtilBase.getElementAtCaret(editor); - for (RegExpRangeProvider provider : rangeProviders) { - TextRange range = provider.getTextRange(element); - if (range != null) { - return Pair.create(element, range); + + if (pair == null) { + RegExpRangeProvider[] rangeProviders = RegExpRangeProvider.EP_NAME.getExtensions(); + PsiElement element = PsiUtilBase.getElementAtCaret(editor); + for (RegExpRangeProvider provider : rangeProviders) { + pair = provider.getRangePair(element); + if (pair != null) break; } } - return null; + return pair; } @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { final Pair pair = getRangePair(file, editor); /*super.isAvailable(project, editor, file) && */ - return pair != null && pair.first != null && pair.first.getLanguage() == RegExpLanguage.INSTANCE; + if (pair != null && pair.first != null) { + Language language = pair.first.getLanguage(); + Language baseLanguage = language.getBaseLanguage(); + return language == RegExpLanguage.INSTANCE || baseLanguage == RegExpLanguage.INSTANCE; + } + return false; } @Override From 396ccdb89314781cd465abb80841596945db56d9 Mon Sep 17 00:00:00 2001 From: Anna Bulenkova Date: Thu, 5 Apr 2012 09:43:59 +0200 Subject: [PATCH 05/10] Check regexp intention action language detection fix --- .../src/org/intellij/lang/regexp/RegExpRangeProvider.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpRangeProvider.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpRangeProvider.java index aa820b4a0012..9407752e3e63 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/RegExpRangeProvider.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpRangeProvider.java @@ -16,6 +16,7 @@ package org.intellij.lang.regexp; import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; @@ -25,5 +26,5 @@ import com.intellij.psi.PsiElement; public interface RegExpRangeProvider { ExtensionPointName EP_NAME = new ExtensionPointName("com.intellij.regExpRangeProvider"); - TextRange getTextRange(PsiElement element); + Pair getRangePair(PsiElement element); } From 8db3d24782a717749bce1456fb19bb28d57abc49 Mon Sep 17 00:00:00 2001 From: Dmitry Boulytchev Date: Thu, 5 Apr 2012 17:20:10 +0400 Subject: [PATCH 06/10] Better storage clean-up on class removal yet again (compile-server). --- .../org/jetbrains/ether/dependencyView/Mappings.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java b/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java index f79b0a38d312..c976b3631cd7 100644 --- a/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java +++ b/jps/model/src/org/jetbrains/ether/dependencyView/Mappings.java @@ -1675,9 +1675,9 @@ public class Mappings { } } - private void cleanupRemovedClass(final int className, ClassRepr cr) { + private void cleanupRemovedClass(final int className, ClassRepr cr, Collection clusters) { if (cr == null) { - cr = new Util().reprByName(className); + cr = new Util().reprByName(className); } if (cr != null) { @@ -1688,7 +1688,9 @@ public class Mappings { final int sourceFile = myClassToSourceFile.get(className); if (sourceFile > 0) { - final Collection clusters = mySourceFileToUsages.get(sourceFile); + if (clusters == null) { + clusters = mySourceFileToUsages.get(sourceFile); + } if (clusters != null) { for (final UsageRepr.Cluster cluster : clusters) { @@ -1727,7 +1729,7 @@ public class Mappings { if (classes != null) { for (final ClassRepr cr : classes) { - cleanupRemovedClass(cr.name, cr); + cleanupRemovedClass(cr.name, cr, clusters); } } @@ -1741,7 +1743,7 @@ public class Mappings { delta.getDeletedClasses().forEach(new TIntProcedure() { @Override public boolean execute(int value) { - cleanupRemovedClass(value, null); + cleanupRemovedClass(value, null, null); return true; } }); From 7be210a3d547ece56297ddb1cb15fbf078a09c97 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 5 Apr 2012 15:31:17 +0200 Subject: [PATCH 07/10] do not create empty arrays --- .../cvsSupport2/cvsBrowser/CvsElement.java | 9 +++++- .../cvsSupport2/cvsBrowser/CvsTree.java | 32 ++++++++++++------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsBrowser/CvsElement.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsBrowser/CvsElement.java index 5110486ae531..0c9482ed21b3 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsBrowser/CvsElement.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsBrowser/CvsElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * 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. @@ -26,6 +26,8 @@ import java.util.*; public class CvsElement extends DefaultMutableTreeNode implements Comparable{ + public static final CvsElement[] EMPTY_ARRAY = {}; + protected RemoteResourceDataProvider myDataProvider; protected String myPath; protected final String myName; @@ -70,18 +72,22 @@ public class CvsElement extends DefaultMutableTreeNode implements Comparable 0; @@ -91,6 +97,7 @@ public class CvsElement extends DefaultMutableTreeNode implements Comparable { - private CvsElement[] myCurrentSelection = new CvsElement[0]; + private CvsElement[] myCurrentSelection = CvsElement.EMPTY_ARRAY; private Tree myTree; private DefaultTreeModel myModel; private CvsRootConfiguration myCvsRootConfiguration = null; @@ -60,8 +60,8 @@ public class CvsTree extends JPanel implements CvsTabbedWindow.DeactivateListene @NonNls public static final String SELECTION_CHANGED = "Selection Changed"; - public CvsTree(Project project, boolean allowRootSelection, @JdkConstants.TreeSelectionMode int selectionMode, boolean showModules, boolean showFiles, - Consumer errorCallback) { + public CvsTree(Project project, boolean allowRootSelection, @JdkConstants.TreeSelectionMode int selectionMode, + boolean showModules, boolean showFiles, Consumer errorCallback) { super(new BorderLayout()); myProject = project; mySelectionMode = selectionMode; @@ -75,6 +75,7 @@ public class CvsTree extends JPanel implements CvsTabbedWindow.DeactivateListene private void addSelectionListener() { myTree.addTreeSelectionListener(new TreeSelectionListener() { + @Override public void valueChanged(TreeSelectionEvent e) { setCurrentSelection(myTree.getSelectionPaths()); } @@ -91,12 +92,12 @@ public class CvsTree extends JPanel implements CvsTabbedWindow.DeactivateListene } private void setCurrentSelection(TreePath[] paths) { - ArrayList selection = new ArrayList(); + final ArrayList selection = new ArrayList(); if (paths != null) { for (TreePath path : paths) { - Object selectedObject = path.getLastPathComponent(); + final Object selectedObject = path.getLastPathComponent(); if (!(selectedObject instanceof CvsElement)) continue; - CvsElement cvsElement = (CvsElement)selectedObject; + final CvsElement cvsElement = (CvsElement)selectedObject; if (cvsElement.getElementPath().equals(".") && !myAllowRootSelection) continue; selection.add(cvsElement); } @@ -109,8 +110,8 @@ public class CvsTree extends JPanel implements CvsTabbedWindow.DeactivateListene if (myCvsRootConfiguration == null) { return new DefaultMutableTreeNode(); } - String rootName = myCvsRootConfiguration.toString(); - CvsElement result = CvsElementFactory.FOLDER_ELEMENT_FACTORY.createElement(rootName, myCvsRootConfiguration, project); + final String rootName = myCvsRootConfiguration.toString(); + final CvsElement result = CvsElementFactory.FOLDER_ELEMENT_FACTORY.createElement(rootName, myCvsRootConfiguration, project); result.setDataProvider(new RootDataProvider(myCvsRootConfiguration)); result.setPath("."); result.cannotBeCheckedOut(); @@ -135,7 +136,7 @@ public class CvsTree extends JPanel implements CvsTabbedWindow.DeactivateListene } public void init() { - TreeNode root = createRoot(myProject); + final TreeNode root = createRoot(myProject); myModel = new DefaultTreeModel(root, true); myTree = new Tree(myModel); add(ScrollPaneFactory.createScrollPane(myTree), BorderLayout.CENTER); @@ -144,7 +145,7 @@ public class CvsTree extends JPanel implements CvsTabbedWindow.DeactivateListene myTree.setCellRenderer(new Cvs2Renderer()); addSelectionListener(); - TreeUIHelper uiHelper = TreeUIHelper.getInstance(); + final TreeUIHelper uiHelper = TreeUIHelper.getInstance(); uiHelper.installTreeSpeedSearch(myTree); TreeUtil.installActions(myTree); @@ -152,6 +153,7 @@ public class CvsTree extends JPanel implements CvsTabbedWindow.DeactivateListene } private static class AlwaysNotifiedObservable extends Observable{ + @Override public void notifyObservers(Object arg) { setChanged(); super.notifyObservers(arg); @@ -174,6 +176,7 @@ public class CvsTree extends JPanel implements CvsTabbedWindow.DeactivateListene } } + @Override public void deactivated() { mySelectionObservable.deleteObservers(); synchronized (myListeners) { @@ -191,6 +194,7 @@ public class CvsTree extends JPanel implements CvsTabbedWindow.DeactivateListene final Application application = ApplicationManager.getApplication(); final ModalityState modalityState = application.getCurrentModalityState(); application.executeOnPooledThread(new Runnable() { + @Override public void run() { final RemoteResourceDataProvider dataProvider = element.getDataProvider(); dataProvider.fillContentFor(new MyGetContentCallback(element, modalityState, myProject), myErrorCallback); @@ -240,18 +244,22 @@ public class CvsTree extends JPanel implements CvsTabbedWindow.DeactivateListene return myModalityState; } + @Override public void deactivated() { if (myListener != null) { myListener.indirectCancel(); } } + @Override public void useForCancel(final CvsListenerWithProgress listener) { myListener = listener; } + @Override public void appendDirectoryContent(final DirectoryContent directoryContent) { ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override public void run() { final TreePath selectionPath = myTree.getSelectionPath(); if (selectionPath != null) { @@ -286,9 +294,11 @@ public class CvsTree extends JPanel implements CvsTabbedWindow.DeactivateListene } } + @Override public void finished() { removeListener(this); ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override public void run() { myLoadingNodeManager.removeFrom(myParentNode); myParentNode.setLoading(false); From eb28850e65dd4fba28517cdd499f2738722180aa Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 5 Apr 2012 15:32:03 +0200 Subject: [PATCH 08/10] adapter --- .../CvsOperationExecutorCallback.java | 13 ++------ .../DefaultCvsOperationExecutorCallback.java | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/DefaultCvsOperationExecutorCallback.java diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/CvsOperationExecutorCallback.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/CvsOperationExecutorCallback.java index b41a2782845d..7111ca2747c5 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/CvsOperationExecutorCallback.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/CvsOperationExecutorCallback.java @@ -21,18 +21,9 @@ package com.intellij.cvsSupport2.cvsExecution; */ public interface CvsOperationExecutorCallback { - CvsOperationExecutorCallback EMPTY = new CvsOperationExecutorCallback(){ - public void executionFinished(boolean successfully) { - } - - public void executionFinishedSuccessfully() { - } - - public void executeInProgressAfterAction(ModalityContext modaityContext) { - } - }; + CvsOperationExecutorCallback EMPTY = new DefaultCvsOperationExecutorCallback(); void executionFinished(boolean successfully); void executionFinishedSuccessfully(); - void executeInProgressAfterAction(ModalityContext modaityContext); + void executeInProgressAfterAction(ModalityContext modalityContext); } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/DefaultCvsOperationExecutorCallback.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/DefaultCvsOperationExecutorCallback.java new file mode 100644 index 000000000000..db2d80901297 --- /dev/null +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsExecution/DefaultCvsOperationExecutorCallback.java @@ -0,0 +1,31 @@ +/* + * 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.cvsSupport2.cvsExecution; + +/** +* @author Bas Leijdekkers +*/ +public class DefaultCvsOperationExecutorCallback implements CvsOperationExecutorCallback { + + public void executionFinished(boolean successfully) { + } + + public void executionFinishedSuccessfully() { + } + + public void executeInProgressAfterAction(ModalityContext modaityContext) { + } +} From 0f8a57f026e23079a305409b9828ef7cca3c5efd Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Thu, 5 Apr 2012 17:48:17 +0400 Subject: [PATCH 09/10] IDEA-83502 fix 'export unsigned package' wizard ui on mac --- .../exportSignedPackage/ExportSignedPackageWizard.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/android/src/org/jetbrains/android/exportSignedPackage/ExportSignedPackageWizard.java b/plugins/android/src/org/jetbrains/android/exportSignedPackage/ExportSignedPackageWizard.java index acd32ff25120..923dbb45b160 100644 --- a/plugins/android/src/org/jetbrains/android/exportSignedPackage/ExportSignedPackageWizard.java +++ b/plugins/android/src/org/jetbrains/android/exportSignedPackage/ExportSignedPackageWizard.java @@ -21,6 +21,7 @@ import com.intellij.ide.wizard.CommitStepException; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.util.SystemInfo; import org.jetbrains.android.facet.AndroidFacet; import org.jetbrains.android.util.AndroidBundle; import org.jetbrains.annotations.NotNull; @@ -53,7 +54,8 @@ public class ExportSignedPackageWizard extends AbstractWizard 0; - if (facets.size() > 1) { + if (facets.size() > 1 || + SystemInfo.isMac /* wizards with only step are shown incorrectly on mac */) { addStep(new ChooseModuleStep(this, facets)); } else { From 129a4f74b0d7d88751a6cc114a6ee8ee86620639 Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Thu, 5 Apr 2012 17:49:42 +0400 Subject: [PATCH 10/10] IDEA-83980 replace apostrophes and quotes in application name --- .../android/intentions/AndroidAddStringResourceAction.java | 2 +- .../jetbrains/android/newProject/AndroidModuleBuilder.java | 7 +++++-- .../org/jetbrains/android/util/AndroidResourceUtil.java | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/android/src/org/jetbrains/android/intentions/AndroidAddStringResourceAction.java b/plugins/android/src/org/jetbrains/android/intentions/AndroidAddStringResourceAction.java index 428c40d72d73..47d47568c64e 100644 --- a/plugins/android/src/org/jetbrains/android/intentions/AndroidAddStringResourceAction.java +++ b/plugins/android/src/org/jetbrains/android/intentions/AndroidAddStringResourceAction.java @@ -184,7 +184,7 @@ public class AndroidAddStringResourceAction extends AbstractIntentionAction impl final AndroidFacet facet = AndroidFacet.getInstance(file); assert facet != null; - value = value.replace("'", "\\'").replace("\"", "\\\""); + value = AndroidResourceUtil.normalizeXmlResourceValue(value); final String aPackage = getPackage(facet); if (aPackage == null) { diff --git a/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleBuilder.java b/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleBuilder.java index 8d98f268d299..525c75c81bd5 100644 --- a/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleBuilder.java +++ b/plugins/android/src/org/jetbrains/android/newProject/AndroidModuleBuilder.java @@ -67,6 +67,7 @@ import org.jetbrains.android.sdk.AndroidPlatform; import org.jetbrains.android.sdk.AndroidSdkUtils; import org.jetbrains.android.util.AndroidBundle; import org.jetbrains.android.util.AndroidCommonUtils; +import org.jetbrains.android.util.AndroidResourceUtil; import org.jetbrains.android.util.AndroidUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -418,11 +419,13 @@ public class AndroidModuleBuilder extends JavaModuleBuilder { } } + final String normalizedAppName = AndroidResourceUtil.normalizeXmlResourceValue(myApplicationName); + if (appNameResElement == null) { - manager.addValueResource("string", appNameResource, myApplicationName); + manager.addValueResource("string", appNameResource, normalizedAppName); } else { - appNameResElement.setStringValue(myApplicationName); + appNameResElement.setStringValue(normalizedAppName); } final Manifest manifest = facet.getManifest(); diff --git a/plugins/android/src/org/jetbrains/android/util/AndroidResourceUtil.java b/plugins/android/src/org/jetbrains/android/util/AndroidResourceUtil.java index 53e348ad7f02..602bff3ea171 100644 --- a/plugins/android/src/org/jetbrains/android/util/AndroidResourceUtil.java +++ b/plugins/android/src/org/jetbrains/android/util/AndroidResourceUtil.java @@ -60,6 +60,11 @@ public class AndroidResourceUtil { private AndroidResourceUtil() { } + @NotNull + public static String normalizeXmlResourceValue(@NotNull String value) { + return value.replace("'", "\\'").replace("\"", "\\\""); + } + static { REFERRABLE_RESOURCE_TYPES.addAll(Arrays.asList(ResourceType.values())); REFERRABLE_RESOURCE_TYPES.remove(ResourceType.ATTR);