use of org.eclipse.swt.dnd.Transfer in project knime-core by knime.
the class WorkflowCoachView method createPartControl.
/**
* {@inheritDoc}
*/
@Override
public void createPartControl(final Composite parent) {
m_viewer = new TableViewer(parent, SWT.V_SCROLL | SWT.FULL_SELECTION) {
@Override
public ISelection getSelection() {
ISelection sel = super.getSelection();
if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) sel;
if (ss.getFirstElement() instanceof NodeRecommendation[]) {
// turn node recommendation selection into a node template selection
NodeRecommendation[] nps = (NodeRecommendation[]) ss.getFirstElement();
return new StructuredSelection(new Object[] { getNonNullEntry(nps).getNodeTemplate() });
}
}
return sel;
}
};
getSite().setSelectionProvider(m_viewer);
m_viewer.setComparator(new TableColumnSorter(m_viewer));
Table table = m_viewer.getTable();
// drag & drop
Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
m_viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new WorkflowCoachDragSource(this));
// column configuration
TableColumn column = new TableColumn(table, SWT.LEFT, 0);
column.setText("Recommended Nodes");
column.setToolTipText("Nodes recommended to use next (e.g. based on the currently selected node).");
column.setWidth(200);
table.setHeaderVisible(true);
table.setLinesVisible(false);
m_viewer.setContentProvider(new WorkflowCoachContentProvider());
m_viewer.setLabelProvider(new WorkflowCoachLabelProvider());
m_viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
getViewSite().getPage().addSelectionListener(this);
hookDoubleClickAction();
// actions
IToolBarManager toolbarMGR = getViewSite().getActionBars().getToolBarManager();
toolbarMGR.add(new ConfigureAction(m_viewer));
updateInput("Waiting for node repository to be loaded ...");
m_loadState.set(LoadState.LoadingNodes);
Job nodesLoader = new KNIMEJob("Workflow Coach loader", FrameworkUtil.getBundle(getClass())) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
// wait until the repository is fully loaded
RepositoryManager.INSTANCE.getRoot();
if (m_loadState.get() == LoadState.Disposed) {
return Status.CANCEL_STATUS;
} else if (monitor.isCanceled()) {
m_loadState.set(LoadState.Initizalized);
return Status.CANCEL_STATUS;
} else {
// check for update if necessary
updateInput("Loading recommendations...");
checkForStatisticUpdates();
}
m_loadState.set(LoadState.Initizalized);
NodeRecommendationManager.getInstance().addUpdateListener(WorkflowCoachView.this);
updateFrequencyColumnHeadersAndToolTips();
updateInput(StructuredSelection.EMPTY);
return Status.OK_STATUS;
}
};
nodesLoader.setSystem(true);
nodesLoader.schedule();
// if the 'send anonymous statistics'-property has been changed, try updating the workflow coach
KNIMECorePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(e -> {
if (e.getProperty().equals(HeadlessPreferencesConstants.P_SEND_ANONYMOUS_STATISTICS)) {
if (e.getNewValue().equals(Boolean.TRUE)) {
// enable the community recommendations
PREFS.setValue(WorkflowCoachPreferenceInitializer.P_COMMUNITY_NODE_TRIPLE_PROVIDER, true);
try {
PREFS.save();
} catch (Exception e1) {
throw new RuntimeException(e1);
}
updateInput(StructuredSelection.EMPTY);
}
}
});
}
use of org.eclipse.swt.dnd.Transfer in project yamcs-studio by yamcs.
the class CopyEventDetailsHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection sel = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
if (sel != null && sel instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) sel;
String property = event.getParameter(EventLog.CMDPARAM_EVENT_PROPERTY);
StringBuilder text = new StringBuilder();
Iterator<?> it = selection.iterator();
while (it.hasNext()) {
Event rec = (Event) it.next();
switch(property) {
case PARAM_MESSAGE:
text.append(rec.getMessage());
break;
case PARAM_SOURCE:
text.append(rec.getSource());
break;
case PARAM_TYPE:
text.append(rec.getSource());
break;
case PARAM_GENTIME:
text.append(rec.getGenerationTimeUTC());
break;
case PARAM_RECTIME:
text.append(rec.getReceptionTimeUTC());
break;
case PARAM_SEQNO:
text.append(rec.getSeqNumber());
break;
case PARAM_SEVERITY:
text.append(rec.getSeverity());
break;
default:
throw new IllegalStateException("Unexpected property: " + property);
}
if (it.hasNext()) {
text.append("\n");
}
}
Display display = Display.getCurrent();
Clipboard clipboard = new Clipboard(display);
Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
clipboard.setContents(new Object[] { text.toString() }, transfers);
clipboard.dispose();
}
return null;
}
use of org.eclipse.swt.dnd.Transfer in project yamcs-studio by yamcs.
the class CopyEventHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection sel = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
if (sel != null && sel instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) sel;
StringBuilder text = new StringBuilder("Severity\tMessage\tType\tSource\tGeneration\tReception\tSequence Number\n");
Iterator<?> it = selection.iterator();
while (it.hasNext()) {
Event rec = (Event) it.next();
text.append(rec.getSeverity()).append("\t").append(rec.getMessage()).append("\t").append(rec.getType()).append("\t").append(rec.getSource()).append("\t").append(rec.getGenerationTimeUTC()).append("\t").append(rec.getReceptionTimeUTC()).append("\t").append(rec.getSeqNumber()).append("\n");
}
Display display = Display.getCurrent();
Clipboard clipboard = new Clipboard(display);
Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
clipboard.setContents(new Object[] { text.toString() }, transfers);
clipboard.dispose();
}
return null;
}
use of org.eclipse.swt.dnd.Transfer in project eclipse.platform.swt by eclipse.
the class ClipboardExample method createFileTransfer.
void createFileTransfer(Composite copyParent, Composite pasteParent) {
// File Transfer
Label l = new Label(copyParent, SWT.NONE);
// $NON-NLS-1$
l.setText("FileTransfer:");
GridData data = new GridData();
data.verticalSpan = 3;
l.setLayoutData(data);
final Table copyFileTable = new Table(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
data = new GridData(GridData.FILL_BOTH);
data.widthHint = HSIZE;
data.heightHint = VSIZE;
data.verticalSpan = 3;
copyFileTable.setLayoutData(data);
Button b = new Button(copyParent, SWT.PUSH);
b.setText("Select file(s)");
b.addSelectionListener(widgetSelectedAdapter(e -> {
FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
String result = dialog.open();
if (result != null && result.length() > 0) {
String path = dialog.getFilterPath();
String[] names = dialog.getFileNames();
for (String name : names) {
TableItem item = new TableItem(copyFileTable, SWT.NONE);
item.setText(path + File.separator + name);
}
}
}));
b = new Button(copyParent, SWT.PUSH);
b.setText("Select directory");
b.addSelectionListener(widgetSelectedAdapter(e -> {
DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN);
String result = dialog.open();
if (result != null && result.length() > 0) {
// copyFileTable.removeAll();
TableItem item = new TableItem(copyFileTable, SWT.NONE);
item.setText(result);
}
}));
b = new Button(copyParent, SWT.PUSH);
b.setText("Copy");
b.addSelectionListener(widgetSelectedAdapter(e -> {
TableItem[] items = copyFileTable.getItems();
if (items.length > 0) {
status.setText("");
String[] itemsData = new String[items.length];
for (int i = 0; i < itemsData.length; i++) {
itemsData[i] = items[i].getText();
}
clipboard.setContents(new Object[] { itemsData }, new Transfer[] { FileTransfer.getInstance() });
} else {
status.setText("No file to copy");
}
}));
l = new Label(pasteParent, SWT.NONE);
// $NON-NLS-1$
l.setText("FileTransfer:");
final Table pasteFileTable = new Table(pasteParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
data = new GridData(GridData.FILL_BOTH);
data.widthHint = HSIZE;
data.heightHint = VSIZE;
pasteFileTable.setLayoutData(data);
b = new Button(pasteParent, SWT.PUSH);
b.setText("Paste");
b.addSelectionListener(widgetSelectedAdapter(e -> {
String[] textData = (String[]) clipboard.getContents(FileTransfer.getInstance());
if (textData != null && textData.length > 0) {
status.setText("");
pasteFileTable.removeAll();
for (String element : textData) {
TableItem item = new TableItem(pasteFileTable, SWT.NONE);
item.setText(element);
}
} else {
status.setText("No file to paste");
}
}));
}
use of org.eclipse.swt.dnd.Transfer in project eclipse.platform.swt by eclipse.
the class ClipboardExample method createImageTransfer.
void createImageTransfer(Composite copyParent, Composite pasteParent) {
final Image[] copyImage = new Image[] { null };
Label l = new Label(copyParent, SWT.NONE);
// $NON-NLS-1$
l.setText("ImageTransfer:");
GridData data = new GridData();
data.verticalSpan = 2;
l.setLayoutData(data);
final Canvas copyImageCanvas = new Canvas(copyParent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
data = new GridData(GridData.FILL_BOTH);
data.verticalSpan = 2;
data.widthHint = HSIZE;
data.heightHint = VSIZE;
copyImageCanvas.setLayoutData(data);
final Point copyOrigin = new Point(0, 0);
final ScrollBar copyHBar = copyImageCanvas.getHorizontalBar();
copyHBar.setEnabled(false);
copyHBar.addListener(SWT.Selection, e -> {
if (copyImage[0] != null) {
int hSelection = copyHBar.getSelection();
int destX = -hSelection - copyOrigin.x;
Rectangle rect = copyImage[0].getBounds();
copyImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false);
copyOrigin.x = -hSelection;
}
});
final ScrollBar copyVBar = copyImageCanvas.getVerticalBar();
copyVBar.setEnabled(false);
copyVBar.addListener(SWT.Selection, e -> {
if (copyImage[0] != null) {
int vSelection = copyVBar.getSelection();
int destY = -vSelection - copyOrigin.y;
Rectangle rect = copyImage[0].getBounds();
copyImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false);
copyOrigin.y = -vSelection;
}
});
copyImageCanvas.addListener(SWT.Paint, e -> {
if (copyImage[0] != null) {
GC gc = e.gc;
gc.drawImage(copyImage[0], copyOrigin.x, copyOrigin.y);
Rectangle rect = copyImage[0].getBounds();
Rectangle client = copyImageCanvas.getClientArea();
int marginWidth = client.width - rect.width;
if (marginWidth > 0) {
gc.fillRectangle(rect.width, 0, marginWidth, client.height);
}
int marginHeight = client.height - rect.height;
if (marginHeight > 0) {
gc.fillRectangle(0, rect.height, client.width, marginHeight);
}
gc.dispose();
}
});
Button openButton = new Button(copyParent, SWT.PUSH);
openButton.setText("Open Image");
openButton.addSelectionListener(widgetSelectedAdapter(e -> {
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
dialog.setText("Open an image file or cancel");
String string = dialog.open();
if (string != null) {
if (copyImage[0] != null) {
System.out.println("CopyImage");
copyImage[0].dispose();
}
copyImage[0] = new Image(e.display, string);
copyVBar.setEnabled(true);
copyHBar.setEnabled(true);
copyOrigin.x = 0;
copyOrigin.y = 0;
Rectangle rect = copyImage[0].getBounds();
Rectangle client = copyImageCanvas.getClientArea();
copyHBar.setMaximum(rect.width);
copyVBar.setMaximum(rect.height);
copyHBar.setThumb(Math.min(rect.width, client.width));
copyVBar.setThumb(Math.min(rect.height, client.height));
copyImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true);
copyVBar.setSelection(0);
copyHBar.setSelection(0);
copyImageCanvas.redraw();
}
}));
Button b = new Button(copyParent, SWT.PUSH);
b.setText("Copy");
b.addSelectionListener(widgetSelectedAdapter(e -> {
if (copyImage[0] != null) {
status.setText("");
// Fetch ImageData at current zoom and save in the clip-board.
clipboard.setContents(new Object[] { copyImage[0].getImageDataAtCurrentZoom() }, new Transfer[] { ImageTransfer.getInstance() });
} else {
status.setText("No image to copy");
}
}));
final Image[] pasteImage = new Image[] { null };
l = new Label(pasteParent, SWT.NONE);
l.setText("ImageTransfer:");
final Canvas pasteImageCanvas = new Canvas(pasteParent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
data = new GridData(GridData.FILL_BOTH);
data.widthHint = HSIZE;
data.heightHint = VSIZE;
pasteImageCanvas.setLayoutData(data);
final Point pasteOrigin = new Point(0, 0);
final ScrollBar pasteHBar = pasteImageCanvas.getHorizontalBar();
pasteHBar.setEnabled(false);
pasteHBar.addListener(SWT.Selection, e -> {
if (pasteImage[0] != null) {
int hSelection = pasteHBar.getSelection();
int destX = -hSelection - pasteOrigin.x;
Rectangle rect = pasteImage[0].getBounds();
pasteImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false);
pasteOrigin.x = -hSelection;
}
});
final ScrollBar pasteVBar = pasteImageCanvas.getVerticalBar();
pasteVBar.setEnabled(false);
pasteVBar.addListener(SWT.Selection, e -> {
if (pasteImage[0] != null) {
int vSelection = pasteVBar.getSelection();
int destY = -vSelection - pasteOrigin.y;
Rectangle rect = pasteImage[0].getBounds();
pasteImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false);
pasteOrigin.y = -vSelection;
}
});
pasteImageCanvas.addListener(SWT.Paint, e -> {
if (pasteImage[0] != null) {
GC gc = e.gc;
gc.drawImage(pasteImage[0], pasteOrigin.x, pasteOrigin.y);
Rectangle rect = pasteImage[0].getBounds();
Rectangle client = pasteImageCanvas.getClientArea();
int marginWidth = client.width - rect.width;
if (marginWidth > 0) {
gc.fillRectangle(rect.width, 0, marginWidth, client.height);
}
int marginHeight = client.height - rect.height;
if (marginHeight > 0) {
gc.fillRectangle(0, rect.height, client.width, marginHeight);
}
}
});
b = new Button(pasteParent, SWT.PUSH);
b.setText("Paste");
b.addSelectionListener(widgetSelectedAdapter(e -> {
ImageData imageData = (ImageData) clipboard.getContents(ImageTransfer.getInstance());
if (imageData != null) {
if (pasteImage[0] != null) {
System.out.println("PasteImage");
pasteImage[0].dispose();
}
status.setText("");
// Consume the ImageData at current zoom as-is.
pasteImage[0] = new Image(e.display, new AutoScaleImageDataProvider(imageData));
pasteVBar.setEnabled(true);
pasteHBar.setEnabled(true);
pasteOrigin.x = 0;
pasteOrigin.y = 0;
Rectangle rect = pasteImage[0].getBounds();
Rectangle client = pasteImageCanvas.getClientArea();
pasteHBar.setMaximum(rect.width);
pasteVBar.setMaximum(rect.height);
pasteHBar.setThumb(Math.min(rect.width, client.width));
pasteVBar.setThumb(Math.min(rect.height, client.height));
pasteImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true);
pasteVBar.setSelection(0);
pasteHBar.setSelection(0);
pasteImageCanvas.redraw();
} else {
status.setText("No image to paste");
}
}));
}
Aggregations