public void setCell(DatasetEditorModelCell cell) { if (this.cell != null) updateUserValue(false); this.cell = cell; DatasetEditorModelRow row = cell.getRow(); boolean editable = !row.isDeleted() && row.getModel().isEditable(); editorComponent.setEnabled(editable); editorComponent.setUserValueHolder(cell); Formatter formatter = regionalSettings.getFormatter(); if (cell.getUserValue() instanceof String) { String userValue = (String) cell.getUserValue(); if (userValue.indexOf('\n') > -1) { userValue = userValue.replace('\n', ' '); editorComponent.setEditable(false); } else { editorComponent.setEditable(editable); } editorComponent.setText(userValue); } else { editable = editable && !(cell.getUserValue() instanceof LazyLoadedValue); editorComponent.setEditable(editable); String formattedUserValue = formatter.formatObject(cell.getUserValue()); editorComponent.setText(formattedUserValue); } JTextField valueTextField = editorComponent.getTextField(); valueTextField.setBackground(UIUtil.getTextFieldBackground()); }
public Object getEditorValue() throws ParseException { DBDataType dataType = cell.getColumnInfo().getDataType(); Class clazz = dataType.getTypeClass(); String textValue = editorComponent.getText().trim(); if (textValue.length() > 0) { Object value = getFormatter().parseObject(clazz, textValue); return dataType.getNativeDataType().getDataTypeDefinition().convert(value); } else { return null; } }
@Override public void focusGained(FocusEvent e) { if (e.getOppositeComponent() != null) { JTextField valueTextField = editorComponent.getTextField(); DataEditorSettings settings = cell.getRow().getModel().getSettings(); if (settings.getGeneralSettings().getSelectContentOnCellEdit().value()) { valueTextField.selectAll(); } Rectangle rectangle = new Rectangle(mainPanel.getLocation(), mainPanel.getSize()); parentForm.getColumnsPanel().scrollRectToVisible(rectangle); } }
public DatasetRecordEditorColumnForm( DatasetRecordEditorForm parentForm, DatasetEditorModelCell cell) { this.parentForm = parentForm; final DatasetEditorColumnInfo columnInfo = cell.getColumnInfo(); DBColumn column = columnInfo.getColumn(); DBDataType dataType = column.getDataType(); Project project = column.getProject(); regionalSettings = RegionalSettings.getInstance(project); columnLabel.setIcon(column.getIcon()); columnLabel.setText(column.getName()); dataTypeLabel.setText(dataType.getQualifiedName()); dataTypeLabel.setForeground(UIUtil.getInactiveTextColor()); DBNativeDataType nativeDataType = dataType.getNativeDataType(); if (nativeDataType != null) { DataTypeDefinition dataTypeDefinition = nativeDataType.getDataTypeDefinition(); GenericDataType genericDataType = dataTypeDefinition.getGenericDataType(); DataEditorSettings dataEditorSettings = DataEditorSettings.getInstance(project); long dataLength = dataType.getLength(); if (genericDataType.is(GenericDataType.DATE_TIME, GenericDataType.LITERAL)) { TextFieldWithPopup textFieldWithPopup = new TextFieldWithPopup(project); textFieldWithPopup.setPreferredSize(new Dimension(200, -1)); JTextField valueTextField = textFieldWithPopup.getTextField(); valueTextField.getDocument().addDocumentListener(documentListener); valueTextField.addKeyListener(keyAdapter); valueTextField.addFocusListener(focusListener); if (cell.getRow().getModel().isEditable()) { if (genericDataType == GenericDataType.DATE_TIME) { textFieldWithPopup.createCalendarPopup(false); } if (genericDataType == GenericDataType.LITERAL) { if (dataLength > 20 && !column.isPrimaryKey() && !column.isForeignKey()) textFieldWithPopup.createTextAreaPopup(false); DataEditorValueListPopupSettings valueListPopupSettings = dataEditorSettings.getValueListPopupSettings(); if (column.isForeignKey() || (dataLength <= valueListPopupSettings.getDataLengthThreshold() && (!column.isSinglePrimaryKey() || valueListPopupSettings.isActiveForPrimaryKeyColumns()))) { ListPopupValuesProvider valuesProvider = new ListPopupValuesProvider() { public List<String> getValues() { return columnInfo.getPossibleValues(); } }; textFieldWithPopup.createValuesListPopup(valuesProvider, false); } } } editorComponent = textFieldWithPopup; } else if (genericDataType.is(GenericDataType.BLOB, GenericDataType.CLOB)) { editorComponent = new TextFieldWithTextEditor(project); } else { editorComponent = new BasicDataEditorComponent(); } } else { editorComponent = new BasicDataEditorComponent(); editorComponent.setEnabled(false); editorComponent.setEditable(false); } valueFieldPanel.add((Component) editorComponent, BorderLayout.CENTER); editorComponent.getTextField().setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); setCell(cell); }
private Formatter getFormatter() { Project project = cell.getRow().getModel().getDataset().getProject(); return Formatter.getInstance(project); }