/** The property set model is a model-within-a-model which * manages the expanded/unexpanded state of expandable * property sets and handles the sorting of properties * within a property set */ public void setPropertySetModel (PropertySetModel mod) { if (this.model == mod) return; if (model != null) model.removePropertySetModelListener (this); model = mod; if (model == null) throw new IllegalArgumentException ("Model cannot be null"); //set the node before adding listener so we don't get duplicate //events mod.addPropertySetModelListener (this); model = mod; fireTableChanged(new TableModelEvent(this)); //XXX optimize rows & stuff }
@Override public int getRowCount() { //JTable init will call this before the constructor is //completed (!!), so handle this case if (model == null) { return 0; } //get the count from the model - will depend on what is expanded. return model.getCount(); }
@Override public Object getValueAt(int rowIndex, int columnIndex) { Object result; if (rowIndex == -1) { result = null; } else { result = model.getFeatureDescriptor(rowIndex); } return result; }
/** Utility method to determine if the left edge margin should * be painted. This is determined by whether the property sheet * items are sorted by name or natural sort, or can be overridden * globally with a startup flag */ static boolean shouldDrawMargin (PropertySetModel psm) { if (neverMargin) return false; //hide margin and expansion handle if only one property //set, if flag is set (there is disagreement about the //right thing to do here, so it's an option for now) int setCount = psm.getSetCount(); if (psm.getComparator() != null) return false; boolean includeMargin = setCount > 1 || (!(setCount == 1 && hideSingleExpansion)); return includeMargin; }
/** * 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 ); } }
public void run() { if (loggable) { PropUtils.log (PropertySheet.class, " Nodes " + "cleared off event queue. Empty model later on EQ."); } table.getPropertySetModel().setPropertySets(null); } });
/** 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; }
/** * Check if the PropertySet the given property belongs to is expanded or not. * @param fd Property or PropertySet to check. * @return True if the PropertySet the given property belongs is expanded. * @since 6.47 */ protected final boolean isExpanded( FeatureDescriptor fd ) { return table.getPropertySetModel().isExpanded( fd ); }
/** Find the current index of the last edited FeatureDescriptor, to * figure out in which cell to restore the editing state */ private int indexOfLastSelected() { if (storedFd == null) { return -1; } PropertySetModel mdl = getPropertySetModel(); int idx = mdl.indexOf(storedFd); storedFd = null; return idx; }
/** Toggle the expanded state of a property set. If editing, the edit is * cancelled. */ private void toggleExpanded(int index) { if (isEditing()) { getEditor().cancelCellEditing(); } PropertySetModel psm = getSheetModel().getPropertySetModel(); psm.toggleExpanded(index); }
/** * Set the sorting mode. * @param sortingMode one of {@link #UNSORTED} or {@link #SORTED_BY_NAMES}. {@link #SORTED_BY_TYPES} is * no longer supported. * @throws PropertyVetoException if a value other than one of the defined sorting modes is set */ public void setSortingMode(int sortingMode) throws PropertyVetoException { try { table.getPropertySetModel().setComparator(PropUtils.getComparator(sortingMode)); this.sortingMode = sortingMode; psheet.setMarginPainted(!PropUtils.neverMargin && (getSortingMode() == UNSORTED)); PropUtils.putSortOrder(sortingMode); } catch (IllegalArgumentException iae) { throw new PropertyVetoException( NbBundle.getMessage(PropertySheet.class, "EXC_Unknown_sorting_mode"), new PropertyChangeEvent(this, PROPERTY_SORTING_MODE, new Integer(0), new Integer(sortingMode)) ); //NOI18N } }
/** * 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(); } } } }); } }
public void run() { if (loggable) { PropUtils.log (PropertySheet.class, " Nodes " + "cleared off event queue. Empty model later on EQ."); } table.getPropertySetModel().setPropertySets(null); } });
/** 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; }
@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); } } }
/** Find the current index of the last edited FeatureDescriptor, to * figure out in which cell to restore the editing state */ private int indexOfLastSelected () { if (storedFd == null) return -1; PropertySetModel mdl = getPropertySetModel(); int idx = mdl.indexOf(storedFd); storedFd = null; return idx; }
/** Utility method to determine if the left edge margin should * be painted. This is determined by whether the property sheet * items are sorted by name or natural sort, or can be overridden * globally with a startup flag */ static boolean shouldDrawMargin (PropertySetModel psm) { if (neverMargin) return false; //hide margin and expansion handle if only one property //set, if flag is set (there is disagreement about the //right thing to do here, so it's an option for now) int setCount = psm.getSetCount(); if (psm.getComparator() != null) return false; boolean includeMargin = setCount > 1 || (!(setCount == 1 && hideSingleExpansion)); return includeMargin; }
/** Toggle the expanded state of a property set. If editing, the edit is * cancelled. */ private void toggleExpanded (int index) { if (isEditing()) getEditor().cancelCellEditing(); PropertySetModel psm = getSheetModel().getPropertySetModel(); psm.toggleExpanded (index); }
/** * Set the sorting mode. * @param sortingMode one of {@link #UNSORTED} or {@link #SORTED_BY_NAMES}. {@link #SORTED_BY_TYPES} is * no longer supported. * @throws PropertyVetoException if a value other than one of the defined sorting modes is set */ public void setSortingMode(int sortingMode) throws PropertyVetoException { try { table.getPropertySetModel().setComparator(PropUtils.getComparator(sortingMode)); this.sortingMode = sortingMode; psheet.setMarginPainted(getSortingMode() == UNSORTED); PropUtils.putSortOrder (sortingMode); } catch (IllegalArgumentException iae) { throw new PropertyVetoException( NbBundle.getMessage( PropertySheet.class, "EXC_Unknown_sorting_mode"), new PropertyChangeEvent(this, PROPERTY_SORTING_MODE, new Integer(0), new Integer(sortingMode)) ); //NOI18N } }
public Object getValueAt(int rowIndex, int columnIndex) { Object result; if (rowIndex == -1) { result = null; } else { result = model.getFeatureDescriptor (rowIndex); } return result; }