01: /*
02: * uDig - User Friendly Desktop Internet GIS client
03: * http://udig.refractions.net
04: * (C) 2004, Refractions Research Inc.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */
17: package net.refractions.udig.catalog.internal.ui;
18:
19: import java.io.Serializable;
20: import java.net.URL;
21: import java.util.List;
22:
23: import net.refractions.udig.catalog.CatalogPlugin;
24: import net.refractions.udig.catalog.IService;
25: import net.refractions.udig.core.internal.CorePlugin;
26:
27: import org.eclipse.jface.viewers.Viewer;
28: import org.eclipse.jface.viewers.ViewerDropAdapter;
29: import org.eclipse.swt.dnd.TransferData;
30:
31: public class CatalogViewDropAdapter extends ViewerDropAdapter {
32:
33: protected CatalogViewDropAdapter(Viewer viewer) {
34: super (viewer);
35: }
36:
37: @Override
38: public boolean performDrop(Object data) {
39:
40: if (data instanceof URL) {
41: CatalogPlugin.getDefault().getServiceFactory().acquire(
42: (URL) data);
43: } else if (data instanceof java.util.Map) {
44: CatalogPlugin.getDefault().getServiceFactory().acquire(
45: (java.util.Map<String, Serializable>) data);
46: } else if (data instanceof String || data instanceof String[]) {
47: List<URL> urls = null;
48: if (data instanceof String) {
49: urls = CorePlugin.stringsToURLs((String) data);
50: } else {
51: urls = CorePlugin.stringsToURLs((String[]) data);
52: }
53:
54: for (URL url : urls) {
55: List<IService> services = CatalogPlugin.getDefault()
56: .getServiceFactory().acquire(url);
57: for (IService service : services) {
58: CatalogPlugin.getDefault().getLocalCatalog().add(
59: service);
60: }
61: }
62: }
63:
64: return true;
65: }
66:
67: @Override
68: public boolean validateDrop(Object target, int operation,
69: TransferData transferType) {
70: return true;
71: }
72:
73: }
|