Search in sources :

Example 26 with TableModel

use of javax.swing.table.TableModel in project intellij-community by JetBrains.

the class ProcessorProfilePanel method createTablePanel.

private static JPanel createTablePanel(final JBTable table) {
    return ToolbarDecorator.createDecorator(table).disableUpAction().disableDownAction().setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton anActionButton) {
            final TableCellEditor cellEditor = table.getCellEditor();
            if (cellEditor != null) {
                cellEditor.stopCellEditing();
            }
            final TableModel model = table.getModel();
            ((EditableModel) model).addRow();
            TableUtil.editCellAt(table, model.getRowCount() - 1, 0);
        }
    }).createPanel();
}
Also used : EditableModel(com.intellij.util.ui.EditableModel) TableCellEditor(javax.swing.table.TableCellEditor) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Example 27 with TableModel

use of javax.swing.table.TableModel in project azure-tools-for-java by Microsoft.

the class TableEntityForm method doValidate.

@Nullable
@Override
protected ValidationInfo doValidate() {
    final TableModel model = propertiesTable.getModel();
    final String partitionKey = model.getValueAt(0, 3).toString();
    final String rowKey = model.getValueAt(1, 3).toString();
    for (int row = 2; row != model.getRowCount(); row++) {
        TableEntity.PropertyType propertyType = (TableEntity.PropertyType) model.getValueAt(row, 2);
        String name = model.getValueAt(row, 1).toString();
        String value = model.getValueAt(row, 3).toString();
        if (!isValidPropertyName(name)) {
            return new ValidationInfo(String.format("The property name \"%s\" is invalid", name), propertiesTable);
        }
        TableEntity.Property property = getProperty(value, propertyType);
        if (property == null) {
            return new ValidationInfo(String.format("The field %s has an invalid value for its type", name), propertiesTable);
        }
    }
    if (tableEntity == null) {
        for (TableEntity te : tableEntityList) {
            if (te.getPartitionKey().equals(partitionKey) && te.getRowKey().equals(rowKey)) {
                return new ValidationInfo("An entity already exists with this partition key and row key pair", propertiesTable);
            }
        }
    }
    return null;
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) TableEntity(com.microsoft.tooling.msservices.model.storage.TableEntity) TableModel(javax.swing.table.TableModel) DefaultTableModel(javax.swing.table.DefaultTableModel) Nullable(org.jetbrains.annotations.Nullable)

Example 28 with TableModel

use of javax.swing.table.TableModel in project intellij-community by JetBrains.

the class EditVariableDialog method createVariablesTable.

private JComponent createVariablesTable() {
    final String[] names = { CodeInsightBundle.message("templates.dialog.edit.variables.table.column.name"), CodeInsightBundle.message("templates.dialog.edit.variables.table.column.expression"), CodeInsightBundle.message("templates.dialog.edit.variables.table.column.default.value"), CodeInsightBundle.message("templates.dialog.edit.variables.table.column.skip.if.defined") };
    // Create a model of the data.
    TableModel dataModel = new VariablesModel(names);
    // Create the table
    myTable = new JBTable(dataModel);
    myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myTable.setPreferredScrollableViewportSize(new Dimension(500, myTable.getRowHeight() * 8));
    myTable.getColumn(names[0]).setPreferredWidth(120);
    myTable.getColumn(names[1]).setPreferredWidth(200);
    myTable.getColumn(names[2]).setPreferredWidth(200);
    myTable.getColumn(names[3]).setPreferredWidth(100);
    if (myVariables.size() > 0) {
        myTable.getSelectionModel().setSelectionInterval(0, 0);
    }
    Predicate<Macro> isAcceptableInContext = macro -> myContextTypes.stream().anyMatch(macro::isAcceptableInContext);
    Stream<String> availableMacroNames = Arrays.stream(MacroFactory.getMacros()).filter(isAcceptableInContext).map(Macro::getPresentableName).sorted();
    Set<String> uniqueNames = availableMacroNames.collect(Collectors.toCollection(LinkedHashSet::new));
    ComboBox comboField = new ComboBox();
    uniqueNames.forEach(comboField::addItem);
    comboField.setEditable(true);
    DefaultCellEditor cellEditor = new DefaultCellEditor(comboField);
    cellEditor.setClickCountToStart(1);
    myTable.getColumn(names[1]).setCellEditor(cellEditor);
    myTable.setRowHeight(comboField.getPreferredSize().height);
    JTextField textField = new JTextField();
    /*textField.addMouseListener(
      new PopupHandler(){
        public void invokePopup(Component comp,int x,int y){
          showCellPopup((JTextField)comp,x,y);
        }
      }
    );*/
    cellEditor = new DefaultCellEditor(textField);
    cellEditor.setClickCountToStart(1);
    myTable.setDefaultEditor(String.class, cellEditor);
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTable).disableAddAction().disableRemoveAction();
    return decorator.createPanel();
}
Also used : java.util(java.util) Document(com.intellij.openapi.editor.Document) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) CodeInsightBundle(com.intellij.codeInsight.CodeInsightBundle) TableCellEditor(javax.swing.table.TableCellEditor) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) CommonBundle(com.intellij.CommonBundle) AbstractTableModel(javax.swing.table.AbstractTableModel) TemplateContextType(com.intellij.codeInsight.template.TemplateContextType) TableModel(javax.swing.table.TableModel) ComboBox(com.intellij.openapi.ui.ComboBox) Predicate(java.util.function.Predicate) Editor(com.intellij.openapi.editor.Editor) Collectors(java.util.stream.Collectors) MacroFactory(com.intellij.codeInsight.template.macro.MacroFactory) java.awt(java.awt) CommandProcessor(com.intellij.openapi.command.CommandProcessor) HelpManager(com.intellij.openapi.help.HelpManager) JBTable(com.intellij.ui.table.JBTable) List(java.util.List) Stream(java.util.stream.Stream) Macro(com.intellij.codeInsight.template.Macro) EditableModel(com.intellij.util.ui.EditableModel) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) Macro(com.intellij.codeInsight.template.Macro) ComboBox(com.intellij.openapi.ui.ComboBox) JBTable(com.intellij.ui.table.JBTable) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Example 29 with TableModel

use of javax.swing.table.TableModel in project intellij-community by JetBrains.

the class UserActivityWatcher method unprocessComponent.

protected void unprocessComponent(final Component component) {
    if (component instanceof JTextComponent) {
        ((JTextComponent) component).getDocument().removeDocumentListener(myDocumentListener);
    } else if (component instanceof ItemSelectable) {
        ((ItemSelectable) component).removeItemListener(myItemListener);
    } else if (component instanceof JTree) {
        ((JTree) component).getModel().removeTreeModelListener(myTreeModelListener);
    } else if (component instanceof DocumentBasedComponent) {
        ((DocumentBasedComponent) component).getDocument().removeDocumentListener(myIdeaDocumentListener);
    }
    if (component instanceof JTable) {
        component.removePropertyChangeListener(myTableListener);
        TableModel model = ((JTable) component).getModel();
        if (model != null) {
            model.removeTableModelListener(myTableModelListener);
        }
        component.removePropertyChangeListener(myCellEditorChangeListener);
    }
    if (component instanceof JSlider) {
        ((JSlider) component).removeChangeListener(myChangeListener);
    }
    if (component instanceof UserActivityProviderComponent) {
        ((UserActivityProviderComponent) component).removeChangeListener(myChangeListener);
    }
}
Also used : JTextComponent(javax.swing.text.JTextComponent) TableModel(javax.swing.table.TableModel)

Example 30 with TableModel

use of javax.swing.table.TableModel in project intellij-community by JetBrains.

the class OrderPanel method getEntries.

public List<T> getEntries() {
    final TableModel model = myEntryTable.getModel();
    final int size = model.getRowCount();
    List<T> result = new ArrayList<>(size);
    for (int idx = 0; idx < size; idx++) {
        result.add(getValueAt(idx));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) DefaultTableModel(javax.swing.table.DefaultTableModel) TableModel(javax.swing.table.TableModel)

Aggregations

TableModel (javax.swing.table.TableModel)53 AbstractTableModel (javax.swing.table.AbstractTableModel)11 JTable (javax.swing.JTable)9 DefaultTableModel (javax.swing.table.DefaultTableModel)9 TableColumn (javax.swing.table.TableColumn)9 ArrayList (java.util.ArrayList)8 TableRowSorter (javax.swing.table.TableRowSorter)8 TableCellRenderer (javax.swing.table.TableCellRenderer)6 ActionEvent (java.awt.event.ActionEvent)5 JButton (javax.swing.JButton)5 JScrollPane (javax.swing.JScrollPane)5 TableCellEditor (javax.swing.table.TableCellEditor)5 Component (java.awt.Component)4 ActionListener (java.awt.event.ActionListener)4 List (java.util.List)4 Set (java.util.Set)4 TableColumnModel (javax.swing.table.TableColumnModel)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 AttributesTableModel (com.android.tools.idea.editors.theme.attributes.AttributesTableModel)2