Search in sources :

Example 26 with TableModelEvent

use of javax.swing.event.TableModelEvent in project intellij-community by JetBrains.

the class ExternalResourceConfigurable method createComponent.

@Override
public JComponent createComponent() {
    myPanel = new JPanel(new GridBagLayout()) {

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(-1, 400);
        }
    };
    myExtPanel = new AddEditRemovePanel<NameLocationPair>(new ExtUrlsTableModel(), myPairs, XmlBundle.message("label.edit.external.resource.configure.external.resources")) {

        @Override
        protected NameLocationPair addItem() {
            return addExtLocation();
        }

        @Override
        protected boolean removeItem(NameLocationPair o) {
            setModified(true);
            return true;
        }

        @Override
        protected NameLocationPair editItem(NameLocationPair o) {
            return editExtLocation(o);
        }
    };
    myExtPanel.getTable().setShowColumns(true);
    myExtPanel.setRenderer(1, new PathRenderer());
    JTable table = myExtPanel.getTable();
    if (myProject != null) {
        TableColumn column = table.getColumn(table.getColumnName(2));
        column.setMaxWidth(50);
        column.setCellEditor(JBTable.createBooleanEditor());
    }
    table.getModel().addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            setModified(true);
        }
    });
    myIgnorePanel = new AddEditRemovePanel<String>(new IgnoredUrlsModel(), myIgnoredUrls, XmlBundle.message("label.edit.external.resource.configure.ignored.resources")) {

        @Override
        protected String addItem() {
            return addIgnoreLocation();
        }

        @Override
        protected boolean removeItem(String o) {
            setModified(true);
            return true;
        }

        @Override
        protected String editItem(String o) {
            return editIgnoreLocation(o);
        }
    };
    myPanel.add(myExtPanel, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    myPanel.add(myIgnorePanel, new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    myExtPanel.setData(myPairs);
    myIgnorePanel.setData(myIgnoredUrls);
    myExtPanel.getEmptyText().setText(XmlBundle.message("no.external.resources"));
    myIgnorePanel.getEmptyText().setText(XmlBundle.message("no.ignored.resources"));
    return myPanel;
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) TableColumn(javax.swing.table.TableColumn) TableModelListener(javax.swing.event.TableModelListener)

Example 27 with TableModelEvent

use of javax.swing.event.TableModelEvent in project android by JetBrains.

the class ViewNodeTableModel method setNode.

public void setNode(@NotNull ViewNode node) {
    // Go through the properties, filtering the favorites properties first
    mEntries.clear();
    mEntries.addAll(node.properties);
    notifyChange(new TableModelEvent(this));
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent)

Example 28 with TableModelEvent

use of javax.swing.event.TableModelEvent in project jdk8u_jdk by JetBrains.

the class XMBeanAttributes method doLoadAttributes.

// Don't call this in EDT, but execute returned Runnable inside
// EDT - typically in the done() method of a SwingWorker
// This method can return null.
private Runnable doLoadAttributes(final XMBean mbean, MBeanInfo infoOrNull) throws JMException, IOException {
    if (mbean == null)
        return null;
    final MBeanInfo curMBeanInfo = (infoOrNull == null) ? mbean.getMBeanInfo() : infoOrNull;
    final MBeanAttributeInfo[] attrsInfo = curMBeanInfo.getAttributes();
    final HashMap<String, Object> attrs = new HashMap<String, Object>(attrsInfo.length);
    final HashMap<String, Object> unavailableAttrs = new HashMap<String, Object>(attrsInfo.length);
    final HashMap<String, Object> viewableAttrs = new HashMap<String, Object>(attrsInfo.length);
    AttributeList list = null;
    try {
        list = mbean.getAttributes(attrsInfo);
    } catch (Exception e) {
        if (JConsole.isDebug()) {
            System.err.println("Error calling getAttributes() on MBean \"" + mbean.getObjectName() + "\". JConsole will " + "try to get them individually calling " + "getAttribute() instead. Exception:");
            e.printStackTrace(System.err);
        }
        list = new AttributeList();
        //Can't load all attributes, do it one after each other.
        for (int i = 0; i < attrsInfo.length; i++) {
            String name = null;
            try {
                name = attrsInfo[i].getName();
                Object value = mbean.getMBeanServerConnection().getAttribute(mbean.getObjectName(), name);
                list.add(new Attribute(name, value));
            } catch (Exception ex) {
                if (attrsInfo[i].isReadable()) {
                    unavailableAttrs.put(name, Utils.getActualException(ex).toString());
                }
            }
        }
    }
    try {
        int att_length = list.size();
        for (int i = 0; i < att_length; i++) {
            Attribute attribute = (Attribute) list.get(i);
            if (isViewable(attribute)) {
                viewableAttrs.put(attribute.getName(), attribute.getValue());
            } else
                attrs.put(attribute.getName(), attribute.getValue());
        }
        // check them one after the other.
        if (att_length < attrsInfo.length) {
            for (int i = 0; i < attrsInfo.length; i++) {
                MBeanAttributeInfo attributeInfo = attrsInfo[i];
                if (!attrs.containsKey(attributeInfo.getName()) && !viewableAttrs.containsKey(attributeInfo.getName()) && !unavailableAttrs.containsKey(attributeInfo.getName())) {
                    if (attributeInfo.isReadable()) {
                        // went wrong.
                        try {
                            Object v = mbean.getMBeanServerConnection().getAttribute(mbean.getObjectName(), attributeInfo.getName());
                            //What happens if now it is ok?
                            // Be pragmatic, add it to readable...
                            attrs.put(attributeInfo.getName(), v);
                        } catch (Exception e) {
                            //Put the exception that will be displayed
                            // in tooltip
                            unavailableAttrs.put(attributeInfo.getName(), Utils.getActualException(e).toString());
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        //sets all attributes unavailable except the writable ones
        for (int i = 0; i < attrsInfo.length; i++) {
            MBeanAttributeInfo attributeInfo = attrsInfo[i];
            if (attributeInfo.isReadable()) {
                unavailableAttrs.put(attributeInfo.getName(), Utils.getActualException(e).toString());
            }
        }
    }
    //one update at a time
    return new Runnable() {

        public void run() {
            synchronized (XMBeanAttributes.this) {
                XMBeanAttributes.this.mbean = mbean;
                XMBeanAttributes.this.mbeanInfo = curMBeanInfo;
                XMBeanAttributes.this.attributesInfo = attrsInfo;
                XMBeanAttributes.this.attributes = attrs;
                XMBeanAttributes.this.unavailableAttributes = unavailableAttrs;
                XMBeanAttributes.this.viewableAttributes = viewableAttrs;
                DefaultTableModel tableModel = (DefaultTableModel) getModel();
                // add attribute information
                emptyTable(tableModel);
                addTableData(tableModel, mbean, attrsInfo, attrs, unavailableAttrs, viewableAttrs);
                // update the model with the new data
                tableModel.newDataAvailable(new TableModelEvent(tableModel));
                // re-register for change events
                tableModel.addTableModelListener(attributesListener);
            }
        }
    };
}
Also used : MBeanInfo(javax.management.MBeanInfo) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) TableModelEvent(javax.swing.event.TableModelEvent) DefaultTableModel(javax.swing.table.DefaultTableModel) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JMException(javax.management.JMException) EventObject(java.util.EventObject)

Example 29 with TableModelEvent

use of javax.swing.event.TableModelEvent in project jabref by JabRef.

the class FileListTableModel method setContent.

private FileListEntry setContent(String val, boolean firstOnly, boolean deduceUnknownTypes) {
    String value = val;
    if (value == null) {
        value = "";
    }
    List<LinkedFile> fields = FileFieldParser.parse(value);
    List<FileListEntry> files = new ArrayList<>();
    for (LinkedFile entry : fields) {
        if (entry.isEmpty()) {
            continue;
        }
        if (firstOnly) {
            return decodeEntry(entry, deduceUnknownTypes);
        } else {
            files.add(decodeEntry(entry, deduceUnknownTypes));
        }
    }
    synchronized (list) {
        list.clear();
        list.addAll(files);
    }
    fireTableChanged(new TableModelEvent(this));
    return null;
}
Also used : LinkedFile(org.jabref.model.entry.LinkedFile) TableModelEvent(javax.swing.event.TableModelEvent) ArrayList(java.util.ArrayList)

Example 30 with TableModelEvent

use of javax.swing.event.TableModelEvent in project pcgen by PCGen.

the class JTableEx method setModel.

@Override
public void setModel(TableModel dataModel) {
    if (dataModel == null) {
        throw new IllegalArgumentException("Cannot set a null TableModel");
    }
    if (this.dataModel != dataModel) {
        TableModel old = this.dataModel;
        if (old != null) {
            old.removeTableModelListener(this);
        }
        this.dataModel = dataModel;
        dataModel.addTableModelListener(this);
        tableChanged(new TableModelEvent(dataModel, TableModelEvent.HEADER_ROW));
        firePropertyChange("model", old, dataModel);
        if (getAutoCreateRowSorter()) {
            if (dataModel instanceof SortableTableModel) {
                super.setRowSorter(new SortableTableRowSorter((SortableTableModel) dataModel));
            } else {
                super.setRowSorter(new TableRowSorter(dataModel));
            }
        }
    }
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) SortableTableRowSorter(pcgen.gui2.util.table.SortableTableRowSorter) SortableTableModel(pcgen.gui2.util.table.SortableTableModel) SortableTableModel(pcgen.gui2.util.table.SortableTableModel) TableModel(javax.swing.table.TableModel) TableRowSorter(javax.swing.table.TableRowSorter) SortableTableRowSorter(pcgen.gui2.util.table.SortableTableRowSorter)

Aggregations

TableModelEvent (javax.swing.event.TableModelEvent)35 TableModelListener (javax.swing.event.TableModelListener)15 DefaultTableModel (javax.swing.table.DefaultTableModel)6 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 ArrayList (java.util.ArrayList)4 JScrollPane (javax.swing.JScrollPane)4 TableColumn (javax.swing.table.TableColumn)4 JBTable (com.intellij.ui.table.JBTable)3 Dimension (java.awt.Dimension)3 GridBagConstraints (java.awt.GridBagConstraints)3 Insets (java.awt.Insets)3 JButton (javax.swing.JButton)3 JTable (javax.swing.JTable)3 ListSelectionEvent (javax.swing.event.ListSelectionEvent)3 ListSelectionListener (javax.swing.event.ListSelectionListener)3 GridBagLayout (java.awt.GridBagLayout)2 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)2 JComboBox (javax.swing.JComboBox)2 JPanel (javax.swing.JPanel)2