aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Guzman2013-11-27 15:43:40 (EST)
committerAlexander Kurtakov2013-12-05 09:33:05 (EST)
commit76c3cfc52c3eee17b87d2969ff1e7c20a2eeaaa3 (patch)
tree1d6042e4d0b9b4ad9bea06567e9d52f08aaaab66
parent1fcb48b34b727a64b1624de0f8cf6657eebddf29 (diff)
downloadorg.eclipse.linuxtools-76c3cfc52c3eee17b87d2969ff1e7c20a2eeaaa3.zip
org.eclipse.linuxtools-76c3cfc52c3eee17b87d2969ff1e7c20a2eeaaa3.tar.gz
org.eclipse.linuxtools-76c3cfc52c3eee17b87d2969ff1e7c20a2eeaaa3.tar.bz2
RPM: createrepo update RPM list project changerefs/changes/87/19087/4
Added functionality to update the RPM list on the Import RPMs form page whenever an RPM has been deleted from the contents folder of the project. Updates to the UI will only occur when at least 1 RPM has been deleted from the contents folder. Change-Id: Ic0319f403a876208ad0ae5174a9f7e54ec160e91 Signed-off-by: Neil Guzman <nguzman@redhat.com> Reviewed-on: https://git.eclipse.org/r/19087 Tested-by: Hudson CI 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.java2
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/ImportRPMsPage.java101
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties1
3 files changed, 103 insertions, 1 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 96f85c3..cea875a 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
@@ -90,6 +90,8 @@ public final class Messages {
public static String ImportRPMsPage_buttonCreateRepo;
/****/
public static String ImportRPMsPage_errorRefreshingTree;
+ /****/
+ public static String ImportRPMsPage_errorResourceChanged;
// ImportRPMsPage$ImportButtonListener
/****/
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 f3c20fb..18bce2c 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
@@ -14,7 +14,13 @@ import java.io.File;
import java.util.List;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -38,6 +44,8 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.console.MessageConsoleStream;
@@ -55,7 +63,7 @@ import org.eclipse.ui.menus.IMenuService;
* file system or the workspace. The RPMs imported will be the
* RPMs used when executing the createrepo command.
*/
-public class ImportRPMsPage extends FormPage {
+public class ImportRPMsPage extends FormPage implements IResourceChangeListener {
private CreaterepoProject project;
@@ -81,6 +89,28 @@ public class ImportRPMsPage extends FormPage {
/*
* (non-Javadoc)
+ * @see org.eclipse.ui.forms.editor.FormPage#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
+ */
+ @Override
+ public void init(IEditorSite site, IEditorInput input) {
+ super.init(site, input);
+ // add the resource change listener
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.forms.editor.FormPage#dispose()
+ */
+ @Override
+ public void dispose() {
+ // remove the resource change listener
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+ super.dispose();
+ }
+
+ /*
+ * (non-Javadoc)
* @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
*/
@Override
@@ -349,4 +379,73 @@ public class ImportRPMsPage extends FormPage {
public void widgetDefaultSelected(SelectionEvent e) {/* not implemented */}
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
+ */
+ @Override
+ public void resourceChanged(IResourceChangeEvent event) {
+ // might have to place the delete/close events to RepoMetadataFormEditor to
+ // occur for all the pages
+ switch (event.getType()) {
+ case IResourceChangeEvent.POST_CHANGE:
+ try {
+ IPath projectPath = project.getContentFolder().getFullPath();
+ IResourceDelta delta = event.getDelta().findMember(projectPath);
+ // delta is only null when nothing changed within the project's
+ // content folder
+ if (delta != null) {
+ delta.accept(new CreaterepoDeltaVisitor());
+ }
+ } catch (CoreException e) {
+ Activator.logError(Messages.ImportRPMsPage_errorResourceChanged, e);
+ }
+ break;
+ }
+ }
+
+ /**
+ * Class to control what to do if something happens in the workspace.
+ */
+ class CreaterepoDeltaVisitor implements IResourceDeltaVisitor {
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
+ */
+ @Override
+ public boolean visit(IResourceDelta delta) {
+ // exit if the project is being removed or closed
+ if (delta.getKind() == IResourceDelta.REMOVED ||
+ (delta.getFlags() | delta.getKind()) == (IResourceDelta.OPEN | IResourceDelta.CHANGED)) {
+ return false;
+ }
+ // get the files that were removed and exit if nothing was removed
+ IResourceDelta[] removedFiles = delta.getAffectedChildren(IResourceDelta.REMOVED);
+ if (removedFiles.length <= 0) {
+ return false;
+ }
+ // check if at least 1 of the files removed is an RPM and break out if so
+ boolean rpmsDeleted = false;
+ for (IResourceDelta resourceDelta : removedFiles) {
+ String extension = resourceDelta.getResource().getFileExtension();
+ if (extension != null && extension.equals(ICreaterepoConstants.RPM_FILE_EXTENSION)) {
+ rpmsDeleted = true;
+ break;
+ }
+ }
+ // exit if none of the removed files is an RPM; no need to update list
+ if (!rpmsDeleted) {
+ return false;
+ }
+ // deals with updating the UI of the page
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ refreshTree();
+ }
+ });
+ return false;
+ }
+ }
+
}
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 96785e2..b6db13d 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
@@ -58,6 +58,7 @@ ImportRPMsPage_buttonRemoveRPMs=&Remove RPMs
ImportRPMsPage_buttonCreateRepo=&Create Repo
ImportRPMsPage_errorRefreshingTree=Error while refreshing the RPM tree. Problem due to trying to get the \
RPMs in the content folder.
+ImportRPMsPage_errorResourceChanged=Error while trying to update the tree when workspace project changed.
# ImportRPMsPage$ImportButtonListener
ImportButtonListener_error=Error occured while trying to import the RPM.