本文整理汇总了Java中org.eclipse.swt.dnd.URLTransfer类的典型用法代码示例。如果您正苦于以下问题:Java URLTransfer类的具体用法?Java URLTransfer怎么用?Java URLTransfer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
URLTransfer类属于org.eclipse.swt.dnd包,在下文中一共展示了URLTransfer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTransferType
import org.eclipse.swt.dnd.URLTransfer; //导入依赖的package包/类
Transfer getTransferType(String mime) {
if (mime.equals("text/plain")) {
return TextTransfer.getInstance();
}
if (mime.equals("text/rtf")) {
return RTFTransfer.getInstance();
}
if (mime.equals("text/html")) {
return HTMLTransfer.getInstance();
}
if (mime.equals("text/uri-list")) {
return URLTransfer.getInstance();
}
if (mime.equals("application/x-java-rawimage")) {
return ImageTransfer.getInstance();
}
if (mime.equals("application/x-java-file-list") || mime.equals("java.file-list")) {
return FileTransfer.getInstance();
}
return getCustomTransfer(mime);
}
示例2: getMime
import org.eclipse.swt.dnd.URLTransfer; //导入依赖的package包/类
String getMime(Transfer transfer) {
if (transfer.equals(TextTransfer.getInstance())) {
return "text/plain";
}
if (transfer.equals(RTFTransfer.getInstance())) {
return "text/rtf";
} ;
if (transfer.equals( HTMLTransfer.getInstance())) {
return "text/html";
}
if (transfer.equals(URLTransfer.getInstance())) {
return "text/uri-list";
}
if (transfer.equals( ImageTransfer.getInstance())) {
return "application/x-java-rawimage";
}
if (transfer.equals(FileTransfer.getInstance())) {
return "application/x-java-file-list";
}
if (transfer instanceof CustomTransfer) {
return ((CustomTransfer)transfer).getMime();
}
return null;
}
示例3: getStructuredSelection
import org.eclipse.swt.dnd.URLTransfer; //导入依赖的package包/类
private IStructuredSelection getStructuredSelection(Object data, TransferData currentDataType) {
if (LocalSelectionTransfer.getTransfer().isSupportedType(currentDataType)) {
return (IStructuredSelection) data;
}
if (URLTransfer.getInstance().isSupportedType(currentDataType)) {
try {
return new StructuredSelection(new URL((String) data));
} catch (MalformedURLException e) {
// ignore
}
}
if (FileTransfer.getInstance().isSupportedType(currentDataType)) {
return new StructuredSelection(Arrays.stream((String[]) data).map(Path::new).collect(Collectors.toList()));
}
return new StructuredSelection();
}
示例4: getStructuredSelectionFromClipboard
import org.eclipse.swt.dnd.URLTransfer; //导入依赖的package包/类
private IStructuredSelection getStructuredSelectionFromClipboard(Display display) {
Clipboard clipboard = new Clipboard(display);
try {
String text = (String) clipboard.getContents(URLTransfer.getInstance());
if (text == null) {
text = (String) clipboard.getContents(TextTransfer.getInstance());
}
if (text != null) {
try {
URL url = new URL(text);
return new StructuredSelection(url);
} catch (MalformedURLException e) {
}
}
String[] paths = (String[]) clipboard.getContents(FileTransfer.getInstance());
if (paths != null) {
return new StructuredSelection(Arrays.stream(paths).map(Path::new).collect(Collectors.toList()));
}
return new StructuredSelection();
} finally {
clipboard.dispose();
}
}
示例5: registerWithExistingTarget
import org.eclipse.swt.dnd.URLTransfer; //导入依赖的package包/类
protected void registerWithExistingTarget(DropTarget target) {
Transfer[] transfers = target.getTransfer();
boolean exists = false;
if (transfers != null) {
for (Transfer transfer : transfers) {
if (transfer instanceof URLTransfer) {
exists = true;
break;
}
}
if (!exists) {
Transfer[] newTransfers = new Transfer[transfers.length + 1];
System.arraycopy(transfers, 0, newTransfers, 0, transfers.length);
newTransfers[transfers.length] = URLTransfer.getInstance();
target.setTransfer(newTransfers);
}
}
}
示例6: dropTargetIsValid
import org.eclipse.swt.dnd.URLTransfer; //导入依赖的package包/类
private boolean dropTargetIsValid(DropTargetEvent e, boolean isDrop) {
if (URLTransfer.getInstance().isSupportedType(e.currentDataType)) {
// on Windows, we get the URL already during drag operations...
// FIXME find a way to check the URL early on other platforms,
// too...
if (isDrop || Util.isWindows()) {
if (e.data == null && !extractEventData(e)) {
// ... but if we don't, it's no problem, unless this is
// already
// the final drop event
return !isDrop;
}
final String url = getUrl(e.data);
if (!ExampleURLHandler.isValidExample(url)) {
return false;
}
}
return true;
}
return false;
}
示例7: drop
import org.eclipse.swt.dnd.URLTransfer; //导入依赖的package包/类
@Override
public void drop(DropTargetEvent event) {
if (!URLTransfer.getInstance().isSupportedType(event.currentDataType)) {
return;
}
final String url = getUrl(event.data);
if (ExampleURLHandler.isValidExample(url)) {
DropTarget source = (DropTarget) event.getSource();
Display display = source.getDisplay();
display.asyncExec(new Runnable() {
public void run() {
proceedInstallation(url);
}
});
}
}
示例8: drop
import org.eclipse.swt.dnd.URLTransfer; //导入依赖的package包/类
@Override
public void drop(DropTargetEvent event) {
if (!URLTransfer.getInstance().isSupportedType(event.currentDataType)) {
traceUnsupportedDataType(event);
//ignore
return;
}
if (event.data == null) {
traceMissingEventData(event);
//reject
event.detail = DND.DROP_NONE;
return;
}
if (!dropTargetIsValid(event, true)) {
//reject
event.detail = DND.DROP_NONE;
return;
}
final String url = getUrl(event.data);
ForceIdeUrlActionHandler urlActionHandler = new ForceIdeUrlActionHandler(url, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay());
ForceIdeUrlActionHandler.ProjectAction result = urlActionHandler.processCommand();
if (result == ForceIdeUrlActionHandler.ProjectAction.IGNORE || result == ForceIdeUrlActionHandler.ProjectAction.INVALID)
traceInvalidEventData(event);
}
示例9: dragSetData
import org.eclipse.swt.dnd.URLTransfer; //导入依赖的package包/类
@Override
public void dragSetData(DragSourceEvent event) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
GitBlitViewModel model= (ProjectViewModel) selection.getFirstElement();
String gitURL=null;
if(model instanceof ProjectViewModel){
ProjectViewModel pm = (ProjectViewModel)model;
gitURL = pm.getGitUrl();
}
if(gitURL == null){
return;
}
if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
event.data = gitURL;
}
if (URLTransfer.getInstance().isSupportedType(event.dataType)) {
try{
event.data = new URL(gitURL);
}
catch(Exception e){
Activator.logError("Error while performin drag & drop",e);
}
}
}
示例10: setDragData
import org.eclipse.swt.dnd.URLTransfer; //导入依赖的package包/类
@Override
public boolean setDragData ( final DragSourceEvent event, final IStructuredSelection selection )
{
logger.debug ( "setDragData ( event: {}, selection: {}", event, selection );
final Collection<Item> items = ItemSelectionHelper.getSelection ( selection );
if ( items.isEmpty () )
{
logger.info ( "Empty item set for setDragData" );
return false;
}
if ( ItemTransfer.getInstance ().isSupportedType ( event.dataType ) )
{
event.data = items.toArray ( new Item[items.size ()] );
return true;
}
else if ( TextTransfer.getInstance ().isSupportedType ( event.dataType ) )
{
event.data = getItemUriData ( items );
return true;
}
else if ( URLTransfer.getInstance ().isSupportedType ( event.dataType ) )
{
event.data = getItemUriData ( items );
return true;
}
logger.debug ( "No possible transfer" );
return false;
}
示例11: dragSetData
import org.eclipse.swt.dnd.URLTransfer; //导入依赖的package包/类
@Override
public void dragSetData ( final DragSourceEvent event )
{
try
{
final IStructuredSelection selection = (IStructuredSelection)LocalSelectionTransfer.getTransfer ().getSelection ();
if ( ItemTransfer.getInstance ().isSupportedType ( event.dataType ) )
{
final List<Item> items = new ArrayList<Item> ();
for ( final Iterator<?> i = selection.iterator (); i.hasNext (); )
{
final ListEntry entry = (ListEntry)i.next ();
items.add ( entry.getItem () );
}
event.data = items.toArray ( new Item[items.size ()] );
}
else if ( TextTransfer.getInstance ().isSupportedType ( event.dataType ) )
{
setItemUriData ( event, selection );
}
else if ( URLTransfer.getInstance ().isSupportedType ( event.dataType ) )
{
setItemUriData ( event, selection );
}
}
catch ( final Exception e )
{
event.doit = false;
}
}
示例12: installDragAndDropSupport
import org.eclipse.swt.dnd.URLTransfer; //导入依赖的package包/类
private void installDragAndDropSupport() {
int operations = DND.DROP_MOVE;
addDragSupport(operations, new Transfer[] { LocalSelectionTransfer.getTransfer() },
new BookmarksViewerDragListener(this));
addDropSupport(DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK,
new Transfer[] { LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance(),
URLTransfer.getInstance() },
new BookmarksViewerDropListener(this, bookmarkDatabase, bookmarkPropertiesProvider));
}
示例13: testPasteUrl
import org.eclipse.swt.dnd.URLTransfer; //导入依赖的package包/类
@Test
public void testPasteUrl() throws BookmarksException {
// Given
// on mac, when you copy from chrome
copyToClipboard("http://www.google.com", URLTransfer.getInstance());
int numberOfBookmarksBefore = bookmarkDatabase.getBookmarksTree().size();
// When
pasteBookmarkOperation.paste(getBookmarkFolder(bookmarkDatabase.getBookmarksTree(), 0, 0, 0).getId(),
new NullProgressMonitor());
// Then
assertEquals(numberOfBookmarksBefore + 1, bookmarkDatabase.getBookmarksTree().size());
}
示例14: extractEventData
import org.eclipse.swt.dnd.URLTransfer; //导入依赖的package包/类
private boolean extractEventData(DropTargetEvent e) {
TransferData transferData = e.currentDataType;
if (transferData != null) {
Object data = URLTransfer.getInstance().nativeToJava(transferData);
if (data != null && getUrl(data) != null) {
e.data = data;
return true;
}
}
return false;
}
示例15: onDropRunnable
import org.eclipse.swt.dnd.URLTransfer; //导入依赖的package包/类
private void onDropRunnable(final DropTargetEvent event) {
final TransferData transferDataType = event.currentDataType;
boolean isPOI = false;
if (TextTransfer.getInstance().isSupportedType(transferDataType)) {
if (event.data instanceof String) {
isPOI = parsePOIText((String) event.data);
}
} else if (URLTransfer.getInstance().isSupportedType(transferDataType)) {
isPOI = parsePOIText((String) event.data);
}
if (isPOI == false) {
String poiText = Messages.Dialog_DropNoPOI_InvalidData;
if (event.data instanceof String) {
poiText = (String) event.data;
final int maxLength = 1000;
if (poiText.length() > maxLength) {
poiText = poiText.substring(0, maxLength) + "..."; //$NON-NLS-1$
}
}
MessageDialog.openInformation(
getShell(), //
Messages.Dialog_DropNoPOI_Title,
NLS.bind(Messages.Dialog_DropNoPOI_Message, poiText));
}
}