From 90963900389ce818c622c525b0990412f077150e Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Sat, 25 Feb 2012 22:04:33 +0400 Subject: [PATCH 01/14] assertValidSeparators seeks \r in array if char sequence is ready to share one --- .../openapi/util/text/StringUtil.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java index c5694078cd8c..e15a5962d3c5 100644 --- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java +++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java @@ -22,6 +22,7 @@ import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.TextRange; import com.intellij.util.*; import com.intellij.util.text.CharArrayCharSequence; +import com.intellij.util.text.CharArrayUtil; import com.intellij.util.text.LineReader; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -2061,12 +2062,29 @@ public class StringUtil { } public static void assertValidSeparators(@NotNull CharSequence s) { - for (int i = 0; i < s.length(); i++) { - if (s.charAt(i) == '\r') { - String context = String.valueOf(last(s.subSequence(0, i), 10, true)) + first(s.subSequence(i, s.length()), 10, true); - context = escapeStringCharacters(context); - LOG.error("Wrong line separators: '" + context + "' at offset " + i); + char[] chars = CharArrayUtil.fromSequenceWithoutCopying(s); + int slashRIndex = -1; + + if (chars != null) { + for(int i = 0, len = s.length(); i < len; ++i) { + if (chars[i] == '\r') { + slashRIndex = i; + break; + } } + } else { + for (int i = 0, len = s.length(); i < len; i++) { + if (s.charAt(i) == '\r') { + slashRIndex = i; + break; + } + } + } + + if (slashRIndex != -1) { + String context = String.valueOf(last(s.subSequence(0, slashRIndex), 10, true)) + first(s.subSequence(slashRIndex, s.length()), 10, true); + context = escapeStringCharacters(context); + LOG.error("Wrong line separators: '" + context + "' at offset " + slashRIndex); } } From 087580afb03cc0d97749cd3686ba40d5ac7d81e5 Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Sat, 25 Feb 2012 22:32:25 +0400 Subject: [PATCH 02/14] Actions --- .../AndroidDesignerEditorPanel.java | 84 ++++++- .../designer/model/RadViewComponent.java | 26 +++ .../android/designer/model/RadViewLayout.java | 27 ++- .../designer/DesignerToolWindowManager.java | 15 +- .../actions/CommonEditActionsProvider.java | 205 ++++++++++++++++++ .../designer/actions/DesignerActionPanel.java | 130 +++++++++++ .../designer/actions/SelectAllAction.java | 51 +++++ .../clipboard/SerializedComponentData.java | 33 +++ .../clipboard/SimpleTransferable.java | 76 +++++++ .../designer/componentTree/ComponentTree.java | 15 +- .../componentTree/ComponentTreeBuilder.java | 4 + .../designSurface/DecorationLayer.java | 16 +- .../designSurface/DesignerEditorPanel.java | 125 +++++++++-- .../designSurface/tools/DragTracker.java | 20 +- .../designSurface/tools/MarqueeTracker.java | 17 +- .../designSurface/tools/ResizeTracker.java | 13 +- .../designSurface/tools/TargetingTool.java | 9 +- .../designSurface/tools/ToolProvider.java | 7 + .../intellij/designer/model/MetaModel.java | 4 +- .../intellij/designer/model/RadComponent.java | 56 +++++ .../intellij/designer/model/RadLayout.java | 9 +- .../com/intellij/designer/palette/Group.java | 4 +- .../com/intellij/designer/palette/Item.java | 15 +- .../src/messages/DesignerBundle.properties | 3 +- 24 files changed, 877 insertions(+), 87 deletions(-) create mode 100644 plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/CommonEditActionsProvider.java create mode 100644 plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/DesignerActionPanel.java create mode 100644 plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/SelectAllAction.java create mode 100644 plugins/ui-designer/ui-designer-new/src/com/intellij/designer/clipboard/SerializedComponentData.java create mode 100644 plugins/ui-designer/ui-designer-new/src/com/intellij/designer/clipboard/SimpleTransferable.java diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java index a7dbd36119d4..89a45ce0a096 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java @@ -34,20 +34,24 @@ import com.intellij.designer.designSurface.OperationContext; import com.intellij.designer.designSurface.selection.DirectionResizePoint; import com.intellij.designer.designSurface.selection.ResizeSelectionDecorator; import com.intellij.designer.designSurface.tools.ComponentCreationFactory; -import com.intellij.designer.designSurface.tools.CreationTool; +import com.intellij.designer.designSurface.tools.ComponentPasteFactory; import com.intellij.designer.model.MetaManager; import com.intellij.designer.model.RadComponent; +import com.intellij.designer.palette.Item; import com.intellij.designer.utils.Position; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.psi.XmlRecursiveElementVisitor; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; +import com.intellij.util.ThrowableRunnable; import org.jetbrains.android.facet.AndroidFacet; import org.jetbrains.android.sdk.AndroidPlatform; import org.jetbrains.android.uipreview.*; @@ -56,9 +60,8 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; +import java.util.Collections; import java.util.List; import java.util.concurrent.Callable; @@ -74,10 +77,19 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { public AndroidDesignerEditorPanel(@NotNull Module module, @NotNull VirtualFile file) { super(module, file); + myActionPanel.getActionGroup() + .add(new AnAction("Android", "Description", IconLoader.getIcon("/com/intellij/android/designer/icons/DeviceScreen.png")) { + @Override + public void actionPerformed(AnActionEvent e) { + System.out.println("Action: " + e); + } + }); + myActionPanel.update(); + myXmlFile = (XmlFile)ApplicationManager.getApplication().runReadAction(new Computable() { @Override public PsiFile compute() { - return PsiManager.getInstance(myModule.getProject()).findFile(myFile); + return PsiManager.getInstance(getProject()).findFile(myFile); } }); @@ -111,7 +123,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { showDesignerCard(); myLayeredPane.repaint(); - DesignerToolWindowManager.getInstance(myModule.getProject()).refresh(); + DesignerToolWindowManager.getInstance(getProject()).refresh(); } catch (Throwable e) { showError("Parse error: ", e); @@ -120,7 +132,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { private void parseFile() throws Throwable { final RadViewComponent[] rootComponents = new RadViewComponent[1]; - final MetaManager metaManager = ViewsMetaManager.getInstance(myModule.getProject()); + final MetaManager metaManager = ViewsMetaManager.getInstance(getProject()); final String layoutXmlText = ApplicationManager.getApplication().runReadAction(new Computable() { RadViewComponent myComponent; @@ -188,7 +200,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { int size = views.size(); if (size == 1) { RadViewComponent newRootComponent = new RadViewComponent(null); - newRootComponent.setMetaModel(ViewsMetaManager.getInstance(myModule.getProject()).getModelByTag("")); + newRootComponent.setMetaModel(ViewsMetaManager.getInstance(getProject()).getModelByTag("")); newRootComponent.getChildren().add(rootComponent); rootComponent.setParent(newRootComponent); @@ -252,7 +264,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { ThemeData theme = new ThemeData("Theme", false); - return RenderUtil.createRenderSession(myModule.getProject(), layoutXmlText, myFile, target, facet, config, xdpi, ydpi, theme); + return RenderUtil.createRenderSession(getProject(), layoutXmlText, myFile, target, facet, config, xdpi, ydpi, theme); } }).get(); } @@ -270,6 +282,11 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { mySession = null; } + @Override + public String getPlatformTarget() { + return "android"; + } + @Override public TreeComponentDecorator getTreeDecorator() { return myTreeDecorator; @@ -287,6 +304,55 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { return null; } + @Override + @NotNull + protected ComponentCreationFactory createCreationFactory(Item paletteItem) { + return new ComponentCreationFactory() { + @Override + @NotNull + public RadComponent create() throws Exception { + return new RadViewComponent(null); + } + }; + //return null; // TODO: Auto-generated method stub + } + + @Override + public ComponentPasteFactory createPasteFactory(String xmlComponents) { + return new ComponentPasteFactory() { + @NotNull + @Override + public List create() throws Exception { + return Collections.singletonList(new RadViewComponent(null)); + } + }; + //return null; // TODO: Auto-generated method stub + } + + @Override + protected boolean execute(ThrowableRunnable operation) { + try { + operation.run(); + return true; + } + catch (Throwable e) { + showError("Execute command", e); + return false; + } + } + + @Override + protected void execute(List operations) { + try { + for (EditOperation operation : operations) { + operation.execute(); + } + } + catch (Throwable e) { + showError("Execute command", e); + } + } + private static class RootView extends JComponent { private final BufferedImage myImage; diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java index a1fed127fcb9..5b923514ea3a 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java @@ -16,7 +16,12 @@ package com.intellij.android.designer.model; import com.intellij.designer.model.RadComponent; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.DefaultActionGroup; +import com.intellij.openapi.util.IconLoader; import com.intellij.psi.xml.XmlTag; +import org.jdom.Element; import javax.swing.*; import java.awt.*; @@ -29,6 +34,13 @@ import java.util.List; * @author Alexander Lobas */ public class RadViewComponent extends RadComponent { + public static final AnAction LinearLayout = + new AnAction("Horizontal/Vertical", "LinearLayout", IconLoader.getIcon("/com/intellij/android/designer/icons/LinearLayout.png")) { + @Override + public void actionPerformed(AnActionEvent e) { + } + }; + private final List myChildren = new ArrayList(); private Component myNativeComponent; private final Rectangle myBounds = new Rectangle(); @@ -81,4 +93,18 @@ public class RadViewComponent extends RadComponent { public Point convertPoint(Component component, int x, int y) { return SwingUtilities.convertPoint(component, x, y, myNativeComponent); } + + @Override + public void addSelectionActions(DefaultActionGroup actionGroup, JComponent shortcuts, List selection) { + if (myTag != null && myTag.getName().equals("LinearLayout") && selection.size() == 1 && selection.get(0) == this) { + AnAction action = new AnAction() { + @Override + public void actionPerformed(AnActionEvent e) { + System.out.println("LinearLayout: " + e); + } + }; + action.copyFrom(LinearLayout); + actionGroup.add(action); + } + } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java index 8d380af0ccc2..c9872c80f061 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java @@ -17,10 +17,16 @@ package com.intellij.android.designer.model; import com.intellij.designer.designSurface.ComponentDecorator; import com.intellij.designer.designSurface.selection.NonResizeSelectionDecorator; +import com.intellij.designer.model.MetaModel; import com.intellij.designer.model.RadComponent; import com.intellij.designer.model.RadLayout; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.DefaultActionGroup; +import javax.swing.*; import java.awt.*; +import java.util.List; /** * @author Alexander Lobas @@ -33,7 +39,26 @@ public class RadViewLayout extends RadLayout { } @Override - public ComponentDecorator getChildSelectionDecorator(RadComponent component) { + public ComponentDecorator getChildSelectionDecorator(RadComponent component, List selection) { return new NonResizeSelectionDecorator(Color.RED, 1); } + + @Override + public void addSelectionActions(DefaultActionGroup actionGroup, JComponent shortcuts, List selection) { + if (myContainer.getTag() != null && myContainer.getTag().getName().equals("LinearLayout")) { + for (RadComponent component : selection) { + if (myContainer != component.getParent()) { + return; + } + } + AnAction action = new AnAction() { + @Override + public void actionPerformed(AnActionEvent e) { + System.out.println("LinearLayout: " + e); + } + }; + action.copyFrom(RadViewComponent.LinearLayout); + actionGroup.add(action); + } + } } \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/DesignerToolWindowManager.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/DesignerToolWindowManager.java index 75c4ceb56ca5..396ac828daff 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/DesignerToolWindowManager.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/DesignerToolWindowManager.java @@ -17,6 +17,7 @@ package com.intellij.designer; import com.intellij.designer.componentTree.ComponentTree; import com.intellij.designer.componentTree.ComponentTreeBuilder; +import com.intellij.designer.componentTree.TreeEditableArea; import com.intellij.designer.designSurface.DesignerEditorPanel; import com.intellij.designer.propertyTable.PropertyTablePanel; import com.intellij.ide.util.treeView.AbstractTreeBuilder; @@ -43,6 +44,7 @@ import com.intellij.util.ui.update.MergingUpdateQueue; import com.intellij.util.ui.update.Update; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; @@ -56,7 +58,7 @@ public final class DesignerToolWindowManager implements ProjectComponent { private final FileEditorManager myFileEditorManager; private ToolWindow myToolWindow; private ComponentTree myComponentTree; - private AbstractTreeBuilder myTreeBuilder; + private ComponentTreeBuilder myTreeBuilder; private PropertyTablePanel myPropertyTablePanel; private boolean myToolWindowReady; private boolean myToolWindowDisposed; @@ -119,6 +121,12 @@ public final class DesignerToolWindowManager implements ProjectComponent { } } + @Nullable + public TreeEditableArea getTreeArea() { + return myTreeBuilder == null ? null : myTreeBuilder.getTreeArea(); + } + + @Nullable private static DesignerEditorPanel getDesigner(FileEditor editor) { if (editor instanceof DesignerEditor) { DesignerEditor designerEditor = (DesignerEditor)editor; @@ -127,7 +135,8 @@ public final class DesignerToolWindowManager implements ProjectComponent { return null; } - private DesignerEditorPanel getActiveDesigner() { + @Nullable + public DesignerEditorPanel getActiveDesigner() { FileEditor[] editors = myFileEditorManager.getSelectedEditors(); return editors.length > 0 ? getDesigner(editors[0]) : null; } @@ -150,10 +159,12 @@ public final class DesignerToolWindowManager implements ProjectComponent { myComponentTree.newModel(); if (designer == null) { myComponentTree.setDecorator(null); + myComponentTree.setActionPanel(null); myToolWindow.setAvailable(false, null); } else { myComponentTree.setDecorator(designer.getTreeDecorator()); + myComponentTree.setActionPanel(designer.getActionPanel()); myTreeBuilder = new ComponentTreeBuilder(myComponentTree, designer); myToolWindow.setAvailable(true, null); myToolWindow.show(null); diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/CommonEditActionsProvider.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/CommonEditActionsProvider.java new file mode 100644 index 000000000000..8a8e49639826 --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/CommonEditActionsProvider.java @@ -0,0 +1,205 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.designer.actions; + +import com.intellij.designer.DesignerBundle; +import com.intellij.designer.clipboard.SerializedComponentData; +import com.intellij.designer.clipboard.SimpleTransferable; +import com.intellij.designer.designSurface.DesignerEditorPanel; +import com.intellij.designer.designSurface.tools.ComponentPasteFactory; +import com.intellij.designer.designSurface.tools.PasteTool; +import com.intellij.designer.model.RadComponent; +import com.intellij.ide.CopyProvider; +import com.intellij.ide.CutProvider; +import com.intellij.ide.DeleteProvider; +import com.intellij.ide.PasteProvider; +import com.intellij.ide.dnd.FileCopyPasteUtil; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.ide.CopyPasteManager; +import com.intellij.util.ThrowableRunnable; +import org.jdom.Element; +import org.jdom.output.XMLOutputter; +import org.jetbrains.annotations.Nullable; + +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.util.List; + +/** + * @author Alexander Lobas + */ +public class CommonEditActionsProvider implements DeleteProvider, CopyProvider, PasteProvider, CutProvider { + private static final DataFlavor DATA_FLAVOR = FileCopyPasteUtil.createJvmDataFlavor(SerializedComponentData.class); + + private final DesignerEditorPanel myDesigner; + + public CommonEditActionsProvider(DesignerEditorPanel designer) { + myDesigner = designer; + } + ////////////////////////////////////////////////////////////////////////////////////////// + // + // Delete + // + ////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public boolean canDeleteElement(DataContext dataContext) { + // TODO: InplaceEditing + List selection = myDesigner.getActionsArea().getSelection(); + if (selection.isEmpty()) { + return false; + } + for (RadComponent component : selection) { + if (!component.canDelete()) { + return false; + } + } + return true; + } + + @Override + public void deleteElement(DataContext dataContext) { + CommandProcessor.getInstance().executeCommand(myDesigner.getProject(), new Runnable() { + public void run() { + myDesigner.getToolProvider().execute(new ThrowableRunnable() { + @Override + public void run() throws Exception { + List components = RadComponent.getPureSelection(myDesigner.getActionsArea().getSelection()); + for (RadComponent component : components) { + component.delete(); + } + } + }); + } + }, DesignerBundle.message("command.delete.selection"), null); + } + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // Copy + // + ////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public boolean isCopyVisible(DataContext dataContext) { + return true; + } + + @Override + public boolean isCopyEnabled(DataContext dataContext) { + // TODO: InplaceEditing + return !myDesigner.getActionsArea().getSelection().isEmpty(); + } + + @Override + public void performCopy(DataContext dataContext) { + doCopy(); + } + + private boolean doCopy() { + return myDesigner.getToolProvider().execute(new ThrowableRunnable() { + @Override + public void run() throws Exception { + Element root = new Element("designer"); + root.setAttribute("target", myDesigner.getPlatformTarget()); + + List components = RadComponent.getPureSelection(myDesigner.getActionsArea().getSelection()); + for (RadComponent component : components) { + component.copyTo(root); + } + + SerializedComponentData data = new SerializedComponentData(new XMLOutputter().outputString(root)); + CopyPasteManager.getInstance().setContents(new SimpleTransferable(data, DATA_FLAVOR)); + } + }); + } + ////////////////////////////////////////////////////////////////////////////////////////// + // + // Paste + // + ////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public boolean isPastePossible(DataContext dataContext) { + return isPasteEnabled(dataContext); + } + + @Override + public boolean isPasteEnabled(DataContext dataContext) { + // TODO: InplaceEditing + return getSerializedComponentData() != null; + } + + @Nullable + private String getSerializedComponentData() { + try { + CopyPasteManager copyPasteManager = CopyPasteManager.getInstance(); + if (!copyPasteManager.isDataFlavorAvailable(DATA_FLAVOR)) { + return null; + } + + Transferable content = copyPasteManager.getContents(); + if (content == null) { + return null; + } + + Object transferData = content.getTransferData(DATA_FLAVOR); + if (transferData instanceof SerializedComponentData) { + SerializedComponentData data = (SerializedComponentData)transferData; + String xmlComponents = data.getSerializedComponents(); + if (xmlComponents.startsWith("")) { + return xmlComponents; + } + } + } + catch (Throwable e) { + } + + return null; + } + + @Override + public void performPaste(DataContext dataContext) { + ComponentPasteFactory factory = myDesigner.createPasteFactory(getSerializedComponentData()); + if (factory != null) { + myDesigner.getToolProvider().setActiveTool(new PasteTool(true, factory)); + } + } + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // Cut + // + ////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public boolean isCutVisible(DataContext dataContext) { + return true; + } + + @Override + public boolean isCutEnabled(DataContext dataContext) { + return isCopyEnabled(dataContext) && canDeleteElement(dataContext); + } + + @Override + public void performCut(DataContext dataContext) { + if (doCopy()) { + deleteElement(dataContext); + } + } +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/DesignerActionPanel.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/DesignerActionPanel.java new file mode 100644 index 000000000000..e6b9f646ede3 --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/DesignerActionPanel.java @@ -0,0 +1,130 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.designer.actions; + +import com.intellij.designer.designSurface.ComponentSelectionListener; +import com.intellij.designer.designSurface.DesignerEditorPanel; +import com.intellij.designer.designSurface.EditableArea; +import com.intellij.designer.model.RadComponent; +import com.intellij.openapi.actionSystem.*; +import com.intellij.ui.IdeBorderFactory; +import com.intellij.ui.SideBorder; +import com.intellij.util.containers.hash.HashSet; +import org.jetbrains.annotations.NonNls; + +import javax.swing.*; +import java.util.List; +import java.util.Set; + +/** + * @author Alexander Lobas + */ +public class DesignerActionPanel implements DataProvider { + public static final String TOOLBAR = "DesignerToolbar"; + public static final String POPUP = "DesignerPopup"; + + private final DefaultActionGroup myActionGroup = new DefaultActionGroup(); + private final DefaultActionGroup myStaticGroup = new DefaultActionGroup(); + private final DefaultActionGroup myDynamicGroup = new DefaultActionGroup(); + private final ActionToolbar myToolbar; + private final CommonEditActionsProvider myCommonEditActionsProvider; + private final JComponent myShortcuts; + + public DesignerActionPanel(DesignerEditorPanel designer, JComponent shortcuts) { + myCommonEditActionsProvider = new CommonEditActionsProvider(designer); + myShortcuts = shortcuts; + + myActionGroup.add(myStaticGroup); + myActionGroup.add(myDynamicGroup); + myToolbar = ActionManager.getInstance().createActionToolbar(TOOLBAR, myActionGroup, true); + myToolbar.setMiniMode(true); + + registerAction(new SelectAllAction(designer.getSurfaceArea()), "$SelectAll"); + + designer.getSurfaceArea().addSelectionListener(new ComponentSelectionListener() { + @Override + public void selectionChanged(EditableArea area) { + updateSelectionActions(area.getSelection()); + } + }); + } + + private void registerAction(AnAction action, @NonNls String actionId) { + action.registerCustomShortcutSet( + ActionManager.getInstance().getAction(actionId).getShortcutSet(), + myShortcuts + ); + } + + public JComponent getToolbarComponent() { + return myToolbar.getComponent(); + } + + public DefaultActionGroup getActionGroup() { + return myStaticGroup; + } + + public void update() { + boolean isEmpty = myActionGroup.getChildrenCount() == 0; + + myToolbar.updateActionsImmediately(); + myToolbar.setMiniMode(isEmpty); + + if (!isEmpty) { + myToolbar.getComponent().setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM)); + } + } + + private void updateSelectionActions(List selection) { + boolean update = myDynamicGroup.getChildrenCount() > 0; + + for (AnAction action : myDynamicGroup.getChildActionsOrStubs()) { + action.unregisterCustomShortcutSet(myShortcuts); + } + myDynamicGroup.removeAll(); + + Set parents = new HashSet(); + for (RadComponent component : selection) { + RadComponent parent = component.getParent(); + if (parent != null) { + parents.add(parent); + } + } + + for (RadComponent parent : parents) { + parent.getLayout().addSelectionActions(myDynamicGroup, myShortcuts, selection); + } + for (RadComponent component : selection) { + component.addSelectionActions(myDynamicGroup, myShortcuts, selection); + } + update |= myDynamicGroup.getChildrenCount() > 0; + + if (update) { + update(); + } + } + + @Override + public Object getData(@NonNls String dataId) { + if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId) || + PlatformDataKeys.CUT_PROVIDER.is(dataId) || + PlatformDataKeys.COPY_PROVIDER.is(dataId) || + PlatformDataKeys.PASTE_PROVIDER.is(dataId)) { + return myCommonEditActionsProvider; + } + return null; + } +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/SelectAllAction.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/SelectAllAction.java new file mode 100644 index 000000000000..944e2566307e --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/SelectAllAction.java @@ -0,0 +1,51 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.designer.actions; + +import com.intellij.designer.designSurface.EditableArea; +import com.intellij.designer.model.RadComponent; +import com.intellij.designer.model.RadComponentVisitor; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Alexander Lobas + */ +public class SelectAllAction extends AnAction { + private final EditableArea myArea; + + public SelectAllAction(EditableArea area) { + myArea = area; + } + + @Override + public void actionPerformed(AnActionEvent e) { + RadComponent rootComponent = myArea.getRootComponent(); + if (rootComponent != null) { + final List components = new ArrayList(); + rootComponent.accept(new RadComponentVisitor() { + @Override + public void endVisit(RadComponent component) { + components.add(component); + } + }, true); + myArea.setSelection(components); + } + } +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/clipboard/SerializedComponentData.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/clipboard/SerializedComponentData.java new file mode 100644 index 000000000000..c2ec117fe37a --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/clipboard/SerializedComponentData.java @@ -0,0 +1,33 @@ +/* + * 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.clipboard; + +/** + * This class must be in main classloader because of JVM's restrictions (it's used as DataFlavor class) + * + * @author yole + */ +public final class SerializedComponentData { + private final String mySerializedComponents; + + public SerializedComponentData(String components) { + mySerializedComponents = components; + } + + public String getSerializedComponents() { + return mySerializedComponents; + } +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/clipboard/SimpleTransferable.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/clipboard/SimpleTransferable.java new file mode 100644 index 000000000000..12071e6253fb --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/clipboard/SimpleTransferable.java @@ -0,0 +1,76 @@ +/* + * 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.clipboard; + +import com.intellij.openapi.diagnostic.Logger; +import org.jetbrains.annotations.Nullable; + +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.IOException; + +/** + * @author yole + */ +public class SimpleTransferable implements Transferable { + private static final Logger LOG = Logger.getInstance("#com.intellij.designer.clipboard.SimpleTransferable"); + + private final Object myData; + private final DataFlavor myFlavor; + + public SimpleTransferable(Object data, DataFlavor flavor) { + myData = data; + myFlavor = flavor; + } + + @Override + public DataFlavor[] getTransferDataFlavors() { + try { + return new DataFlavor[]{myFlavor}; + } + catch (Exception ex) { + LOG.error(ex); + return new DataFlavor[0]; + } + } + + @Override + public boolean isDataFlavorSupported(DataFlavor flavor) { + try { + return myFlavor.equals(flavor); + } + catch (Exception ex) { + LOG.error(ex); + return false; + } + } + + @Override + @Nullable + public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { + try { + if (!myFlavor.equals(flavor)) { + return null; + } + return myData; + } + catch (Exception e) { + LOG.error(e); + return null; + } + } +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTree.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTree.java index 00d88adf08fa..d78e51425a84 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTree.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTree.java @@ -15,6 +15,7 @@ */ package com.intellij.designer.componentTree; +import com.intellij.designer.actions.DesignerActionPanel; import com.intellij.designer.designSurface.FeedbackTreeLayer; import com.intellij.designer.model.RadComponent; import com.intellij.openapi.actionSystem.DataProvider; @@ -37,6 +38,7 @@ import java.awt.*; */ public final class ComponentTree extends Tree implements DataProvider { private TreeComponentDecorator myDecorator; + private DesignerActionPanel myActionPanel; private RadComponent myMarkComponent; private int myMarkFeedback; @@ -64,11 +66,15 @@ public final class ComponentTree extends Tree implements DataProvider { setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); } - public void setDecorator(TreeComponentDecorator decorator) { + public void setDecorator(@Nullable TreeComponentDecorator decorator) { myDecorator = decorator; myMarkComponent = null; } + public void setActionPanel(@Nullable DesignerActionPanel actionPanel) { + myActionPanel = actionPanel; + } + public void mark(RadComponent component, int feedback) { myMarkComponent = component; myMarkFeedback = feedback; @@ -77,7 +83,12 @@ public final class ComponentTree extends Tree implements DataProvider { @Override public Object getData(@NonNls String dataId) { - return null; //TODO + // TODO: support keys + + if (myActionPanel != null) { + return myActionPanel.getData(dataId); + } + return null; } @Nullable diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java index 16d05a471e27..71f7675d413c 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTreeBuilder.java @@ -50,6 +50,10 @@ public final class ComponentTreeBuilder extends AbstractTreeBuilder implements C addListeners(); } + public TreeEditableArea getTreeArea() { + return myTreeArea; + } + @Override public void dispose() { removeListeners(); diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DecorationLayer.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DecorationLayer.java index 3c23fa4cd134..3502c90926e0 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DecorationLayer.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DecorationLayer.java @@ -21,6 +21,8 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; +import java.util.*; +import java.util.List; /** * @author Alexander Lobas @@ -34,8 +36,9 @@ public class DecorationLayer extends JComponent { @Nullable public InputTool findTargetTool(int x, int y) { - for (RadComponent component : myArea.getSelection()) { - ComponentDecorator decorator = getDecorator(component); + List selection = myArea.getSelection(); + for (RadComponent component : selection) { + ComponentDecorator decorator = getDecorator(component, selection); InputTool tracker = decorator.findTargetTool(this, component, x, y); if (tracker != null) { return tracker; @@ -50,17 +53,18 @@ public class DecorationLayer extends JComponent { } private void painSelection(Graphics2D g) { - for (RadComponent component : myArea.getSelection()) { - ComponentDecorator decorator = getDecorator(component); + List selection = myArea.getSelection(); + for (RadComponent component : selection) { + ComponentDecorator decorator = getDecorator(component, selection); decorator.decorate(this, g, component); } } - private ComponentDecorator getDecorator(RadComponent component) { + private ComponentDecorator getDecorator(RadComponent component, List selection) { RadComponent parent = component.getParent(); if (parent == null) { return myArea.getRootSelectionDecorator(); } - return parent.getLayout().getChildSelectionDecorator(component); + return parent.getLayout().getChildSelectionDecorator(component, selection); } } \ No newline at end of file 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 65d6f52b78e1..4d30219a5a8e 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 @@ -16,17 +16,22 @@ package com.intellij.designer.designSurface; import com.intellij.designer.DesignerToolWindowManager; +import com.intellij.designer.actions.DesignerActionPanel; import com.intellij.designer.componentTree.TreeComponentDecorator; -import com.intellij.designer.designSurface.tools.InputTool; -import com.intellij.designer.designSurface.tools.SelectionTool; -import com.intellij.designer.designSurface.tools.ToolProvider; +import com.intellij.designer.componentTree.TreeEditableArea; +import com.intellij.designer.designSurface.tools.*; +import com.intellij.designer.model.MetaModel; import com.intellij.designer.model.RadComponent; import com.intellij.designer.model.RadComponentVisitor; +import com.intellij.designer.palette.Item; +import com.intellij.ide.palette.PaletteItem; +import com.intellij.ide.palette.impl.PaletteManager; import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.ScrollPaneFactory; @@ -36,7 +41,10 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; import java.awt.*; /** @@ -59,14 +67,19 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider private final CardLayout myLayout = new CardLayout(); private JPanel myDesignerCard; + + protected DesignerActionPanel myActionPanel; + private CaptionPanel myHorizontalCaption; private CaptionPanel myVerticalCaption; + private JScrollPane myScrollPane; protected JLayeredPane myLayeredPane; protected GlassLayer myGlassLayer; private DecorationLayer myDecorationLayer; private FeedbackLayer myFeedbackLayer; + private ListSelectionListener myPaletteListener; protected ToolProvider myToolProvider; protected EditableArea mySurfaceArea; @@ -90,15 +103,16 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider add(myDesignerCard, DESIGNER_CARD); GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridx = 0; - gbc.gridy = 1; + gbc.gridy = 2; gbc.fill = GridBagConstraints.BOTH; myVerticalCaption = new CaptionPanel(this, false); myDesignerCard.add(myVerticalCaption, gbc); gbc.gridx = 1; - gbc.gridy = 0; + gbc.gridy = 1; myHorizontalCaption = new CaptionPanel(this, true); myDesignerCard.add(myHorizontalCaption, gbc); @@ -149,12 +163,45 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider } }; + myPaletteListener = new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + if (DesignerToolWindowManager.getInstance(getProject()).getActiveDesigner() == DesignerEditorPanel.this) { + Item paletteItem = (Item)PaletteManager.getInstance(getProject()).getActiveItem(); + if (paletteItem != null) { + myToolProvider.setActiveTool(new CreationTool(true, createCreationFactory(paletteItem))); + } + else if (myToolProvider.getActiveTool() instanceof CreationTool) { + myToolProvider.loadDefaultTool(); + } + } + } + }; + myToolProvider = new ToolProvider() { @Override public void loadDefaultTool() { setActiveTool(new SelectionTool()); } + @Override + public void setActiveTool(InputTool tool) { + if (getActiveTool() instanceof CreationTool && !(tool instanceof CreationTool)) { + PaletteManager.getInstance(getProject()).clearActiveItem(); + } + super.setActiveTool(tool); + } + + @Override + public boolean execute(ThrowableRunnable operation) { + return DesignerEditorPanel.this.execute(operation); + } + + @Override + public void execute(List operations) { + DesignerEditorPanel.this.execute(operations); + } + @Override public void showError(@NonNls String message, Throwable e) { DesignerEditorPanel.this.showError(message, e); @@ -171,13 +218,29 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider myLayeredPane.add(myFeedbackLayer, LAYER_FEEDBACK); gbc.gridx = 1; - gbc.gridy = 1; + gbc.gridy = 2; gbc.weightx = 1; gbc.weighty = 1; myScrollPane = ScrollPaneFactory.createScrollPane(myLayeredPane); myScrollPane.setBackground(Color.WHITE); myDesignerCard.add(myScrollPane, gbc); + + gbc.gridx = 0; + gbc.gridy = 0; + gbc.gridwidth = 2; + gbc.weightx = 0; + gbc.weighty = 0; + gbc.fill = GridBagConstraints.HORIZONTAL; + + myActionPanel = new DesignerActionPanel(this, myGlassLayer); + myDesignerCard.add(myActionPanel.getToolbarComponent(), gbc); + + PaletteManager.getInstance(getProject()).addSelectionListener(myPaletteListener); + } + + protected final void showDesignerCard() { + myLayout.show(this, DESIGNER_CARD); } private void createErrorCard() { @@ -185,33 +248,54 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider add(myErrorLabel, ERROR_CARD); } - protected final void showDesignerCard() { - myLayout.show(this, DESIGNER_CARD); + public void showError(@NonNls String message, Throwable e) { + myRootComponent = null; + myErrorLabel.setText(message + e.toString()); + myLayout.show(this, ERROR_CARD); + DesignerToolWindowManager.getInstance(getProject()).refresh(); + repaint(); + if (ApplicationManagerEx.getApplicationEx().isInternal()) { + e.printStackTrace(); + } + } + + public abstract String getPlatformTarget(); + + public Project getProject() { + return myModule.getProject(); } public EditableArea getSurfaceArea() { return mySurfaceArea; } + public EditableArea getActionsArea() { + TreeEditableArea treeArea = DesignerToolWindowManager.getInstance(getProject()).getTreeArea(); + return treeArea == null ? mySurfaceArea : treeArea; + } + public ToolProvider getToolProvider() { return myToolProvider; } + public DesignerActionPanel getActionPanel() { + return myActionPanel; + } + protected abstract ComponentDecorator getRootSelectionDecorator(); @Nullable protected abstract EditOperation processRootOperation(OperationContext context); - public void showError(@NonNls String message, Throwable e) { - myRootComponent = null; - myErrorLabel.setText(message + e.toString()); - myLayout.show(this, ERROR_CARD); - DesignerToolWindowManager.getInstance(myModule.getProject()).refresh(); - repaint(); - if (ApplicationManagerEx.getApplicationEx().isInternal()) { - e.printStackTrace(); - } - } + protected abstract boolean execute(ThrowableRunnable operation); + + protected abstract void execute(List operations); + + @NotNull + protected abstract ComponentCreationFactory createCreationFactory(Item paletteItem); + + @Nullable + public abstract ComponentPasteFactory createPasteFactory(String xmlComponents); public void activate() { } @@ -221,11 +305,12 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider @Override public Object getData(@NonNls String dataId) { - return null; //To change body of implemented methods use File | Settings | File Templates. + // TODO: support keys + return myActionPanel.getData(dataId); } public void dispose() { - // TODO: Auto-generated method stub + PaletteManager.getInstance(getProject()).removeSelectionListener(myPaletteListener); } public JComponent getPreferredFocusedComponent() { diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/DragTracker.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/DragTracker.java index d001b23d962c..c657bd64afa5 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/DragTracker.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/DragTracker.java @@ -122,14 +122,7 @@ public class DragTracker extends SelectionTracker { myContext.setLocation(getLocation()); if (myContext.getComponents() == null) { - List components = new ArrayList(); - List selection = myArea.getSelection(); - - for (RadComponent component : selection) { - if (!isParentsContainedIn(selection, component)) { - components.add(component); - } - } + List components = RadComponent.getPureSelection(myArea.getSelection()); RadComponent parent = null; for (RadComponent component : components) { @@ -148,15 +141,4 @@ public class DragTracker extends SelectionTracker { } } } - - private static boolean isParentsContainedIn(List components, RadComponent component) { - RadComponent parent = component.getParent(); - while (parent != null) { - if (components.contains(parent)) { - return true; - } - parent = parent.getParent(); - } - return false; - } } \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/MarqueeTracker.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/MarqueeTracker.java index 64b9479a31b1..17116f7d051c 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/MarqueeTracker.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/MarqueeTracker.java @@ -134,15 +134,18 @@ public class MarqueeTracker extends InputTool { private void performMarqueeSelect() { final Rectangle selectionRectangle = getSelectionRectangle(); final List newSelection = new ArrayList(); + RadComponent rootComponent = myArea.getRootComponent(); - myArea.getRootComponent().accept(new RadComponentVisitor() { - @Override - public void endVisit(RadComponent component) { - if (selectionRectangle.contains(component.getBounds(myArea.getNativeComponent()))) { - newSelection.add(component); + if (rootComponent != null) { + rootComponent.accept(new RadComponentVisitor() { + @Override + public void endVisit(RadComponent component) { + if (selectionRectangle.contains(component.getBounds(myArea.getNativeComponent()))) { + newSelection.add(component); + } } - } - }, true); + }, true); + } if (mySelectionMode == TOGGLE_MODE) { List selection = new ArrayList(myArea.getSelection()); diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/ResizeTracker.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/ResizeTracker.java index 5b43768cd769..213cf8068538 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/ResizeTracker.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/ResizeTracker.java @@ -116,16 +116,13 @@ public class ResizeTracker extends InputTool { private void executeCommand() { if (myExecuteEnabled) { - try { - for (EditOperation operation : getOperations()) { - if (operation.canExecute()) { - operation.execute(); - } + List operations = new ArrayList(); + for (EditOperation operation : getOperations()) { + if (operation.canExecute()) { + operations.add(operation); } } - catch (Exception e) { - myToolProvider.showError("Execute command: ", e); - } + myToolProvider.execute(operations); } } diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/TargetingTool.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/TargetingTool.java index b7209eb8fb9a..9bb7df7b8e1a 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/TargetingTool.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/TargetingTool.java @@ -22,6 +22,8 @@ import com.intellij.designer.model.RadComponent; import com.intellij.designer.model.RadLayout; import org.jetbrains.annotations.Nullable; +import java.util.Collections; + /** * @author Alexander Lobas */ @@ -76,12 +78,7 @@ public abstract class TargetingTool extends InputTool { protected void executeCommand() { if (myExecuteEnabled) { - try { - myTargetOperation.execute(); - } - catch (Exception e) { - myToolProvider.showError("Execute command: ", e); - } + myToolProvider.execute(Collections.singletonList(myTargetOperation)); } } diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/ToolProvider.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/ToolProvider.java index d8a5012ae174..434fe67c7e1d 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/ToolProvider.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/tools/ToolProvider.java @@ -15,12 +15,15 @@ */ package com.intellij.designer.designSurface.tools; +import com.intellij.designer.designSurface.EditOperation; import com.intellij.designer.designSurface.EditableArea; +import com.intellij.util.ThrowableRunnable; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; +import java.util.List; /** * @author Alexander Lobas @@ -126,4 +129,8 @@ public abstract class ToolProvider { } public abstract void loadDefaultTool(); + + public abstract boolean execute(ThrowableRunnable operation); + + public abstract void execute(List operations); } \ No newline at end of file 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 ad361e454da1..e6e8a0ed9c08 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 @@ -17,6 +17,7 @@ package com.intellij.designer.model; import com.intellij.designer.palette.Item; import com.intellij.openapi.util.IconLoader; +import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -92,7 +93,8 @@ public class MetaModel { return myPaletteItem; } - public void setPaletteItem(Item paletteItem) { + public void setPaletteItem(@NotNull Item paletteItem) { myPaletteItem = paletteItem; + myPaletteItem.setMetaModel(this); } } \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java index 3b1a7c1794e2..757d130325a7 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java @@ -19,12 +19,15 @@ import com.intellij.designer.designSurface.OperationContext; import com.intellij.designer.designSurface.tools.DragTracker; import com.intellij.designer.designSurface.tools.InputTool; import com.intellij.designer.propertyTable.Property; +import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.util.containers.hash.HashMap; +import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -38,6 +41,12 @@ public abstract class RadComponent { private RadLayout myLayout; private final Map myClientProperties = new HashMap(); + ////////////////////////////////////////////////////////////////////////////////////////// + // + // MetaModel + // + ////////////////////////////////////////////////////////////////////////////////////////// + public MetaModel getMetaModel() { return myMetaModel; } @@ -97,6 +106,8 @@ public abstract class RadComponent { public void processDropOperation(OperationContext context) { } + public void addSelectionActions(DefaultActionGroup actionGroup, JComponent shortcuts, List selection) { + } ////////////////////////////////////////////////////////////////////////////////////////// // // layout @@ -157,4 +168,49 @@ public abstract class RadComponent { visitor.endVisit(this); } } + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // Operations + // + ////////////////////////////////////////////////////////////////////////////////////////// + + public boolean canDelete() { + return true; + } + + public void delete() throws Exception { + } + + public void copyTo(Element parentElement) throws Exception { + } + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // Utils + // + ////////////////////////////////////////////////////////////////////////////////////////// + + public static boolean isParentsContainedIn(List components, RadComponent component) { + RadComponent parent = component.getParent(); + while (parent != null) { + if (components.contains(parent)) { + return true; + } + parent = parent.getParent(); + } + return false; + } + + public static List getPureSelection(List selection) { + List components = new ArrayList(); + + for (RadComponent component : selection) { + if (!isParentsContainedIn(selection, component)) { + components.add(component); + } + } + + return components; + } } \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadLayout.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadLayout.java index a4a3e310c691..7f4e0982a868 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadLayout.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadLayout.java @@ -18,16 +18,23 @@ package com.intellij.designer.model; import com.intellij.designer.designSurface.ComponentDecorator; import com.intellij.designer.designSurface.EditOperation; import com.intellij.designer.designSurface.OperationContext; +import com.intellij.openapi.actionSystem.DefaultActionGroup; import org.jetbrains.annotations.Nullable; +import javax.swing.*; +import java.util.List; + /** * @author Alexander Lobas */ public abstract class RadLayout { - public abstract ComponentDecorator getChildSelectionDecorator(RadComponent component); + public abstract ComponentDecorator getChildSelectionDecorator(RadComponent component, List selection); @Nullable public EditOperation processChildOperation(OperationContext context) { return null; } + + public void addSelectionActions(DefaultActionGroup actionGroup, JComponent shortcuts, List selection) { + } } \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Group.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Group.java index ed8d7790ea9f..23905efe5ad2 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Group.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Group.java @@ -59,12 +59,12 @@ public final class Group implements PaletteGroup { @Override public ActionGroup getPopupActionGroup() { - return (ActionGroup)ActionManager.getInstance().getAction("Designer.PaletteGroupPopupMenu"); + return null; // TODO: Auto-generated method stub } @Override public Object getData(Project project, String dataId) { - return null; // TODO: Auto-generated method stub + return null; // TODO: Auto-generated method stub } @Override diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Item.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Item.java index 06da4e8306ae..5da043ce8e45 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Item.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/palette/Item.java @@ -15,6 +15,7 @@ */ package com.intellij.designer.palette; +import com.intellij.designer.model.MetaModel; import com.intellij.ide.dnd.DnDDragStartBean; import com.intellij.ide.palette.PaletteItem; import com.intellij.openapi.actionSystem.ActionGroup; @@ -35,6 +36,8 @@ public final class Item implements PaletteItem { private Icon myIcon; private String myTooltip; + private MetaModel myMetaModel; + public Item(String title, String iconPath, String tooltip) { myTitle = title; myIconPath = iconPath; @@ -66,11 +69,19 @@ public final class Item implements PaletteItem { @Override public ActionGroup getPopupActionGroup() { - return (ActionGroup)ActionManager.getInstance().getAction("Designer.PaletteItemPopupMenu"); + return null; // TODO: Auto-generated method stub } @Override public Object getData(Project project, String dataId) { - return null; // TODO: Auto-generated method stub + return null; // TODO: Auto-generated method stub + } + + public MetaModel getMetaModel() { + return myMetaModel; + } + + public void setMetaModel(MetaModel metaModel) { + myMetaModel = metaModel; } } \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/messages/DesignerBundle.properties b/plugins/ui-designer/ui-designer-new/src/messages/DesignerBundle.properties index ccbb2605abf0..f9d86bec4cad 100644 --- a/plugins/ui-designer/ui-designer-new/src/messages/DesignerBundle.properties +++ b/plugins/ui-designer/ui-designer-new/src/messages/DesignerBundle.properties @@ -1,2 +1,3 @@ designer.toolwindow.name=Designer -designer.toolwindow.title=Component Tree \ No newline at end of file +designer.toolwindow.title=Component Tree +command.delete.selection=Delete Selection \ No newline at end of file From 980e34376aac27c055cdac3d8e992aa64ff47d58 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Sun, 26 Feb 2012 02:07:18 +0100 Subject: [PATCH 03/14] modality wars --- .../ide/diff/VirtualFileDiffElement.java | 35 ++++++++----------- .../diff/impl/dir/DirDiffManagerImpl.java | 2 +- .../diff/impl/dir/DirDiffTableModel.java | 26 ++++---------- 3 files changed, 22 insertions(+), 41 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/diff/VirtualFileDiffElement.java b/platform/platform-impl/src/com/intellij/ide/diff/VirtualFileDiffElement.java index 422fb29338da..90ec7c08a626 100644 --- a/platform/platform-impl/src/com/intellij/ide/diff/VirtualFileDiffElement.java +++ b/platform/platform-impl/src/com/intellij/ide/diff/VirtualFileDiffElement.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. @@ -20,8 +20,6 @@ import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.AccessToken; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.diff.DiffRequest; import com.intellij.openapi.editor.Document; @@ -271,31 +269,26 @@ public class VirtualFileDiffElement extends DiffElement { final FileDocumentManager manager = FileDocumentManager.getInstance(); for (Document document : manager.getUnsavedDocuments()) { VirtualFile file = manager.getFile(document); - if (file!=null && VfsUtilCore.isAncestor(virtualFile, file, false)) { + if (file != null && VfsUtilCore.isAncestor(virtualFile, file, false)) { docsToSave.add(document); } } if (!docsToSave.isEmpty()) { - ApplicationManager.getApplication().invokeAndWait(new Runnable() { - @Override - public void run() { - AccessToken token = WriteAction.start(); - try { - for (Document document : docsToSave) { - manager.saveDocument(document); - } - } - finally { - token.finish(); - } + AccessToken token = WriteAction.start(); + try { + for (Document document : docsToSave) { + manager.saveDocument(document); } - }, ModalityState.defaultModalityState()); + } + finally { + token.finish(); + } } + if (!FileWatcher.getInstance().isWatched(virtualFile)) { + ((NewVirtualFile)virtualFile).markDirtyRecursively(); + } + virtualFile.refresh(true, true); } - if (!FileWatcher.getInstance().isWatched(virtualFile)) { - ((NewVirtualFile)virtualFile).markDirtyRecursively(); - } - virtualFile.refresh(false, true); } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffManagerImpl.java index c4126cccdf75..cdd2727419d1 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffManagerImpl.java @@ -54,7 +54,7 @@ public class DirDiffManagerImpl extends DirDiffManager { frame.show(); } else { DirDiffDialog dirDiffDialog = new DirDiffDialog(myProject, model); - if (myProject == null || myProject.isDefault() || isFromModalDialog(myProject)) { + if (myProject == null || myProject.isDefault()/* || isFromModalDialog(myProject)*/) { dirDiffDialog.setModal(true); } setWindowListener(onWindowClose, dirDiffDialog.getOwner()); diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java index cd0a9ca34abb..1964b1c72218 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java @@ -24,7 +24,7 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ex.ApplicationManagerEx; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.MessageType; @@ -206,8 +206,7 @@ public class DirDiffTableModel extends AbstractTableModel implements DirDiffMode myUpdating.set(true); final JBLoadingPanel loadingPanel = getLoadingPanel(); loadingPanel.startLoading(); - - final Runnable action = new Runnable() { + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { public void run() { try { updater = new Updater(loadingPanel, 100); @@ -229,12 +228,7 @@ public class DirDiffTableModel extends AbstractTableModel implements DirDiffMode applySettings(); } } - }; - if (DirDiffManagerImpl.isFromModalDialog(myProject)) { - action.run(); - } else { - ApplicationManager.getApplication().executeOnPooledThread(action); - } + }); } private void reportException(final String htmlContent) { @@ -285,7 +279,7 @@ public class DirDiffTableModel extends AbstractTableModel implements DirDiffMode clear(); myElements.addAll(elements); myUpdating.set(false); - myTable.revalidate(); + fireTableDataChanged(); DirDiffTableModel.this.text.set(""); if (loadingPanel.isLoading()) { loadingPanel.stopLoading(); @@ -301,13 +295,7 @@ public class DirDiffTableModel extends AbstractTableModel implements DirDiffMode if (myProject.isDefault()) { SwingUtilities.invokeLater(uiThread); } else { - final AccessToken token = ApplicationManager.getApplication().acquireReadActionLock(); - try { - ApplicationManagerEx.getApplicationEx().runEdtSafeAction(uiThread); - } - finally { - token.finish(); - } + app.invokeLater(uiThread, ModalityState.any()); } } }); @@ -779,7 +767,7 @@ public class DirDiffTableModel extends AbstractTableModel implements DirDiffMode } catch (InterruptedException e) {// } - SwingUtilities.invokeLater(new Runnable() { + ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { final String s = text.get(); @@ -787,7 +775,7 @@ public class DirDiffTableModel extends AbstractTableModel implements DirDiffMode myLoadingPanel.setLoadingText(s); } } - }); + }, ModalityState.stateForComponent(myLoadingPanel)); updater = new Updater(myLoadingPanel, mySleep); updater.start(); } else { From 2389a0687744d08c5f1cc4b251a6282ce1bab067 Mon Sep 17 00:00:00 2001 From: "kirill.safonov" Date: Thu, 23 Feb 2012 20:20:15 +0400 Subject: [PATCH 04/14] JDK -> SDK --- .../platform-resources-en/src/messages/IdeBundle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-resources-en/src/messages/IdeBundle.properties b/platform/platform-resources-en/src/messages/IdeBundle.properties index d645042cb8df..04cb05f5726d 100644 --- a/platform/platform-resources-en/src/messages/IdeBundle.properties +++ b/platform/platform-resources-en/src/messages/IdeBundle.properties @@ -679,7 +679,7 @@ title.select.project.file.directory=Select {0} file directory description.select.project.file.directory={0} file will be stored in this directory label.please.enter.project.name=Please enter a name to create a new {0} {1}. prompt.please.select.project.jdk=Please select project SDK.\nThis SDK will be used by default by all project modules. -label.project.jdk=Project JDK: +label.project.jdk=Project SDK: button.configure=&Configure... prompt.confirm.project.no.jdk=Do you want to create a project with no SDK assigned?\nSDK is required for compiling, debugging and running applications\nas well as for standard SDK classes resolution. title.no.jdk.specified=No SDK Specified From 814efeeee9de63dc602c8c8f45e32ca2871474d7 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Sun, 26 Feb 2012 16:33:35 +0400 Subject: [PATCH 05/14] IDEA-81486 (IDEA complains about "stable" snapshot dependencies) Don't highlight stable snapshot dependencies red. --- .../MavenArtifactCoordinatesVersionConverter.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesVersionConverter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesVersionConverter.java index b7afdd34061a..ceec59f41e39 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesVersionConverter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/converters/MavenArtifactCoordinatesVersionConverter.java @@ -22,8 +22,12 @@ import org.jetbrains.idea.maven.model.MavenId; import java.util.Collections; import java.util.Set; +import java.util.regex.Pattern; public class MavenArtifactCoordinatesVersionConverter extends MavenArtifactCoordinatesConverter { + + private static final Pattern MAGIC_VERSION_PATTERN = Pattern.compile("\\s*(?:LATEST|RELEASE|[(\\[].*|.*-20\\d{6}\\.[0-2]\\d{5}-\\d+)\\s*"); + @Override protected boolean doIsValid(MavenId id, MavenProjectIndicesManager manager, ConvertContext context) { if (StringUtil.isEmpty(id.getGroupId()) @@ -31,15 +35,10 @@ public class MavenArtifactCoordinatesVersionConverter extends MavenArtifactCoord || StringUtil.isEmpty(id.getVersion())) { return false; } - if (isMagicVersion(id)) return true; // todo handle ranges more sensibly + if (MAGIC_VERSION_PATTERN.matcher(id.getVersion()).matches()) return true; // todo handle ranges more sensibly return manager.hasVersion(id.getGroupId(), id.getArtifactId(), id.getVersion()); } - private boolean isMagicVersion(MavenId id) { - String version = id.getVersion().trim(); - return version.equals("LATEST") || version.equals("RELEASE") || version.startsWith("(") || version.startsWith("["); - } - @Override protected Set doGetVariants(MavenId id, MavenProjectIndicesManager manager) { if (StringUtil.isEmpty(id.getGroupId()) || StringUtil.isEmpty(id.getArtifactId())) return Collections.emptySet(); From e2d7315aee1e2851de96dfc437c9757b40a7564f Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Sun, 26 Feb 2012 15:37:35 +0400 Subject: [PATCH 06/14] cleanup --- .../src/com/intellij/openapi/extensions/Extensions.java | 2 +- .../src/com/intellij/ide/plugins/PluginManager.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java b/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java index 04642acee638..6e0af9b95f0a 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/Extensions.java @@ -147,7 +147,7 @@ public class Extensions { return getRootArea().getExtensionPoint(AREA_LISTENER_EXTENSION_POINT).getExtensions(); } - public static void registerAreaClass(@NonNls String areaClass, @NonNls String parentAreaClass) { + public static void registerAreaClass(@NonNls String areaClass, @Nullable @NonNls String parentAreaClass) { if (ourAreaClass2Configuration.containsKey(areaClass)) { // allow duplicate area class registrations if they are the same - fixing duplicate registration in tests is much more trouble AreaClassConfiguration configuration = ourAreaClass2Configuration.get(areaClass); diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java index 3257425964e4..b07c594c0fdf 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java @@ -358,7 +358,7 @@ public class PluginManager { //noinspection HardCodedStringLiteral final String pluginId = System.getProperty("idea.load.plugins.id"); if (pluginId == null) { - if (descriptor instanceof IdeaPluginDescriptorImpl && !((IdeaPluginDescriptorImpl)descriptor).isEnabled()) return true; + if (descriptor instanceof IdeaPluginDescriptorImpl && !descriptor.isEnabled()) return true; if (!shouldLoadPlugins()) return true; } @@ -443,7 +443,7 @@ public class PluginManager { } public static boolean isIncompatible(final IdeaPluginDescriptor descriptor) { - BuildNumber buildNumber = null; + BuildNumber buildNumber; try { buildNumber = getBuildNumber(); } @@ -614,7 +614,7 @@ public class PluginManager { final String pathProperty = System.getProperty(PROPERTY_PLUGIN_PATH); if (pathProperty == null) return; - for (java.util.StringTokenizer t = new java.util.StringTokenizer(pathProperty, File.pathSeparator); t.hasMoreTokens();) { + for (StringTokenizer t = new StringTokenizer(pathProperty, File.pathSeparator); t.hasMoreTokens();) { String s = t.nextToken(); final IdeaPluginDescriptorImpl ideaPluginDescriptor = loadDescriptor(new File(s), PLUGIN_XML); if (ideaPluginDescriptor != null) { From c89abe9dc88697d7a38c96dbeeffe2bb5d72a82e Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Sun, 26 Feb 2012 19:08:28 +0400 Subject: [PATCH 07/14] cleanup --- .../intellij/openapi/application/impl/ApplicationImpl.java | 2 +- platform/testFramework/src/_LastInSuiteTest.java | 7 +------ .../com/intellij/testFramework/LightPlatformTestCase.java | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index b3f56b46d224..62e85334f893 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -202,7 +202,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application boolean isHeadless, boolean isCommandLine, @NotNull String appName, - Splash splash) { + @Nullable Splash splash) { super(null); ApplicationManager.setApplication(this, myLastDisposable); // reset back to null only when all components already disposed diff --git a/platform/testFramework/src/_LastInSuiteTest.java b/platform/testFramework/src/_LastInSuiteTest.java index 6ef2c2afd273..ea8463a6d3c3 100644 --- a/platform/testFramework/src/_LastInSuiteTest.java +++ b/platform/testFramework/src/_LastInSuiteTest.java @@ -42,12 +42,7 @@ public class _LastInSuiteTest extends TestCase { UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { - try { - LightPlatformTestCase.disposeApplication(); - } - catch (Exception e) { - throw new RuntimeException(e); - } + LightPlatformTestCase.disposeApplication(); } }); diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 58c841027f5d..9ed1809a4b89 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -155,7 +155,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da } @TestOnly - public static void disposeApplication() throws Exception { + public static void disposeApplication() { if (ourApplication != null) { Disposer.dispose(ourApplication); ourApplication = null; From da1e08540a5cf5193267becfb29b36a5084a78a5 Mon Sep 17 00:00:00 2001 From: Evgeny Zakrevsky Date: Sun, 26 Feb 2012 21:06:33 +0400 Subject: [PATCH 08/14] OptionalChooserComponent. Border has fixed. --- .../src/com/intellij/ui/OptionalChooserComponent.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/platform-api/src/com/intellij/ui/OptionalChooserComponent.java b/platform/platform-api/src/com/intellij/ui/OptionalChooserComponent.java index dbf4464ea373..97094ce67f4e 100644 --- a/platform/platform-api/src/com/intellij/ui/OptionalChooserComponent.java +++ b/platform/platform-api/src/com/intellij/ui/OptionalChooserComponent.java @@ -59,6 +59,7 @@ public abstract class OptionalChooserComponent implements CheckBoxListListene private void createUIComponents() { myList = new CheckBoxList(this); + myList.setBorder(null); myListModel = (DefaultListModel)myList.getModel(); } From 108532059f12e9f68b7df5bd61b8883cb7f1b169 Mon Sep 17 00:00:00 2001 From: Evgeny Zakrevsky Date: Sun, 26 Feb 2012 21:07:13 +0400 Subject: [PATCH 09/14] Toolbar Decorator for Paths Chooser. --- .../intellij/ui/PathsChooserComponent.form | 49 ------------------- .../intellij/ui/PathsChooserComponent.java | 27 +++++----- 2 files changed, 12 insertions(+), 64 deletions(-) delete mode 100644 platform/platform-api/src/com/intellij/ui/PathsChooserComponent.form diff --git a/platform/platform-api/src/com/intellij/ui/PathsChooserComponent.form b/platform/platform-api/src/com/intellij/ui/PathsChooserComponent.form deleted file mode 100644 index fd2d4dfbdc22..000000000000 --- a/platform/platform-api/src/com/intellij/ui/PathsChooserComponent.form +++ /dev/null @@ -1,49 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/platform/platform-api/src/com/intellij/ui/PathsChooserComponent.java b/platform/platform-api/src/com/intellij/ui/PathsChooserComponent.java index be6008261557..e0935ac0c4c2 100644 --- a/platform/platform-api/src/com/intellij/ui/PathsChooserComponent.java +++ b/platform/platform-api/src/com/intellij/ui/PathsChooserComponent.java @@ -28,8 +28,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.List; @@ -40,8 +38,6 @@ import java.util.List; public class PathsChooserComponent implements ComponentWithEmptyText { private JPanel myContentPane; private JBList myList; - private JButton myAddButton; - private JButton myRemoveButton; private final DefaultListModel myListModel; private List myWorkingCollection; @@ -55,18 +51,17 @@ public class PathsChooserComponent implements ComponentWithEmptyText { public PathsChooserComponent(@NotNull final List collection, @NotNull final PathProcessor processor, @Nullable final Project project) { + myList = new JBList(); + myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myInitialCollection = collection; myProject = project; myWorkingCollection = new ArrayList(myInitialCollection); myListModel = new DefaultListModel(); myList.setModel(myListModel); - // fill list - reset(); - - // listeners - myAddButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { + myContentPane = ToolbarDecorator.createDecorator(myList).disableUpDownActions().setAddAction(new AnActionButtonRunnable() { + @Override + public void run(AnActionButton button) { final FileChooserDescriptor dirChooser = FileChooserDescriptorFactory.createSingleFolderDescriptor(); dirChooser.setShowFileSystemRoots(true); dirChooser.setHideIgnored(true); @@ -84,10 +79,9 @@ public class PathsChooserComponent implements ComponentWithEmptyText { } }); } - }); - - myRemoveButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { + }).setRemoveAction(new AnActionButtonRunnable() { + @Override + public void run(AnActionButton button) { int selected = myList.getSelectedIndex(); if (selected != -1) { // removing index @@ -97,7 +91,10 @@ public class PathsChooserComponent implements ComponentWithEmptyText { } } } - }); + }).createPanel(); + + // fill list + reset(); } @Override From 4fe0ae886f6d26d7ccd0f85645139244279b8852 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Sun, 26 Feb 2012 20:54:28 +0400 Subject: [PATCH 10/14] Add "true com.springsource.loaded.*" to stepping filters. --- .../GroovyDebuggerClassFilterProvider.java | 17 +++++++---------- resources/src/DebuggerSettings.xml | 4 ++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/debugger/filters/GroovyDebuggerClassFilterProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/debugger/filters/GroovyDebuggerClassFilterProvider.java index ac50c0773ec6..f8ae68069f2d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/debugger/filters/GroovyDebuggerClassFilterProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/debugger/filters/GroovyDebuggerClassFilterProvider.java @@ -17,28 +17,25 @@ package org.jetbrains.plugins.groovy.debugger.filters; import com.intellij.ui.classFilter.ClassFilter; import com.intellij.ui.classFilter.DebuggerClassFilterProvider; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames; -import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; /** * @author ilyas */ public class GroovyDebuggerClassFilterProvider implements DebuggerClassFilterProvider { - private static final ClassFilter[] FILTERS = {new ClassFilter("org.codehaus.groovy.*"), new ClassFilter("groovy.*")}; + private static final List FILTERS = Arrays.asList(new ClassFilter("org.codehaus.groovy.*"), new ClassFilter("groovy.*")); public List getFilters() { - - final GroovyDebuggerSettings settings = GroovyDebuggerSettings.getInstance(); - final Boolean flag = settings.DEBUG_DISABLE_SPECIFIC_GROOVY_METHODS; - final ArrayList list = new ArrayList(); + GroovyDebuggerSettings settings = GroovyDebuggerSettings.getInstance(); + Boolean flag = settings.DEBUG_DISABLE_SPECIFIC_GROOVY_METHODS; if (flag == null || flag.booleanValue()) { - ContainerUtil.addAll(list, FILTERS); - return list; + return FILTERS; } - return list; + return Collections.emptyList(); } public boolean isAuxiliaryFrame(String className, String methodName) { diff --git a/resources/src/DebuggerSettings.xml b/resources/src/DebuggerSettings.xml index b61860511d4f..9e9abb06af0b 100644 --- a/resources/src/DebuggerSettings.xml +++ b/resources/src/DebuggerSettings.xml @@ -64,4 +64,8 @@