|
From: <caw...@us...> - 2007-09-07 14:16:10
|
Revision: 3103
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=3103&view=rev
Author: cawilliams
Date: 2007-09-07 07:16:03 -0700 (Fri, 07 Sep 2007)
Log Message:
-----------
add File Transfer Drag and Drop adapter
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/CorextMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/CorextMessages.properties
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerPart.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackagesMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackagesMessages.properties
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/Resources.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/FileTransferDragAdapter.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/FileTransferDropAdapter.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/CorextMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/CorextMessages.java 2007-09-07 13:47:58 UTC (rev 3102)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/CorextMessages.java 2007-09-07 14:16:03 UTC (rev 3103)
@@ -9,6 +9,11 @@
public static String History_error_serialize;
public static String History_error_read;
public static String TypeInfoHistory_consistency_check;
+
+ public static String Resources_fileModified;
+ public static String Resources_modifiedResources;
+ public static String Resources_outOfSync;
+ public static String Resources_outOfSyncResources;
static {
NLS.initializeMessages(BUNDLE_NAME, CorextMessages.class);
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/CorextMessages.properties
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/CorextMessages.properties 2007-09-07 13:47:58 UTC (rev 3102)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/CorextMessages.properties 2007-09-07 14:16:03 UTC (rev 3103)
@@ -1,3 +1,18 @@
+###############################################################################
+# Copyright (c) 2000, 2006 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+Resources_outOfSyncResources= Some resources are out of sync
+Resources_outOfSync= Resource ''{0}'' is out of sync with file system.
+Resources_modifiedResources= There are modified resources
+Resources_fileModified= File ''{0}'' has been modified since the beginning of the operation
+
History_error_serialize= Problems serializing information to XML ''{0}''
TypeInfoHistory_consistency_check=Checking consistency of type history...
History_error_read=Problems reading information from XML ''{0}''
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/Resources.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/Resources.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/Resources.java 2007-09-07 14:16:03 UTC (rev 3103)
@@ -0,0 +1,237 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.corext.util;
+
+import java.io.File;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceStatus;
+import org.eclipse.core.resources.ResourceAttributes;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Status;
+import org.rubypeople.rdt.internal.ui.IRubyStatusConstants;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.RubyUIStatus;
+
+public class Resources {
+
+ private Resources() {
+ }
+
+ /**
+ * Checks if the given resource is in sync with the underlying file system.
+ *
+ * @param resource the resource to be checked
+ * @return IStatus status describing the check's result. If <code>status.
+ * isOK()</code> returns <code>true</code> then the resource is in sync
+ */
+ public static IStatus checkInSync(IResource resource) {
+ return checkInSync(new IResource[] {resource});
+ }
+
+ /**
+ * Checks if the given resources are in sync with the underlying file
+ * system.
+ *
+ * @param resources the resources to be checked
+ * @return IStatus status describing the check's result. If <code>status.
+ * isOK() </code> returns <code>true</code> then the resources are in sync
+ */
+ public static IStatus checkInSync(IResource[] resources) {
+ IStatus result= null;
+ for (int i= 0; i < resources.length; i++) {
+ IResource resource= resources[i];
+ if (!resource.isSynchronized(IResource.DEPTH_INFINITE)) {
+ result= addOutOfSync(result, resource);
+ }
+ }
+ if (result != null)
+ return result;
+ return new Status(IStatus.OK, RubyPlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$
+ }
+
+ /**
+ * Makes the given resource committable. Committable means that it is
+ * writeable and that its content hasn't changed by calling
+ * <code>validateEdit</code> for the given resource on <tt>IWorkspace</tt>.
+ *
+ * @param resource the resource to be checked
+ * @param context the context passed to <code>validateEdit</code>
+ * @return status describing the method's result. If <code>status.isOK()</code> returns <code>true</code> then the resources are committable.
+ *
+ * @see org.eclipse.core.resources.IWorkspace#validateEdit(org.eclipse.core.resources.IFile[], java.lang.Object)
+ */
+ public static IStatus makeCommittable(IResource resource, Object context) {
+ return makeCommittable(new IResource[] { resource }, context);
+ }
+
+ /**
+ * Makes the given resources committable. Committable means that all
+ * resources are writeable and that the content of the resources hasn't
+ * changed by calling <code>validateEdit</code> for a given file on
+ * <tt>IWorkspace</tt>.
+ *
+ * @param resources the resources to be checked
+ * @param context the context passed to <code>validateEdit</code>
+ * @return IStatus status describing the method's result. If <code>status.
+ * isOK()</code> returns <code>true</code> then the add resources are
+ * committable
+ *
+ * @see org.eclipse.core.resources.IWorkspace#validateEdit(org.eclipse.core.resources.IFile[], java.lang.Object)
+ */
+ public static IStatus makeCommittable(IResource[] resources, Object context) {
+ List readOnlyFiles= new ArrayList();
+ for (int i= 0; i < resources.length; i++) {
+ IResource resource= resources[i];
+ if (resource.getType() == IResource.FILE && isReadOnly(resource))
+ readOnlyFiles.add(resource);
+ }
+ if (readOnlyFiles.size() == 0)
+ return new Status(IStatus.OK, RubyPlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$
+
+ Map oldTimeStamps= createModificationStampMap(readOnlyFiles);
+ IStatus status= ResourcesPlugin.getWorkspace().validateEdit(
+ (IFile[]) readOnlyFiles.toArray(new IFile[readOnlyFiles.size()]), context);
+ if (!status.isOK())
+ return status;
+
+ IStatus modified= null;
+ Map newTimeStamps= createModificationStampMap(readOnlyFiles);
+ for (Iterator iter= oldTimeStamps.keySet().iterator(); iter.hasNext();) {
+ IFile file= (IFile) iter.next();
+ if (!oldTimeStamps.get(file).equals(newTimeStamps.get(file)))
+ modified= addModified(modified, file);
+ }
+ if (modified != null)
+ return modified;
+ return new Status(IStatus.OK, RubyPlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$
+ }
+
+ private static Map createModificationStampMap(List files){
+ Map map= new HashMap();
+ for (Iterator iter= files.iterator(); iter.hasNext(); ) {
+ IFile file= (IFile)iter.next();
+ map.put(file, new Long(file.getModificationStamp()));
+ }
+ return map;
+ }
+
+ private static IStatus addModified(IStatus status, IFile file) {
+ IStatus entry= RubyUIStatus.createError(
+ IRubyStatusConstants.VALIDATE_EDIT_CHANGED_CONTENT,
+ Messages.format(CorextMessages.Resources_fileModified, file.getFullPath().toString()),
+ null);
+ if (status == null) {
+ return entry;
+ } else if (status.isMultiStatus()) {
+ ((MultiStatus)status).add(entry);
+ return status;
+ } else {
+ MultiStatus result= new MultiStatus(RubyPlugin.getPluginId(),
+ IRubyStatusConstants.VALIDATE_EDIT_CHANGED_CONTENT,
+ CorextMessages.Resources_modifiedResources, null);
+ result.add(status);
+ result.add(entry);
+ return result;
+ }
+ }
+
+ private static IStatus addOutOfSync(IStatus status, IResource resource) {
+ IStatus entry= new Status(
+ IStatus.ERROR,
+ ResourcesPlugin.PI_RESOURCES,
+ IResourceStatus.OUT_OF_SYNC_LOCAL,
+ Messages.format(CorextMessages.Resources_outOfSync, resource.getFullPath().toString()),
+ null);
+ if (status == null) {
+ return entry;
+ } else if (status.isMultiStatus()) {
+ ((MultiStatus)status).add(entry);
+ return status;
+ } else {
+ MultiStatus result= new MultiStatus(
+ ResourcesPlugin.PI_RESOURCES,
+ IResourceStatus.OUT_OF_SYNC_LOCAL,
+ CorextMessages.Resources_outOfSyncResources, null);
+ result.add(status);
+ result.add(entry);
+ return result;
+ }
+ }
+
+ /**
+ * This method is used to generate a list of local locations to
+ * be used in DnD for file transfers.
+ *
+ * @param resources the array of resources to get the local
+ * locations for
+ * @return the local locations
+ */
+ public static String[] getLocationOSStrings(IResource[] resources) {
+ List result= new ArrayList(resources.length);
+ for (int i= 0; i < resources.length; i++) {
+ IPath location= resources[i].getLocation();
+ if (location != null)
+ result.add(location.toOSString());
+ }
+ return (String[]) result.toArray(new String[result.size()]);
+ }
+
+ /**
+ * Returns the location of the given resource. For local
+ * resources this is the OS path in the local file system. For
+ * remote resource this is the URI.
+ *
+ * @param resource the resource
+ * @return the location string or <code>null</code> if the
+ * location URI of the resource is <code>null</code>
+ */
+ public static String getLocationString(IResource resource) {
+ URI uri= resource.getLocationURI();
+ if (uri == null)
+ return null;
+ return EFS.SCHEME_FILE.equalsIgnoreCase(uri.getScheme())
+ ? new File(uri).getAbsolutePath()
+ : uri.toString();
+ }
+
+ public static boolean isReadOnly(IResource resource) {
+ ResourceAttributes resourceAttributes = resource.getResourceAttributes();
+ if (resourceAttributes == null) // not supported on this platform for this resource
+ return false;
+ return resourceAttributes.isReadOnly();
+ }
+
+ static void setReadOnly(IResource resource, boolean readOnly) {
+ ResourceAttributes resourceAttributes = resource.getResourceAttributes();
+ if (resourceAttributes == null) // not supported on this platform for this resource
+ return;
+
+ resourceAttributes.setReadOnly(readOnly);
+ try {
+ resource.setResourceAttributes(resourceAttributes);
+ } catch (CoreException e) {
+ RubyPlugin.log(e);
+ }
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/Resources.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/FileTransferDragAdapter.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/FileTransferDragAdapter.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/FileTransferDragAdapter.java 2007-09-07 14:16:03 UTC (rev 3103)
@@ -0,0 +1,240 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.packageview;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.util.TransferDragSourceListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DragSourceAdapter;
+import org.eclipse.swt.dnd.DragSourceEvent;
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.ISourceFolderRoot;
+import org.rubypeople.rdt.internal.corext.util.Resources;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.util.ExceptionHandler;
+
+/**
+ * Drag support class to allow dragging of files and folder from
+ * the packages view to another application.
+ */
+class FileTransferDragAdapter extends DragSourceAdapter implements TransferDragSourceListener {
+
+ private ISelectionProvider fProvider;
+
+ FileTransferDragAdapter(ISelectionProvider provider) {
+ fProvider= provider;
+ Assert.isNotNull(fProvider);
+ }
+
+ public Transfer getTransfer() {
+ return FileTransfer.getInstance();
+ }
+
+ public void dragStart(DragSourceEvent event) {
+ event.doit= isDragable(fProvider.getSelection());
+ }
+
+ private boolean isDragable(ISelection s) {
+ if (!(s instanceof IStructuredSelection))
+ return false;
+ IStructuredSelection selection= (IStructuredSelection)s;
+ for (Iterator iter= selection.iterator(); iter.hasNext();) {
+ Object element= iter.next();
+ if (element instanceof IRubyElement) {
+ IRubyElement jElement= (IRubyElement)element;
+ int type= jElement.getElementType();
+ // valid elements are: roots, units and types. Don't allow dragging
+ // projects outside of eclipse
+ if (type != IRubyElement.SOURCE_FOLDER_ROOT &&
+ type != IRubyElement.SCRIPT && type != IRubyElement.TYPE)
+ return false;
+ ISourceFolderRoot root= (ISourceFolderRoot)jElement.getAncestor(IRubyElement.SOURCE_FOLDER_ROOT);
+ if (root != null && root.isArchive())
+ return false;
+ }
+ }
+ List resources= convertIntoResources(selection);
+ return resources.size() == selection.size();
+ }
+
+ public void dragSetData(DragSourceEvent event){
+ List elements= getResources();
+ if (elements == null || elements.size() == 0) {
+ event.data= null;
+ return;
+ }
+
+ event.data= getResourceLocations(elements);
+ }
+
+ private static String[] getResourceLocations(List resources) {
+ return Resources.getLocationOSStrings((IResource[]) resources.toArray(new IResource[resources.size()]));
+ }
+
+ public void dragFinished(DragSourceEvent event) {
+ if (!event.doit)
+ return;
+
+ if (event.detail == DND.DROP_MOVE) {
+ // http://bugs.eclipse.org/bugs/show_bug.cgi?id=30543
+ // handleDropMove(event);
+ } else if (event.detail == DND.DROP_NONE || event.detail == DND.DROP_TARGET_MOVE) {
+ handleRefresh(event);
+ }
+ }
+
+ /* package */ void handleDropMove(DragSourceEvent event) {
+ final List elements= getResources();
+ if (elements == null || elements.size() == 0)
+ return;
+
+ WorkspaceModifyOperation op= new WorkspaceModifyOperation() {
+ public void execute(IProgressMonitor monitor) throws CoreException {
+ try {
+ monitor.beginTask(PackagesMessages.DragAdapter_deleting, elements.size());
+ MultiStatus status= createMultiStatus();
+ Iterator iter= elements.iterator();
+ while(iter.hasNext()) {
+ IResource resource= (IResource)iter.next();
+ try {
+ monitor.subTask(resource.getFullPath().toOSString());
+ resource.delete(true, null);
+
+ } catch (CoreException e) {
+ status.add(e.getStatus());
+ } finally {
+ monitor.worked(1);
+ }
+ }
+ if (!status.isOK()) {
+ throw new CoreException(status);
+ }
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+ runOperation(op, true, false);
+ }
+
+ private void handleRefresh(DragSourceEvent event) {
+ final Set roots= collectRoots(getResources());
+
+ WorkspaceModifyOperation op= new WorkspaceModifyOperation() {
+ public void execute(IProgressMonitor monitor) throws CoreException {
+ try {
+ monitor.beginTask(PackagesMessages.DragAdapter_refreshing, roots.size());
+ MultiStatus status= createMultiStatus();
+ Iterator iter= roots.iterator();
+ while (iter.hasNext()) {
+ IResource r= (IResource)iter.next();
+ try {
+ r.refreshLocal(IResource.DEPTH_ONE, new SubProgressMonitor(monitor, 1));
+ } catch (CoreException e) {
+ status.add(e.getStatus());
+ }
+ }
+ if (!status.isOK()) {
+ throw new CoreException(status);
+ }
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+
+ runOperation(op, true, false);
+ }
+
+ protected Set collectRoots(final List elements) {
+ final Set roots= new HashSet(10);
+
+ Iterator iter= elements.iterator();
+ while (iter.hasNext()) {
+ IResource resource= (IResource)iter.next();
+ IResource parent= resource.getParent();
+ if (parent == null) {
+ roots.add(resource);
+ } else {
+ roots.add(parent);
+ }
+ }
+ return roots;
+ }
+
+ private List getResources() {
+ ISelection s= fProvider.getSelection();
+ if (!(s instanceof IStructuredSelection))
+ return null;
+
+ return convertIntoResources((IStructuredSelection)s);
+ }
+
+ private List convertIntoResources(IStructuredSelection selection) {
+ List result= new ArrayList(selection.size());
+ for (Iterator iter= selection.iterator(); iter.hasNext();) {
+ Object o= iter.next();
+ IResource r= null;
+ if (o instanceof IResource) {
+ r= (IResource)o;
+ } else if (o instanceof IAdaptable) {
+ r= (IResource)((IAdaptable)o).getAdapter(IResource.class);
+ }
+ // Only add resource for which we have a location
+ // in the local file system.
+ if (r != null && r.getLocation() != null) {
+ result.add(r);
+ }
+ }
+ return result;
+ }
+
+ private MultiStatus createMultiStatus() {
+ return new MultiStatus(RubyPlugin.getPluginId(),
+ IStatus.OK, PackagesMessages.DragAdapter_problem, null);
+ }
+
+ private void runOperation(IRunnableWithProgress op, boolean fork, boolean cancelable) {
+ try {
+ Shell parent= RubyPlugin.getActiveWorkbenchShell();
+ new ProgressMonitorDialog(parent).run(fork, cancelable, op);
+ } catch (InvocationTargetException e) {
+ String message= PackagesMessages.DragAdapter_problem;
+ String title= PackagesMessages.DragAdapter_problemTitle;
+ ExceptionHandler.handle(e, title, message);
+ } catch (InterruptedException e) {
+ // Do nothing. Operation has been canceled by user.
+ }
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/FileTransferDragAdapter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/FileTransferDropAdapter.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/FileTransferDropAdapter.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/FileTransferDropAdapter.java 2007-09-07 14:16:03 UTC (rev 3103)
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.packageview;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.util.TransferDropTargetListener;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.actions.CopyFilesAndFoldersOperation;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.ISourceFolder;
+import org.rubypeople.rdt.core.ISourceFolderRoot;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.corext.util.Resources;
+import org.rubypeople.rdt.internal.ui.dnd.RdtViewerDropAdapter;
+import org.rubypeople.rdt.internal.ui.util.ExceptionHandler;
+
+/**
+ * Adapter to handle file drop from other applications.
+ */
+class FileTransferDropAdapter extends RdtViewerDropAdapter implements TransferDropTargetListener {
+
+ FileTransferDropAdapter(AbstractTreeViewer viewer) {
+ super(viewer, DND.FEEDBACK_SCROLL | DND.FEEDBACK_EXPAND);
+ }
+
+ //---- TransferDropTargetListener interface ---------------------------------------
+
+ public Transfer getTransfer() {
+ return FileTransfer.getInstance();
+ }
+
+ public boolean isEnabled(DropTargetEvent event) {
+ Object target= event.item != null ? event.item.getData() : null;
+ if (target == null)
+ return false;
+ return target instanceof IRubyElement || target instanceof IResource;
+ }
+
+ //---- Actual DND -----------------------------------------------------------------
+
+ public void validateDrop(Object target, DropTargetEvent event, int operation) {
+ event.detail= DND.DROP_NONE;
+
+ boolean isPackageFragment= target instanceof ISourceFolder;
+ boolean isRubyProject= target instanceof IRubyProject;
+ boolean isPackageFragmentRoot= target instanceof ISourceFolderRoot;
+ boolean isContainer= target instanceof IContainer;
+
+ if (!(isPackageFragment || isRubyProject || isPackageFragmentRoot || isContainer))
+ return;
+
+ if (isContainer) {
+ IContainer container= (IContainer)target;
+ if (container.isAccessible() && !Resources.isReadOnly(container))
+ event.detail= DND.DROP_COPY;
+ } else {
+ IRubyElement element= (IRubyElement)target;
+ if (!element.isReadOnly())
+ event.detail= DND.DROP_COPY;
+ }
+
+ return;
+ }
+
+ public void drop(Object dropTarget, final DropTargetEvent event) {
+ try {
+ int operation= event.detail;
+
+ event.detail= DND.DROP_NONE;
+ final Object data= event.data;
+ if (data == null || !(data instanceof String[]) || operation != DND.DROP_COPY)
+ return;
+
+ final IContainer target= getActualTarget(dropTarget);
+ if (target == null)
+ return;
+
+ // Run the import operation asynchronously.
+ // Otherwise the drag source (e.g., Windows Explorer) will be blocked
+ // while the operation executes. Fixes bug 35796.
+ Display.getCurrent().asyncExec(new Runnable() {
+ public void run() {
+ getShell().forceActive();
+ new CopyFilesAndFoldersOperation(getShell()).copyFiles((String[]) data, target);
+ // Import always performs a copy.
+ event.detail= DND.DROP_COPY;
+ }
+ });
+ } catch (RubyModelException e) {
+ String title= PackagesMessages.DropAdapter_errorTitle;
+ String message= PackagesMessages.DropAdapter_errorMessage;
+ ExceptionHandler.handle(e, getShell(), title, message);
+ }
+ }
+
+ private IContainer getActualTarget(Object dropTarget) throws RubyModelException{
+ if (dropTarget instanceof IContainer)
+ return (IContainer)dropTarget;
+ else if (dropTarget instanceof IRubyElement)
+ return getActualTarget(((IRubyElement)dropTarget).getCorrespondingResource());
+ return null;
+ }
+
+ private Shell getShell() {
+ return getViewer().getControl().getShell();
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/FileTransferDropAdapter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerPart.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerPart.java 2007-09-07 13:47:58 UTC (rev 3102)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackageExplorerPart.java 2007-09-07 14:16:03 UTC (rev 3103)
@@ -115,7 +115,6 @@
import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.core.util.Messages;
-import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.dnd.DelegatingDropAdapter;
import org.rubypeople.rdt.internal.ui.dnd.RdtViewerDragAdapter;
@@ -926,7 +925,7 @@
TransferDragSourceListener[] dragListeners= new TransferDragSourceListener[] {
new SelectionTransferDragAdapter(fViewer),
new ResourceTransferDragAdapter(fViewer),
-// new FileTransferDragAdapter(fViewer)
+ new FileTransferDragAdapter(fViewer)
};
fViewer.addDragSupport(ops, transfers, new RdtViewerDragAdapter(fViewer, dragListeners));
}
@@ -938,7 +937,7 @@
FileTransfer.getInstance()};
TransferDropTargetListener[] dropListeners= new TransferDropTargetListener[] {
new SelectionTransferDropAdapter(fViewer),
-// new FileTransferDropAdapter(fViewer),
+ new FileTransferDropAdapter(fViewer),
// new WorkingSetDropAdapter(this)
};
fViewer.addDropSupport(ops, transfers, new DelegatingDropAdapter(dropListeners));
@@ -1651,7 +1650,7 @@
case IRubyElement.TYPE:
case IRubyElement.METHOD:
case IRubyElement.FIELD:
- // select parent cu/classfile
+ // select parent script
element2= (IRubyElement)element2.getOpenable();
break;
case IRubyElement.RUBY_MODEL:
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackagesMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackagesMessages.java 2007-09-07 13:47:58 UTC (rev 3102)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackagesMessages.java 2007-09-07 14:16:03 UTC (rev 3103)
@@ -43,6 +43,14 @@
public static String PackageExplorer_notFound;
public static String PackageExplorer_filteredDialog_title;
public static String PackageExplorer_removeFilters;
+
+ public static String DragAdapter_deleting;
+ public static String DragAdapter_refreshing;
+ public static String DragAdapter_problem;
+ public static String DragAdapter_problemTitle;
+
+ public static String DropAdapter_errorTitle;
+ public static String DropAdapter_errorMessage;
static {
NLS.initializeMessages(BUNDLE_NAME, PackagesMessages.class);
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackagesMessages.properties
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackagesMessages.properties 2007-09-07 13:47:58 UTC (rev 3102)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/packageview/PackagesMessages.properties 2007-09-07 14:16:03 UTC (rev 3103)
@@ -8,7 +8,13 @@
# Contributors:
# IBM Corporation - initial API and implementation
###############################################################################
+DragAdapter_deleting=Deleting ...
+DragAdapter_problem=Problem while moving or copying files.
+DragAdapter_problemTitle=Drag & Drop
+DragAdapter_refreshing=Refreshing...
+DropAdapter_errorTitle=Drag & Drop
+DropAdapter_errorMessage=Error while moving or copying files.
GotoType_action_label=&Type...
GotoType_action_description=Searches for and selects the type entered.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|