/** Internal implementation of getSelection() which returns the selected feature * descriptor whether or not the component has focus. */ public final FeatureDescriptor _getSelection() { int i = getSelectedRow(); FeatureDescriptor result; //Check bounds - a change can be fired after the model has been changed, but //before the table has received the event and updated itself, in which case //you get an AIOOBE if (i < getPropertySetModel().getCount()) { result = getSheetModel().getPropertySetModel().getFeatureDescriptor(getSelectedRow()); } else { result = null; } return result; }
/** * Select (and start editing) the given property. * @param fd * @param startEditing */ public void select( FeatureDescriptor fd, boolean startEditing ) { PropertySetModel psm = getPropertySetModel(); final int index = psm.indexOf( fd ); if( index < 0 ) { return; //not in our list } getSelectionModel().setSelectionInterval( index, index ); if( startEditing && psm.isProperty( index ) ) { editCellAt( index, 1, new MouseEvent( SheetTable.this, 0, System.currentTimeMillis(), 0, 0, 0, 1, false) ); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { SheetCellEditor cellEditor = getEditor(); if( null != cellEditor ) { InplaceEditor inplace = cellEditor.getInplaceEditor(); if( null != inplace && null != inplace.getComponent() ) { inplace.getComponent().requestFocus(); } } } }); } }
@Override public void actionPerformed(ActionEvent ae) { int i = getSelectedRow(); if (i != -1) { FeatureDescriptor fd = getPropertySetModel().getFeatureDescriptor(i); if (fd instanceof Property) { java.beans.PropertyEditor ped = PropUtils.getPropertyEditor((Property) fd); System.err.println(ped.getClass().getName()); } else { System.err.println("PropertySets - no editor"); //NOI18N } } else { System.err.println("No selection"); //NOI18N } }
@Override protected Transferable createTransferable(JComponent c) { if (c instanceof SheetTable) { SheetTable table = (SheetTable) c; FeatureDescriptor fd = table.getSelection(); if (fd == null) { return null; } String res = fd.getDisplayName(); if (fd instanceof Node.Property) { Node.Property prop = (Node.Property) fd; res += ("\t" + PropUtils.getPropertyEditor(prop).getAsText()); } return new SheetTableTransferable(res); } return null; }
/** * Expand or collapse the PropertySet the given property belongs to. * @param fd * @since 6.47 */ protected final void toggleExpanded( FeatureDescriptor fd ) { int index = table.getPropertySetModel().indexOf( fd ); if( index >= 0 ) { table.getPropertySetModel().toggleExpanded( index ); } }
/** Creates a new instance of ModelProperty */ private ModelProperty(PropertyModel pm) { super(pm.getPropertyType()); this.mdl = pm; if (mdl instanceof ExPropertyModel) { FeatureDescriptor fd = ((ExPropertyModel) mdl).getFeatureDescriptor(); Boolean result = (Boolean) fd.getValue("canEditAsText"); // NOI18N if (result != null) { this.setValue("canEditAsText", result); } } //System.err.println( //"Created ModelProperty wrapper for mystery PropertyModel " + pm); }
/** * Feature descritor that describes the property. It is feature * descriptor so one can plug in PropertyDescritor and also Node.Property * which both inherit from FeatureDescriptor */ void setFeatureDescriptor(FeatureDescriptor desc) { if (desc == null) { throw new IllegalArgumentException("Cannot set FeatureDescriptor to null."); //NOI18N } this.featureDescriptor = desc; if (featureDescriptor != null) { Object obj = featureDescriptor.getValue(PROP_CHANGE_IMMEDIATE); if (obj instanceof Boolean) { setChangeImmediate(((Boolean) obj).booleanValue()); } } }
void readEnv (FeatureDescriptor desc) { if (desc instanceof Node.Property){ Node.Property prop = (Node.Property)desc; editable = prop.canWrite(); //enh 29294 - support one-line editor & suppression of custom //editor instructions = (String) prop.getValue ("instructions"); //NOI18N oneline = Boolean.TRUE.equals (prop.getValue ("oneline")); //NOI18N customEd = !Boolean.TRUE.equals (prop.getValue ("suppressCustomEditor")); //NOI18N } Object obj = desc.getValue(ObjectEditor.PROP_NULL); if (Boolean.TRUE.equals(obj)) { nullValue = NbBundle.getMessage(StringEditor.class, "CTL_NullValue"); } else { if (obj instanceof String) { nullValue = (String)obj; } else { nullValue = null; } } }
@Override public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) { if (base == null) { return null; } try { BeanInfo info = Introspector.getBeanInfo(base.getClass()); PropertyDescriptor[] pds = info.getPropertyDescriptors(); for (int i = 0; i < pds.length; i++) { pds[i].setValue(RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE); pds[i].setValue(TYPE, pds[i].getPropertyType()); } return Arrays.asList((FeatureDescriptor[]) pds).iterator(); } catch (IntrospectionException e) { // } return null; }
/** * Tests that a valid FeatureDescriptors are returned. */ @Test public void testGetFeatureDescriptors02() { BeanELResolver resolver = new BeanELResolver(); ELContext context = new ELContextImpl(); Iterator<FeatureDescriptor> result = resolver.getFeatureDescriptors(context, new Bean()); while (result.hasNext()) { PropertyDescriptor featureDescriptor = (PropertyDescriptor) result.next(); Assert.assertEquals(featureDescriptor.getPropertyType(), featureDescriptor.getValue(ELResolver.TYPE)); Assert.assertEquals(Boolean.TRUE, featureDescriptor.getValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME)); } }
/** * Tests that a valid FeatureDescriptors are returned. */ @Test public void testGetFeatureDescriptors02() { MapELResolver mapELResolver = new MapELResolver(); ELContext context = new ELContextImpl(); Map<String, String> map = new HashMap<String, String>(); map.put("key", "value"); Iterator<FeatureDescriptor> result = mapELResolver .getFeatureDescriptors(context, map); while (result.hasNext()) { FeatureDescriptor featureDescriptor = result.next(); Assert.assertEquals("key", featureDescriptor.getDisplayName()); Assert.assertEquals("key", featureDescriptor.getName()); Assert.assertEquals("", featureDescriptor.getShortDescription()); Assert.assertFalse(featureDescriptor.isExpert()); Assert.assertFalse(featureDescriptor.isHidden()); Assert.assertTrue(featureDescriptor.isPreferred()); Assert.assertEquals("key".getClass(), featureDescriptor.getValue(ELResolver.TYPE)); Assert.assertEquals(Boolean.TRUE, featureDescriptor .getValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME)); } }
/** * Tests that a valid FeatureDescriptors are returned. */ @Test public void testGetFeatureDescriptors02() { ResourceBundleELResolver resolver = new ResourceBundleELResolver(); ELContext context = new ELContextImpl(); ResourceBundle resourceBundle = new TesterResourceBundle( new Object[][] { { "key", "value" } }); @SuppressWarnings("unchecked") Iterator<FeatureDescriptor> result = resolver.getFeatureDescriptors( context, resourceBundle); while (result.hasNext()) { FeatureDescriptor featureDescriptor = result.next(); Assert.assertEquals("key", featureDescriptor.getDisplayName()); Assert.assertEquals("key", featureDescriptor.getName()); Assert.assertEquals("", featureDescriptor.getShortDescription()); Assert.assertFalse(featureDescriptor.isExpert()); Assert.assertFalse(featureDescriptor.isHidden()); Assert.assertTrue(featureDescriptor.isPreferred()); Assert.assertEquals(String.class, featureDescriptor.getValue(ELResolver.TYPE)); Assert.assertEquals(Boolean.TRUE, featureDescriptor .getValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME)); } }
/** * Add all of the attributes of one FeatureDescriptor to thos * of another, replacing any attributes that conflict. */ static void __addFeatureValues( FeatureDescriptor addingDescriptor, FeatureDescriptor destinationDescriptor ) { Enumeration<String> keys = addingDescriptor.attributeNames(); if (keys != null) { while (keys.hasMoreElements()) { String key = keys.nextElement(); Object value = addingDescriptor.getValue(key); destinationDescriptor.setValue(key, value); } } }
@Override public void attachEnv(PropertyEnv env) { FeatureDescriptor desc = env.getFeatureDescriptor(); if (desc instanceof Node.Property){ Node.Property prop = (Node.Property)desc; editable = prop.canWrite(); if (textComp != null) textComp.setEditable(editable); } }
@Override public void attachEnv(PropertyEnv env) { //System.out.println("ValuePropertyEditor.attachEnv("+env+"), feature descriptor = "+env.getFeatureDescriptor()); env.setState(PropertyEnv.STATE_NEEDS_VALIDATION); env.addVetoableChangeListener(validate); if (delegatePropertyEditor instanceof ExPropertyEditor) { //System.out.println(" attaches to "+delegatePropertyEditor); if (delegateValue instanceof String) { ShortenedStrings.StringInfo shortenedInfo = ShortenedStrings.getShortenedInfo((String) delegateValue); if (shortenedInfo != null) { // The value is too large, do not allow editing! FeatureDescriptor desc = env.getFeatureDescriptor(); if (desc instanceof Node.Property){ Node.Property prop = (Node.Property)desc; // Need to make it uneditable try { Method forceNotEditableMethod = prop.getClass().getDeclaredMethod("forceNotEditable"); forceNotEditableMethod.setAccessible(true); forceNotEditableMethod.invoke(prop); } catch (Exception ex){} //editable = prop.canWrite(); } } } ((ExPropertyEditor) delegatePropertyEditor).attachEnv(env); this.env = env; } }
private void call_PropertySheet_select(PropertySheet sheet, FeatureDescriptor descriptor, boolean edit) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { //private so far, will be public later Class clz = PropertySheet.class; Method select_method = clz.getDeclaredMethod("select", FeatureDescriptor.class, boolean.class); //NOI18N select_method.setAccessible(true); select_method.invoke(sheet, descriptor, edit); }
@Override protected JPopupMenu createPopupMenu() { FeatureDescriptor fd = getSelection(); if (fd != null) { if (fd instanceof RuleEditorNode.DeclarationProperty) { //property // //actions: //remove //hide //???? //custom popop for the whole panel JPopupMenu pm = new JPopupMenu(); if(!addPropertyMode) { pm.add(new GoToSourceAction(RuleEditorPanel.this, (RuleEditorNode.DeclarationProperty) fd)); pm.addSeparator(); pm.add(new RemovePropertyAction(RuleEditorPanel.this, (RuleEditorNode.DeclarationProperty) fd)); } return pm; } else if (fd instanceof RuleEditorNode.PropertyCategoryPropertySet) { //property category //TODO possibly add "add property" action which would //preselect the css category in the "add property dialog". } } //no context popup - create the generic popup return genericPopupMenu; }
private TableCellRenderer getCustomRenderer( int row ) { FeatureDescriptor fd = getPropertySetModel().getFeatureDescriptor(row); if (fd instanceof PropertySet) return null; Object res = fd.getValue( "custom.cell.renderer"); //NOI18N if( res instanceof TableCellRenderer ) { prepareCustomEditor( res ); 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"); //NOI18N if( res instanceof TableCellEditor ) { prepareCustomEditor( res ); return ( TableCellEditor ) res; } return null; }
/** Overridden to cast value to FeatureDescriptor and return true if the * text matches its display name. The popup search field uses this method * to check matches. */ @Override protected boolean matchText(Object value, String text) { if (value instanceof FeatureDescriptor) { return ((FeatureDescriptor) value).getDisplayName().toUpperCase().startsWith(text.toUpperCase()); } else { return false; } }
/** We only use a single listener on the selected node, PropertySheet.SheetPCListener, * to centralize things. It will call this method if a property change is detected * so that it can be repainted. */ void repaintProperty(String name) { if (!isShowing()) { return; } if (PropUtils.isLoggable(SheetTable.class)) { PropUtils.log(SheetTable.class, "RepaintProperty: " + name); } PropertySetModel psm = getPropertySetModel(); int min = getFirstVisibleRow(); if (min == -1) { return; } int max = min + getVisibleRowCount(); for (int i = min; i < max; i++) { FeatureDescriptor fd = psm.getFeatureDescriptor(i); if (null != fd && fd.getName().equals(name)) { //repaint property value & name paintRow( i ); return; } } if (PropUtils.isLoggable(SheetTable.class)) { PropUtils.log(SheetTable.class, "Property is either scrolled offscreen or property name is bogus: " + name); } }
/**Overridden to do the assorted black magic by which one determines if * a property is editable */ @Override public boolean isCellEditable(int row, int column) { if (column == 0) { return null != getCustomEditor( row ); } FeatureDescriptor fd = getPropertySetModel().getFeatureDescriptor(row); boolean result; if (fd instanceof PropertySet) { result = false; } else { Property p = (Property) fd; result = p.canWrite(); if (result) { Object val = p.getValue("canEditAsText"); //NOI18N if (val != null) { result &= Boolean.TRUE.equals(val); if( !result ) { //#227661 - combo box editor should be allowed to show its popup PropertyEditor ped = PropUtils.getPropertyEditor(p); result |= ped.getTags() != null; } } } } return result; }
@Override public void actionPerformed(ActionEvent ae) { FeatureDescriptor fd = _getSelection(); if (fd instanceof PropertySet) { int row = SheetTable.this.getSelectedRow(); boolean b = getPropertySetModel().isExpanded(fd); if (b) { toggleExpanded(row); } } }
@Override public void actionPerformed(ActionEvent ae) { FeatureDescriptor fd = _getSelection(); if (fd instanceof PropertySet) { int row = SheetTable.this.getSelectedRow(); boolean b = getPropertySetModel().isExpanded(fd); if (!b) { toggleExpanded(row); } } }
public void valueChanged(PropertyEditor editor) { failed = false; try { // System.err.println("ValueChanged - new value " + editor.getValue()); if (getInplaceEditor() != null) { setEnteredValue(getProperty().getValue()); } else { //Handle case where our parent PropertyPanel is no longer showing, but //the custom editor we invoked still is. Issue 38004 PropertyModel mdl = (modelRef != null) ? modelRef.get() : null; if (mdl != null) { FeatureDescriptor fd = null; if (mdl instanceof ExPropertyModel) { fd = ((ExPropertyModel) mdl).getFeatureDescriptor(); } String title = null; if (fd != null) { title = fd.getDisplayName(); } failed = PropUtils.updateProp(mdl, editor, title); //XXX } } } catch (Exception e) { throw (IllegalStateException) new IllegalStateException("Problem setting entered value from custom editor").initCause(e); } }
/** Basically some hacks to acquire the underlying property descriptor in * the case of a wrapper. This is here because some property editors will * cast the result of PropertyEnv.getFeatureDescriptor() as a specific * implementation type, so even if we're wrapping a property model, we * still need to make sure we're returning the class they expect. */ static final FeatureDescriptor findFeatureDescriptor(PropertyDisplayer pd) { if (pd instanceof EditorPropertyDisplayer) { //Issue 38004, more gunk to ensure we get the right feature //descriptor EditorPropertyDisplayer epd = (EditorPropertyDisplayer) pd; if (epd.modelRef != null) { PropertyModel pm = epd.modelRef.get(); if (pm instanceof ExPropertyModel) { FeatureDescriptor fd = ((ExPropertyModel) pm).getFeatureDescriptor(); if (fd != null) { return fd; } } } } Property p = pd.getProperty(); if (p instanceof ModelProperty) { return ((ModelProperty) p).getFeatureDescriptor(); } else if (p instanceof ModelProperty.DPMWrapper) { return ((ModelProperty.DPMWrapper) p).getFeatureDescriptor(); } else { return p; } }
/** Used by EditablePropertyDisplayer to provide access to the real * feature descriptor. Some property editors will cast the result of * env.getFeatureDescriptor() as Property or PropertyDescriptor, so we * need to return the original */ FeatureDescriptor getFeatureDescriptor() { if (mdl instanceof ExPropertyModel) { return ((ExPropertyModel) mdl).getFeatureDescriptor(); } else { return this; } }
public String getAccessibleName() { String name = super.getAccessibleName(); if ((name == null) && model instanceof ExPropertyModel) { FeatureDescriptor fd = ((ExPropertyModel) model).getFeatureDescriptor(); name = NbBundle.getMessage(PropertyPanel.class, "ACS_PropertyPanel", fd.getDisplayName()); //NOI18N } return name; }
public String getAccessibleDescription() { String description = super.getAccessibleDescription(); if ((description == null) && model instanceof ExPropertyModel) { FeatureDescriptor fd = ((ExPropertyModel) model).getFeatureDescriptor(); description = NbBundle.getMessage(PropertyPanel.class, "ACSD_PropertyPanel", fd.getShortDescription()); //NOI18N } return description; }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()); sb.append("@"); //NOI18N sb.append(System.identityHashCode(this)); sb.append("[state="); //NOI18N sb.append( (state == STATE_NEEDS_VALIDATION) ? "STATE_NEEDS_VALIDATION" : ((state == STATE_INVALID) ? "STATE_INVALID" : "STATE_VALID") ); //NOI18N sb.append(", "); //NOI18N Factory f = factory; if (f != null) { sb.append("InplaceEditorFactory=").append(f.getClass().getName()); //NOI18N sb.append(", "); //NOI18N } sb.append("editable="); //NOI18N sb.append(editable); sb.append(", isChangeImmediate="); //NOI18N sb.append(isChangeImmediate()); sb.append(", featureDescriptor="); //NOI18N final FeatureDescriptor fd = getFeatureDescriptor(); if (fd != null) { sb.append(fd.getDisplayName()); } else { sb.append("null"); // NOI18N } return sb.toString(); }
public void testCurrentNodes () throws Exception { tc.setActivatedNodes(new Node[] {Node.EMPTY}); assertEquals ("This fires change", 1, cnt); assertEquals ("One item in result", 1, result.allItems ().size ()); Lookup.Item item = (Lookup.Item)result.allItems ().iterator ().next (); assertEquals ("Item should return Node.EMPTY", Node.EMPTY, item.getInstance()); assertActionMap (); tc.setActivatedNodes (null); assertEquals ("One change", 2, cnt); assertEquals ("One empty item in result", 1, result.allItems ().size ()); item = (Lookup.Item)result.allItems ().iterator ().next (); assertEquals ("Item should return null", null, item.getInstance()); assertEquals ("Name is null", "none", item.getId ()); assertActionMap (); Result<MyNode> subclass = lookup.lookup (new Lookup.Template<MyNode> (MyNode.class)); assertTrue("No items are returned", subclass.allItems().isEmpty()); Result<FeatureDescriptor> superclass = lookup.lookup (new Lookup.Template<FeatureDescriptor>(FeatureDescriptor.class)); assertEquals("One item is returned", 1, superclass.allItems().size()); item = (Lookup.Item)superclass.allItems ().iterator ().next (); assertEquals ("Item should return null", null, item.getInstance()); tc.setActivatedNodes (new Node[0]); assertEquals ("No change", 3, cnt); assertEquals ("No items in lookup", 0, result.allItems ().size ()); assertActionMap (); }
@Override public void attachEnv(PropertyEnv env) { FeatureDescriptor d = env.getFeatureDescriptor(); if (d instanceof Node.Property) { canWrite = ((Node.Property) d).canWrite(); } }
/** */ public void attachEnv (PropertyEnv env) { FeatureDescriptor desc = env.getFeatureDescriptor(); if (desc instanceof Node.Property){ Node.Property prop = (Node.Property)desc; editable = prop.canWrite(); } }
public void attachEnv(PropertyEnv env) { this.env = env; FeatureDescriptor desc = env.getFeatureDescriptor(); if (desc instanceof Node.Property){ Node.Property prop = (Node.Property)desc; editable = prop.canWrite(); //enh 29294 - support one-line editor & suppression of custom //editor instructions = (String) prop.getValue ("instructions"); //NOI18N oneline = Boolean.TRUE.equals (prop.getValue ("oneline")); //NOI18N customEd = !Boolean.TRUE.equals (prop.getValue ("suppressCustomEditor")); //NOI18N } }
@Override public FeatureDescriptor next() { if (!hasNext()) throw new NoSuchElementException(); FeatureDescriptor result = this.next; this.next = null; return result; }