use of org.eclipse.swt.dnd.Clipboard in project GT by Tencent.
the class CopySelectedItemsFromTableViewAction method run.
@Override
public void run() {
StringBuffer sb = getContents();
clipboard = new Clipboard(Display.getCurrent());
Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
clipboard.setContents(new String[] { sb.toString() }, transfers);
}
use of org.eclipse.swt.dnd.Clipboard in project dbeaver by dbeaver.
the class GISLeafletViewer method updateToolbar.
private void updateToolbar() {
toolBarManager.removeAll();
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_open, DBeaverIcons.getImageDescriptor(UIIcon.BROWSER)) {
@Override
public void run() {
UIUtils.launchProgram(scriptFile.getAbsolutePath());
}
});
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_copy_as, DBeaverIcons.getImageDescriptor(UIIcon.PICTURE)) {
@Override
public void run() {
Image image = new Image(Display.getDefault(), browser.getBounds());
GC gc = new GC(image);
try {
browser.print(gc);
} finally {
gc.dispose();
}
ImageTransfer imageTransfer = ImageTransfer.getInstance();
Clipboard clipboard = new Clipboard(Display.getCurrent());
clipboard.setContents(new Object[] { image.getImageData() }, new Transfer[] { imageTransfer });
}
});
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_save_as, DBeaverIcons.getImageDescriptor(UIIcon.PICTURE_SAVE)) {
@Override
public void run() {
final Shell shell = browser.getShell();
FileDialog saveDialog = new FileDialog(shell, SWT.SAVE);
String[] extensions = new String[SUPPORTED_FORMATS.length];
String[] filterNames = new String[SUPPORTED_FORMATS.length];
for (int i = 0; i < SUPPORTED_FORMATS.length; i++) {
extensions[i] = "*." + SUPPORTED_FORMATS[i];
filterNames[i] = SUPPORTED_FORMATS[i].toUpperCase() + " (*." + SUPPORTED_FORMATS[i] + ")";
}
saveDialog.setFilterExtensions(extensions);
saveDialog.setFilterNames(filterNames);
String filePath = DialogUtils.openFileDialog(saveDialog);
if (filePath == null) {
return;
}
int imageType = SWT.IMAGE_BMP;
{
String filePathLower = filePath.toLowerCase();
if (filePathLower.endsWith(".png")) {
imageType = SWT.IMAGE_PNG;
} else if (filePathLower.endsWith(".gif")) {
imageType = SWT.IMAGE_GIF;
}
}
Image image = new Image(Display.getDefault(), browser.getBounds());
GC gc = new GC(image);
try {
browser.print(gc);
} finally {
gc.dispose();
}
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[1];
imageLoader.data[0] = image.getImageData();
File outFile = new File(filePath);
try (OutputStream fos = new FileOutputStream(outFile)) {
imageLoader.save(fos, imageType);
} catch (IOException e) {
DBWorkbench.getPlatformUI().showError("Image save error", "Error saving as picture", e);
}
UIUtils.launchProgram(outFile.getAbsolutePath());
}
});
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_print, DBeaverIcons.getImageDescriptor(UIIcon.PRINT)) {
@Override
public void run() {
GC gc = new GC(browser.getDisplay());
try {
browser.execute("javascript:window.print();");
} finally {
gc.dispose();
}
}
});
toolBarManager.add(new Separator());
Action crsSelectorAction = new SelectCRSAction(this);
toolBarManager.add(ActionUtils.makeActionContribution(crsSelectorAction, true));
Action tilesSelectorAction = new SelectTilesAction(this);
toolBarManager.add(ActionUtils.makeActionContribution(tilesSelectorAction, true));
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_flip, Action.AS_CHECK_BOX) {
{
setToolTipText(GISMessages.panel_leaflet_viewer_tool_bar_action_tool_tip_text_flip);
setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.LINK_TO_EDITOR));
}
@Override
public boolean isChecked() {
return flipCoordinates;
}
@Override
public void run() {
flipCoordinates = !flipCoordinates;
try {
reloadGeometryData(lastValue, true);
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError("Render error", "Error rendering geometry", e);
}
saveAttributeSettings();
updateToolbar();
}
});
toolBarManager.add(new Separator());
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_show_hide, Action.AS_CHECK_BOX) {
{
setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.PALETTE));
}
@Override
public boolean isChecked() {
return toolsVisible;
}
@Override
public void run() {
toolsVisible = !toolsVisible;
updateControlsVisibility();
updateToolbar();
}
});
toolBarManager.update(true);
}
use of org.eclipse.swt.dnd.Clipboard in project hale by halestudio.
the class InstanceExplorer method createControls.
/**
* @see InstanceViewer#createControls(Composite, SchemaSpaceID)
*/
@Override
public void createControls(Composite parent, SchemaSpaceID schemaSpace) {
main = new Composite(parent, SWT.NONE);
main.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).create());
// selector composite
selectorComposite = new Composite(main, SWT.NONE);
selectorComposite.setLayoutData(GridDataFactory.swtDefaults().create());
selectorComposite.setLayout(GridLayoutFactory.fillDefaults().create());
// viewer composite
Composite viewerComposite = new Composite(main, SWT.NONE);
viewerComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
TreeColumnLayout layout = new TreeColumnLayout();
viewerComposite.setLayout(layout);
viewer = new TreeViewer(viewerComposite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
viewer.getTree().setLinesVisible(true);
// set content provider
viewer.setContentProvider(new InstanceContentProvider());
viewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS);
// TODO set label provider?
// add definition columns
TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.LEFT);
column.getColumn().setText("Definition");
column.setLabelProvider(new TreeColumnViewerLabelProvider(new PairLabelProvider(true, new DefinitionMetaLabelProvider(viewer, false, true))));
layout.setColumnData(column.getColumn(), new ColumnWeightData(1));
// add value column
column = new TreeViewerColumn(viewer, SWT.LEFT);
column.getColumn().setText("Value");
final InstanceValueLabelProvider instanceLabelProvider = new InstanceValueLabelProvider();
column.setLabelProvider(instanceLabelProvider);
// new PairLabelProvider(false, new LabelProvider())));
ColumnViewerToolTipSupport.enableFor(viewer);
layout.setColumnData(column.getColumn(), new ColumnWeightData(1));
MetadataActionProvider maep = new MetadataExploreActionProvider(viewer);
maep.setup();
// Add an editor for copying instance values
editor = new TreeEditor(viewer.getTree());
editor.horizontalAlignment = SWT.RIGHT;
viewer.getTree().addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
final ViewerCell cell = viewer.getCell(new Point(e.x, e.y));
// Selected cell changed?
if (cell == null || editor.getItem() != cell.getItem() || editor.getColumn() != cell.getColumnIndex()) {
// Clean up any previous editor control
Control oldEditor = editor.getEditor();
if (oldEditor != null) {
oldEditor.dispose();
editor.setEditor(null, null, 0);
}
}
// No valid selected cell
if (cell == null || cell.getColumnIndex() == 0) {
return;
}
// cell didn't change
if ((editor.getItem() == cell.getItem() && editor.getColumn() == cell.getColumnIndex())) {
return;
}
// determine instance value
Object value = ((Pair<?, ?>) cell.getViewerRow().getTreePath().getLastSegment()).getSecond();
if (value instanceof Instance) {
value = ((Instance) value).getValue();
}
// copy button
if (value != null) {
final String textValue = value.toString();
if (!textValue.isEmpty()) {
// empty string invalid for
// clipboard
Button button = new Button(viewer.getTree(), SWT.PUSH | SWT.FLAT);
button.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_COPY));
button.setToolTipText("Copy string value");
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// copy content to clipboard
Clipboard clipBoard = new Clipboard(Display.getCurrent());
clipBoard.setContents(new Object[] { textValue }, new Transfer[] { TextTransfer.getInstance() });
clipBoard.dispose();
}
});
// calculate editor size
Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
editor.minimumHeight = size.y;
editor.minimumWidth = size.x;
editor.setEditor(button, (TreeItem) cell.getItem(), cell.getColumnIndex());
}
}
}
});
update();
}
use of org.eclipse.swt.dnd.Clipboard in project hale by halestudio.
the class StackTraceErrorDialog method copyToClipboard.
/**
* Copies the stack trace to the clipboard
*/
protected void copyToClipboard() {
if (_clipboard != null) {
_clipboard.dispose();
}
String stackTrace = stackTraceToString(_status.getException());
_clipboard = new Clipboard(_list.getDisplay());
_clipboard.setContents(new Object[] { stackTrace }, new Transfer[] { TextTransfer.getInstance() });
}
use of org.eclipse.swt.dnd.Clipboard in project pentaho-kettle by pentaho.
the class StyledTextComp method checkPaste.
// Check if something is stored inside the Clipboard
private boolean checkPaste() {
try {
Clipboard clipboard = new Clipboard(xParent.getDisplay());
TextTransfer transfer = TextTransfer.getInstance();
String text = (String) clipboard.getContents(transfer);
if (text != null && text.length() > 0) {
return true;
} else {
return false;
}
} catch (Exception e) {
return false;
}
}
Aggregations