use of org.eclipse.swt.custom.StyledText in project cubrid-manager by CUBRID.
the class LongTextCellPopupDialog method createDialogArea.
/**
* Create dialog area
*
* @param parent Composite
* @return Control
*/
protected Control createDialogArea(Composite parent) {
Composite parentComp = (Composite) super.createDialogArea(parent);
Composite composite = new Composite(parentComp, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout();
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
Composite btnComposite = new Composite(composite, SWT.NONE);
RowLayout rowLayout = new RowLayout();
rowLayout.spacing = 5;
btnComposite.setLayout(rowLayout);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalAlignment = GridData.BEGINNING;
gridData.horizontalSpan = 2;
btnComposite.setLayoutData(gridData);
setNullBtn = new Button(btnComposite, SWT.CHECK);
{
setNullBtn.setText(Messages.btnSetNull);
setNullBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
changeBtnStatus();
}
});
}
importBtn = new Button(btnComposite, SWT.PUSH);
importBtn.setText(Messages.btnImport);
importBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
File file = FileDialogUtils.getImportedFile(getShell(), new String[] { "*.txt", "*.sql", "*.csv" });
if (null != file && file.getName().length() > 0) {
final String charsetName = fileCharsetCombo.getText();
try {
"".getBytes(charsetName);
} catch (UnsupportedEncodingException e) {
CommonUITool.openErrorBox(Messages.errCharset);
return;
}
try {
String textValue = FileUtil.readData(file.getPath(), charsetName);
columnValueText.setText(textValue);
currValue = textValue;
} catch (IOException ex) {
CommonUITool.openErrorBox(ex.getMessage());
}
}
}
});
exportBtn = new Button(btnComposite, SWT.PUSH);
exportBtn.setText(Messages.btnExport);
exportBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (columnValueText.getText().length() == 0) {
CommonUITool.openWarningBox(Messages.noDataExport);
return;
}
String charsetName = fileCharsetCombo.getText();
try {
"".getBytes(charsetName);
} catch (UnsupportedEncodingException e) {
CommonUITool.openErrorBox(Messages.errCharset);
return;
}
File file = FileDialogUtils.getDataExportedFile(getShell(), new String[] { "*.*" }, new String[] { "*.*" }, null);
if (null != file && file.getName().length() > 0) {
exportData(file.getPath());
}
}
});
fileCharsetCombo = new Combo(btnComposite, SWT.NONE);
{
fileCharsetCombo.setItems(QueryOptions.getAllCharset(null));
String charset = StringUtil.getDefaultCharset();
fileCharsetCombo.setText(charset);
}
columnValueText = new StyledText(composite, SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
if (value.hasLoadAll()) {
CommonUITool.registerContextMenu(columnValueText, isEditable);
}
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 280;
gd.widthHint = 500;
columnValueText.setLayoutData(gd);
initValue();
return composite;
}
use of org.eclipse.swt.custom.StyledText in project dbeaver by serge-rider.
the class TextViewDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite dialogGroup = (Composite) super.createDialogArea(parent);
ReferenceValueEditor referenceValueEditor = new ReferenceValueEditor(getValueController(), this);
boolean isForeignKey = referenceValueEditor.isReferenceValue();
Label label = new Label(dialogGroup, SWT.NONE);
label.setText(CoreMessages.dialog_data_label_value);
boolean readOnly = getValueController().isReadOnly();
boolean useHex = !isForeignKey;
final DBSTypedObject valueType = getValueController().getValueType();
long maxSize = valueType.getMaxLength();
if (useHex) {
editorContainer = new CTabFolder(dialogGroup, SWT.FLAT | SWT.TOP);
editorContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
lengthLabel = new Label(editorContainer, SWT.RIGHT);
lengthLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
editorContainer.setTopRight(lengthLabel, SWT.FILL);
}
int selectedType = 0;
if (getDialogSettings().get(VALUE_TYPE_SELECTOR) != null) {
selectedType = getDialogSettings().getInt(VALUE_TYPE_SELECTOR);
}
{
int style = SWT.NONE;
if (readOnly) {
style |= SWT.READ_ONLY;
}
if (useHex) {
style |= SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP;
} else {
// Use border only for plain text editor, otherwise tab folder's border will be used
style |= SWT.BORDER;
}
textEdit = new StyledText(useHex ? editorContainer : dialogGroup, style);
textEdit.setMargins(3, 3, 3, 3);
if (maxSize > 0 && valueType.getDataKind() == DBPDataKind.STRING) {
textEdit.setTextLimit((int) maxSize);
}
if (readOnly) {
//textEdit.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
}
GridData gd = new GridData(isForeignKey ? GridData.FILL_HORIZONTAL : GridData.FILL_BOTH);
gd.widthHint = 300;
if (!isForeignKey) {
gd.heightHint = 200;
gd.grabExcessVerticalSpace = true;
}
textEdit.setLayoutData(gd);
textEdit.setFocus();
textEdit.setEditable(!readOnly);
textEdit.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
dirty = true;
updateValueLength();
}
});
UIUtils.fillDefaultStyledTextContextMenu(textEdit);
if (useHex) {
CTabItem item = new CTabItem(editorContainer, SWT.NO_FOCUS);
item.setText("Text");
item.setImage(DBeaverIcons.getImage(DBIcon.TYPE_TEXT));
item.setControl(textEdit);
}
}
Point minSize = null;
if (useHex) {
hexEditControl = new HexEditControl(editorContainer, readOnly ? SWT.READ_ONLY : SWT.NONE, 6, 8);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 200;
gd.minimumWidth = hexEditControl.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
hexEditControl.setLayoutData(gd);
minSize = hexEditControl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
minSize.x += 50;
minSize.y += 50;
CTabItem item = new CTabItem(editorContainer, SWT.NO_FOCUS);
item.setText("Hex");
item.setImage(DBeaverIcons.getImage(DBIcon.TYPE_BINARY));
item.setControl(hexEditControl);
if (selectedType >= editorContainer.getItemCount()) {
selectedType = 0;
}
editorContainer.setSelection(selectedType);
editorContainer.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
getDialogSettings().put(VALUE_TYPE_SELECTOR, editorContainer.getSelectionIndex());
}
});
hexEditControl.addListener(SWT.Modify, new Listener() {
@Override
public void handleEvent(Event event) {
dirty = true;
}
});
updateValueLength();
}
primeEditorValue(getValueController().getValue());
if (isForeignKey) {
referenceValueEditor.createEditorSelector(dialogGroup);
}
if (minSize != null) {
// Set default size as minimum
getShell().setMinimumSize(minSize);
}
return dialogGroup;
}
use of org.eclipse.swt.custom.StyledText in project dbeaver by serge-rider.
the class XMLPanelEditor method createControl.
@Override
public StyledText createControl(IValueController valueController) {
this.valueController = valueController;
this.subSite = new SubEditorSite(valueController.getValueSite());
editor = new XMLEditor();
try {
editor.init(subSite, StringEditorInput.EMPTY_INPUT);
} catch (PartInitException e) {
valueController.showMessage(e.getMessage(), DBPMessageType.ERROR);
return new StyledText(valueController.getEditPlaceholder(), SWT.NONE);
}
editor.createPartControl(valueController.getEditPlaceholder());
ContentPanelEditor.setEditorSettings(editor.getEditorControl());
return editor.getEditorControl();
}
use of org.eclipse.swt.custom.StyledText in project cubrid-manager by CUBRID.
the class TextEditorFindReplaceMediator method focusGained.
/**
* When text editor focus gained, update the find dialog's buttons.
*
* @param event FocusEnent
*/
public void focusGained(FocusEvent event) {
if (event.widget instanceof StyledText) {
StyledText text = (StyledText) event.widget;
setCurrentTextEditor((TextViewer) text.getData(SQL_EDITOR_FLAG));
if (null == dialog) {
return;
}
dialog.updateButtons();
}
}
use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.
the class EncodingChangeTests method testAInvalidEncoding.
@Test
public void testAInvalidEncoding() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
fFile.setCharset("nonexistent", null);
} catch (CoreException e2) {
fail();
}
try {
fEditor = IDE.openEditor(page, fFile);
if (fEditor instanceof TextEditor) {
TextEditor editor = (TextEditor) fEditor;
Accessor accessor = new Accessor(editor, StatusTextEditor.class);
while (editor.getSite().getShell().getDisplay().readAndDispatch()) {
}
ITextFileBuffer fileBuffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
DefaultEncodingSupport encodingSupport = (DefaultEncodingSupport) editor.getAdapter(IEncodingSupport.class);
String expected = encodingSupport.getStatusMessage(fileBuffer.getStatus());
Composite composite = (Composite) accessor.get("fStatusControl");
ScrolledComposite scrolledComposite = (ScrolledComposite) composite.getChildren()[0];
StyledText statusText = (StyledText) ((Composite) scrolledComposite.getContent()).getChildren()[5];
String actual = statusText.getText();
assertEquals(expected, actual);
} else
fail();
} catch (PartInitException e) {
fail();
}
}
Aggregations