aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Guzman2013-11-25 13:59:55 (EST)
committerAlexander Kurtakov2013-11-26 03:34:17 (EST)
commit04a9203f9054cbff8bafdd785def556fa523734d (patch)
tree842b53b8f4781654c8ae3dc82fc7ef4561d1f7f0
parent64bbd5261020b9fe4f3297e7781133270962180d (diff)
downloadorg.eclipse.linuxtools-04a9203f9054cbff8bafdd785def556fa523734d.zip
org.eclipse.linuxtools-04a9203f9054cbff8bafdd785def556fa523734d.tar.gz
org.eclipse.linuxtools-04a9203f9054cbff8bafdd785def556fa523734d.tar.bz2
RPM: createrepo editor and project creationrefs/changes/49/18849/2
Changed project creation to create and store the repo file if initial creation, or find the repo file if existing project. Added a listener to listen on when a createrepo project has been deleted/closed to also close the relating file if open in an editor. Change-Id: I175bc8831a2212cefc2e6f9ae01797a935323344 Signed-off-by: Neil Guzman <nguzman@redhat.com> Reviewed-on: https://git.eclipse.org/r/18849 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.java4
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/RepoFormEditor.java20
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/listener/CreaterepoResourceChangeListener.java90
-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/internal/rpm/createrepo/wizard/CreaterepoWizard.java6
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java28
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProjectCreator.java13
7 files changed, 150 insertions, 14 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 e335706..301395b 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
@@ -101,6 +101,10 @@ public final class Messages {
/****/
public static String MetadataPage_buttonRemoveTag;
+ // CreaterepoResourceChangeListener
+ /****/
+ public static String CreaterepoResourceChangeListener_errorGettingResource;
+
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/form/RepoFormEditor.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/RepoFormEditor.java
index 2410fbf..d59bd94 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/RepoFormEditor.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/RepoFormEditor.java
@@ -11,10 +11,13 @@
package org.eclipse.linuxtools.internal.rpm.createrepo.form;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.linuxtools.internal.rpm.createrepo.Activator;
import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
+import org.eclipse.linuxtools.internal.rpm.createrepo.listener.CreaterepoResourceChangeListener;
import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
@@ -31,8 +34,11 @@ import org.eclipse.ui.ide.ResourceUtil;
*/
public class RepoFormEditor extends FormEditor {
+ public static final String EDITOR_ID = "org.eclipse.linuxtools.rpm.createrepo.repoEditor"; //$NON-NLS-1$
+
private CreaterepoProject project;
private TextEditor editor;
+ private IResourceChangeListener resourceChangeListener;
/*
* (non-Javadoc)
@@ -44,10 +50,22 @@ public class RepoFormEditor extends FormEditor {
IFile file = ResourceUtil.getFile(input);
setPartName(file.getName());
try {
- project = new CreaterepoProject(file.getProject());
+ project = new CreaterepoProject(file.getProject(), file);
} catch (CoreException e) {
Activator.logError(Messages.RepoFormEditor_errorInitializingProject, e);
}
+ resourceChangeListener = new CreaterepoResourceChangeListener(project);
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
+ */
+ @Override
+ public void dispose() {
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceChangeListener);
+ super.dispose();
}
/*
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/listener/CreaterepoResourceChangeListener.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/listener/CreaterepoResourceChangeListener.java
new file mode 100644
index 0000000..ee1ea0f
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/listener/CreaterepoResourceChangeListener.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * 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.listener;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.linuxtools.internal.rpm.createrepo.Activator;
+import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
+import org.eclipse.linuxtools.internal.rpm.createrepo.form.RepoFormEditor;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.ResourceUtil;
+
+/**
+ * Handle the closing of the editors when their projects
+ * get deleted or closed.
+ */
+public class CreaterepoResourceChangeListener implements
+ IResourceChangeListener {
+
+ private CreaterepoProject project;
+
+ /** Default Constructor. */
+ public CreaterepoResourceChangeListener(CreaterepoProject project) {
+ this.project = project;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
+ */
+ @Override
+ public void resourceChanged(IResourceChangeEvent event) {
+ switch (event.getType()) {
+ case IResourceChangeEvent.POST_CHANGE:
+ case IResourceChangeEvent.PRE_CLOSE:
+ case IResourceChangeEvent.PRE_DELETE:
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ closeEditors();
+ }
+ });
+ break;
+ }
+ }
+
+ /**
+ * Close the editors thats resource has been affected by a change in the
+ * workspace. E.g. if an editor's project has been closed/deleted, close the
+ * editor.
+ */
+ private void closeEditors() {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ IResource repomdFile = project.getRepoFile();
+ // If the file is gone, that could mean: the project is closed, the project was
+ // deleted, or the file was deleted. If so, close the editor of the file.
+ if (!repomdFile.exists()) {
+ for (IWorkbenchPage page : workbench.getActiveWorkbenchWindow().getPages()) {
+ for (IEditorReference ref : page.getEditorReferences()) {
+ try {
+ // get the resource from the editor part and exit the editor if
+ // it is within the project(s) being closed/deleted
+ IResource resource = ResourceUtil.getResource(ref.getEditorInput());
+ if (ref.getId().equals(RepoFormEditor.EDITOR_ID) &&
+ resource.getProject().equals(project.getProject())) {
+ page.closeEditor(ref.getEditor(false), false);
+ }
+ } catch (PartInitException e) {
+ Activator.logError(Messages.CreaterepoResourceChangeListener_errorGettingResource, e);
+ }
+ }
+ }
+ }
+ }
+
+}
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 721aa4f..cfca731 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
@@ -62,3 +62,6 @@ MetadataPage_sectionInstructionTags=Add or remove as many tags per category as n
MetadataPage_buttonAddTag=&Add
MetadataPage_buttonEditTag=&Edit
MetadataPage_buttonRemoveTag=&Remove
+
+# CreaterepoResourceChangeListener
+CreaterepoResourceChangeListener_errorGettingResource=Error trying to get the resource from the editor.
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/wizard/CreaterepoWizard.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/wizard/CreaterepoWizard.java
index 0be5471..684b9f1 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/wizard/CreaterepoWizard.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/wizard/CreaterepoWizard.java
@@ -107,9 +107,11 @@ public class CreaterepoWizard extends Wizard implements INewWizard {
*/
protected void createProject(IProgressMonitor monitor) {
try {
+ String fileName = pageTwo.getRepositoryID().concat("."+ICreaterepoConstants. //$NON-NLS-1$
+ REPO_FILE_EXTENSION);
// create the project
project = CreaterepoProjectCreator.create(pageOne.getProjectName(),
- pageOne.getLocationPath(), monitor);
+ pageOne.getLocationPath(), fileName, monitor);
// get a handle on the content folder
IFolder folder = project
.getFolder(ICreaterepoConstants.CONTENT_FOLDER);
@@ -117,8 +119,6 @@ public class CreaterepoWizard extends Wizard implements INewWizard {
folder.create(false, true, monitor);
}
// get a handle on the .repo file
- String fileName = pageTwo.getRepositoryID().concat("."+ICreaterepoConstants. //$NON-NLS-1$
- REPO_FILE_EXTENSION);
final IFile file = project.getFile(fileName);
final String repoFileContents = initializeRepoContents(pageTwo.getRepositoryID(),
pageTwo.getRepositoryName(), pageTwo.getRepositoryURL());
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 fed16ed..f4a6512 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
@@ -34,13 +34,24 @@ public class CreaterepoProject {
private IProgressMonitor monitor;
/**
- * Default constructor.
+ * Constructor without repo file.
*
* @param project The project.
* @throws CoreException Thrown when unable to initialize project.
*/
public CreaterepoProject(IProject project) throws CoreException {
+ this(project, null);
+ }
+
+ /**
+ * Default constructor.
+ *
+ * @param project The project.
+ * @throws CoreException Thrown when unable to initialize project.
+ */
+ public CreaterepoProject(IProject project, IFile repoFile) throws CoreException {
this.project = project;
+ this.repoFile = repoFile;
monitor = new NullProgressMonitor();
intitialize();
// if something is deleted from the project while outside of eclipse,
@@ -59,14 +70,15 @@ public class CreaterepoProject {
if (!content.exists()) {
content.create(false, true, monitor);
}
- // tries to check if a .repo file already exists in the project
- for (IResource child : getProject().members()) {
- String extension = child.getFileExtension();
- if (extension != null && extension.equals(ICreaterepoConstants.REPO_FILE_EXTENSION)) {
- // assumes that there will only be 1 .repo file in the folder
- repoFile = (IFile) child;
+ if (repoFile == null) {
+ for (IResource child : getProject().members()) {
+ String extension = child.getFileExtension();
+ if (extension != null && extension.equals(ICreaterepoConstants.REPO_FILE_EXTENSION)) {
+ // assumes that there will only be 1 .repo file in the folder
+ repoFile = (IFile) child;
+ }
+ // if no repo file then keep it null
}
- // if no repo file then keep it null
}
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProjectCreator.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProjectCreator.java
index 1453242..6dd8b3c 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProjectCreator.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProjectCreator.java
@@ -10,6 +10,10 @@
*******************************************************************************/
package org.eclipse.linuxtools.rpm.createrepo;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspaceRoot;
@@ -35,7 +39,7 @@ public class CreaterepoProjectCreator {
* @throws CoreException Thrown when creating a project fails.
*/
public static IProject create(String projectName, IPath locationPath,
- IProgressMonitor monitor) throws CoreException {
+ String repoName, IProgressMonitor monitor) throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(projectName);
IProjectDescription description = ResourcesPlugin.getWorkspace()
@@ -45,7 +49,12 @@ public class CreaterepoProjectCreator {
}
project.create(description, monitor);
project.open(monitor);
- new CreaterepoProject(project);
+ IFile repoFile = project.getFile(repoName);
+ InputStream stream = new ByteArrayInputStream(ICreaterepoConstants.EMPTY_STRING.getBytes());
+ if (!repoFile.exists()) {
+ repoFile.create(stream, true, monitor);
+ }
+ new CreaterepoProject(project, repoFile);
return project;
}