From c9609013a4f09be6e1e6bbfe91ad6181b19b5d89 Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Fri, 18 Apr 2014 23:35:18 +0400 Subject: [PATCH] OC-9559 IDEA-107592 --- .../com/intellij/designer/model/Property.java | 13 +++++ .../designer/propertyTable/PropertyTable.java | 21 +++++++- .../propertyTable/PropertyTablePanel.java | 16 ++++-- .../propertyTable/RadPropertyTable.java | 52 +++++++++++++++++-- 4 files changed, 93 insertions(+), 9 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/designer/model/Property.java b/platform/platform-impl/src/com/intellij/designer/model/Property.java index 8c6d85fbf03b..51d27b767691 100644 --- a/platform/platform-impl/src/com/intellij/designer/model/Property.java +++ b/platform/platform-impl/src/com/intellij/designer/model/Property.java @@ -18,9 +18,11 @@ package com.intellij.designer.model; import com.intellij.designer.propertyTable.PropertyEditor; import com.intellij.designer.propertyTable.PropertyRenderer; import com.intellij.psi.PsiElement; +import com.intellij.util.ui.TextTransferable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.awt.datatransfer.Transferable; import java.util.Collections; import java.util.List; @@ -124,6 +126,17 @@ public abstract class Property { return false; } + ////////////////////////////////////////////////////////////////////////////////////////// + // + // Copy + // + ////////////////////////////////////////////////////////////////////////////////////////// + + @NotNull + public Transferable doCopy(@NotNull T container, @NotNull Object commonValue) { + return new TextTransferable(commonValue.toString()); + } + ////////////////////////////////////////////////////////////////////////////////////////// // // Presentation diff --git a/platform/platform-impl/src/com/intellij/designer/propertyTable/PropertyTable.java b/platform/platform-impl/src/com/intellij/designer/propertyTable/PropertyTable.java index 8a101141a3f5..06d487255f40 100644 --- a/platform/platform-impl/src/com/intellij/designer/propertyTable/PropertyTable.java +++ b/platform/platform-impl/src/com/intellij/designer/propertyTable/PropertyTable.java @@ -22,6 +22,7 @@ import com.intellij.designer.model.PropertyContext; import com.intellij.designer.propertyTable.renderers.LabelPropertyRenderer; import com.intellij.ide.ui.search.SearchUtil; import com.intellij.lang.annotation.HighlightSeverity; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.TextAttributesKey; @@ -84,7 +85,7 @@ public abstract class PropertyTable extends JBTable { private final TableSpeedSearch mySpeedSearch; private final AbstractTableModel myModel = new PropertyTableModel(); - private List myContainers = Collections.emptyList(); + protected List myContainers = Collections.emptyList(); protected List myProperties = Collections.emptyList(); protected final Set myExpandedProperties = new HashSet(); @@ -636,7 +637,7 @@ public abstract class PropertyTable extends JBTable { } @Nullable - private Object getValue(Property property) throws Exception { + protected final Object getValue(Property property) throws Exception { int size = myContainers.size(); if (size == 0) { return null; @@ -815,6 +816,15 @@ public abstract class PropertyTable extends JBTable { } } + @Override + public void removeEditor() { + super.removeEditor(); + updateEditActions(); + } + + protected void updateEditActions() { + } + private boolean setValueAtRow(int row, final Object newValue) { final Property property = myProperties.get(row); @@ -1165,6 +1175,13 @@ public abstract class PropertyTable extends JBTable { .append(MessageFormat.format("Error getting value: {0}", e.getMessage()), SimpleTextAttributes.ERROR_ATTRIBUTES); return errComponent; } + finally { + ApplicationManager.getApplication().invokeLater(new Runnable() { + public void run() { + updateEditActions(); + } + }); + } } @Override diff --git a/plugins/ui-designer-core/src/com/intellij/designer/propertyTable/PropertyTablePanel.java b/plugins/ui-designer-core/src/com/intellij/designer/propertyTable/PropertyTablePanel.java index 6a98c017cff8..a44a34398d3c 100644 --- a/plugins/ui-designer-core/src/com/intellij/designer/propertyTable/PropertyTablePanel.java +++ b/plugins/ui-designer-core/src/com/intellij/designer/propertyTable/PropertyTablePanel.java @@ -57,7 +57,12 @@ public final class PropertyTablePanel extends JPanel implements ListSelectionLis private final JLabel myTitleLabel; public PropertyTablePanel(final Project project) { - myPropertyTable = new RadPropertyTable(project); + myPropertyTable = new RadPropertyTable(project) { + @Override + protected void updateEditActions() { + updateActions(); + } + }; setLayout(new GridBagLayout()); @@ -67,7 +72,8 @@ public final class PropertyTablePanel extends JPanel implements ListSelectionLis myTitleLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL)); add(myTitleLabel, new GridBagConstraints(gridX++, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, - new Insets(2, 5, 2, 10), 0, 0)); + new Insets(2, 5, 2, 10), 0, 0) + ); ActionManager actionManager = ActionManager.getInstance(); DefaultActionGroup actionGroup = new DefaultActionGroup(); @@ -87,12 +93,14 @@ public final class PropertyTablePanel extends JPanel implements ListSelectionLis myTabPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0)); add(myTabPanel, new GridBagConstraints(gridX++, 0, 1, 1, 1, 0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, - new Insets(2, 0, 2, 0), 0, 0)); + new Insets(2, 0, 2, 0), 0, 0) + ); myActionPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0)); add(myActionPanel, new GridBagConstraints(gridX++, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, - new Insets(2, 0, 2, 2), 0, 0)); + new Insets(2, 0, 2, 2), 0, 0) + ); myActions = actionGroup.getChildren(null); for (AnAction action : myActions) { diff --git a/plugins/ui-designer-core/src/com/intellij/designer/propertyTable/RadPropertyTable.java b/plugins/ui-designer-core/src/com/intellij/designer/propertyTable/RadPropertyTable.java index 0fe7d64f0411..3ce8a72703d7 100644 --- a/plugins/ui-designer-core/src/com/intellij/designer/propertyTable/RadPropertyTable.java +++ b/plugins/ui-designer-core/src/com/intellij/designer/propertyTable/RadPropertyTable.java @@ -21,12 +21,16 @@ import com.intellij.designer.designSurface.ComponentSelectionListener; import com.intellij.designer.designSurface.DesignerEditorPanel; import com.intellij.designer.designSurface.EditableArea; import com.intellij.designer.model.*; +import com.intellij.ide.CopyProvider; import com.intellij.lang.annotation.HighlightSeverity; +import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.editor.colors.TextAttributesKey; +import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.project.Project; import com.intellij.util.ThrowableRunnable; +import com.intellij.util.ui.TextTransferable; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,10 +41,13 @@ import javax.swing.event.ListSelectionListener; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; import java.awt.*; +import java.awt.datatransfer.Transferable; import java.util.Collections; import java.util.List; public class RadPropertyTable extends PropertyTable implements DataProvider, ComponentSelectionListener { + private final MyCopyProvider myCopyProvider = new MyCopyProvider(); + private final Project myProject; private EditableArea myArea; @@ -91,8 +98,13 @@ public class RadPropertyTable extends PropertyTable implements DataProvider, Com @Override public Object getData(@NonNls String dataId) { - if (PlatformDataKeys.FILE_EDITOR.is(dataId) && myDesigner != null) { - return myDesigner.getEditor(); + if (myDesigner != null) { + if (PlatformDataKeys.FILE_EDITOR.is(dataId)) { + return myDesigner.getEditor(); + } + if (PlatformDataKeys.COPY_PROVIDER.is(dataId) && !isEditing()) { + return myCopyProvider; + } } return null; } @@ -185,4 +197,38 @@ public class RadPropertyTable extends PropertyTable implements DataProvider, Com protected PropertyContext getPropertyContext() { return myDesigner; } -} + + private class MyCopyProvider implements CopyProvider { + + @Override + public void performCopy(@NotNull DataContext dataContext) { + try { + Property property = getSelectionProperty(); + Object value = getValue(property); + Transferable transferable; + + if (value == null) { + transferable = new TextTransferable(""); + } + else { + transferable = property.doCopy(myContainers.get(0), value); + } + + CopyPasteManager.getInstance().setContents(transferable); + } + catch (Throwable e) { + myDesigner.showError("Copy property error", e); + } + } + + @Override + public boolean isCopyEnabled(@NotNull DataContext dataContext) { + return getSelectionProperty() != null; + } + + @Override + public boolean isCopyVisible(@NotNull DataContext dataContext) { + return true; + } + } +} \ No newline at end of file