diff -r 9d36fe77552e css.visual/src/org/netbeans/modules/css/visual/AutocompleteJComboBox.java --- a/css.visual/src/org/netbeans/modules/css/visual/AutocompleteJComboBox.java Wed Oct 31 14:54:22 2012 +0100 +++ b/css.visual/src/org/netbeans/modules/css/visual/AutocompleteJComboBox.java Wed Oct 31 17:29:16 2012 +0100 @@ -44,69 +44,198 @@ * * @author marekfukala */ - package org.netbeans.modules.css.visual; -import java.util.logging.Level; +import java.awt.Rectangle; import java.util.logging.Logger; +import javax.accessibility.Accessible; +import javax.swing.ComboBoxEditor; import javax.swing.ComboBoxModel; import javax.swing.JComboBox; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; -import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; +import javax.swing.JList; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.plaf.basic.ComboPopup; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import javax.swing.text.JTextComponent; import org.jdesktop.swingx.autocomplete.ObjectToStringConverter; +import org.netbeans.modules.css.lib.api.properties.PropertyDefinition; public class AutocompleteJComboBox extends JComboBox { private static final Logger LOGGER = Logger.getLogger(AutocompleteJComboBox.class.getSimpleName()); - private boolean popupCancelled; public AutocompleteJComboBox(ComboBoxModel model, ObjectToStringConverter objectToStringConverter) { super(model); - initialize(objectToStringConverter); +// setEditable(true); + ComboBoxEditor comboEditor = getEditor(); + JTextComponent textEditor = ( JTextComponent ) comboEditor.getEditorComponent(); + Document doc = textEditor.getDocument(); + doc.addDocumentListener( new AutoComleteListener() ); + +// initialize(objectToStringConverter); } +// @Override +// public void setValue(Object o) { +// ignoreSelectionEvents = true; +// setSelectedItem(o); +// ignoreSelectionEvents = false; +// } +// private void initialize(ObjectToStringConverter converter) { - AutoCompleteDecorator.decorate(this, converter); +// AutoCompleteDecorator.decorate(this, converter); //At least on Mac and Windows XP L&F, the decorated JComboBox doesn't not fire //ActionEvent when the value is confirmed. - addPopupMenuListener(new PopupMenuListener() { - @Override - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - popupCancelled = false; +// addPopupMenuListener(new PopupMenuListener() { +// @Override +// public void popupMenuWillBecomeVisible(PopupMenuEvent e) { +// popupCancelled = false; +// } +// +// @Override +// public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { +// if (!popupCancelled) { +// superFireActionEvent(); +// } +// } +// +// @Override +// public void popupMenuCanceled(PopupMenuEvent e) { +// popupCancelled = false; +// } +// }); + + } + + + + public String getSelectedPropertyName() { + Object selected = getModel().getSelectedItem(); + if (selected != null) { + if (selected instanceof PropertyDefinition) { + PropertyDefinition pd = (PropertyDefinition) selected; + return pd.getName(); + } else if (selected instanceof String) { + String val = (String) selected; + if (!val.trim().isEmpty()) { + return val; + } + } + } + return null; + } + +// @Override +// protected void fireActionEvent() { +// LOGGER.log(Level.FINE, "fireActionEvent()", new Exception()); +// LOGGER.log(Level.FINE, "popup opened: {0}", isPopupVisible()); +// +// //On the contrary to the ActionEvent not being fired upon entering the value, +// //each keystroke causes an ActionEvent to be fired!!! +// //So filter out such action events and fire the action event only when the popup is closed +// //and it has not been cancelled. +// } +// +// private void superFireActionEvent() { +// //really fire the action event once the edited value is confirmed +// super.fireActionEvent(); +// } + + private boolean ignoreSelectionEvents = false; +// final boolean isAutoComplete; + + private class AutoComleteListener implements DocumentListener { + + @Override + public void insertUpdate( DocumentEvent e ) { + matchSelection( e ); + } + + @Override + public void removeUpdate( DocumentEvent e ) { + matchSelection( e ); + } + + @Override + public void changedUpdate( DocumentEvent e ) { + matchSelection( e ); + } + } + + private void matchSelection( DocumentEvent e ) { + if( ignoreSelectionEvents ) + return; + try { + ignoreSelectionEvents = true; + if( !isDisplayable() ) + return; + String editorText; + try { + editorText = e.getDocument().getText( 0, e.getDocument().getLength() ); + } catch( BadLocationException ex ) { + //ignore + return; } - @Override - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - if (!popupCancelled) { - superFireActionEvent(); - } + if( null != getSelectedItem() && getSelectedItem().toString().equals(editorText) ) + return; + + if( !isPopupVisible() ) { + showPopup(); } - @Override - public void popupMenuCanceled(PopupMenuEvent e) { - popupCancelled = false; + JList list = getPopupList(); + if( null == list ) + return; + + int matchIndex = findMatch( editorText ); + + if( matchIndex >= 0 ) { + list.setSelectedIndex( matchIndex ); + Rectangle rect = list.getCellBounds(matchIndex, matchIndex); + if( null != rect ) + list.scrollRectToVisible( rect ); + } else { + list.clearSelection(); + list.scrollRectToVisible( new Rectangle( 1, 1 ) ); } - }); - + } finally { + ignoreSelectionEvents = false; + } } - @Override - protected void fireActionEvent() { - LOGGER.log(Level.FINE, "fireActionEvent()", new Exception()); - LOGGER.log(Level.FINE, "popup opened: {0}", isPopupVisible()); - - //On the contrary to the ActionEvent not being fired upon entering the value, - //each keystroke causes an ActionEvent to be fired!!! - //So filter out such action events and fire the action event only when the popup is closed - //and it has not been cancelled. + private int findMatch( String editorText ) { + if( null == editorText || editorText.isEmpty() ) + return -1; + + for( int i=0; i getCategoryProperties(PropertyCategory cat) { Collection defs = Properties.getPropertyDefinitions(getModel().getLookup().lookup(FileObject.class), true); List defsInCat = new ArrayList(); - for(PropertyDefinition d : defs) { - if(d.getPropertyCategory() == cat) { + for (PropertyDefinition d : defs) { + if (d.getPropertyCategory() == cat) { defsInCat.add(d); } } return defsInCat; } - + /** * Returns an unique id of the property within current rule. * @@ -543,6 +561,10 @@ propertyCategory.getShortDescription()); } + public void add_Add_Property_FeatureDescriptor() { + properties.add(create_Add_Property_Feature_Descriptor()); + } + public void add(Declaration declaration, boolean markAsModified) { DeclarationProperty property = createDeclarationProperty(declaration, markAsModified); declaration2PropertyMap.put(declaration, property); @@ -581,8 +603,8 @@ private PropertyValuesEditor createPropertyValueEditor(FileObject context, PropertyDefinition pmodel, boolean addNoneProperty) { final Collection unitElements = new ArrayList(); final Collection fixedElements = new ArrayList(); - - if(pmodel != null) { + + if (pmodel != null) { GroupGrammarElement rootElement = pmodel.getGrammarElement(context); rootElement.accept(new GrammarElementVisitor() { @@ -843,7 +865,7 @@ String oldValue = getValue(); this.declaration = declaration; String newValue = getValue(); - + locationPrefix = null; //reset the prefix as it was computed for the original declaration /* Reset DeclarationInfo to default state (null) as the contract @@ -1047,6 +1069,198 @@ }); } + private Property create_Add_Property_Feature_Descriptor() { + return ADD_PROPERTY_FD; + } + + private Property ADD_PROPERTY_FD = new AddPropertyFD(); + + private class AddPropertyFD extends Property { + + public AddPropertyFD() { + super(String.class); + setName(AddPropertyFD.class.getSimpleName()); +// setDisplayName("Add Property"); + } + + @Override + public PropertyEditor getPropertyEditor() { + return new AddPropertyPropertyEditor(this); + } + + @Override + public boolean canRead() { + return true; + } + + @Override + public String getValue() throws IllegalAccessException, InvocationTargetException { + return ""; + } + + @Override + public boolean canWrite() { + return true; + } + + //called from AddPropertyPropertyEditor when a value is entered + @Override + public void setValue(final String propertyName) { + System.out.println("AddProperty - setValue(" + propertyName + ")"); + if (propertyName == null) { + return; + } + + //1.create the property + //2.select the corresponding row in the PS + + final Model model = getModel(); + final Rule rule = getRule(); + model.runWriteTask(new Model.ModelTask() { + @Override + public void run(StyleSheet styleSheet) { + //add the new declaration to the model. + //the declaration is not complete - the value is missing and it is necessary to + //enter in the PS otherwise the model become invalid. + ModelUtils utils = new ModelUtils(model); + Declarations decls = rule.getDeclarations(); + if (decls == null) { + decls = model.getElementFactory().createDeclarations(); + rule.setDeclarations(decls); + } + + Declaration declaration = utils.createDeclaration(propertyName + ":"); + decls.addDeclaration(declaration); + + //do not save the model (apply changes) - once the write task finishes + //the embedded property sheet will be refreshed from the modified model. + + //remember the created declaration so once the model change is fired + //and the property sheet is refreshed, we can find and select the corresponding + //FeatureDescriptor + panel.createdDeclaration = declaration; + } + }); + } + } + + private class AddPropertyPropertyEditor extends PropertyEditorSupport implements ExPropertyEditor { + + private AddPropertyFD property; + + public AddPropertyPropertyEditor(AddPropertyFD property) { + this.property = property; + } + + @Override + public void attachEnv(PropertyEnv env) { + env.getFeatureDescriptor().setValue("custom.cell.renderer", + new AddPropertyCellRendererComponent()); //NOI18N + + env.getFeatureDescriptor().setValue("custom.cell.editor", + new AddPropertyCellEditorComponent(panel.createAddPropertyCB(), property)); //NOI18N + } + } + + private class AddPropertyCellRendererComponent implements TableCellRenderer { + + @Override + public Component getTableCellRendererComponent(JTable jtable, Object o, boolean bln, boolean bln1, int i, int i1) { + return new JLabel("Add Property"); + } + } + + private class AddPropertyCellEditorComponent extends DefaultCellEditor { + + private AutocompleteJComboBox editor; + private AddPropertyFD property; + private List listeners = new ArrayList(); + + public AddPropertyCellEditorComponent(AutocompleteJComboBox jcb, AddPropertyFD addFDProperty) { + super(jcb); + this.property = addFDProperty; + this.editor = jcb; + this.editor.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + property.setValue(editor.getSelectedPropertyName()); +// stopCellEditing(); + } + }); + + } + + + +// public AddPropertyCellEditorComponent(AddPropertyFD addFDProperty) { +// +// this.property = addFDProperty; +// this.editor = panel.createAddPropertyCB(); +// this.editor.addActionListener(new ActionListener() { +// @Override +// public void actionPerformed(ActionEvent ae) { +// property.setValue(editor.getSelectedPropertyName()); +// stopCellEditing(); +// } +// }); +// } +// + @Override + public Component getTableCellEditorComponent(JTable jtable, Object o, boolean bln, int i, int i1) { + return editor; + } +// +// @Override +// public Object getCellEditorValue() { +// return ""; +// } +// +// @Override +// public boolean isCellEditable(EventObject eo) { +// return true; +// } +// +// @Override +// public boolean shouldSelectCell(EventObject eo) { +// return false; +// } +// +// @Override +// public boolean stopCellEditing() { +// fireEditingStopped(); +// return true; +// } +// +// @Override +// public void cancelCellEditing() { +// fireEditingCancelled(); +// } +// +// @Override +// public void addCellEditorListener(CellEditorListener cl) { +// listeners.add(cl); +// } +// +// @Override +// public void removeCellEditorListener(CellEditorListener cl) { +// listeners.remove(cl); +// } +// +// private void fireEditingStopped() { +// List ls = new ArrayList(listeners); +// for (CellEditorListener l : ls) { +// l.editingStopped(new ChangeEvent(this)); +// } +// } +// +// private void fireEditingCancelled() { +// List ls = new ArrayList(listeners); +// for (CellEditorListener l : ls) { +// l.editingCanceled(new ChangeEvent(this)); +// } +// } + } + /** * Empty children keys */ diff -r 9d36fe77552e css.visual/src/org/netbeans/modules/css/visual/RuleEditorPanel.form --- a/css.visual/src/org/netbeans/modules/css/visual/RuleEditorPanel.form Wed Oct 31 14:54:22 2012 +0100 +++ b/css.visual/src/org/netbeans/modules/css/visual/RuleEditorPanel.form Wed Oct 31 17:29:16 2012 +0100 @@ -152,23 +152,6 @@ - - - - - - - - - - - - - - - - - diff -r 9d36fe77552e css.visual/src/org/netbeans/modules/css/visual/RuleEditorPanel.java --- a/css.visual/src/org/netbeans/modules/css/visual/RuleEditorPanel.java Wed Oct 31 14:54:22 2012 +0100 +++ b/css.visual/src/org/netbeans/modules/css/visual/RuleEditorPanel.java Wed Oct 31 17:29:16 2012 +0100 @@ -66,6 +66,7 @@ import javax.swing.DefaultListCellRenderer; import javax.swing.Icon; import javax.swing.ImageIcon; +import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; @@ -183,7 +184,7 @@ Declaration createdDeclaration; - private AddPropertyComboBoxModel ADD_PROPERTY_CB_MODEL = new AddPropertyComboBoxModel(); +// private AddPropertyComboBoxModel ADD_PROPERTY_CB_MODEL = new AddPropertyComboBoxModel(); private PropertyChangeListener MODEL_LISTENER = new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent evt) { @@ -237,14 +238,14 @@ } }; - private final ActionListener addPropertyCBActionListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - addPropertyCBValueEntered(); - } - }; - +// private final ActionListener addPropertyCBActionListener = new ActionListener() { +// +// @Override +// public void actionPerformed(ActionEvent e) { +// addPropertyCBValueEntered(); +// } +// }; +// public RuleEditorPanel() { this(false); } @@ -325,25 +326,25 @@ //init the add property combo box - addPropertyCB.getEditor().getEditorComponent().addFocusListener(new FocusListener() { - @Override - public void focusGained(FocusEvent e) { - ADD_PROPERTY_CB_MODEL.removeInitialText(); - - //add the ActionListener after the model change (removed initial text) - //as it fires an action event - addPropertyCB.addActionListener(addPropertyCBActionListener); - } - - @Override - public void focusLost(FocusEvent e) { - ADD_PROPERTY_CB_MODEL.addInitialText(); - - //add the ActionListener after the model change (added initial text) - //as it fires an action event - addPropertyCB.removeActionListener(addPropertyCBActionListener); - } - }); +// addPropertyCB.getEditor().getEditorComponent().addFocusListener(new FocusListener() { +// @Override +// public void focusGained(FocusEvent e) { +// ADD_PROPERTY_CB_MODEL.removeInitialText(); +// +// //add the ActionListener after the model change (removed initial text) +// //as it fires an action event +// addPropertyCB.addActionListener(addPropertyCBActionListener); +// } +// +// @Override +// public void focusLost(FocusEvent e) { +// ADD_PROPERTY_CB_MODEL.addInitialText(); +// +// //add the ActionListener after the model change (added initial text) +// //as it fires an action event +// addPropertyCB.removeActionListener(addPropertyCBActionListener); +// } +// }); if (!addPropertyMode) { @@ -352,7 +353,7 @@ } addPropertyButton.setVisible(!addPropertyMode); - addPropertyCB.setVisible(!addPropertyMode); +// addPropertyCB.setVisible(!addPropertyMode); titleLabel.setText(null); @@ -403,63 +404,69 @@ }); } + + AutocompleteJComboBox createAddPropertyCB() { + AutocompleteJComboBox ajcb = new AutocompleteJComboBox(new AddPropertyComboBoxModel(), new AddPropertyCBObjectToStringConverter()); + ajcb.setRenderer(new AddPropertyCBRendeder()); + return ajcb; + } - private void addPropertyCBValueEntered() { - Object selected = ADD_PROPERTY_CB_MODEL.getSelectedItem(); - if (selected == null) { - return; - } - - final String propertyName; - if (selected instanceof PropertyDefinition) { - PropertyDefinition pd = (PropertyDefinition) selected; - propertyName = pd.getName(); - } else if (selected instanceof String) { - String val = (String) selected; - if (!val.trim().isEmpty()) { - propertyName = val; - } else { - propertyName = null; - } - } else { - propertyName = null; - } - - if (propertyName != null) { - //1.verify whether there's such property - if(Properties.getPropertyDefinition(model.getLookup().lookup(FileObject.class), propertyName) != null) { - //2.create the property - //3.select the corresponding row in the PS - - model.runWriteTask(new Model.ModelTask() { - @Override - public void run(StyleSheet styleSheet) { - //add the new declaration to the model. - //the declaration is not complete - the value is missing and it is necessary to - //enter in the PS otherwise the model become invalid. - ModelUtils utils = new ModelUtils(model); - Declarations decls = rule.getDeclarations(); - if (decls == null) { - decls = model.getElementFactory().createDeclarations(); - rule.setDeclarations(decls); - } - - Declaration declaration = utils.createDeclaration(propertyName + ":"); - decls.addDeclaration(declaration); - - //do not save the model (apply changes) - once the write task finishes - //the embedded property sheet will be refreshed from the modified model. - - //remember the created declaration so once the model change is fired - //and the property sheet is refreshed, we can find and select the corresponding - //FeatureDescriptor - createdDeclaration = declaration; - } - }); - } - - } - } +// private void addPropertyCBValueEntered() { +// Object selected = ADD_PROPERTY_CB_MODEL.getSelectedItem(); +// if (selected == null) { +// return; +// } +// +// final String propertyName; +// if (selected instanceof PropertyDefinition) { +// PropertyDefinition pd = (PropertyDefinition) selected; +// propertyName = pd.getName(); +// } else if (selected instanceof String) { +// String val = (String) selected; +// if (!val.trim().isEmpty()) { +// propertyName = val; +// } else { +// propertyName = null; +// } +// } else { +// propertyName = null; +// } +// +// if (propertyName != null) { +// //1.verify whether there's such property +// if(Properties.getPropertyDefinition(model.getLookup().lookup(FileObject.class), propertyName) != null) { +// //2.create the property +// //3.select the corresponding row in the PS +// +// model.runWriteTask(new Model.ModelTask() { +// @Override +// public void run(StyleSheet styleSheet) { +// //add the new declaration to the model. +// //the declaration is not complete - the value is missing and it is necessary to +// //enter in the PS otherwise the model become invalid. +// ModelUtils utils = new ModelUtils(model); +// Declarations decls = rule.getDeclarations(); +// if (decls == null) { +// decls = model.getElementFactory().createDeclarations(); +// rule.setDeclarations(decls); +// } +// +// Declaration declaration = utils.createDeclaration(propertyName + ":"); +// decls.addDeclaration(declaration); +// +// //do not save the model (apply changes) - once the write task finishes +// //the embedded property sheet will be refreshed from the modified model. +// +// //remember the created declaration so once the model change is fired +// //and the property sheet is refreshed, we can find and select the corresponding +// //FeatureDescriptor +// createdDeclaration = declaration; +// } +// }); +// } +// +// } +// } public FeatureDescriptor getSelected() { return sheet.getSelectedFeatureDescriptor(); @@ -662,7 +669,7 @@ ? Collections.emptyList() : decls.getDeclarations(); - ADD_PROPERTY_CB_MODEL.setExistingProperties(declarations); +// ADD_PROPERTY_CB_MODEL.setExistingProperties(declarations); CHANGE_SUPPORT.firePropertyChange(RuleEditorController.PropertyNames.RULE_SET.name(), old, this.rule); @@ -670,11 +677,11 @@ if (!rule.isValid()) { northWestPanel.add(ERROR_LABEL); addPropertyButton.setEnabled(false); - addPropertyCB.setEnabled(false); +// addPropertyCB.setEnabled(false); } else { northWestPanel.remove(ERROR_LABEL); addPropertyButton.setEnabled(true); - addPropertyCB.setEnabled(true); +// addPropertyCB.setEnabled(true); } northWestPanel.revalidate(); @@ -708,7 +715,7 @@ titleLabel.setEnabled(false); addPropertyButton.setEnabled(false); - addPropertyCB.setEnabled(false); +// addPropertyCB.setEnabled(false); node.fireContextChanged(false); } @@ -757,7 +764,6 @@ titleLabel = new javax.swing.JLabel(); southPanel = new javax.swing.JPanel(); addPropertyButton = new javax.swing.JButton(); - addPropertyCB = new AutocompleteJComboBox(ADD_PROPERTY_CB_MODEL, new AddPropertyCBObjectToStringConverter()); menuLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/css/visual/resources/menu.png"))); // NOI18N menuLabel.setText(org.openide.util.NbBundle.getMessage(RuleEditorPanel.class, "RuleEditorPanel.menuLabel.text")); // NOI18N @@ -810,11 +816,6 @@ addPropertyButton.setMargin(new java.awt.Insets(0, 0, 0, 0)); southPanel.add(addPropertyButton, java.awt.BorderLayout.LINE_END); - addPropertyCB.setEditable(true); - addPropertyCB.setEnabled(false); - addPropertyCB.setRenderer(new AddPropertyCBRendeder()); - southPanel.add(addPropertyCB, java.awt.BorderLayout.CENTER); - add(southPanel, java.awt.BorderLayout.SOUTH); }// //GEN-END:initComponents @@ -829,7 +830,6 @@ // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addPropertyButton; - private javax.swing.JComboBox addPropertyCB; private javax.swing.JLabel cancelFilterLabel; private javax.swing.JTextField filterTextField; private javax.swing.JLabel menuLabel; @@ -844,54 +844,51 @@ private class AddPropertyComboBoxModel extends DefaultComboBoxModel { - private boolean containsInitialText; +// private boolean containsInitialText; public AddPropertyComboBoxModel() { - addInitialText(); - } - - private Collection getProperties() { - Collection properties = new TreeSet(PropertyUtils.PROPERTY_DEFINITIONS_COMPARATOR); - properties.addAll(Properties.getPropertyDefinitions(getModel().getLookup().lookup(FileObject.class))); - return properties; - } - - private void addInitialText() { - if (!containsInitialText) { - insertElementAt(INITIAL_TEXT_OBJECT, 0); - setSelectedItem(INITIAL_TEXT_OBJECT); - containsInitialText = true; +// addInitialText(); + for(PropertyDefinition prop : Properties.getPropertyDefinitions(getModel().getLookup().lookup(FileObject.class), true)) { + addElement(prop.getName()); } } - private void removeInitialText() { - if (containsInitialText) { - removeElement(INITIAL_TEXT_OBJECT); - setSelectedItem(null); - containsInitialText = false; - } - } +// private void addInitialText() { +// if (!containsInitialText) { +// insertElementAt(INITIAL_TEXT_OBJECT, 0); +// setSelectedItem(INITIAL_TEXT_OBJECT); +// containsInitialText = true; +// } +// } +// +// private void removeInitialText() { +// if (containsInitialText) { +// removeElement(INITIAL_TEXT_OBJECT); +// setSelectedItem(null); +// containsInitialText = false; +// } +// } private void setExistingProperties(Collection existing) { - removeInitialText(); - removeAllElements(); - - addInitialText(); - - FileObject file = model.getLookup().lookup(FileObject.class); - Collection existingDefs = new ArrayList(); - for(Declaration d : existing) { - PropertyDefinition definition = Properties.getPropertyDefinition(file, d.getProperty().getContent().toString()); - if(definition != null) { - existingDefs.add(definition); - } - } - - for(PropertyDefinition prop : getProperties()) { - if(!existingDefs.contains(prop)) { - addElement(prop); - } - } +// removeInitialText(); +// removeAllElements(); +// +// addInitialText(); +// +// FileObject file = model.getLookup().lookup(FileObject.class); +// Collection existingDefs = new ArrayList(); +// for(Declaration d : existing) { +// PropertyDefinition definition = Properties.getPropertyDefinition(file, d.getProperty().getContent().toString()); +// if(definition != null) { +// existingDefs.add(definition); +// } +// } +// +// for(PropertyDefinition prop : getProperties()) { +// if(!existingDefs.contains(prop)) { +// addElement(prop); +// } +// } } @@ -906,8 +903,9 @@ if (value == INITIAL_TEXT_OBJECT) { setText(ADD_PROPERTY_CB_TEXT); } else { - PropertyDefinition pd = (PropertyDefinition) value; - setText(pd.getName()); + setText(value.toString()); +// PropertyDefinition pd = (PropertyDefinition) value; +// setText(pd.getName()); } } return c; diff -r 9d36fe77552e openide.explorer/src/org/openide/explorer/propertysheet/CleanComboUI.java --- a/openide.explorer/src/org/openide/explorer/propertysheet/CleanComboUI.java Wed Oct 31 14:54:22 2012 +0100 +++ b/openide.explorer/src/org/openide/explorer/propertysheet/CleanComboUI.java Wed Oct 31 17:29:16 2012 +0100 @@ -371,9 +371,11 @@ @Override protected Rectangle computePopupBounds(int px, int py, int pw, int ph) { - if( comboBox instanceof ComboInplaceEditor ) { - ComboInplaceEditor inPlaceCombo = ( ComboInplaceEditor ) comboBox; - if( inPlaceCombo.isAutoComplete ) +// if( comboBox instanceof ComboInplaceEditor ) { + if( true ) { +// ComboInplaceEditor inPlaceCombo = ( ComboInplaceEditor ) comboBox; +// if( inPlaceCombo.isAutoComplete ) + if( true ) return super.computePopupBounds( px, py, pw, ph ); } Dimension d = list.getPreferredSize(); diff -r 9d36fe77552e openide.explorer/src/org/openide/explorer/propertysheet/ComboInplaceEditor.java --- a/openide.explorer/src/org/openide/explorer/propertysheet/ComboInplaceEditor.java Wed Oct 31 14:54:22 2012 +0100 +++ b/openide.explorer/src/org/openide/explorer/propertysheet/ComboInplaceEditor.java Wed Oct 31 17:29:16 2012 +0100 @@ -518,12 +518,12 @@ return (c == getEditor().getEditorComponent()); } - @Override - public void setValue(Object o) { - ignoreSelectionEvents = true; - setSelectedItem(o); - ignoreSelectionEvents = false; - } + @Override + public void setValue(Object o) { + ignoreSelectionEvents = true; + setSelectedItem(o); + ignoreSelectionEvents = false; + } /** Returns true if the combo box is editable */ @Override diff -r 9d36fe77552e openide.explorer/src/org/openide/explorer/propertysheet/SheetTable.java --- a/openide.explorer/src/org/openide/explorer/propertysheet/SheetTable.java Wed Oct 31 14:54:22 2012 +0100 +++ b/openide.explorer/src/org/openide/explorer/propertysheet/SheetTable.java Wed Oct 31 17:29:16 2012 +0100 @@ -81,8 +81,10 @@ import javax.swing.Action; import javax.swing.ActionMap; import javax.swing.BorderFactory; +import javax.swing.DefaultCellEditor; import javax.swing.DefaultListSelectionModel; import javax.swing.InputMap; +import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JFrame; @@ -280,6 +282,42 @@ return sheetCellEditor; } + private TableCellRenderer getCustomRenderer( int row ) { + FeatureDescriptor fd = getPropertySetModel().getFeatureDescriptor(row); + + if (fd instanceof PropertySet) + return null; + + Object res = fd.getValue( "custom.cell.renderer"); + if( res instanceof TableCellRenderer ) { + if( res instanceof DefaultCellEditor ) { + if( ((DefaultCellEditor)res).getComponent() instanceof JComboBox ) { + ((JComboBox)((DefaultCellEditor)res).getComponent()).setUI( new CleanComboUI( true ) ); + } + } + return ( TableCellRenderer ) res; + } + return null; + } + + private TableCellEditor getCustomEditor( int row ) { + FeatureDescriptor fd = getPropertySetModel().getFeatureDescriptor(row); + + if (fd instanceof PropertySet) + return null; + + Object res = fd.getValue( "custom.cell.editor"); + if( res instanceof TableCellEditor ) { + if( res instanceof DefaultCellEditor ) { + if( ((DefaultCellEditor)res).getComponent() instanceof JComboBox ) { + ((JComboBox)((DefaultCellEditor)res).getComponent()).setUI( new CleanComboUI( true ) ); + } + } + return ( TableCellEditor ) res; + } + return null; + } + /****************Bean getters/setters***************************************** /** Implement's Rochelle's suggestion of including the display name @@ -300,6 +338,12 @@ * of SheetTable */ @Override public TableCellEditor getCellEditor(int row, int column) { + if( 0 == column ) { + TableCellEditor res = getCustomEditor( row ); + if( null != res ) + return res; + } + return getEditor(); } @@ -307,6 +351,11 @@ * of SheetTable */ @Override public TableCellRenderer getCellRenderer(int row, int column) { + if( 0 == column ) { + TableCellRenderer res = getCustomRenderer( row ); + if( null != res ) + return res; + } return getRenderer(); } @@ -1157,7 +1206,7 @@ @Override public boolean isCellEditable(int row, int column) { if (column == 0) { - return false; + return null != getCustomEditor( row ); } FeatureDescriptor fd = getPropertySetModel().getFeatureDescriptor(row); @@ -1300,6 +1349,7 @@ return null; } + if( 1 == col ) { //Usually result == ine, but custom impls may not be InplaceEditor ine = getEditor().getInplaceEditor(); @@ -1307,6 +1357,7 @@ result.setBackground(PropUtils.getTextFieldBackground()); result.setForeground(PropUtils.getTextFieldForeground()); } + } if (result instanceof JComponent) { //unlikely that it won't be