aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Guzman2013-12-12 09:15:21 (EST)
committerAlexander Kurtakov2013-12-12 09:29:13 (EST)
commit6266a594c354351d0b9658eafd05ba7214d00ddb (patch)
tree59a35bc72b43fb4131165c6bf2e3d16851f421fb
parenta905d2064a9d1bd62308f9640f6d8100cf069779 (diff)
downloadorg.eclipse.linuxtools-6266a594c354351d0b9658eafd05ba7214d00ddb.zip
org.eclipse.linuxtools-6266a594c354351d0b9658eafd05ba7214d00ddb.tar.gz
org.eclipse.linuxtools-6266a594c354351d0b9658eafd05ba7214d00ddb.tar.bz2
RPM: createrepo drag and drop listenerrefs/changes/65/19465/7
Allow dropping of RPM files into the RPM treeviewer, which would import it into the project's content folder. Also modified resource change listener to update tree when an RPM file has been added. Change-Id: I07dd7b42acf3b0c5e9a9502be76c232a77a18658 Signed-off-by: Neil Guzman <nguzman@redhat.com> Reviewed-on: https://git.eclipse.org/r/19465 Reviewed-by: Alexander Kurtakov <akurtako@redhat.com> IP-Clean: Alexander Kurtakov <akurtako@redhat.com> Tested-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java4
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/dnd/ImportRPMDropListener.java98
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java28
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties3
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java4
5 files changed, 132 insertions, 5 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java
index cbe4ed1..4838e7c 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java
@@ -189,6 +189,10 @@ public final class Messages {
/****/
public static String CreaterepoDeltaPropertyPage_directoryDialogLabel;
+ // ImportRPMDropListener
+ /****/
+ public static String ImportRPMDropListener_errorCopyingFileToProject;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/dnd/ImportRPMDropListener.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/dnd/ImportRPMDropListener.java
new file mode 100644
index 0000000..188e315
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/dnd/ImportRPMDropListener.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat Inc. 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:
+ * Neil Guzman - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.rpm.createrepo.dnd;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerDropAdapter;
+import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoUtils;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.swt.dnd.TransferData;
+import org.eclipse.ui.console.MessageConsoleStream;
+
+/**
+ * Drop listener that only accepts a copy drag of a file.
+ */
+public class ImportRPMDropListener extends ViewerDropAdapter {
+
+ private CreaterepoProject project;
+
+ /**
+ * Default constructor.
+ *
+ * @param viewer The viewer to listen to.
+ * @param project The createrepo project.
+ */
+ public ImportRPMDropListener(Viewer viewer, CreaterepoProject project) {
+ super(viewer);
+ this.project = project;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ViewerDropAdapter#dragEnter(org.eclipse.swt.dnd.DropTargetEvent)
+ */
+ @Override
+ public void dragEnter(DropTargetEvent event) {
+ // only support file transfer types
+ if (FileTransfer.getInstance().isSupportedType(event.currentDataType)) {
+ // change the detail to a drag copy if is file transfer
+ event.detail = DND.DROP_COPY;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
+ */
+ @Override
+ public boolean validateDrop(Object target, int operation,
+ TransferData transferType) {
+ // true if it is a file transfer and is a copy action
+ if (FileTransfer.getInstance().isSupportedType(transferType) && operation == DND.DROP_COPY) {
+ return true;
+ }
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
+ */
+ @Override
+ public boolean performDrop(Object data) {
+ // data should be an array of paths to the file being transferred
+ if (data instanceof String[]) {
+ String[] dragData = (String[]) data;
+ for (String str : dragData) {
+ IPath path = new Path(str);
+ try {
+ project.importRPM(path.toFile());
+ } catch (CoreException e) {
+ MessageConsoleStream os = CreaterepoUtils.findConsole(Messages.CreaterepoProject_consoleName)
+ .newMessageStream();
+ os.print(NLS.bind(Messages.ImportRPMDropListener_errorCopyingFileToProject,
+ path.segment(path.segmentCount()-1)));
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java
index bc7d267..4b45cbe 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java
@@ -26,12 +26,17 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.linuxtools.internal.rpm.createrepo.Activator;
import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
+import org.eclipse.linuxtools.internal.rpm.createrepo.dnd.ImportRPMDropListener;
import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject;
import org.eclipse.linuxtools.rpm.createrepo.CreaterepoUtils;
import org.eclipse.linuxtools.rpm.createrepo.ICreaterepoConstants;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
@@ -147,8 +152,11 @@ public class ImportRPMsPage extends FormPage implements IResourceChangeListener
layout = new GridLayout(2, false);
layout.marginWidth = 1; layout.marginHeight = 7;
sectionClient.setLayout(layout);
- tree = toolkit.createTree(sectionClient, SWT.BORDER | SWT.MULTI | SWT.HORIZONTAL
+ TreeViewer viewer = new TreeViewer(sectionClient, SWT.BORDER | SWT.MULTI | SWT.HORIZONTAL
| SWT.VERTICAL | SWT.LEFT_TO_RIGHT | SWT.SMOOTH);
+ viewer.addDropSupport(DND.DROP_COPY, new Transfer[] {FileTransfer.getInstance()},
+ new ImportRPMDropListener(viewer, project));
+ tree = viewer.getTree();
tree.setLayoutData(expandComposite());
buttonList = toolkit.createComposite(sectionClient);
@@ -398,9 +406,10 @@ public class ImportRPMsPage extends FormPage implements IResourceChangeListener
(delta.getFlags() | delta.getKind()) == (IResourceDelta.OPEN | IResourceDelta.CHANGED)) {
return false;
}
- // get the files that were removed and exit if nothing was removed
+ // get the files that were removed/added and exit if nothing was removed/added
IResourceDelta[] removedFiles = delta.getAffectedChildren(IResourceDelta.REMOVED);
- if (removedFiles.length <= 0) {
+ IResourceDelta[] addedFiles = delta.getAffectedChildren(IResourceDelta.ADDED);
+ if (removedFiles.length <= 0 && addedFiles.length == 0) {
return false;
}
// check if at least 1 of the files removed is an RPM and break out if so
@@ -412,8 +421,17 @@ public class ImportRPMsPage extends FormPage implements IResourceChangeListener
break;
}
}
- // exit if none of the removed files is an RPM; no need to update list
- if (!rpmsDeleted) {
+ // check if at least 1 of the files added is an RPM and break out if so
+ boolean rpmsAdded = false;
+ for (IResourceDelta resourceDelta : addedFiles) {
+ String extension = resourceDelta.getResource().getFileExtension();
+ if (extension != null && extension.equals(ICreaterepoConstants.RPM_FILE_EXTENSION)) {
+ rpmsAdded = true;
+ break;
+ }
+ }
+ // exit if none of the removed/added files is an RPM; no need to update list
+ if (!rpmsDeleted && !rpmsAdded) {
return false;
}
// deals with updating the UI of the page
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties
index 68480d5..cff4350 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties
@@ -117,3 +117,6 @@ CreaterepoDeltaPropertyPage_errorInvalidText=Field must be an integer that is gr
CreaterepoDeltaPropertyPage_directoryDescription=Paths to look for older packages to delta against. Can be \
specified multiple times.
CreaterepoDeltaPropertyPage_directoryDialogLabel=Select a directory to delta against.
+
+# ImportRPMDropListener
+ImportRPMDropListener_errorCopyingFileToProject=Error occured trying to import {0} file into project.
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java
index bfff0d5..64d312a 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java
@@ -120,6 +120,10 @@ public class CreaterepoProject {
createContentFolder();
}
IFile file = getContentFolder().getFile(new Path(externalFile.getName()));
+ // do not import non-RPMs
+ if (!file.getFileExtension().equals(ICreaterepoConstants.RPM_FILE_EXTENSION)) {
+ return;
+ }
if (!file.exists()) {
try {
file.create(new FileInputStream(externalFile), false, monitor);