@Override public TableCellEditor getCellEditor(int row, int column) { MyTableModel model = (MyTableModel) getModel(); if (column == 0) { return null; } // code repetition with getCellRenderer because of TableCell{Renderer, Editor} // non-inheritance Class<?> klass = model.getClassAt(row, column); PropertyEditorTableAdapter javaBeansEditor = PropertyEditorTableAdapter.forClass(klass); if (javaBeansEditor != null) { return javaBeansEditor; } TableCellEditor defaultEditor = getDefaultEditor(klass); if (defaultEditor == null) { log.warning("No TableCellEditor for " + klass.getName()); } if (defaultEditor instanceof DefaultCellEditor) { // default double-click is bad user interaction ((DefaultCellEditor) defaultEditor).setClickCountToStart(0); } return defaultEditor; }
@Override protected void fireEditingStopped() { super.fireEditingStopped(); System.out.println("ttttttttt"); }
public void init() { // <Begin_init> if (getParameter("RESOURCE_PROPERTIES") != null) { localePropertiesFileName = getParameter("RESOURCE_PROPERTIES"); } resourceBundle = com.adventnet.apiutils.Utility.getBundle( localePropertiesFileName, getParameter("RESOURCE_LOCALE"), applet); if (initialized) return; this.setSize(getPreferredSize().width + 495, getPreferredSize().height + 480); setTitle(resourceBundle.getString("ViewConfig")); Container container = getContentPane(); container.setLayout(new BorderLayout()); try { initVariables(); setUpGUI(container); setUpProperties(); setUpConnections(); } catch (Exception ex) { showStatus(resourceBundle.getString("Error in init method"), ex); } // let us set the initialized variable to true so // we dont initialize again even if init is called initialized = true; // <End_init> setTitle(resourceBundle.getString("View Configuration")); setIconImage(AuthMain.getBuilderUiIfInstance().getFrameIcon()); JLabel1.setIcon(AuthMain.getBuilderUiIfInstance().getImage("viewconfig.png")); com.adventnet.security.ui.ViewListCellRenderer ViewListCellRenderer1 = new com.adventnet.security.ui.ViewListCellRenderer(); JTable1.setDefaultRenderer(JTable1.getColumnClass(0), ViewListCellRenderer1); JLabel2.setIcon(AuthMain.getBuilderUiIfInstance().getImage("addview1.png")); JTable1.getCellEditor(0, 0) .getTableCellEditorComponent(JTable1, null, true, 0, 0) .setEnabled(false); DefaultCellEditor te = (DefaultCellEditor) JTable1.getCellEditor(0, 0); te.setClickCountToStart(10); JTable1.setCellEditor(te); JViewport vp = new JViewport(); JLabel lab = new JLabel(resourceBundle.getString("List of available views")); lab.setHorizontalAlignment((int) JLabel.CENTER_ALIGNMENT); lab.setForeground(Color.black); vp.setView(lab); AuthMain.getBuilderUiIfInstance().centerWindow(this); setData(); viewc = this; addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { close(); } }); /* TableColumn col2 = JTable1.getColumnModel().getColumn(1); DefaultTableCellRenderer ren = new DefaultTableCellRenderer(); ren.setIcon(AuthMain.getBuilderUiIfInstance().getImage("task1.png")); col2.setCellRenderer(ren); col2.setMaxWidth(30); */ DefaultListSelectionModel selModel = new DefaultListSelectionModel(); selModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JTable1.setSelectionModel(selModel); }
@Override public void cancelCellEditing() { super.cancelCellEditing(); requestFocusToTree(); }
public void itemStateChanged(ItemEvent e) { super.fireEditingStopped(); }
public ParameterTablePanel( Project project, VariableData[] variableData, final PsiElement... scopeElements) { super(new BorderLayout()); myProject = project; myVariableData = variableData; myTableModel = new MyTableModel(); myTable = new JBTable(myTableModel); DefaultCellEditor defaultEditor = (DefaultCellEditor) myTable.getDefaultEditor(Object.class); defaultEditor.setClickCountToStart(1); myTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myTable.setCellSelectionEnabled(true); TableColumn checkboxColumn = myTable.getColumnModel().getColumn(MyTableModel.CHECKMARK_COLUMN); TableUtil.setupCheckboxColumn(checkboxColumn); checkboxColumn.setCellRenderer(new CheckBoxTableCellRenderer()); myTable .getColumnModel() .getColumn(MyTableModel.PARAMETER_NAME_COLUMN) .setCellRenderer( new DefaultTableCellRenderer() { public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column); VariableData data = getVariableData()[row]; setText(data.name); return this; } }); myParameterTypeSelectors = new TypeSelector[getVariableData().length]; for (int i = 0; i < myParameterTypeSelectors.length; i++) { final PsiVariable variable = getVariableData()[i].variable; final PsiExpression[] occurrences = findVariableOccurrences(scopeElements, variable); final TypeSelectorManager manager = new TypeSelectorManagerImpl( myProject, getVariableData()[i].type, occurrences, areTypesDirected()) { @Override protected boolean isUsedAfter() { return ParameterTablePanel.this.isUsedAfter(variable); } }; myParameterTypeSelectors[i] = manager.getTypeSelector(); getVariableData()[i].type = myParameterTypeSelectors[i].getSelectedType(); // reverse order } myTypeRendererCombo = new JComboBox(getVariableData()); myTypeRendererCombo.setOpaque(true); myTypeRendererCombo.setBorder(null); myTypeRendererCombo.setRenderer( new ListCellRendererWrapper<VariableData>() { @Override public void customize( JList list, VariableData value, int index, boolean selected, boolean hasFocus) { if (value != null) { setText(value.type.getPresentableText()); } } }); final TableColumn typeColumn = myTable.getColumnModel().getColumn(MyTableModel.PARAMETER_TYPE_COLUMN); typeColumn.setCellEditor( new AbstractTableCellEditor() { TypeSelector myCurrentSelector; final JBComboBoxTableCellEditorComponent myEditorComponent = new JBComboBoxTableCellEditorComponent(); @Nullable public Object getCellEditorValue() { return myEditorComponent.getEditorValue(); } public Component getTableCellEditorComponent( final JTable table, final Object value, final boolean isSelected, final int row, final int column) { myEditorComponent.setCell(table, row, column); myEditorComponent.setOptions(myParameterTypeSelectors[row].getTypes()); myEditorComponent.setDefaultValue(getVariableData()[row].type); myEditorComponent.setToString( new Function<Object, String>() { @Override public String fun(Object o) { return ((PsiType) o).getPresentableText(); } }); myCurrentSelector = myParameterTypeSelectors[row]; return myEditorComponent; } }); myTable .getColumnModel() .getColumn(MyTableModel.PARAMETER_TYPE_COLUMN) .setCellRenderer( new DefaultTableCellRenderer() { private JBComboBoxLabel myLabel = new JBComboBoxLabel(); public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { myLabel.setText(String.valueOf(value)); myLabel.setBackground( isSelected ? table.getSelectionBackground() : table.getBackground()); myLabel.setForeground( isSelected ? table.getSelectionForeground() : table.getForeground()); if (isSelected) { myLabel.setSelectionIcon(); } else { myLabel.setRegularIcon(); } return myLabel; } }); myTable.setPreferredScrollableViewportSize(new Dimension(250, myTable.getRowHeight() * 5)); myTable.setShowGrid(false); myTable.setIntercellSpacing(new Dimension(0, 0)); @NonNls final InputMap inputMap = myTable.getInputMap(); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "enable_disable"); @NonNls final ActionMap actionMap = myTable.getActionMap(); actionMap.put( "enable_disable", new AbstractAction() { public void actionPerformed(ActionEvent e) { if (myTable.isEditing()) return; int[] rows = myTable.getSelectedRows(); if (rows.length > 0) { boolean valueToBeSet = false; for (int row : rows) { if (!getVariableData()[row].passAsParameter) { valueToBeSet = true; break; } } for (int row : rows) { getVariableData()[row].passAsParameter = valueToBeSet; } myTableModel.fireTableRowsUpdated(rows[0], rows[rows.length - 1]); TableUtil.selectRows(myTable, rows); } } }); //// F2 should edit the name // inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "edit_parameter_name"); // actionMap.put("edit_parameter_name", new AbstractAction() { // public void actionPerformed(ActionEvent e) { // if (!myTable.isEditing()) { // int row = myTable.getSelectedRow(); // if (row >= 0 && row < myTableModel.getRowCount()) { // TableUtil.editCellAt(myTable, row, MyTableModel.PARAMETER_NAME_COLUMN); // } // } // } // }); //// make ENTER work when the table has focus // inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "invokeImpl"); // actionMap.put("invokeImpl", new AbstractAction() { // public void actionPerformed(ActionEvent e) { // TableCellEditor editor = myTable.getCellEditor(); // if (editor != null) { // editor.stopCellEditing(); // } // else { // doEnterAction(); // } // } // }); // make ESCAPE work when the table has focus actionMap.put( "doCancel", new AbstractAction() { public void actionPerformed(ActionEvent e) { TableCellEditor editor = myTable.getCellEditor(); if (editor != null) { editor.stopCellEditing(); } else { doCancelAction(); } } }); JPanel listPanel = ToolbarDecorator.createDecorator(myTable) .disableAddAction() .disableRemoveAction() .createPanel(); add(listPanel, BorderLayout.CENTER); if (getVariableData().length > 1) { myTable.getSelectionModel().setSelectionInterval(0, 0); } }
@Override protected void fireEditingStopped() { super.fireEditingStopped(); }