OC-9559 IDEA-107592

This commit is contained in:
Alexander Lobas
2014-04-18 23:35:53 +04:00
parent 64fc873ee4
commit c9609013a4
4 changed files with 93 additions and 9 deletions
@@ -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<T extends PropertiesContainer> {
return false;
}
//////////////////////////////////////////////////////////////////////////////////////////
//
// Copy
//
//////////////////////////////////////////////////////////////////////////////////////////
@NotNull
public Transferable doCopy(@NotNull T container, @NotNull Object commonValue) {
return new TextTransferable(commonValue.toString());
}
//////////////////////////////////////////////////////////////////////////////////////////
//
// Presentation
@@ -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<PropertiesContainer> myContainers = Collections.emptyList();
protected List<PropertiesContainer> myContainers = Collections.emptyList();
protected List<Property> myProperties = Collections.emptyList();
protected final Set<String> myExpandedProperties = new HashSet<String>();
@@ -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
@@ -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) {
@@ -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;
}
}
}