public static IValueEditor openContentEditor(@NotNull IValueController controller) { Object value = controller.getValue(); IValueController.EditType binaryEditType = IValueController.EditType.valueOf( controller .getExecutionContext() .getDataSource() .getContainer() .getPreferenceStore() .getString(DBeaverPreferences.RESULT_SET_BINARY_EDITOR_TYPE)); if (binaryEditType != IValueController.EditType.EDITOR && value instanceof DBDContentCached) { // Use string editor for cached content return new TextViewDialog(controller); } else if (value instanceof DBDContent) { DBDContent content = (DBDContent) value; boolean isText = ContentUtils.isTextContent(content); List<ContentEditorPart> parts = new ArrayList<>(); if (isText) { parts.add(new ContentTextEditorPart()); if (ContentUtils.isXML(content)) { parts.add(new ContentXMLEditorPart()); } } else { parts.add(new ContentBinaryEditorPart()); parts.add(new ContentTextEditorPart()); parts.add(new ContentImageEditorPart()); } return ContentEditor.openEditor( controller, parts.toArray(new ContentEditorPart[parts.size()])); } else { controller.showMessage(CoreMessages.model_jdbc_unsupported_content_value_type_, true); return null; } }
@Override public void contributeProperties( @NotNull DBPPropertyManager propertySource, @NotNull IValueController controller) { super.contributeProperties(propertySource, controller); try { Object value = controller.getValue(); if (value instanceof DBDContent) { propertySource.addProperty( PROP_CATEGORY_CONTENT, "content_type", //$NON-NLS-1$ CoreMessages.model_jdbc_content_type, ((DBDContent) value).getContentType()); final long contentLength = ((DBDContent) value).getContentLength(); if (contentLength >= 0) { propertySource.addProperty( PROP_CATEGORY_CONTENT, "content_length", //$NON-NLS-1$ CoreMessages.model_jdbc_content_length, contentLength); } } } catch (Exception e) { log.warn("Can't extract CONTENT value information", e); // $NON-NLS-1$ } }
@Override protected Control createDialogArea(Composite parent) { IValueController valueController = getValueController(); Object value = valueController.getValue(); Composite dialogGroup = (Composite) super.createDialogArea(parent); Composite panel = UIUtils.createPlaceholder(dialogGroup, 3); panel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); int style = SWT.BORDER; if (valueController.isReadOnly()) { style |= SWT.READ_ONLY; } UIUtils.createControlLabel(panel, "Time") .setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); DBDDataFormatter formatter = helper.getFormatter(valueController, valueController.getValueType()); timeEditor = new CustomTimeEditor(panel, style, formatter); GridData gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalAlignment = GridData.CENTER; timeEditor.getControl().setLayoutData(gd); primeEditorValue(value); Button button = UIUtils.createPushButton(panel, "Set Current", null); button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); button.setEnabled(!valueController.isReadOnly()); button.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { primeEditorValue(new Date()); } }); return dialogGroup; }
@Override public IValueEditor createEditor(@NotNull final IValueController controller) throws DBException { switch (controller.getEditType()) { case INLINE: // Open inline/panel editor if (controller.getValue() instanceof DBDContentCached) { return new ContentInlineEditor(controller); } else { return null; } case EDITOR: return openContentEditor(controller); case PANEL: Object value = controller.getValue(); if (value instanceof DBDContent && ContentUtils.isXML((DBDContent) value)) { return new XMLPanelEditor(controller); } else { return new ContentPanelEditor(controller); } default: return null; } }
public static void contributeContentActions( @NotNull IContributionManager manager, @NotNull final IValueController controller) throws DBCException { if (controller.getValue() instanceof DBDContent && !((DBDContent) controller.getValue()).isNull()) { manager.add( new Action( CoreMessages.model_jdbc_save_to_file_, DBeaverIcons.getImageDescriptor(UIIcon.SAVE_AS)) { @Override public void run() { DialogUtils.saveToFile(controller); } }); } manager.add( new Action( CoreMessages.model_jdbc_load_from_file_, DBeaverIcons.getImageDescriptor(UIIcon.LOAD)) { @Override public void run() { DialogUtils.loadFromFile(controller); } }); }