mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Properties
This commit is contained in:
@@ -95,8 +95,6 @@ public class PropertyParser {
|
||||
if (properties == null) {
|
||||
properties = new ArrayList<Property>();
|
||||
|
||||
System.out.println("--- " + componentClass + " -----------------");
|
||||
|
||||
StyleableDefinition definitions = myDefinitions.getStyleableByName(component);
|
||||
if (definitions != null) {
|
||||
for (AttributeDefinition definition : definitions.getAttributes()) {
|
||||
@@ -118,8 +116,6 @@ public class PropertyParser {
|
||||
}
|
||||
|
||||
properties.add(property);
|
||||
|
||||
System.out.println(definition + " = " + Arrays.toString(definition.getValues()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+48
-9
@@ -17,13 +17,16 @@ package com.intellij.android.designer.propertyTable;
|
||||
|
||||
import com.intellij.android.designer.model.RadViewComponent;
|
||||
import com.intellij.android.designer.propertyTable.editors.BooleanEditor;
|
||||
import com.intellij.android.designer.propertyTable.editors.StringsComboEditor;
|
||||
import com.intellij.android.designer.propertyTable.renderers.BooleanRenderer;
|
||||
import com.intellij.designer.model.RadComponent;
|
||||
import com.intellij.designer.propertyTable.Property;
|
||||
import com.intellij.designer.propertyTable.PropertyEditor;
|
||||
import com.intellij.designer.propertyTable.PropertyRenderer;
|
||||
import com.intellij.designer.propertyTable.editors.AbstractTextFieldEditor;
|
||||
import com.intellij.designer.propertyTable.renderers.LabelPropertyRenderer;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import org.jetbrains.android.dom.attrs.AttributeDefinition;
|
||||
@@ -31,6 +34,9 @@ import org.jetbrains.android.dom.attrs.AttributeFormat;
|
||||
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.Set;
|
||||
|
||||
/**
|
||||
@@ -54,18 +60,19 @@ public class AttributeProperty extends Property<RadViewComponent> {
|
||||
myRenderer = new LabelPropertyRenderer(null);
|
||||
|
||||
if (formats.contains(AttributeFormat.Enum)) {
|
||||
|
||||
myEditor = new StringsComboEditor(definition.getValues());
|
||||
}
|
||||
else if (formats.contains(AttributeFormat.Reference)) {
|
||||
myEditor = new TextDialogEditor();
|
||||
}
|
||||
else {
|
||||
|
||||
myEditor = new AbstractTextFieldEditor() {
|
||||
@Override
|
||||
public Object getValue() throws Exception {
|
||||
return myTextField.getText();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
myEditor = new AbstractTextFieldEditor() {
|
||||
@Override
|
||||
public Object getValue() throws Exception {
|
||||
return myTextField.getText();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,4 +138,36 @@ public class AttributeProperty extends Property<RadViewComponent> {
|
||||
public PropertyEditor getEditor() {
|
||||
return myEditor;
|
||||
}
|
||||
|
||||
private static class TextDialogEditor extends PropertyEditor {
|
||||
private TextFieldWithBrowseButton myTextField;
|
||||
|
||||
public TextDialogEditor() {
|
||||
myTextField = new TextFieldWithBrowseButton(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO: Auto-generated method stub
|
||||
}
|
||||
});
|
||||
myTextField.getTextField().setBorder(null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JComponent getComponent(@Nullable RadComponent component, Object value) {
|
||||
myTextField.setText(value == null ? "" : value.toString());
|
||||
myTextField.getTextField().setBorder(null);
|
||||
return myTextField;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() throws Exception {
|
||||
return myTextField.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUI() {
|
||||
SwingUtilities.updateComponentTreeUI(myTextField);
|
||||
}
|
||||
}
|
||||
}
|
||||
+138
-10
@@ -19,12 +19,17 @@ import com.intellij.android.designer.model.RadViewComponent;
|
||||
import com.intellij.designer.propertyTable.Property;
|
||||
import com.intellij.designer.propertyTable.PropertyEditor;
|
||||
import com.intellij.designer.propertyTable.PropertyRenderer;
|
||||
import com.intellij.designer.propertyTable.editors.BooleanEditor;
|
||||
import com.intellij.designer.propertyTable.renderers.BooleanRenderer;
|
||||
import com.intellij.designer.propertyTable.renderers.LabelPropertyRenderer;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import org.jetbrains.android.dom.attrs.AttributeDefinition;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Alexander Lobas
|
||||
@@ -32,10 +37,15 @@ import java.util.List;
|
||||
public class FlagProperty extends Property<RadViewComponent> {
|
||||
private final PropertyRenderer myRenderer = new LabelPropertyRenderer(null);
|
||||
private final AttributeDefinition myDefinition;
|
||||
private final List<Property> myOptions = new ArrayList<Property>();
|
||||
|
||||
public FlagProperty(@NotNull String name, @NotNull AttributeDefinition definition) {
|
||||
super(null, name);
|
||||
myDefinition = definition;
|
||||
|
||||
for (String option : definition.getValues()) {
|
||||
myOptions.add(new OptionProperty(this, option, option));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,27 +55,41 @@ public class FlagProperty extends Property<RadViewComponent> {
|
||||
|
||||
@Override
|
||||
public List<Property> getChildren(@Nullable RadViewComponent component) {
|
||||
return super.getChildren(component); // TODO: Auto-generated method stub
|
||||
return myOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(RadViewComponent component) throws Exception {
|
||||
return "[]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(RadViewComponent component, Object value) throws Exception {
|
||||
super.setValue(component, value); // TODO: Auto-generated method stub
|
||||
StringBuffer value = new StringBuffer("[");
|
||||
Set<String> options = getOptions(component);
|
||||
int index = 0;
|
||||
for (Property option : myOptions) {
|
||||
if (options.contains(((OptionProperty)option).getValueName())) {
|
||||
if (index++ > 0) {
|
||||
value.append(", ");
|
||||
}
|
||||
value.append(option.getName());
|
||||
}
|
||||
}
|
||||
return value.append("]").toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefaultValue(RadViewComponent component) throws Exception {
|
||||
return super.isDefaultValue(component); // TODO: Auto-generated method stub
|
||||
return getAttribute(component) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultValue(RadViewComponent component) throws Exception {
|
||||
super.setDefaultValue(component); // TODO: Auto-generated method stub
|
||||
final XmlAttribute attribute = getAttribute(component);
|
||||
if (attribute != null) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
attribute.delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -78,4 +102,108 @@ public class FlagProperty extends Property<RadViewComponent> {
|
||||
public PropertyEditor getEditor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private XmlAttribute getAttribute(RadViewComponent component) {
|
||||
return component.getTag().getAttribute("android:" + myDefinition.getName());
|
||||
}
|
||||
|
||||
private Set<String> getOptions(RadViewComponent component) throws Exception {
|
||||
String value = component.getTag().getAttributeValue("android:" + myDefinition.getName());
|
||||
if (value == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
Set<String> options = new HashSet<String>();
|
||||
for (String option : StringUtil.split(value, "|")) {
|
||||
options.add(option.trim());
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
private boolean isOption(RadViewComponent component, String name) throws Exception {
|
||||
return getOptions(component).contains(name);
|
||||
}
|
||||
|
||||
private void setOption(final RadViewComponent component, String name, boolean set) throws Exception {
|
||||
final Set<String> options = new HashSet<String>(getOptions(component));
|
||||
if (set) {
|
||||
if (!options.add(name)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!options.remove(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (options.isEmpty()) {
|
||||
XmlAttribute attribute = getAttribute(component);
|
||||
if (attribute != null) {
|
||||
attribute.delete();
|
||||
}
|
||||
}
|
||||
else {
|
||||
component.getTag().setAttribute("android:" + myDefinition.getName(), StringUtil.join(options, "|"));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class OptionProperty extends Property<RadViewComponent> {
|
||||
private PropertyRenderer myRenderer = new BooleanRenderer();
|
||||
private PropertyEditor myEditor = new BooleanEditor();
|
||||
private final String myValueName;
|
||||
|
||||
public OptionProperty(@Nullable Property parent, @NotNull String name, @NotNull String valueName) {
|
||||
super(parent, name);
|
||||
myValueName = valueName;
|
||||
}
|
||||
|
||||
public String getValueName() {
|
||||
return myValueName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property createForNewPresentation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(RadViewComponent component) throws Exception {
|
||||
return isOption(component, myValueName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(RadViewComponent component, Object value) throws Exception {
|
||||
setOption(component, myValueName, (Boolean)value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefaultValue(RadViewComponent component) throws Exception {
|
||||
return !isOption(component, myValueName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultValue(RadViewComponent component) throws Exception {
|
||||
setValue(component, Boolean.FALSE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyRenderer getRenderer() {
|
||||
return myRenderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyEditor getEditor() {
|
||||
return myEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needRefreshPropertyList() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.android.designer.propertyTable.editors;
|
||||
|
||||
import com.intellij.designer.model.RadComponent;
|
||||
import com.intellij.designer.propertyTable.editors.ComboEditor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author Alexander Lobas
|
||||
*/
|
||||
public class StringsComboEditor extends ComboEditor {
|
||||
public StringsComboEditor(String[] values) {
|
||||
myCombo.setModel(new DefaultComboBoxModel(values));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JComponent getComponent(@Nullable RadComponent component, Object value) {
|
||||
myCombo.setSelectedItem(value);
|
||||
return myCombo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() throws Exception {
|
||||
return myCombo.getSelectedItem();
|
||||
}
|
||||
}
|
||||
+19
@@ -109,6 +109,10 @@ public final class PropertyTable extends JBTable implements ComponentSelectionLi
|
||||
focusedInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel");
|
||||
ancestorInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel");
|
||||
|
||||
actionMap.put("restoreDefault", new MyRestoreDefaultAction());
|
||||
focusedInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "restoreDefault");
|
||||
ancestorInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "restoreDefault");
|
||||
|
||||
actionMap.put("expandCurrent", new MyExpandCurrentAction(true));
|
||||
focusedInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0), "expandCurrent");
|
||||
ancestorInputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0));
|
||||
@@ -562,6 +566,13 @@ public final class PropertyTable extends JBTable implements ComponentSelectionLi
|
||||
Throwable cause = e.getCause();
|
||||
String message = cause == null ? e.getMessage() : cause.getMessage();
|
||||
|
||||
if (cause == null) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
else {
|
||||
cause.printStackTrace();
|
||||
}
|
||||
|
||||
if (message == null || message.length() == 0) {
|
||||
message = DesignerBundle.message("designer.properties.no_message.error");
|
||||
}
|
||||
@@ -693,6 +704,13 @@ public final class PropertyTable extends JBTable implements ComponentSelectionLi
|
||||
}
|
||||
}
|
||||
|
||||
private class MyRestoreDefaultAction extends AbstractAction {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
restoreDefaultValue();
|
||||
}
|
||||
}
|
||||
|
||||
private class MouseTableListener extends MouseAdapter {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
@@ -807,6 +825,7 @@ public final class PropertyTable extends JBTable implements ComponentSelectionLi
|
||||
|
||||
if (component instanceof JComboBox) {
|
||||
component.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
|
||||
component.putClientProperty("tableCellEditor", this);
|
||||
}
|
||||
else if (component instanceof JCheckBox) {
|
||||
component.putClientProperty("JComponent.sizeVariant", UIUtil.isUnderAquaLookAndFeel() ? "small" : null);
|
||||
|
||||
+18
-15
@@ -18,38 +18,52 @@ package com.intellij.designer.propertyTable.editors;
|
||||
import com.intellij.designer.model.RadComponent;
|
||||
import com.intellij.designer.propertyTable.PropertyEditor;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.PopupMenuEvent;
|
||||
import javax.swing.event.PopupMenuListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
/**
|
||||
* @author Alexander Lobas
|
||||
*/
|
||||
public class ComboEditor extends PropertyEditor {
|
||||
public abstract class ComboEditor extends PropertyEditor {
|
||||
protected final ComboBox myCombo;
|
||||
private boolean myCancelled;
|
||||
|
||||
public ComboEditor() {
|
||||
myCombo = new ComboBox(-1);
|
||||
myCombo.setBorder(null);
|
||||
myCombo.addPopupMenuListener(new PopupMenuListener() {
|
||||
|
||||
@Override
|
||||
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
||||
// TODO: Auto-generated method stub
|
||||
myCancelled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
|
||||
// TODO: Auto-generated method stub
|
||||
if (!myCancelled) {
|
||||
fireValueCommitted(true, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void popupMenuCanceled(PopupMenuEvent e) {
|
||||
// TODO: Auto-generated method stub
|
||||
myCancelled = true;
|
||||
}
|
||||
});
|
||||
myCombo.registerKeyboardAction(new ActionListener() {
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
myCancelled = true;
|
||||
fireEditingCancelled();
|
||||
}
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,15 +74,4 @@ public class ComboEditor extends PropertyEditor {
|
||||
SwingUtilities.updateComponentTreeUI((JComponent)renderer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() throws Exception {
|
||||
return null; // TODO: Auto-generated method stub
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JComponent getComponent(@Nullable RadComponent component, Object value) {
|
||||
return null; // TODO: Auto-generated method stub
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user