Java Code Examples for javax.swing.table.DefaultTableModel#getDataVector()

The following examples show how to use javax.swing.table.DefaultTableModel#getDataVector() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: J2SEModularProjectProperties.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void storeRoots( ModuleRoots roots, DefaultTableModel tableModel ) throws MalformedURLException {
    Vector data = tableModel.getDataVector();
    URL[] rootURLs = new URL[data.size()];
    String []rootPaths = new String[data.size()];
    final LinkedList<URL> oldRootURLs = new LinkedList<>(Arrays.asList (roots.getRootURLs (false)));
    final LinkedList<String> oldRootPathProps = new LinkedList<>(Arrays.asList (roots.getRootPathProperties()));
    boolean rootsAreSame = true;
    for (int i=0; i<data.size();i++) {
        File f = (File) ((Vector)data.elementAt(i)).elementAt(0);
        rootURLs[i] = Utilities.toURI(f).toURL();
        if (!rootURLs[i].toExternalForm().endsWith("/")) {  //NOI18N
            rootURLs[i] = new URL(rootURLs[i]+"/");
        }
        validateURL(rootURLs[i],f);
        rootPaths[i] = (String) ((Vector)data.elementAt(i)).elementAt(1);
        rootsAreSame &= !oldRootURLs.isEmpty() &&
                        oldRootURLs.removeFirst().equals(rootURLs[i]) &&
                        roots.getRootPath(oldRootPathProps.removeFirst()).equals(rootPaths[i]);
    }
    if (!rootsAreSame || !oldRootURLs.isEmpty ()) {
        roots.putModuleRoots(rootURLs, rootPaths);
    }
}
 
Example 2
Source File: J2SEProjectProperties.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void storeRoots( SourceRoots roots, DefaultTableModel tableModel ) throws MalformedURLException {
    Vector data = tableModel.getDataVector();
    URL[] rootURLs = new URL[data.size()];
    String []rootLabels = new String[data.size()];
    final LinkedList<URL> oldRootURLs = new LinkedList<URL>(Arrays.asList (roots.getRootURLs (false)));
    final LinkedList<String> oldRootLabels = new LinkedList<String>(Arrays.asList(roots.getRootNames()));
    final LinkedList<String> oldRootProps = new LinkedList<String>(Arrays.asList (roots.getRootProperties()));
    boolean rootsAreSame = true;
    for (int i=0; i<data.size();i++) {
        File f = (File) ((Vector)data.elementAt(i)).elementAt(0);
        rootURLs[i] = Utilities.toURI(f).toURL();
        if (!rootURLs[i].toExternalForm().endsWith("/")) {  //NOI18N
            rootURLs[i] = new URL(rootURLs[i]+"/");
        }
        validateURL(rootURLs[i],f);
        rootLabels[i] = (String) ((Vector)data.elementAt(i)).elementAt(1);
        rootsAreSame &= !oldRootURLs.isEmpty() &&
                        oldRootURLs.removeFirst().equals(rootURLs[i]) &&
                        roots.getRootDisplayName(oldRootLabels.removeFirst(), oldRootProps.removeFirst()).equals(rootLabels[i]);
    }
    if (!rootsAreSame || !oldRootURLs.isEmpty ()) {
        roots.putRoots(rootURLs,rootLabels);
    }
}
 
Example 3
Source File: HeaderCheckBoxHandler.java    From java-swing-tips with MIT License 6 votes vote down vote up
private boolean fireUpdateEvent(DefaultTableModel m, TableColumn column, Object status) {
  if (status == Status.INDETERMINATE) {
    List<?> data =  m.getDataVector();
    List<Boolean> l = data.stream()
        .map(v -> (Boolean) ((List<?>) v).get(targetColumnIndex))
        .distinct()
        .collect(Collectors.toList());
    boolean notDuplicates = l.size() == 1;
    if (notDuplicates) {
      boolean isSelected = l.get(0);
      column.setHeaderValue(isSelected ? Status.SELECTED : Status.DESELECTED);
      return true;
    } else {
      return false;
    }
  } else {
    column.setHeaderValue(Status.INDETERMINATE);
    return true;
  }
}
 
Example 4
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private boolean fireUpdateEvent(DefaultTableModel m, TableColumn column, Object status) {
  if (status == Status.INDETERMINATE) {
    List<?> data = m.getDataVector();
    List<Boolean> l = data.stream()
        .map(v -> (Boolean) ((List<?>) v).get(targetColumnIndex))
        .distinct()
        .collect(Collectors.toList());
    boolean notDuplicates = l.size() == 1;
    if (notDuplicates) {
      boolean isSelected = l.get(0);
      column.setHeaderValue(isSelected ? Status.SELECTED : Status.DESELECTED);
      return true;
    } else {
      return false;
    }
  } else {
    column.setHeaderValue(Status.INDETERMINATE);
    return true;
  }
}
 
Example 5
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private boolean fireUpdateEvent(DefaultTableModel m, TableColumn column, Object status) {
  if (status == Status.INDETERMINATE) {
    List<?> data = m.getDataVector();
    List<Boolean> l = data.stream()
        .map(v -> (Boolean) ((List<?>) v).get(targetColumnIndex))
        .distinct()
        .collect(Collectors.toList());
    boolean notDuplicates = l.size() == 1;
    if (notDuplicates) {
      boolean isSelected = l.get(0);
      column.setHeaderValue(isSelected ? Status.SELECTED : Status.DESELECTED);
      return true;
    } else {
      return false;
    }
  } else {
    column.setHeaderValue(Status.INDETERMINATE);
    return true;
  }
}
 
Example 6
Source File: RunContainerPropertiesVisual.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Map<String, String> getVolumesTable() {
    Map<String, String> result = new TreeMap<>();
    DefaultTableModel model = (DefaultTableModel) volumesTable.getModel();
    if (volumesTable.isEditing()) {
        volumesTable.getCellEditor().stopCellEditing();
    }
    for (Object o : model.getDataVector()) {
        Vector v = (Vector) o;
        String target = (String) v.elementAt(0);
        String source = (String) v.elementAt(1);
        if (target != null && source != null) {
            result.put(target, source);
        }
    }
    return result;
}
 
Example 7
Source File: BuildOptionsVisual.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Map<String, String> getBuildArgs() {
    Map<String, String> result = new TreeMap<>();
    DefaultTableModel model = (DefaultTableModel) buildargsTable.getModel();
    if (buildargsTable.isEditing()) {
        buildargsTable.getCellEditor().stopCellEditing();
    }
    for (Object o : model.getDataVector()) {
        Vector v = (Vector) o;
        String name = (String) v.elementAt(0);
        String value = (String) v.elementAt(1);
        if (name != null && value != null) {
            result.put(name, value);
        }
    }
    return result;
}
 
Example 8
Source File: J2SEModularProjectProperties.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void loadIncludesExcludes(IncludeExcludeVisualizer v) {
    Set<File> roots = new HashSet<File>();
    for (DefaultTableModel model : new DefaultTableModel[] {MODULE_ROOTS_MODEL, TEST_MODULE_ROOTS_MODEL}) {
        for (Object row : model.getDataVector()) {
            File d = (File) ((Vector) row).elementAt(0);
            if (/* #104996 */d.isDirectory()) {
                roots.add(d);
            }
        }
    }
    v.setRoots(roots.toArray(new File[roots.size()]));
    v.setIncludePattern(includes);
    v.setExcludePattern(excludes);
}
 
Example 9
Source File: RunCalibrationAction.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void refreshModel(final ProfilerTable table) {
    Object selected = null;
    Set original = new HashSet();
    int selrow = table.getSelectedRow();
    int column = table.convertColumnIndexToView(0);
    for (int row = 0; row < table.getRowCount(); row++) {
        Object value = table.getValueAt(row, column);
        original.add(value);
        if (row == selrow) selected = value;
    }
    
    final DefaultTableModel model = (DefaultTableModel)table.getModel();
    Vector data = model.getDataVector();
    data.clear();
    
    for (JavaPlatform platform : JavaPlatform.getPlatforms()) {
        data.add(new Vector(Arrays.asList(platform, null)));
        if (!original.contains(platform)) selected = platform;
    }
    
    table.clearSelection();
    model.fireTableDataChanged();
    
    if (selected != null) table.selectValue(selected, column, true);
    
    RequestProcessor.getDefault().post(new Runnable() {
        public void run() { refreshTimes(model); }
    });
}
 
Example 10
Source File: AppClientProjectProperties.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void loadIncludesExcludes(IncludeExcludeVisualizer v) {
    Set<File> roots = new HashSet<File>();
    for (DefaultTableModel model : new DefaultTableModel[] {SOURCE_ROOTS_MODEL, TEST_ROOTS_MODEL}) {
        for (Object row : model.getDataVector()) {
            File d = (File) ((Vector) row).elementAt(0);
            if (d.isDirectory()) {
                roots.add(d);
            }
        }
    }
    v.setRoots(roots.toArray(new File[roots.size()]));
    v.setIncludePattern(includes);
    v.setExcludePattern(excludes);
}
 
Example 11
Source File: AppClientProjectProperties.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void storeRoots( SourceRoots roots, DefaultTableModel tableModel ) throws MalformedURLException {
    Vector data = tableModel.getDataVector();
    URL[] rootURLs = new URL[data.size()];
    String []rootLabels = new String[data.size()];
    for (int i=0; i<data.size();i++) {
        File f = (File) ((Vector)data.elementAt(i)).elementAt(0);
        rootURLs[i] = Utils.getRootURL(f,null);            
        rootLabels[i] = (String) ((Vector)data.elementAt(i)).elementAt(1);
    }
    roots.putRoots(rootURLs,rootLabels);
}
 
Example 12
Source File: WebProjectProperties.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void storeRoots( SourceRoots roots, DefaultTableModel tableModel ) throws MalformedURLException {
    Vector data = tableModel.getDataVector();
    URL[] rootURLs = new URL[data.size()];
    String []rootLabels = new String[data.size()];
    for (int i=0; i<data.size();i++) {
        File f = ((File)((Vector)data.elementAt(i)).elementAt(0));
        rootURLs[i] = Utils.getRootURL(f,null);
        rootLabels[i] = (String) ((Vector)data.elementAt(i)).elementAt(1);
    }
    roots.putRoots(rootURLs,rootLabels);
}
 
Example 13
Source File: EjbJarProjectProperties.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void loadIncludesExcludes(IncludeExcludeVisualizer v) {
    Set<File> roots = new HashSet<File>();
    for (DefaultTableModel model : new DefaultTableModel[] {SOURCE_ROOTS_MODEL, TEST_ROOTS_MODEL}) {
        for (Object row : model.getDataVector()) {
            File d = (File) ((Vector) row).elementAt(0);
            if (d.isDirectory()) {
                roots.add(d);
            }
        }
    }
    v.setRoots(roots.toArray(new File[roots.size()]));
    v.setIncludePattern(includes);
    v.setExcludePattern(excludes);
}
 
Example 14
Source File: EjbJarProjectProperties.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void storeRoots( SourceRoots roots, DefaultTableModel tableModel ) throws MalformedURLException {
    Vector data = tableModel.getDataVector();
    URL[] rootURLs = new URL[data.size()];
    String []rootLabels = new String[data.size()];
    for (int i=0; i<data.size();i++) {
        File f = ((File)((Vector)data.elementAt(i)).elementAt(0));
        rootURLs[i] = Utils.getRootURL(f,null);
        rootLabels[i] = (String) ((Vector)data.elementAt(i)).elementAt(1);
    }
    roots.putRoots(rootURLs,rootLabels);
}
 
Example 15
Source File: RunCalibrationAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void refreshModel(final ProfilerTable table) {
    Object selected = null;
    Set original = new HashSet();
    int selrow = table.getSelectedRow();
    int column = table.convertColumnIndexToView(0);
    for (int row = 0; row < table.getRowCount(); row++) {
        Object value = table.getValueAt(row, column);
        original.add(value);
        if (row == selrow) selected = value;
    }
    
    final DefaultTableModel model = (DefaultTableModel)table.getModel();
    Vector data = model.getDataVector();
    data.clear();
    
    for (JavaPlatform platform : JavaPlatform.getPlatforms()) {
        data.add(new Vector(Arrays.asList(platform, null)));
        if (!original.contains(platform)) selected = platform;
    }
    
    table.clearSelection();
    model.fireTableDataChanged();
    
    if (selected != null) table.selectValue(selected, column, true);
    
    RequestProcessor.getDefault().post(new Runnable() {
        public void run() { refreshTimes(model); }
    });
}
 
Example 16
Source File: J2SEProjectProperties.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void loadIncludesExcludes(IncludeExcludeVisualizer v) {
    Set<File> roots = new HashSet<File>();
    for (DefaultTableModel model : new DefaultTableModel[] {SOURCE_ROOTS_MODEL, TEST_ROOTS_MODEL}) {
        for (Object row : model.getDataVector()) {
            File d = (File) ((Vector) row).elementAt(0);
            if (/* #104996 */d.isDirectory()) {
                roots.add(d);
            }
        }
    }
    v.setRoots(roots.toArray(new File[roots.size()]));
    v.setIncludePattern(includes);
    v.setExcludePattern(excludes);
}
 
Example 17
Source File: AbstractTableAdapter.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private void adjustTableModel() {
    final DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
    final Object value = getBinding().getPropertyValue();
    if (value instanceof Object[]) {
        final Object[] items = (Object[]) value;
        // 1. add missing rows to model
        for (int i = tableModel.getRowCount(); i < items.length; i++) {
            tableModel.addRow((Object[]) null);
        }
        // 2. remove redundant rows from model
        for (int i = items.length; i < tableModel.getRowCount(); i++) {
            tableModel.removeRow(i);
        }
        // 3. update cell values
        for (int i = 0; i < items.length; i++) {
            final Object item = items[i];
            final Field[] fields = item.getClass().getDeclaredFields();
            for (int k = 0; k < fields.length; k++) {
                final Field field = fields[k];
                final boolean accessible = field.isAccessible();
                if (!accessible) {
                    field.setAccessible(true);
                }
                try {
                    Vector dataVector = tableModel.getDataVector();
                    Vector row = (Vector)dataVector.elementAt(i);
                    // 1. add missing columns to row
                    for (int l = row.size(); l < fields.length; l++) {
                        row.add(null);
                    }
                    // 2. remove redundant columns from row
                    for (int l = fields.length; l < row.size(); l++) {
                        row.remove(l);
                    }

                    tableModel.setValueAt(field.get(item), i, k);
                } catch (IllegalAccessException e) {
                    // ignore
                }
                if (!accessible) {
                    field.setAccessible(false);
                }
            }
        }
    }
}