Lines 66-71
Link Here
|
66 |
import javax.swing.DefaultListCellRenderer; |
66 |
import javax.swing.DefaultListCellRenderer; |
67 |
import javax.swing.Icon; |
67 |
import javax.swing.Icon; |
68 |
import javax.swing.ImageIcon; |
68 |
import javax.swing.ImageIcon; |
|
|
69 |
import javax.swing.JComboBox; |
69 |
import javax.swing.JLabel; |
70 |
import javax.swing.JLabel; |
70 |
import javax.swing.JList; |
71 |
import javax.swing.JList; |
71 |
import javax.swing.JPanel; |
72 |
import javax.swing.JPanel; |
Lines 183-189
Link Here
|
183 |
|
184 |
|
184 |
Declaration createdDeclaration; |
185 |
Declaration createdDeclaration; |
185 |
|
186 |
|
186 |
private AddPropertyComboBoxModel ADD_PROPERTY_CB_MODEL = new AddPropertyComboBoxModel(); |
187 |
// private AddPropertyComboBoxModel ADD_PROPERTY_CB_MODEL = new AddPropertyComboBoxModel(); |
187 |
private PropertyChangeListener MODEL_LISTENER = new PropertyChangeListener() { |
188 |
private PropertyChangeListener MODEL_LISTENER = new PropertyChangeListener() { |
188 |
@Override |
189 |
@Override |
189 |
public void propertyChange(final PropertyChangeEvent evt) { |
190 |
public void propertyChange(final PropertyChangeEvent evt) { |
Lines 237-250
Link Here
|
237 |
} |
238 |
} |
238 |
}; |
239 |
}; |
239 |
|
240 |
|
240 |
private final ActionListener addPropertyCBActionListener = new ActionListener() { |
241 |
// private final ActionListener addPropertyCBActionListener = new ActionListener() { |
241 |
|
242 |
// |
242 |
@Override |
243 |
// @Override |
243 |
public void actionPerformed(ActionEvent e) { |
244 |
// public void actionPerformed(ActionEvent e) { |
244 |
addPropertyCBValueEntered(); |
245 |
// addPropertyCBValueEntered(); |
245 |
} |
246 |
// } |
246 |
}; |
247 |
// }; |
247 |
|
248 |
// |
248 |
public RuleEditorPanel() { |
249 |
public RuleEditorPanel() { |
249 |
this(false); |
250 |
this(false); |
250 |
} |
251 |
} |
Lines 325-349
Link Here
|
325 |
|
326 |
|
326 |
//init the add property combo box |
327 |
//init the add property combo box |
327 |
|
328 |
|
328 |
addPropertyCB.getEditor().getEditorComponent().addFocusListener(new FocusListener() { |
329 |
// addPropertyCB.getEditor().getEditorComponent().addFocusListener(new FocusListener() { |
329 |
@Override |
330 |
// @Override |
330 |
public void focusGained(FocusEvent e) { |
331 |
// public void focusGained(FocusEvent e) { |
331 |
ADD_PROPERTY_CB_MODEL.removeInitialText(); |
332 |
// ADD_PROPERTY_CB_MODEL.removeInitialText(); |
332 |
|
333 |
// |
333 |
//add the ActionListener after the model change (removed initial text) |
334 |
// //add the ActionListener after the model change (removed initial text) |
334 |
//as it fires an action event |
335 |
// //as it fires an action event |
335 |
addPropertyCB.addActionListener(addPropertyCBActionListener); |
336 |
// addPropertyCB.addActionListener(addPropertyCBActionListener); |
336 |
} |
337 |
// } |
337 |
|
338 |
// |
338 |
@Override |
339 |
// @Override |
339 |
public void focusLost(FocusEvent e) { |
340 |
// public void focusLost(FocusEvent e) { |
340 |
ADD_PROPERTY_CB_MODEL.addInitialText(); |
341 |
// ADD_PROPERTY_CB_MODEL.addInitialText(); |
341 |
|
342 |
// |
342 |
//add the ActionListener after the model change (added initial text) |
343 |
// //add the ActionListener after the model change (added initial text) |
343 |
//as it fires an action event |
344 |
// //as it fires an action event |
344 |
addPropertyCB.removeActionListener(addPropertyCBActionListener); |
345 |
// addPropertyCB.removeActionListener(addPropertyCBActionListener); |
345 |
} |
346 |
// } |
346 |
}); |
347 |
// }); |
347 |
|
348 |
|
348 |
|
349 |
|
349 |
if (!addPropertyMode) { |
350 |
if (!addPropertyMode) { |
Lines 352-358
Link Here
|
352 |
} |
353 |
} |
353 |
|
354 |
|
354 |
addPropertyButton.setVisible(!addPropertyMode); |
355 |
addPropertyButton.setVisible(!addPropertyMode); |
355 |
addPropertyCB.setVisible(!addPropertyMode); |
356 |
// addPropertyCB.setVisible(!addPropertyMode); |
356 |
|
357 |
|
357 |
titleLabel.setText(null); |
358 |
titleLabel.setText(null); |
358 |
|
359 |
|
Lines 403-465
Link Here
|
403 |
}); |
404 |
}); |
404 |
|
405 |
|
405 |
} |
406 |
} |
|
|
407 |
|
408 |
AutocompleteJComboBox createAddPropertyCB() { |
409 |
AutocompleteJComboBox ajcb = new AutocompleteJComboBox(new AddPropertyComboBoxModel(), new AddPropertyCBObjectToStringConverter()); |
410 |
ajcb.setRenderer(new AddPropertyCBRendeder()); |
411 |
return ajcb; |
412 |
} |
406 |
|
413 |
|
407 |
private void addPropertyCBValueEntered() { |
414 |
// private void addPropertyCBValueEntered() { |
408 |
Object selected = ADD_PROPERTY_CB_MODEL.getSelectedItem(); |
415 |
// Object selected = ADD_PROPERTY_CB_MODEL.getSelectedItem(); |
409 |
if (selected == null) { |
416 |
// if (selected == null) { |
410 |
return; |
417 |
// return; |
411 |
} |
418 |
// } |
412 |
|
419 |
// |
413 |
final String propertyName; |
420 |
// final String propertyName; |
414 |
if (selected instanceof PropertyDefinition) { |
421 |
// if (selected instanceof PropertyDefinition) { |
415 |
PropertyDefinition pd = (PropertyDefinition) selected; |
422 |
// PropertyDefinition pd = (PropertyDefinition) selected; |
416 |
propertyName = pd.getName(); |
423 |
// propertyName = pd.getName(); |
417 |
} else if (selected instanceof String) { |
424 |
// } else if (selected instanceof String) { |
418 |
String val = (String) selected; |
425 |
// String val = (String) selected; |
419 |
if (!val.trim().isEmpty()) { |
426 |
// if (!val.trim().isEmpty()) { |
420 |
propertyName = val; |
427 |
// propertyName = val; |
421 |
} else { |
428 |
// } else { |
422 |
propertyName = null; |
429 |
// propertyName = null; |
423 |
} |
430 |
// } |
424 |
} else { |
431 |
// } else { |
425 |
propertyName = null; |
432 |
// propertyName = null; |
426 |
} |
433 |
// } |
427 |
|
434 |
// |
428 |
if (propertyName != null) { |
435 |
// if (propertyName != null) { |
429 |
//1.verify whether there's such property |
436 |
// //1.verify whether there's such property |
430 |
if(Properties.getPropertyDefinition(model.getLookup().lookup(FileObject.class), propertyName) != null) { |
437 |
// if(Properties.getPropertyDefinition(model.getLookup().lookup(FileObject.class), propertyName) != null) { |
431 |
//2.create the property |
438 |
// //2.create the property |
432 |
//3.select the corresponding row in the PS |
439 |
// //3.select the corresponding row in the PS |
433 |
|
440 |
// |
434 |
model.runWriteTask(new Model.ModelTask() { |
441 |
// model.runWriteTask(new Model.ModelTask() { |
435 |
@Override |
442 |
// @Override |
436 |
public void run(StyleSheet styleSheet) { |
443 |
// public void run(StyleSheet styleSheet) { |
437 |
//add the new declaration to the model. |
444 |
// //add the new declaration to the model. |
438 |
//the declaration is not complete - the value is missing and it is necessary to |
445 |
// //the declaration is not complete - the value is missing and it is necessary to |
439 |
//enter in the PS otherwise the model become invalid. |
446 |
// //enter in the PS otherwise the model become invalid. |
440 |
ModelUtils utils = new ModelUtils(model); |
447 |
// ModelUtils utils = new ModelUtils(model); |
441 |
Declarations decls = rule.getDeclarations(); |
448 |
// Declarations decls = rule.getDeclarations(); |
442 |
if (decls == null) { |
449 |
// if (decls == null) { |
443 |
decls = model.getElementFactory().createDeclarations(); |
450 |
// decls = model.getElementFactory().createDeclarations(); |
444 |
rule.setDeclarations(decls); |
451 |
// rule.setDeclarations(decls); |
445 |
} |
452 |
// } |
446 |
|
453 |
// |
447 |
Declaration declaration = utils.createDeclaration(propertyName + ":"); |
454 |
// Declaration declaration = utils.createDeclaration(propertyName + ":"); |
448 |
decls.addDeclaration(declaration); |
455 |
// decls.addDeclaration(declaration); |
449 |
|
456 |
// |
450 |
//do not save the model (apply changes) - once the write task finishes |
457 |
// //do not save the model (apply changes) - once the write task finishes |
451 |
//the embedded property sheet will be refreshed from the modified model. |
458 |
// //the embedded property sheet will be refreshed from the modified model. |
452 |
|
459 |
// |
453 |
//remember the created declaration so once the model change is fired |
460 |
// //remember the created declaration so once the model change is fired |
454 |
//and the property sheet is refreshed, we can find and select the corresponding |
461 |
// //and the property sheet is refreshed, we can find and select the corresponding |
455 |
//FeatureDescriptor |
462 |
// //FeatureDescriptor |
456 |
createdDeclaration = declaration; |
463 |
// createdDeclaration = declaration; |
457 |
} |
464 |
// } |
458 |
}); |
465 |
// }); |
459 |
} |
466 |
// } |
460 |
|
467 |
// |
461 |
} |
468 |
// } |
462 |
} |
469 |
// } |
463 |
|
470 |
|
464 |
public FeatureDescriptor getSelected() { |
471 |
public FeatureDescriptor getSelected() { |
465 |
return sheet.getSelectedFeatureDescriptor(); |
472 |
return sheet.getSelectedFeatureDescriptor(); |
Lines 662-668
Link Here
|
662 |
? Collections.<Declaration>emptyList() |
669 |
? Collections.<Declaration>emptyList() |
663 |
: decls.getDeclarations(); |
670 |
: decls.getDeclarations(); |
664 |
|
671 |
|
665 |
ADD_PROPERTY_CB_MODEL.setExistingProperties(declarations); |
672 |
// ADD_PROPERTY_CB_MODEL.setExistingProperties(declarations); |
666 |
|
673 |
|
667 |
CHANGE_SUPPORT.firePropertyChange(RuleEditorController.PropertyNames.RULE_SET.name(), old, this.rule); |
674 |
CHANGE_SUPPORT.firePropertyChange(RuleEditorController.PropertyNames.RULE_SET.name(), old, this.rule); |
668 |
|
675 |
|
Lines 670-680
Link Here
|
670 |
if (!rule.isValid()) { |
677 |
if (!rule.isValid()) { |
671 |
northWestPanel.add(ERROR_LABEL); |
678 |
northWestPanel.add(ERROR_LABEL); |
672 |
addPropertyButton.setEnabled(false); |
679 |
addPropertyButton.setEnabled(false); |
673 |
addPropertyCB.setEnabled(false); |
680 |
// addPropertyCB.setEnabled(false); |
674 |
} else { |
681 |
} else { |
675 |
northWestPanel.remove(ERROR_LABEL); |
682 |
northWestPanel.remove(ERROR_LABEL); |
676 |
addPropertyButton.setEnabled(true); |
683 |
addPropertyButton.setEnabled(true); |
677 |
addPropertyCB.setEnabled(true); |
684 |
// addPropertyCB.setEnabled(true); |
678 |
} |
685 |
} |
679 |
northWestPanel.revalidate(); |
686 |
northWestPanel.revalidate(); |
680 |
|
687 |
|
Lines 708-714
Link Here
|
708 |
titleLabel.setEnabled(false); |
715 |
titleLabel.setEnabled(false); |
709 |
|
716 |
|
710 |
addPropertyButton.setEnabled(false); |
717 |
addPropertyButton.setEnabled(false); |
711 |
addPropertyCB.setEnabled(false); |
718 |
// addPropertyCB.setEnabled(false); |
712 |
node.fireContextChanged(false); |
719 |
node.fireContextChanged(false); |
713 |
} |
720 |
} |
714 |
|
721 |
|
Lines 757-763
Link Here
|
757 |
titleLabel = new javax.swing.JLabel(); |
764 |
titleLabel = new javax.swing.JLabel(); |
758 |
southPanel = new javax.swing.JPanel(); |
765 |
southPanel = new javax.swing.JPanel(); |
759 |
addPropertyButton = new javax.swing.JButton(); |
766 |
addPropertyButton = new javax.swing.JButton(); |
760 |
addPropertyCB = new AutocompleteJComboBox(ADD_PROPERTY_CB_MODEL, new AddPropertyCBObjectToStringConverter()); |
|
|
761 |
|
767 |
|
762 |
menuLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/css/visual/resources/menu.png"))); // NOI18N |
768 |
menuLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/css/visual/resources/menu.png"))); // NOI18N |
763 |
menuLabel.setText(org.openide.util.NbBundle.getMessage(RuleEditorPanel.class, "RuleEditorPanel.menuLabel.text")); // NOI18N |
769 |
menuLabel.setText(org.openide.util.NbBundle.getMessage(RuleEditorPanel.class, "RuleEditorPanel.menuLabel.text")); // NOI18N |
Lines 810-820
Link Here
|
810 |
addPropertyButton.setMargin(new java.awt.Insets(0, 0, 0, 0)); |
816 |
addPropertyButton.setMargin(new java.awt.Insets(0, 0, 0, 0)); |
811 |
southPanel.add(addPropertyButton, java.awt.BorderLayout.LINE_END); |
817 |
southPanel.add(addPropertyButton, java.awt.BorderLayout.LINE_END); |
812 |
|
818 |
|
813 |
addPropertyCB.setEditable(true); |
|
|
814 |
addPropertyCB.setEnabled(false); |
815 |
addPropertyCB.setRenderer(new AddPropertyCBRendeder()); |
816 |
southPanel.add(addPropertyCB, java.awt.BorderLayout.CENTER); |
817 |
|
818 |
add(southPanel, java.awt.BorderLayout.SOUTH); |
819 |
add(southPanel, java.awt.BorderLayout.SOUTH); |
819 |
}// </editor-fold>//GEN-END:initComponents |
820 |
}// </editor-fold>//GEN-END:initComponents |
820 |
|
821 |
|
Lines 829-835
Link Here
|
829 |
|
830 |
|
830 |
// Variables declaration - do not modify//GEN-BEGIN:variables |
831 |
// Variables declaration - do not modify//GEN-BEGIN:variables |
831 |
private javax.swing.JButton addPropertyButton; |
832 |
private javax.swing.JButton addPropertyButton; |
832 |
private javax.swing.JComboBox addPropertyCB; |
|
|
833 |
private javax.swing.JLabel cancelFilterLabel; |
833 |
private javax.swing.JLabel cancelFilterLabel; |
834 |
private javax.swing.JTextField filterTextField; |
834 |
private javax.swing.JTextField filterTextField; |
835 |
private javax.swing.JLabel menuLabel; |
835 |
private javax.swing.JLabel menuLabel; |
Lines 844-897
Link Here
|
844 |
|
844 |
|
845 |
private class AddPropertyComboBoxModel extends DefaultComboBoxModel { |
845 |
private class AddPropertyComboBoxModel extends DefaultComboBoxModel { |
846 |
|
846 |
|
847 |
private boolean containsInitialText; |
847 |
// private boolean containsInitialText; |
848 |
|
848 |
|
849 |
public AddPropertyComboBoxModel() { |
849 |
public AddPropertyComboBoxModel() { |
850 |
addInitialText(); |
850 |
// addInitialText(); |
851 |
} |
851 |
for(PropertyDefinition prop : Properties.getPropertyDefinitions(getModel().getLookup().lookup(FileObject.class), true)) { |
852 |
|
852 |
addElement(prop.getName()); |
853 |
private Collection<PropertyDefinition> getProperties() { |
|
|
854 |
Collection<PropertyDefinition> properties = new TreeSet<PropertyDefinition>(PropertyUtils.PROPERTY_DEFINITIONS_COMPARATOR); |
855 |
properties.addAll(Properties.getPropertyDefinitions(getModel().getLookup().lookup(FileObject.class))); |
856 |
return properties; |
857 |
} |
858 |
|
859 |
private void addInitialText() { |
860 |
if (!containsInitialText) { |
861 |
insertElementAt(INITIAL_TEXT_OBJECT, 0); |
862 |
setSelectedItem(INITIAL_TEXT_OBJECT); |
863 |
containsInitialText = true; |
864 |
} |
853 |
} |
865 |
} |
854 |
} |
866 |
|
855 |
|
867 |
private void removeInitialText() { |
856 |
// private void addInitialText() { |
868 |
if (containsInitialText) { |
857 |
// if (!containsInitialText) { |
869 |
removeElement(INITIAL_TEXT_OBJECT); |
858 |
// insertElementAt(INITIAL_TEXT_OBJECT, 0); |
870 |
setSelectedItem(null); |
859 |
// setSelectedItem(INITIAL_TEXT_OBJECT); |
871 |
containsInitialText = false; |
860 |
// containsInitialText = true; |
872 |
} |
861 |
// } |
873 |
} |
862 |
// } |
|
|
863 |
// |
864 |
// private void removeInitialText() { |
865 |
// if (containsInitialText) { |
866 |
// removeElement(INITIAL_TEXT_OBJECT); |
867 |
// setSelectedItem(null); |
868 |
// containsInitialText = false; |
869 |
// } |
870 |
// } |
874 |
|
871 |
|
875 |
private void setExistingProperties(Collection<Declaration> existing) { |
872 |
private void setExistingProperties(Collection<Declaration> existing) { |
876 |
removeInitialText(); |
873 |
// removeInitialText(); |
877 |
removeAllElements(); |
874 |
// removeAllElements(); |
878 |
|
875 |
// |
879 |
addInitialText(); |
876 |
// addInitialText(); |
880 |
|
877 |
// |
881 |
FileObject file = model.getLookup().lookup(FileObject.class); |
878 |
// FileObject file = model.getLookup().lookup(FileObject.class); |
882 |
Collection<PropertyDefinition> existingDefs = new ArrayList<PropertyDefinition>(); |
879 |
// Collection<PropertyDefinition> existingDefs = new ArrayList<PropertyDefinition>(); |
883 |
for(Declaration d : existing) { |
880 |
// for(Declaration d : existing) { |
884 |
PropertyDefinition definition = Properties.getPropertyDefinition(file, d.getProperty().getContent().toString()); |
881 |
// PropertyDefinition definition = Properties.getPropertyDefinition(file, d.getProperty().getContent().toString()); |
885 |
if(definition != null) { |
882 |
// if(definition != null) { |
886 |
existingDefs.add(definition); |
883 |
// existingDefs.add(definition); |
887 |
} |
884 |
// } |
888 |
} |
885 |
// } |
889 |
|
886 |
// |
890 |
for(PropertyDefinition prop : getProperties()) { |
887 |
// for(PropertyDefinition prop : getProperties()) { |
891 |
if(!existingDefs.contains(prop)) { |
888 |
// if(!existingDefs.contains(prop)) { |
892 |
addElement(prop); |
889 |
// addElement(prop); |
893 |
} |
890 |
// } |
894 |
} |
891 |
// } |
895 |
} |
892 |
} |
896 |
|
893 |
|
897 |
|
894 |
|
Lines 906-913
Link Here
|
906 |
if (value == INITIAL_TEXT_OBJECT) { |
903 |
if (value == INITIAL_TEXT_OBJECT) { |
907 |
setText(ADD_PROPERTY_CB_TEXT); |
904 |
setText(ADD_PROPERTY_CB_TEXT); |
908 |
} else { |
905 |
} else { |
909 |
PropertyDefinition pd = (PropertyDefinition) value; |
906 |
setText(value.toString()); |
910 |
setText(pd.getName()); |
907 |
// PropertyDefinition pd = (PropertyDefinition) value; |
|
|
908 |
// setText(pd.getName()); |
911 |
} |
909 |
} |
912 |
} |
910 |
} |
913 |
return c; |
911 |
return c; |