Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilos Kleint2011-02-01 11:54:44 +0000
committerMilos Kleint2011-02-01 11:54:44 +0000
commitd58495352dec6d7e51460dd52b5be9db39e51d0c (patch)
tree6194a47d3adf511035dd293837def7fc19fe2d51
parent4961542e6a3a9197e846e192ea6b7ec302fc9b26 (diff)
downloadm2e-core-d58495352dec6d7e51460dd52b5be9db39e51d0c.tar.gz
m2e-core-d58495352dec6d7e51460dd52b5be9db39e51d0c.tar.xz
m2e-core-d58495352dec6d7e51460dd52b5be9db39e51d0c.zip
embed the default return value into the provider
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/EffectivePomEditorProvider.java56
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java16
2 files changed, 42 insertions, 30 deletions
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/EffectivePomEditorProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/EffectivePomEditorProvider.java
index 617f5589..2f96e938 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/EffectivePomEditorProvider.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/EffectivePomEditorProvider.java
@@ -1,7 +1,16 @@
package org.eclipse.m2e.editor.pom;
+import java.io.IOException;
+import java.io.StringWriter;
+
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.MavenProject;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.m2e.core.actions.OpenPomAction.MavenStorageEditorInput;
+import org.eclipse.m2e.core.core.MavenLogger;
import org.eclipse.m2e.editor.MavenEditorPlugin;
+import org.eclipse.m2e.editor.internal.Messages;
import org.eclipse.ui.IEditorInput;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.osgi.framework.BundleContext;
@@ -15,31 +24,30 @@ public final class EffectivePomEditorProvider {
public static IEditorInput createEditorInput(MavenProject project, String name) {
BundleContext context = MavenEditorPlugin.getDefault().getBundle().getBundleContext();
if (context == null) {
- return null;
+ return createDefaultEditorInput(project, name);
}
ServiceReference ref = context.getServiceReference(Implementation.class.getName());
- if (ref == null) {
- return null;
- }
- Implementation service = (Implementation)context.getService(ref);
- if (service != null) {
- try {
- return service.createEditorInput(project, name);
- } finally {
- context.ungetService(ref);
+ if(ref != null) {
+ Implementation service = (Implementation) context.getService(ref);
+ if(service != null) {
+ try {
+ return service.createEditorInput(project, name);
+ } finally {
+ context.ungetService(ref);
+ }
}
}
- return null;
+ return createDefaultEditorInput(project, name);
}
public static StructuredTextEditor createTextEditor() {
BundleContext context = MavenEditorPlugin.getDefault().getBundle().getBundleContext();
if (context == null) {
- return null;
+ return createDefaultEditor();
}
ServiceReference ref = context.getServiceReference(Implementation.class.getName());
if (ref == null) {
- return null;
+ return createDefaultEditor();
}
Implementation service = (Implementation)context.getService(ref);
if (service != null) {
@@ -49,8 +57,26 @@ public final class EffectivePomEditorProvider {
context.ungetService(ref);
}
}
- return null;
- }
+ return createDefaultEditor();
+ }
+
+ private static StructuredTextEditor createDefaultEditor() {
+ return new StructuredTextEditor();
+ }
+
+ private static IEditorInput createDefaultEditorInput(MavenProject mavenProject, String name) {
+ StringWriter sw = new StringWriter();
+ byte[] bytes = new byte[0];
+ try {
+ new MavenXpp3Writer().write(sw, mavenProject.getModel());
+ String content = sw.toString();
+ bytes = content.getBytes("UTF-8");
+ } catch (IOException ie) {
+ MavenLogger.log(new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, -1,
+ Messages.MavenPomEditor_error_failed_effective, ie));
+ }
+ return new MavenStorageEditorInput(name, name, null, bytes); //$NON-NLS-1$
+ }
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java
index a4120e0c..273c451e 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java
@@ -534,18 +534,7 @@ public class MavenPomEditor extends FormEditor implements IResourceChangeListene
showEffectivePomError(name);
return Status.CANCEL_STATUS;
}
- IEditorInput editorInput = EffectivePomEditorProvider.createEditorInput(mavenProject, name);
- if (editorInput == null) {
- try{
- StringWriter sw = new StringWriter();
- new MavenXpp3Writer().write(sw, mavenProject.getModel());
- final String content = sw.toString();
- editorInput = new MavenStorageEditorInput(name, name, null, content.getBytes("UTF-8")); //$NON-NLS-1$
- }catch(IOException ie){
- MavenLogger.log(new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, -1, Messages.MavenPomEditor_error_failed_effective, ie));
- }
- }
- final IEditorInput fEditorInput = editorInput;
+ final IEditorInput fEditorInput = EffectivePomEditorProvider.createEditorInput(mavenProject, name);;
Display.getDefault().asyncExec(new Runnable(){
public void run() {
effectivePomSourcePage.setInput(fEditorInput);
@@ -680,9 +669,6 @@ public class MavenPomEditor extends FormEditor implements IResourceChangeListene
sourcePage.setEditorPart(this);
//the page for showing the effective POM
effectivePomSourcePage = EffectivePomEditorProvider.createTextEditor();
- if (effectivePomSourcePage == null) {
- effectivePomSourcePage = new StructuredTextEditor();
- }
effectivePomSourcePage.setEditorPart(this);
try {
int dex = addPage(effectivePomSourcePage, getEditorInput());

Back to the top