diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaChainLookupElement.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaChainLookupElement.java index 83243e975e63..d76684f2c04b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaChainLookupElement.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaChainLookupElement.java @@ -130,7 +130,9 @@ public class JavaChainLookupElement extends LookupElementDecorator base = JavaSmartCompletionContributor.completeReference(element, reference, filter, false, true, parameters.getParameters(), null); - for (final LookupElement item : base) { - addSingleArrayElementAccess(element, item, parameters, result); + for (final LookupElement item : new LinkedHashSet(base)) { + ExpressionLookupItem access = getSingleArrayElementAccess(element, item); + if (access != null) { + base.add(access); + PsiType type = access.getType(); + if (type != null && parameters.getExpectedType().isAssignableFrom(type)) { + result.consume(access); + } + } } if (secondTime) { @@ -218,24 +223,25 @@ public class ReferenceExpressionCompletionContributor { return used; } - private static void addSingleArrayElementAccess(PsiElement element, LookupElement item, JavaSmartCompletionParameters parameters, - Consumer result) { + @Nullable + private static ExpressionLookupItem getSingleArrayElementAccess(PsiElement element, LookupElement item) { if (item.getObject() instanceof PsiLocalVariable) { final PsiLocalVariable variable = (PsiLocalVariable)item.getObject(); final PsiType type = variable.getType(); - if (type instanceof PsiArrayType && parameters.getExpectedType().isAssignableFrom(((PsiArrayType)type).getComponentType())) { - final PsiExpression expression = variable.getInitializer(); - if (expression instanceof PsiNewExpression) { - final PsiNewExpression newExpression = (PsiNewExpression)expression; - final PsiExpression[] dimensions = newExpression.getArrayDimensions(); - if (dimensions.length == 1 && "1".equals(dimensions[0].getText()) && newExpression.getArrayInitializer() == null) { - final String text = variable.getName() + "[0]"; - final PsiExpression conversion = createExpression(text, element); - result.consume(new ExpressionLookupItem(conversion).setIcon(variable.getIcon(Iconable.ICON_FLAG_VISIBILITY))); - } + final PsiExpression expression = variable.getInitializer(); + if (type instanceof PsiArrayType && expression instanceof PsiNewExpression) { + final PsiNewExpression newExpression = (PsiNewExpression)expression; + final PsiExpression[] dimensions = newExpression.getArrayDimensions(); + if (dimensions.length == 1 && "1".equals(dimensions[0].getText()) && newExpression.getArrayInitializer() == null) { + final String text = variable.getName() + "[0]"; + final PsiExpression conversion = createExpression(text, element); + ExpressionLookupItem result = new ExpressionLookupItem(conversion); + result.setIcon(variable.getIcon(Iconable.ICON_FLAG_VISIBILITY)); + return result; } } } + return null; } private static PsiExpression createExpression(String text, PsiElement element) { diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java b/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java index 51186e0aac75..a85b8d43c342 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java @@ -568,6 +568,10 @@ public class OverrideImplementUtil { } }; mergeAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.ALT_MASK)), myTree); + + Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts("OverrideMethods"); + mergeAction.registerCustomShortcutSet(new CustomShortcutSet(shortcuts), myTree); + group.add(mergeAction); } }; diff --git a/java/java-tests/testData/codeInsight/completion/smartType/second/ArrayRefAsQualifier-out.java b/java/java-tests/testData/codeInsight/completion/smartType/second/ArrayRefAsQualifier-out.java new file mode 100644 index 000000000000..493d9d56d413 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/second/ArrayRefAsQualifier-out.java @@ -0,0 +1,11 @@ +class Bar { + Goo getGoo(); +} +class Goo {} + +class Foo { + { + Bar[] ref = new Bar[1]; + Goo g = ref[0].getGoo(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/smartType/second/ArrayRefAsQualifier.java b/java/java-tests/testData/codeInsight/completion/smartType/second/ArrayRefAsQualifier.java new file mode 100644 index 000000000000..53e4b684d7d9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/second/ArrayRefAsQualifier.java @@ -0,0 +1,11 @@ +class Bar { + Goo getGoo(); +} +class Goo {} + +class Foo { + { + Bar[] ref = new Bar[1]; + Goo g = + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/smartTypeSorting/DispreferGetterInSetterCall.java b/java/java-tests/testData/codeInsight/completion/smartTypeSorting/DispreferGetterInSetterCall.java new file mode 100644 index 000000000000..80abddfe9250 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartTypeSorting/DispreferGetterInSetterCall.java @@ -0,0 +1,13 @@ +public class Aaaaaaa { + int color; + + void setColor(int color) {} + int getColor() {} + int getZooColor() {} + + { + setColor(); + } + + +} diff --git a/java/java-tests/testData/codeInsight/completion/smartTypeSorting/PreferOtherGetterInSetterCall.java b/java/java-tests/testData/codeInsight/completion/smartTypeSorting/PreferOtherGetterInSetterCall.java new file mode 100644 index 000000000000..861cce30711a --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartTypeSorting/PreferOtherGetterInSetterCall.java @@ -0,0 +1,13 @@ +public class Aaaaaaa { + int color; + + void setColor(int color) {} + int getColor() {} + int getZooColor() {} + + void foo(Aaaaaaa a) { + setColor(a.); + } + + +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java index 082584d0aa84..2e8c686948d0 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SecondSmartTypeCompletionTest.java @@ -23,6 +23,7 @@ public class SecondSmartTypeCompletionTest extends LightCompletionTestCase { public void testMethodAsQualifier() throws Throwable { doTest(); } public void testFieldAsQualifier() throws Throwable { doTest(); } + public void testArrayRefAsQualifier() throws Throwable { doTest(); } public void testMethodWithParams() throws Throwable { doTest(); } public void testMergeMethods() throws Throwable { doTest(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy index 348ceb177809..2480cc6bca78 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionOrderingTest.groovy @@ -296,6 +296,13 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase { assert 'FList.emptyList' in lookup.items[5].allLookupStrings } + public void testDispreferGetterInSetterCall() { + checkPreferredItems 0, 'getZooColor', 'hashCode', 'color', 'getColor' + } + public void testPreferOtherGetterInSetterCall() { + checkPreferredItems 0, 'color', 'getColor', 'getZooColor', 'hashCode' + } + @Override protected String getBasePath() { return JavaTestUtil.getRelativeJavaTestDataPath() + BASE_PATH; diff --git a/java/openapi/src/com/intellij/psi/util/PropertyUtil.java b/java/openapi/src/com/intellij/psi/util/PropertyUtil.java index 4166a3b450f2..89b7159f9554 100644 --- a/java/openapi/src/com/intellij/psi/util/PropertyUtil.java +++ b/java/openapi/src/com/intellij/psi/util/PropertyUtil.java @@ -77,7 +77,7 @@ public class PropertyUtil { } @SuppressWarnings("HardCodedStringLiteral") - public static boolean isSimplePropertySetter(PsiMethod method) { + public static boolean isSimplePropertySetter(@Nullable PsiMethod method) { if (method == null) return false; if (method.isConstructor()) return false; diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopupFactory.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopupFactory.java index 479cbe9ffe1d..85321761dcb7 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopupFactory.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/JBPopupFactory.java @@ -155,7 +155,7 @@ public abstract class JBPopupFactory { * @param showDisabledActions if true, disabled actions are shown as disabled; if false, disabled actions are not shown * @return the popup instance. */ - public abstract ListPopup createActionGroupPopup(String title, + public abstract ListPopup createActionGroupPopup(@Nullable String title, ActionGroup actionGroup, @NotNull DataContext dataContext, ActionSelectionAid selectionAidMethod, diff --git a/platform/platform-api/src/com/intellij/ui/CommonActionsPanel.java b/platform/platform-api/src/com/intellij/ui/CommonActionsPanel.java index 383495fbf2e8..90ad2778d913 100644 --- a/platform/platform-api/src/com/intellij/ui/CommonActionsPanel.java +++ b/platform/platform-api/src/com/intellij/ui/CommonActionsPanel.java @@ -30,7 +30,7 @@ import java.util.*; /** * @author Konstantin Bulenkov */ -class CommonActionsPanel extends JPanel { +public class CommonActionsPanel extends JPanel { public static enum Buttons { ADD, EDIT, REMOVE, UP, DOWN; @@ -193,14 +193,7 @@ class CommonActionsPanel extends JPanel { @Override public ShortcutSet getShortcut() { - switch (myButton) { - case ADD: return CommonShortcuts.getNewForDialogs(); - case EDIT: return CustomShortcutSet.fromString("ENTER"); - case REMOVE: return CustomShortcutSet.fromString(SystemInfo.isMac ? "meta BACK_SPACE" : "alt DELETE"); - case UP: return CustomShortcutSet.fromString("alt UP"); - case DOWN: return CustomShortcutSet.fromString("alt DOWN"); - } - return null; + return getCommonShortcut(myButton); } @Override @@ -244,6 +237,17 @@ class CommonActionsPanel extends JPanel { } } + public static ShortcutSet getCommonShortcut(Buttons button) { + switch (button) { + case ADD: return CommonShortcuts.getNewForDialogs(); + case EDIT: return CustomShortcutSet.fromString("ENTER"); + case REMOVE: return CustomShortcutSet.fromString(SystemInfo.isMac ? "meta BACK_SPACE" : "alt DELETE"); + case UP: return CustomShortcutSet.fromString("alt UP"); + case DOWN: return CustomShortcutSet.fromString("alt DOWN"); + } + return null; + } + interface ListenerFactory { Listener createListener(CommonActionsPanel panel); } diff --git a/platform/platform-api/src/com/intellij/ui/table/BaseTableView.java b/platform/platform-api/src/com/intellij/ui/table/BaseTableView.java index 000d313443d0..a79349b5f6aa 100644 --- a/platform/platform-api/src/com/intellij/ui/table/BaseTableView.java +++ b/platform/platform-api/src/com/intellij/ui/table/BaseTableView.java @@ -18,7 +18,6 @@ package com.intellij.ui.table; import com.intellij.openapi.diagnostic.Logger; import com.intellij.util.config.Storage; import com.intellij.util.ui.ListTableModel; -import com.intellij.util.ui.Table; import org.jetbrains.annotations.NonNls; import javax.swing.*; @@ -31,7 +30,7 @@ import java.util.Arrays; /** * Do NOT add code that assumes that table has same number of rows as model. It isn't true! */ -public class BaseTableView extends Table { +public class BaseTableView extends JBTable { private static final Logger LOG = Logger.getInstance("#com.intellij.ui.table.BaseTableView"); public BaseTableView(final ListTableModel model) { diff --git a/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java b/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java index ab0e758c0024..75e8b5fface9 100644 --- a/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java +++ b/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java @@ -23,6 +23,7 @@ import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.JDOMExternalizable; import com.intellij.openapi.util.WriteExternalException; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.WaitForProgressToShow; import com.intellij.util.xmlb.XmlSerializer; import com.intellij.util.xmlb.XmlSerializerUtil; @@ -180,7 +181,13 @@ public class HttpConfigurable implements PersistentStateComponent() { @@ -172,16 +169,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { createRenderer(layoutXmlText, new ThrowableRunnable() { @Override public void run() throws Throwable { - Result result = mySession.getResult(); - if (!result.isSuccess()) { - Throwable exception = result.getException(); - if (exception != null) { - throw exception; - } - else { - throw new Exception("No session result"); - } - } + checkRenderer(); RootView rootView = new RootView(mySession.getImage(), 30, 20); updateRootComponent(rootComponents, mySession.getRootViews(), rootView); @@ -199,6 +187,41 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { }); } + private void updateRenderer() { + final String layoutXmlText = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override + public String compute() { + return myXmlFile.getText(); + } + }); + createRenderer(layoutXmlText, new ThrowableRunnable() { + @Override + public void run() throws Throwable { + checkRenderer(); + + RadViewComponent rootComponent = (RadViewComponent)myRootComponent; + RootView rootView = (RootView)rootComponent.getNativeComponent(); + rootView.setImage(mySession.getImage()); + updateRootComponent(rootComponent, mySession.getRootViews(), rootView); + + myLayeredPane.repaint(); + } + }); + } + + private void checkRenderer() throws Throwable { + Result result = mySession.getResult(); + if (!result.isSuccess()) { + Throwable exception = result.getException(); + if (exception != null) { + throw exception; + } + else { + throw new Exception("No session result"); + } + } + } + private void removeNativeRoot() { if (myRootComponent != null) { myLayeredPane.remove(((RadViewComponent)myRootComponent).getNativeComponent().getParent()); @@ -208,8 +231,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { private void updateRootComponent(RadViewComponent[] rootComponents, List views, JComponent nativeComponent) { RadViewComponent rootComponent = rootComponents[0]; - int size = views.size(); - if (size == 1) { + if (views.size() == 1) { RadViewComponent newRootComponent = new RadViewComponent(null); newRootComponent.setMetaModel(ViewsMetaManager.getInstance(getProject()).getModelByTag("")); newRootComponent.getChildren().add(rootComponent); @@ -217,13 +239,21 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { updateComponent(rootComponent, views.get(0), nativeComponent, 0, 0); - rootComponents[0] = rootComponent = newRootComponent; + rootComponents[0] = newRootComponent; + + newRootComponent.setNativeComponent(nativeComponent); + newRootComponent.setBounds(0, 0, nativeComponent.getWidth(), nativeComponent.getHeight()); } else { - List children = rootComponent.getChildren(); - for (int i = 0; i < size; i++) { - updateComponent((RadViewComponent)children.get(i), views.get(i), nativeComponent, 0, 0); - } + updateRootComponent(rootComponent, views, nativeComponent); + } + } + + private static void updateRootComponent(RadViewComponent rootComponent, List views, JComponent nativeComponent) { + int size = views.size(); + List children = rootComponent.getChildren(); + for (int i = 0; i < size; i++) { + updateComponent((RadViewComponent)children.get(i), views.get(i), nativeComponent, 0, 0); } rootComponent.setNativeComponent(nativeComponent); @@ -247,7 +277,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { } - private void createRenderer(final String layoutXmlText, final ThrowableRunnable runnable) throws Exception { + private void createRenderer(final String layoutXmlText, final ThrowableRunnable runnable) { if (mySession == null) { ApplicationManager.getApplication().invokeLater( new Runnable() { @@ -278,28 +308,32 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { throw new AndroidSdkNotConfiguredException(); } - IAndroidTarget target = platform.getTarget(); AndroidFacet facet = AndroidFacet.getInstance(myModule); + ProfileManager manager = myProfileAction.getProfileManager(); - LayoutDeviceManager layoutDeviceManager = new LayoutDeviceManager(); - layoutDeviceManager.loadDevices(platform.getSdkData()); - LayoutDevice layoutDevice = layoutDeviceManager.getCombinedList().get(0); - - LayoutDeviceConfiguration deviceConfiguration = layoutDevice.getConfigurations().get(0); + LayoutDeviceConfiguration deviceConfiguration = manager.getSelectedDeviceConfiguration(); + if (deviceConfiguration == null) { + throw new RenderingException("Device is not specified"); + } FolderConfiguration config = new FolderConfiguration(); config.set(deviceConfiguration.getConfiguration()); - config.setUiModeQualifier(new UiModeQualifier(UiMode.NORMAL)); - config.setNightModeQualifier(new NightModeQualifier(NightMode.NIGHT)); - config.setLanguageQualifier(new LanguageQualifier()); - config.setRegionQualifier(new RegionQualifier()); + config.setUiModeQualifier(new UiModeQualifier(manager.getSelectedDockMode())); + config.setNightModeQualifier(new NightModeQualifier(manager.getSelectedNightMode())); + + LocaleData locale = manager.getSelectedLocale(); + if (locale == null) { + throw new RenderingException("Locale is not specified"); + } + config.setLanguageQualifier(new LanguageQualifier(locale.getLanguage())); + config.setRegionQualifier(new RegionQualifier(locale.getRegion())); float xdpi = deviceConfiguration.getDevice().getXDpi(); float ydpi = deviceConfiguration.getDevice().getYDpi(); - ThemeData theme = new ThemeData("Theme", false); - - mySession = RenderUtil.createRenderSession(getProject(), layoutXmlText, myFile, target, facet, config, xdpi, ydpi, theme); + mySession = RenderUtil + .createRenderSession(getProject(), layoutXmlText, myFile, manager.getSelectedTarget(), facet, config, xdpi, ydpi, + manager.getSelectedTheme()); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override @@ -314,6 +348,14 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { } }); } + catch (RenderingException e) { + // TODO + e.printStackTrace(); + } + catch (AndroidSdkNotConfiguredException e) { + // TODO + e.printStackTrace(); + } catch (final Throwable e) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override @@ -427,11 +469,19 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { } private static class RootView extends JComponent { - private final BufferedImage myImage; + private int myX; + private int myY; + private BufferedImage myImage; public RootView(BufferedImage image, int x, int y) { + myX = x; + myY = y; + setImage(image); + } + + public void setImage(BufferedImage image) { myImage = image; - setBounds(x, y, image.getWidth(), image.getHeight()); + setBounds(myX, myY, image.getWidth(), image.getHeight()); } @Override diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/ExternalPSIChangeListener.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/ExternalPSIChangeListener.java index 623686c2c5f4..601cca10860a 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/ExternalPSIChangeListener.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/ExternalPSIChangeListener.java @@ -18,6 +18,7 @@ package com.intellij.android.designer.designSurface; import com.intellij.openapi.application.ModalityState; import com.intellij.psi.*; import com.intellij.util.Alarm; +import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -54,20 +55,28 @@ public class ExternalPSIChangeListener extends PsiTreeChangeAdapter { } } - private void update(PsiTreeChangeEvent event) { + private void updatePsi(PsiTreeChangeEvent event) { if (myRunState && myFile == event.getFile()) { - myAlarm.cancelAllRequests(); - myAlarm.addRequest(new Runnable() { - @Override - public void run() { - if (myRunState) { - myRunnable.run(); - } - } - }, myDelayMillis, ModalityState.stateForComponent(myComponent)); + addRequest(); } } + public void addRequest() { + addRequest(myRunnable); + } + + public void addRequest(final Runnable runnable) { + myAlarm.cancelAllRequests(); + myAlarm.addRequest(new Runnable() { + @Override + public void run() { + if (myRunState) { + runnable.run(); + } + } + }, myDelayMillis, ModalityState.stateForComponent(myComponent)); + } + ////////////////////////////////////////////////////////////////////////////////////////// // // PSI @@ -76,31 +85,31 @@ public class ExternalPSIChangeListener extends PsiTreeChangeAdapter { @Override public void childAdded(PsiTreeChangeEvent event) { - update(event); + updatePsi(event); } @Override public void childRemoved(PsiTreeChangeEvent event) { - update(event); + updatePsi(event); } @Override public void childReplaced(PsiTreeChangeEvent event) { - update(event); + updatePsi(event); } @Override public void childMoved(PsiTreeChangeEvent event) { - update(event); + updatePsi(event); } @Override public void childrenChanged(PsiTreeChangeEvent event) { - update(event); + updatePsi(event); } @Override public void propertyChanged(PsiTreeChangeEvent event) { - update(event); + updatePsi(event); } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/profile/ProfileManager.java b/plugins/android-designer/src/com/intellij/android/designer/profile/ProfileManager.java index 4e60a17c400a..130761e9095f 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/profile/ProfileManager.java +++ b/plugins/android-designer/src/com/intellij/android/designer/profile/ProfileManager.java @@ -132,6 +132,7 @@ public class ProfileManager { @Override protected boolean selectionChanged(LayoutDeviceConfiguration item) { updateDeviceConfiguration(item); + myRefreshAction.run(); return true; } }; @@ -141,7 +142,6 @@ public class ProfileManager { protected boolean selectionChanged(IAndroidTarget item) { updateTarget(item); updateThemes(); - myRefreshAction.run(); return true; } }; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java index 6350b6ff8f40..9c0ee98046b6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java @@ -63,6 +63,7 @@ import com.intellij.psi.PsiManager; import com.intellij.util.*; import com.intellij.util.cls.ClsFormatException; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.net.HttpConfigurable; import gnu.trove.THashSet; import org.jetbrains.annotations.Nullable; import org.jetbrains.groovy.compiler.rt.GroovycRunner; @@ -150,6 +151,7 @@ public abstract class GroovyCompilerBase implements TranslatingCompiler { if (profileGroovyc) { parameters.getVMParametersList().add("-XX:+HeapDumpOnOutOfMemoryError"); } + parameters.getVMParametersList().addAll(HttpConfigurable.getProxyCmdLineProperties()); //debug //parameters.getVMParametersList().add("-Xdebug"); parameters.getVMParametersList().add("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5239"); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java index 2f0ee33e22ab..a0d21ba0581b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/StubGenerator.java @@ -41,6 +41,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrRe import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; +import org.jetbrains.plugins.groovy.lang.psi.util.GroovyConstantExpressionEvaluator; import java.util.*; @@ -365,12 +366,20 @@ public class StubGenerator implements ClassItemGenerator { //type PsiType declaredType = typeElement == null ? PsiType.getJavaLangObject(variable.getManager(), variable.getResolveScope()) : typeElement.getType(); - final String initializer = GroovyToJavaGenerator.getDefaultValueText(declaredType.getCanonicalText()); writeType(text, declaredType, variableDeclaration, classNameProvider); - text.append(' ').append(name).append(" = ").append(initializer); + text.append(' ').append(name).append(" = ").append(getVariableInitializer(variable, declaredType)); text.append(";\n"); } } + private static String getVariableInitializer(GrVariable variable, PsiType declaredType) { + if (declaredType instanceof PsiPrimitiveType) { + Object eval = GroovyConstantExpressionEvaluator.evaluate(variable.getInitializerGroovy()); + if (eval instanceof Number || eval instanceof Boolean) { + return eval.toString(); + } + } + return GroovyToJavaGenerator.getDefaultValueText(declaredType.getCanonicalText()); + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/DefaultGroovyScriptRunner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/DefaultGroovyScriptRunner.java index 1c8f9abf4d0f..e958e7c7ed26 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/DefaultGroovyScriptRunner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/DefaultGroovyScriptRunner.java @@ -32,6 +32,7 @@ import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.encoding.EncodingManager; import com.intellij.openapi.vfs.encoding.EncodingProjectManager; +import com.intellij.util.net.HttpConfigurable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.util.GroovyUtils; @@ -100,6 +101,7 @@ public class DefaultGroovyScriptRunner extends GroovyScriptRunner { final String confPath = getConfPath(groovyHome); params.getVMParametersList().add("-Dgroovy.starter.conf=" + confPath); + params.getVMParametersList().addAll(HttpConfigurable.getProxyCmdLineProperties()); params.setMainClass("org.codehaus.groovy.tools.GroovyStarter"); diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy index f2dcfbf91b6a..3aa64fada2ba 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy @@ -561,6 +561,25 @@ class Main { assertEmpty make() } + public void testCompileTimeConstants() { + myFixture.addFileToProject 'Gr.groovy', ''' +interface Gr { + String HELLO = "Hello" + int MAGIC = 239 + Boolean BOOL = true + boolean bool = true +}''' + myFixture.addFileToProject 'Main.java', ''' +public class Main { + public static void main(String[] args) { + System.out.println(Gr.HELLO + ", " + Gr.BOOL + Gr.bool + Gr.MAGIC); + } +} +''' + make() + assertOutput 'Main', 'Hello, truetrue239' + } + public static class IdeaModeTest extends GroovyCompilerTest { @Override protected boolean useJps() { false } } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/compiler/MavenResourceCompiler.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/compiler/MavenResourceCompiler.java index cf4e4e77c138..a6bb8baa5e49 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/compiler/MavenResourceCompiler.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/compiler/MavenResourceCompiler.java @@ -18,8 +18,8 @@ package org.jetbrains.idea.maven.compiler; import com.intellij.compiler.CompilerConfigurationImpl; import com.intellij.compiler.CompilerIOUtil; import com.intellij.compiler.impl.CompilerUtil; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ReadAction; -import com.intellij.openapi.application.Result; import com.intellij.openapi.compiler.*; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; @@ -37,11 +37,13 @@ import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.LightVirtualFile; +import com.intellij.util.containers.CollectionFactory; import com.intellij.util.text.CaseInsensitiveStringHashingStrategy; import gnu.trove.THashMap; import gnu.trove.THashSet; import org.jdom.Element; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.maven.dom.MavenPropertyResolver; import org.jetbrains.idea.maven.model.MavenResource; import org.jetbrains.idea.maven.project.MavenProject; @@ -57,6 +59,8 @@ import java.util.regex.Pattern; public class MavenResourceCompiler implements ClassPostProcessingCompiler { private static final Key> FILES_TO_DELETE_KEY = Key.create(MavenResourceCompiler.class.getSimpleName() + ".FILES_TO_DELETE"); + private static final Set DEFAULT_NON_FILTERED_EXTENSIONS = CollectionFactory.newSet("jpg", "jpeg", "gif", "bmp", "png"); + private Map> myOutputItemsCache = new THashMap>(); public MavenResourceCompiler(Project project) { @@ -76,7 +80,7 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler { while (modulesSize-- > 0) { String module = CompilerIOUtil.readString(in); int pathsSize = in.readInt(); - Set paths = createPathsSet(pathsSize); + Set paths = createPathsSet(); while (pathsSize-- > 0) { paths.add(CompilerIOUtil.readString(in)); } @@ -93,10 +97,10 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler { } } - private static Set createPathsSet(int size) { + private static Set createPathsSet() { return SystemInfo.isFileSystemCaseSensitive - ? new THashSet(size) - : new THashSet(size, CaseInsensitiveStringHashingStrategy.INSTANCE); + ? new THashSet() + : new THashSet(CaseInsensitiveStringHashingStrategy.INSTANCE); } private void saveCache(final Project project) { @@ -140,54 +144,60 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler { final Project project = context.getProject(); final MavenProjectsManager mavenProjectManager = MavenProjectsManager.getInstance(project); if (!mavenProjectManager.isMavenizedProject()) return ProcessingItem.EMPTY_ARRAY; - return new ReadAction() { - protected void run(Result resultObject) throws Throwable { - // make sure null reference will not be returned. By default return empty array - resultObject.setResult(ProcessingItem.EMPTY_ARRAY); - List allItemsToProcess = new ArrayList(); - List filesToDelete = new ArrayList(); - for (Module eachModule : context.getCompileScope().getAffectedModules()) { - MavenProject mavenProject = mavenProjectManager.findProject(eachModule); - if (mavenProject == null) continue; + List allItemsToProcess = new ArrayList(); + List filesToDelete = new ArrayList(); - Properties properties = loadPropertiesAndFilters(context, mavenProject); + AccessToken accessToken = ReadAction.start(); + try { + for (Module eachModule : context.getCompileScope().getAffectedModules()) { + MavenProject mavenProject = mavenProjectManager.findProject(eachModule); + if (mavenProject == null) continue; - List nonFilteredExtensions = collectNonFilteredExtensions(mavenProject); - String escapeString = MavenJDOMUtil.findChildValueByPath(mavenProject.getPluginConfiguration("org.apache.maven.plugins", - "maven-resources-plugin"), - "escapeString", "\\"); + Properties properties = loadPropertiesAndFilters(context, mavenProject); - long propertiesHashCode = calculateHashCode(mavenProject, properties); + Set nonFilteredExtensions = collectNonFilteredExtensions(mavenProject); + String escapeString = MavenJDOMUtil.findChildValueByPath(mavenProject.getPluginConfiguration("org.apache.maven.plugins", + "maven-resources-plugin"), + "escapeString", "\\"); - List moduleItemsToProcess = new ArrayList(); - collectProcessingItems(eachModule, mavenProject, context, properties, propertiesHashCode, - nonFilteredExtensions, escapeString, false, moduleItemsToProcess); - collectProcessingItems(eachModule, mavenProject, context, properties, propertiesHashCode, - nonFilteredExtensions, escapeString, true, moduleItemsToProcess); - collectItemsToDelete(eachModule, moduleItemsToProcess, filesToDelete); - allItemsToProcess.addAll(moduleItemsToProcess); - } + long propertiesHashCode = calculateHashCode(mavenProject, properties); - if (!filesToDelete.isEmpty()) { - allItemsToProcess.add(new FakeProcessingItem()); - } - context.putUserData(FILES_TO_DELETE_KEY, filesToDelete); - resultObject.setResult(allItemsToProcess.toArray(new ProcessingItem[allItemsToProcess.size()])); - removeObsoleteModulesFromCache(project); - saveCache(project); + List moduleItemsToProcess = new ArrayList(); + collectProcessingItems(eachModule, mavenProject, context, properties, propertiesHashCode, + nonFilteredExtensions, escapeString, false, moduleItemsToProcess); + collectProcessingItems(eachModule, mavenProject, context, properties, propertiesHashCode, + nonFilteredExtensions, escapeString, true, moduleItemsToProcess); + collectItemsToDelete(eachModule, moduleItemsToProcess, filesToDelete); + allItemsToProcess.addAll(moduleItemsToProcess); } - }.execute().getResultObject(); + + if (!filesToDelete.isEmpty()) { + allItemsToProcess.add(new FakeProcessingItem()); + } + context.putUserData(FILES_TO_DELETE_KEY, filesToDelete); + + removeObsoleteModulesFromCache(project); + saveCache(project); + } + finally { + accessToken.finish(); + } + + return allItemsToProcess.toArray(new ProcessingItem[allItemsToProcess.size()]); } - private static List collectNonFilteredExtensions(MavenProject mavenProject) { - List result = new ArrayList(Arrays.asList("jpg", "jpeg", "gif", "bmp", "png")); + private static Set collectNonFilteredExtensions(MavenProject mavenProject) { Element config = mavenProject.getPluginConfiguration("org.apache.maven.plugins", "maven-resources-plugin"); - if (config == null) return result; + if (config == null) return DEFAULT_NON_FILTERED_EXTENSIONS; + + List customNonFilteredExtensions = MavenJDOMUtil.findChildrenValuesByPath(config, "nonFilteredFileExtensions", "nonFilteredFileExtension"); + if (customNonFilteredExtensions.isEmpty()) return DEFAULT_NON_FILTERED_EXTENSIONS; + + Set result = new HashSet(); + result.addAll(DEFAULT_NON_FILTERED_EXTENSIONS); + result.addAll(customNonFilteredExtensions); - for (String each : MavenJDOMUtil.findChildrenValuesByPath(config, "nonFilteredFileExtensions", "nonFilteredFileExtension")) { - result.add(each); - } return result; } @@ -221,15 +231,15 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler { return properties; } - private void collectProcessingItems(Module module, - MavenProject mavenProject, - CompileContext context, - Properties properties, - long propertiesHashCode, - List nonFilteredExtensions, - String escapeString, - boolean tests, - List result) { + private static void collectProcessingItems(Module module, + MavenProject mavenProject, + CompileContext context, + Properties properties, + long propertiesHashCode, + Set nonFilteredExtensions, + String escapeString, + boolean tests, + List result) { String outputDir = CompilerPaths.getModuleOutputPath(module, tests); if (outputDir == null) { context.addMessage(CompilerMessageCategory.ERROR, "Maven: Module '" + module.getName() + "'output is not specified", null, -1, -1); @@ -265,7 +275,7 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler { } } - public static List collectPatterns(List values, String defaultValue) { + public static List collectPatterns(@Nullable List values, @Nullable String defaultValue) { List result = new ArrayList(); if (values == null || values.isEmpty()) { if (defaultValue == null) return Collections.emptyList(); @@ -277,21 +287,21 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler { return result; } - private void collectProcessingItems(Module module, - VirtualFile sourceRoot, - VirtualFile currentDir, - String outputDir, - List includes, - List excludes, - boolean isSourceRootFiltered, - Properties properties, - long propertiesHashCode, - List nonFilteredExtensions, - String escapeString, - List result, - ProgressIndicator indicator) { + private static void collectProcessingItems(Module module, + VirtualFile sourceRoot, + VirtualFile currentDir, + String outputDir, + List includes, + List excludes, + boolean isSourceRootFiltered, + Properties properties, + long propertiesHashCode, + Set nonFilteredExtensions, + String escapeString, + List result, + ProgressIndicator indicator) { indicator.checkCanceled(); - final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex(); + for (VirtualFile eachSourceFile : currentDir.getChildren()) { if (eachSourceFile.isDirectory()) { collectProcessingItems(module, @@ -315,6 +325,7 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler { continue; } + ProjectFileIndex fileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex(); if (fileIndex.isIgnored(eachSourceFile)) continue; if (!MavenUtil.isIncluded(relPath, includes, excludes)) continue; @@ -337,29 +348,20 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler { } } - private void collectItemsToDelete(Module module, List processingItems, List result) { - Set currentPaths = createPathsSet(processingItems.size()); - for (ProcessingItem each : processingItems) { - if (!(each instanceof MyProcessingItem)) continue; - currentPaths.add(((MyProcessingItem)each).getOutputPath()); + private void collectItemsToDelete(Module module, List processingItems, List result) { + Set currentPaths = createPathsSet(); + for (MyProcessingItem each : processingItems) { + currentPaths.add(each.getOutputPath()); } - Set cachedPaths = null; - Set otherModulesCachedPaths = new THashSet(); - for (Map.Entry> eachEntry : myOutputItemsCache.entrySet()) { - if (eachEntry.getKey().equals(module.getName())) { - cachedPaths = eachEntry.getValue(); + Set cachedPaths = myOutputItemsCache.put(module.getName(), currentPaths); + if (cachedPaths != null) { + for (Set set : myOutputItemsCache.values()) { + cachedPaths.removeAll(set); } - else { - otherModulesCachedPaths.addAll(eachEntry.getValue()); - } - } - myOutputItemsCache.put(module.getName(), currentPaths); - if (cachedPaths == null) return; - cachedPaths.removeAll(currentPaths); - cachedPaths.removeAll(otherModulesCachedPaths); - result.addAll(cachedPaths); + result.addAll(cachedPaths); + } } private void removeObsoleteModulesFromCache(final Project project) { @@ -383,14 +385,13 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler { deleteOutdatedFile(context.getUserData(FILES_TO_DELETE_KEY), filesToRefresh); - int count = 0; - for (final ProcessingItem each : items) { - if (!(each instanceof MyProcessingItem)) continue; + for (int i = 0; i < items.length; i++) { + if (!(items[i] instanceof MyProcessingItem)) continue; - context.getProgressIndicator().setFraction(((double)count) / items.length); + context.getProgressIndicator().setFraction(((double)i) / items.length); context.getProgressIndicator().checkCanceled(); - MyProcessingItem eachItem = (MyProcessingItem)each; + MyProcessingItem eachItem = (MyProcessingItem)items[i]; VirtualFile sourceVirtualFile = eachItem.getFile(); File sourceFile = new File(sourceVirtualFile.getPath()); File outputFile = new File(eachItem.getOutputPath()); @@ -410,7 +411,7 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler { String charset = sourceVirtualFile.getCharset().name(); String text = new String(FileUtil.loadFileBytes(sourceFile), charset); String escapedCharacters = sourceVirtualFile.getName().endsWith(".properties") ? "\\" : null; - + PrintWriter printWriter = new PrintWriter(outputFile, charset); try { MavenPropertyResolver.doFilterText(eachItem.getModule(), @@ -428,8 +429,8 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler { FileUtil.copy(sourceFile, outputFile); } - ((MyValididtyState)each.getValidityState()).setOutputFileTimestamp(outputFile.lastModified()); - result.add(each); + eachItem.getValidityState().setOutputFileTimestamp(outputFile.lastModified()); + result.add(eachItem); filesToRefresh.add(outputFile); } catch (IOException e) { @@ -445,7 +446,7 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler { return result.toArray(new ProcessingItem[result.size()]); } - private void deleteOutdatedFile(List filesToDelete, List filesToRefresh) { + private static void deleteOutdatedFile(List filesToDelete, List filesToRefresh) { for (String each : filesToDelete) { File file = new File(each); if (FileUtil.delete(file)) { @@ -514,7 +515,8 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler { return myEscapeString; } - public ValidityState getValidityState() { + @NotNull + public MyValididtyState getValidityState() { return myState; } } @@ -538,7 +540,7 @@ public class MavenResourceCompiler implements ClassPostProcessingCompiler { private static class MyValididtyState implements ValidityState { private final long mySourceFileTimestamp; - private volatile long myOutputFileTimestamp; + private long myOutputFileTimestamp; private final boolean myFiltered; private final long myPropertiesHashCode; private final String myEscapeString; 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 c36e47b0b7f6..b2aa0f8e20a4 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 @@ -271,9 +271,11 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider protected final void showProgress(String message) { myProgressMessage.setText(message); - myProgressIcon.resume(); - myLayeredPane.add(myProgressPanel, LAYER_PROGRESS); - myLayeredPane.repaint(); + if (myProgressPanel.getParent() == null) { + myProgressIcon.resume(); + myLayeredPane.add(myProgressPanel, LAYER_PROGRESS); + myLayeredPane.repaint(); + } } protected final void hideProgress() { diff --git a/xml/dom-openapi/src/com/intellij/util/xml/ui/AbstractTableView.java b/xml/dom-openapi/src/com/intellij/util/xml/ui/AbstractTableView.java index f56e7cbcc344..fe8c445ecfc3 100644 --- a/xml/dom-openapi/src/com/intellij/util/xml/ui/AbstractTableView.java +++ b/xml/dom-openapi/src/com/intellij/util/xml/ui/AbstractTableView.java @@ -127,6 +127,7 @@ public abstract class AbstractTableView extends JPanel implements TypeSafeDat final ActionManager actionManager = ActionManager.getInstance(); final ToolbarPosition position = getToolbarPosition(); final ActionToolbar myActionToolbar = actionManager.createActionToolbar(ActionPlaces.PROJECT_VIEW_TOOLBAR, actionGroup, position == ToolbarPosition.TOP || position == ToolbarPosition.BOTTOM); + myActionToolbar.setTargetComponent(myTable); final JComponent toolbarComponent = myActionToolbar.getComponent(); final MatteBorder matteBorder = BorderFactory.createMatteBorder(0, 0, position == ToolbarPosition.TOP ? 1 : 0, 0, Color.darkGray); toolbarComponent.setBorder(BorderFactory.createCompoundBorder(matteBorder, toolbarComponent.getBorder())); @@ -169,14 +170,6 @@ public abstract class AbstractTableView extends JPanel implements TypeSafeDat tuneTable(myTable); } - protected final void fireTableChanged() { - final int row = myTable.getSelectedRow(); - getTableModel().fireTableDataChanged(); - if (row >= 0 && row < myTableModel.getRowCount()) { - myTable.getSelectionModel().setSelectionInterval(row, row); - } - } - protected void adjustColumnWidths() { final ColumnInfo[] columnInfos = myTableModel.getColumnInfos(); for (int i = 0; i < columnInfos.length; i++) { @@ -205,10 +198,6 @@ public abstract class AbstractTableView extends JPanel implements TypeSafeDat protected final void updateTooltip(final MouseEvent e) { final int i = myTable.columnAtPoint(e.getPoint()); - final int k = myTable.rowAtPoint(e.getPoint()); - - //myTable.getTableHeader().setToolTipText(((DefaultTableCellRenderer)myTable.getCellRenderer(i,k)).getToolTipText(); - if (i >= 0) { myTable.getTableHeader().setToolTipText(myTableModel.getColumnInfos()[i].getTooltipText()); } diff --git a/xml/dom-openapi/src/com/intellij/util/xml/ui/DomCollectionControl.java b/xml/dom-openapi/src/com/intellij/util/xml/ui/DomCollectionControl.java index 803b890ecf12..30b718b1031d 100644 --- a/xml/dom-openapi/src/com/intellij/util/xml/ui/DomCollectionControl.java +++ b/xml/dom-openapi/src/com/intellij/util/xml/ui/DomCollectionControl.java @@ -25,11 +25,12 @@ import com.intellij.openapi.util.IconLoader; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiUtilCore; import com.intellij.psi.xml.XmlElement; +import com.intellij.ui.CommonActionsPanel; import com.intellij.util.ArrayUtil; import com.intellij.util.EventDispatcher; import com.intellij.util.ReflectionUtil; -import com.intellij.util.containers.HashSet; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.HashSet; import com.intellij.util.ui.ColumnInfo; import com.intellij.util.xml.DomElement; import com.intellij.util.xml.highlighting.DomCollectionProblemDescriptor; @@ -63,22 +64,6 @@ public class DomCollectionControl extends DomUIControl imp private List myCollectionElements = new ArrayList(); private ColumnInfo[] myColumnInfos; private boolean myEditable = false; - private final AnAction myAddAction = new AddAction() { - protected DomCollectionControl getDomCollectionControl(final AnActionEvent e) { - return DomCollectionControl.this; - } - }; - - private final AnAction myEditAction = new EditAction() { - protected DomCollectionControl getDomCollectionControl(final AnActionEvent e) { - return DomCollectionControl.this; - } - }; - private final AnAction myRemoveAction = new RemoveAction() { - protected DomCollectionControl getDomCollectionControl(final AnActionEvent e) { - return DomCollectionControl.this; - } - }; public static final Icon ADD_ICON = IconLoader.getIcon("/general/add.png"); public static final Icon EDIT_ICON = IconLoader.getIcon("/actions/editSource.png"); public static final Icon REMOVE_ICON = IconLoader.getIcon("/general/remove.png"); @@ -169,7 +154,7 @@ public class DomCollectionControl extends DomUIControl imp else { myCollectionPanel = boundComponent; } - myCollectionPanel.setToolbarActions(myAddAction, myEditAction, myRemoveAction); + myCollectionPanel.setToolbarActions(new AddAction(), new EditAction(), new RemoveAction()); myCollectionPanel.installPopup(ActionPlaces.J2EE_ATTRIBUTES_VIEW_POPUP, createPopupActionGroup()); myCollectionPanel.initializeTable(); myCollectionPanel.addCustomDataProvider(this); @@ -389,8 +374,13 @@ public class DomCollectionControl extends DomUIControl imp } public static class AddAction extends AddDomElementAction { + + public AddAction() { + setShortcutSet(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.ADD)); + } + protected boolean isEnabled(final AnActionEvent e) { - return getDomCollectionControl(e) != null || "ProjectViewToolbar".equals(e.getPlace()); + return getDomCollectionControl(e) != null; } protected DomCollectionControl getDomCollectionControl(final AnActionEvent e) { @@ -428,22 +418,20 @@ public class DomCollectionControl extends DomUIControl imp } public static class EditAction extends AnAction { - protected DomCollectionControl getDomCollectionControl(final AnActionEvent e) { - return DomCollectionControl.getDomCollectionControl(e); - } public EditAction() { super(ApplicationBundle.message("action.edit"), null, DomCollectionControl.EDIT_ICON); + setShortcutSet(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.EDIT)); } public void actionPerformed(AnActionEvent e) { - final DomCollectionControl control = getDomCollectionControl(e); + final DomCollectionControl control = DomCollectionControl.getDomCollectionControl(e); control.doEdit(); control.reset(); } public void update(AnActionEvent e) { - final DomCollectionControl control = getDomCollectionControl(e); + final DomCollectionControl control = DomCollectionControl.getDomCollectionControl(e); final boolean visible = control != null && control.isEditable(); e.getPresentation().setVisible(visible); e.getPresentation().setEnabled(visible && control.getComponent().getTable().getSelectedRowCount() == 1); @@ -453,21 +441,18 @@ public class DomCollectionControl extends DomUIControl imp public static class RemoveAction extends AnAction { public RemoveAction() { super(ApplicationBundle.message("action.remove"), null, DomCollectionControl.REMOVE_ICON); - } - - protected DomCollectionControl getDomCollectionControl(final AnActionEvent e) { - return DomCollectionControl.getDomCollectionControl(e); + setShortcutSet(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.REMOVE)); } public void actionPerformed(AnActionEvent e) { - final DomCollectionControl control = getDomCollectionControl(e); + final DomCollectionControl control = DomCollectionControl.getDomCollectionControl(e); control.doRemove(); control.reset(); } public void update(AnActionEvent e) { final boolean enabled; - final DomCollectionControl control = getDomCollectionControl(e); + final DomCollectionControl control = DomCollectionControl.getDomCollectionControl(e); if (control != null) { final JTable table = control.getComponent().getTable(); enabled = table != null && table.getSelectedRowCount() > 0; diff --git a/xml/dom-openapi/src/com/intellij/util/xml/ui/actions/AddDomElementAction.java b/xml/dom-openapi/src/com/intellij/util/xml/ui/actions/AddDomElementAction.java index 0e12ce1c47bd..b89220127c21 100644 --- a/xml/dom-openapi/src/com/intellij/util/xml/ui/actions/AddDomElementAction.java +++ b/xml/dom-openapi/src/com/intellij/util/xml/ui/actions/AddDomElementAction.java @@ -22,8 +22,12 @@ import com.intellij.openapi.application.ApplicationBundle; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.popup.ListPopup; +import com.intellij.ui.CommonActionsPanel; import com.intellij.util.ReflectionUtil; -import com.intellij.util.xml.*; +import com.intellij.util.xml.DomElement; +import com.intellij.util.xml.DomManager; +import com.intellij.util.xml.ElementPresentationManager; +import com.intellij.util.xml.TypeChooser; import com.intellij.util.xml.reflect.DomCollectionChildDescription; import com.intellij.util.xml.ui.DomCollectionControl; import org.jetbrains.annotations.NotNull; @@ -31,7 +35,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -import java.awt.event.KeyEvent; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; @@ -41,8 +44,6 @@ import java.util.List; */ public abstract class AddDomElementAction extends AnAction { - private final static ShortcutSet shortcutSet = new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0)); - public AddDomElementAction() { super(ApplicationBundle.message("action.add"), null, DomCollectionControl.ADD_ICON); } @@ -84,7 +85,7 @@ public abstract class AddDomElementAction extends AnAction { final DataContext dataContext = e.getDataContext(); final ListPopup groupPopup = - JBPopupFactory.getInstance().createActionGroupPopup(null,//J2EEBundle.message("label.menu.title.add.activation.config.property"), + JBPopupFactory.getInstance().createActionGroupPopup(null, group, dataContext, JBPopupFactory.ActionSelectionAid.NUMBERING, true); showPopup(groupPopup, e); @@ -137,8 +138,9 @@ public abstract class AddDomElementAction extends AnAction { } if (actions.size() > 1 && showAsPopup()) { ActionGroup group = new ActionGroup() { + @NotNull public AnAction[] getChildren(@Nullable AnActionEvent e) { - return actions.toArray(AnAction.EMPTY_ARRAY); + return actions.toArray(new AnAction[actions.size()]); } }; return new AnAction[]{new ShowPopupAction(group)}; @@ -150,7 +152,7 @@ public abstract class AddDomElementAction extends AnAction { } } - return actions.toArray(AnAction.EMPTY_ARRAY); + return actions.toArray(new AnAction[actions.size()]); } protected abstract AnAction createAddingAction(final AnActionEvent e, @@ -178,12 +180,12 @@ public abstract class AddDomElementAction extends AnAction { protected ShowPopupAction(ActionGroup group) { super(ApplicationBundle.message("action.add"), null, DomCollectionControl.ADD_ICON); myGroup = group; - setShortcutSet(shortcutSet); + setShortcutSet(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.ADD)); } public void actionPerformed(AnActionEvent e) { final ListPopup groupPopup = - JBPopupFactory.getInstance().createActionGroupPopup(null,//J2EEBundle.message("label.menu.title.add.activation.config.property"), + JBPopupFactory.getInstance().createActionGroupPopup(null, myGroup, e.getDataContext(), JBPopupFactory.ActionSelectionAid.NUMBERING, true); showPopup(groupPopup, e);